Fix crash when opening in new tab

This commit is contained in:
James Magahern
2020-09-24 16:36:31 -07:00
parent d0713b5f11
commit 6e0e2a0f20
5 changed files with 45 additions and 30 deletions

View File

@@ -34,9 +34,13 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) BOOL webContentProcessConnected;
- (instancetype)initWithWebViewConfiguration:(nullable WKWebViewConfiguration *)webViewConfiguration NS_DESIGNATED_INITIALIZER;
- (void)policyDataSourceDidChange;
- (void)tearDown;
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END

View File

@@ -60,32 +60,38 @@
return interface;
}
- (WKWebView *)webView
- (instancetype)initWithWebViewConfiguration:(WKWebViewConfiguration *)webViewConfiguration
{
if (!_webView) {
// Inject bundle
_WKProcessPoolConfiguration *poolConfiguration = [[_WKProcessPoolConfiguration alloc] init];
NSURL *bundleURL = [[[NSBundle mainBundle] builtInPlugInsURL] URLByAppendingPathComponent:@"SBrowserProcessBundle.bundle"];
// Make sure it exists. Bail if otherwise.
NSBundle *pluginBundle = [NSBundle bundleWithURL:bundleURL];
NSAssert(pluginBundle != nil, @"Attix process bundle not found at %@", bundleURL.path);
[poolConfiguration setInjectedBundleURL:bundleURL];
self = [super init];
if (self) {
if (!webViewConfiguration) {
webViewConfiguration = [[WKWebViewConfiguration alloc] init];
// Inject bundle
_WKProcessPoolConfiguration *poolConfiguration = [[_WKProcessPoolConfiguration alloc] init];
NSURL *bundleURL = [[[NSBundle mainBundle] builtInPlugInsURL] URLByAppendingPathComponent:@"SBrowserProcessBundle.bundle"];
// Make sure it exists. Bail if otherwise.
NSBundle *pluginBundle = [NSBundle bundleWithURL:bundleURL];
NSAssert(pluginBundle != nil, @"Attix process bundle not found at %@", bundleURL.path);
[poolConfiguration setInjectedBundleURL:bundleURL];
// Set up process pool
_processPool = [[WKProcessPool alloc] _initWithConfiguration:poolConfiguration];
// Set up process pool
_processPool = [[WKProcessPool alloc] _initWithConfiguration:poolConfiguration];
// Initialize allowed origins now
NSArray<NSString *> *allowedOrigins = [[_policyDataSource allowedOriginsForScriptResources] allObjects];
[_processPool _setObject:allowedOrigins forBundleParameter:SBRGetAllowedOriginsKey()];
[_processPool _setObject:@(_allowAllScripts) forBundleParameter:SBRGetAllScriptsAllowedKey()];
webViewConfiguration.processPool = _processPool;
}
// Initialize allowed origins now
NSArray<NSString *> *allowedOrigins = [[_policyDataSource allowedOriginsForScriptResources] allObjects];
[_processPool _setObject:allowedOrigins forBundleParameter:SBRGetAllowedOriginsKey()];
[_processPool _setObject:@(_allowAllScripts) forBundleParameter:SBRGetAllScriptsAllowedKey()];
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.processPool = _processPool;
_webViewConfiguration = webViewConfiguration;
// Instantiate web view
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfiguration];
// Configure proxy interface (interface to remote web process)
_webProcessProxy = [[webView _remoteObjectRegistry] remoteObjectProxyWithInterface:[self _webProcessProxyInterface]];
@@ -94,10 +100,9 @@
[[webView _remoteObjectRegistry] registerExportedObject:self interface:[self _webProcessDelegateInterface]];
_webView = webView;
_webViewConfiguration = configuration;
}
return _webView;
return self;
}
#pragma mark <SBRWebProcessDelegate>