diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+WKNavigationDelegate.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+WKNavigationDelegate.swift index bf7cabb06e6b..27abfcd7df3c 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+WKNavigationDelegate.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+WKNavigationDelegate.swift @@ -737,14 +737,42 @@ extension BrowserViewController: WKNavigationDelegate { .mobileConfiguration, ] + let mimeTypesThatRequireSFSafariViewControllerHandlingTexts: [UTType: (String, String)] = [ + .textCalendar: (Strings.openTextCalendarAlertTitle, Strings.openTextCalendarAlertDescription), + .mobileConfiguration: ( + Strings.openMobileConfigurationAlertTitle, Strings.openMobileConfigurationAlertDescription + ), + ] + // SFSafariViewController only supports http/https links if navigationResponse.isForMainFrame, let url = responseURL, url.isWebPage(includeDataURIs: false), let tab, tab === tabManager.selectedTab, let mimeType = response.mimeType.flatMap({ UTType(mimeType: $0) }), - mimeTypesThatRequireSFSafariViewControllerHandling.contains(mimeType) + mimeTypesThatRequireSFSafariViewControllerHandling.contains(mimeType), + let (alertTitle, alertMessage) = mimeTypesThatRequireSFSafariViewControllerHandlingTexts[ + mimeType + ] { - handleLinkWithSafariViewController(url, tab: tab) + // Do what Chromium does: https://source.chromium.org/chromium/chromium/src/+/main:ios/chrome/browser/download/ui_bundled/safari_download_coordinator.mm;l=100;bpv=1;bpt=1?q=presentMobileConfigAlertFromURL&ss=chromium%2Fchromium%2Fsrc + // and present an alert before showing the Safari View Controller + let alert = UIAlertController( + title: alertTitle, + message: String.init( + format: alertMessage, + url.absoluteString + ), + preferredStyle: .alert + ) + alert.addAction( + UIAlertAction(title: Strings.OBContinueButton, style: .default) { [weak self] _ in + self?.handleLinkWithSafariViewController(url, tab: tab) + } + ) + + alert.addAction(UIAlertAction(title: Strings.cancelButtonTitle, style: .cancel)) + present(alert, animated: true) + return .cancel } diff --git a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift index ffe4b31c704f..db63a79aec39 100644 --- a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift +++ b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift @@ -3611,6 +3611,34 @@ extension Strings { value: "Don't Allow", comment: "Don't allow Brave to open the external app URL" ) + public static let openMobileConfigurationAlertTitle = NSLocalizedString( + "OpenMobileConfigurationAlertTitle", + tableName: "BraveShared", + bundle: .module, + value: "Configuration profile available", + comment: "Title of the alert when a mobile configuration profile is available for download" + ) + public static let openMobileConfigurationAlertDescription = NSLocalizedString( + "OpenMobileConfigurationAlertDescription", + tableName: "BraveShared", + bundle: .module, + value: "Continue download a configuration profile from %@", + comment: "Title of the alert when a mobile configuration profile is available for download. %@ is the URL placeholder of the website where the profile will be downloaded from" + ) + public static let openTextCalendarAlertTitle = NSLocalizedString( + "OpenTextCalendarAlertTitle", + tableName: "BraveShared", + bundle: .module, + value: "Calendar Event available", + comment: "Title of the alert when a calendar event is available for download" + ) + public static let openTextCalendarAlertDescription = NSLocalizedString( + "OpenTextCalendarAlertDescription", + tableName: "BraveShared", + bundle: .module, + value: "Continue download a calendar event from %@", + comment: "Title of the alert when a calendar event is available for download. %@ is the URL placeholder of the website where the calendar will be downloaded from" + ) public static let requestCameraPermissionPrompt = NSLocalizedString( "requestCameraPermissionPrompt", tableName: "BraveShared",