| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/web/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 // Key of UMA IOSFix.ViewportZoomBugCount histogram. | 174 // Key of UMA IOSFix.ViewportZoomBugCount histogram. |
| 175 const char kUMAViewportZoomBugCount[] = "Renderer.ViewportZoomBugCount"; | 175 const char kUMAViewportZoomBugCount[] = "Renderer.ViewportZoomBugCount"; |
| 176 | 176 |
| 177 // A tag for the web view, so that tests can identify it. This is used instead | 177 // A tag for the web view, so that tests can identify it. This is used instead |
| 178 // of exposing a getter (and deliberately not exposed in the header) to make it | 178 // of exposing a getter (and deliberately not exposed in the header) to make it |
| 179 // *very* clear that this is a hack which should only be used as a last resort. | 179 // *very* clear that this is a hack which should only be used as a last resort. |
| 180 const NSUInteger kWebViewTag = 0x3eb71e3; | 180 const NSUInteger kWebViewTag = 0x3eb71e3; |
| 181 // URL scheme for messages sent from javascript for asynchronous processing. | 181 // URL scheme for messages sent from javascript for asynchronous processing. |
| 182 NSString* const kScriptMessageName = @"crwebinvoke"; | 182 NSString* const kScriptMessageName = @"crwebinvoke"; |
| 183 // URL scheme for messages sent from javascript for immediate processing. | |
| 184 NSString* const kScriptImmediateName = @"crwebinvokeimmediate"; | |
| 185 | 183 |
| 186 // Constants for storing the source of NSErrors received by WKWebViews: | 184 // Constants for storing the source of NSErrors received by WKWebViews: |
| 187 // - Errors received by |-webView:didFailProvisionalNavigation:withError:| are | 185 // - Errors received by |-webView:didFailProvisionalNavigation:withError:| are |
| 188 // recorded using WKWebViewErrorSource::PROVISIONAL_LOAD. These should be | 186 // recorded using WKWebViewErrorSource::PROVISIONAL_LOAD. These should be |
| 189 // cancelled. | 187 // cancelled. |
| 190 // - Errors received by |-webView:didFailNavigation:withError:| are recorded | 188 // - Errors received by |-webView:didFailNavigation:withError:| are recorded |
| 191 // using WKWebViewsource::NAVIGATION. These errors should not be cancelled, | 189 // using WKWebViewsource::NAVIGATION. These errors should not be cancelled, |
| 192 // as the WKWebView will automatically retry the load. | 190 // as the WKWebView will automatically retry the load. |
| 193 NSString* const kWKWebViewErrorSourceKey = @"ErrorSource"; | 191 NSString* const kWKWebViewErrorSourceKey = @"ErrorSource"; |
| 194 typedef enum { NONE = 0, PROVISIONAL_LOAD, NAVIGATION } WKWebViewErrorSource; | 192 typedef enum { NONE = 0, PROVISIONAL_LOAD, NAVIGATION } WKWebViewErrorSource; |
| (...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2623 if (base::SysNSStringToUTF8([_windowIDJSManager windowID]) != windowID) { | 2621 if (base::SysNSStringToUTF8([_windowIDJSManager windowID]) != windowID) { |
| 2624 DLOG(WARNING) << "Message from JS ignored due to non-matching windowID: " << | 2622 DLOG(WARNING) << "Message from JS ignored due to non-matching windowID: " << |
| 2625 [_windowIDJSManager windowID] | 2623 [_windowIDJSManager windowID] |
| 2626 << " != " << base::SysUTF8ToNSString(windowID); | 2624 << " != " << base::SysUTF8ToNSString(windowID); |
| 2627 return NO; | 2625 return NO; |
| 2628 } | 2626 } |
| 2629 base::DictionaryValue* command = nullptr; | 2627 base::DictionaryValue* command = nullptr; |
| 2630 if (!message->GetDictionary("crwCommand", &command)) { | 2628 if (!message->GetDictionary("crwCommand", &command)) { |
| 2631 return NO; | 2629 return NO; |
| 2632 } | 2630 } |
| 2633 if ([scriptMessage.name isEqualToString:kScriptImmediateName] || | 2631 if ([scriptMessage.name isEqualToString:kScriptMessageName]) { |
| 2634 [scriptMessage.name isEqualToString:kScriptMessageName]) { | |
| 2635 return [self respondToMessage:command | 2632 return [self respondToMessage:command |
| 2636 userIsInteracting:[self userIsInteracting] | 2633 userIsInteracting:[self userIsInteracting] |
| 2637 originURL:net::GURLWithNSURL([_webView URL])]; | 2634 originURL:net::GURLWithNSURL([_webView URL])]; |
| 2638 } | 2635 } |
| 2639 | 2636 |
| 2640 NOTREACHED(); | 2637 NOTREACHED(); |
| 2641 return NO; | 2638 return NO; |
| 2642 } | 2639 } |
| 2643 | 2640 |
| 2644 #pragma mark - | 2641 #pragma mark - |
| (...skipping 2002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4647 for (NSString* keyPath in self.WKWebViewObservers) { | 4644 for (NSString* keyPath in self.WKWebViewObservers) { |
| 4648 [_webView removeObserver:self forKeyPath:keyPath]; | 4645 [_webView removeObserver:self forKeyPath:keyPath]; |
| 4649 } | 4646 } |
| 4650 [self clearActivityIndicatorTasks]; | 4647 [self clearActivityIndicatorTasks]; |
| 4651 | 4648 |
| 4652 _webView.reset([webView retain]); | 4649 _webView.reset([webView retain]); |
| 4653 | 4650 |
| 4654 // Set up the new web view. | 4651 // Set up the new web view. |
| 4655 if (webView) { | 4652 if (webView) { |
| 4656 base::WeakNSObject<CRWWebController> weakSelf(self); | 4653 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 4657 void (^messageHandler)(WKScriptMessage*) = ^(WKScriptMessage* message) { | 4654 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { |
| 4658 [weakSelf didReceiveScriptMessage:message]; | 4655 [weakSelf didReceiveScriptMessage:message]; |
| 4659 }; | 4656 } |
| 4660 [messageRouter setScriptMessageHandler:messageHandler | |
| 4661 name:kScriptMessageName | 4657 name:kScriptMessageName |
| 4662 webView:webView]; | 4658 webView:webView]; |
| 4663 [messageRouter setScriptMessageHandler:messageHandler | |
| 4664 name:kScriptImmediateName | |
| 4665 webView:webView]; | |
| 4666 _windowIDJSManager.reset( | 4659 _windowIDJSManager.reset( |
| 4667 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); | 4660 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); |
| 4668 } else { | 4661 } else { |
| 4669 _windowIDJSManager.reset(); | 4662 _windowIDJSManager.reset(); |
| 4670 } | 4663 } |
| 4671 [_webView setNavigationDelegate:self]; | 4664 [_webView setNavigationDelegate:self]; |
| 4672 [_webView setUIDelegate:self]; | 4665 [_webView setUIDelegate:self]; |
| 4673 for (NSString* keyPath in self.WKWebViewObservers) { | 4666 for (NSString* keyPath in self.WKWebViewObservers) { |
| 4674 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; | 4667 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; |
| 4675 } | 4668 } |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5614 } | 5607 } |
| 5615 | 5608 |
| 5616 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5609 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 5617 } | 5610 } |
| 5618 | 5611 |
| 5619 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5612 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5620 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5613 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5621 } | 5614 } |
| 5622 | 5615 |
| 5623 @end | 5616 @end |
| OLD | NEW |