Chromium Code Reviews| 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/containers/mru_cache.h" | 9 #include "base/containers/mru_cache.h" |
| 10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| 11 #include "base/ios/weak_nsobject.h" | 11 #include "base/ios/weak_nsobject.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/mac/objc_property_releaser.h" | 13 #import "base/mac/objc_property_releaser.h" |
| 14 #import "base/mac/scoped_nsobject.h" | 14 #import "base/mac/scoped_nsobject.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #import "ios/net/http_response_headers_util.h" | 19 #import "ios/net/http_response_headers_util.h" |
| 20 #import "ios/web/crw_network_activity_indicator_manager.h" | 20 #import "ios/web/crw_network_activity_indicator_manager.h" |
| 21 #import "ios/web/navigation/crw_session_controller.h" | 21 #import "ios/web/navigation/crw_session_controller.h" |
| 22 #import "ios/web/navigation/crw_session_entry.h" | 22 #import "ios/web/navigation/crw_session_entry.h" |
| 23 #include "ios/web/navigation/navigation_item_impl.h" | 23 #include "ios/web/navigation/navigation_item_impl.h" |
| 24 #include "ios/web/navigation/web_load_params.h" | 24 #include "ios/web/navigation/web_load_params.h" |
| 25 #include "ios/web/net/cert_host_pair.h" | 25 #include "ios/web/net/cert_host_pair.h" |
| 26 #import "ios/web/net/crw_cert_verification_controller.h" | 26 #import "ios/web/net/crw_cert_verification_controller.h" |
| 27 #include "ios/web/public/browser_state.h" | 27 #include "ios/web/public/browser_state.h" |
| 28 #include "ios/web/public/cert_store.h" | 28 #include "ios/web/public/cert_store.h" |
| 29 #include "ios/web/public/navigation_item.h" | 29 #include "ios/web/public/navigation_item.h" |
| 30 #include "ios/web/public/ssl_status.h" | 30 #include "ios/web/public/ssl_status.h" |
| 31 #include "ios/web/public/url_util.h" | 31 #include "ios/web/public/url_util.h" |
| 32 #include "ios/web/public/web_client.h" | 32 #include "ios/web/public/web_client.h" |
| 33 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" | 33 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" |
| 34 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" | 34 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" |
| 35 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" | 35 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" |
| 36 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 36 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
| 37 #import "ios/web/ui_web_view_util.h" | 37 #import "ios/web/ui_web_view_util.h" |
| 38 #include "ios/web/web_state/blocked_popup_info.h" | 38 #include "ios/web/web_state/blocked_popup_info.h" |
| 39 #import "ios/web/web_state/crw_pass_kit_downloader.h" | 39 #import "ios/web/web_state/crw_pass_kit_downloader.h" |
| 40 #import "ios/web/web_state/error_translation_util.h" | 40 #import "ios/web/web_state/error_translation_util.h" |
| 41 #include "ios/web/web_state/frame_info.h" | 41 #include "ios/web/web_state/frame_info.h" |
| 42 #import "ios/web/web_state/js/crw_js_post_request_loader.h" | |
| 42 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 43 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
| 43 #import "ios/web/web_state/ui/crw_web_controller+protected.h" | 44 #import "ios/web/web_state/ui/crw_web_controller+protected.h" |
| 44 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" | 45 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" |
| 45 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" | 46 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" |
| 46 #import "ios/web/web_state/ui/web_view_js_utils.h" | 47 #import "ios/web/web_state/ui/web_view_js_utils.h" |
| 47 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" | 48 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" |
| 48 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" | 49 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
| 49 #import "ios/web/web_state/web_state_impl.h" | 50 #import "ios/web/web_state/web_state_impl.h" |
| 50 #import "ios/web/web_state/web_view_internal_creation_util.h" | 51 #import "ios/web/web_state/web_view_internal_creation_util.h" |
| 51 #import "ios/web/web_state/wk_web_view_security_util.h" | 52 #import "ios/web/web_state/wk_web_view_security_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 self, [CRWWebControllerPendingNavigationInfo class]); | 146 self, [CRWWebControllerPendingNavigationInfo class]); |
| 146 _navigationType = WKNavigationTypeOther; | 147 _navigationType = WKNavigationTypeOther; |
| 147 } | 148 } |
| 148 return self; | 149 return self; |
| 149 } | 150 } |
| 150 @end | 151 @end |
| 151 | 152 |
| 152 #pragma mark - | 153 #pragma mark - |
| 153 | 154 |
| 154 @interface CRWWKWebViewWebController ()<WKNavigationDelegate, WKUIDelegate> { | 155 @interface CRWWKWebViewWebController ()<WKNavigationDelegate, WKUIDelegate> { |
| 156 base::mac::ObjCPropertyReleaser _propertyReleaser_CRWWKWebViewWebController; | |
|
Eugene But (OOO till 7-30)
2015/12/02 17:06:16
Please don't use property releaser here. All memor
stkhapugin
2015/12/03 15:43:02
Done.
| |
| 157 | |
| 155 // The WKWebView managed by this instance. | 158 // The WKWebView managed by this instance. |
| 156 base::scoped_nsobject<WKWebView> _wkWebView; | 159 base::scoped_nsobject<WKWebView> _wkWebView; |
| 157 | 160 |
| 158 // The Watch Dog that detects and reports WKWebView crashes. | 161 // The Watch Dog that detects and reports WKWebView crashes. |
| 159 base::scoped_nsobject<CRWWKWebViewCrashDetector> _crashDetector; | 162 base::scoped_nsobject<CRWWKWebViewCrashDetector> _crashDetector; |
| 160 | 163 |
| 161 // The actual URL of the document object (i.e., the last committed URL). | 164 // The actual URL of the document object (i.e., the last committed URL). |
| 162 // TODO(crbug.com/549616): Remove this in favor of just updating the | 165 // TODO(crbug.com/549616): Remove this in favor of just updating the |
| 163 // navigation manager and treating that as authoritative. For now, this allows | 166 // navigation manager and treating that as authoritative. For now, this allows |
| 164 // sharing the flow that's currently in the superclass. | 167 // sharing the flow that's currently in the superclass. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 scoped_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; | 213 scoped_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; |
| 211 | 214 |
| 212 // YES if the user has interacted with the content area since the last URL | 215 // YES if the user has interacted with the content area since the last URL |
| 213 // change. | 216 // change. |
| 214 BOOL _interactionRegisteredSinceLastURLChange; | 217 BOOL _interactionRegisteredSinceLastURLChange; |
| 215 | 218 |
| 216 // YES if the web process backing _wkWebView is believed to currently be dead. | 219 // YES if the web process backing _wkWebView is believed to currently be dead. |
| 217 BOOL _webProcessIsDead; | 220 BOOL _webProcessIsDead; |
| 218 } | 221 } |
| 219 | 222 |
| 223 // Object for loading POST requests with body. | |
| 224 @property(nonatomic, retain) CRWJSPOSTRequestLoader* POSTRequestLoader; | |
| 225 | |
| 220 // Dictionary where keys are the names of WKWebView properties and values are | 226 // Dictionary where keys are the names of WKWebView properties and values are |
| 221 // selector names which should be called when a corresponding property has | 227 // selector names which should be called when a corresponding property has |
| 222 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 228 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
| 223 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 229 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
| 224 // changed. | 230 // changed. |
| 225 @property(nonatomic, readonly) NSDictionary* wkWebViewObservers; | 231 @property(nonatomic, readonly) NSDictionary* wkWebViewObservers; |
| 226 | 232 |
| 227 // Activity indicator group ID for this web controller. | 233 // Activity indicator group ID for this web controller. |
| 228 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; | 234 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; |
| 229 | 235 |
| 230 // Identifier used for storing and retrieving certificates. | 236 // Identifier used for storing and retrieving certificates. |
| 231 @property(nonatomic, readonly) int certGroupID; | 237 @property(nonatomic, readonly) int certGroupID; |
| 232 | 238 |
| 233 // Downloader for PassKit files. Lazy initialized. | 239 // Downloader for PassKit files. Lazy initialized. |
| 234 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; | 240 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; |
| 235 | 241 |
| 242 // Loads POST request with body in |_wkWebView| by constructing an HTML page | |
| 243 // that executes the request through javascript and replaces document with the | |
| 244 // result. | |
| 245 // Note that this approach includes multiple body encodings and decodings, plus | |
| 246 // the data is passed to |_wkWebView| on main thread, hence the performance is | |
| 247 // expected to be low. | |
| 248 // This is necessary because WKWebView ignores POST request body. | |
| 249 // Workaround for https://bugs.webkit.org/show_bug.cgi?id=145410 | |
| 250 - (void)loadPOSTRequestWithBody:(NSMutableURLRequest*)request; | |
|
Eugene But (OOO till 7-30)
2015/12/02 17:06:16
Word before argument should describe argument. How
stkhapugin
2015/12/03 15:43:02
Done.
| |
| 251 | |
| 236 // Returns the WKWebViewConfigurationProvider associated with the web | 252 // Returns the WKWebViewConfigurationProvider associated with the web |
| 237 // controller's BrowserState. | 253 // controller's BrowserState. |
| 238 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; | 254 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; |
| 239 | 255 |
| 240 // Creates a web view with given |config|. No-op if web view is already created. | 256 // Creates a web view with given |config|. No-op if web view is already created. |
| 241 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; | 257 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; |
| 242 | 258 |
| 243 // Returns a new autoreleased web view created with given configuration. | 259 // Returns a new autoreleased web view created with given configuration. |
| 244 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config; | 260 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config; |
| 245 | 261 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 | 388 |
| 373 // Called when WKWebView title has been changed. | 389 // Called when WKWebView title has been changed. |
| 374 - (void)webViewTitleDidChange; | 390 - (void)webViewTitleDidChange; |
| 375 | 391 |
| 376 // Called when WKWebView URL has been changed. | 392 // Called when WKWebView URL has been changed. |
| 377 - (void)webViewURLDidChange; | 393 - (void)webViewURLDidChange; |
| 378 | 394 |
| 379 @end | 395 @end |
| 380 | 396 |
| 381 @implementation CRWWKWebViewWebController | 397 @implementation CRWWKWebViewWebController |
| 398 @synthesize POSTRequestLoader = _POSTRequestLoader; | |
| 382 | 399 |
| 383 #pragma mark CRWWebController public methods | 400 #pragma mark CRWWebController public methods |
| 384 | 401 |
| 385 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { | 402 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { |
| 386 DCHECK(webState); | 403 DCHECK(webState); |
| 387 web::BrowserState* browserState = webState->GetBrowserState(); | 404 web::BrowserState* browserState = webState->GetBrowserState(); |
| 388 self = [super initWithWebState:webState.Pass()]; | 405 self = [super initWithWebState:webState.Pass()]; |
| 389 if (self) { | 406 if (self) { |
| 407 _propertyReleaser_CRWWKWebViewWebController.Init( | |
| 408 self, [CRWWKWebViewWebController class]); | |
| 390 _certVerificationController.reset([[CRWCertVerificationController alloc] | 409 _certVerificationController.reset([[CRWCertVerificationController alloc] |
| 391 initWithBrowserState:browserState]); | 410 initWithBrowserState:browserState]); |
| 392 _certVerificationErrors.reset( | 411 _certVerificationErrors.reset( |
| 393 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); | 412 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); |
| 394 } | 413 } |
| 395 return self; | 414 return self; |
| 396 } | 415 } |
| 397 | 416 |
| 398 - (BOOL)keyboardDisplayRequiresUserAction { | 417 - (BOOL)keyboardDisplayRequiresUserAction { |
| 399 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment | 418 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 [_injectedScriptManagers addObject:JSInjectionManagerClass]; | 569 [_injectedScriptManagers addObject:JSInjectionManagerClass]; |
| 551 } | 570 } |
| 552 | 571 |
| 553 - (void)willLoadCurrentURLInWebView { | 572 - (void)willLoadCurrentURLInWebView { |
| 554 // TODO(stuartmorgan): Get a WKWebView version of the request ID verification | 573 // TODO(stuartmorgan): Get a WKWebView version of the request ID verification |
| 555 // code working for debug builds. | 574 // code working for debug builds. |
| 556 } | 575 } |
| 557 | 576 |
| 558 - (void)loadRequestForCurrentNavigationItem { | 577 - (void)loadRequestForCurrentNavigationItem { |
| 559 DCHECK(self.webView && !self.nativeController); | 578 DCHECK(self.webView && !self.nativeController); |
| 579 DCHECK([self currentSessionEntry]); | |
| 580 | |
| 581 web::WKBackForwardListItemHolder* holder = | |
| 582 [self currentBackForwardListItemHolder]; | |
| 583 BOOL isFormResubmission = | |
| 584 (holder->navigation_type() == WKNavigationTypeFormResubmitted || | |
| 585 holder->navigation_type() == WKNavigationTypeFormSubmitted); | |
| 586 web::NavigationItemImpl* currentItem = | |
| 587 [self currentSessionEntry].navigationItemImpl; | |
| 588 NSData* POSTData = currentItem->GetPostData(); | |
| 589 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; | |
| 560 | 590 |
| 561 ProceduralBlock defaultNavigationBlock = ^{ | 591 ProceduralBlock defaultNavigationBlock = ^{ |
| 562 [self registerLoadRequest:[self currentNavigationURL] | 592 [self registerLoadRequest:[self currentNavigationURL] |
| 563 referrer:[self currentSessionEntryReferrer] | 593 referrer:[self currentSessionEntryReferrer] |
| 564 transition:[self currentTransition]]; | 594 transition:[self currentTransition]]; |
| 565 [self loadRequest:[self requestForCurrentNavigationItem]]; | 595 [self loadRequest:request]; |
| 566 }; | 596 }; |
| 567 | 597 |
| 568 // If there is no corresponding WKBackForwardListItem, or the item is not in | 598 ProceduralBlock POSTBlock = ^{ |
| 569 // the current WKWebView's back-forward list, navigating using WKWebView API | 599 [request setHTTPMethod:@"POST"]; |
| 570 // is not possible. In this case, fall back to the default navigation | 600 [request setHTTPBody:POSTData]; |
| 571 // mechanism. | 601 [request setAllHTTPHeaderFields:[self currentHTTPHeaders]]; |
| 572 web::WKBackForwardListItemHolder* holder = | 602 [self registerLoadRequest:[self currentNavigationURL] |
| 573 [self currentBackForwardListItemHolder]; | 603 referrer:[self currentSessionEntryReferrer] |
| 574 if (!holder->back_forward_list_item() || | 604 transition:[self currentTransition]]; |
| 575 ![self isBackForwardListItemValid:holder->back_forward_list_item()]) { | 605 [self loadPOSTRequestWithBody:request]; |
| 576 defaultNavigationBlock(); | 606 }; |
| 577 return; | |
| 578 } | |
| 579 | 607 |
| 580 ProceduralBlock webViewNavigationBlock = ^{ | 608 ProceduralBlock webViewNavigationBlock = ^{ |
| 581 // If the current navigation URL is the same as the URL of the visible | 609 // If the current navigation URL is the same as the URL of the visible |
| 582 // page, that means the user requested a reload. |goToBackForwardListItem| | 610 // page, that means the user requested a reload. |goToBackForwardListItem| |
| 583 // will be a no-op when it is passed the current back forward list item, | 611 // will be a no-op when it is passed the current back forward list item, |
| 584 // so |reload| must be explicitly called. | 612 // so |reload| must be explicitly called. |
| 585 [self registerLoadRequest:[self currentNavigationURL] | 613 [self registerLoadRequest:[self currentNavigationURL] |
| 586 referrer:[self currentSessionEntryReferrer] | 614 referrer:[self currentSessionEntryReferrer] |
| 587 transition:[self currentTransition]]; | 615 transition:[self currentTransition]]; |
| 588 if ([self currentNavigationURL] == net::GURLWithNSURL([_wkWebView URL])) { | 616 if ([self currentNavigationURL] == net::GURLWithNSURL([_wkWebView URL])) { |
| 589 [_wkWebView reload]; | 617 [_wkWebView reload]; |
| 590 } else { | 618 } else { |
| 591 [_wkWebView goToBackForwardListItem:holder->back_forward_list_item()]; | 619 [_wkWebView goToBackForwardListItem:holder->back_forward_list_item()]; |
| 592 } | 620 } |
| 593 }; | 621 }; |
| 594 | 622 |
| 623 // If the request has POST data and is not a form resubmission, configure and | |
| 624 // run the POST request. | |
| 625 if (POSTData.length && !isFormResubmission) { | |
| 626 POSTBlock(); | |
| 627 return; | |
| 628 } | |
| 629 | |
| 630 // If there is no corresponding WKBackForwardListItem, or the item is not in | |
| 631 // the current WKWebView's back-forward list, navigating using WKWebView API | |
| 632 // is not possible. In this case, fall back to the default navigation | |
| 633 // mechanism. | |
| 634 if (!holder->back_forward_list_item() || | |
| 635 ![self isBackForwardListItemValid:holder->back_forward_list_item()]) { | |
| 636 defaultNavigationBlock(); | |
| 637 return; | |
| 638 } | |
| 639 | |
| 595 // If the request is not a form submission or resubmission, or the user | 640 // If the request is not a form submission or resubmission, or the user |
| 596 // doesn't need to confirm the load, then continue right away. | 641 // doesn't need to confirm the load, then continue right away. |
| 597 web::NavigationItemImpl* currentItem = | 642 if (!isFormResubmission || |
| 598 [self currentSessionEntry].navigationItemImpl; | |
| 599 if ((holder->navigation_type() != WKNavigationTypeFormResubmitted && | |
| 600 holder->navigation_type() != WKNavigationTypeFormSubmitted) || | |
| 601 currentItem->ShouldSkipResubmitDataConfirmation()) { | 643 currentItem->ShouldSkipResubmitDataConfirmation()) { |
| 602 webViewNavigationBlock(); | 644 webViewNavigationBlock(); |
| 603 return; | 645 return; |
| 604 } | 646 } |
| 605 | 647 |
| 606 // If the request is form submission or resubmission, then prompt the | 648 // If the request is form submission or resubmission, then prompt the |
| 607 // user before proceeding. | 649 // user before proceeding. |
| 650 DCHECK(isFormResubmission); | |
| 608 [self.delegate webController:self | 651 [self.delegate webController:self |
| 609 onFormResubmissionForRequest:nil | 652 onFormResubmissionForRequest:nil |
| 610 continueBlock:webViewNavigationBlock | 653 continueBlock:webViewNavigationBlock |
| 611 cancelBlock:defaultNavigationBlock]; | 654 cancelBlock:defaultNavigationBlock]; |
| 612 } | 655 } |
| 613 | 656 |
| 614 // Overrides the hashchange workaround in the super class that manually | 657 // Overrides the hashchange workaround in the super class that manually |
| 615 // triggers Javascript hashchange events. If navigating with native API, | 658 // triggers Javascript hashchange events. If navigating with native API, |
| 616 // i.e. using a back forward list item, hashchange events will be triggered | 659 // i.e. using a back forward list item, hashchange events will be triggered |
| 617 // automatically, so no URL tampering is required. | 660 // automatically, so no URL tampering is required. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 @"WKWebViewWebController.NetworkActivityIndicatorKey.%@", | 751 @"WKWebViewWebController.NetworkActivityIndicatorKey.%@", |
| 709 self.webStateImpl->GetRequestGroupID()]; | 752 self.webStateImpl->GetRequestGroupID()]; |
| 710 } | 753 } |
| 711 | 754 |
| 712 - (int)certGroupID { | 755 - (int)certGroupID { |
| 713 DCHECK(self.webStateImpl); | 756 DCHECK(self.webStateImpl); |
| 714 // Request tracker IDs are used as certificate groups. | 757 // Request tracker IDs are used as certificate groups. |
| 715 return self.webStateImpl->GetRequestTracker()->identifier(); | 758 return self.webStateImpl->GetRequestTracker()->identifier(); |
| 716 } | 759 } |
| 717 | 760 |
| 761 - (void)loadPOSTRequestWithBody:(NSMutableURLRequest*)request { | |
| 762 if (!self.POSTRequestLoader) { | |
|
Eugene But (OOO till 7-30)
2015/12/02 17:06:16
s/self.POSTRequestLoader/_POSTRequestLoader
stkhapugin
2015/12/03 15:43:02
Done.
| |
| 763 _POSTRequestLoader = [[CRWJSPOSTRequestLoader alloc] init]; | |
| 764 } | |
| 765 | |
| 766 CRWWKScriptMessageRouter* messageRouter = | |
| 767 [self webViewConfigurationProvider].GetScriptMessageRouter(); | |
| 768 | |
| 769 [self.POSTRequestLoader loadPOSTRequest:request | |
| 770 inWebView:_wkWebView | |
|
Eugene But (OOO till 7-30)
2015/12/02 17:06:16
This is not correct formatting. Di you run git cl
stkhapugin
2015/12/03 15:43:02
Done. git cl format doesn't format some things for
| |
| 771 messageRouter:messageRouter | |
| 772 errorBlock:^(NSError* loadError) { | |
| 773 [self handleLoadError:loadError inMainFrame:YES]; | |
| 774 } | |
| 775 successBlock:^{ | |
| 776 self.webStateImpl->SetContentsMimeType("text/html"); | |
| 777 }]; | |
| 778 } | |
| 779 | |
| 718 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { | 780 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { |
| 719 DCHECK(self.webStateImpl); | 781 DCHECK(self.webStateImpl); |
| 720 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); | 782 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); |
| 721 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); | 783 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); |
| 722 } | 784 } |
| 723 | 785 |
| 724 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { | 786 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { |
| 725 if (!_wkWebView) { | 787 if (!_wkWebView) { |
| 726 [self setWebView:[self createWebViewWithConfiguration:config]]; | 788 [self setWebView:[self createWebViewWithConfiguration:config]]; |
| 727 // Notify super class about created web view. -webViewDidChange is not | 789 // Notify super class about created web view. -webViewDidChange is not |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 | 905 |
| 844 - (void)updateCurrentBackForwardListItemHolder { | 906 - (void)updateCurrentBackForwardListItemHolder { |
| 845 // WebUI pages (which are loaded via loadHTMLString:baseURL:) have no entry | 907 // WebUI pages (which are loaded via loadHTMLString:baseURL:) have no entry |
| 846 // in the back/forward list, so the current item will still be the previous | 908 // in the back/forward list, so the current item will still be the previous |
| 847 // page, and should not be associated. | 909 // page, and should not be associated. |
| 848 if (_webUIManager) | 910 if (_webUIManager) |
| 849 return; | 911 return; |
| 850 | 912 |
| 851 web::WKBackForwardListItemHolder* holder = | 913 web::WKBackForwardListItemHolder* holder = |
| 852 [self currentBackForwardListItemHolder]; | 914 [self currentBackForwardListItemHolder]; |
| 853 | |
| 854 WKNavigationType navigationType = | 915 WKNavigationType navigationType = |
| 855 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] | 916 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] |
| 856 : WKNavigationTypeOther; | 917 : WKNavigationTypeOther; |
| 857 holder->set_back_forward_list_item([_wkWebView backForwardList].currentItem); | 918 holder->set_back_forward_list_item( |
| 858 holder->set_navigation_type(navigationType); | 919 [_wkWebView backForwardList].currentItem); |
| 859 | 920 holder->set_navigation_type(navigationType); |
| 860 // Only update the MIME type in the holder if there was MIME type information | |
| 861 // as part of this pending load. It will be nil when doing a fast | |
| 862 // back/forward navigation, for instance, because the callback that would | |
| 863 // populate it is not called in that flow. | |
| 864 if ([_pendingNavigationInfo MIMEType]) | |
| 865 holder->set_mime_type([_pendingNavigationInfo MIMEType]); | |
| 866 } | 921 } |
| 867 | 922 |
| 868 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { | 923 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { |
| 869 // The current back-forward list item MUST be in the WKWebView's back-forward | 924 // The current back-forward list item MUST be in the WKWebView's back-forward |
| 870 // list to be valid. | 925 // list to be valid. |
| 871 WKBackForwardList* list = [_wkWebView backForwardList]; | 926 WKBackForwardList* list = [_wkWebView backForwardList]; |
| 872 return list.currentItem == item || | 927 return list.currentItem == item || |
| 873 [list.forwardList indexOfObject:item] != NSNotFound || | 928 [list.forwardList indexOfObject:item] != NSNotFound || |
| 874 [list.backList indexOfObject:item] != NSNotFound; | 929 [list.backList indexOfObject:item] != NSNotFound; |
| 875 } | 930 } |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1535 } else if ([self isKVOChangePotentialSameDocumentNavigationToURL:url]) { | 1590 } else if ([self isKVOChangePotentialSameDocumentNavigationToURL:url]) { |
| 1536 [_wkWebView evaluateJavaScript:@"window.location.href" | 1591 [_wkWebView evaluateJavaScript:@"window.location.href" |
| 1537 completionHandler:^(id result, NSError* error) { | 1592 completionHandler:^(id result, NSError* error) { |
| 1538 // If the web view has gone away, or the location | 1593 // If the web view has gone away, or the location |
| 1539 // couldn't be retrieved, abort. | 1594 // couldn't be retrieved, abort. |
| 1540 if (!_wkWebView || | 1595 if (!_wkWebView || |
| 1541 ![result isKindOfClass:[NSString class]]) { | 1596 ![result isKindOfClass:[NSString class]]) { |
| 1542 return; | 1597 return; |
| 1543 } | 1598 } |
| 1544 GURL jsURL([result UTF8String]); | 1599 GURL jsURL([result UTF8String]); |
| 1545 // Make sure that the window location is as expected, | 1600 // Make sure that the URL is as expected, and re-check |
| 1546 // and re-check the origin and web view URL to prevent | 1601 // the origin to prevent race conditions. |
| 1547 // race conditions. | |
| 1548 // TODO(crbug.com/563568): The third check may drop same | |
| 1549 // document URL changes if pending URL change occurs | |
| 1550 // immediately after. Revisit heuristics to prevent this. | |
| 1551 if (jsURL == url && | 1602 if (jsURL == url && |
| 1552 _documentURL.GetOrigin() == url.GetOrigin() && | 1603 _documentURL.GetOrigin() == url.GetOrigin()) { |
| 1553 net::GURLWithNSURL([_wkWebView URL]) == url) { | |
| 1554 [self URLDidChangeWithoutDocumentChange:url]; | 1604 [self URLDidChangeWithoutDocumentChange:url]; |
| 1555 } | 1605 } |
| 1556 }]; | 1606 }]; |
| 1557 } | 1607 } |
| 1558 } | 1608 } |
| 1559 | 1609 |
| 1560 #pragma mark - | 1610 #pragma mark - |
| 1561 #pragma mark WKNavigationDelegate Methods | 1611 #pragma mark WKNavigationDelegate Methods |
| 1562 | 1612 |
| 1563 - (void)webView:(WKWebView *)webView | 1613 - (void)webView:(WKWebView *)webView |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1707 // the list of injected scripts to those that are automatically injected. | 1757 // the list of injected scripts to those that are automatically injected. |
| 1708 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 1758 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 1709 [self injectWindowID]; | 1759 [self injectWindowID]; |
| 1710 | 1760 |
| 1711 // This is the point where the document's URL has actually changed, and | 1761 // This is the point where the document's URL has actually changed, and |
| 1712 // pending navigation information should be applied to state information. | 1762 // pending navigation information should be applied to state information. |
| 1713 [self setDocumentURL:net::GURLWithNSURL([_wkWebView URL])]; | 1763 [self setDocumentURL:net::GURLWithNSURL([_wkWebView URL])]; |
| 1714 DCHECK(_documentURL == self.lastRegisteredRequestURL); | 1764 DCHECK(_documentURL == self.lastRegisteredRequestURL); |
| 1715 self.webStateImpl->OnNavigationCommitted(_documentURL); | 1765 self.webStateImpl->OnNavigationCommitted(_documentURL); |
| 1716 [self commitPendingNavigationInfo]; | 1766 [self commitPendingNavigationInfo]; |
| 1717 if ([self currentBackForwardListItemHolder]->navigation_type() == | |
| 1718 WKNavigationTypeBackForward) { | |
| 1719 // A fast back/forward won't call decidePolicyForNavigationResponse, so | |
| 1720 // the MIME type needs to be updated explicitly. | |
| 1721 NSString* storedMIMEType = | |
| 1722 [self currentBackForwardListItemHolder]->mime_type(); | |
| 1723 if (storedMIMEType) { | |
| 1724 self.webStateImpl->SetContentsMimeType( | |
| 1725 base::SysNSStringToUTF8(storedMIMEType)); | |
| 1726 } | |
| 1727 } | |
| 1728 [self webPageChanged]; | 1767 [self webPageChanged]; |
| 1729 | 1768 |
| 1730 [self updateSSLStatusForCurrentNavigationItem]; | 1769 [self updateSSLStatusForCurrentNavigationItem]; |
| 1731 | 1770 |
| 1732 // Report cases where SSL cert is missing for a secure connection. | 1771 // Report cases where SSL cert is missing for a secure connection. |
| 1733 if (_documentURL.SchemeIsCryptographic()) { | 1772 if (_documentURL.SchemeIsCryptographic()) { |
| 1734 scoped_refptr<net::X509Certificate> cert = | 1773 scoped_refptr<net::X509Certificate> cert = |
| 1735 web::CreateCertFromChain([_wkWebView certificateChain]); | 1774 web::CreateCertFromChain([_wkWebView certificateChain]); |
| 1736 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", | 1775 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", |
| 1737 cert); | 1776 cert); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1877 runJavaScriptTextInputPanelWithPrompt:prompt | 1916 runJavaScriptTextInputPanelWithPrompt:prompt |
| 1878 defaultText:defaultText | 1917 defaultText:defaultText |
| 1879 requestURL:requestURL | 1918 requestURL:requestURL |
| 1880 completionHandler:completionHandler]; | 1919 completionHandler:completionHandler]; |
| 1881 } else if (completionHandler) { | 1920 } else if (completionHandler) { |
| 1882 completionHandler(nil); | 1921 completionHandler(nil); |
| 1883 } | 1922 } |
| 1884 } | 1923 } |
| 1885 | 1924 |
| 1886 @end | 1925 @end |
| OLD | NEW |