Skip to content

Commit

Permalink
Add support for calendar mime type
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Jan 3, 2025
1 parent 4b3d4ca commit 257703d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions ios/brave-ios/Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 257703d

Please sign in to comment.