Chromium Code Reviews| 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/ios/weak_nsobject.h" |
| 22 #include "base/json/json_reader.h" | 22 #include "base/json/json_reader.h" |
| 23 #include "base/json/string_escape.h" | 23 #include "base/json/string_escape.h" |
| 24 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "base/mac/bind_objc_block.h" | 25 #include "base/mac/bind_objc_block.h" |
| 26 #include "base/mac/bundle_locations.h" | 26 #include "base/mac/bundle_locations.h" |
| 27 #include "base/mac/foundation_util.h" | 27 #include "base/mac/foundation_util.h" |
| 28 #include "base/mac/objc_property_releaser.h" | |
| 29 #include "base/mac/scoped_cftyperef.h" | 28 #include "base/mac/scoped_cftyperef.h" |
| 30 #include "base/mac/scoped_nsobject.h" | 29 #include "base/mac/scoped_nsobject.h" |
| 31 #include "base/metrics/histogram.h" | 30 #include "base/metrics/histogram.h" |
| 32 #include "base/metrics/user_metrics.h" | 31 #include "base/metrics/user_metrics.h" |
| 33 #include "base/metrics/user_metrics_action.h" | 32 #include "base/metrics/user_metrics_action.h" |
| 34 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
| 35 #include "base/strings/sys_string_conversions.h" | 34 #include "base/strings/sys_string_conversions.h" |
| 36 #include "base/strings/utf_string_conversions.h" | 35 #include "base/strings/utf_string_conversions.h" |
| 37 #include "base/time/time.h" | 36 #include "base/time/time.h" |
| 38 #include "base/values.h" | 37 #include "base/values.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 #import "ios/web/web_state/wk_web_view_security_util.h" | 99 #import "ios/web/web_state/wk_web_view_security_util.h" |
| 101 #import "ios/web/webui/crw_web_ui_manager.h" | 100 #import "ios/web/webui/crw_web_ui_manager.h" |
| 102 #import "ios/web/webui/mojo_facade.h" | 101 #import "ios/web/webui/mojo_facade.h" |
| 103 #import "net/base/mac/url_conversions.h" | 102 #import "net/base/mac/url_conversions.h" |
| 104 #include "net/base/net_errors.h" | 103 #include "net/base/net_errors.h" |
| 105 #include "services/service_manager/public/cpp/interface_registry.h" | 104 #include "services/service_manager/public/cpp/interface_registry.h" |
| 106 #include "ui/base/page_transition_types.h" | 105 #include "ui/base/page_transition_types.h" |
| 107 #include "url/gurl.h" | 106 #include "url/gurl.h" |
| 108 #include "url/url_constants.h" | 107 #include "url/url_constants.h" |
| 109 | 108 |
| 109 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 110 #error "This file requires ARC support." | |
| 111 #endif | |
| 112 | |
| 110 using base::UserMetricsAction; | 113 using base::UserMetricsAction; |
| 111 using web::NavigationManager; | 114 using web::NavigationManager; |
| 112 using web::NavigationManagerImpl; | 115 using web::NavigationManagerImpl; |
| 113 using web::WebState; | 116 using web::WebState; |
| 114 using web::WebStateImpl; | 117 using web::WebStateImpl; |
| 115 | 118 |
| 116 namespace web { | 119 namespace web { |
| 117 NSString* const kContainerViewID = @"Container View"; | 120 NSString* const kContainerViewID = @"Container View"; |
| 118 const char* kWindowNameSeparator = "#"; | 121 const char* kWindowNameSeparator = "#"; |
| 119 NSString* const kUserIsInteractingKey = @"userIsInteracting"; | 122 NSString* const kUserIsInteractingKey = @"userIsInteracting"; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 return | 247 return |
| 245 [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; | 248 [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; |
| 246 } | 249 } |
| 247 } // namespace | 250 } // namespace |
| 248 | 251 |
| 249 #pragma mark - | 252 #pragma mark - |
| 250 | 253 |
| 251 // A container object for any navigation information that is only available | 254 // A container object for any navigation information that is only available |
| 252 // during pre-commit delegate callbacks, and thus must be held until the | 255 // during pre-commit delegate callbacks, and thus must be held until the |
| 253 // navigation commits and the informatino can be used. | 256 // navigation commits and the informatino can be used. |
| 254 @interface CRWWebControllerPendingNavigationInfo : NSObject { | 257 @interface CRWWebControllerPendingNavigationInfo : NSObject |
| 255 base::mac::ObjCPropertyReleaser | |
| 256 _propertyReleaser_CRWWebControllerPendingNavigationInfo; | |
| 257 } | |
| 258 // The referrer for the page. | 258 // The referrer for the page. |
| 259 @property(nonatomic, copy) NSString* referrer; | 259 @property(nonatomic, copy) NSString* referrer; |
| 260 // The MIME type for the page. | 260 // The MIME type for the page. |
| 261 @property(nonatomic, copy) NSString* MIMEType; | 261 @property(nonatomic, copy) NSString* MIMEType; |
| 262 // The navigation type for the load. | 262 // The navigation type for the load. |
| 263 @property(nonatomic, assign) WKNavigationType navigationType; | 263 @property(nonatomic, assign) WKNavigationType navigationType; |
| 264 // HTTP request method for the load. | 264 // HTTP request method for the load. |
| 265 @property(nonatomic, copy) NSString* HTTPMethod; | 265 @property(nonatomic, copy) NSString* HTTPMethod; |
| 266 // Whether the pending navigation has been directly cancelled before the | 266 // Whether the pending navigation has been directly cancelled before the |
| 267 // navigation is committed. | 267 // navigation is committed. |
| 268 // Cancelled navigations should be simply discarded without handling any | 268 // Cancelled navigations should be simply discarded without handling any |
| 269 // specific error. | 269 // specific error. |
| 270 @property(nonatomic, assign) BOOL cancelled; | 270 @property(nonatomic, assign) BOOL cancelled; |
| 271 @end | 271 @end |
| 272 | 272 |
| 273 @implementation CRWWebControllerPendingNavigationInfo | 273 @implementation CRWWebControllerPendingNavigationInfo |
| 274 @synthesize referrer = _referrer; | 274 @synthesize referrer = _referrer; |
| 275 @synthesize MIMEType = _MIMEType; | 275 @synthesize MIMEType = _MIMEType; |
| 276 @synthesize navigationType = _navigationType; | 276 @synthesize navigationType = _navigationType; |
| 277 @synthesize HTTPMethod = _HTTPMethod; | 277 @synthesize HTTPMethod = _HTTPMethod; |
| 278 @synthesize cancelled = _cancelled; | 278 @synthesize cancelled = _cancelled; |
| 279 | 279 |
| 280 - (instancetype)init { | 280 - (instancetype)init { |
| 281 if ((self = [super init])) { | 281 if ((self = [super init])) { |
| 282 _propertyReleaser_CRWWebControllerPendingNavigationInfo.Init( | |
| 283 self, [CRWWebControllerPendingNavigationInfo class]); | |
| 284 _navigationType = WKNavigationTypeOther; | 282 _navigationType = WKNavigationTypeOther; |
| 285 } | 283 } |
| 286 return self; | 284 return self; |
| 287 } | 285 } |
| 288 @end | 286 @end |
| 289 | 287 |
| 290 @interface CRWWebController ()<CRWNativeContentDelegate, | 288 @interface CRWWebController ()<CRWNativeContentDelegate, |
| 291 CRWSSLStatusUpdaterDataSource, | 289 CRWSSLStatusUpdaterDataSource, |
| 292 CRWSSLStatusUpdaterDelegate, | 290 CRWSSLStatusUpdaterDelegate, |
| 293 CRWWebControllerContainerViewDelegate, | 291 CRWWebControllerContainerViewDelegate, |
| 294 CRWWebViewScrollViewProxyObserver, | 292 CRWWebViewScrollViewProxyObserver, |
| 295 WKNavigationDelegate, | 293 WKNavigationDelegate, |
| 296 WKUIDelegate> { | 294 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; | |
| 301 // The WKWebView managed by this instance. | 295 // The WKWebView managed by this instance. |
| 302 base::scoped_nsobject<WKWebView> _webView; | 296 base::scoped_nsobject<WKWebView> _webView; |
| 303 // The CRWWebViewProxy is the wrapper to give components access to the | 297 // The CRWWebViewProxy is the wrapper to give components access to the |
| 304 // web view in a controlled and limited way. | 298 // web view in a controlled and limited way. |
| 305 base::scoped_nsobject<CRWWebViewProxyImpl> _webViewProxy; | 299 base::scoped_nsobject<CRWWebViewProxyImpl> _webViewProxy; |
| 306 // The view used to display content. Must outlive |_webViewProxy|. The | 300 // The view used to display content. Must outlive |_webViewProxy|. The |
| 307 // container view should be accessed through this property rather than | 301 // container view should be accessed through this property rather than |
| 308 // |self.view| from within this class, as |self.view| triggers creation while | 302 // |self.view| from within this class, as |self.view| triggers creation while |
| 309 // |self.containerView| will return nil if the view hasn't been instantiated. | 303 // |self.containerView| will return nil if the view hasn't been instantiated. |
| 310 base::scoped_nsobject<CRWWebControllerContainerView> _containerView; | 304 base::scoped_nsobject<CRWWebControllerContainerView> _containerView; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 // |didFailProvisionalNavigation|. | 440 // |didFailProvisionalNavigation|. |
| 447 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo> | 441 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo> |
| 448 _pendingNavigationInfo; | 442 _pendingNavigationInfo; |
| 449 | 443 |
| 450 // The WKNavigation for the most recent load request. | 444 // The WKNavigation for the most recent load request. |
| 451 base::scoped_nsobject<WKNavigation> _latestWKNavigation; | 445 base::scoped_nsobject<WKNavigation> _latestWKNavigation; |
| 452 | 446 |
| 453 // The WKNavigation captured when |stopLoading| was called. Used for reporting | 447 // The WKNavigation captured when |stopLoading| was called. Used for reporting |
| 454 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which | 448 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which |
| 455 // helps with diagnosing a navigation related crash (crbug.com/565457). | 449 // helps with diagnosing a navigation related crash (crbug.com/565457). |
| 456 base::WeakNSObject<WKNavigation> _stoppedWKNavigation; | 450 __weak WKNavigation* _stoppedWKNavigation; |
| 457 | 451 |
| 458 // CRWWebUIManager object for loading WebUI pages. | 452 // CRWWebUIManager object for loading WebUI pages. |
| 459 base::scoped_nsobject<CRWWebUIManager> _webUIManager; | 453 base::scoped_nsobject<CRWWebUIManager> _webUIManager; |
| 460 | 454 |
| 461 // Updates SSLStatus for current navigation item. | 455 // Updates SSLStatus for current navigation item. |
| 462 base::scoped_nsobject<CRWSSLStatusUpdater> _SSLStatusUpdater; | 456 base::scoped_nsobject<CRWSSLStatusUpdater> _SSLStatusUpdater; |
| 463 | 457 |
| 464 // Controller used for certs verification to help with blocking requests with | 458 // Controller used for certs verification to help with blocking requests with |
| 465 // bad SSL cert, presenting SSL interstitials and determining SSL status for | 459 // bad SSL cert, presenting SSL interstitials and determining SSL status for |
| 466 // Navigation Items. | 460 // Navigation Items. |
| 467 base::scoped_nsobject<CRWCertVerificationController> | 461 base::scoped_nsobject<CRWCertVerificationController> |
| 468 _certVerificationController; | 462 _certVerificationController; |
| 469 | 463 |
| 470 // CertVerification errors which happened inside | 464 // CertVerification errors which happened inside |
| 471 // |webView:didReceiveAuthenticationChallenge:completionHandler:|. | 465 // |webView:didReceiveAuthenticationChallenge:completionHandler:|. |
| 472 // Key is leaf-cert/host pair. This storage is used to carry calculated | 466 // Key is leaf-cert/host pair. This storage is used to carry calculated |
| 473 // cert status from |didReceiveAuthenticationChallenge:| to | 467 // cert status from |didReceiveAuthenticationChallenge:| to |
| 474 // |didFailProvisionalNavigation:| delegate method. | 468 // |didFailProvisionalNavigation:| delegate method. |
| 475 std::unique_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; | 469 std::unique_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; |
| 476 } | 470 } |
| 477 | 471 |
| 478 // If |contentView_| contains a web view, this is the web view it contains. | 472 // If |contentView_| contains a web view, this is the web view it contains. |
| 479 // If not, it's nil. | 473 // If not, it's nil. |
| 480 @property(nonatomic, readonly) WKWebView* webView; | 474 @property(weak, nonatomic, readonly) WKWebView* webView; |
|
sdefresne
2016/10/19 18:44:07
ditto regarding ordering of keywords
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
Should this actually be strong?
stkhapugin
2016/10/25 16:16:46
Done.
| |
| 481 // The scroll view of |webView|. | 475 // The scroll view of |webView|. |
| 482 @property(nonatomic, readonly) UIScrollView* webScrollView; | 476 @property(weak, nonatomic, readonly) UIScrollView* webScrollView; |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
Should this actually be strong?
stkhapugin
2016/10/25 16:16:46
Done.
| |
| 483 // The current page state of the web view. Writing to this property | 477 // The current page state of the web view. Writing to this property |
| 484 // asynchronously applies the passed value to the current web view. | 478 // asynchronously applies the passed value to the current web view. |
| 485 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; | 479 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; |
| 486 // The currently displayed native controller, if any. | 480 // The currently displayed native controller, if any. |
| 487 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; | 481 @property(weak, nonatomic, readwrite) id<CRWNativeContent> nativeController; |
|
sdefresne
2016/10/19 18:44:07
ditto regarding readwrite
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
Should this actually be strong?
| |
| 488 // Returns NavigationManager's session controller. | 482 // Returns NavigationManager's session controller. |
| 489 @property(nonatomic, readonly) CRWSessionController* sessionController; | 483 @property(weak, nonatomic, readonly) CRWSessionController* sessionController; |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
Should this actually be strong?
stkhapugin
2016/10/25 16:16:46
Done.
| |
| 490 // Activity indicator group ID for this web controller. | 484 // Activity indicator group ID for this web controller. |
| 491 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; | 485 @property(weak, nonatomic, readonly) NSString* activityIndicatorGroupID; |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
Should this be copy?
stkhapugin
2016/10/25 16:16:46
Done.
| |
| 492 // Dictionary where keys are the names of WKWebView properties and values are | 486 // List of keypaths observed on WKWebView. All KVO-observed keypaths have to |
| 493 // selector names which should be called when a corresponding property has | 487 // be added to this list. |
| 494 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 488 @property(weak, nonatomic, readonly) NSArray* observedKeyPaths; |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
ditto
stkhapugin
2016/10/25 16:16:46
Done.
| |
| 495 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | |
| 496 // changed. | |
| 497 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers; | |
| 498 // Downloader for PassKit files. Lazy initialized. | 489 // Downloader for PassKit files. Lazy initialized. |
| 499 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; | 490 @property(weak, nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
Should this actually be strong?
stkhapugin
2016/10/25 16:16:46
Done.
| |
| 500 | 491 |
| 501 // The web view's view of the current URL. During page transitions | 492 // The web view's view of the current URL. During page transitions |
| 502 // this may not be the same as the session history's view of the current URL. | 493 // this may not be the same as the session history's view of the current URL. |
| 503 // This method can change the state of the CRWWebController, as it will display | 494 // This method can change the state of the CRWWebController, as it will display |
| 504 // an error if the returned URL is not reliable from a security point of view. | 495 // an error if the returned URL is not reliable from a security point of view. |
| 505 // Note that this method is expensive, so it should always be cached locally if | 496 // Note that this method is expensive, so it should always be cached locally if |
| 506 // it's needed multiple times in a method. | 497 // it's needed multiple times in a method. |
| 507 @property(nonatomic, readonly) GURL currentURL; | 498 @property(nonatomic, readonly) GURL currentURL; |
| 508 // Returns the referrer for the current page. | 499 // Returns the referrer for the current page. |
| 509 @property(nonatomic, readonly) web::Referrer currentReferrer; | 500 @property(nonatomic, readonly) web::Referrer currentReferrer; |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1000 const NSTimeInterval kSnapshotOverlayTransition = 0.5; | 991 const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| 1001 | 992 |
| 1002 } // namespace | 993 } // namespace |
| 1003 | 994 |
| 1004 @implementation CRWWebController | 995 @implementation CRWWebController |
| 1005 | 996 |
| 1006 @synthesize webUsageEnabled = _webUsageEnabled; | 997 @synthesize webUsageEnabled = _webUsageEnabled; |
| 1007 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay; | 998 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay; |
| 1008 @synthesize loadPhase = _loadPhase; | 999 @synthesize loadPhase = _loadPhase; |
| 1009 @synthesize shouldSuppressDialogs = _shouldSuppressDialogs; | 1000 @synthesize shouldSuppressDialogs = _shouldSuppressDialogs; |
| 1001 @synthesize delegate = _delegate; | |
| 1002 @synthesize UIDelegate = _UIDelegate; | |
| 1003 @synthesize nativeProvider = _nativeProvider; | |
| 1004 @synthesize swipeRecognizerProvider = _swipeRecognizerProvider; | |
| 1010 | 1005 |
| 1011 - (instancetype)initWithWebState:(WebStateImpl*)webState { | 1006 - (instancetype)initWithWebState:(WebStateImpl*)webState { |
| 1012 self = [super init]; | 1007 self = [super init]; |
| 1013 if (self) { | 1008 if (self) { |
| 1014 _webStateImpl = webState; | 1009 _webStateImpl = webState; |
| 1015 DCHECK(_webStateImpl); | 1010 DCHECK(_webStateImpl); |
| 1016 _webStateImpl->InitializeRequestTracker(self); | 1011 _webStateImpl->InitializeRequestTracker(self); |
| 1017 // Load phase when no WebView present is 'loaded' because this represents | 1012 // Load phase when no WebView present is 'loaded' because this represents |
| 1018 // the idle state. | 1013 // the idle state. |
| 1019 _loadPhase = web::PAGE_LOADED; | 1014 _loadPhase = web::PAGE_LOADED; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1034 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); | 1029 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); |
| 1035 [[NSNotificationCenter defaultCenter] | 1030 [[NSNotificationCenter defaultCenter] |
| 1036 addObserver:self | 1031 addObserver:self |
| 1037 selector:@selector(orientationDidChange) | 1032 selector:@selector(orientationDidChange) |
| 1038 name:UIApplicationDidChangeStatusBarOrientationNotification | 1033 name:UIApplicationDidChangeStatusBarOrientationNotification |
| 1039 object:nil]; | 1034 object:nil]; |
| 1040 } | 1035 } |
| 1041 return self; | 1036 return self; |
| 1042 } | 1037 } |
| 1043 | 1038 |
| 1044 - (id<CRWNativeContentProvider>)nativeProvider { | |
| 1045 return _nativeProvider.get(); | |
| 1046 } | |
| 1047 | |
| 1048 - (void)setNativeProvider:(id<CRWNativeContentProvider>)nativeProvider { | |
| 1049 _nativeProvider.reset(nativeProvider); | |
| 1050 } | |
| 1051 | |
| 1052 - (id<CRWSwipeRecognizerProvider>)swipeRecognizerProvider { | |
| 1053 return _swipeRecognizerProvider.get(); | |
| 1054 } | |
| 1055 | |
| 1056 - (void)setSwipeRecognizerProvider: | |
| 1057 (id<CRWSwipeRecognizerProvider>)swipeRecognizerProvider { | |
| 1058 _swipeRecognizerProvider.reset(swipeRecognizerProvider); | |
| 1059 } | |
| 1060 | |
| 1061 - (WebState*)webState { | 1039 - (WebState*)webState { |
| 1062 return _webStateImpl; | 1040 return _webStateImpl; |
| 1063 } | 1041 } |
| 1064 | 1042 |
| 1065 - (WebStateImpl*)webStateImpl { | 1043 - (WebStateImpl*)webStateImpl { |
| 1066 return _webStateImpl; | 1044 return _webStateImpl; |
| 1067 } | 1045 } |
| 1068 | 1046 |
| 1069 - (void)clearTransientContentView { | 1047 - (void)clearTransientContentView { |
| 1070 // Early return if there is no transient content view. | 1048 // Early return if there is no transient content view. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1081 | 1059 |
| 1082 - (void)showTransientContentView:(CRWContentView*)contentView { | 1060 - (void)showTransientContentView:(CRWContentView*)contentView { |
| 1083 DCHECK(contentView); | 1061 DCHECK(contentView); |
| 1084 DCHECK(contentView.scrollView); | 1062 DCHECK(contentView.scrollView); |
| 1085 // TODO(crbug.com/556848) Reenable DCHECK when |CRWWebControllerContainerView| | 1063 // TODO(crbug.com/556848) Reenable DCHECK when |CRWWebControllerContainerView| |
| 1086 // is restructured so that subviews are not added during |layoutSubviews|. | 1064 // is restructured so that subviews are not added during |layoutSubviews|. |
| 1087 // DCHECK([contentView.scrollView isDescendantOfView:contentView]); | 1065 // DCHECK([contentView.scrollView isDescendantOfView:contentView]); |
| 1088 [_containerView displayTransientContent:contentView]; | 1066 [_containerView displayTransientContent:contentView]; |
| 1089 } | 1067 } |
| 1090 | 1068 |
| 1091 - (id<CRWWebDelegate>)delegate { | |
| 1092 return _delegate.get(); | |
| 1093 } | |
| 1094 | 1069 |
| 1095 - (void)setDelegate:(id<CRWWebDelegate>)delegate { | 1070 - (void)setDelegate:(id<CRWWebDelegate>)delegate { |
| 1096 _delegate.reset(delegate); | 1071 _delegate = delegate; |
| 1097 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { | 1072 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { |
| 1098 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) | 1073 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) |
| 1099 [self.nativeController setDelegate:self]; | 1074 [self.nativeController setDelegate:self]; |
| 1100 else | 1075 else |
| 1101 [self.nativeController setDelegate:nil]; | 1076 [self.nativeController setDelegate:nil]; |
| 1102 } | 1077 } |
| 1103 } | 1078 } |
| 1104 | 1079 |
| 1105 - (id<CRWWebUserInterfaceDelegate>)UIDelegate { | |
| 1106 return _UIDelegate.get(); | |
| 1107 } | |
| 1108 | |
| 1109 - (void)setUIDelegate:(id<CRWWebUserInterfaceDelegate>)UIDelegate { | |
| 1110 _UIDelegate.reset(UIDelegate); | |
| 1111 } | |
| 1112 | |
| 1113 - (void)dealloc { | 1080 - (void)dealloc { |
| 1114 DCHECK([NSThread isMainThread]); | 1081 DCHECK([NSThread isMainThread]); |
| 1115 DCHECK(_isBeingDestroyed); // 'close' must have been called already. | 1082 DCHECK(_isBeingDestroyed); // 'close' must have been called already. |
| 1116 DCHECK(!_webView); | 1083 DCHECK(!_webView); |
| 1084 [_containerView.get() setDelegate:nil]; | |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
You don't need |.get()| here. Also could you pleas
| |
| 1117 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; | 1085 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; |
| 1118 [[_webViewProxy scrollViewProxy] removeObserver:self]; | 1086 [[_webViewProxy scrollViewProxy] removeObserver:self]; |
| 1119 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 1087 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 1120 [super dealloc]; | |
| 1121 } | 1088 } |
| 1122 | 1089 |
| 1123 - (void)dismissKeyboard { | 1090 - (void)dismissKeyboard { |
| 1124 [_webView endEditing:YES]; | 1091 [_webView endEditing:YES]; |
| 1125 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) | 1092 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) |
| 1126 [self.nativeController dismissKeyboard]; | 1093 [self.nativeController dismissKeyboard]; |
| 1127 } | 1094 } |
| 1128 | 1095 |
| 1129 - (id<CRWNativeContent>)nativeController { | 1096 - (id<CRWNativeContent>)nativeController { |
| 1130 return [_containerView nativeController]; | 1097 return [_containerView nativeController]; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1142 [_containerView displayNativeContent:nativeController]; | 1109 [_containerView displayNativeContent:nativeController]; |
| 1143 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; | 1110 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; |
| 1144 } | 1111 } |
| 1145 | 1112 |
| 1146 - (NSString*)activityIndicatorGroupID { | 1113 - (NSString*)activityIndicatorGroupID { |
| 1147 return [NSString | 1114 return [NSString |
| 1148 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@", | 1115 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@", |
| 1149 self.webStateImpl->GetRequestGroupID()]; | 1116 self.webStateImpl->GetRequestGroupID()]; |
| 1150 } | 1117 } |
| 1151 | 1118 |
| 1152 - (NSDictionary*)WKWebViewObservers { | 1119 - (NSArray*)observedKeyPaths { |
| 1153 return @{ | 1120 return @[ |
| 1154 @"certificateChain" : @"webViewSecurityFeaturesDidChange", | 1121 @"certificateChain", @"estimatedProgress", @"hasOnlySecureContent", |
| 1155 @"estimatedProgress" : @"webViewEstimatedProgressDidChange", | 1122 @"loading", @"title", @"URL" |
| 1156 @"hasOnlySecureContent" : @"webViewSecurityFeaturesDidChange", | 1123 ]; |
| 1157 @"loading" : @"webViewLoadingStateDidChange", | |
| 1158 @"title" : @"webViewTitleDidChange", | |
| 1159 @"URL" : @"webViewURLDidChange", | |
| 1160 }; | |
| 1161 } | 1124 } |
| 1162 | 1125 |
| 1163 // NativeControllerDelegate method, called to inform that title has changed. | 1126 // NativeControllerDelegate method, called to inform that title has changed. |
| 1164 - (void)nativeContent:(id)content titleDidChange:(NSString*)title { | 1127 - (void)nativeContent:(id)content titleDidChange:(NSString*)title { |
| 1165 // Responsiveness to delegate method was checked in setDelegate:. | 1128 // Responsiveness to delegate method was checked in setDelegate:. |
| 1166 [_delegate webController:self titleDidChange:title]; | 1129 [_delegate webController:self titleDidChange:title]; |
| 1167 } | 1130 } |
| 1168 | 1131 |
| 1169 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled { | 1132 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled { |
| 1170 if ([self.nativeController | 1133 if ([self.nativeController |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1296 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { | 1259 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { |
| 1297 // We don't want ongoing notification that the long press is held. | 1260 // We don't want ongoing notification that the long press is held. |
| 1298 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) | 1261 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) |
| 1299 return; | 1262 return; |
| 1300 | 1263 |
| 1301 if (![_DOMElementForLastTouch count]) | 1264 if (![_DOMElementForLastTouch count]) |
| 1302 return; | 1265 return; |
| 1303 | 1266 |
| 1304 web::ContextMenuParams params = | 1267 web::ContextMenuParams params = |
| 1305 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()]; | 1268 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()]; |
| 1306 params.view.reset([_webView retain]); | 1269 params.view.reset(_webView); |
| 1307 params.location = [gestureRecognizer locationInView:_webView]; | 1270 params.location = [gestureRecognizer locationInView:_webView]; |
| 1308 if (self.webStateImpl->HandleContextMenu(params)) { | 1271 if (self.webStateImpl->HandleContextMenu(params)) { |
| 1309 // Cancelling all touches has the intended side effect of suppressing the | 1272 // Cancelling all touches has the intended side effect of suppressing the |
| 1310 // system's context menu. | 1273 // system's context menu. |
| 1311 [self cancelAllTouches]; | 1274 [self cancelAllTouches]; |
| 1312 } | 1275 } |
| 1313 } | 1276 } |
| 1314 | 1277 |
| 1315 - (void)cancelAllTouches { | 1278 - (void)cancelAllTouches { |
| 1316 // Disable web view scrolling. | 1279 // Disable web view scrolling. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1339 | 1302 |
| 1340 if (!defaultImage) { | 1303 if (!defaultImage) { |
| 1341 CGRect frame = CGRectMake(0, 0, 2, 2); | 1304 CGRect frame = CGRectMake(0, 0, 2, 2); |
| 1342 UIGraphicsBeginImageContext(frame.size); | 1305 UIGraphicsBeginImageContext(frame.size); |
| 1343 [[UIColor whiteColor] setFill]; | 1306 [[UIColor whiteColor] setFill]; |
| 1344 CGContextFillRect(UIGraphicsGetCurrentContext(), frame); | 1307 CGContextFillRect(UIGraphicsGetCurrentContext(), frame); |
| 1345 | 1308 |
| 1346 UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); | 1309 UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); |
| 1347 UIGraphicsEndImageContext(); | 1310 UIGraphicsEndImageContext(); |
| 1348 | 1311 |
| 1349 defaultImage = | 1312 defaultImage = [result stretchableImageWithLeftCapWidth:1 topCapHeight:1]; |
| 1350 [[result stretchableImageWithLeftCapWidth:1 topCapHeight:1] retain]; | |
| 1351 } | 1313 } |
| 1352 return defaultImage; | 1314 return defaultImage; |
| 1353 } | 1315 } |
| 1354 | 1316 |
| 1355 - (BOOL)canGoBack { | 1317 - (BOOL)canGoBack { |
| 1356 return _webStateImpl->GetNavigationManagerImpl().CanGoBack(); | 1318 return _webStateImpl->GetNavigationManagerImpl().CanGoBack(); |
| 1357 } | 1319 } |
| 1358 | 1320 |
| 1359 - (BOOL)canGoForward { | 1321 - (BOOL)canGoForward { |
| 1360 return _webStateImpl->GetNavigationManagerImpl().CanGoForward(); | 1322 return _webStateImpl->GetNavigationManagerImpl().CanGoForward(); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1578 if (iRecognizer != recognizer) { | 1540 if (iRecognizer != recognizer) { |
| 1579 NSString* description = [iRecognizer description]; | 1541 NSString* description = [iRecognizer description]; |
| 1580 if ([description rangeOfString:fragment].length) { | 1542 if ([description rangeOfString:fragment].length) { |
| 1581 [iRecognizer requireGestureRecognizerToFail:recognizer]; | 1543 [iRecognizer requireGestureRecognizerToFail:recognizer]; |
| 1582 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it | 1544 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it |
| 1583 // is possible for |iRecognizer| to outlive |recognizer| and end up with | 1545 // is possible for |iRecognizer| to outlive |recognizer| and end up with |
| 1584 // a dangling pointer. Add a retaining associative reference to ensure | 1546 // a dangling pointer. Add a retaining associative reference to ensure |
| 1585 // that the lifetimes work out. | 1547 // that the lifetimes work out. |
| 1586 // Note that normally using the value as the key wouldn't make any | 1548 // Note that normally using the value as the key wouldn't make any |
| 1587 // sense, but here it's fine since nothing needs to look up the value. | 1549 // sense, but here it's fine since nothing needs to look up the value. |
| 1588 objc_setAssociatedObject(view, recognizer, recognizer, | 1550 objc_setAssociatedObject(view, (__bridge void*)recognizer, recognizer, |
| 1589 OBJC_ASSOCIATION_RETAIN_NONATOMIC); | 1551 OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
| 1590 } | 1552 } |
| 1591 } | 1553 } |
| 1592 } | 1554 } |
| 1593 } | 1555 } |
| 1594 | 1556 |
| 1595 - (CRWWebController*)createChildWebController { | 1557 - (CRWWebController*)createChildWebController { |
| 1596 CRWWebController* result = [self.delegate webPageOrderedOpen]; | 1558 CRWWebController* result = [self.delegate webPageOrderedOpen]; |
| 1597 DCHECK(!result || result.sessionController.openedByDOM); | 1559 DCHECK(!result || result.sessionController.openedByDOM); |
| 1598 return result; | 1560 return result; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1725 NSString* replaceWebViewUrlJS = | 1687 NSString* replaceWebViewUrlJS = |
| 1726 [self javascriptToReplaceWebViewURL:URL stateObjectJSON:stateObject]; | 1688 [self javascriptToReplaceWebViewURL:URL stateObjectJSON:stateObject]; |
| 1727 std::string outState; | 1689 std::string outState; |
| 1728 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState); | 1690 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState); |
| 1729 NSString* popstateJS = | 1691 NSString* popstateJS = |
| 1730 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);", | 1692 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);", |
| 1731 base::SysUTF8ToNSString(outState)]; | 1693 base::SysUTF8ToNSString(outState)]; |
| 1732 NSString* combinedJS = | 1694 NSString* combinedJS = |
| 1733 [NSString stringWithFormat:@"%@%@", replaceWebViewUrlJS, popstateJS]; | 1695 [NSString stringWithFormat:@"%@%@", replaceWebViewUrlJS, popstateJS]; |
| 1734 GURL blockURL(URL); | 1696 GURL blockURL(URL); |
| 1735 base::WeakNSObject<CRWWebController> weakSelf(self); | 1697 __weak CRWWebController* weakSelf = self; |
| 1736 [self executeJavaScript:combinedJS completionHandler:^(id, NSError*) { | 1698 [self executeJavaScript:combinedJS |
| 1737 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) | 1699 completionHandler:^(id, NSError*) { |
| 1738 return; | 1700 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
nit: Do we still need scoped_nsobject here?
| |
| 1739 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); | 1701 if (!strongSelf || strongSelf.get()->_isBeingDestroyed) |
| 1740 strongSelf.get()->_URLOnStartLoading = blockURL; | 1702 return; |
| 1741 strongSelf.get()->_lastRegisteredRequestURL = blockURL; | 1703 strongSelf.get()->_URLOnStartLoading = blockURL; |
| 1742 }]; | 1704 strongSelf.get()->_lastRegisteredRequestURL = blockURL; |
| 1705 }]; | |
| 1743 } | 1706 } |
| 1744 | 1707 |
| 1745 // Load the current URL in a web view, first ensuring the web view is visible. | 1708 // Load the current URL in a web view, first ensuring the web view is visible. |
| 1746 - (void)loadCurrentURLInWebView { | 1709 - (void)loadCurrentURLInWebView { |
| 1747 // Clear the set of URLs opened in external applications. | 1710 // Clear the set of URLs opened in external applications. |
| 1748 _openedApplicationURL.reset([[NSMutableSet alloc] init]); | 1711 _openedApplicationURL.reset([[NSMutableSet alloc] init]); |
| 1749 | 1712 |
| 1750 // Load the url. The UIWebView delegate callbacks take care of updating the | 1713 // Load the url. The UIWebView delegate callbacks take care of updating the |
| 1751 // session history and UI. | 1714 // session history and UI. |
| 1752 const GURL targetURL([self currentNavigationURL]); | 1715 const GURL targetURL([self currentNavigationURL]); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2230 } else { | 2193 } else { |
| 2231 // Before changing the current session history entry, record the tab state. | 2194 // Before changing the current session history entry, record the tab state. |
| 2232 [self recordStateInHistory]; | 2195 [self recordStateInHistory]; |
| 2233 } | 2196 } |
| 2234 | 2197 |
| 2235 CRWSessionController* sessionController = | 2198 CRWSessionController* sessionController = |
| 2236 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); | 2199 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); |
| 2237 // fromEntry is retained because it has the potential to be released | 2200 // fromEntry is retained because it has the potential to be released |
| 2238 // by goDelta: if it has not been committed. | 2201 // by goDelta: if it has not been committed. |
| 2239 base::scoped_nsobject<CRWSessionEntry> fromEntry( | 2202 base::scoped_nsobject<CRWSessionEntry> fromEntry( |
| 2240 [[sessionController currentEntry] retain]); | 2203 [sessionController currentEntry]); |
| 2241 [sessionController goDelta:delta]; | 2204 [sessionController goDelta:delta]; |
| 2242 if (fromEntry) { | 2205 if (fromEntry) { |
| 2243 [self finishHistoryNavigationFromEntry:fromEntry]; | 2206 [self finishHistoryNavigationFromEntry:fromEntry]; |
| 2244 } | 2207 } |
| 2245 } | 2208 } |
| 2246 | 2209 |
| 2247 - (BOOL)isLoaded { | 2210 - (BOOL)isLoaded { |
| 2248 return _loadPhase == web::PAGE_LOADED; | 2211 return _loadPhase == web::PAGE_LOADED; |
| 2249 } | 2212 } |
| 2250 | 2213 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2430 _webStateImpl->GetMojoInterfaceRegistry(); | 2393 _webStateImpl->GetMojoInterfaceRegistry(); |
| 2431 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); | 2394 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); |
| 2432 } | 2395 } |
| 2433 return _mojoFacade.get(); | 2396 return _mojoFacade.get(); |
| 2434 } | 2397 } |
| 2435 | 2398 |
| 2436 - (CRWPassKitDownloader*)passKitDownloader { | 2399 - (CRWPassKitDownloader*)passKitDownloader { |
| 2437 if (_passKitDownloader) { | 2400 if (_passKitDownloader) { |
| 2438 return _passKitDownloader.get(); | 2401 return _passKitDownloader.get(); |
| 2439 } | 2402 } |
| 2440 base::WeakNSObject<CRWWebController> weakSelf(self); | 2403 __weak CRWWebController* weakSelf = self; |
| 2441 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) { | 2404 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) { |
| 2442 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); | 2405 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
nit: Do we still need scoped_nsobject here?
stkhapugin
2016/10/25 16:16:46
Here and below: no, we shouldn't need scoped_nsobj
| |
| 2443 if (!strongSelf) { | 2406 if (!strongSelf) { |
| 2444 return; | 2407 return; |
| 2445 } | 2408 } |
| 2446 // Cancel load to update web state, since the PassKit download happens | 2409 // Cancel load to update web state, since the PassKit download happens |
| 2447 // through a separate flow. This follows the same flow as when PassKit is | 2410 // through a separate flow. This follows the same flow as when PassKit is |
| 2448 // downloaded through UIWebView. | 2411 // downloaded through UIWebView. |
| 2449 [strongSelf loadCancelled]; | 2412 [strongSelf loadCancelled]; |
| 2450 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:); | 2413 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:); |
| 2451 id<CRWWebDelegate> delegate = [strongSelf delegate]; | 2414 id<CRWWebDelegate> delegate = [strongSelf delegate]; |
| 2452 if ([delegate respondsToSelector:didLoadPassKitObject]) { | 2415 if ([delegate respondsToSelector:didLoadPassKitObject]) { |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3037 // TODO(crbug.com/549301): Improve transition detection. | 3000 // TODO(crbug.com/549301): Improve transition detection. |
| 3038 ui::PageTransition transition = self.userInteractionRegistered | 3001 ui::PageTransition transition = self.userInteractionRegistered |
| 3039 ? ui::PAGE_TRANSITION_LINK | 3002 ? ui::PAGE_TRANSITION_LINK |
| 3040 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 3003 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
| 3041 [self pushStateWithPageURL:pushURL | 3004 [self pushStateWithPageURL:pushURL |
| 3042 stateObject:stateObject | 3005 stateObject:stateObject |
| 3043 transition:transition]; | 3006 transition:transition]; |
| 3044 | 3007 |
| 3045 NSString* replaceWebViewJS = | 3008 NSString* replaceWebViewJS = |
| 3046 [self javascriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; | 3009 [self javascriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; |
| 3047 base::WeakNSObject<CRWWebController> weakSelf(self); | 3010 __weak CRWWebController* weakSelf = self; |
| 3048 [self executeJavaScript:replaceWebViewJS completionHandler:^(id, NSError*) { | 3011 [self executeJavaScript:replaceWebViewJS |
| 3049 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) | 3012 completionHandler:^(id, NSError*) { |
| 3050 return; | 3013 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
nit: Do we still need scoped_nsobject here?
stkhapugin
2016/10/25 16:16:46
we shouldn't need scoped_nsobject in .mm built wit
| |
| 3051 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); | 3014 if (!strongSelf || strongSelf.get()->_isBeingDestroyed) |
| 3052 [strongSelf optOutScrollsToTopForSubviews]; | 3015 return; |
| 3053 // Notify the observers. | 3016 [strongSelf optOutScrollsToTopForSubviews]; |
| 3054 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); | 3017 // Notify the observers. |
| 3055 [strongSelf didFinishNavigation]; | 3018 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); |
| 3056 }]; | 3019 [strongSelf didFinishNavigation]; |
| 3020 }]; | |
| 3057 return YES; | 3021 return YES; |
| 3058 } | 3022 } |
| 3059 | 3023 |
| 3060 - (BOOL)handleWindowHistoryDidReplaceStateMessage: | 3024 - (BOOL)handleWindowHistoryDidReplaceStateMessage: |
| 3061 (base::DictionaryValue*)message | 3025 (base::DictionaryValue*)message |
| 3062 context:(NSDictionary*)context { | 3026 context:(NSDictionary*)context { |
| 3063 DCHECK(_changingHistoryState); | 3027 DCHECK(_changingHistoryState); |
| 3064 _changingHistoryState = NO; | 3028 _changingHistoryState = NO; |
| 3065 | 3029 |
| 3066 std::string pageURL; | 3030 std::string pageURL; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 3096 if (!message->GetString("stateObject", &stateObjectJSON)) { | 3060 if (!message->GetString("stateObject", &stateObjectJSON)) { |
| 3097 DLOG(WARNING) << "JS message parameter not found: stateObject"; | 3061 DLOG(WARNING) << "JS message parameter not found: stateObject"; |
| 3098 return NO; | 3062 return NO; |
| 3099 } | 3063 } |
| 3100 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); | 3064 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); |
| 3101 _URLOnStartLoading = replaceURL; | 3065 _URLOnStartLoading = replaceURL; |
| 3102 _lastRegisteredRequestURL = replaceURL; | 3066 _lastRegisteredRequestURL = replaceURL; |
| 3103 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; | 3067 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; |
| 3104 NSString* replaceStateJS = [self javascriptToReplaceWebViewURL:replaceURL | 3068 NSString* replaceStateJS = [self javascriptToReplaceWebViewURL:replaceURL |
| 3105 stateObjectJSON:stateObject]; | 3069 stateObjectJSON:stateObject]; |
| 3106 base::WeakNSObject<CRWWebController> weakSelf(self); | 3070 __weak CRWWebController* weakSelf = self; |
| 3107 [self executeJavaScript:replaceStateJS completionHandler:^(id, NSError*) { | 3071 [self executeJavaScript:replaceStateJS |
| 3108 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) | 3072 completionHandler:^(id, NSError*) { |
| 3109 return; | 3073 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); |
|
Eugene But (OOO till 7-30)
2016/10/25 02:26:06
nit: Do we still need scoped_nsobject here?
stkhapugin
2016/10/25 16:16:46
we shouldn't need scoped_nsobject in .mm built wit
| |
| 3110 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); | 3074 if (!strongSelf || strongSelf.get()->_isBeingDestroyed) |
| 3111 [strongSelf didFinishNavigation]; | 3075 return; |
| 3112 }]; | 3076 [strongSelf didFinishNavigation]; |
| 3077 }]; | |
| 3113 return YES; | 3078 return YES; |
| 3114 } | 3079 } |
| 3115 | 3080 |
| 3116 #pragma mark - | 3081 #pragma mark - |
| 3117 | 3082 |
| 3118 - (BOOL)wantsKeyboardShield { | 3083 - (BOOL)wantsKeyboardShield { |
| 3119 if ([self.nativeController | 3084 if ([self.nativeController |
| 3120 respondsToSelector:@selector(wantsKeyboardShield)]) { | 3085 respondsToSelector:@selector(wantsKeyboardShield)]) { |
| 3121 return [self.nativeController wantsKeyboardShield]; | 3086 return [self.nativeController wantsKeyboardShield]; |
| 3122 } | 3087 } |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3518 shouldReceiveTouch:(UITouch*)touch { | 3483 shouldReceiveTouch:(UITouch*)touch { |
| 3519 // Expect only _contextMenuRecognizer. | 3484 // Expect only _contextMenuRecognizer. |
| 3520 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); | 3485 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); |
| 3521 | 3486 |
| 3522 // This is custom long press gesture recognizer. By the time the gesture is | 3487 // This is custom long press gesture recognizer. By the time the gesture is |
| 3523 // recognized the web controller needs to know if there is a link under the | 3488 // recognized the web controller needs to know if there is a link under the |
| 3524 // touch. If there a link, the web controller will reject system's context | 3489 // touch. If there a link, the web controller will reject system's context |
| 3525 // menu and show another one. If for some reason context menu info is not | 3490 // menu and show another one. If for some reason context menu info is not |
| 3526 // fetched - system context menu will be shown. | 3491 // fetched - system context menu will be shown. |
| 3527 [self setDOMElementForLastTouch:nil]; | 3492 [self setDOMElementForLastTouch:nil]; |
| 3528 base::WeakNSObject<CRWWebController> weakSelf(self); | 3493 __weak CRWWebController* weakSelf = self; |
| 3529 [self fetchDOMElementAtPoint:[touch locationInView:_webView] | 3494 [self fetchDOMElementAtPoint:[touch locationInView:_webView] |
| 3530 completionHandler:^(NSDictionary* element) { | 3495 completionHandler:^(NSDictionary* element) { |
| 3531 [weakSelf setDOMElementForLastTouch:element]; | 3496 [weakSelf setDOMElementForLastTouch:element]; |
| 3532 }]; | 3497 }]; |
| 3533 return YES; | 3498 return YES; |
| 3534 } | 3499 } |
| 3535 | 3500 |
| 3536 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { | 3501 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { |
| 3537 // Expect only _contextMenuRecognizer. | 3502 // Expect only _contextMenuRecognizer. |
| 3538 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); | 3503 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3633 return [_delegate webController:self | 3598 return [_delegate webController:self |
| 3634 shouldBlockPopupWithURL:popupURL | 3599 shouldBlockPopupWithURL:popupURL |
| 3635 sourceURL:sourceURL]; | 3600 sourceURL:sourceURL]; |
| 3636 } | 3601 } |
| 3637 | 3602 |
| 3638 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { | 3603 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { |
| 3639 const GURL url(windowInfo.url); | 3604 const GURL url(windowInfo.url); |
| 3640 const GURL currentURL([self currentNavigationURL]); | 3605 const GURL currentURL([self currentNavigationURL]); |
| 3641 NSString* windowName = windowInfo.window_name.get(); | 3606 NSString* windowName = windowInfo.window_name.get(); |
| 3642 web::Referrer referrer(currentURL, windowInfo.referrer_policy); | 3607 web::Referrer referrer(currentURL, windowInfo.referrer_policy); |
| 3643 base::WeakNSObject<CRWWebController> weakSelf(self); | 3608 __weak CRWWebController* weakSelf = self; |
| 3644 void (^showPopupHandler)() = ^{ | 3609 void (^showPopupHandler)() = ^{ |
| 3645 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url | 3610 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url |
| 3646 referrer:referrer | 3611 referrer:referrer |
| 3647 windowName:windowName | 3612 windowName:windowName |
| 3648 inBackground:NO]; | 3613 inBackground:NO]; |
| 3649 DCHECK(!child || child.sessionController.openedByDOM); | 3614 DCHECK(!child || child.sessionController.openedByDOM); |
| 3650 }; | 3615 }; |
| 3651 | 3616 |
| 3652 BOOL showPopup = windowInfo.user_is_interacting || | 3617 BOOL showPopup = windowInfo.user_is_interacting || |
| 3653 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]); | 3618 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3948 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders(); | 3913 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders(); |
| 3949 } | 3914 } |
| 3950 | 3915 |
| 3951 #pragma mark - | 3916 #pragma mark - |
| 3952 #pragma mark CRWWebViewScrollViewProxyObserver | 3917 #pragma mark CRWWebViewScrollViewProxyObserver |
| 3953 | 3918 |
| 3954 - (void)webViewScrollViewDidZoom: | 3919 - (void)webViewScrollViewDidZoom: |
| 3955 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | 3920 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| 3956 _pageHasZoomed = YES; | 3921 _pageHasZoomed = YES; |
| 3957 | 3922 |
| 3958 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); | 3923 __weak UIScrollView* weakScrollView = self.webScrollView; |
| 3959 [self extractViewportTagWithCompletion:^( | 3924 [self extractViewportTagWithCompletion:^( |
| 3960 const web::PageViewportState* viewportState) { | 3925 const web::PageViewportState* viewportState) { |
| 3961 if (!weakScrollView) | 3926 if (!weakScrollView) |
| 3962 return; | 3927 return; |
| 3963 base::scoped_nsobject<UIScrollView> scrollView([weakScrollView retain]); | 3928 base::scoped_nsobject<UIScrollView> scrollView(weakScrollView); |
| 3964 if (viewportState && !viewportState->viewport_tag_present() && | 3929 if (viewportState && !viewportState->viewport_tag_present() && |
| 3965 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] && | 3930 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] && |
| 3966 [scrollView zoomScale] > 1.0) { | 3931 [scrollView zoomScale] > 1.0) { |
| 3967 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true); | 3932 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true); |
| 3968 } | 3933 } |
| 3969 }]; | 3934 }]; |
| 3970 } | 3935 } |
| 3971 | 3936 |
| 3972 - (void)webViewScrollViewDidResetContentSize: | 3937 - (void)webViewScrollViewDidResetContentSize: |
| 3973 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | 3938 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4068 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion { | 4033 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion { |
| 4069 DCHECK(completion); | 4034 DCHECK(completion); |
| 4070 web::NavigationItem* currentItem = [self currentNavItem]; | 4035 web::NavigationItem* currentItem = [self currentNavItem]; |
| 4071 if (!currentItem) { | 4036 if (!currentItem) { |
| 4072 completion(nullptr); | 4037 completion(nullptr); |
| 4073 return; | 4038 return; |
| 4074 } | 4039 } |
| 4075 NSString* const kViewportContentQuery = | 4040 NSString* const kViewportContentQuery = |
| 4076 @"var viewport = document.querySelector('meta[name=\"viewport\"]');" | 4041 @"var viewport = document.querySelector('meta[name=\"viewport\"]');" |
| 4077 "viewport ? viewport.content : '';"; | 4042 "viewport ? viewport.content : '';"; |
| 4078 base::WeakNSObject<CRWWebController> weakSelf(self); | 4043 __weak CRWWebController* weakSelf = self; |
| 4079 int itemID = currentItem->GetUniqueID(); | 4044 int itemID = currentItem->GetUniqueID(); |
| 4080 [self executeJavaScript:kViewportContentQuery | 4045 [self executeJavaScript:kViewportContentQuery |
| 4081 completionHandler:^(id viewportContent, NSError*) { | 4046 completionHandler:^(id viewportContent, NSError*) { |
| 4082 web::NavigationItem* item = [weakSelf currentNavItem]; | 4047 web::NavigationItem* item = [weakSelf currentNavItem]; |
| 4083 if (item && item->GetUniqueID() == itemID) { | 4048 if (item && item->GetUniqueID() == itemID) { |
| 4084 web::PageViewportState viewportState( | 4049 web::PageViewportState viewportState( |
| 4085 base::mac::ObjCCast<NSString>(viewportContent)); | 4050 base::mac::ObjCCast<NSString>(viewportContent)); |
| 4086 completion(&viewportState); | 4051 completion(&viewportState); |
| 4087 } else { | 4052 } else { |
| 4088 completion(nullptr); | 4053 completion(nullptr); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 4117 displayState.zoom_state().set_zoom_scale( | 4082 displayState.zoom_state().set_zoom_scale( |
| 4118 displayState.zoom_state().minimum_zoom_scale() + | 4083 displayState.zoom_state().minimum_zoom_scale() + |
| 4119 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference()); | 4084 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference()); |
| 4120 currentItem->SetPageDisplayState(displayState); | 4085 currentItem->SetPageDisplayState(displayState); |
| 4121 [self applyPageDisplayState:currentItem->GetPageDisplayState()]; | 4086 [self applyPageDisplayState:currentItem->GetPageDisplayState()]; |
| 4122 } | 4087 } |
| 4123 | 4088 |
| 4124 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState { | 4089 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState { |
| 4125 if (!displayState.IsValid()) | 4090 if (!displayState.IsValid()) |
| 4126 return; | 4091 return; |
| 4127 base::WeakNSObject<CRWWebController> weakSelf(self); | 4092 __weak CRWWebController* weakSelf = self; |
| 4128 web::PageDisplayState displayStateCopy = displayState; | 4093 web::PageDisplayState displayStateCopy = displayState; |
| 4129 [self extractViewportTagWithCompletion:^( | 4094 [self extractViewportTagWithCompletion:^( |
| 4130 const web::PageViewportState* viewportState) { | 4095 const web::PageViewportState* viewportState) { |
| 4131 if (viewportState) { | 4096 if (viewportState) { |
| 4132 [weakSelf applyPageDisplayState:displayStateCopy | 4097 [weakSelf applyPageDisplayState:displayStateCopy |
| 4133 userScalable:viewportState->user_scalable()]; | 4098 userScalable:viewportState->user_scalable()]; |
| 4134 } | 4099 } |
| 4135 }]; | 4100 }]; |
| 4136 } | 4101 } |
| 4137 | 4102 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4206 (const web::PageScrollState&)scrollState { | 4171 (const web::PageScrollState&)scrollState { |
| 4207 DCHECK(scrollState.IsValid()); | 4172 DCHECK(scrollState.IsValid()); |
| 4208 CGPoint scrollOffset = | 4173 CGPoint scrollOffset = |
| 4209 CGPointMake(scrollState.offset_x(), scrollState.offset_y()); | 4174 CGPointMake(scrollState.offset_x(), scrollState.offset_y()); |
| 4210 if (_loadPhase == web::PAGE_LOADED) { | 4175 if (_loadPhase == web::PAGE_LOADED) { |
| 4211 // If the page is loaded, update the scroll immediately. | 4176 // If the page is loaded, update the scroll immediately. |
| 4212 [self.webScrollView setContentOffset:scrollOffset]; | 4177 [self.webScrollView setContentOffset:scrollOffset]; |
| 4213 } else { | 4178 } else { |
| 4214 // If the page isn't loaded, store the action to update the scroll | 4179 // If the page isn't loaded, store the action to update the scroll |
| 4215 // when the page finishes loading. | 4180 // when the page finishes loading. |
| 4216 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); | 4181 __weak UIScrollView* weakScrollView = self.webScrollView; |
| 4217 base::scoped_nsprotocol<ProceduralBlock> action([^{ | 4182 base::scoped_nsprotocol<ProceduralBlock> action([^{ |
| 4218 [weakScrollView setContentOffset:scrollOffset]; | 4183 [weakScrollView setContentOffset:scrollOffset]; |
| 4219 } copy]); | 4184 } copy]); |
| 4220 [_pendingLoadCompleteActions addObject:action]; | 4185 [_pendingLoadCompleteActions addObject:action]; |
| 4221 } | 4186 } |
| 4222 } | 4187 } |
| 4223 | 4188 |
| 4224 #pragma mark - | 4189 #pragma mark - |
| 4225 #pragma mark Web Page Features | 4190 #pragma mark Web Page Features |
| 4226 | 4191 |
| 4227 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { | 4192 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { |
| 4228 if (!_webView) { | 4193 if (!_webView) { |
| 4229 handler(0); | 4194 handler(0); |
| 4230 return; | 4195 return; |
| 4231 } | 4196 } |
| 4232 | 4197 |
| 4233 [self executeJavaScript:@"__gCrWeb.getPageWidth();" | 4198 [self executeJavaScript:@"__gCrWeb.getPageWidth();" |
| 4234 completionHandler:^(id pageWidth, NSError*) { | 4199 completionHandler:^(id pageWidth, NSError*) { |
| 4235 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]); | 4200 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]); |
| 4236 }]; | 4201 }]; |
| 4237 } | 4202 } |
| 4238 | 4203 |
| 4239 - (void)fetchDOMElementAtPoint:(CGPoint)point | 4204 - (void)fetchDOMElementAtPoint:(CGPoint)point |
| 4240 completionHandler:(void (^)(NSDictionary*))handler { | 4205 completionHandler:(void (^)(NSDictionary*))handler { |
| 4241 DCHECK(handler); | 4206 DCHECK(handler); |
| 4242 // Convert point into web page's coordinate system (which may be scaled and/or | 4207 // Convert point into web page's coordinate system (which may be scaled and/or |
| 4243 // scrolled). | 4208 // scrolled). |
| 4244 CGPoint scrollOffset = self.scrollPosition; | 4209 CGPoint scrollOffset = self.scrollPosition; |
| 4245 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; | 4210 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; |
| 4246 base::WeakNSObject<CRWWebController> weakSelf(self); | 4211 __weak CRWWebController* weakSelf = self; |
| 4247 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { | 4212 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { |
| 4248 CGFloat scale = pageWidth / webViewContentWidth; | 4213 CGFloat scale = pageWidth / webViewContentWidth; |
| 4249 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, | 4214 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, |
| 4250 (point.y + scrollOffset.y) * scale); | 4215 (point.y + scrollOffset.y) * scale); |
| 4251 NSString* const kGetElementScript = | 4216 NSString* const kGetElementScript = |
| 4252 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", | 4217 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", |
| 4253 localPoint.x, localPoint.y]; | 4218 localPoint.x, localPoint.y]; |
| 4254 [weakSelf executeJavaScript:kGetElementScript | 4219 [weakSelf executeJavaScript:kGetElementScript |
| 4255 completionHandler:^(id element, NSError*) { | 4220 completionHandler:^(id element, NSError*) { |
| 4256 handler(base::mac::ObjCCastStrict<NSDictionary>(element)); | 4221 handler(base::mac::ObjCCastStrict<NSDictionary>(element)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 4268 title = @"JavaScript"; | 4233 title = @"JavaScript"; |
| 4269 } else { | 4234 } else { |
| 4270 base::string16 URLText = url_formatter::FormatUrl(params.link_url); | 4235 base::string16 URLText = url_formatter::FormatUrl(params.link_url); |
| 4271 title = base::SysUTF16ToNSString(URLText); | 4236 title = base::SysUTF16ToNSString(URLText); |
| 4272 } | 4237 } |
| 4273 } | 4238 } |
| 4274 NSString* src = element[@"src"]; | 4239 NSString* src = element[@"src"]; |
| 4275 if (src) { | 4240 if (src) { |
| 4276 params.src_url = GURL(base::SysNSStringToUTF8(src)); | 4241 params.src_url = GURL(base::SysNSStringToUTF8(src)); |
| 4277 if (!title) | 4242 if (!title) |
| 4278 title = [[src copy] autorelease]; | 4243 title = [src copy]; |
| 4279 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)]) | 4244 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)]) |
| 4280 title = nil; | 4245 title = nil; |
| 4281 } | 4246 } |
| 4282 NSString* titleAttribute = element[@"title"]; | 4247 NSString* titleAttribute = element[@"title"]; |
| 4283 if (titleAttribute) | 4248 if (titleAttribute) |
| 4284 title = titleAttribute; | 4249 title = titleAttribute; |
| 4285 if (title) { | 4250 if (title) { |
| 4286 params.menu_title.reset([title copy]); | 4251 params.menu_title.reset([title copy]); |
| 4287 } | 4252 } |
| 4288 NSString* referrerPolicy = element[@"referrerPolicy"]; | 4253 NSString* referrerPolicy = element[@"referrerPolicy"]; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4343 [_delegate webControllerDidSuppressDialog:self]; | 4308 [_delegate webControllerDidSuppressDialog:self]; |
| 4344 } | 4309 } |
| 4345 | 4310 |
| 4346 - (void)didBlockPopupWithURL:(GURL)popupURL | 4311 - (void)didBlockPopupWithURL:(GURL)popupURL |
| 4347 sourceURL:(GURL)sourceURL | 4312 sourceURL:(GURL)sourceURL |
| 4348 referrerPolicy:(const std::string&)referrerPolicyString { | 4313 referrerPolicy:(const std::string&)referrerPolicyString { |
| 4349 web::ReferrerPolicy referrerPolicy = | 4314 web::ReferrerPolicy referrerPolicy = |
| 4350 web::ReferrerPolicyFromString(referrerPolicyString); | 4315 web::ReferrerPolicyFromString(referrerPolicyString); |
| 4351 web::Referrer referrer(sourceURL, referrerPolicy); | 4316 web::Referrer referrer(sourceURL, referrerPolicy); |
| 4352 NSString* const kWindowName = @""; // obsoleted | 4317 NSString* const kWindowName = @""; // obsoleted |
| 4353 base::WeakNSObject<CRWWebController> weakSelf(self); | 4318 __weak CRWWebController* weakSelf = self; |
| 4354 void (^showPopupHandler)() = ^{ | 4319 void (^showPopupHandler)() = ^{ |
| 4355 // On Desktop cross-window comunication is not supported for unblocked | 4320 // On Desktop cross-window comunication is not supported for unblocked |
| 4356 // popups; so it's ok to create a new independent page. | 4321 // popups; so it's ok to create a new independent page. |
| 4357 CRWWebController* child = | 4322 CRWWebController* child = |
| 4358 [[weakSelf delegate] webPageOrderedOpen:popupURL | 4323 [[weakSelf delegate] webPageOrderedOpen:popupURL |
| 4359 referrer:referrer | 4324 referrer:referrer |
| 4360 windowName:kWindowName | 4325 windowName:kWindowName |
| 4361 inBackground:NO]; | 4326 inBackground:NO]; |
| 4362 DCHECK(!child || child.sessionController.openedByDOM); | 4327 DCHECK(!child || child.sessionController.openedByDOM); |
| 4363 }; | 4328 }; |
| 4364 | 4329 |
| 4365 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); | 4330 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); |
| 4366 [self.delegate webController:self didBlockPopup:info]; | 4331 [self.delegate webController:self didBlockPopup:info]; |
| 4367 } | 4332 } |
| 4368 | 4333 |
| 4369 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { | 4334 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { |
| 4370 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { | 4335 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { |
| 4371 base::WeakNSObject<CRWWebController> weakSelf(self); | 4336 __weak CRWWebController* weakSelf = self; |
| 4372 dispatch_async(dispatch_get_main_queue(), ^{ | 4337 dispatch_async(dispatch_get_main_queue(), ^{ |
| 4373 [self queryPageReferrerPolicy:^(NSString* policy) { | 4338 [self queryPageReferrerPolicy:^(NSString* policy) { |
| 4374 [weakSelf didBlockPopupWithURL:popupURL | 4339 [weakSelf didBlockPopupWithURL:popupURL |
| 4375 sourceURL:sourceURL | 4340 sourceURL:sourceURL |
| 4376 referrerPolicy:base::SysNSStringToUTF8(policy)]; | 4341 referrerPolicy:base::SysNSStringToUTF8(policy)]; |
| 4377 }]; | 4342 }]; |
| 4378 }); | 4343 }); |
| 4379 } | 4344 } |
| 4380 } | 4345 } |
| 4381 | 4346 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4627 [_containerView addToolbars:_webViewToolbars]; | 4592 [_containerView addToolbars:_webViewToolbars]; |
| 4628 | 4593 |
| 4629 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( | 4594 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( |
| 4630 [[CRWWebViewContentView alloc] initWithWebView:_webView | 4595 [[CRWWebViewContentView alloc] initWithWebView:_webView |
| 4631 scrollView:self.webScrollView]); | 4596 scrollView:self.webScrollView]); |
| 4632 [_containerView displayWebViewContentView:webViewContentView]; | 4597 [_containerView displayWebViewContentView:webViewContentView]; |
| 4633 } | 4598 } |
| 4634 } | 4599 } |
| 4635 | 4600 |
| 4636 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { | 4601 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { |
| 4637 return [web::CreateWKWebView(CGRectZero, config, | 4602 return web::CreateWKWebView(CGRectZero, config, |
| 4638 self.webStateImpl->GetBrowserState(), | 4603 self.webStateImpl->GetBrowserState(), |
| 4639 [self useDesktopUserAgent]) autorelease]; | 4604 [self useDesktopUserAgent]); |
| 4640 } | 4605 } |
| 4641 | 4606 |
| 4642 - (void)setWebView:(WKWebView*)webView { | 4607 - (void)setWebView:(WKWebView*)webView { |
| 4643 DCHECK_NE(_webView.get(), webView); | 4608 DCHECK_NE(_webView.get(), webView); |
| 4644 | 4609 |
| 4645 // Unwind the old web view. | 4610 // Unwind the old web view. |
| 4646 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is | 4611 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is |
| 4647 // fixed. | 4612 // fixed. |
| 4648 CRWWKScriptMessageRouter* messageRouter = | 4613 CRWWKScriptMessageRouter* messageRouter = |
| 4649 [self webViewConfigurationProvider].GetScriptMessageRouter(); | 4614 [self webViewConfigurationProvider].GetScriptMessageRouter(); |
| 4650 if (_webView) { | 4615 if (_webView) { |
| 4651 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; | 4616 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; |
| 4652 } | 4617 } |
| 4653 [_webView setNavigationDelegate:nil]; | 4618 [_webView setNavigationDelegate:nil]; |
| 4654 [_webView setUIDelegate:nil]; | 4619 [_webView setUIDelegate:nil]; |
| 4655 for (NSString* keyPath in self.WKWebViewObservers) { | 4620 for (NSString* keyPath in self.observedKeyPaths) { |
| 4656 [_webView removeObserver:self forKeyPath:keyPath]; | 4621 [_webView removeObserver:self forKeyPath:keyPath]; |
| 4657 } | 4622 } |
| 4658 [self clearActivityIndicatorTasks]; | 4623 [self clearActivityIndicatorTasks]; |
| 4659 | 4624 |
| 4660 _webView.reset([webView retain]); | 4625 _webView.reset(webView); |
| 4661 | 4626 |
| 4662 // Set up the new web view. | 4627 // Set up the new web view. |
| 4663 if (webView) { | 4628 if (webView) { |
| 4664 base::WeakNSObject<CRWWebController> weakSelf(self); | 4629 __weak CRWWebController* weakSelf = self; |
| 4665 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { | 4630 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { |
| 4666 [weakSelf didReceiveScriptMessage:message]; | 4631 [weakSelf didReceiveScriptMessage:message]; |
| 4667 } | 4632 } |
| 4668 name:kScriptMessageName | 4633 name:kScriptMessageName |
| 4669 webView:webView]; | 4634 webView:webView]; |
| 4670 _windowIDJSManager.reset( | 4635 _windowIDJSManager.reset( |
| 4671 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); | 4636 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); |
| 4672 } else { | 4637 } else { |
| 4673 _windowIDJSManager.reset(); | 4638 _windowIDJSManager.reset(); |
| 4674 } | 4639 } |
| 4675 [_webView setNavigationDelegate:self]; | 4640 [_webView setNavigationDelegate:self]; |
| 4676 [_webView setUIDelegate:self]; | 4641 [_webView setUIDelegate:self]; |
| 4677 for (NSString* keyPath in self.WKWebViewObservers) { | 4642 for (NSString* keyPath in self.observedKeyPaths) { |
| 4678 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; | 4643 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; |
| 4679 } | 4644 } |
| 4680 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 4645 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 4681 [self setDocumentURL:_defaultURL]; | 4646 [self setDocumentURL:_defaultURL]; |
| 4682 } | 4647 } |
| 4683 | 4648 |
| 4684 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { | 4649 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| 4685 if (!_webView) | 4650 if (!_webView) |
| 4686 return; | 4651 return; |
| 4687 | 4652 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4723 // This happens during tests. | 4688 // This happens during tests. |
| 4724 if (!_webView) { | 4689 if (!_webView) { |
| 4725 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 4690 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 4726 } | 4691 } |
| 4727 | 4692 |
| 4728 std::string MIMEType = self.webState->GetContentsMimeType(); | 4693 std::string MIMEType = self.webState->GetContentsMimeType(); |
| 4729 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; | 4694 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; |
| 4730 } | 4695 } |
| 4731 | 4696 |
| 4732 - (void)loadRequest:(NSMutableURLRequest*)request { | 4697 - (void)loadRequest:(NSMutableURLRequest*)request { |
| 4733 _latestWKNavigation.reset([[_webView loadRequest:request] retain]); | 4698 _latestWKNavigation.reset([_webView loadRequest:request]); |
| 4734 } | 4699 } |
| 4735 | 4700 |
| 4736 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { | 4701 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { |
| 4737 if (!_POSTRequestLoader) { | 4702 if (!_POSTRequestLoader) { |
| 4738 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); | 4703 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); |
| 4739 } | 4704 } |
| 4740 | 4705 |
| 4741 CRWWKScriptMessageRouter* messageRouter = | 4706 CRWWKScriptMessageRouter* messageRouter = |
| 4742 [self webViewConfigurationProvider].GetScriptMessageRouter(); | 4707 [self webViewConfigurationProvider].GetScriptMessageRouter(); |
| 4743 | 4708 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 4769 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { | 4734 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { |
| 4770 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); | 4735 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); |
| 4771 [self loadHTML:HTML forURL:URL]; | 4736 [self loadHTML:HTML forURL:URL]; |
| 4772 } | 4737 } |
| 4773 | 4738 |
| 4774 - (void)loadHTMLForCurrentURL:(NSString*)HTML { | 4739 - (void)loadHTMLForCurrentURL:(NSString*)HTML { |
| 4775 [self loadHTML:HTML forURL:self.currentURL]; | 4740 [self loadHTML:HTML forURL:self.currentURL]; |
| 4776 } | 4741 } |
| 4777 | 4742 |
| 4778 - (void)stopLoading { | 4743 - (void)stopLoading { |
| 4779 _stoppedWKNavigation.reset(_latestWKNavigation); | 4744 _stoppedWKNavigation = _latestWKNavigation; |
| 4780 | 4745 |
| 4781 base::RecordAction(UserMetricsAction("Stop")); | 4746 base::RecordAction(UserMetricsAction("Stop")); |
| 4782 // Discard the pending and transient entried before notifying the tab model | 4747 // Discard the pending and transient entried before notifying the tab model |
| 4783 // observers of the change via |-abortLoad|. | 4748 // observers of the change via |-abortLoad|. |
| 4784 [[self sessionController] discardNonCommittedEntries]; | 4749 [[self sessionController] discardNonCommittedEntries]; |
| 4785 [self abortLoad]; | 4750 [self abortLoad]; |
| 4786 // If discarding the non-committed entries results in an app-specific URL, | 4751 // If discarding the non-committed entries results in an app-specific URL, |
| 4787 // reload it in its native view. | 4752 // reload it in its native view. |
| 4788 if (!self.nativeController && | 4753 if (!self.nativeController && |
| 4789 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { | 4754 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5067 [self loadWithParams:params]; | 5032 [self loadWithParams:params]; |
| 5068 } | 5033 } |
| 5069 return; | 5034 return; |
| 5070 } else { | 5035 } else { |
| 5071 [self registerLoadRequest:webViewURL]; | 5036 [self registerLoadRequest:webViewURL]; |
| 5072 } | 5037 } |
| 5073 } | 5038 } |
| 5074 // Ensure the URL is registered and loadPhase is as expected. | 5039 // Ensure the URL is registered and loadPhase is as expected. |
| 5075 DCHECK(_lastRegisteredRequestURL == webViewURL); | 5040 DCHECK(_lastRegisteredRequestURL == webViewURL); |
| 5076 DCHECK(self.loadPhase == web::LOAD_REQUESTED); | 5041 DCHECK(self.loadPhase == web::LOAD_REQUESTED); |
| 5077 _latestWKNavigation.reset([navigation retain]); | 5042 _latestWKNavigation.reset(navigation); |
| 5078 } | 5043 } |
| 5079 | 5044 |
| 5080 - (void)webView:(WKWebView*)webView | 5045 - (void)webView:(WKWebView*)webView |
| 5081 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { | 5046 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { |
| 5082 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) | 5047 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) |
| 5083 referrer:[self currentReferrer] | 5048 referrer:[self currentReferrer] |
| 5084 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; | 5049 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; |
| 5085 } | 5050 } |
| 5086 | 5051 |
| 5087 - (void)webView:(WKWebView*)webView | 5052 - (void)webView:(WKWebView*)webView |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5213 } | 5178 } |
| 5214 | 5179 |
| 5215 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) { | 5180 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) { |
| 5216 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 5181 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| 5217 return; | 5182 return; |
| 5218 } | 5183 } |
| 5219 | 5184 |
| 5220 SecTrustRef trust = challenge.protectionSpace.serverTrust; | 5185 SecTrustRef trust = challenge.protectionSpace.serverTrust; |
| 5221 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust, | 5186 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust, |
| 5222 base::scoped_policy::RETAIN); | 5187 base::scoped_policy::RETAIN); |
| 5223 base::WeakNSObject<CRWWebController> weakSelf(self); | 5188 __weak CRWWebController* weakSelf = self; |
| 5224 [_certVerificationController | 5189 [_certVerificationController |
| 5225 decideLoadPolicyForTrust:scopedTrust | 5190 decideLoadPolicyForTrust:scopedTrust |
| 5226 host:challenge.protectionSpace.host | 5191 host:challenge.protectionSpace.host |
| 5227 completionHandler:^(web::CertAcceptPolicy policy, | 5192 completionHandler:^(web::CertAcceptPolicy policy, |
| 5228 net::CertStatus status) { | 5193 net::CertStatus status) { |
| 5229 base::scoped_nsobject<CRWWebController> strongSelf( | 5194 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf); |
| 5230 [weakSelf retain]); | |
| 5231 if (!strongSelf) { | 5195 if (!strongSelf) { |
| 5232 completionHandler( | 5196 completionHandler( |
| 5233 NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 5197 NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| 5234 return; | 5198 return; |
| 5235 } | 5199 } |
| 5236 [strongSelf processAuthChallenge:challenge | 5200 [strongSelf processAuthChallenge:challenge |
| 5237 forCertAcceptPolicy:policy | 5201 forCertAcceptPolicy:policy |
| 5238 certStatus:status | 5202 certStatus:status |
| 5239 completionHandler:completionHandler]; | 5203 completionHandler:completionHandler]; |
| 5240 }]; | 5204 }]; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 5266 } | 5230 } |
| 5267 } | 5231 } |
| 5268 | 5232 |
| 5269 #pragma mark - | 5233 #pragma mark - |
| 5270 #pragma mark KVO Observation | 5234 #pragma mark KVO Observation |
| 5271 | 5235 |
| 5272 - (void)observeValueForKeyPath:(NSString*)keyPath | 5236 - (void)observeValueForKeyPath:(NSString*)keyPath |
| 5273 ofObject:(id)object | 5237 ofObject:(id)object |
| 5274 change:(NSDictionary*)change | 5238 change:(NSDictionary*)change |
| 5275 context:(void*)context { | 5239 context:(void*)context { |
| 5276 NSString* dispatcherSelectorName = self.WKWebViewObservers[keyPath]; | 5240 // All observed keypaths have to be present in |self.observedKeyPaths|. |
| 5277 DCHECK(dispatcherSelectorName); | 5241 DCHECK([self.observedKeyPaths containsObject:keyPath]); |
| 5278 if (dispatcherSelectorName) | 5242 if ([keyPath isEqualToString:@"certificateChain"]) { |
| 5279 [self performSelector:NSSelectorFromString(dispatcherSelectorName)]; | 5243 [self webViewSecurityFeaturesDidChange]; |
| 5244 } else if ([keyPath isEqualToString:@"estimatedProgress"]) { | |
| 5245 [self webViewEstimatedProgressDidChange]; | |
| 5246 } else if ([keyPath isEqualToString:@"hasOnlySecureContent"]) { | |
| 5247 [self webViewSecurityFeaturesDidChange]; | |
| 5248 } else if ([keyPath isEqualToString:@"loading"]) { | |
| 5249 [self webViewLoadingStateDidChange]; | |
| 5250 } else if ([keyPath isEqualToString:@"title"]) { | |
| 5251 [self webViewTitleDidChange]; | |
| 5252 } else if ([keyPath isEqualToString:@"URL"]) { | |
| 5253 [self webViewURLDidChange]; | |
| 5254 } else { | |
| 5255 DCHECK(false); | |
|
sdefresne
2016/10/19 18:44:07
NOTREACHED();
stkhapugin
2016/10/25 16:16:46
Done.
| |
| 5256 } | |
| 5280 } | 5257 } |
| 5281 | 5258 |
| 5282 - (void)webViewEstimatedProgressDidChange { | 5259 - (void)webViewEstimatedProgressDidChange { |
| 5283 if (!_isBeingDestroyed) { | 5260 if (!_isBeingDestroyed) { |
| 5284 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]); | 5261 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]); |
| 5285 } | 5262 } |
| 5286 } | 5263 } |
| 5287 | 5264 |
| 5288 - (void)webViewSecurityFeaturesDidChange { | 5265 - (void)webViewSecurityFeaturesDidChange { |
| 5289 if (self.loadPhase == web::LOAD_REQUESTED) { | 5266 if (self.loadPhase == web::LOAD_REQUESTED) { |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5649 } | 5626 } |
| 5650 | 5627 |
| 5651 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5628 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 5652 } | 5629 } |
| 5653 | 5630 |
| 5654 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5631 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5655 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5632 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5656 } | 5633 } |
| 5657 | 5634 |
| 5658 @end | 5635 @end |
| OLD | NEW |