// // SBRProcessBundleBridge.m // SBrowser // // Created by James Magahern on 7/22/20. // #import "SBRProcessBundleBridge.h" #import "SBRWebProcessDelegate.h" #import "SBRWebProcessProxy.h" #import #import #import #import #import #import @interface SBRProcessBundleBridge () @end @implementation SBRProcessBundleBridge { WKWebView *_webView; id _webProcessProxy; } - (WKWebView *)webView { if (!_webView) { // Inject bundle _WKProcessPoolConfiguration *poolConfiguration = [[_WKProcessPoolConfiguration alloc] init]; NSURL *bundleURL = [[[NSBundle mainBundle] builtInPlugInsURL] URLByAppendingPathComponent:@"SBrowserProcessBundle.bundle"]; [poolConfiguration setInjectedBundleURL:bundleURL]; // Set up process pool WKProcessPool *processPool = [[WKProcessPool alloc] _initWithConfiguration:poolConfiguration]; WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; configuration.processPool = processPool; // Instantiate web view WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]; // Configure proxy interface (interface to remote web process) _WKRemoteObjectInterface *proxyInterface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(SBRWebProcessProxy)]; _webProcessProxy = [[webView _remoteObjectRegistry] remoteObjectProxyWithInterface:proxyInterface]; // Configure delegate interface (registering us as the web process delegate for the remote process) _WKRemoteObjectInterface *delegateInterface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(SBRWebProcessDelegate)]; [[webView _remoteObjectRegistry] registerExportedObject:self interface:delegateInterface]; _webView = webView; } return _webView; } #pragma mark - (void)webProcessDidConnect { NSLog(@"SBRProcessBundleBridge: did connect. Saying hello, syncing allowlist"); [_webProcessProxy hello]; [self policyDataSourceDidChange]; } - (void)webProcessDidLoadScriptWithOrigin:(NSString *)origin { [_delegate webProcess:self didBlockScriptResourceFromOrigin:origin]; } #pragma mark Actions - (void)policyDataSourceDidChange { NSSet *allowedOrigins = [_policyDataSource allowedOriginsForScriptResources]; [_webProcessProxy syncAllowedResourceOrigins:allowedOrigins]; } @end