Initial commit
Able to actually block scripts using a plugin, have XPC set up between plugin and host process. Limited UI support
This commit is contained in:
24
SBrowserProcessBundle/Info.plist
Normal file
24
SBrowserProcessBundle/Info.plist
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>SBRProcessPlugin</string>
|
||||
</dict>
|
||||
</plist>
|
||||
17
SBrowserProcessBundle/SBRProcessPlugin.h
Normal file
17
SBrowserProcessBundle/SBRProcessPlugin.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// SBRProcessPlugin.h
|
||||
// SBrowserProcessBundle
|
||||
//
|
||||
// Created by James Magahern on 7/22/20.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <WebKit/WKWebProcessPlugIn.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SBRProcessPlugin : NSObject <WKWebProcessPlugIn>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
86
SBrowserProcessBundle/SBRProcessPlugin.m
Normal file
86
SBrowserProcessBundle/SBRProcessPlugin.m
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// SBRProcessPlugin.m
|
||||
// SBrowserProcessBundle
|
||||
//
|
||||
// Created by James Magahern on 7/22/20.
|
||||
//
|
||||
|
||||
#import "SBRProcessPlugin.h"
|
||||
|
||||
#import "SBRWebProcessDelegate.h"
|
||||
#import "SBRWebProcessProxy.h"
|
||||
|
||||
#import <WebKit/_WKRemoteObjectInterface.h>
|
||||
#import <WebKit/_WKRemoteObjectRegistry.h>
|
||||
#import <WebKit/WKWebProcessPlugInBrowserContextController.h>
|
||||
#import <WebKit/WKWebProcessPlugInBrowserContextControllerPrivate.h>
|
||||
#import <WebKit/WKWebProcessPlugInLoadDelegate.h>
|
||||
|
||||
@interface SBRProcessPlugin () <WKWebProcessPlugInLoadDelegate, SBRWebProcessProxy>
|
||||
@property (nonatomic, strong) id<SBRWebProcessDelegate> processDelegate;
|
||||
@property (nonatomic, strong) NSMutableSet<NSString *> *allowedResourceOrigins;
|
||||
@end
|
||||
|
||||
@implementation SBRProcessPlugin
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
[super initialize];
|
||||
NSLog(@"SBRProcessPlugin Initialized");
|
||||
}
|
||||
|
||||
#pragma mark <SBRWebProcessProxy>
|
||||
|
||||
- (void)hello
|
||||
{
|
||||
NSLog(@"SBRProcessPlugin: Helloooooo");
|
||||
}
|
||||
|
||||
- (void)syncAllowedResourceOrigins:(NSSet<NSString *> *)allowedOrigins
|
||||
{
|
||||
if (!_allowedResourceOrigins) {
|
||||
_allowedResourceOrigins = [allowedOrigins mutableCopy];
|
||||
} else {
|
||||
[_allowedResourceOrigins unionSet:allowedOrigins];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark <WKWebProcessPlugIn>
|
||||
|
||||
- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
|
||||
{
|
||||
_WKRemoteObjectInterface *proxyInterface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(SBRWebProcessProxy)];
|
||||
[browserContextController._remoteObjectRegistry registerExportedObject:self interface:proxyInterface];
|
||||
|
||||
_WKRemoteObjectInterface *eventListenerInterface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(SBRWebProcessDelegate)];
|
||||
self.processDelegate = [browserContextController._remoteObjectRegistry remoteObjectProxyWithInterface:eventListenerInterface];
|
||||
|
||||
browserContextController.loadDelegate = self;
|
||||
|
||||
[[self processDelegate] webProcessDidConnect];
|
||||
}
|
||||
|
||||
#pragma mark <WKWebProcessPlugInLoadDelegate>
|
||||
|
||||
- (NSURLRequest *)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller frame:(WKWebProcessPlugInFrame *)frame willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
|
||||
{
|
||||
NSLog(@"SBRProcessPlugin: Sending request: %@", request);
|
||||
|
||||
NSURL *requestURL = [request URL];
|
||||
NSString *originString = [requestURL host];
|
||||
NSString *requestExtension = [requestURL pathExtension];
|
||||
if (requestExtension.length > 0 && [requestExtension isEqualToString:@"js"]) {
|
||||
[[self processDelegate] webProcessDidLoadScriptWithOrigin:originString];
|
||||
|
||||
if ([_allowedResourceOrigins containsObject:originString]) {
|
||||
NSLog(@"SBRProcessPlugin: Allowing whitelisted requestURL: %@", requestURL);
|
||||
} else {
|
||||
NSLog(@"SBRProcessPlugin: Blocking requestURL: %@", requestURL);
|
||||
request = nil;
|
||||
}
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
@end
|
||||
15
SBrowserProcessBundle/SBRWebProcessDelegate.h
Normal file
15
SBrowserProcessBundle/SBRWebProcessDelegate.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// SBRWebProcessDelegate.h
|
||||
// SBrowser
|
||||
//
|
||||
// Created by James Magahern on 7/22/20.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol SBRWebProcessDelegate <NSObject>
|
||||
|
||||
- (void)webProcessDidConnect;
|
||||
- (void)webProcessDidLoadScriptWithOrigin:(NSString *)origin;
|
||||
|
||||
@end
|
||||
15
SBrowserProcessBundle/SBRWebProcessProxy.h
Normal file
15
SBrowserProcessBundle/SBRWebProcessProxy.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// SBRWebProcessProxy.h
|
||||
// SBrowser
|
||||
//
|
||||
// Created by James Magahern on 7/22/20.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol SBRWebProcessProxy <NSObject>
|
||||
|
||||
- (void)hello;
|
||||
- (void)syncAllowedResourceOrigins:(NSSet<NSString *> *)allowedOrigins;
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user