From 2cdee87e8a4895e49f9fe803ff9539e74691e9cd Mon Sep 17 00:00:00 2001 From: James Magahern Date: Tue, 22 Sep 2020 12:30:09 -0700 Subject: [PATCH] Show error if web process never connects --- App/Browser View/BrowserViewController.swift | 24 +++++++++++++++++++ .../SBRProcessBundleBridge.h | 2 ++ .../SBRProcessBundleBridge.m | 2 ++ 3 files changed, 28 insertions(+) diff --git a/App/Browser View/BrowserViewController.swift b/App/Browser View/BrowserViewController.swift index d8e5b3a..eb53d38 100644 --- a/App/Browser View/BrowserViewController.swift +++ b/App/Browser View/BrowserViewController.swift @@ -282,6 +282,30 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { loadError = nil + // Check to make sure we have connected to the web content process + if !tab.bridge.webContentProcessConnected { + // This means we started loading a page but the web content process hasn't loaded, which means + // scripts are not getting blocked. + + // If you're ad-hoc signing this, you'll need to disable library validation: + // sudo defaults write /Library/Preferences/com.apple.security.libraryvalidation DisableLibraryValidation -bool YES + + DispatchQueue.main.async { [unowned self] in + // Stop loading now + webView.stopLoading() + + // Show an alert + let alert = UIAlertController(title: "Web Process Not Loaded", + message: "The web content process never contacted the host application", + preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in + alert.dismiss(animated: true, completion: nil) + })) + + present(alert, animated: true, completion: nil) + } + } + // Reset tracking this tab.allowedScriptOrigins.removeAll() tab.blockedScriptOrigins.removeAll() diff --git a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.h b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.h index 19c7ae2..11146cf 100644 --- a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.h +++ b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.h @@ -32,6 +32,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) BOOL allowAllScripts; // default is NO @property (nonatomic, assign) BOOL darkModeEnabled; +@property (nonatomic, readonly) BOOL webContentProcessConnected; + - (void)policyDataSourceDidChange; - (void)tearDown; diff --git a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m index 6587f3b..745dc0d 100644 --- a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m +++ b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m @@ -105,6 +105,8 @@ - (void)webProcessDidConnect { NSLog(@"SBRProcessBundleBridge: did connect. Saying hello, syncing allowlist"); + _webContentProcessConnected = YES; + [_webProcessProxy hello]; [self policyDataSourceDidChange]; }