Skip to content

Bugfix FXIOS-9909 [Content Sharing] Block open external apps (backport #26341) #26534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions firefox-ios/Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@
1DA710072AE7106B00677F6B /* AppDataUsageReportSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA710062AE7106B00677F6B /* AppDataUsageReportSetting.swift */; };
1DAEEE002D93532900F4B42D /* UIImage+RenderingUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAEEDFF2D93532400F4B42D /* UIImage+RenderingUtilities.swift */; };
1DC372022B23C80F000F96C8 /* WindowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC372012B23C80F000F96C8 /* WindowManager.swift */; };
<<<<<<< HEAD
=======
1DC598B02DC3EDD50037D263 /* BenchmarkSteps.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC598AF2DC3EDD40037D263 /* BenchmarkSteps.swift */; };
1DC598B42DC52E3A0037D263 /* ForceRSSyncSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC598B32DC52E360037D263 /* ForceRSSyncSetting.swift */; };
>>>>>>> 855393657 (Bugfix FXIOS-9909 [Content Sharing] Block open external apps (#26341))
1DCEC3F22D5D1FEC00129966 /* ASSearchEngineSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCEC3F12D5D1FDD00129966 /* ASSearchEngineSelector.swift */; };
1DCEC3F42D600AE000129966 /* ASSearchEngineProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCEC3F32D600ADC00129966 /* ASSearchEngineProvider.swift */; };
1DCEC3F62D600C4400129966 /* ASSearchEngineIconRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCEC3F52D600C3D00129966 /* ASSearchEngineIconRecord.swift */; };
Expand Down Expand Up @@ -694,8 +699,6 @@
6669B5E2211418A200CA117B /* WebsiteDataSearchResultsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6669B5E1211418A200CA117B /* WebsiteDataSearchResultsViewController.swift */; };
66CE54A820FCF6CF00CC310B /* WebsiteDataManagementViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66CE54A720FCF6CF00CC310B /* WebsiteDataManagementViewController.swift */; };
6A3E5D8A283831D1001E706E /* DownloadQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A3E5D89283831D0001E706E /* DownloadQueueTests.swift */; };
6A5F591D28627C0100FABA92 /* TabManagerNavDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A5F591C28627C0100FABA92 /* TabManagerNavDelegateTests.swift */; };
6ACB550C28633860007A6ABD /* TabManagerNavDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ACB550B28633860007A6ABD /* TabManagerNavDelegate.swift */; };
6ADB651B285C03B100947EA4 /* DownloadHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ADB651A285C03B100947EA4 /* DownloadHelperTests.swift */; };
742A56391D80B54A00BDB803 /* PhotonActionSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 742A56381D80B54A00BDB803 /* PhotonActionSheet.swift */; };
742BD99E2A13AC9000BA6B15 /* OnboardingInstructionPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 742BD99D2A13AC9000BA6B15 /* OnboardingInstructionPopupViewController.swift */; };
Expand Down Expand Up @@ -2723,6 +2726,11 @@
1DA710062AE7106B00677F6B /* AppDataUsageReportSetting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDataUsageReportSetting.swift; sourceTree = "<group>"; };
1DAEEDFF2D93532400F4B42D /* UIImage+RenderingUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+RenderingUtilities.swift"; sourceTree = "<group>"; };
1DC372012B23C80F000F96C8 /* WindowManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowManager.swift; sourceTree = "<group>"; };
<<<<<<< HEAD
=======
1DC598AF2DC3EDD40037D263 /* BenchmarkSteps.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BenchmarkSteps.swift; sourceTree = "<group>"; };
1DC598B32DC52E360037D263 /* ForceRSSyncSetting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForceRSSyncSetting.swift; sourceTree = "<group>"; };
>>>>>>> 855393657 (Bugfix FXIOS-9909 [Content Sharing] Block open external apps (#26341))
1DCEC3F12D5D1FDD00129966 /* ASSearchEngineSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASSearchEngineSelector.swift; sourceTree = "<group>"; };
1DCEC3F32D600ADC00129966 /* ASSearchEngineProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASSearchEngineProvider.swift; sourceTree = "<group>"; };
1DCEC3F52D600C3D00129966 /* ASSearchEngineIconRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASSearchEngineIconRecord.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7889,11 +7897,9 @@
6A3E5D89283831D0001E706E /* DownloadQueueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadQueueTests.swift; sourceTree = "<group>"; };
6A4646B4A929C5049ED3E0DB /* nn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nn; path = nn.lproj/ClearHistoryConfirm.strings; sourceTree = "<group>"; };
6A574F2FAB02381D22FD47B4 /* af */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = af; path = af.lproj/LoginManager.strings; sourceTree = "<group>"; };
6A5F591C28627C0100FABA92 /* TabManagerNavDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabManagerNavDelegateTests.swift; sourceTree = "<group>"; };
6A694C35BF15DBBE61D7DB77 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Search.strings; sourceTree = "<group>"; };
6A8B40A7B8B0933B706C84B0 /* or */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = or; path = or.lproj/InfoPlist.strings; sourceTree = "<group>"; };
6A954888A18B54ED87980F19 /* af */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = af; path = af.lproj/Intro.strings; sourceTree = "<group>"; };
6ACB550B28633860007A6ABD /* TabManagerNavDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabManagerNavDelegate.swift; sourceTree = "<group>"; };
6AD94362821BDAD94165D610 /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/Intro.strings"; sourceTree = "<group>"; };
6ADB651A285C03B100947EA4 /* DownloadHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadHelperTests.swift; sourceTree = "<group>"; };
6B0545D197CACC8F242FBBC4 /* lt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/Search.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -12534,8 +12540,11 @@
39F819C51FD70F5D009E31E4 /* GlobalTabEventHandlers.swift */,
D3968F241A38FE8500CEFD3B /* TabManager.swift */,
5A8017DF29CE15D90047120D /* TabManagerImplementation.swift */,
<<<<<<< HEAD
6ACB550B28633860007A6ABD /* TabManagerNavDelegate.swift */,
21BFEEF42A040EF40033048D /* TabMigrationUtility.swift */,
=======
>>>>>>> 855393657 (Bugfix FXIOS-9909 [Content Sharing] Block open external apps (#26341))
1D558A592BEE7D07001EF527 /* WindowSimpleTabsCoordinator.swift */,
BD0D40792D83124E00C38511 /* TabWebViewPreview.swift */,
);
Expand Down Expand Up @@ -13174,7 +13183,13 @@
8AED868428CA7B1200351A50 /* TabManagement */ = {
isa = PBXGroup;
children = (
<<<<<<< HEAD
5A475E8829DB87BF009C13FD /* Legacy */,
=======
8AD08D1627E91AC800B8E907 /* TabsTelemetryTests.swift */,
AB7D4C3029ACAED100626427 /* Tab+ChangeUserAgentTests.swift */,
39236E711FCC600200A38F1B /* TabEventHandlerTests.swift */,
>>>>>>> 855393657 (Bugfix FXIOS-9909 [Content Sharing] Block open external apps (#26341))
5A475E8B29DB87F6009C13FD /* Mocks */,
5A475E8929DB87F2009C13FD /* TabManagerTests.swift */,
21BFEEF62A05A0310033048D /* TabMigrationUtilityTests.swift */,
Expand Down Expand Up @@ -17369,8 +17384,11 @@
8A3EF8072A2FCFF700796E3A /* SentryIDSetting.swift in Sources */,
ED390D202CF4DE2E00A775F9 /* URLActivityItemProvider.swift in Sources */,
8A03294E288F1F0800AD9B89 /* TopSitesDimension.swift in Sources */,
<<<<<<< HEAD
E1516A3E2A7BC07E007819A4 /* ReliabilityGrade.swift in Sources */,
6ACB550C28633860007A6ABD /* TabManagerNavDelegate.swift in Sources */,
=======
>>>>>>> 855393657 (Bugfix FXIOS-9909 [Content Sharing] Block open external apps (#26341))
E18259DF29B25E4F00E6BE76 /* UserNotificationCenterProtocol.swift in Sources */,
DFFC9AD12A681FA0002A6AAD /* NimbusFakespotFeatureLayer.swift in Sources */,
EDDB13872D3184F300C4B165 /* Site+createSponsoredSite.swift in Sources */,
Expand Down Expand Up @@ -18680,7 +18698,6 @@
8A2825352760399B00395E66 /* KeyboardPressesHandlerTests.swift in Sources */,
8AEF41622D15EDBC0013925D /* TopSitesMiddlewareTests.swift in Sources */,
ABEF80D92A2F283E003F52C4 /* CreditCardBottomSheetViewModelTests.swift in Sources */,
6A5F591D28627C0100FABA92 /* TabManagerNavDelegateTests.swift in Sources */,
8AABBD052A0041380089941E /* MockCoordinator.swift in Sources */,
8AABBCFF2A0017960089941E /* MockGleanWrapper.swift in Sources */,
21FA8FAE2AE856460013B815 /* TabsCoordinatorTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,29 @@ extension BrowserViewController: WKUIDelegate {

// MARK: - WKNavigationDelegate
extension BrowserViewController: WKNavigationDelegate {
/// Called when the WKWebView's content process has gone away. If this happens for the currently selected tab
/// then we immediately reload it.
func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
if let tab = tabManager.selectedTab, tab.webView == webView {
tab.consecutiveCrashes += 1

// Only automatically attempt to reload the crashed
// tab three times before giving up.
if tab.consecutiveCrashes < 3 {
logger.log("The webview has crashed, trying to reload.",
level: .warning,
category: .webview,
extra: ["Attempt number": "\(tab.consecutiveCrashes)"])

tabsTelemetry.trackConsecutiveCrashTelemetry(attemptNumber: tab.consecutiveCrashes)

webView.reload()
} else {
tab.consecutiveCrashes = 0
}
}
}

func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation?) {
guard let tab = tabManager[webView] else { return }

Expand All @@ -465,6 +488,11 @@ extension BrowserViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation?) {
if tabManager.selectedTab?.webView !== webView { return }

// Note the main frame JSContext (i.e. document, window) is not available yet.
if let tab = tabManager[webView], let blocker = tab.contentBlocker {
blocker.clearPageStats()
}

updateFindInPageVisibility(isVisible: false)

// If we are going to navigate to a new page, hide the reader mode button. Unless we
Expand All @@ -488,6 +516,9 @@ extension BrowserViewController: WKNavigationDelegate {
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
) {
// prevent the App from opening universal links
// https://stackoverflow.com/questions/38450586/prevent-universal-links-from-opening-in-wkwebview-uiwebview
let allowPolicy = WKNavigationActionPolicy(rawValue: WKNavigationActionPolicy.allow.rawValue + 2) ?? .allow
guard let url = navigationAction.request.url,
let tab = tabManager[webView]
else {
Expand Down Expand Up @@ -645,15 +676,20 @@ extension BrowserViewController: WKNavigationDelegate {
return
}

if navigationAction.navigationType == .linkActivated && url != webView.url {
if profile.prefs.boolForKey(PrefsKeys.BlockOpeningExternalApps) ?? false {
decisionHandler(.cancel)
webView.load(navigationAction.request)
return
}
let shouldBlockExternalApps = profile.prefs.boolForKey(PrefsKeys.BlockOpeningExternalApps) ?? false
let isGoogleDomain = url.host?.contains("google") ?? false
let isPrivate = tab.isPrivate

if navigationAction.navigationType == .linkActivated,
!shouldBlockExternalApps,
url != webView.url,
!isPrivate,
!isGoogleDomain {
decisionHandler(.allow)
return
}

decisionHandler(.allow)
decisionHandler(allowPolicy)
return
}

Expand Down Expand Up @@ -1047,6 +1083,13 @@ extension BrowserViewController: WKNavigationDelegate {
let metadataManager = tab.metadataManager
else { return }

// The main frame JSContext is available, and DOM parsing has begun.
// Do not execute JS at this point that requires running prior to DOM parsing.
if let tpHelper = tab.contentBlocker, !tpHelper.isEnabled {
let js = "window.__firefox__.TrackingProtectionStats.setEnabled(false, \(UserScriptManager.appIdToken))"
webView.evaluateJavascriptInDefaultContentWorld(js)
}

searchTelemetry.trackTabAndTopSiteSAP(tab, webView: webView)
webviewTelemetry.start()
tab.url = webView.url
Expand Down Expand Up @@ -1090,6 +1133,20 @@ extension BrowserViewController: WKNavigationDelegate {

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation?) {
webviewTelemetry.stop()
<<<<<<< HEAD
=======

if let url = webView.url, InternalURL(url) == nil {
if let title = webView.title,
tabManager.selectedTab?.webView == webView {
tabManager.selectedTab?.lastTitle = title
tabManager.notifyCurrentTabDidFinishLoading()
}

tabManager.commitChanges()
}

>>>>>>> 855393657 (Bugfix FXIOS-9909 [Content Sharing] Block open external apps (#26341))
if isPDFRefactorEnabled {
scrollController.configureRefreshControl()
navigationHandler?.removeDocumentLoading()
Expand Down Expand Up @@ -1160,7 +1217,8 @@ private extension BrowserViewController {
}

// Use for sms and mailto, which do not show a confirmation before opening.
func showExternalAlert(withText text: String, completion: @escaping (UIAlertAction) -> Void) {
func showExternalAlert(withText text: String,
completion: @escaping (UIAlertAction) -> Void) {
let alert = UIAlertController(title: nil,
message: text,
preferredStyle: .alert)
Expand All @@ -1173,8 +1231,7 @@ private extension BrowserViewController {

let cancelOption = UIAlertAction(
title: .CancelString,
style: .cancel,
handler: nil
style: .cancel
)

alert.addAction(okOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ class BrowserViewController: UIViewController,
private(set) lazy var searchTelemetry = SearchTelemetry(tabManager: tabManager)
private(set) lazy var webviewTelemetry = WebViewLoadMeasurementTelemetry()
private(set) lazy var privateBrowsingTelemetry = PrivateBrowsingTelemetry()
private(set) lazy var tabsTelemetry = TabsTelemetry()

private lazy var appStartupTelemetry = AppStartupTelemetry()

// location label actions
Expand Down Expand Up @@ -380,7 +382,7 @@ class BrowserViewController: UIViewController,

fileprivate func didInit() {
tabManager.addDelegate(self)
tabManager.addNavigationDelegate(self)
tabManager.setNavigationDelegate(self)
downloadQueue.addDelegate(self)
let tabWindowUUID = tabManager.windowUUID
AppEventQueue.wait(for: [.startupFlowComplete, .tabRestoration(tabWindowUUID)]) { [weak self] in
Expand Down
7 changes: 6 additions & 1 deletion firefox-ios/Client/TabManagement/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protocol TabManager: AnyObject {

// MARK: - Add/Remove Delegate
func addDelegate(_ delegate: TabManagerDelegate)
func addNavigationDelegate(_ delegate: WKNavigationDelegate)
func setNavigationDelegate(_ delegate: WKNavigationDelegate)
func removeDelegate(_ delegate: TabManagerDelegate, completion: (() -> Void)?)

// MARK: - Select Tab
Expand Down Expand Up @@ -94,6 +94,11 @@ protocol TabManager: AnyObject {
func clearAllTabsHistory()
func reorderTabs(isPrivate privateMode: Bool, fromIndex visibleFromIndex: Int, toIndex visibleToIndex: Int)
func preserveTabs()

/// Commits the pending changes to the persistent store.
func commitChanges()

func notifyCurrentTabDidFinishLoading()
func restoreTabs(_ forced: Bool)
func startAtHomeCheck() -> Bool
func expireLoginAlerts()
Expand Down
Loading