Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2434853002: [ObjC ARC] Converts crw_web_controller to ARC. (Closed)
Patch Set: d Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
22 #include "base/json/json_reader.h" 21 #include "base/json/json_reader.h"
23 #include "base/json/string_escape.h" 22 #include "base/json/string_escape.h"
24 #include "base/logging.h" 23 #include "base/logging.h"
25 #include "base/mac/bind_objc_block.h" 24 #include "base/mac/bind_objc_block.h"
26 #include "base/mac/bundle_locations.h" 25 #include "base/mac/bundle_locations.h"
27 #include "base/mac/foundation_util.h" 26 #include "base/mac/foundation_util.h"
28 #include "base/mac/objc_property_releaser.h"
29 #include "base/mac/scoped_cftyperef.h" 27 #include "base/mac/scoped_cftyperef.h"
30 #include "base/mac/scoped_nsobject.h" 28 #include "base/mac/scoped_nsobject.h"
31 #include "base/metrics/histogram.h" 29 #include "base/metrics/histogram.h"
32 #include "base/metrics/user_metrics.h" 30 #include "base/metrics/user_metrics.h"
33 #include "base/metrics/user_metrics_action.h" 31 #include "base/metrics/user_metrics_action.h"
34 #include "base/strings/string_util.h" 32 #include "base/strings/string_util.h"
35 #include "base/strings/sys_string_conversions.h" 33 #include "base/strings/sys_string_conversions.h"
36 #include "base/strings/utf_string_conversions.h" 34 #include "base/strings/utf_string_conversions.h"
37 #include "base/time/time.h" 35 #include "base/time/time.h"
38 #include "base/values.h" 36 #include "base/values.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 #import "ios/web/web_state/wk_web_view_security_util.h" 98 #import "ios/web/web_state/wk_web_view_security_util.h"
101 #import "ios/web/webui/crw_web_ui_manager.h" 99 #import "ios/web/webui/crw_web_ui_manager.h"
102 #import "ios/web/webui/mojo_facade.h" 100 #import "ios/web/webui/mojo_facade.h"
103 #import "net/base/mac/url_conversions.h" 101 #import "net/base/mac/url_conversions.h"
104 #include "net/base/net_errors.h" 102 #include "net/base/net_errors.h"
105 #include "services/service_manager/public/cpp/interface_registry.h" 103 #include "services/service_manager/public/cpp/interface_registry.h"
106 #include "ui/base/page_transition_types.h" 104 #include "ui/base/page_transition_types.h"
107 #include "url/gurl.h" 105 #include "url/gurl.h"
108 #include "url/url_constants.h" 106 #include "url/url_constants.h"
109 107
108 #if !defined(__has_feature) || !__has_feature(objc_arc)
109 #error "This file requires ARC support."
110 #endif
111
110 using base::UserMetricsAction; 112 using base::UserMetricsAction;
111 using web::NavigationManager; 113 using web::NavigationManager;
112 using web::NavigationManagerImpl; 114 using web::NavigationManagerImpl;
113 using web::WebState; 115 using web::WebState;
114 using web::WebStateImpl; 116 using web::WebStateImpl;
115 117
116 namespace web { 118 namespace web {
117 NSString* const kContainerViewID = @"Container View"; 119 NSString* const kContainerViewID = @"Container View";
118 const char* kWindowNameSeparator = "#"; 120 const char* kWindowNameSeparator = "#";
119 NSString* const kUserIsInteractingKey = @"userIsInteracting"; 121 NSString* const kUserIsInteractingKey = @"userIsInteracting";
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return 246 return
245 [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; 247 [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo];
246 } 248 }
247 } // namespace 249 } // namespace
248 250
249 #pragma mark - 251 #pragma mark -
250 252
251 // A container object for any navigation information that is only available 253 // A container object for any navigation information that is only available
252 // during pre-commit delegate callbacks, and thus must be held until the 254 // during pre-commit delegate callbacks, and thus must be held until the
253 // navigation commits and the informatino can be used. 255 // navigation commits and the informatino can be used.
254 @interface CRWWebControllerPendingNavigationInfo : NSObject { 256 @interface CRWWebControllerPendingNavigationInfo : NSObject
255 base::mac::ObjCPropertyReleaser
256 _propertyReleaser_CRWWebControllerPendingNavigationInfo;
257 }
258 // The referrer for the page. 257 // The referrer for the page.
259 @property(nonatomic, copy) NSString* referrer; 258 @property(nonatomic, copy) NSString* referrer;
260 // The MIME type for the page. 259 // The MIME type for the page.
261 @property(nonatomic, copy) NSString* MIMEType; 260 @property(nonatomic, copy) NSString* MIMEType;
262 // The navigation type for the load. 261 // The navigation type for the load.
263 @property(nonatomic, assign) WKNavigationType navigationType; 262 @property(nonatomic, assign) WKNavigationType navigationType;
264 // HTTP request method for the load. 263 // HTTP request method for the load.
265 @property(nonatomic, copy) NSString* HTTPMethod; 264 @property(nonatomic, copy) NSString* HTTPMethod;
266 // Whether the pending navigation has been directly cancelled before the 265 // Whether the pending navigation has been directly cancelled before the
267 // navigation is committed. 266 // navigation is committed.
268 // Cancelled navigations should be simply discarded without handling any 267 // Cancelled navigations should be simply discarded without handling any
269 // specific error. 268 // specific error.
270 @property(nonatomic, assign) BOOL cancelled; 269 @property(nonatomic, assign) BOOL cancelled;
271 @end 270 @end
272 271
273 @implementation CRWWebControllerPendingNavigationInfo 272 @implementation CRWWebControllerPendingNavigationInfo
274 @synthesize referrer = _referrer; 273 @synthesize referrer = _referrer;
275 @synthesize MIMEType = _MIMEType; 274 @synthesize MIMEType = _MIMEType;
276 @synthesize navigationType = _navigationType; 275 @synthesize navigationType = _navigationType;
277 @synthesize HTTPMethod = _HTTPMethod; 276 @synthesize HTTPMethod = _HTTPMethod;
278 @synthesize cancelled = _cancelled; 277 @synthesize cancelled = _cancelled;
279 278
280 - (instancetype)init { 279 - (instancetype)init {
281 if ((self = [super init])) { 280 if ((self = [super init])) {
282 _propertyReleaser_CRWWebControllerPendingNavigationInfo.Init(
283 self, [CRWWebControllerPendingNavigationInfo class]);
284 _navigationType = WKNavigationTypeOther; 281 _navigationType = WKNavigationTypeOther;
285 } 282 }
286 return self; 283 return self;
287 } 284 }
288 @end 285 @end
289 286
290 @interface CRWWebController ()<CRWNativeContentDelegate, 287 @interface CRWWebController ()<CRWNativeContentDelegate,
291 CRWSSLStatusUpdaterDataSource, 288 CRWSSLStatusUpdaterDataSource,
292 CRWSSLStatusUpdaterDelegate, 289 CRWSSLStatusUpdaterDelegate,
293 CRWWebControllerContainerViewDelegate, 290 CRWWebControllerContainerViewDelegate,
294 CRWWebViewScrollViewProxyObserver, 291 CRWWebViewScrollViewProxyObserver,
295 WKNavigationDelegate, 292 WKNavigationDelegate,
296 WKUIDelegate> { 293 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. 294 // The WKWebView managed by this instance.
302 base::scoped_nsobject<WKWebView> _webView; 295 base::scoped_nsobject<WKWebView> _webView;
303 // The CRWWebViewProxy is the wrapper to give components access to the 296 // The CRWWebViewProxy is the wrapper to give components access to the
304 // web view in a controlled and limited way. 297 // web view in a controlled and limited way.
305 base::scoped_nsobject<CRWWebViewProxyImpl> _webViewProxy; 298 base::scoped_nsobject<CRWWebViewProxyImpl> _webViewProxy;
306 // The view used to display content. Must outlive |_webViewProxy|. The 299 // The view used to display content. Must outlive |_webViewProxy|. The
307 // container view should be accessed through this property rather than 300 // container view should be accessed through this property rather than
308 // |self.view| from within this class, as |self.view| triggers creation while 301 // |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. 302 // |self.containerView| will return nil if the view hasn't been instantiated.
310 base::scoped_nsobject<CRWWebControllerContainerView> _containerView; 303 base::scoped_nsobject<CRWWebControllerContainerView> _containerView;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // |didFailProvisionalNavigation|. 442 // |didFailProvisionalNavigation|.
450 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo> 443 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo>
451 _pendingNavigationInfo; 444 _pendingNavigationInfo;
452 445
453 // The WKNavigation for the most recent load request. 446 // The WKNavigation for the most recent load request.
454 base::scoped_nsobject<WKNavigation> _latestWKNavigation; 447 base::scoped_nsobject<WKNavigation> _latestWKNavigation;
455 448
456 // The WKNavigation captured when |stopLoading| was called. Used for reporting 449 // The WKNavigation captured when |stopLoading| was called. Used for reporting
457 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which 450 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which
458 // helps with diagnosing a navigation related crash (crbug.com/565457). 451 // helps with diagnosing a navigation related crash (crbug.com/565457).
459 base::WeakNSObject<WKNavigation> _stoppedWKNavigation; 452 __weak WKNavigation* _stoppedWKNavigation;
460 453
461 // CRWWebUIManager object for loading WebUI pages. 454 // CRWWebUIManager object for loading WebUI pages.
462 base::scoped_nsobject<CRWWebUIManager> _webUIManager; 455 base::scoped_nsobject<CRWWebUIManager> _webUIManager;
463 456
464 // Updates SSLStatus for current navigation item. 457 // Updates SSLStatus for current navigation item.
465 base::scoped_nsobject<CRWSSLStatusUpdater> _SSLStatusUpdater; 458 base::scoped_nsobject<CRWSSLStatusUpdater> _SSLStatusUpdater;
466 459
467 // Controller used for certs verification to help with blocking requests with 460 // Controller used for certs verification to help with blocking requests with
468 // bad SSL cert, presenting SSL interstitials and determining SSL status for 461 // bad SSL cert, presenting SSL interstitials and determining SSL status for
469 // Navigation Items. 462 // Navigation Items.
470 base::scoped_nsobject<CRWCertVerificationController> 463 base::scoped_nsobject<CRWCertVerificationController>
471 _certVerificationController; 464 _certVerificationController;
472 465
473 // CertVerification errors which happened inside 466 // CertVerification errors which happened inside
474 // |webView:didReceiveAuthenticationChallenge:completionHandler:|. 467 // |webView:didReceiveAuthenticationChallenge:completionHandler:|.
475 // Key is leaf-cert/host pair. This storage is used to carry calculated 468 // Key is leaf-cert/host pair. This storage is used to carry calculated
476 // cert status from |didReceiveAuthenticationChallenge:| to 469 // cert status from |didReceiveAuthenticationChallenge:| to
477 // |didFailProvisionalNavigation:| delegate method. 470 // |didFailProvisionalNavigation:| delegate method.
478 std::unique_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; 471 std::unique_ptr<CertVerificationErrorsCacheType> _certVerificationErrors;
479 } 472 }
480 473
481 // If |contentView_| contains a web view, this is the web view it contains. 474 // If |contentView_| contains a web view, this is the web view it contains.
482 // If not, it's nil. 475 // If not, it's nil.
483 @property(nonatomic, readonly) WKWebView* webView; 476 @property(nonatomic, strong, readonly) WKWebView* webView;
484 // The scroll view of |webView|. 477 // The scroll view of |webView|.
485 @property(nonatomic, readonly) UIScrollView* webScrollView; 478 @property(nonatomic, strong, readonly) UIScrollView* webScrollView;
486 // The current page state of the web view. Writing to this property 479 // The current page state of the web view. Writing to this property
487 // asynchronously applies the passed value to the current web view. 480 // asynchronously applies the passed value to the current web view.
488 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; 481 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState;
489 // The currently displayed native controller, if any. 482 // The currently displayed native controller, if any.
490 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; 483 @property(nonatomic, strong) id<CRWNativeContent> nativeController;
491 // Returns NavigationManager's session controller. 484 // Returns NavigationManager's session controller.
492 @property(nonatomic, readonly) CRWSessionController* sessionController; 485 @property(nonatomic, strong, readonly) CRWSessionController* sessionController;
493 // Activity indicator group ID for this web controller. 486 // Activity indicator group ID for this web controller.
494 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; 487 @property(nonatomic, copy, readonly) NSString* activityIndicatorGroupID;
495 // Dictionary where keys are the names of WKWebView properties and values are 488 // List of keypaths observed on WKWebView. All KVO-observed keypaths have to
496 // selector names which should be called when a corresponding property has 489 // be added to this list.
497 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that 490 @property(nonatomic, strong, readonly) NSArray* observedKeyPaths;
498 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is
499 // changed.
500 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers;
501 // Downloader for PassKit files. Lazy initialized. 491 // Downloader for PassKit files. Lazy initialized.
502 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; 492 @property(nonatomic, strong, readonly) CRWPassKitDownloader* passKitDownloader;
503 493
504 // The web view's view of the current URL. During page transitions 494 // The web view's view of the current URL. During page transitions
505 // this may not be the same as the session history's view of the current URL. 495 // this may not be the same as the session history's view of the current URL.
506 // This method can change the state of the CRWWebController, as it will display 496 // This method can change the state of the CRWWebController, as it will display
507 // an error if the returned URL is not reliable from a security point of view. 497 // an error if the returned URL is not reliable from a security point of view.
508 // Note that this method is expensive, so it should always be cached locally if 498 // Note that this method is expensive, so it should always be cached locally if
509 // it's needed multiple times in a method. 499 // it's needed multiple times in a method.
510 @property(nonatomic, readonly) GURL currentURL; 500 @property(nonatomic, readonly) GURL currentURL;
511 // Returns the referrer for the current page. 501 // Returns the referrer for the current page.
512 @property(nonatomic, readonly) web::Referrer currentReferrer; 502 @property(nonatomic, readonly) web::Referrer currentReferrer;
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 const NSTimeInterval kSnapshotOverlayTransition = 0.5; 1015 const NSTimeInterval kSnapshotOverlayTransition = 0.5;
1026 1016
1027 } // namespace 1017 } // namespace
1028 1018
1029 @implementation CRWWebController 1019 @implementation CRWWebController
1030 1020
1031 @synthesize webUsageEnabled = _webUsageEnabled; 1021 @synthesize webUsageEnabled = _webUsageEnabled;
1032 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay; 1022 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay;
1033 @synthesize loadPhase = _loadPhase; 1023 @synthesize loadPhase = _loadPhase;
1034 @synthesize shouldSuppressDialogs = _shouldSuppressDialogs; 1024 @synthesize shouldSuppressDialogs = _shouldSuppressDialogs;
1025 @synthesize delegate = _delegate;
1026 @synthesize UIDelegate = _UIDelegate;
1027 @synthesize nativeProvider = _nativeProvider;
1028 @synthesize swipeRecognizerProvider = _swipeRecognizerProvider;
1035 1029
1036 - (instancetype)initWithWebState:(WebStateImpl*)webState { 1030 - (instancetype)initWithWebState:(WebStateImpl*)webState {
1037 self = [super init]; 1031 self = [super init];
1038 if (self) { 1032 if (self) {
1039 _webStateImpl = webState; 1033 _webStateImpl = webState;
1040 DCHECK(_webStateImpl); 1034 DCHECK(_webStateImpl);
1041 _webStateImpl->InitializeRequestTracker(self); 1035 _webStateImpl->InitializeRequestTracker(self);
1042 // Load phase when no WebView present is 'loaded' because this represents 1036 // Load phase when no WebView present is 'loaded' because this represents
1043 // the idle state. 1037 // the idle state.
1044 _loadPhase = web::PAGE_LOADED; 1038 _loadPhase = web::PAGE_LOADED;
(...skipping 14 matching lines...) Expand all
1059 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); 1053 new CertVerificationErrorsCacheType(kMaxCertErrorsCount));
1060 [[NSNotificationCenter defaultCenter] 1054 [[NSNotificationCenter defaultCenter]
1061 addObserver:self 1055 addObserver:self
1062 selector:@selector(orientationDidChange) 1056 selector:@selector(orientationDidChange)
1063 name:UIApplicationDidChangeStatusBarOrientationNotification 1057 name:UIApplicationDidChangeStatusBarOrientationNotification
1064 object:nil]; 1058 object:nil];
1065 } 1059 }
1066 return self; 1060 return self;
1067 } 1061 }
1068 1062
1069 - (id<CRWNativeContentProvider>)nativeProvider {
1070 return _nativeProvider.get();
1071 }
1072
1073 - (void)setNativeProvider:(id<CRWNativeContentProvider>)nativeProvider {
1074 _nativeProvider.reset(nativeProvider);
1075 }
1076
1077 - (id<CRWSwipeRecognizerProvider>)swipeRecognizerProvider {
1078 return _swipeRecognizerProvider.get();
1079 }
1080
1081 - (void)setSwipeRecognizerProvider:
1082 (id<CRWSwipeRecognizerProvider>)swipeRecognizerProvider {
1083 _swipeRecognizerProvider.reset(swipeRecognizerProvider);
1084 }
1085
1086 - (WebState*)webState { 1063 - (WebState*)webState {
1087 return _webStateImpl; 1064 return _webStateImpl;
1088 } 1065 }
1089 1066
1090 - (WebStateImpl*)webStateImpl { 1067 - (WebStateImpl*)webStateImpl {
1091 return _webStateImpl; 1068 return _webStateImpl;
1092 } 1069 }
1093 1070
1094 - (void)clearTransientContentView { 1071 - (void)clearTransientContentView {
1095 // Early return if there is no transient content view. 1072 // Early return if there is no transient content view.
(...skipping 10 matching lines...) Expand all
1106 1083
1107 - (void)showTransientContentView:(CRWContentView*)contentView { 1084 - (void)showTransientContentView:(CRWContentView*)contentView {
1108 DCHECK(contentView); 1085 DCHECK(contentView);
1109 DCHECK(contentView.scrollView); 1086 DCHECK(contentView.scrollView);
1110 // TODO(crbug.com/556848) Reenable DCHECK when |CRWWebControllerContainerView| 1087 // TODO(crbug.com/556848) Reenable DCHECK when |CRWWebControllerContainerView|
1111 // is restructured so that subviews are not added during |layoutSubviews|. 1088 // is restructured so that subviews are not added during |layoutSubviews|.
1112 // DCHECK([contentView.scrollView isDescendantOfView:contentView]); 1089 // DCHECK([contentView.scrollView isDescendantOfView:contentView]);
1113 [_containerView displayTransientContent:contentView]; 1090 [_containerView displayTransientContent:contentView];
1114 } 1091 }
1115 1092
1116 - (id<CRWWebDelegate>)delegate {
1117 return _delegate.get();
1118 }
1119 1093
1120 - (void)setDelegate:(id<CRWWebDelegate>)delegate { 1094 - (void)setDelegate:(id<CRWWebDelegate>)delegate {
1121 _delegate.reset(delegate); 1095 _delegate = delegate;
1122 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { 1096 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) {
1123 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) 1097 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)])
1124 [self.nativeController setDelegate:self]; 1098 [self.nativeController setDelegate:self];
1125 else 1099 else
1126 [self.nativeController setDelegate:nil]; 1100 [self.nativeController setDelegate:nil];
1127 } 1101 }
1128 } 1102 }
1129 1103
1130 - (id<CRWWebUserInterfaceDelegate>)UIDelegate {
1131 return _UIDelegate.get();
1132 }
1133
1134 - (void)setUIDelegate:(id<CRWWebUserInterfaceDelegate>)UIDelegate {
1135 _UIDelegate.reset(UIDelegate);
1136 }
1137
1138 - (void)dealloc { 1104 - (void)dealloc {
1139 DCHECK([NSThread isMainThread]); 1105 DCHECK([NSThread isMainThread]);
1140 DCHECK(_isBeingDestroyed); // 'close' must have been called already. 1106 DCHECK(_isBeingDestroyed); // 'close' must have been called already.
1141 DCHECK(!_webView); 1107 DCHECK(!_webView);
1142 // TODO(crbug.com/662860): Don't set the delegate to nil. 1108 // TODO(crbug.com/662860): Don't set the delegate to nil.
1143 [_containerView setDelegate:nil]; 1109 [_containerView setDelegate:nil];
1144 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; 1110 _touchTrackingRecognizer.get().touchTrackingDelegate = nil;
1145 [[_webViewProxy scrollViewProxy] removeObserver:self]; 1111 [[_webViewProxy scrollViewProxy] removeObserver:self];
1146 [[NSNotificationCenter defaultCenter] removeObserver:self]; 1112 [[NSNotificationCenter defaultCenter] removeObserver:self];
1147 [super dealloc];
1148 } 1113 }
1149 1114
1150 - (void)dismissKeyboard { 1115 - (void)dismissKeyboard {
1151 [_webView endEditing:YES]; 1116 [_webView endEditing:YES];
1152 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) 1117 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)])
1153 [self.nativeController dismissKeyboard]; 1118 [self.nativeController dismissKeyboard];
1154 } 1119 }
1155 1120
1156 - (id<CRWNativeContent>)nativeController { 1121 - (id<CRWNativeContent>)nativeController {
1157 return [_containerView nativeController]; 1122 return [_containerView nativeController];
(...skipping 11 matching lines...) Expand all
1169 [_containerView displayNativeContent:nativeController]; 1134 [_containerView displayNativeContent:nativeController];
1170 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; 1135 [self setNativeControllerWebUsageEnabled:_webUsageEnabled];
1171 } 1136 }
1172 1137
1173 - (NSString*)activityIndicatorGroupID { 1138 - (NSString*)activityIndicatorGroupID {
1174 return [NSString 1139 return [NSString
1175 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@", 1140 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@",
1176 self.webStateImpl->GetRequestGroupID()]; 1141 self.webStateImpl->GetRequestGroupID()];
1177 } 1142 }
1178 1143
1179 - (NSDictionary*)WKWebViewObservers { 1144 - (NSArray*)observedKeyPaths {
1180 return @{ 1145 return @[
1181 @"certificateChain" : @"webViewSecurityFeaturesDidChange", 1146 @"certificateChain", @"estimatedProgress", @"hasOnlySecureContent",
1182 @"estimatedProgress" : @"webViewEstimatedProgressDidChange", 1147 @"loading", @"title", @"URL"
1183 @"hasOnlySecureContent" : @"webViewSecurityFeaturesDidChange", 1148 ];
1184 @"loading" : @"webViewLoadingStateDidChange",
1185 @"title" : @"webViewTitleDidChange",
1186 @"URL" : @"webViewURLDidChange",
1187 };
1188 } 1149 }
1189 1150
1190 // NativeControllerDelegate method, called to inform that title has changed. 1151 // NativeControllerDelegate method, called to inform that title has changed.
1191 - (void)nativeContent:(id)content titleDidChange:(NSString*)title { 1152 - (void)nativeContent:(id)content titleDidChange:(NSString*)title {
1192 // Responsiveness to delegate method was checked in setDelegate:. 1153 // Responsiveness to delegate method was checked in setDelegate:.
1193 [_delegate webController:self titleDidChange:title]; 1154 [_delegate webController:self titleDidChange:title];
1194 } 1155 }
1195 1156
1196 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled { 1157 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled {
1197 if ([self.nativeController 1158 if ([self.nativeController
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { 1284 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer {
1324 // We don't want ongoing notification that the long press is held. 1285 // We don't want ongoing notification that the long press is held.
1325 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) 1286 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan)
1326 return; 1287 return;
1327 1288
1328 if (![_DOMElementForLastTouch count]) 1289 if (![_DOMElementForLastTouch count])
1329 return; 1290 return;
1330 1291
1331 web::ContextMenuParams params = 1292 web::ContextMenuParams params =
1332 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()]; 1293 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()];
1333 params.view.reset([_webView retain]); 1294 params.view.reset(_webView);
1334 params.location = [gestureRecognizer locationInView:_webView]; 1295 params.location = [gestureRecognizer locationInView:_webView];
1335 if (self.webStateImpl->HandleContextMenu(params)) { 1296 if (self.webStateImpl->HandleContextMenu(params)) {
1336 // Cancelling all touches has the intended side effect of suppressing the 1297 // Cancelling all touches has the intended side effect of suppressing the
1337 // system's context menu. 1298 // system's context menu.
1338 [self cancelAllTouches]; 1299 [self cancelAllTouches];
1339 } 1300 }
1340 } 1301 }
1341 1302
1342 - (void)cancelAllTouches { 1303 - (void)cancelAllTouches {
1343 // Disable web view scrolling. 1304 // Disable web view scrolling.
(...skipping 22 matching lines...) Expand all
1366 1327
1367 if (!defaultImage) { 1328 if (!defaultImage) {
1368 CGRect frame = CGRectMake(0, 0, 2, 2); 1329 CGRect frame = CGRectMake(0, 0, 2, 2);
1369 UIGraphicsBeginImageContext(frame.size); 1330 UIGraphicsBeginImageContext(frame.size);
1370 [[UIColor whiteColor] setFill]; 1331 [[UIColor whiteColor] setFill];
1371 CGContextFillRect(UIGraphicsGetCurrentContext(), frame); 1332 CGContextFillRect(UIGraphicsGetCurrentContext(), frame);
1372 1333
1373 UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); 1334 UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
1374 UIGraphicsEndImageContext(); 1335 UIGraphicsEndImageContext();
1375 1336
1376 defaultImage = 1337 defaultImage = [result stretchableImageWithLeftCapWidth:1 topCapHeight:1];
1377 [[result stretchableImageWithLeftCapWidth:1 topCapHeight:1] retain];
1378 } 1338 }
1379 return defaultImage; 1339 return defaultImage;
1380 } 1340 }
1381 1341
1382 - (BOOL)canGoBack { 1342 - (BOOL)canGoBack {
1383 return _webStateImpl->GetNavigationManagerImpl().CanGoBack(); 1343 return _webStateImpl->GetNavigationManagerImpl().CanGoBack();
1384 } 1344 }
1385 1345
1386 - (BOOL)canGoForward { 1346 - (BOOL)canGoForward {
1387 return _webStateImpl->GetNavigationManagerImpl().CanGoForward(); 1347 return _webStateImpl->GetNavigationManagerImpl().CanGoForward();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 if (iRecognizer != recognizer) { 1565 if (iRecognizer != recognizer) {
1606 NSString* description = [iRecognizer description]; 1566 NSString* description = [iRecognizer description];
1607 if ([description rangeOfString:fragment].length) { 1567 if ([description rangeOfString:fragment].length) {
1608 [iRecognizer requireGestureRecognizerToFail:recognizer]; 1568 [iRecognizer requireGestureRecognizerToFail:recognizer];
1609 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it 1569 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it
1610 // is possible for |iRecognizer| to outlive |recognizer| and end up with 1570 // is possible for |iRecognizer| to outlive |recognizer| and end up with
1611 // a dangling pointer. Add a retaining associative reference to ensure 1571 // a dangling pointer. Add a retaining associative reference to ensure
1612 // that the lifetimes work out. 1572 // that the lifetimes work out.
1613 // Note that normally using the value as the key wouldn't make any 1573 // Note that normally using the value as the key wouldn't make any
1614 // sense, but here it's fine since nothing needs to look up the value. 1574 // sense, but here it's fine since nothing needs to look up the value.
1615 objc_setAssociatedObject(view, recognizer, recognizer, 1575 objc_setAssociatedObject(view, (__bridge void*)recognizer, recognizer,
1616 OBJC_ASSOCIATION_RETAIN_NONATOMIC); 1576 OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1617 } 1577 }
1618 } 1578 }
1619 } 1579 }
1620 } 1580 }
1621 1581
1622 - (CRWWebController*)createChildWebController { 1582 - (CRWWebController*)createChildWebController {
1623 CRWWebController* result = [self.delegate webPageOrderedOpen]; 1583 CRWWebController* result = [self.delegate webPageOrderedOpen];
1624 DCHECK(!result || result.sessionController.openedByDOM); 1584 DCHECK(!result || result.sessionController.openedByDOM);
1625 return result; 1585 return result;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 [script 1777 [script
1818 appendString:[self javaScriptToDispatchPopStateWithObject:stateObject]]; 1778 appendString:[self javaScriptToDispatchPopStateWithObject:stateObject]];
1819 } 1779 }
1820 if (dispatchHashChange) { 1780 if (dispatchHashChange) {
1821 web::NavigationItemImpl* previousItem = 1781 web::NavigationItemImpl* previousItem =
1822 self.sessionController.previousEntry.navigationItemImpl; 1782 self.sessionController.previousEntry.navigationItemImpl;
1823 const GURL oldURL = previousItem ? previousItem->GetURL() : GURL(); 1783 const GURL oldURL = previousItem ? previousItem->GetURL() : GURL();
1824 [script appendString:[self javaScriptToDispatchHashChangeWithOldURL:oldURL 1784 [script appendString:[self javaScriptToDispatchHashChangeWithOldURL:oldURL
1825 newURL:URL]]; 1785 newURL:URL]];
1826 } 1786 }
1827 base::WeakNSObject<CRWWebController> weakSelf(self); 1787 __weak CRWWebController* weakSelf = self;
1828 [self executeJavaScript:script 1788 [self executeJavaScript:script
1829 completionHandler:^(id, NSError*) { 1789 completionHandler:^(id, NSError*) {
1830 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) 1790 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
1791 if (!strongSelf || strongSelf.get()->_isBeingDestroyed)
1831 return; 1792 return;
1832 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]);
1833 strongSelf.get()->_URLOnStartLoading = URL; 1793 strongSelf.get()->_URLOnStartLoading = URL;
1834 strongSelf.get()->_lastRegisteredRequestURL = URL; 1794 strongSelf.get()->_lastRegisteredRequestURL = URL;
1835 }]; 1795 }];
1836 } 1796 }
1837 1797
1838 // Load the current URL in a web view, first ensuring the web view is visible. 1798 // Load the current URL in a web view, first ensuring the web view is visible.
1839 - (void)loadCurrentURLInWebView { 1799 - (void)loadCurrentURLInWebView {
1840 // Clear the set of URLs opened in external applications. 1800 // Clear the set of URLs opened in external applications.
1841 _openedApplicationURL.reset([[NSMutableSet alloc] init]); 1801 _openedApplicationURL.reset([[NSMutableSet alloc] init]);
1842 1802
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
2303 2263
2304 if (delta >= 0 || !_webStateImpl->IsShowingWebInterstitial()) { 2264 if (delta >= 0 || !_webStateImpl->IsShowingWebInterstitial()) {
2305 [self recordStateInHistory]; 2265 [self recordStateInHistory];
2306 } 2266 }
2307 2267
2308 CRWSessionController* sessionController = 2268 CRWSessionController* sessionController =
2309 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); 2269 _webStateImpl->GetNavigationManagerImpl().GetSessionController();
2310 // fromEntry is retained because it has the potential to be released 2270 // fromEntry is retained because it has the potential to be released
2311 // by goDelta: if it has not been committed. 2271 // by goDelta: if it has not been committed.
2312 base::scoped_nsobject<CRWSessionEntry> fromEntry( 2272 base::scoped_nsobject<CRWSessionEntry> fromEntry(
2313 [[sessionController currentEntry] retain]); 2273 [sessionController currentEntry]);
2314 [sessionController goDelta:delta]; 2274 [sessionController goDelta:delta];
2315 if (fromEntry) { 2275 if (fromEntry) {
2316 [self finishHistoryNavigationFromEntry:fromEntry]; 2276 [self finishHistoryNavigationFromEntry:fromEntry];
2317 } 2277 }
2318 } 2278 }
2319 2279
2320 - (void)goToItemAtIndex:(int)index { 2280 - (void)goToItemAtIndex:(int)index {
2321 NSArray* entries = self.sessionController.entries; 2281 NSArray* entries = self.sessionController.entries;
2322 DCHECK_LT(static_cast<NSUInteger>(index), entries.count); 2282 DCHECK_LT(static_cast<NSUInteger>(index), entries.count);
2323 DCHECK_GE(index, 0); 2283 DCHECK_GE(index, 0);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 _webStateImpl->GetMojoInterfaceRegistry(); 2471 _webStateImpl->GetMojoInterfaceRegistry();
2512 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); 2472 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self));
2513 } 2473 }
2514 return _mojoFacade.get(); 2474 return _mojoFacade.get();
2515 } 2475 }
2516 2476
2517 - (CRWPassKitDownloader*)passKitDownloader { 2477 - (CRWPassKitDownloader*)passKitDownloader {
2518 if (_passKitDownloader) { 2478 if (_passKitDownloader) {
2519 return _passKitDownloader.get(); 2479 return _passKitDownloader.get();
2520 } 2480 }
2521 base::WeakNSObject<CRWWebController> weakSelf(self); 2481 __weak CRWWebController* weakSelf = self;
2522 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) { 2482 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) {
2523 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); 2483 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
2524 if (!strongSelf) { 2484 if (!strongSelf) {
2525 return; 2485 return;
2526 } 2486 }
2527 // Cancel load to update web state, since the PassKit download happens 2487 // Cancel load to update web state, since the PassKit download happens
2528 // through a separate flow. This follows the same flow as when PassKit is 2488 // through a separate flow. This follows the same flow as when PassKit is
2529 // downloaded through UIWebView. 2489 // downloaded through UIWebView.
2530 [strongSelf loadCancelled]; 2490 [strongSelf loadCancelled];
2531 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:); 2491 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:);
2532 id<CRWWebDelegate> delegate = [strongSelf delegate]; 2492 id<CRWWebDelegate> delegate = [strongSelf delegate];
2533 if ([delegate respondsToSelector:didLoadPassKitObject]) { 2493 if ([delegate respondsToSelector:didLoadPassKitObject]) {
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
3130 // TODO(crbug.com/549301): Improve transition detection. 3090 // TODO(crbug.com/549301): Improve transition detection.
3131 ui::PageTransition transition = self.userInteractionRegistered 3091 ui::PageTransition transition = self.userInteractionRegistered
3132 ? ui::PAGE_TRANSITION_LINK 3092 ? ui::PAGE_TRANSITION_LINK
3133 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; 3093 : ui::PAGE_TRANSITION_CLIENT_REDIRECT;
3134 [self pushStateWithPageURL:pushURL 3094 [self pushStateWithPageURL:pushURL
3135 stateObject:stateObject 3095 stateObject:stateObject
3136 transition:transition]; 3096 transition:transition];
3137 3097
3138 NSString* replaceWebViewJS = 3098 NSString* replaceWebViewJS =
3139 [self javaScriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; 3099 [self javaScriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject];
3140 base::WeakNSObject<CRWWebController> weakSelf(self); 3100 __weak CRWWebController* weakSelf = self;
3141 [self executeJavaScript:replaceWebViewJS completionHandler:^(id, NSError*) { 3101 [self executeJavaScript:replaceWebViewJS
3142 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) 3102 completionHandler:^(id, NSError*) {
3143 return; 3103 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
3144 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); 3104 if (!strongSelf || strongSelf.get()->_isBeingDestroyed)
3145 [strongSelf optOutScrollsToTopForSubviews]; 3105 return;
3146 // Notify the observers. 3106 [strongSelf optOutScrollsToTopForSubviews];
3147 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); 3107 // Notify the observers.
3148 [strongSelf didFinishNavigation]; 3108 strongSelf.get()->_webStateImpl->OnHistoryStateChanged();
3149 }]; 3109 [strongSelf didFinishNavigation];
3110 }];
3111
3150 return YES; 3112 return YES;
3151 } 3113 }
3152 3114
3153 - (BOOL)handleWindowHistoryDidReplaceStateMessage: 3115 - (BOOL)handleWindowHistoryDidReplaceStateMessage:
3154 (base::DictionaryValue*)message 3116 (base::DictionaryValue*)message
3155 context:(NSDictionary*)context { 3117 context:(NSDictionary*)context {
3156 DCHECK(_changingHistoryState); 3118 DCHECK(_changingHistoryState);
3157 _changingHistoryState = NO; 3119 _changingHistoryState = NO;
3158 3120
3159 std::string pageURL; 3121 std::string pageURL;
(...skipping 29 matching lines...) Expand all
3189 if (!message->GetString("stateObject", &stateObjectJSON)) { 3151 if (!message->GetString("stateObject", &stateObjectJSON)) {
3190 DLOG(WARNING) << "JS message parameter not found: stateObject"; 3152 DLOG(WARNING) << "JS message parameter not found: stateObject";
3191 return NO; 3153 return NO;
3192 } 3154 }
3193 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); 3155 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON);
3194 _URLOnStartLoading = replaceURL; 3156 _URLOnStartLoading = replaceURL;
3195 _lastRegisteredRequestURL = replaceURL; 3157 _lastRegisteredRequestURL = replaceURL;
3196 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; 3158 [self replaceStateWithPageURL:replaceURL stateObject:stateObject];
3197 NSString* replaceStateJS = [self javaScriptToReplaceWebViewURL:replaceURL 3159 NSString* replaceStateJS = [self javaScriptToReplaceWebViewURL:replaceURL
3198 stateObjectJSON:stateObject]; 3160 stateObjectJSON:stateObject];
3199 base::WeakNSObject<CRWWebController> weakSelf(self); 3161 __weak CRWWebController* weakSelf = self;
3200 [self executeJavaScript:replaceStateJS completionHandler:^(id, NSError*) { 3162 [self executeJavaScript:replaceStateJS
3201 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) 3163 completionHandler:^(id, NSError*) {
3202 return; 3164 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
3203 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); 3165 if (!strongSelf || strongSelf.get()->_isBeingDestroyed)
3204 [strongSelf didFinishNavigation]; 3166 return;
3205 }]; 3167 [strongSelf didFinishNavigation];
3168 }];
3206 return YES; 3169 return YES;
3207 } 3170 }
3208 3171
3209 #pragma mark - 3172 #pragma mark -
3210 3173
3211 - (BOOL)wantsKeyboardShield { 3174 - (BOOL)wantsKeyboardShield {
3212 if ([self.nativeController 3175 if ([self.nativeController
3213 respondsToSelector:@selector(wantsKeyboardShield)]) { 3176 respondsToSelector:@selector(wantsKeyboardShield)]) {
3214 return [self.nativeController wantsKeyboardShield]; 3177 return [self.nativeController wantsKeyboardShield];
3215 } 3178 }
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 shouldReceiveTouch:(UITouch*)touch { 3574 shouldReceiveTouch:(UITouch*)touch {
3612 // Expect only _contextMenuRecognizer. 3575 // Expect only _contextMenuRecognizer.
3613 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); 3576 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]);
3614 3577
3615 // This is custom long press gesture recognizer. By the time the gesture is 3578 // This is custom long press gesture recognizer. By the time the gesture is
3616 // recognized the web controller needs to know if there is a link under the 3579 // recognized the web controller needs to know if there is a link under the
3617 // touch. If there a link, the web controller will reject system's context 3580 // touch. If there a link, the web controller will reject system's context
3618 // menu and show another one. If for some reason context menu info is not 3581 // menu and show another one. If for some reason context menu info is not
3619 // fetched - system context menu will be shown. 3582 // fetched - system context menu will be shown.
3620 [self setDOMElementForLastTouch:nil]; 3583 [self setDOMElementForLastTouch:nil];
3621 base::WeakNSObject<CRWWebController> weakSelf(self); 3584 __weak CRWWebController* weakSelf = self;
3622 [self fetchDOMElementAtPoint:[touch locationInView:_webView] 3585 [self fetchDOMElementAtPoint:[touch locationInView:_webView]
3623 completionHandler:^(NSDictionary* element) { 3586 completionHandler:^(NSDictionary* element) {
3624 [weakSelf setDOMElementForLastTouch:element]; 3587 [weakSelf setDOMElementForLastTouch:element];
3625 }]; 3588 }];
3626 return YES; 3589 return YES;
3627 } 3590 }
3628 3591
3629 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { 3592 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
3630 // Expect only _contextMenuRecognizer. 3593 // Expect only _contextMenuRecognizer.
3631 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); 3594 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3726 return [_delegate webController:self 3689 return [_delegate webController:self
3727 shouldBlockPopupWithURL:popupURL 3690 shouldBlockPopupWithURL:popupURL
3728 sourceURL:sourceURL]; 3691 sourceURL:sourceURL];
3729 } 3692 }
3730 3693
3731 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { 3694 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo {
3732 const GURL url(windowInfo.url); 3695 const GURL url(windowInfo.url);
3733 const GURL currentURL([self currentNavigationURL]); 3696 const GURL currentURL([self currentNavigationURL]);
3734 NSString* windowName = windowInfo.window_name.get(); 3697 NSString* windowName = windowInfo.window_name.get();
3735 web::Referrer referrer(currentURL, windowInfo.referrer_policy); 3698 web::Referrer referrer(currentURL, windowInfo.referrer_policy);
3736 base::WeakNSObject<CRWWebController> weakSelf(self); 3699 __weak CRWWebController* weakSelf = self;
3737 void (^showPopupHandler)() = ^{ 3700 void (^showPopupHandler)() = ^{
3738 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url 3701 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url
3739 referrer:referrer 3702 referrer:referrer
3740 windowName:windowName 3703 windowName:windowName
3741 inBackground:NO]; 3704 inBackground:NO];
3742 DCHECK(!child || child.sessionController.openedByDOM); 3705 DCHECK(!child || child.sessionController.openedByDOM);
3743 }; 3706 };
3744 3707
3745 BOOL showPopup = windowInfo.user_is_interacting || 3708 BOOL showPopup = windowInfo.user_is_interacting ||
3746 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]); 3709 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
4041 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders(); 4004 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders();
4042 } 4005 }
4043 4006
4044 #pragma mark - 4007 #pragma mark -
4045 #pragma mark CRWWebViewScrollViewProxyObserver 4008 #pragma mark CRWWebViewScrollViewProxyObserver
4046 4009
4047 - (void)webViewScrollViewDidZoom: 4010 - (void)webViewScrollViewDidZoom:
4048 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { 4011 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy {
4049 _pageHasZoomed = YES; 4012 _pageHasZoomed = YES;
4050 4013
4051 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); 4014 __weak UIScrollView* weakScrollView = self.webScrollView;
4052 [self extractViewportTagWithCompletion:^( 4015 [self extractViewportTagWithCompletion:^(
4053 const web::PageViewportState* viewportState) { 4016 const web::PageViewportState* viewportState) {
4054 if (!weakScrollView) 4017 if (!weakScrollView)
4055 return; 4018 return;
4056 base::scoped_nsobject<UIScrollView> scrollView([weakScrollView retain]); 4019 base::scoped_nsobject<UIScrollView> scrollView(weakScrollView);
4057 if (viewportState && !viewportState->viewport_tag_present() && 4020 if (viewportState && !viewportState->viewport_tag_present() &&
4058 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] && 4021 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] &&
4059 [scrollView zoomScale] > 1.0) { 4022 [scrollView zoomScale] > 1.0) {
4060 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true); 4023 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true);
4061 } 4024 }
4062 }]; 4025 }];
4063 } 4026 }
4064 4027
4065 - (void)webViewScrollViewDidResetContentSize: 4028 - (void)webViewScrollViewDidResetContentSize:
4066 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { 4029 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
4161 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion { 4124 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion {
4162 DCHECK(completion); 4125 DCHECK(completion);
4163 web::NavigationItem* currentItem = [self currentNavItem]; 4126 web::NavigationItem* currentItem = [self currentNavItem];
4164 if (!currentItem) { 4127 if (!currentItem) {
4165 completion(nullptr); 4128 completion(nullptr);
4166 return; 4129 return;
4167 } 4130 }
4168 NSString* const kViewportContentQuery = 4131 NSString* const kViewportContentQuery =
4169 @"var viewport = document.querySelector('meta[name=\"viewport\"]');" 4132 @"var viewport = document.querySelector('meta[name=\"viewport\"]');"
4170 "viewport ? viewport.content : '';"; 4133 "viewport ? viewport.content : '';";
4171 base::WeakNSObject<CRWWebController> weakSelf(self); 4134 __weak CRWWebController* weakSelf = self;
4172 int itemID = currentItem->GetUniqueID(); 4135 int itemID = currentItem->GetUniqueID();
4173 [self executeJavaScript:kViewportContentQuery 4136 [self executeJavaScript:kViewportContentQuery
4174 completionHandler:^(id viewportContent, NSError*) { 4137 completionHandler:^(id viewportContent, NSError*) {
4175 web::NavigationItem* item = [weakSelf currentNavItem]; 4138 web::NavigationItem* item = [weakSelf currentNavItem];
4176 if (item && item->GetUniqueID() == itemID) { 4139 if (item && item->GetUniqueID() == itemID) {
4177 web::PageViewportState viewportState( 4140 web::PageViewportState viewportState(
4178 base::mac::ObjCCast<NSString>(viewportContent)); 4141 base::mac::ObjCCast<NSString>(viewportContent));
4179 completion(&viewportState); 4142 completion(&viewportState);
4180 } else { 4143 } else {
4181 completion(nullptr); 4144 completion(nullptr);
(...skipping 28 matching lines...) Expand all
4210 displayState.zoom_state().set_zoom_scale( 4173 displayState.zoom_state().set_zoom_scale(
4211 displayState.zoom_state().minimum_zoom_scale() + 4174 displayState.zoom_state().minimum_zoom_scale() +
4212 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference()); 4175 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference());
4213 currentItem->SetPageDisplayState(displayState); 4176 currentItem->SetPageDisplayState(displayState);
4214 [self applyPageDisplayState:currentItem->GetPageDisplayState()]; 4177 [self applyPageDisplayState:currentItem->GetPageDisplayState()];
4215 } 4178 }
4216 4179
4217 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState { 4180 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState {
4218 if (!displayState.IsValid()) 4181 if (!displayState.IsValid())
4219 return; 4182 return;
4220 base::WeakNSObject<CRWWebController> weakSelf(self); 4183 __weak CRWWebController* weakSelf = self;
4221 web::PageDisplayState displayStateCopy = displayState; 4184 web::PageDisplayState displayStateCopy = displayState;
4222 [self extractViewportTagWithCompletion:^( 4185 [self extractViewportTagWithCompletion:^(
4223 const web::PageViewportState* viewportState) { 4186 const web::PageViewportState* viewportState) {
4224 if (viewportState) { 4187 if (viewportState) {
4225 [weakSelf applyPageDisplayState:displayStateCopy 4188 [weakSelf applyPageDisplayState:displayStateCopy
4226 userScalable:viewportState->user_scalable()]; 4189 userScalable:viewportState->user_scalable()];
4227 } 4190 }
4228 }]; 4191 }];
4229 } 4192 }
4230 4193
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4299 (const web::PageScrollState&)scrollState { 4262 (const web::PageScrollState&)scrollState {
4300 DCHECK(scrollState.IsValid()); 4263 DCHECK(scrollState.IsValid());
4301 CGPoint scrollOffset = 4264 CGPoint scrollOffset =
4302 CGPointMake(scrollState.offset_x(), scrollState.offset_y()); 4265 CGPointMake(scrollState.offset_x(), scrollState.offset_y());
4303 if (_loadPhase == web::PAGE_LOADED) { 4266 if (_loadPhase == web::PAGE_LOADED) {
4304 // If the page is loaded, update the scroll immediately. 4267 // If the page is loaded, update the scroll immediately.
4305 [self.webScrollView setContentOffset:scrollOffset]; 4268 [self.webScrollView setContentOffset:scrollOffset];
4306 } else { 4269 } else {
4307 // If the page isn't loaded, store the action to update the scroll 4270 // If the page isn't loaded, store the action to update the scroll
4308 // when the page finishes loading. 4271 // when the page finishes loading.
4309 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); 4272 __weak UIScrollView* weakScrollView = self.webScrollView;
4310 base::scoped_nsprotocol<ProceduralBlock> action([^{ 4273 base::scoped_nsprotocol<ProceduralBlock> action([^{
4311 [weakScrollView setContentOffset:scrollOffset]; 4274 [weakScrollView setContentOffset:scrollOffset];
4312 } copy]); 4275 } copy]);
4313 [_pendingLoadCompleteActions addObject:action]; 4276 [_pendingLoadCompleteActions addObject:action];
4314 } 4277 }
4315 } 4278 }
4316 4279
4317 #pragma mark - 4280 #pragma mark -
4318 #pragma mark Web Page Features 4281 #pragma mark Web Page Features
4319 4282
4320 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { 4283 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler {
4321 if (!_webView) { 4284 if (!_webView) {
4322 handler(0); 4285 handler(0);
4323 return; 4286 return;
4324 } 4287 }
4325 4288
4326 [self executeJavaScript:@"__gCrWeb.getPageWidth();" 4289 [self executeJavaScript:@"__gCrWeb.getPageWidth();"
4327 completionHandler:^(id pageWidth, NSError*) { 4290 completionHandler:^(id pageWidth, NSError*) {
4328 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]); 4291 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]);
4329 }]; 4292 }];
4330 } 4293 }
4331 4294
4332 - (void)fetchDOMElementAtPoint:(CGPoint)point 4295 - (void)fetchDOMElementAtPoint:(CGPoint)point
4333 completionHandler:(void (^)(NSDictionary*))handler { 4296 completionHandler:(void (^)(NSDictionary*))handler {
4334 DCHECK(handler); 4297 DCHECK(handler);
4335 // Convert point into web page's coordinate system (which may be scaled and/or 4298 // Convert point into web page's coordinate system (which may be scaled and/or
4336 // scrolled). 4299 // scrolled).
4337 CGPoint scrollOffset = self.scrollPosition; 4300 CGPoint scrollOffset = self.scrollPosition;
4338 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; 4301 CGFloat webViewContentWidth = self.webScrollView.contentSize.width;
4339 base::WeakNSObject<CRWWebController> weakSelf(self); 4302 __weak CRWWebController* weakSelf = self;
4340 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { 4303 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) {
4341 CGFloat scale = pageWidth / webViewContentWidth; 4304 CGFloat scale = pageWidth / webViewContentWidth;
4342 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, 4305 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale,
4343 (point.y + scrollOffset.y) * scale); 4306 (point.y + scrollOffset.y) * scale);
4344 NSString* const kGetElementScript = 4307 NSString* const kGetElementScript =
4345 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", 4308 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);",
4346 localPoint.x, localPoint.y]; 4309 localPoint.x, localPoint.y];
4347 [weakSelf executeJavaScript:kGetElementScript 4310 [weakSelf executeJavaScript:kGetElementScript
4348 completionHandler:^(id element, NSError*) { 4311 completionHandler:^(id element, NSError*) {
4349 handler(base::mac::ObjCCastStrict<NSDictionary>(element)); 4312 handler(base::mac::ObjCCastStrict<NSDictionary>(element));
(...skipping 11 matching lines...) Expand all
4361 title = @"JavaScript"; 4324 title = @"JavaScript";
4362 } else { 4325 } else {
4363 base::string16 URLText = url_formatter::FormatUrl(params.link_url); 4326 base::string16 URLText = url_formatter::FormatUrl(params.link_url);
4364 title = base::SysUTF16ToNSString(URLText); 4327 title = base::SysUTF16ToNSString(URLText);
4365 } 4328 }
4366 } 4329 }
4367 NSString* src = element[@"src"]; 4330 NSString* src = element[@"src"];
4368 if (src) { 4331 if (src) {
4369 params.src_url = GURL(base::SysNSStringToUTF8(src)); 4332 params.src_url = GURL(base::SysNSStringToUTF8(src));
4370 if (!title) 4333 if (!title)
4371 title = [[src copy] autorelease]; 4334 title = [src copy];
4372 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)]) 4335 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)])
4373 title = nil; 4336 title = nil;
4374 } 4337 }
4375 NSString* titleAttribute = element[@"title"]; 4338 NSString* titleAttribute = element[@"title"];
4376 if (titleAttribute) 4339 if (titleAttribute)
4377 title = titleAttribute; 4340 title = titleAttribute;
4378 if (title) { 4341 if (title) {
4379 params.menu_title.reset([title copy]); 4342 params.menu_title.reset([title copy]);
4380 } 4343 }
4381 NSString* referrerPolicy = element[@"referrerPolicy"]; 4344 NSString* referrerPolicy = element[@"referrerPolicy"];
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4436 [_delegate webControllerDidSuppressDialog:self]; 4399 [_delegate webControllerDidSuppressDialog:self];
4437 } 4400 }
4438 4401
4439 - (void)didBlockPopupWithURL:(GURL)popupURL 4402 - (void)didBlockPopupWithURL:(GURL)popupURL
4440 sourceURL:(GURL)sourceURL 4403 sourceURL:(GURL)sourceURL
4441 referrerPolicy:(const std::string&)referrerPolicyString { 4404 referrerPolicy:(const std::string&)referrerPolicyString {
4442 web::ReferrerPolicy referrerPolicy = 4405 web::ReferrerPolicy referrerPolicy =
4443 web::ReferrerPolicyFromString(referrerPolicyString); 4406 web::ReferrerPolicyFromString(referrerPolicyString);
4444 web::Referrer referrer(sourceURL, referrerPolicy); 4407 web::Referrer referrer(sourceURL, referrerPolicy);
4445 NSString* const kWindowName = @""; // obsoleted 4408 NSString* const kWindowName = @""; // obsoleted
4446 base::WeakNSObject<CRWWebController> weakSelf(self); 4409 __weak CRWWebController* weakSelf = self;
4447 void (^showPopupHandler)() = ^{ 4410 void (^showPopupHandler)() = ^{
4448 // On Desktop cross-window comunication is not supported for unblocked 4411 // On Desktop cross-window comunication is not supported for unblocked
4449 // popups; so it's ok to create a new independent page. 4412 // popups; so it's ok to create a new independent page.
4450 CRWWebController* child = 4413 CRWWebController* child =
4451 [[weakSelf delegate] webPageOrderedOpen:popupURL 4414 [[weakSelf delegate] webPageOrderedOpen:popupURL
4452 referrer:referrer 4415 referrer:referrer
4453 windowName:kWindowName 4416 windowName:kWindowName
4454 inBackground:NO]; 4417 inBackground:NO];
4455 DCHECK(!child || child.sessionController.openedByDOM); 4418 DCHECK(!child || child.sessionController.openedByDOM);
4456 }; 4419 };
4457 4420
4458 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); 4421 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler);
4459 [self.delegate webController:self didBlockPopup:info]; 4422 [self.delegate webController:self didBlockPopup:info];
4460 } 4423 }
4461 4424
4462 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { 4425 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL {
4463 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { 4426 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) {
4464 base::WeakNSObject<CRWWebController> weakSelf(self); 4427 __weak CRWWebController* weakSelf = self;
4465 dispatch_async(dispatch_get_main_queue(), ^{ 4428 dispatch_async(dispatch_get_main_queue(), ^{
4466 [self queryPageReferrerPolicy:^(NSString* policy) { 4429 [self queryPageReferrerPolicy:^(NSString* policy) {
4467 [weakSelf didBlockPopupWithURL:popupURL 4430 [weakSelf didBlockPopupWithURL:popupURL
4468 sourceURL:sourceURL 4431 sourceURL:sourceURL
4469 referrerPolicy:base::SysNSStringToUTF8(policy)]; 4432 referrerPolicy:base::SysNSStringToUTF8(policy)];
4470 }]; 4433 }];
4471 }); 4434 });
4472 } 4435 }
4473 } 4436 }
4474 4437
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
4720 [_containerView addToolbars:_webViewToolbars]; 4683 [_containerView addToolbars:_webViewToolbars];
4721 4684
4722 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( 4685 base::scoped_nsobject<CRWWebViewContentView> webViewContentView(
4723 [[CRWWebViewContentView alloc] initWithWebView:_webView 4686 [[CRWWebViewContentView alloc] initWithWebView:_webView
4724 scrollView:self.webScrollView]); 4687 scrollView:self.webScrollView]);
4725 [_containerView displayWebViewContentView:webViewContentView]; 4688 [_containerView displayWebViewContentView:webViewContentView];
4726 } 4689 }
4727 } 4690 }
4728 4691
4729 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { 4692 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config {
4730 return [web::CreateWKWebView(CGRectZero, config, 4693 return web::CreateWKWebView(CGRectZero, config,
4731 self.webStateImpl->GetBrowserState(), 4694 self.webStateImpl->GetBrowserState(),
4732 [self useDesktopUserAgent]) autorelease]; 4695 [self useDesktopUserAgent]);
4733 } 4696 }
4734 4697
4735 - (void)setWebView:(WKWebView*)webView { 4698 - (void)setWebView:(WKWebView*)webView {
4736 DCHECK_NE(_webView.get(), webView); 4699 DCHECK_NE(_webView.get(), webView);
4737 4700
4738 // Unwind the old web view. 4701 // Unwind the old web view.
4739 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is 4702 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is
4740 // fixed. 4703 // fixed.
4741 CRWWKScriptMessageRouter* messageRouter = 4704 CRWWKScriptMessageRouter* messageRouter =
4742 [self webViewConfigurationProvider].GetScriptMessageRouter(); 4705 [self webViewConfigurationProvider].GetScriptMessageRouter();
4743 if (_webView) { 4706 if (_webView) {
4744 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; 4707 [messageRouter removeAllScriptMessageHandlersForWebView:_webView];
4745 } 4708 }
4746 [_webView setNavigationDelegate:nil]; 4709 [_webView setNavigationDelegate:nil];
4747 [_webView setUIDelegate:nil]; 4710 [_webView setUIDelegate:nil];
4748 for (NSString* keyPath in self.WKWebViewObservers) { 4711 for (NSString* keyPath in self.observedKeyPaths) {
4749 [_webView removeObserver:self forKeyPath:keyPath]; 4712 [_webView removeObserver:self forKeyPath:keyPath];
4750 } 4713 }
4751 [self clearActivityIndicatorTasks]; 4714 [self clearActivityIndicatorTasks];
4752 4715
4753 _webView.reset([webView retain]); 4716 _webView.reset(webView);
4754 4717
4755 // Set up the new web view. 4718 // Set up the new web view.
4756 if (webView) { 4719 if (webView) {
4757 base::WeakNSObject<CRWWebController> weakSelf(self); 4720 __weak CRWWebController* weakSelf = self;
4758 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { 4721 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) {
4759 [weakSelf didReceiveScriptMessage:message]; 4722 [weakSelf didReceiveScriptMessage:message];
4760 } 4723 }
4761 name:kScriptMessageName 4724 name:kScriptMessageName
4762 webView:webView]; 4725 webView:webView];
4763 _windowIDJSManager.reset( 4726 _windowIDJSManager.reset(
4764 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); 4727 [[CRWJSWindowIDManager alloc] initWithWebView:webView]);
4765 } else { 4728 } else {
4766 _windowIDJSManager.reset(); 4729 _windowIDJSManager.reset();
4767 } 4730 }
4768 [_webView setNavigationDelegate:self]; 4731 [_webView setNavigationDelegate:self];
4769 [_webView setUIDelegate:self]; 4732 [_webView setUIDelegate:self];
4770 for (NSString* keyPath in self.WKWebViewObservers) { 4733 for (NSString* keyPath in self.observedKeyPaths) {
4771 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; 4734 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr];
4772 } 4735 }
4773 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); 4736 _injectedScriptManagers.reset([[NSMutableSet alloc] init]);
4774 [self setDocumentURL:_defaultURL]; 4737 [self setDocumentURL:_defaultURL];
4775 } 4738 }
4776 4739
4777 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { 4740 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache {
4778 if (!_webView) 4741 if (!_webView)
4779 return; 4742 return;
4780 4743
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4816 // This happens during tests. 4779 // This happens during tests.
4817 if (!_webView) { 4780 if (!_webView) {
4818 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 4781 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
4819 } 4782 }
4820 4783
4821 std::string MIMEType = self.webState->GetContentsMimeType(); 4784 std::string MIMEType = self.webState->GetContentsMimeType();
4822 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; 4785 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)];
4823 } 4786 }
4824 4787
4825 - (void)loadRequest:(NSMutableURLRequest*)request { 4788 - (void)loadRequest:(NSMutableURLRequest*)request {
4826 _latestWKNavigation.reset([[_webView loadRequest:request] retain]); 4789 _latestWKNavigation.reset([_webView loadRequest:request]);
4827 } 4790 }
4828 4791
4829 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { 4792 - (void)loadPOSTRequest:(NSMutableURLRequest*)request {
4830 if (!_POSTRequestLoader) { 4793 if (!_POSTRequestLoader) {
4831 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); 4794 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]);
4832 } 4795 }
4833 4796
4834 CRWWKScriptMessageRouter* messageRouter = 4797 CRWWKScriptMessageRouter* messageRouter =
4835 [self webViewConfigurationProvider].GetScriptMessageRouter(); 4798 [self webViewConfigurationProvider].GetScriptMessageRouter();
4836 4799
(...skipping 25 matching lines...) Expand all
4862 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { 4825 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL {
4863 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); 4826 CHECK(web::GetWebClient()->IsAppSpecificURL(URL));
4864 [self loadHTML:HTML forURL:URL]; 4827 [self loadHTML:HTML forURL:URL];
4865 } 4828 }
4866 4829
4867 - (void)loadHTMLForCurrentURL:(NSString*)HTML { 4830 - (void)loadHTMLForCurrentURL:(NSString*)HTML {
4868 [self loadHTML:HTML forURL:self.currentURL]; 4831 [self loadHTML:HTML forURL:self.currentURL];
4869 } 4832 }
4870 4833
4871 - (void)stopLoading { 4834 - (void)stopLoading {
4872 _stoppedWKNavigation.reset(_latestWKNavigation); 4835 _stoppedWKNavigation = _latestWKNavigation;
4873 4836
4874 base::RecordAction(UserMetricsAction("Stop")); 4837 base::RecordAction(UserMetricsAction("Stop"));
4875 // Discard the pending and transient entried before notifying the tab model 4838 // Discard the pending and transient entried before notifying the tab model
4876 // observers of the change via |-abortLoad|. 4839 // observers of the change via |-abortLoad|.
4877 [[self sessionController] discardNonCommittedEntries]; 4840 [[self sessionController] discardNonCommittedEntries];
4878 [self abortLoad]; 4841 [self abortLoad];
4879 // If discarding the non-committed entries results in an app-specific URL, 4842 // If discarding the non-committed entries results in an app-specific URL,
4880 // reload it in its native view. 4843 // reload it in its native view.
4881 if (!self.nativeController && 4844 if (!self.nativeController &&
4882 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { 4845 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
5159 [self loadWithParams:params]; 5122 [self loadWithParams:params];
5160 } 5123 }
5161 return; 5124 return;
5162 } else { 5125 } else {
5163 [self registerLoadRequest:webViewURL]; 5126 [self registerLoadRequest:webViewURL];
5164 } 5127 }
5165 } 5128 }
5166 // Ensure the URL is registered and loadPhase is as expected. 5129 // Ensure the URL is registered and loadPhase is as expected.
5167 DCHECK(_lastRegisteredRequestURL == webViewURL); 5130 DCHECK(_lastRegisteredRequestURL == webViewURL);
5168 DCHECK(self.loadPhase == web::LOAD_REQUESTED); 5131 DCHECK(self.loadPhase == web::LOAD_REQUESTED);
5169 _latestWKNavigation.reset([navigation retain]); 5132 _latestWKNavigation.reset(navigation);
5170 } 5133 }
5171 5134
5172 - (void)webView:(WKWebView*)webView 5135 - (void)webView:(WKWebView*)webView
5173 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { 5136 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
5174 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) 5137 [self registerLoadRequest:net::GURLWithNSURL(webView.URL)
5175 referrer:[self currentReferrer] 5138 referrer:[self currentReferrer]
5176 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; 5139 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT];
5177 } 5140 }
5178 5141
5179 - (void)webView:(WKWebView*)webView 5142 - (void)webView:(WKWebView*)webView
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
5308 } 5271 }
5309 5272
5310 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) { 5273 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) {
5311 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); 5274 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
5312 return; 5275 return;
5313 } 5276 }
5314 5277
5315 SecTrustRef trust = challenge.protectionSpace.serverTrust; 5278 SecTrustRef trust = challenge.protectionSpace.serverTrust;
5316 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust, 5279 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust,
5317 base::scoped_policy::RETAIN); 5280 base::scoped_policy::RETAIN);
5318 base::WeakNSObject<CRWWebController> weakSelf(self); 5281 __weak CRWWebController* weakSelf = self;
5319 [_certVerificationController 5282 [_certVerificationController
5320 decideLoadPolicyForTrust:scopedTrust 5283 decideLoadPolicyForTrust:scopedTrust
5321 host:challenge.protectionSpace.host 5284 host:challenge.protectionSpace.host
5322 completionHandler:^(web::CertAcceptPolicy policy, 5285 completionHandler:^(web::CertAcceptPolicy policy,
5323 net::CertStatus status) { 5286 net::CertStatus status) {
5324 base::scoped_nsobject<CRWWebController> strongSelf( 5287 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
5325 [weakSelf retain]);
5326 if (!strongSelf) { 5288 if (!strongSelf) {
5327 completionHandler( 5289 completionHandler(
5328 NSURLSessionAuthChallengeRejectProtectionSpace, nil); 5290 NSURLSessionAuthChallengeRejectProtectionSpace, nil);
5329 return; 5291 return;
5330 } 5292 }
5331 [strongSelf processAuthChallenge:challenge 5293 [strongSelf processAuthChallenge:challenge
5332 forCertAcceptPolicy:policy 5294 forCertAcceptPolicy:policy
5333 certStatus:status 5295 certStatus:status
5334 completionHandler:completionHandler]; 5296 completionHandler:completionHandler];
5335 }]; 5297 }];
(...skipping 25 matching lines...) Expand all
5361 } 5323 }
5362 } 5324 }
5363 5325
5364 #pragma mark - 5326 #pragma mark -
5365 #pragma mark KVO Observation 5327 #pragma mark KVO Observation
5366 5328
5367 - (void)observeValueForKeyPath:(NSString*)keyPath 5329 - (void)observeValueForKeyPath:(NSString*)keyPath
5368 ofObject:(id)object 5330 ofObject:(id)object
5369 change:(NSDictionary*)change 5331 change:(NSDictionary*)change
5370 context:(void*)context { 5332 context:(void*)context {
5371 NSString* dispatcherSelectorName = self.WKWebViewObservers[keyPath]; 5333 // All observed keypaths have to be present in |self.observedKeyPaths|.
5372 DCHECK(dispatcherSelectorName); 5334 DCHECK([self.observedKeyPaths containsObject:keyPath]);
5373 if (dispatcherSelectorName) 5335 if ([keyPath isEqualToString:@"certificateChain"]) {
5374 [self performSelector:NSSelectorFromString(dispatcherSelectorName)]; 5336 [self webViewSecurityFeaturesDidChange];
5337 } else if ([keyPath isEqualToString:@"estimatedProgress"]) {
5338 [self webViewEstimatedProgressDidChange];
5339 } else if ([keyPath isEqualToString:@"hasOnlySecureContent"]) {
5340 [self webViewSecurityFeaturesDidChange];
5341 } else if ([keyPath isEqualToString:@"loading"]) {
5342 [self webViewLoadingStateDidChange];
5343 } else if ([keyPath isEqualToString:@"title"]) {
5344 [self webViewTitleDidChange];
5345 } else if ([keyPath isEqualToString:@"URL"]) {
5346 [self webViewURLDidChange];
5347 } else {
5348 NOTREACHED();
5349 }
5375 } 5350 }
5376 5351
5377 - (void)webViewEstimatedProgressDidChange { 5352 - (void)webViewEstimatedProgressDidChange {
5378 if (!_isBeingDestroyed) { 5353 if (!_isBeingDestroyed) {
5379 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]); 5354 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]);
5380 } 5355 }
5381 } 5356 }
5382 5357
5383 - (void)webViewSecurityFeaturesDidChange { 5358 - (void)webViewSecurityFeaturesDidChange {
5384 if (self.loadPhase == web::LOAD_REQUESTED) { 5359 if (self.loadPhase == web::LOAD_REQUESTED) {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
5759 } 5734 }
5760 5735
5761 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5736 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5762 } 5737 }
5763 5738
5764 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5739 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5765 return [action.request valueForHTTPHeaderField:@"Referer"]; 5740 return [action.request valueForHTTPHeaderField:@"Referer"];
5766 } 5741 }
5767 5742
5768 @end 5743 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698