| 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> |
| 11 | 11 |
| 12 #include <cmath> | 12 #include <cmath> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/containers/mru_cache.h" | 17 #include "base/containers/mru_cache.h" |
| 18 #include "base/ios/block_types.h" | 18 #include "base/ios/block_types.h" |
| 19 #include "base/ios/ios_util.h" | 19 #include "base/ios/ios_util.h" |
| 20 #import "base/ios/ns_error_util.h" | 20 #import "base/ios/ns_error_util.h" |
| 21 #include "base/ios/weak_nsobject.h" |
| 21 #include "base/json/json_reader.h" | 22 #include "base/json/json_reader.h" |
| 22 #include "base/json/string_escape.h" | 23 #include "base/json/string_escape.h" |
| 23 #include "base/logging.h" | 24 #include "base/logging.h" |
| 24 #include "base/mac/bind_objc_block.h" | 25 #include "base/mac/bind_objc_block.h" |
| 25 #include "base/mac/bundle_locations.h" | 26 #include "base/mac/bundle_locations.h" |
| 26 #include "base/mac/foundation_util.h" | 27 #include "base/mac/foundation_util.h" |
| 28 #include "base/mac/objc_property_releaser.h" |
| 27 #include "base/mac/scoped_cftyperef.h" | 29 #include "base/mac/scoped_cftyperef.h" |
| 28 #include "base/mac/scoped_nsobject.h" | 30 #include "base/mac/scoped_nsobject.h" |
| 29 #include "base/metrics/histogram.h" | 31 #include "base/metrics/histogram.h" |
| 30 #include "base/metrics/user_metrics.h" | 32 #include "base/metrics/user_metrics.h" |
| 31 #include "base/metrics/user_metrics_action.h" | 33 #include "base/metrics/user_metrics_action.h" |
| 32 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
| 33 #include "base/strings/sys_string_conversions.h" | 35 #include "base/strings/sys_string_conversions.h" |
| 34 #include "base/strings/utf_string_conversions.h" | 36 #include "base/strings/utf_string_conversions.h" |
| 35 #include "base/time/time.h" | 37 #include "base/time/time.h" |
| 36 #include "base/values.h" | 38 #include "base/values.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 #import "ios/web/web_state/wk_web_view_security_util.h" | 100 #import "ios/web/web_state/wk_web_view_security_util.h" |
| 99 #import "ios/web/webui/crw_web_ui_manager.h" | 101 #import "ios/web/webui/crw_web_ui_manager.h" |
| 100 #import "ios/web/webui/mojo_facade.h" | 102 #import "ios/web/webui/mojo_facade.h" |
| 101 #import "net/base/mac/url_conversions.h" | 103 #import "net/base/mac/url_conversions.h" |
| 102 #include "net/base/net_errors.h" | 104 #include "net/base/net_errors.h" |
| 103 #include "services/service_manager/public/cpp/interface_registry.h" | 105 #include "services/service_manager/public/cpp/interface_registry.h" |
| 104 #include "ui/base/page_transition_types.h" | 106 #include "ui/base/page_transition_types.h" |
| 105 #include "url/gurl.h" | 107 #include "url/gurl.h" |
| 106 #include "url/url_constants.h" | 108 #include "url/url_constants.h" |
| 107 | 109 |
| 108 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 109 #error "This file requires ARC support." | |
| 110 #endif | |
| 111 | |
| 112 using base::UserMetricsAction; | 110 using base::UserMetricsAction; |
| 113 using web::NavigationManager; | 111 using web::NavigationManager; |
| 114 using web::NavigationManagerImpl; | 112 using web::NavigationManagerImpl; |
| 115 using web::WebState; | 113 using web::WebState; |
| 116 using web::WebStateImpl; | 114 using web::WebStateImpl; |
| 117 | 115 |
| 118 namespace web { | 116 namespace web { |
| 119 NSString* const kContainerViewID = @"Container View"; | 117 NSString* const kContainerViewID = @"Container View"; |
| 120 const char* kWindowNameSeparator = "#"; | 118 const char* kWindowNameSeparator = "#"; |
| 121 NSString* const kUserIsInteractingKey = @"userIsInteracting"; | 119 NSString* const kUserIsInteractingKey = @"userIsInteracting"; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return | 244 return |
| 247 [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; | 245 [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; |
| 248 } | 246 } |
| 249 } // namespace | 247 } // namespace |
| 250 | 248 |
| 251 #pragma mark - | 249 #pragma mark - |
| 252 | 250 |
| 253 // A container object for any navigation information that is only available | 251 // A container object for any navigation information that is only available |
| 254 // during pre-commit delegate callbacks, and thus must be held until the | 252 // during pre-commit delegate callbacks, and thus must be held until the |
| 255 // navigation commits and the informatino can be used. | 253 // navigation commits and the informatino can be used. |
| 256 @interface CRWWebControllerPendingNavigationInfo : NSObject | 254 @interface CRWWebControllerPendingNavigationInfo : NSObject { |
| 255 base::mac::ObjCPropertyReleaser |
| 256 _propertyReleaser_CRWWebControllerPendingNavigationInfo; |
| 257 } |
| 257 // The referrer for the page. | 258 // The referrer for the page. |
| 258 @property(nonatomic, copy) NSString* referrer; | 259 @property(nonatomic, copy) NSString* referrer; |
| 259 // The MIME type for the page. | 260 // The MIME type for the page. |
| 260 @property(nonatomic, copy) NSString* MIMEType; | 261 @property(nonatomic, copy) NSString* MIMEType; |
| 261 // The navigation type for the load. | 262 // The navigation type for the load. |
| 262 @property(nonatomic, assign) WKNavigationType navigationType; | 263 @property(nonatomic, assign) WKNavigationType navigationType; |
| 263 // HTTP request method for the load. | 264 // HTTP request method for the load. |
| 264 @property(nonatomic, copy) NSString* HTTPMethod; | 265 @property(nonatomic, copy) NSString* HTTPMethod; |
| 265 // Whether the pending navigation has been directly cancelled before the | 266 // Whether the pending navigation has been directly cancelled before the |
| 266 // navigation is committed. | 267 // navigation is committed. |
| 267 // Cancelled navigations should be simply discarded without handling any | 268 // Cancelled navigations should be simply discarded without handling any |
| 268 // specific error. | 269 // specific error. |
| 269 @property(nonatomic, assign) BOOL cancelled; | 270 @property(nonatomic, assign) BOOL cancelled; |
| 270 @end | 271 @end |
| 271 | 272 |
| 272 @implementation CRWWebControllerPendingNavigationInfo | 273 @implementation CRWWebControllerPendingNavigationInfo |
| 273 @synthesize referrer = _referrer; | 274 @synthesize referrer = _referrer; |
| 274 @synthesize MIMEType = _MIMEType; | 275 @synthesize MIMEType = _MIMEType; |
| 275 @synthesize navigationType = _navigationType; | 276 @synthesize navigationType = _navigationType; |
| 276 @synthesize HTTPMethod = _HTTPMethod; | 277 @synthesize HTTPMethod = _HTTPMethod; |
| 277 @synthesize cancelled = _cancelled; | 278 @synthesize cancelled = _cancelled; |
| 278 | 279 |
| 279 - (instancetype)init { | 280 - (instancetype)init { |
| 280 if ((self = [super init])) { | 281 if ((self = [super init])) { |
| 282 _propertyReleaser_CRWWebControllerPendingNavigationInfo.Init( |
| 283 self, [CRWWebControllerPendingNavigationInfo class]); |
| 281 _navigationType = WKNavigationTypeOther; | 284 _navigationType = WKNavigationTypeOther; |
| 282 } | 285 } |
| 283 return self; | 286 return self; |
| 284 } | 287 } |
| 285 @end | 288 @end |
| 286 | 289 |
| 287 @interface CRWWebController ()<CRWNativeContentDelegate, | 290 @interface CRWWebController ()<CRWNativeContentDelegate, |
| 288 CRWSSLStatusUpdaterDataSource, | 291 CRWSSLStatusUpdaterDataSource, |
| 289 CRWSSLStatusUpdaterDelegate, | 292 CRWSSLStatusUpdaterDelegate, |
| 290 CRWWebControllerContainerViewDelegate, | 293 CRWWebControllerContainerViewDelegate, |
| 291 CRWWebViewScrollViewProxyObserver, | 294 CRWWebViewScrollViewProxyObserver, |
| 292 WKNavigationDelegate, | 295 WKNavigationDelegate, |
| 293 WKUIDelegate> { | 296 WKUIDelegate> { |
| 297 base::WeakNSProtocol<id<CRWWebDelegate>> _delegate; |
| 298 base::WeakNSProtocol<id<CRWWebUserInterfaceDelegate>> _UIDelegate; |
| 299 base::WeakNSProtocol<id<CRWNativeContentProvider>> _nativeProvider; |
| 300 base::WeakNSProtocol<id<CRWSwipeRecognizerProvider>> _swipeRecognizerProvider; |
| 294 // The WKWebView managed by this instance. | 301 // The WKWebView managed by this instance. |
| 295 base::scoped_nsobject<WKWebView> _webView; | 302 base::scoped_nsobject<WKWebView> _webView; |
| 296 // The CRWWebViewProxy is the wrapper to give components access to the | 303 // The CRWWebViewProxy is the wrapper to give components access to the |
| 297 // web view in a controlled and limited way. | 304 // web view in a controlled and limited way. |
| 298 base::scoped_nsobject<CRWWebViewProxyImpl> _webViewProxy; | 305 base::scoped_nsobject<CRWWebViewProxyImpl> _webViewProxy; |
| 299 // The view used to display content. Must outlive |_webViewProxy|. The | 306 // The view used to display content. Must outlive |_webViewProxy|. The |
| 300 // container view should be accessed through this property rather than | 307 // container view should be accessed through this property rather than |
| 301 // |self.view| from within this class, as |self.view| triggers creation while | 308 // |self.view| from within this class, as |self.view| triggers creation while |
| 302 // |self.containerView| will return nil if the view hasn't been instantiated. | 309 // |self.containerView| will return nil if the view hasn't been instantiated. |
| 303 base::scoped_nsobject<CRWWebControllerContainerView> _containerView; | 310 base::scoped_nsobject<CRWWebControllerContainerView> _containerView; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 // |didFailProvisionalNavigation|. | 449 // |didFailProvisionalNavigation|. |
| 443 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo> | 450 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo> |
| 444 _pendingNavigationInfo; | 451 _pendingNavigationInfo; |
| 445 | 452 |
| 446 // The WKNavigation for the most recent load request. | 453 // The WKNavigation for the most recent load request. |
| 447 base::scoped_nsobject<WKNavigation> _latestWKNavigation; | 454 base::scoped_nsobject<WKNavigation> _latestWKNavigation; |
| 448 | 455 |
| 449 // The WKNavigation captured when |stopLoading| was called. Used for reporting | 456 // The WKNavigation captured when |stopLoading| was called. Used for reporting |
| 450 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which | 457 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which |
| 451 // helps with diagnosing a navigation related crash (crbug.com/565457). | 458 // helps with diagnosing a navigation related crash (crbug.com/565457). |
| 452 __weak WKNavigation* _stoppedWKNavigation; | 459 base::WeakNSObject<WKNavigation> _stoppedWKNavigation; |
| 453 | 460 |
| 454 // CRWWebUIManager object for loading WebUI pages. | 461 // CRWWebUIManager object for loading WebUI pages. |
| 455 base::scoped_nsobject<CRWWebUIManager> _webUIManager; | 462 base::scoped_nsobject<CRWWebUIManager> _webUIManager; |
| 456 | 463 |
| 457 // Updates SSLStatus for current navigation item. | 464 // Updates SSLStatus for current navigation item. |
| 458 base::scoped_nsobject<CRWSSLStatusUpdater> _SSLStatusUpdater; | 465 base::scoped_nsobject<CRWSSLStatusUpdater> _SSLStatusUpdater; |
| 459 | 466 |
| 460 // Controller used for certs verification to help with blocking requests with | 467 // Controller used for certs verification to help with blocking requests with |
| 461 // bad SSL cert, presenting SSL interstitials and determining SSL status for | 468 // bad SSL cert, presenting SSL interstitials and determining SSL status for |
| 462 // Navigation Items. | 469 // Navigation Items. |
| 463 base::scoped_nsobject<CRWCertVerificationController> | 470 base::scoped_nsobject<CRWCertVerificationController> |
| 464 _certVerificationController; | 471 _certVerificationController; |
| 465 | 472 |
| 466 // CertVerification errors which happened inside | 473 // CertVerification errors which happened inside |
| 467 // |webView:didReceiveAuthenticationChallenge:completionHandler:|. | 474 // |webView:didReceiveAuthenticationChallenge:completionHandler:|. |
| 468 // Key is leaf-cert/host pair. This storage is used to carry calculated | 475 // Key is leaf-cert/host pair. This storage is used to carry calculated |
| 469 // cert status from |didReceiveAuthenticationChallenge:| to | 476 // cert status from |didReceiveAuthenticationChallenge:| to |
| 470 // |didFailProvisionalNavigation:| delegate method. | 477 // |didFailProvisionalNavigation:| delegate method. |
| 471 std::unique_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; | 478 std::unique_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; |
| 472 } | 479 } |
| 473 | 480 |
| 474 // If |contentView_| contains a web view, this is the web view it contains. | 481 // If |contentView_| contains a web view, this is the web view it contains. |
| 475 // If not, it's nil. | 482 // If not, it's nil. |
| 476 @property(nonatomic, strong, readonly) WKWebView* webView; | 483 @property(nonatomic, readonly) WKWebView* webView; |
| 477 // The scroll view of |webView|. | 484 // The scroll view of |webView|. |
| 478 @property(nonatomic, strong, readonly) UIScrollView* webScrollView; | 485 @property(nonatomic, readonly) UIScrollView* webScrollView; |
| 479 // The current page state of the web view. Writing to this property | 486 // The current page state of the web view. Writing to this property |
| 480 // asynchronously applies the passed value to the current web view. | 487 // asynchronously applies the passed value to the current web view. |
| 481 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; | 488 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; |
| 482 // The currently displayed native controller, if any. | 489 // The currently displayed native controller, if any. |
| 483 @property(nonatomic, strong) id<CRWNativeContent> nativeController; | 490 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; |
| 484 // Returns NavigationManager's session controller. | 491 // Returns NavigationManager's session controller. |
| 485 @property(nonatomic, strong, readonly) CRWSessionController* sessionController; | 492 @property(nonatomic, readonly) CRWSessionController* sessionController; |
| 486 // Activity indicator group ID for this web controller. | 493 // Activity indicator group ID for this web controller. |
| 487 @property(nonatomic, copy, readonly) NSString* activityIndicatorGroupID; | 494 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; |
| 488 // List of keypaths observed on WKWebView. All KVO-observed keypaths have to | 495 // Dictionary where keys are the names of WKWebView properties and values are |
| 489 // be added to this list. | 496 // selector names which should be called when a corresponding property has |
| 490 @property(nonatomic, strong, readonly) NSArray* observedKeyPaths; | 497 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
| 498 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
| 499 // changed. |
| 500 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers; |
| 491 // Downloader for PassKit files. Lazy initialized. | 501 // Downloader for PassKit files. Lazy initialized. |
| 492 @property(nonatomic, strong, readonly) CRWPassKitDownloader* passKitDownloader; | 502 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; |
| 493 | 503 |
| 494 // The web view's view of the current URL. During page transitions | 504 // The web view's view of the current URL. During page transitions |
| 495 // this may not be the same as the session history's view of the current URL. | 505 // this may not be the same as the session history's view of the current URL. |
| 496 // This method can change the state of the CRWWebController, as it will display | 506 // This method can change the state of the CRWWebController, as it will display |
| 497 // an error if the returned URL is not reliable from a security point of view. | 507 // an error if the returned URL is not reliable from a security point of view. |
| 498 // Note that this method is expensive, so it should always be cached locally if | 508 // Note that this method is expensive, so it should always be cached locally if |
| 499 // it's needed multiple times in a method. | 509 // it's needed multiple times in a method. |
| 500 @property(nonatomic, readonly) GURL currentURL; | 510 @property(nonatomic, readonly) GURL currentURL; |
| 501 // Returns the referrer for the current page. | 511 // Returns the referrer for the current page. |
| 502 @property(nonatomic, readonly) web::Referrer currentReferrer; | 512 @property(nonatomic, readonly) web::Referrer currentReferrer; |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 const NSTimeInterval kSnapshotOverlayTransition = 0.5; | 1021 const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| 1012 | 1022 |
| 1013 } // namespace | 1023 } // namespace |
| 1014 | 1024 |
| 1015 @implementation CRWWebController | 1025 @implementation CRWWebController |
| 1016 | 1026 |
| 1017 @synthesize webUsageEnabled = _webUsageEnabled; | 1027 @synthesize webUsageEnabled = _webUsageEnabled; |
| 1018 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay; | 1028 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay; |
| 1019 @synthesize loadPhase = _loadPhase; | 1029 @synthesize loadPhase = _loadPhase; |
| 1020 @synthesize shouldSuppressDialogs = _shouldSuppressDialogs; | 1030 @synthesize shouldSuppressDialogs = _shouldSuppressDialogs; |
| 1021 @synthesize delegate = _delegate; | |
| 1022 @synthesize UIDelegate = _UIDelegate; | |
| 1023 @synthesize nativeProvider = _nativeProvider; | |
| 1024 @synthesize swipeRecognizerProvider = _swipeRecognizerProvider; | |
| 1025 | 1031 |
| 1026 - (instancetype)initWithWebState:(WebStateImpl*)webState { | 1032 - (instancetype)initWithWebState:(WebStateImpl*)webState { |
| 1027 self = [super init]; | 1033 self = [super init]; |
| 1028 if (self) { | 1034 if (self) { |
| 1029 _webStateImpl = webState; | 1035 _webStateImpl = webState; |
| 1030 DCHECK(_webStateImpl); | 1036 DCHECK(_webStateImpl); |
| 1031 _webStateImpl->InitializeRequestTracker(self); | 1037 _webStateImpl->InitializeRequestTracker(self); |
| 1032 // Load phase when no WebView present is 'loaded' because this represents | 1038 // Load phase when no WebView present is 'loaded' because this represents |
| 1033 // the idle state. | 1039 // the idle state. |
| 1034 _loadPhase = web::PAGE_LOADED; | 1040 _loadPhase = web::PAGE_LOADED; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1049 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); | 1055 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); |
| 1050 [[NSNotificationCenter defaultCenter] | 1056 [[NSNotificationCenter defaultCenter] |
| 1051 addObserver:self | 1057 addObserver:self |
| 1052 selector:@selector(orientationDidChange) | 1058 selector:@selector(orientationDidChange) |
| 1053 name:UIApplicationDidChangeStatusBarOrientationNotification | 1059 name:UIApplicationDidChangeStatusBarOrientationNotification |
| 1054 object:nil]; | 1060 object:nil]; |
| 1055 } | 1061 } |
| 1056 return self; | 1062 return self; |
| 1057 } | 1063 } |
| 1058 | 1064 |
| 1065 - (id<CRWNativeContentProvider>)nativeProvider { |
| 1066 return _nativeProvider.get(); |
| 1067 } |
| 1068 |
| 1069 - (void)setNativeProvider:(id<CRWNativeContentProvider>)nativeProvider { |
| 1070 _nativeProvider.reset(nativeProvider); |
| 1071 } |
| 1072 |
| 1073 - (id<CRWSwipeRecognizerProvider>)swipeRecognizerProvider { |
| 1074 return _swipeRecognizerProvider.get(); |
| 1075 } |
| 1076 |
| 1077 - (void)setSwipeRecognizerProvider: |
| 1078 (id<CRWSwipeRecognizerProvider>)swipeRecognizerProvider { |
| 1079 _swipeRecognizerProvider.reset(swipeRecognizerProvider); |
| 1080 } |
| 1081 |
| 1059 - (WebState*)webState { | 1082 - (WebState*)webState { |
| 1060 return _webStateImpl; | 1083 return _webStateImpl; |
| 1061 } | 1084 } |
| 1062 | 1085 |
| 1063 - (WebStateImpl*)webStateImpl { | 1086 - (WebStateImpl*)webStateImpl { |
| 1064 return _webStateImpl; | 1087 return _webStateImpl; |
| 1065 } | 1088 } |
| 1066 | 1089 |
| 1067 - (void)clearTransientContentView { | 1090 - (void)clearTransientContentView { |
| 1068 // Early return if there is no transient content view. | 1091 // Early return if there is no transient content view. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1079 | 1102 |
| 1080 - (void)showTransientContentView:(CRWContentView*)contentView { | 1103 - (void)showTransientContentView:(CRWContentView*)contentView { |
| 1081 DCHECK(contentView); | 1104 DCHECK(contentView); |
| 1082 DCHECK(contentView.scrollView); | 1105 DCHECK(contentView.scrollView); |
| 1083 // TODO(crbug.com/556848) Reenable DCHECK when |CRWWebControllerContainerView| | 1106 // TODO(crbug.com/556848) Reenable DCHECK when |CRWWebControllerContainerView| |
| 1084 // is restructured so that subviews are not added during |layoutSubviews|. | 1107 // is restructured so that subviews are not added during |layoutSubviews|. |
| 1085 // DCHECK([contentView.scrollView isDescendantOfView:contentView]); | 1108 // DCHECK([contentView.scrollView isDescendantOfView:contentView]); |
| 1086 [_containerView displayTransientContent:contentView]; | 1109 [_containerView displayTransientContent:contentView]; |
| 1087 } | 1110 } |
| 1088 | 1111 |
| 1112 - (id<CRWWebDelegate>)delegate { |
| 1113 return _delegate.get(); |
| 1114 } |
| 1089 | 1115 |
| 1090 - (void)setDelegate:(id<CRWWebDelegate>)delegate { | 1116 - (void)setDelegate:(id<CRWWebDelegate>)delegate { |
| 1091 _delegate = delegate; | 1117 _delegate.reset(delegate); |
| 1092 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { | 1118 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { |
| 1093 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) | 1119 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) |
| 1094 [self.nativeController setDelegate:self]; | 1120 [self.nativeController setDelegate:self]; |
| 1095 else | 1121 else |
| 1096 [self.nativeController setDelegate:nil]; | 1122 [self.nativeController setDelegate:nil]; |
| 1097 } | 1123 } |
| 1098 } | 1124 } |
| 1099 | 1125 |
| 1126 - (id<CRWWebUserInterfaceDelegate>)UIDelegate { |
| 1127 return _UIDelegate.get(); |
| 1128 } |
| 1129 |
| 1130 - (void)setUIDelegate:(id<CRWWebUserInterfaceDelegate>)UIDelegate { |
| 1131 _UIDelegate.reset(UIDelegate); |
| 1132 } |
| 1133 |
| 1100 - (void)dealloc { | 1134 - (void)dealloc { |
| 1101 DCHECK([NSThread isMainThread]); | 1135 DCHECK([NSThread isMainThread]); |
| 1102 DCHECK(_isBeingDestroyed); // 'close' must have been called already. | 1136 DCHECK(_isBeingDestroyed); // 'close' must have been called already. |
| 1103 DCHECK(!_webView); | 1137 DCHECK(!_webView); |
| 1104 [_containerView setDelegate:nil]; | 1138 [_containerView setDelegate:nil]; |
| 1105 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; | 1139 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; |
| 1106 [[_webViewProxy scrollViewProxy] removeObserver:self]; | 1140 [[_webViewProxy scrollViewProxy] removeObserver:self]; |
| 1107 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 1141 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 1142 [super dealloc]; |
| 1108 } | 1143 } |
| 1109 | 1144 |
| 1110 - (void)dismissKeyboard { | 1145 - (void)dismissKeyboard { |
| 1111 [_webView endEditing:YES]; | 1146 [_webView endEditing:YES]; |
| 1112 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) | 1147 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) |
| 1113 [self.nativeController dismissKeyboard]; | 1148 [self.nativeController dismissKeyboard]; |
| 1114 } | 1149 } |
| 1115 | 1150 |
| 1116 - (id<CRWNativeContent>)nativeController { | 1151 - (id<CRWNativeContent>)nativeController { |
| 1117 return [_containerView nativeController]; | 1152 return [_containerView nativeController]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1129 [_containerView displayNativeContent:nativeController]; | 1164 [_containerView displayNativeContent:nativeController]; |
| 1130 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; | 1165 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; |
| 1131 } | 1166 } |
| 1132 | 1167 |
| 1133 - (NSString*)activityIndicatorGroupID { | 1168 - (NSString*)activityIndicatorGroupID { |
| 1134 return [NSString | 1169 return [NSString |
| 1135 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@", | 1170 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@", |
| 1136 self.webStateImpl->GetRequestGroupID()]; | 1171 self.webStateImpl->GetRequestGroupID()]; |
| 1137 } | 1172 } |
| 1138 | 1173 |
| 1139 - (NSArray*)observedKeyPaths { | 1174 - (NSDictionary*)WKWebViewObservers { |
| 1140 return @[ | 1175 return @{ |
| 1141 @"certificateChain", @"estimatedProgress", @"hasOnlySecureContent", | 1176 @"certificateChain" : @"webViewSecurityFeaturesDidChange", |
| 1142 @"loading", @"title", @"URL" | 1177 @"estimatedProgress" : @"webViewEstimatedProgressDidChange", |
| 1143 ]; | 1178 @"hasOnlySecureContent" : @"webViewSecurityFeaturesDidChange", |
| 1179 @"loading" : @"webViewLoadingStateDidChange", |
| 1180 @"title" : @"webViewTitleDidChange", |
| 1181 @"URL" : @"webViewURLDidChange", |
| 1182 }; |
| 1144 } | 1183 } |
| 1145 | 1184 |
| 1146 // NativeControllerDelegate method, called to inform that title has changed. | 1185 // NativeControllerDelegate method, called to inform that title has changed. |
| 1147 - (void)nativeContent:(id)content titleDidChange:(NSString*)title { | 1186 - (void)nativeContent:(id)content titleDidChange:(NSString*)title { |
| 1148 // Responsiveness to delegate method was checked in setDelegate:. | 1187 // Responsiveness to delegate method was checked in setDelegate:. |
| 1149 [_delegate webController:self titleDidChange:title]; | 1188 [_delegate webController:self titleDidChange:title]; |
| 1150 } | 1189 } |
| 1151 | 1190 |
| 1152 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled { | 1191 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled { |
| 1153 if ([self.nativeController | 1192 if ([self.nativeController |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { | 1318 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { |
| 1280 // We don't want ongoing notification that the long press is held. | 1319 // We don't want ongoing notification that the long press is held. |
| 1281 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) | 1320 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) |
| 1282 return; | 1321 return; |
| 1283 | 1322 |
| 1284 if (![_DOMElementForLastTouch count]) | 1323 if (![_DOMElementForLastTouch count]) |
| 1285 return; | 1324 return; |
| 1286 | 1325 |
| 1287 web::ContextMenuParams params = | 1326 web::ContextMenuParams params = |
| 1288 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()]; | 1327 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()]; |
| 1289 params.view.reset(_webView); | 1328 params.view.reset([_webView retain]); |
| 1290 params.location = [gestureRecognizer locationInView:_webView]; | 1329 params.location = [gestureRecognizer locationInView:_webView]; |
| 1291 if (self.webStateImpl->HandleContextMenu(params)) { | 1330 if (self.webStateImpl->HandleContextMenu(params)) { |
| 1292 // Cancelling all touches has the intended side effect of suppressing the | 1331 // Cancelling all touches has the intended side effect of suppressing the |
| 1293 // system's context menu. | 1332 // system's context menu. |
| 1294 [self cancelAllTouches]; | 1333 [self cancelAllTouches]; |
| 1295 } | 1334 } |
| 1296 } | 1335 } |
| 1297 | 1336 |
| 1298 - (void)cancelAllTouches { | 1337 - (void)cancelAllTouches { |
| 1299 // Disable web view scrolling. | 1338 // Disable web view scrolling. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1322 | 1361 |
| 1323 if (!defaultImage) { | 1362 if (!defaultImage) { |
| 1324 CGRect frame = CGRectMake(0, 0, 2, 2); | 1363 CGRect frame = CGRectMake(0, 0, 2, 2); |
| 1325 UIGraphicsBeginImageContext(frame.size); | 1364 UIGraphicsBeginImageContext(frame.size); |
| 1326 [[UIColor whiteColor] setFill]; | 1365 [[UIColor whiteColor] setFill]; |
| 1327 CGContextFillRect(UIGraphicsGetCurrentContext(), frame); | 1366 CGContextFillRect(UIGraphicsGetCurrentContext(), frame); |
| 1328 | 1367 |
| 1329 UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); | 1368 UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); |
| 1330 UIGraphicsEndImageContext(); | 1369 UIGraphicsEndImageContext(); |
| 1331 | 1370 |
| 1332 defaultImage = [result stretchableImageWithLeftCapWidth:1 topCapHeight:1]; | 1371 defaultImage = |
| 1372 [[result stretchableImageWithLeftCapWidth:1 topCapHeight:1] retain]; |
| 1333 } | 1373 } |
| 1334 return defaultImage; | 1374 return defaultImage; |
| 1335 } | 1375 } |
| 1336 | 1376 |
| 1337 - (BOOL)canGoBack { | 1377 - (BOOL)canGoBack { |
| 1338 return _webStateImpl->GetNavigationManagerImpl().CanGoBack(); | 1378 return _webStateImpl->GetNavigationManagerImpl().CanGoBack(); |
| 1339 } | 1379 } |
| 1340 | 1380 |
| 1341 - (BOOL)canGoForward { | 1381 - (BOOL)canGoForward { |
| 1342 return _webStateImpl->GetNavigationManagerImpl().CanGoForward(); | 1382 return _webStateImpl->GetNavigationManagerImpl().CanGoForward(); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 if (iRecognizer != recognizer) { | 1600 if (iRecognizer != recognizer) { |
| 1561 NSString* description = [iRecognizer description]; | 1601 NSString* description = [iRecognizer description]; |
| 1562 if ([description rangeOfString:fragment].length) { | 1602 if ([description rangeOfString:fragment].length) { |
| 1563 [iRecognizer requireGestureRecognizerToFail:recognizer]; | 1603 [iRecognizer requireGestureRecognizerToFail:recognizer]; |
| 1564 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it | 1604 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it |
| 1565 // is possible for |iRecognizer| to outlive |recognizer| and end up with | 1605 // is possible for |iRecognizer| to outlive |recognizer| and end up with |
| 1566 // a dangling pointer. Add a retaining associative reference to ensure | 1606 // a dangling pointer. Add a retaining associative reference to ensure |
| 1567 // that the lifetimes work out. | 1607 // that the lifetimes work out. |
| 1568 // Note that normally using the value as the key wouldn't make any | 1608 // Note that normally using the value as the key wouldn't make any |
| 1569 // sense, but here it's fine since nothing needs to look up the value. | 1609 // sense, but here it's fine since nothing needs to look up the value. |
| 1570 objc_setAssociatedObject(view, (__bridge void*)recognizer, recognizer, | 1610 objc_setAssociatedObject(view, recognizer, recognizer, |
| 1571 OBJC_ASSOCIATION_RETAIN_NONATOMIC); | 1611 OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
| 1572 } | 1612 } |
| 1573 } | 1613 } |
| 1574 } | 1614 } |
| 1575 } | 1615 } |
| 1576 | 1616 |
| 1577 - (CRWWebController*)createChildWebController { | 1617 - (CRWWebController*)createChildWebController { |
| 1578 CRWWebController* result = [self.delegate webPageOrderedOpen]; | 1618 CRWWebController* result = [self.delegate webPageOrderedOpen]; |
| 1579 DCHECK(!result || result.sessionController.openedByDOM); | 1619 DCHECK(!result || result.sessionController.openedByDOM); |
| 1580 return result; | 1620 return result; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 [script | 1812 [script |
| 1773 appendString:[self javaScriptToDispatchPopStateWithObject:stateObject]]; | 1813 appendString:[self javaScriptToDispatchPopStateWithObject:stateObject]]; |
| 1774 } | 1814 } |
| 1775 if (dispatchHashChange) { | 1815 if (dispatchHashChange) { |
| 1776 web::NavigationItemImpl* previousItem = | 1816 web::NavigationItemImpl* previousItem = |
| 1777 self.sessionController.previousEntry.navigationItemImpl; | 1817 self.sessionController.previousEntry.navigationItemImpl; |
| 1778 const GURL oldURL = previousItem ? previousItem->GetURL() : GURL(); | 1818 const GURL oldURL = previousItem ? previousItem->GetURL() : GURL(); |
| 1779 [script appendString:[self javaScriptToDispatchHashChangeWithOldURL:oldURL | 1819 [script appendString:[self javaScriptToDispatchHashChangeWithOldURL:oldURL |
| 1780 newURL:URL]]; | 1820 newURL:URL]]; |
| 1781 } | 1821 } |
| 1782 __weak CRWWebController* weakSelf = self; | 1822 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 1783 [self executeJavaScript:script | 1823 [self executeJavaScript:script |
| 1784 completionHandler:^(id, NSError*) { | 1824 completionHandler:^(id, NSError*) { |
| 1785 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); | 1825 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) |
| 1786 if (!strongSelf || strongSelf.get()->_isBeingDestroyed) | |
| 1787 return; | 1826 return; |
| 1827 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); |
| 1788 strongSelf.get()->_URLOnStartLoading = URL; | 1828 strongSelf.get()->_URLOnStartLoading = URL; |
| 1789 strongSelf.get()->_lastRegisteredRequestURL = URL; | 1829 strongSelf.get()->_lastRegisteredRequestURL = URL; |
| 1790 }]; | 1830 }]; |
| 1791 } | 1831 } |
| 1792 | 1832 |
| 1793 // Load the current URL in a web view, first ensuring the web view is visible. | 1833 // Load the current URL in a web view, first ensuring the web view is visible. |
| 1794 - (void)loadCurrentURLInWebView { | 1834 - (void)loadCurrentURLInWebView { |
| 1795 // Clear the set of URLs opened in external applications. | 1835 // Clear the set of URLs opened in external applications. |
| 1796 _openedApplicationURL.reset([[NSMutableSet alloc] init]); | 1836 _openedApplicationURL.reset([[NSMutableSet alloc] init]); |
| 1797 | 1837 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2258 | 2298 |
| 2259 if (delta >= 0 || !_webStateImpl->IsShowingWebInterstitial()) { | 2299 if (delta >= 0 || !_webStateImpl->IsShowingWebInterstitial()) { |
| 2260 [self recordStateInHistory]; | 2300 [self recordStateInHistory]; |
| 2261 } | 2301 } |
| 2262 | 2302 |
| 2263 CRWSessionController* sessionController = | 2303 CRWSessionController* sessionController = |
| 2264 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); | 2304 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); |
| 2265 // fromEntry is retained because it has the potential to be released | 2305 // fromEntry is retained because it has the potential to be released |
| 2266 // by goDelta: if it has not been committed. | 2306 // by goDelta: if it has not been committed. |
| 2267 base::scoped_nsobject<CRWSessionEntry> fromEntry( | 2307 base::scoped_nsobject<CRWSessionEntry> fromEntry( |
| 2268 [sessionController currentEntry]); | 2308 [[sessionController currentEntry] retain]); |
| 2269 [sessionController goDelta:delta]; | 2309 [sessionController goDelta:delta]; |
| 2270 if (fromEntry) { | 2310 if (fromEntry) { |
| 2271 [self finishHistoryNavigationFromEntry:fromEntry]; | 2311 [self finishHistoryNavigationFromEntry:fromEntry]; |
| 2272 } | 2312 } |
| 2273 } | 2313 } |
| 2274 | 2314 |
| 2275 - (BOOL)isLoaded { | 2315 - (BOOL)isLoaded { |
| 2276 return _loadPhase == web::PAGE_LOADED; | 2316 return _loadPhase == web::PAGE_LOADED; |
| 2277 } | 2317 } |
| 2278 | 2318 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 _webStateImpl->GetMojoInterfaceRegistry(); | 2493 _webStateImpl->GetMojoInterfaceRegistry(); |
| 2454 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); | 2494 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); |
| 2455 } | 2495 } |
| 2456 return _mojoFacade.get(); | 2496 return _mojoFacade.get(); |
| 2457 } | 2497 } |
| 2458 | 2498 |
| 2459 - (CRWPassKitDownloader*)passKitDownloader { | 2499 - (CRWPassKitDownloader*)passKitDownloader { |
| 2460 if (_passKitDownloader) { | 2500 if (_passKitDownloader) { |
| 2461 return _passKitDownloader.get(); | 2501 return _passKitDownloader.get(); |
| 2462 } | 2502 } |
| 2463 __weak CRWWebController* weakSelf = self; | 2503 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 2464 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) { | 2504 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) { |
| 2465 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); | 2505 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); |
| 2466 if (!strongSelf) { | 2506 if (!strongSelf) { |
| 2467 return; | 2507 return; |
| 2468 } | 2508 } |
| 2469 // Cancel load to update web state, since the PassKit download happens | 2509 // Cancel load to update web state, since the PassKit download happens |
| 2470 // through a separate flow. This follows the same flow as when PassKit is | 2510 // through a separate flow. This follows the same flow as when PassKit is |
| 2471 // downloaded through UIWebView. | 2511 // downloaded through UIWebView. |
| 2472 [strongSelf loadCancelled]; | 2512 [strongSelf loadCancelled]; |
| 2473 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:); | 2513 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:); |
| 2474 id<CRWWebDelegate> delegate = [strongSelf delegate]; | 2514 id<CRWWebDelegate> delegate = [strongSelf delegate]; |
| 2475 if ([delegate respondsToSelector:didLoadPassKitObject]) { | 2515 if ([delegate respondsToSelector:didLoadPassKitObject]) { |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3072 // TODO(crbug.com/549301): Improve transition detection. | 3112 // TODO(crbug.com/549301): Improve transition detection. |
| 3073 ui::PageTransition transition = self.userInteractionRegistered | 3113 ui::PageTransition transition = self.userInteractionRegistered |
| 3074 ? ui::PAGE_TRANSITION_LINK | 3114 ? ui::PAGE_TRANSITION_LINK |
| 3075 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 3115 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
| 3076 [self pushStateWithPageURL:pushURL | 3116 [self pushStateWithPageURL:pushURL |
| 3077 stateObject:stateObject | 3117 stateObject:stateObject |
| 3078 transition:transition]; | 3118 transition:transition]; |
| 3079 | 3119 |
| 3080 NSString* replaceWebViewJS = | 3120 NSString* replaceWebViewJS = |
| 3081 [self javaScriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; | 3121 [self javaScriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; |
| 3082 __weak CRWWebController* weakSelf = self; | 3122 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 3083 [self executeJavaScript:replaceWebViewJS | 3123 [self executeJavaScript:replaceWebViewJS completionHandler:^(id, NSError*) { |
| 3084 completionHandler:^(id, NSError*) { | 3124 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) |
| 3085 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); | 3125 return; |
| 3086 if (!strongSelf || strongSelf.get()->_isBeingDestroyed) | 3126 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); |
| 3087 return; | 3127 [strongSelf optOutScrollsToTopForSubviews]; |
| 3088 [strongSelf optOutScrollsToTopForSubviews]; | 3128 // Notify the observers. |
| 3089 // Notify the observers. | 3129 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); |
| 3090 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); | 3130 [strongSelf didFinishNavigation]; |
| 3091 [strongSelf didFinishNavigation]; | 3131 }]; |
| 3092 }]; | |
| 3093 | |
| 3094 return YES; | 3132 return YES; |
| 3095 } | 3133 } |
| 3096 | 3134 |
| 3097 - (BOOL)handleWindowHistoryDidReplaceStateMessage: | 3135 - (BOOL)handleWindowHistoryDidReplaceStateMessage: |
| 3098 (base::DictionaryValue*)message | 3136 (base::DictionaryValue*)message |
| 3099 context:(NSDictionary*)context { | 3137 context:(NSDictionary*)context { |
| 3100 DCHECK(_changingHistoryState); | 3138 DCHECK(_changingHistoryState); |
| 3101 _changingHistoryState = NO; | 3139 _changingHistoryState = NO; |
| 3102 | 3140 |
| 3103 std::string pageURL; | 3141 std::string pageURL; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3133 if (!message->GetString("stateObject", &stateObjectJSON)) { | 3171 if (!message->GetString("stateObject", &stateObjectJSON)) { |
| 3134 DLOG(WARNING) << "JS message parameter not found: stateObject"; | 3172 DLOG(WARNING) << "JS message parameter not found: stateObject"; |
| 3135 return NO; | 3173 return NO; |
| 3136 } | 3174 } |
| 3137 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); | 3175 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); |
| 3138 _URLOnStartLoading = replaceURL; | 3176 _URLOnStartLoading = replaceURL; |
| 3139 _lastRegisteredRequestURL = replaceURL; | 3177 _lastRegisteredRequestURL = replaceURL; |
| 3140 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; | 3178 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; |
| 3141 NSString* replaceStateJS = [self javaScriptToReplaceWebViewURL:replaceURL | 3179 NSString* replaceStateJS = [self javaScriptToReplaceWebViewURL:replaceURL |
| 3142 stateObjectJSON:stateObject]; | 3180 stateObjectJSON:stateObject]; |
| 3143 __weak CRWWebController* weakSelf = self; | 3181 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 3144 [self executeJavaScript:replaceStateJS | 3182 [self executeJavaScript:replaceStateJS completionHandler:^(id, NSError*) { |
| 3145 completionHandler:^(id, NSError*) { | 3183 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) |
| 3146 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); | 3184 return; |
| 3147 if (!strongSelf || strongSelf.get()->_isBeingDestroyed) | 3185 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); |
| 3148 return; | 3186 [strongSelf didFinishNavigation]; |
| 3149 [strongSelf didFinishNavigation]; | 3187 }]; |
| 3150 }]; | |
| 3151 return YES; | 3188 return YES; |
| 3152 } | 3189 } |
| 3153 | 3190 |
| 3154 #pragma mark - | 3191 #pragma mark - |
| 3155 | 3192 |
| 3156 - (BOOL)wantsKeyboardShield { | 3193 - (BOOL)wantsKeyboardShield { |
| 3157 if ([self.nativeController | 3194 if ([self.nativeController |
| 3158 respondsToSelector:@selector(wantsKeyboardShield)]) { | 3195 respondsToSelector:@selector(wantsKeyboardShield)]) { |
| 3159 return [self.nativeController wantsKeyboardShield]; | 3196 return [self.nativeController wantsKeyboardShield]; |
| 3160 } | 3197 } |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3556 shouldReceiveTouch:(UITouch*)touch { | 3593 shouldReceiveTouch:(UITouch*)touch { |
| 3557 // Expect only _contextMenuRecognizer. | 3594 // Expect only _contextMenuRecognizer. |
| 3558 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); | 3595 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); |
| 3559 | 3596 |
| 3560 // This is custom long press gesture recognizer. By the time the gesture is | 3597 // This is custom long press gesture recognizer. By the time the gesture is |
| 3561 // recognized the web controller needs to know if there is a link under the | 3598 // recognized the web controller needs to know if there is a link under the |
| 3562 // touch. If there a link, the web controller will reject system's context | 3599 // touch. If there a link, the web controller will reject system's context |
| 3563 // menu and show another one. If for some reason context menu info is not | 3600 // menu and show another one. If for some reason context menu info is not |
| 3564 // fetched - system context menu will be shown. | 3601 // fetched - system context menu will be shown. |
| 3565 [self setDOMElementForLastTouch:nil]; | 3602 [self setDOMElementForLastTouch:nil]; |
| 3566 __weak CRWWebController* weakSelf = self; | 3603 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 3567 [self fetchDOMElementAtPoint:[touch locationInView:_webView] | 3604 [self fetchDOMElementAtPoint:[touch locationInView:_webView] |
| 3568 completionHandler:^(NSDictionary* element) { | 3605 completionHandler:^(NSDictionary* element) { |
| 3569 [weakSelf setDOMElementForLastTouch:element]; | 3606 [weakSelf setDOMElementForLastTouch:element]; |
| 3570 }]; | 3607 }]; |
| 3571 return YES; | 3608 return YES; |
| 3572 } | 3609 } |
| 3573 | 3610 |
| 3574 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { | 3611 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { |
| 3575 // Expect only _contextMenuRecognizer. | 3612 // Expect only _contextMenuRecognizer. |
| 3576 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); | 3613 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3671 return [_delegate webController:self | 3708 return [_delegate webController:self |
| 3672 shouldBlockPopupWithURL:popupURL | 3709 shouldBlockPopupWithURL:popupURL |
| 3673 sourceURL:sourceURL]; | 3710 sourceURL:sourceURL]; |
| 3674 } | 3711 } |
| 3675 | 3712 |
| 3676 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { | 3713 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { |
| 3677 const GURL url(windowInfo.url); | 3714 const GURL url(windowInfo.url); |
| 3678 const GURL currentURL([self currentNavigationURL]); | 3715 const GURL currentURL([self currentNavigationURL]); |
| 3679 NSString* windowName = windowInfo.window_name.get(); | 3716 NSString* windowName = windowInfo.window_name.get(); |
| 3680 web::Referrer referrer(currentURL, windowInfo.referrer_policy); | 3717 web::Referrer referrer(currentURL, windowInfo.referrer_policy); |
| 3681 __weak CRWWebController* weakSelf = self; | 3718 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 3682 void (^showPopupHandler)() = ^{ | 3719 void (^showPopupHandler)() = ^{ |
| 3683 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url | 3720 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url |
| 3684 referrer:referrer | 3721 referrer:referrer |
| 3685 windowName:windowName | 3722 windowName:windowName |
| 3686 inBackground:NO]; | 3723 inBackground:NO]; |
| 3687 DCHECK(!child || child.sessionController.openedByDOM); | 3724 DCHECK(!child || child.sessionController.openedByDOM); |
| 3688 }; | 3725 }; |
| 3689 | 3726 |
| 3690 BOOL showPopup = windowInfo.user_is_interacting || | 3727 BOOL showPopup = windowInfo.user_is_interacting || |
| 3691 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]); | 3728 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3986 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders(); | 4023 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders(); |
| 3987 } | 4024 } |
| 3988 | 4025 |
| 3989 #pragma mark - | 4026 #pragma mark - |
| 3990 #pragma mark CRWWebViewScrollViewProxyObserver | 4027 #pragma mark CRWWebViewScrollViewProxyObserver |
| 3991 | 4028 |
| 3992 - (void)webViewScrollViewDidZoom: | 4029 - (void)webViewScrollViewDidZoom: |
| 3993 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | 4030 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| 3994 _pageHasZoomed = YES; | 4031 _pageHasZoomed = YES; |
| 3995 | 4032 |
| 3996 __weak UIScrollView* weakScrollView = self.webScrollView; | 4033 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); |
| 3997 [self extractViewportTagWithCompletion:^( | 4034 [self extractViewportTagWithCompletion:^( |
| 3998 const web::PageViewportState* viewportState) { | 4035 const web::PageViewportState* viewportState) { |
| 3999 if (!weakScrollView) | 4036 if (!weakScrollView) |
| 4000 return; | 4037 return; |
| 4001 base::scoped_nsobject<UIScrollView> scrollView(weakScrollView); | 4038 base::scoped_nsobject<UIScrollView> scrollView([weakScrollView retain]); |
| 4002 if (viewportState && !viewportState->viewport_tag_present() && | 4039 if (viewportState && !viewportState->viewport_tag_present() && |
| 4003 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] && | 4040 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] && |
| 4004 [scrollView zoomScale] > 1.0) { | 4041 [scrollView zoomScale] > 1.0) { |
| 4005 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true); | 4042 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true); |
| 4006 } | 4043 } |
| 4007 }]; | 4044 }]; |
| 4008 } | 4045 } |
| 4009 | 4046 |
| 4010 - (void)webViewScrollViewDidResetContentSize: | 4047 - (void)webViewScrollViewDidResetContentSize: |
| 4011 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | 4048 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4106 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion { | 4143 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion { |
| 4107 DCHECK(completion); | 4144 DCHECK(completion); |
| 4108 web::NavigationItem* currentItem = [self currentNavItem]; | 4145 web::NavigationItem* currentItem = [self currentNavItem]; |
| 4109 if (!currentItem) { | 4146 if (!currentItem) { |
| 4110 completion(nullptr); | 4147 completion(nullptr); |
| 4111 return; | 4148 return; |
| 4112 } | 4149 } |
| 4113 NSString* const kViewportContentQuery = | 4150 NSString* const kViewportContentQuery = |
| 4114 @"var viewport = document.querySelector('meta[name=\"viewport\"]');" | 4151 @"var viewport = document.querySelector('meta[name=\"viewport\"]');" |
| 4115 "viewport ? viewport.content : '';"; | 4152 "viewport ? viewport.content : '';"; |
| 4116 __weak CRWWebController* weakSelf = self; | 4153 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 4117 int itemID = currentItem->GetUniqueID(); | 4154 int itemID = currentItem->GetUniqueID(); |
| 4118 [self executeJavaScript:kViewportContentQuery | 4155 [self executeJavaScript:kViewportContentQuery |
| 4119 completionHandler:^(id viewportContent, NSError*) { | 4156 completionHandler:^(id viewportContent, NSError*) { |
| 4120 web::NavigationItem* item = [weakSelf currentNavItem]; | 4157 web::NavigationItem* item = [weakSelf currentNavItem]; |
| 4121 if (item && item->GetUniqueID() == itemID) { | 4158 if (item && item->GetUniqueID() == itemID) { |
| 4122 web::PageViewportState viewportState( | 4159 web::PageViewportState viewportState( |
| 4123 base::mac::ObjCCast<NSString>(viewportContent)); | 4160 base::mac::ObjCCast<NSString>(viewportContent)); |
| 4124 completion(&viewportState); | 4161 completion(&viewportState); |
| 4125 } else { | 4162 } else { |
| 4126 completion(nullptr); | 4163 completion(nullptr); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4155 displayState.zoom_state().set_zoom_scale( | 4192 displayState.zoom_state().set_zoom_scale( |
| 4156 displayState.zoom_state().minimum_zoom_scale() + | 4193 displayState.zoom_state().minimum_zoom_scale() + |
| 4157 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference()); | 4194 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference()); |
| 4158 currentItem->SetPageDisplayState(displayState); | 4195 currentItem->SetPageDisplayState(displayState); |
| 4159 [self applyPageDisplayState:currentItem->GetPageDisplayState()]; | 4196 [self applyPageDisplayState:currentItem->GetPageDisplayState()]; |
| 4160 } | 4197 } |
| 4161 | 4198 |
| 4162 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState { | 4199 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState { |
| 4163 if (!displayState.IsValid()) | 4200 if (!displayState.IsValid()) |
| 4164 return; | 4201 return; |
| 4165 __weak CRWWebController* weakSelf = self; | 4202 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 4166 web::PageDisplayState displayStateCopy = displayState; | 4203 web::PageDisplayState displayStateCopy = displayState; |
| 4167 [self extractViewportTagWithCompletion:^( | 4204 [self extractViewportTagWithCompletion:^( |
| 4168 const web::PageViewportState* viewportState) { | 4205 const web::PageViewportState* viewportState) { |
| 4169 if (viewportState) { | 4206 if (viewportState) { |
| 4170 [weakSelf applyPageDisplayState:displayStateCopy | 4207 [weakSelf applyPageDisplayState:displayStateCopy |
| 4171 userScalable:viewportState->user_scalable()]; | 4208 userScalable:viewportState->user_scalable()]; |
| 4172 } | 4209 } |
| 4173 }]; | 4210 }]; |
| 4174 } | 4211 } |
| 4175 | 4212 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4244 (const web::PageScrollState&)scrollState { | 4281 (const web::PageScrollState&)scrollState { |
| 4245 DCHECK(scrollState.IsValid()); | 4282 DCHECK(scrollState.IsValid()); |
| 4246 CGPoint scrollOffset = | 4283 CGPoint scrollOffset = |
| 4247 CGPointMake(scrollState.offset_x(), scrollState.offset_y()); | 4284 CGPointMake(scrollState.offset_x(), scrollState.offset_y()); |
| 4248 if (_loadPhase == web::PAGE_LOADED) { | 4285 if (_loadPhase == web::PAGE_LOADED) { |
| 4249 // If the page is loaded, update the scroll immediately. | 4286 // If the page is loaded, update the scroll immediately. |
| 4250 [self.webScrollView setContentOffset:scrollOffset]; | 4287 [self.webScrollView setContentOffset:scrollOffset]; |
| 4251 } else { | 4288 } else { |
| 4252 // If the page isn't loaded, store the action to update the scroll | 4289 // If the page isn't loaded, store the action to update the scroll |
| 4253 // when the page finishes loading. | 4290 // when the page finishes loading. |
| 4254 __weak UIScrollView* weakScrollView = self.webScrollView; | 4291 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); |
| 4255 base::scoped_nsprotocol<ProceduralBlock> action([^{ | 4292 base::scoped_nsprotocol<ProceduralBlock> action([^{ |
| 4256 [weakScrollView setContentOffset:scrollOffset]; | 4293 [weakScrollView setContentOffset:scrollOffset]; |
| 4257 } copy]); | 4294 } copy]); |
| 4258 [_pendingLoadCompleteActions addObject:action]; | 4295 [_pendingLoadCompleteActions addObject:action]; |
| 4259 } | 4296 } |
| 4260 } | 4297 } |
| 4261 | 4298 |
| 4262 #pragma mark - | 4299 #pragma mark - |
| 4263 #pragma mark Web Page Features | 4300 #pragma mark Web Page Features |
| 4264 | 4301 |
| 4265 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { | 4302 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { |
| 4266 if (!_webView) { | 4303 if (!_webView) { |
| 4267 handler(0); | 4304 handler(0); |
| 4268 return; | 4305 return; |
| 4269 } | 4306 } |
| 4270 | 4307 |
| 4271 [self executeJavaScript:@"__gCrWeb.getPageWidth();" | 4308 [self executeJavaScript:@"__gCrWeb.getPageWidth();" |
| 4272 completionHandler:^(id pageWidth, NSError*) { | 4309 completionHandler:^(id pageWidth, NSError*) { |
| 4273 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]); | 4310 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]); |
| 4274 }]; | 4311 }]; |
| 4275 } | 4312 } |
| 4276 | 4313 |
| 4277 - (void)fetchDOMElementAtPoint:(CGPoint)point | 4314 - (void)fetchDOMElementAtPoint:(CGPoint)point |
| 4278 completionHandler:(void (^)(NSDictionary*))handler { | 4315 completionHandler:(void (^)(NSDictionary*))handler { |
| 4279 DCHECK(handler); | 4316 DCHECK(handler); |
| 4280 // Convert point into web page's coordinate system (which may be scaled and/or | 4317 // Convert point into web page's coordinate system (which may be scaled and/or |
| 4281 // scrolled). | 4318 // scrolled). |
| 4282 CGPoint scrollOffset = self.scrollPosition; | 4319 CGPoint scrollOffset = self.scrollPosition; |
| 4283 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; | 4320 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; |
| 4284 __weak CRWWebController* weakSelf = self; | 4321 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 4285 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { | 4322 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { |
| 4286 CGFloat scale = pageWidth / webViewContentWidth; | 4323 CGFloat scale = pageWidth / webViewContentWidth; |
| 4287 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, | 4324 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, |
| 4288 (point.y + scrollOffset.y) * scale); | 4325 (point.y + scrollOffset.y) * scale); |
| 4289 NSString* const kGetElementScript = | 4326 NSString* const kGetElementScript = |
| 4290 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", | 4327 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", |
| 4291 localPoint.x, localPoint.y]; | 4328 localPoint.x, localPoint.y]; |
| 4292 [weakSelf executeJavaScript:kGetElementScript | 4329 [weakSelf executeJavaScript:kGetElementScript |
| 4293 completionHandler:^(id element, NSError*) { | 4330 completionHandler:^(id element, NSError*) { |
| 4294 handler(base::mac::ObjCCastStrict<NSDictionary>(element)); | 4331 handler(base::mac::ObjCCastStrict<NSDictionary>(element)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4306 title = @"JavaScript"; | 4343 title = @"JavaScript"; |
| 4307 } else { | 4344 } else { |
| 4308 base::string16 URLText = url_formatter::FormatUrl(params.link_url); | 4345 base::string16 URLText = url_formatter::FormatUrl(params.link_url); |
| 4309 title = base::SysUTF16ToNSString(URLText); | 4346 title = base::SysUTF16ToNSString(URLText); |
| 4310 } | 4347 } |
| 4311 } | 4348 } |
| 4312 NSString* src = element[@"src"]; | 4349 NSString* src = element[@"src"]; |
| 4313 if (src) { | 4350 if (src) { |
| 4314 params.src_url = GURL(base::SysNSStringToUTF8(src)); | 4351 params.src_url = GURL(base::SysNSStringToUTF8(src)); |
| 4315 if (!title) | 4352 if (!title) |
| 4316 title = [src copy]; | 4353 title = [[src copy] autorelease]; |
| 4317 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)]) | 4354 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)]) |
| 4318 title = nil; | 4355 title = nil; |
| 4319 } | 4356 } |
| 4320 NSString* titleAttribute = element[@"title"]; | 4357 NSString* titleAttribute = element[@"title"]; |
| 4321 if (titleAttribute) | 4358 if (titleAttribute) |
| 4322 title = titleAttribute; | 4359 title = titleAttribute; |
| 4323 if (title) { | 4360 if (title) { |
| 4324 params.menu_title.reset([title copy]); | 4361 params.menu_title.reset([title copy]); |
| 4325 } | 4362 } |
| 4326 NSString* referrerPolicy = element[@"referrerPolicy"]; | 4363 NSString* referrerPolicy = element[@"referrerPolicy"]; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4381 [_delegate webControllerDidSuppressDialog:self]; | 4418 [_delegate webControllerDidSuppressDialog:self]; |
| 4382 } | 4419 } |
| 4383 | 4420 |
| 4384 - (void)didBlockPopupWithURL:(GURL)popupURL | 4421 - (void)didBlockPopupWithURL:(GURL)popupURL |
| 4385 sourceURL:(GURL)sourceURL | 4422 sourceURL:(GURL)sourceURL |
| 4386 referrerPolicy:(const std::string&)referrerPolicyString { | 4423 referrerPolicy:(const std::string&)referrerPolicyString { |
| 4387 web::ReferrerPolicy referrerPolicy = | 4424 web::ReferrerPolicy referrerPolicy = |
| 4388 web::ReferrerPolicyFromString(referrerPolicyString); | 4425 web::ReferrerPolicyFromString(referrerPolicyString); |
| 4389 web::Referrer referrer(sourceURL, referrerPolicy); | 4426 web::Referrer referrer(sourceURL, referrerPolicy); |
| 4390 NSString* const kWindowName = @""; // obsoleted | 4427 NSString* const kWindowName = @""; // obsoleted |
| 4391 __weak CRWWebController* weakSelf = self; | 4428 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 4392 void (^showPopupHandler)() = ^{ | 4429 void (^showPopupHandler)() = ^{ |
| 4393 // On Desktop cross-window comunication is not supported for unblocked | 4430 // On Desktop cross-window comunication is not supported for unblocked |
| 4394 // popups; so it's ok to create a new independent page. | 4431 // popups; so it's ok to create a new independent page. |
| 4395 CRWWebController* child = | 4432 CRWWebController* child = |
| 4396 [[weakSelf delegate] webPageOrderedOpen:popupURL | 4433 [[weakSelf delegate] webPageOrderedOpen:popupURL |
| 4397 referrer:referrer | 4434 referrer:referrer |
| 4398 windowName:kWindowName | 4435 windowName:kWindowName |
| 4399 inBackground:NO]; | 4436 inBackground:NO]; |
| 4400 DCHECK(!child || child.sessionController.openedByDOM); | 4437 DCHECK(!child || child.sessionController.openedByDOM); |
| 4401 }; | 4438 }; |
| 4402 | 4439 |
| 4403 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); | 4440 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); |
| 4404 [self.delegate webController:self didBlockPopup:info]; | 4441 [self.delegate webController:self didBlockPopup:info]; |
| 4405 } | 4442 } |
| 4406 | 4443 |
| 4407 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { | 4444 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { |
| 4408 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { | 4445 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { |
| 4409 __weak CRWWebController* weakSelf = self; | 4446 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 4410 dispatch_async(dispatch_get_main_queue(), ^{ | 4447 dispatch_async(dispatch_get_main_queue(), ^{ |
| 4411 [self queryPageReferrerPolicy:^(NSString* policy) { | 4448 [self queryPageReferrerPolicy:^(NSString* policy) { |
| 4412 [weakSelf didBlockPopupWithURL:popupURL | 4449 [weakSelf didBlockPopupWithURL:popupURL |
| 4413 sourceURL:sourceURL | 4450 sourceURL:sourceURL |
| 4414 referrerPolicy:base::SysNSStringToUTF8(policy)]; | 4451 referrerPolicy:base::SysNSStringToUTF8(policy)]; |
| 4415 }]; | 4452 }]; |
| 4416 }); | 4453 }); |
| 4417 } | 4454 } |
| 4418 } | 4455 } |
| 4419 | 4456 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4665 [_containerView addToolbars:_webViewToolbars]; | 4702 [_containerView addToolbars:_webViewToolbars]; |
| 4666 | 4703 |
| 4667 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( | 4704 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( |
| 4668 [[CRWWebViewContentView alloc] initWithWebView:_webView | 4705 [[CRWWebViewContentView alloc] initWithWebView:_webView |
| 4669 scrollView:self.webScrollView]); | 4706 scrollView:self.webScrollView]); |
| 4670 [_containerView displayWebViewContentView:webViewContentView]; | 4707 [_containerView displayWebViewContentView:webViewContentView]; |
| 4671 } | 4708 } |
| 4672 } | 4709 } |
| 4673 | 4710 |
| 4674 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { | 4711 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { |
| 4675 return web::CreateWKWebView(CGRectZero, config, | 4712 return [web::CreateWKWebView(CGRectZero, config, |
| 4676 self.webStateImpl->GetBrowserState(), | 4713 self.webStateImpl->GetBrowserState(), |
| 4677 [self useDesktopUserAgent]); | 4714 [self useDesktopUserAgent]) autorelease]; |
| 4678 } | 4715 } |
| 4679 | 4716 |
| 4680 - (void)setWebView:(WKWebView*)webView { | 4717 - (void)setWebView:(WKWebView*)webView { |
| 4681 DCHECK_NE(_webView.get(), webView); | 4718 DCHECK_NE(_webView.get(), webView); |
| 4682 | 4719 |
| 4683 // Unwind the old web view. | 4720 // Unwind the old web view. |
| 4684 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is | 4721 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is |
| 4685 // fixed. | 4722 // fixed. |
| 4686 CRWWKScriptMessageRouter* messageRouter = | 4723 CRWWKScriptMessageRouter* messageRouter = |
| 4687 [self webViewConfigurationProvider].GetScriptMessageRouter(); | 4724 [self webViewConfigurationProvider].GetScriptMessageRouter(); |
| 4688 if (_webView) { | 4725 if (_webView) { |
| 4689 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; | 4726 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; |
| 4690 } | 4727 } |
| 4691 [_webView setNavigationDelegate:nil]; | 4728 [_webView setNavigationDelegate:nil]; |
| 4692 [_webView setUIDelegate:nil]; | 4729 [_webView setUIDelegate:nil]; |
| 4693 for (NSString* keyPath in self.observedKeyPaths) { | 4730 for (NSString* keyPath in self.WKWebViewObservers) { |
| 4694 [_webView removeObserver:self forKeyPath:keyPath]; | 4731 [_webView removeObserver:self forKeyPath:keyPath]; |
| 4695 } | 4732 } |
| 4696 [self clearActivityIndicatorTasks]; | 4733 [self clearActivityIndicatorTasks]; |
| 4697 | 4734 |
| 4698 _webView.reset(webView); | 4735 _webView.reset([webView retain]); |
| 4699 | 4736 |
| 4700 // Set up the new web view. | 4737 // Set up the new web view. |
| 4701 if (webView) { | 4738 if (webView) { |
| 4702 __weak CRWWebController* weakSelf = self; | 4739 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 4703 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { | 4740 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { |
| 4704 [weakSelf didReceiveScriptMessage:message]; | 4741 [weakSelf didReceiveScriptMessage:message]; |
| 4705 } | 4742 } |
| 4706 name:kScriptMessageName | 4743 name:kScriptMessageName |
| 4707 webView:webView]; | 4744 webView:webView]; |
| 4708 _windowIDJSManager.reset( | 4745 _windowIDJSManager.reset( |
| 4709 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); | 4746 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); |
| 4710 } else { | 4747 } else { |
| 4711 _windowIDJSManager.reset(); | 4748 _windowIDJSManager.reset(); |
| 4712 } | 4749 } |
| 4713 [_webView setNavigationDelegate:self]; | 4750 [_webView setNavigationDelegate:self]; |
| 4714 [_webView setUIDelegate:self]; | 4751 [_webView setUIDelegate:self]; |
| 4715 for (NSString* keyPath in self.observedKeyPaths) { | 4752 for (NSString* keyPath in self.WKWebViewObservers) { |
| 4716 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; | 4753 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; |
| 4717 } | 4754 } |
| 4718 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 4755 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 4719 [self setDocumentURL:_defaultURL]; | 4756 [self setDocumentURL:_defaultURL]; |
| 4720 } | 4757 } |
| 4721 | 4758 |
| 4722 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { | 4759 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| 4723 if (!_webView) | 4760 if (!_webView) |
| 4724 return; | 4761 return; |
| 4725 | 4762 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4761 // This happens during tests. | 4798 // This happens during tests. |
| 4762 if (!_webView) { | 4799 if (!_webView) { |
| 4763 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 4800 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 4764 } | 4801 } |
| 4765 | 4802 |
| 4766 std::string MIMEType = self.webState->GetContentsMimeType(); | 4803 std::string MIMEType = self.webState->GetContentsMimeType(); |
| 4767 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; | 4804 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; |
| 4768 } | 4805 } |
| 4769 | 4806 |
| 4770 - (void)loadRequest:(NSMutableURLRequest*)request { | 4807 - (void)loadRequest:(NSMutableURLRequest*)request { |
| 4771 _latestWKNavigation.reset([_webView loadRequest:request]); | 4808 _latestWKNavigation.reset([[_webView loadRequest:request] retain]); |
| 4772 } | 4809 } |
| 4773 | 4810 |
| 4774 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { | 4811 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { |
| 4775 if (!_POSTRequestLoader) { | 4812 if (!_POSTRequestLoader) { |
| 4776 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); | 4813 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); |
| 4777 } | 4814 } |
| 4778 | 4815 |
| 4779 CRWWKScriptMessageRouter* messageRouter = | 4816 CRWWKScriptMessageRouter* messageRouter = |
| 4780 [self webViewConfigurationProvider].GetScriptMessageRouter(); | 4817 [self webViewConfigurationProvider].GetScriptMessageRouter(); |
| 4781 | 4818 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4807 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { | 4844 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { |
| 4808 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); | 4845 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); |
| 4809 [self loadHTML:HTML forURL:URL]; | 4846 [self loadHTML:HTML forURL:URL]; |
| 4810 } | 4847 } |
| 4811 | 4848 |
| 4812 - (void)loadHTMLForCurrentURL:(NSString*)HTML { | 4849 - (void)loadHTMLForCurrentURL:(NSString*)HTML { |
| 4813 [self loadHTML:HTML forURL:self.currentURL]; | 4850 [self loadHTML:HTML forURL:self.currentURL]; |
| 4814 } | 4851 } |
| 4815 | 4852 |
| 4816 - (void)stopLoading { | 4853 - (void)stopLoading { |
| 4817 _stoppedWKNavigation = _latestWKNavigation; | 4854 _stoppedWKNavigation.reset(_latestWKNavigation); |
| 4818 | 4855 |
| 4819 base::RecordAction(UserMetricsAction("Stop")); | 4856 base::RecordAction(UserMetricsAction("Stop")); |
| 4820 // Discard the pending and transient entried before notifying the tab model | 4857 // Discard the pending and transient entried before notifying the tab model |
| 4821 // observers of the change via |-abortLoad|. | 4858 // observers of the change via |-abortLoad|. |
| 4822 [[self sessionController] discardNonCommittedEntries]; | 4859 [[self sessionController] discardNonCommittedEntries]; |
| 4823 [self abortLoad]; | 4860 [self abortLoad]; |
| 4824 // If discarding the non-committed entries results in an app-specific URL, | 4861 // If discarding the non-committed entries results in an app-specific URL, |
| 4825 // reload it in its native view. | 4862 // reload it in its native view. |
| 4826 if (!self.nativeController && | 4863 if (!self.nativeController && |
| 4827 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { | 4864 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5104 [self loadWithParams:params]; | 5141 [self loadWithParams:params]; |
| 5105 } | 5142 } |
| 5106 return; | 5143 return; |
| 5107 } else { | 5144 } else { |
| 5108 [self registerLoadRequest:webViewURL]; | 5145 [self registerLoadRequest:webViewURL]; |
| 5109 } | 5146 } |
| 5110 } | 5147 } |
| 5111 // Ensure the URL is registered and loadPhase is as expected. | 5148 // Ensure the URL is registered and loadPhase is as expected. |
| 5112 DCHECK(_lastRegisteredRequestURL == webViewURL); | 5149 DCHECK(_lastRegisteredRequestURL == webViewURL); |
| 5113 DCHECK(self.loadPhase == web::LOAD_REQUESTED); | 5150 DCHECK(self.loadPhase == web::LOAD_REQUESTED); |
| 5114 _latestWKNavigation.reset(navigation); | 5151 _latestWKNavigation.reset([navigation retain]); |
| 5115 } | 5152 } |
| 5116 | 5153 |
| 5117 - (void)webView:(WKWebView*)webView | 5154 - (void)webView:(WKWebView*)webView |
| 5118 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { | 5155 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { |
| 5119 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) | 5156 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) |
| 5120 referrer:[self currentReferrer] | 5157 referrer:[self currentReferrer] |
| 5121 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; | 5158 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; |
| 5122 } | 5159 } |
| 5123 | 5160 |
| 5124 - (void)webView:(WKWebView*)webView | 5161 - (void)webView:(WKWebView*)webView |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5253 } | 5290 } |
| 5254 | 5291 |
| 5255 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) { | 5292 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) { |
| 5256 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 5293 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| 5257 return; | 5294 return; |
| 5258 } | 5295 } |
| 5259 | 5296 |
| 5260 SecTrustRef trust = challenge.protectionSpace.serverTrust; | 5297 SecTrustRef trust = challenge.protectionSpace.serverTrust; |
| 5261 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust, | 5298 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust, |
| 5262 base::scoped_policy::RETAIN); | 5299 base::scoped_policy::RETAIN); |
| 5263 __weak CRWWebController* weakSelf = self; | 5300 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 5264 [_certVerificationController | 5301 [_certVerificationController |
| 5265 decideLoadPolicyForTrust:scopedTrust | 5302 decideLoadPolicyForTrust:scopedTrust |
| 5266 host:challenge.protectionSpace.host | 5303 host:challenge.protectionSpace.host |
| 5267 completionHandler:^(web::CertAcceptPolicy policy, | 5304 completionHandler:^(web::CertAcceptPolicy policy, |
| 5268 net::CertStatus status) { | 5305 net::CertStatus status) { |
| 5269 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); | 5306 base::scoped_nsobject<CRWWebController> strongSelf( |
| 5307 [weakSelf retain]); |
| 5270 if (!strongSelf) { | 5308 if (!strongSelf) { |
| 5271 completionHandler( | 5309 completionHandler( |
| 5272 NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 5310 NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| 5273 return; | 5311 return; |
| 5274 } | 5312 } |
| 5275 [strongSelf processAuthChallenge:challenge | 5313 [strongSelf processAuthChallenge:challenge |
| 5276 forCertAcceptPolicy:policy | 5314 forCertAcceptPolicy:policy |
| 5277 certStatus:status | 5315 certStatus:status |
| 5278 completionHandler:completionHandler]; | 5316 completionHandler:completionHandler]; |
| 5279 }]; | 5317 }]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 5305 } | 5343 } |
| 5306 } | 5344 } |
| 5307 | 5345 |
| 5308 #pragma mark - | 5346 #pragma mark - |
| 5309 #pragma mark KVO Observation | 5347 #pragma mark KVO Observation |
| 5310 | 5348 |
| 5311 - (void)observeValueForKeyPath:(NSString*)keyPath | 5349 - (void)observeValueForKeyPath:(NSString*)keyPath |
| 5312 ofObject:(id)object | 5350 ofObject:(id)object |
| 5313 change:(NSDictionary*)change | 5351 change:(NSDictionary*)change |
| 5314 context:(void*)context { | 5352 context:(void*)context { |
| 5315 // All observed keypaths have to be present in |self.observedKeyPaths|. | 5353 NSString* dispatcherSelectorName = self.WKWebViewObservers[keyPath]; |
| 5316 DCHECK([self.observedKeyPaths containsObject:keyPath]); | 5354 DCHECK(dispatcherSelectorName); |
| 5317 if ([keyPath isEqualToString:@"certificateChain"]) { | 5355 if (dispatcherSelectorName) |
| 5318 [self webViewSecurityFeaturesDidChange]; | 5356 [self performSelector:NSSelectorFromString(dispatcherSelectorName)]; |
| 5319 } else if ([keyPath isEqualToString:@"estimatedProgress"]) { | |
| 5320 [self webViewEstimatedProgressDidChange]; | |
| 5321 } else if ([keyPath isEqualToString:@"hasOnlySecureContent"]) { | |
| 5322 [self webViewSecurityFeaturesDidChange]; | |
| 5323 } else if ([keyPath isEqualToString:@"loading"]) { | |
| 5324 [self webViewLoadingStateDidChange]; | |
| 5325 } else if ([keyPath isEqualToString:@"title"]) { | |
| 5326 [self webViewTitleDidChange]; | |
| 5327 } else if ([keyPath isEqualToString:@"URL"]) { | |
| 5328 [self webViewURLDidChange]; | |
| 5329 } else { | |
| 5330 NOTREACHED(); | |
| 5331 } | |
| 5332 } | 5357 } |
| 5333 | 5358 |
| 5334 - (void)webViewEstimatedProgressDidChange { | 5359 - (void)webViewEstimatedProgressDidChange { |
| 5335 if (!_isBeingDestroyed) { | 5360 if (!_isBeingDestroyed) { |
| 5336 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]); | 5361 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]); |
| 5337 } | 5362 } |
| 5338 } | 5363 } |
| 5339 | 5364 |
| 5340 - (void)webViewSecurityFeaturesDidChange { | 5365 - (void)webViewSecurityFeaturesDidChange { |
| 5341 if (self.loadPhase == web::LOAD_REQUESTED) { | 5366 if (self.loadPhase == web::LOAD_REQUESTED) { |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5713 } | 5738 } |
| 5714 | 5739 |
| 5715 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5740 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 5716 } | 5741 } |
| 5717 | 5742 |
| 5718 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5743 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5719 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5744 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5720 } | 5745 } |
| 5721 | 5746 |
| 5722 @end | 5747 @end |
| OLD | NEW |