From 09591e46d9bdaf5fe6e3d0c37b1987cc5c48344e Mon Sep 17 00:00:00 2001 From: Brandon T Date: Fri, 3 Jan 2025 15:50:31 -0500 Subject: [PATCH 1/4] Add alert for mobile config download --- .../BVC+WKNavigationDelegate.swift | 21 ++++++++++++++++++- .../Sources/BraveStrings/BraveStrings.swift | 14 +++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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..05572bc93668 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 @@ -744,7 +744,26 @@ extension BrowserViewController: WKNavigationDelegate { let mimeType = response.mimeType.flatMap({ UTType(mimeType: $0) }), mimeTypesThatRequireSFSafariViewControllerHandling.contains(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: Strings.openMobileConfigurationAlertTitle, + message: String.init( + format: Strings.openMobileConfigurationAlertDescription, + 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 2a27cd39c880..cf7daaeee96f 100644 --- a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift +++ b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift @@ -3619,6 +3619,20 @@ 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( + "OpenMobileConfigurationAlertTitle", + 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 requestCameraPermissionPrompt = NSLocalizedString( "requestCameraPermissionPrompt", tableName: "BraveShared", From 4b3d4ca92ef869f92bd560085dce3ed49f880ab2 Mon Sep 17 00:00:00 2001 From: Brandon T Date: Fri, 3 Jan 2025 15:59:59 -0500 Subject: [PATCH 2/4] Fix key dup --- .../BrowserViewController/BVC+WKNavigationDelegate.swift | 1 - ios/brave-ios/Sources/BraveStrings/BraveStrings.swift | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) 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 05572bc93668..4eeffab59283 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 @@ -746,7 +746,6 @@ extension BrowserViewController: WKNavigationDelegate { { // 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: Strings.openMobileConfigurationAlertTitle, message: String.init( diff --git a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift index cf7daaeee96f..f8d837cd6b0c 100644 --- a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift +++ b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift @@ -3627,7 +3627,7 @@ extension Strings { comment: "Title of the alert when a mobile configuration profile is available for download" ) public static let openMobileConfigurationAlertDescription = NSLocalizedString( - "OpenMobileConfigurationAlertTitle", + "OpenMobileConfigurationAlertDescription", tableName: "BraveShared", bundle: .module, value: "Continue download a configuration profile from %@", From 257703da7e8bfaa7c2e7f8846ce8bbf043c59cc4 Mon Sep 17 00:00:00 2001 From: Brandon T Date: Fri, 3 Jan 2025 16:08:58 -0500 Subject: [PATCH 3/4] Add support for calendar mime type --- .../BVC+WKNavigationDelegate.swift | 16 +++++++++++++--- .../Sources/BraveStrings/BraveStrings.swift | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) 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 4eeffab59283..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,19 +737,29 @@ 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 + ] { // 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: Strings.openMobileConfigurationAlertTitle, + title: alertTitle, message: String.init( - format: Strings.openMobileConfigurationAlertDescription, + format: alertMessage, url.absoluteString ), preferredStyle: .alert diff --git a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift index f8d837cd6b0c..53b5c9200128 100644 --- a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift +++ b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift @@ -3633,6 +3633,20 @@ extension Strings { 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 available", + comment: "Title of the alert when a calendar is available for download" + ) + public static let openTextCalendarAlertDescription = NSLocalizedString( + "OpenTextCalendarAlertDescription", + tableName: "BraveShared", + bundle: .module, + value: "Continue download a calendar from %@", + comment: "Title of the alert when a calendar 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", From c155b178d32feaab3e43440c640718eca7b88eb9 Mon Sep 17 00:00:00 2001 From: Brandon-T Date: Fri, 3 Jan 2025 16:20:53 -0500 Subject: [PATCH 4/4] Change title and description of alert to say calendar event instead --- ios/brave-ios/Sources/BraveStrings/BraveStrings.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift index 53b5c9200128..80cc4a44d3a4 100644 --- a/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift +++ b/ios/brave-ios/Sources/BraveStrings/BraveStrings.swift @@ -3637,15 +3637,15 @@ extension Strings { "OpenTextCalendarAlertTitle", tableName: "BraveShared", bundle: .module, - value: "Calendar available", - comment: "Title of the alert when a calendar is available for download" + 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 from %@", - comment: "Title of the alert when a calendar is available for download. %@ is the URL placeholder of the website where the calendar will be downloaded from" + 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",