Skip to content

Commit

Permalink
Updated OSX WebView to use the new Base class
Browse files Browse the repository at this point in the history
  • Loading branch information
lokimeyburg committed Nov 9, 2014
1 parent e2bdcf5 commit 1bce38a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
12 changes: 12 additions & 0 deletions Example Apps/ExampleApp-OSX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
0ECB01491A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */; };
0ECB014A1A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */; };
2C136A2517641106004C7401 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C136A2417641106004C7401 /* Cocoa.framework */; };
2C136A2F17641106004C7401 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2C136A2D17641106004C7401 /* InfoPlist.strings */; };
2C136A3117641106004C7401 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C136A3017641106004C7401 /* main.m */; };
Expand All @@ -20,6 +22,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
0ECB01451A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridgeBase.h; sourceTree = "<group>"; };
0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridgeBase.m; sourceTree = "<group>"; };
0ECB01471A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewJavascriptBridge.h; sourceTree = "<group>"; };
0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WKWebViewJavascriptBridge.m; sourceTree = "<group>"; };
2C136A2117641106004C7401 /* ExampleApp-OSX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ExampleApp-OSX.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2C136A2417641106004C7401 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
2C136A2717641106004C7401 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -118,6 +124,10 @@
2C1562C1176BA9FF00B4AE50 /* WebViewJavascriptBridge */ = {
isa = PBXGroup;
children = (
0ECB01451A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.h */,
0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */,
0ECB01471A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.h */,
0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */,
2C1562C2176BA9FF00B4AE50 /* WebViewJavascriptBridge.h */,
2C1562C3176BA9FF00B4AE50 /* WebViewJavascriptBridge.js.txt */,
2C1562C4176BA9FF00B4AE50 /* WebViewJavascriptBridge.m */,
Expand Down Expand Up @@ -192,6 +202,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0ECB01491A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m in Sources */,
0ECB014A1A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m in Sources */,
2C136A3117641106004C7401 /* main.m in Sources */,
2C1562C6176BA9FF00B4AE50 /* WebViewJavascriptBridge.m in Sources */,
2C136A3817641106004C7401 /* AppDelegate.m in Sources */,
Expand Down
28 changes: 10 additions & 18 deletions WebViewJavascriptBridge/WebViewJavascriptBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ - (NSString*) _evaluateJavascript:(NSString*)javascriptCommand
#if defined WVJB_PLATFORM_OSX

- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)messageHandler resourceBundle:(NSBundle*)bundle{
_messageHandler = messageHandler;
_webView = webView;
_webViewDelegate = webViewDelegate;
_messageHandlers = [NSMutableDictionary dictionary];

_webView.frameLoadDelegate = self;
_webView.resourceLoadDelegate = self;
_webView.policyDelegate = self;

_resourceBundle = bundle;
_base = [[WebViewJavascriptBridgeBase alloc] initWithWebViewType:@"WebView" handler:(WVJBHandler)messageHandler resourceBundle:(NSBundle*)bundle];
_base.delegate = self;
}

- (void) _platformSpecificDealloc {
Expand All @@ -114,19 +113,11 @@ - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)frame
{
if (webView != _webView) { return; }

if (![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) {
NSBundle *bundle = _resourceBundle ? _resourceBundle : [NSBundle mainBundle];
NSString *filePath = [bundle pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"];
NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:js];
if (![[webView stringByEvaluatingJavaScriptFromString:[_base webViewJavascriptCheckCommand]] isEqualToString:@"true"]) {
[_base injectJavascriptFile:NO];
}

if (_startupMessageQueue) {
for (id queuedMessage in _startupMessageQueue) {
[self _dispatchMessage:queuedMessage];
}
_startupMessageQueue = nil;
}
[_base dispatchStartUpMessageQueue];

if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)]) {
[_webViewDelegate webView:webView didFinishLoadForFrame:frame];
Expand All @@ -146,11 +137,12 @@ - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary
if (webView != _webView) { return; }

NSURL *url = [request URL];
if ([[url scheme] isEqualToString:kCustomProtocolScheme]) {
if ([[url host] isEqualToString:kQueueHasMessage]) {
[self _flushMessageQueue];
if ([_base correctProcotocolScheme:url]) {
if ([_base correctHost:url]) {
NSString *messageQueueString = [self _evaluateJavascript:[_base webViewJavascriptFetchQueyCommand]];
[_base _flushMessageQueue:messageQueueString];
} else {
NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@://%@", kCustomProtocolScheme, [url path]);
[_base logUnkownMessage:url];
}
[listener ignore];
} else if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) {
Expand Down

0 comments on commit 1bce38a

Please sign in to comment.