@@ -92,16 +92,15 @@ - (NSString*) _evaluateJavascript:(NSString*)javascriptCommand
92
92
#if defined WVJB_PLATFORM_OSX
93
93
94
94
- (void ) _platformSpecificSetup : (WVJB_WEBVIEW_TYPE*)webView webViewDelegate : (WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler : (WVJBHandler)messageHandler resourceBundle : (NSBundle *)bundle {
95
- _messageHandler = messageHandler;
96
95
_webView = webView;
97
96
_webViewDelegate = webViewDelegate;
98
- _messageHandlers = [NSMutableDictionary dictionary ];
99
97
100
98
_webView.frameLoadDelegate = self;
101
99
_webView.resourceLoadDelegate = self;
102
100
_webView.policyDelegate = self;
103
101
104
- _resourceBundle = bundle;
102
+ _base = [[WebViewJavascriptBridgeBase alloc ] initWithWebViewType: @" WebView" handler: (WVJBHandler)messageHandler resourceBundle: (NSBundle *)bundle];
103
+ _base.delegate = self;
105
104
}
106
105
107
106
- (void ) _platformSpecificDealloc {
@@ -114,19 +113,11 @@ - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)frame
114
113
{
115
114
if (webView != _webView) { return ; }
116
115
117
- if (![[webView stringByEvaluatingJavaScriptFromString: @" typeof WebViewJavascriptBridge == 'object'" ] isEqualToString: @" true" ]) {
118
- NSBundle *bundle = _resourceBundle ? _resourceBundle : [NSBundle mainBundle ];
119
- NSString *filePath = [bundle pathForResource: @" WebViewJavascriptBridge.js" ofType: @" txt" ];
120
- NSString *js = [NSString stringWithContentsOfFile: filePath encoding: NSUTF8StringEncoding error: nil ];
121
- [webView stringByEvaluatingJavaScriptFromString: js];
116
+ if (![[webView stringByEvaluatingJavaScriptFromString: [_base webViewJavascriptCheckCommand ]] isEqualToString: @" true" ]) {
117
+ [_base injectJavascriptFile: NO ];
122
118
}
123
119
124
- if (_startupMessageQueue) {
125
- for (id queuedMessage in _startupMessageQueue) {
126
- [self _dispatchMessage: queuedMessage];
127
- }
128
- _startupMessageQueue = nil ;
129
- }
120
+ [_base dispatchStartUpMessageQueue ];
130
121
131
122
if (_webViewDelegate && [_webViewDelegate respondsToSelector: @selector (webView:didFinishLoadForFrame: )]) {
132
123
[_webViewDelegate webView: webView didFinishLoadForFrame: frame];
@@ -146,11 +137,12 @@ - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary
146
137
if (webView != _webView) { return ; }
147
138
148
139
NSURL *url = [request URL ];
149
- if ([[url scheme ] isEqualToString: kCustomProtocolScheme ]) {
150
- if ([[url host ] isEqualToString: kQueueHasMessage ]) {
151
- [self _flushMessageQueue ];
140
+ if ([_base correctProcotocolScheme: url]) {
141
+ if ([_base correctHost: url]) {
142
+ NSString *messageQueueString = [self _evaluateJavascript: [_base webViewJavascriptFetchQueyCommand ]];
143
+ [_base _flushMessageQueue: messageQueueString];
152
144
} else {
153
- NSLog ( @" WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@ :// %@ " , kCustomProtocolScheme , [ url path ]) ;
145
+ [_base logUnkownMessage: url] ;
154
146
}
155
147
[listener ignore ];
156
148
} else if (_webViewDelegate && [_webViewDelegate respondsToSelector: @selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener: )]) {
0 commit comments