| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_wk_web_view_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #include "base/ios/weak_nsobject.h" | 9 #include "base/ios/weak_nsobject.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #import "base/mac/scoped_nsobject.h" | 11 #import "base/mac/scoped_nsobject.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #import "ios/web/crw_network_activity_indicator_manager.h" | 15 #import "ios/web/crw_network_activity_indicator_manager.h" |
| 16 #import "ios/web/navigation/crw_session_controller.h" | 16 #import "ios/web/navigation/crw_session_controller.h" |
| 17 #include "ios/web/navigation/web_load_params.h" |
| 17 #include "ios/web/public/web_client.h" | 18 #include "ios/web/public/web_client.h" |
| 19 #import "ios/web/public/web_state/crw_native_content_provider.h" |
| 18 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" | 20 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" |
| 19 #import "ios/web/ui_web_view_util.h" | 21 #import "ios/web/ui_web_view_util.h" |
| 20 #include "ios/web/web_state/blocked_popup_info.h" | 22 #include "ios/web/web_state/blocked_popup_info.h" |
| 21 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 23 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
| 22 #import "ios/web/web_state/js/page_script_util.h" | 24 #import "ios/web/web_state/js/page_script_util.h" |
| 23 #import "ios/web/web_state/ui/crw_web_controller+protected.h" | 25 #import "ios/web/web_state/ui/crw_web_controller+protected.h" |
| 24 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" | 26 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" |
| 25 #import "ios/web/web_state/ui/web_view_js_utils.h" | 27 #import "ios/web/web_state/ui/web_view_js_utils.h" |
| 26 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" | 28 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
| 27 #import "ios/web/web_state/web_state_impl.h" | 29 #import "ios/web/web_state/web_state_impl.h" |
| 28 #import "ios/web/web_state/web_view_creation_utils.h" | 30 #import "ios/web/web_state/web_view_creation_utils.h" |
| 31 #import "ios/web/webui/crw_web_ui_manager.h" |
| 29 #import "net/base/mac/url_conversions.h" | 32 #import "net/base/mac/url_conversions.h" |
| 30 | 33 |
| 31 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 34 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
| 32 #include "ios/web/public/cert_store.h" | 35 #include "ios/web/public/cert_store.h" |
| 33 #include "ios/web/public/navigation_item.h" | 36 #include "ios/web/public/navigation_item.h" |
| 34 #include "ios/web/public/ssl_status.h" | 37 #include "ios/web/public/ssl_status.h" |
| 35 #import "ios/web/web_state/wk_web_view_ssl_error_util.h" | 38 #import "ios/web/web_state/wk_web_view_ssl_error_util.h" |
| 36 #include "net/ssl/ssl_info.h" | 39 #include "net/ssl/ssl_info.h" |
| 37 #endif | 40 #endif |
| 38 | 41 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 base::scoped_nsobject<NSString> _currentReferrerString; | 85 base::scoped_nsobject<NSString> _currentReferrerString; |
| 83 | 86 |
| 84 // Backs the property of the same name. | 87 // Backs the property of the same name. |
| 85 base::scoped_nsobject<NSString> _documentMIMEType; | 88 base::scoped_nsobject<NSString> _documentMIMEType; |
| 86 | 89 |
| 87 // Whether the web page is currently performing window.history.pushState or | 90 // Whether the web page is currently performing window.history.pushState or |
| 88 // window.history.replaceState | 91 // window.history.replaceState |
| 89 // Set to YES on window.history.willChangeState message. To NO on | 92 // Set to YES on window.history.willChangeState message. To NO on |
| 90 // window.history.didPushState or window.history.didReplaceState. | 93 // window.history.didPushState or window.history.didReplaceState. |
| 91 BOOL _changingHistoryState; | 94 BOOL _changingHistoryState; |
| 95 |
| 96 // CRWWebUIManager object for loading WebUI pages. |
| 97 base::scoped_nsobject<CRWWebUIManager> web_ui_manager_; |
| 92 } | 98 } |
| 93 | 99 |
| 94 // Response's MIME type of the last known navigation. | 100 // Response's MIME type of the last known navigation. |
| 95 @property(nonatomic, copy) NSString* documentMIMEType; | 101 @property(nonatomic, copy) NSString* documentMIMEType; |
| 96 | 102 |
| 97 // Dictionary where keys are the names of WKWebView properties and values are | 103 // Dictionary where keys are the names of WKWebView properties and values are |
| 98 // selector names which should be called when a corresponding property has | 104 // selector names which should be called when a corresponding property has |
| 99 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 105 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
| 100 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 106 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
| 101 // changed. | 107 // changed. |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 340 |
| 335 if ([self.documentMIMEType isEqualToString:@"text/html"] || | 341 if ([self.documentMIMEType isEqualToString:@"text/html"] || |
| 336 [self.documentMIMEType isEqualToString:@"application/xhtml+xml"] || | 342 [self.documentMIMEType isEqualToString:@"application/xhtml+xml"] || |
| 337 [self.documentMIMEType isEqualToString:@"application/xml"]) { | 343 [self.documentMIMEType isEqualToString:@"application/xml"]) { |
| 338 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; | 344 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; |
| 339 } | 345 } |
| 340 | 346 |
| 341 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 347 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 342 } | 348 } |
| 343 | 349 |
| 344 - (void)loadWebRequest:(NSURLRequest*)request { | 350 - (void)loadRequest:(NSMutableURLRequest*)request { |
| 345 [_wkWebView loadRequest:request]; | 351 [_wkWebView loadRequest:request]; |
| 346 } | 352 } |
| 347 | 353 |
| 348 - (void)loadWebHTMLString:(NSString*)html forURL:(const GURL&)URL { | 354 - (void)loadWebHTMLString:(NSString*)html forURL:(const GURL&)URL { |
| 349 [_wkWebView loadHTMLString:html baseURL:net::NSURLWithGURL(URL)]; | 355 [_wkWebView loadHTMLString:html baseURL:net::NSURLWithGURL(URL)]; |
| 350 } | 356 } |
| 351 | 357 |
| 352 - (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass | 358 - (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass |
| 353 presenceBeacon:(NSString*)beacon { | 359 presenceBeacon:(NSString*)beacon { |
| 354 return [_injectedScriptManagers containsObject:jsInjectionManagerClass]; | 360 return [_injectedScriptManagers containsObject:jsInjectionManagerClass]; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 - (BOOL)handleWindowHistoryDidReplaceStateMessage: | 792 - (BOOL)handleWindowHistoryDidReplaceStateMessage: |
| 787 (base::DictionaryValue*)message | 793 (base::DictionaryValue*)message |
| 788 context:(NSDictionary*)context { | 794 context:(NSDictionary*)context { |
| 789 DCHECK(_changingHistoryState); | 795 DCHECK(_changingHistoryState); |
| 790 _changingHistoryState = NO; | 796 _changingHistoryState = NO; |
| 791 return [super handleWindowHistoryDidReplaceStateMessage:message | 797 return [super handleWindowHistoryDidReplaceStateMessage:message |
| 792 context:context]; | 798 context:context]; |
| 793 } | 799 } |
| 794 | 800 |
| 795 #pragma mark - | 801 #pragma mark - |
| 802 #pragma mark WebUI |
| 803 |
| 804 - (void)createWebUIForURL:(const GURL&)URL { |
| 805 [super createWebUIForURL:URL]; |
| 806 web_ui_manager_.reset( |
| 807 [[CRWWebUIManager alloc] initWithWebState:self.webStateImpl]); |
| 808 } |
| 809 |
| 810 - (void)clearWebUI { |
| 811 [super clearWebUI]; |
| 812 web_ui_manager_.reset(); |
| 813 } |
| 814 |
| 815 #pragma mark - |
| 796 #pragma mark KVO Observation | 816 #pragma mark KVO Observation |
| 797 | 817 |
| 798 - (void)observeValueForKeyPath:(NSString*)keyPath | 818 - (void)observeValueForKeyPath:(NSString*)keyPath |
| 799 ofObject:(id)object | 819 ofObject:(id)object |
| 800 change:(NSDictionary*)change | 820 change:(NSDictionary*)change |
| 801 context:(void*)context { | 821 context:(void*)context { |
| 802 NSString* dispatcherSelectorName = self.wkWebViewObservers[keyPath]; | 822 NSString* dispatcherSelectorName = self.wkWebViewObservers[keyPath]; |
| 803 DCHECK(dispatcherSelectorName); | 823 DCHECK(dispatcherSelectorName); |
| 804 if (dispatcherSelectorName) | 824 if (dispatcherSelectorName) |
| 805 [self performSelector:NSSelectorFromString(dispatcherSelectorName)]; | 825 [self performSelector:NSSelectorFromString(dispatcherSelectorName)]; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 } | 952 } |
| 933 | 953 |
| 934 // TODO(stuartmorgan): Move all the guesswork around these states out of the | 954 // TODO(stuartmorgan): Move all the guesswork around these states out of the |
| 935 // superclass, and wire these up to the remaining methods. | 955 // superclass, and wire these up to the remaining methods. |
| 936 - (void)webView:(WKWebView *)webView | 956 - (void)webView:(WKWebView *)webView |
| 937 didStartProvisionalNavigation:(WKNavigation *)navigation { | 957 didStartProvisionalNavigation:(WKNavigation *)navigation { |
| 938 GURL webViewURL = net::GURLWithNSURL(webView.URL); | 958 GURL webViewURL = net::GURLWithNSURL(webView.URL); |
| 939 // If this navigation has not yet been registered, do so. loadPhase check is | 959 // If this navigation has not yet been registered, do so. loadPhase check is |
| 940 // necessary because lastRegisteredRequestURL may be the same as the | 960 // necessary because lastRegisteredRequestURL may be the same as the |
| 941 // webViewURL on a new tab created by window.open (default is about::blank). | 961 // webViewURL on a new tab created by window.open (default is about::blank). |
| 962 // TODO(jyquinn): Audit [CRWWebController loadCurrentURL] for other tasks that |
| 963 // should be performed here. |
| 942 if (self.lastRegisteredRequestURL != webViewURL || | 964 if (self.lastRegisteredRequestURL != webViewURL || |
| 943 self.loadPhase != web::LOAD_REQUESTED) { | 965 self.loadPhase != web::LOAD_REQUESTED) { |
| 944 [self registerLoadRequest:webViewURL]; | 966 // Reset current WebUI if one exists. |
| 967 [self clearWebUI]; |
| 968 // If webViewURL is a chrome URL, abort the current load and initialize the |
| 969 // load from the web controller. |
| 970 if (web::GetWebClient()->IsAppSpecificURL(webViewURL)) { |
| 971 [self abortWebLoad]; |
| 972 web::WebLoadParams params(webViewURL); |
| 973 [self loadWithParams:params]; |
| 974 return; |
| 975 } else { |
| 976 [self registerLoadRequest:webViewURL]; |
| 977 } |
| 945 } | 978 } |
| 946 // Ensure the URL is registered and loadPhase is as expected. | 979 // Ensure the URL is registered and loadPhase is as expected. |
| 947 DCHECK(self.lastRegisteredRequestURL == webViewURL); | 980 DCHECK(self.lastRegisteredRequestURL == webViewURL); |
| 948 DCHECK(self.loadPhase == web::LOAD_REQUESTED); | 981 DCHECK(self.loadPhase == web::LOAD_REQUESTED); |
| 949 } | 982 } |
| 950 | 983 |
| 951 - (void)webView:(WKWebView *)webView | 984 - (void)webView:(WKWebView *)webView |
| 952 didReceiveServerRedirectForProvisionalNavigation: | 985 didReceiveServerRedirectForProvisionalNavigation: |
| 953 (WKNavigation *)navigation { | 986 (WKNavigation *)navigation { |
| 954 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) | 987 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 placeholderText:defaultText | 1134 placeholderText:defaultText |
| 1102 requestURL: | 1135 requestURL: |
| 1103 net::GURLWithNSURL(frame.request.URL) | 1136 net::GURLWithNSURL(frame.request.URL) |
| 1104 completionHandler:completionHandler]; | 1137 completionHandler:completionHandler]; |
| 1105 } else if (completionHandler) { | 1138 } else if (completionHandler) { |
| 1106 completionHandler(nil); | 1139 completionHandler(nil); |
| 1107 } | 1140 } |
| 1108 } | 1141 } |
| 1109 | 1142 |
| 1110 @end | 1143 @end |
| OLD | NEW |