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

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: rebase 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" 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
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
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
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(nonatomic, strong, readonly) WKWebView* webView;
481 // The scroll view of |webView|. 475 // The scroll view of |webView|.
482 @property(nonatomic, readonly) UIScrollView* webScrollView; 476 @property(nonatomic, strong, readonly) UIScrollView* webScrollView;
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(strong, nonatomic) id<CRWNativeContent> nativeController;
Eugene But (OOO till 7-30) 2016/10/25 20:04:54 nit: could you please swap strong and nonatomic fo
stkhapugin 2016/11/07 16:16:50 Done.
488 // Returns NavigationManager's session controller. 482 // Returns NavigationManager's session controller.
489 @property(nonatomic, readonly) CRWSessionController* sessionController; 483 @property(nonatomic, strong, readonly) CRWSessionController* sessionController;
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(nonatomic, copy, readonly) NSString* activityIndicatorGroupID;
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(nonatomic, strong, readonly) NSArray* observedKeyPaths;
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(nonatomic, strong, readonly) CRWPassKitDownloader* passKitDownloader;
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
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
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
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);
1117 [_containerView setDelegate:nil]; 1084 [_containerView setDelegate:nil];
1118 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; 1085 _touchTrackingRecognizer.get().touchTrackingDelegate = nil;
1119 [[_webViewProxy scrollViewProxy] removeObserver:self]; 1086 [[_webViewProxy scrollViewProxy] removeObserver:self];
1120 [[NSNotificationCenter defaultCenter] removeObserver:self]; 1087 [[NSNotificationCenter defaultCenter] removeObserver:self];
1121 [super dealloc];
1122 } 1088 }
1123 1089
1124 - (void)dismissKeyboard { 1090 - (void)dismissKeyboard {
1125 [_webView endEditing:YES]; 1091 [_webView endEditing:YES];
1126 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) 1092 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)])
1127 [self.nativeController dismissKeyboard]; 1093 [self.nativeController dismissKeyboard];
1128 } 1094 }
1129 1095
1130 - (id<CRWNativeContent>)nativeController { 1096 - (id<CRWNativeContent>)nativeController {
1131 return [_containerView nativeController]; 1097 return [_containerView nativeController];
(...skipping 11 matching lines...) Expand all
1143 [_containerView displayNativeContent:nativeController]; 1109 [_containerView displayNativeContent:nativeController];
1144 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; 1110 [self setNativeControllerWebUsageEnabled:_webUsageEnabled];
1145 } 1111 }
1146 1112
1147 - (NSString*)activityIndicatorGroupID { 1113 - (NSString*)activityIndicatorGroupID {
1148 return [NSString 1114 return [NSString
1149 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@", 1115 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@",
1150 self.webStateImpl->GetRequestGroupID()]; 1116 self.webStateImpl->GetRequestGroupID()];
1151 } 1117 }
1152 1118
1153 - (NSDictionary*)WKWebViewObservers { 1119 - (NSArray*)observedKeyPaths {
1154 return @{ 1120 return @[
1155 @"certificateChain" : @"webViewSecurityFeaturesDidChange", 1121 @"certificateChain", @"estimatedProgress", @"hasOnlySecureContent",
1156 @"estimatedProgress" : @"webViewEstimatedProgressDidChange", 1122 @"loading", @"title", @"URL"
1157 @"hasOnlySecureContent" : @"webViewSecurityFeaturesDidChange", 1123 ];
1158 @"loading" : @"webViewLoadingStateDidChange",
1159 @"title" : @"webViewTitleDidChange",
1160 @"URL" : @"webViewURLDidChange",
1161 };
1162 } 1124 }
1163 1125
1164 // NativeControllerDelegate method, called to inform that title has changed. 1126 // NativeControllerDelegate method, called to inform that title has changed.
1165 - (void)nativeContent:(id)content titleDidChange:(NSString*)title { 1127 - (void)nativeContent:(id)content titleDidChange:(NSString*)title {
1166 // Responsiveness to delegate method was checked in setDelegate:. 1128 // Responsiveness to delegate method was checked in setDelegate:.
1167 [_delegate webController:self titleDidChange:title]; 1129 [_delegate webController:self titleDidChange:title];
1168 } 1130 }
1169 1131
1170 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled { 1132 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled {
1171 if ([self.nativeController 1133 if ([self.nativeController
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { 1259 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer {
1298 // 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.
1299 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) 1261 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan)
1300 return; 1262 return;
1301 1263
1302 if (![_DOMElementForLastTouch count]) 1264 if (![_DOMElementForLastTouch count])
1303 return; 1265 return;
1304 1266
1305 web::ContextMenuParams params = 1267 web::ContextMenuParams params =
1306 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()]; 1268 [self contextMenuParamsForElement:_DOMElementForLastTouch.get()];
1307 params.view.reset([_webView retain]); 1269 params.view.reset(_webView);
1308 params.location = [gestureRecognizer locationInView:_webView]; 1270 params.location = [gestureRecognizer locationInView:_webView];
1309 if (self.webStateImpl->HandleContextMenu(params)) { 1271 if (self.webStateImpl->HandleContextMenu(params)) {
1310 // Cancelling all touches has the intended side effect of suppressing the 1272 // Cancelling all touches has the intended side effect of suppressing the
1311 // system's context menu. 1273 // system's context menu.
1312 [self cancelAllTouches]; 1274 [self cancelAllTouches];
1313 } 1275 }
1314 } 1276 }
1315 1277
1316 - (void)cancelAllTouches { 1278 - (void)cancelAllTouches {
1317 // Disable web view scrolling. 1279 // Disable web view scrolling.
(...skipping 22 matching lines...) Expand all
1340 1302
1341 if (!defaultImage) { 1303 if (!defaultImage) {
1342 CGRect frame = CGRectMake(0, 0, 2, 2); 1304 CGRect frame = CGRectMake(0, 0, 2, 2);
1343 UIGraphicsBeginImageContext(frame.size); 1305 UIGraphicsBeginImageContext(frame.size);
1344 [[UIColor whiteColor] setFill]; 1306 [[UIColor whiteColor] setFill];
1345 CGContextFillRect(UIGraphicsGetCurrentContext(), frame); 1307 CGContextFillRect(UIGraphicsGetCurrentContext(), frame);
1346 1308
1347 UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); 1309 UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
1348 UIGraphicsEndImageContext(); 1310 UIGraphicsEndImageContext();
1349 1311
1350 defaultImage = 1312 defaultImage = [result stretchableImageWithLeftCapWidth:1 topCapHeight:1];
1351 [[result stretchableImageWithLeftCapWidth:1 topCapHeight:1] retain];
1352 } 1313 }
1353 return defaultImage; 1314 return defaultImage;
1354 } 1315 }
1355 1316
1356 - (BOOL)canGoBack { 1317 - (BOOL)canGoBack {
1357 return _webStateImpl->GetNavigationManagerImpl().CanGoBack(); 1318 return _webStateImpl->GetNavigationManagerImpl().CanGoBack();
1358 } 1319 }
1359 1320
1360 - (BOOL)canGoForward { 1321 - (BOOL)canGoForward {
1361 return _webStateImpl->GetNavigationManagerImpl().CanGoForward(); 1322 return _webStateImpl->GetNavigationManagerImpl().CanGoForward();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 if (iRecognizer != recognizer) { 1540 if (iRecognizer != recognizer) {
1580 NSString* description = [iRecognizer description]; 1541 NSString* description = [iRecognizer description];
1581 if ([description rangeOfString:fragment].length) { 1542 if ([description rangeOfString:fragment].length) {
1582 [iRecognizer requireGestureRecognizerToFail:recognizer]; 1543 [iRecognizer requireGestureRecognizerToFail:recognizer];
1583 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it 1544 // requireGestureRecognizerToFail: doesn't retain the recognizer, so it
1584 // is possible for |iRecognizer| to outlive |recognizer| and end up with 1545 // is possible for |iRecognizer| to outlive |recognizer| and end up with
1585 // a dangling pointer. Add a retaining associative reference to ensure 1546 // a dangling pointer. Add a retaining associative reference to ensure
1586 // that the lifetimes work out. 1547 // that the lifetimes work out.
1587 // 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
1588 // 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.
1589 objc_setAssociatedObject(view, recognizer, recognizer, 1550 objc_setAssociatedObject(view, (__bridge void*)recognizer, recognizer,
1590 OBJC_ASSOCIATION_RETAIN_NONATOMIC); 1551 OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1591 } 1552 }
1592 } 1553 }
1593 } 1554 }
1594 } 1555 }
1595 1556
1596 - (CRWWebController*)createChildWebController { 1557 - (CRWWebController*)createChildWebController {
1597 CRWWebController* result = [self.delegate webPageOrderedOpen]; 1558 CRWWebController* result = [self.delegate webPageOrderedOpen];
1598 DCHECK(!result || result.sessionController.openedByDOM); 1559 DCHECK(!result || result.sessionController.openedByDOM);
1599 return result; 1560 return result;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 NSString* replaceWebViewUrlJS = 1687 NSString* replaceWebViewUrlJS =
1727 [self javascriptToReplaceWebViewURL:URL stateObjectJSON:stateObject]; 1688 [self javascriptToReplaceWebViewURL:URL stateObjectJSON:stateObject];
1728 std::string outState; 1689 std::string outState;
1729 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState); 1690 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState);
1730 NSString* popstateJS = 1691 NSString* popstateJS =
1731 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);", 1692 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);",
1732 base::SysUTF8ToNSString(outState)]; 1693 base::SysUTF8ToNSString(outState)];
1733 NSString* combinedJS = 1694 NSString* combinedJS =
1734 [NSString stringWithFormat:@"%@%@", replaceWebViewUrlJS, popstateJS]; 1695 [NSString stringWithFormat:@"%@%@", replaceWebViewUrlJS, popstateJS];
1735 GURL blockURL(URL); 1696 GURL blockURL(URL);
1736 base::WeakNSObject<CRWWebController> weakSelf(self); 1697 __weak CRWWebController* weakSelf = self;
1737 [self executeJavaScript:combinedJS completionHandler:^(id, NSError*) { 1698 [self executeJavaScript:combinedJS
1738 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) 1699 completionHandler:^(id, NSError*) {
1739 return; 1700 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
1740 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); 1701 if (!strongSelf || strongSelf.get()->_isBeingDestroyed)
1741 strongSelf.get()->_URLOnStartLoading = blockURL; 1702 return;
1742 strongSelf.get()->_lastRegisteredRequestURL = blockURL; 1703 strongSelf.get()->_URLOnStartLoading = blockURL;
1743 }]; 1704 strongSelf.get()->_lastRegisteredRequestURL = blockURL;
1705 }];
1744 } 1706 }
1745 1707
1746 // 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.
1747 - (void)loadCurrentURLInWebView { 1709 - (void)loadCurrentURLInWebView {
1748 // Clear the set of URLs opened in external applications. 1710 // Clear the set of URLs opened in external applications.
1749 _openedApplicationURL.reset([[NSMutableSet alloc] init]); 1711 _openedApplicationURL.reset([[NSMutableSet alloc] init]);
1750 1712
1751 // 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
1752 // session history and UI. 1714 // session history and UI.
1753 const GURL targetURL([self currentNavigationURL]); 1715 const GURL targetURL([self currentNavigationURL]);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 } else { 2193 } else {
2232 // Before changing the current session history entry, record the tab state. 2194 // Before changing the current session history entry, record the tab state.
2233 [self recordStateInHistory]; 2195 [self recordStateInHistory];
2234 } 2196 }
2235 2197
2236 CRWSessionController* sessionController = 2198 CRWSessionController* sessionController =
2237 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); 2199 _webStateImpl->GetNavigationManagerImpl().GetSessionController();
2238 // fromEntry is retained because it has the potential to be released 2200 // fromEntry is retained because it has the potential to be released
2239 // by goDelta: if it has not been committed. 2201 // by goDelta: if it has not been committed.
2240 base::scoped_nsobject<CRWSessionEntry> fromEntry( 2202 base::scoped_nsobject<CRWSessionEntry> fromEntry(
2241 [[sessionController currentEntry] retain]); 2203 [sessionController currentEntry]);
2242 [sessionController goDelta:delta]; 2204 [sessionController goDelta:delta];
2243 if (fromEntry) { 2205 if (fromEntry) {
2244 [self finishHistoryNavigationFromEntry:fromEntry]; 2206 [self finishHistoryNavigationFromEntry:fromEntry];
2245 } 2207 }
2246 } 2208 }
2247 2209
2248 - (BOOL)isLoaded { 2210 - (BOOL)isLoaded {
2249 return _loadPhase == web::PAGE_LOADED; 2211 return _loadPhase == web::PAGE_LOADED;
2250 } 2212 }
2251 2213
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 _webStateImpl->GetMojoInterfaceRegistry(); 2393 _webStateImpl->GetMojoInterfaceRegistry();
2432 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); 2394 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self));
2433 } 2395 }
2434 return _mojoFacade.get(); 2396 return _mojoFacade.get();
2435 } 2397 }
2436 2398
2437 - (CRWPassKitDownloader*)passKitDownloader { 2399 - (CRWPassKitDownloader*)passKitDownloader {
2438 if (_passKitDownloader) { 2400 if (_passKitDownloader) {
2439 return _passKitDownloader.get(); 2401 return _passKitDownloader.get();
2440 } 2402 }
2441 base::WeakNSObject<CRWWebController> weakSelf(self); 2403 __weak CRWWebController* weakSelf = self;
2442 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) { 2404 web::PassKitCompletionHandler passKitCompletion = ^(NSData* data) {
2443 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); 2405 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
2444 if (!strongSelf) { 2406 if (!strongSelf) {
2445 return; 2407 return;
2446 } 2408 }
2447 // Cancel load to update web state, since the PassKit download happens 2409 // Cancel load to update web state, since the PassKit download happens
2448 // 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
2449 // downloaded through UIWebView. 2411 // downloaded through UIWebView.
2450 [strongSelf loadCancelled]; 2412 [strongSelf loadCancelled];
2451 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:); 2413 SEL didLoadPassKitObject = @selector(webController:didLoadPassKitObject:);
2452 id<CRWWebDelegate> delegate = [strongSelf delegate]; 2414 id<CRWWebDelegate> delegate = [strongSelf delegate];
2453 if ([delegate respondsToSelector:didLoadPassKitObject]) { 2415 if ([delegate respondsToSelector:didLoadPassKitObject]) {
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 // TODO(crbug.com/549301): Improve transition detection. 3000 // TODO(crbug.com/549301): Improve transition detection.
3039 ui::PageTransition transition = self.userInteractionRegistered 3001 ui::PageTransition transition = self.userInteractionRegistered
3040 ? ui::PAGE_TRANSITION_LINK 3002 ? ui::PAGE_TRANSITION_LINK
3041 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; 3003 : ui::PAGE_TRANSITION_CLIENT_REDIRECT;
3042 [self pushStateWithPageURL:pushURL 3004 [self pushStateWithPageURL:pushURL
3043 stateObject:stateObject 3005 stateObject:stateObject
3044 transition:transition]; 3006 transition:transition];
3045 3007
3046 NSString* replaceWebViewJS = 3008 NSString* replaceWebViewJS =
3047 [self javascriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; 3009 [self javascriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject];
3048 base::WeakNSObject<CRWWebController> weakSelf(self); 3010 __weak CRWWebController* weakSelf = self;
3049 [self executeJavaScript:replaceWebViewJS completionHandler:^(id, NSError*) { 3011 [self executeJavaScript:replaceWebViewJS
3050 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) 3012 completionHandler:^(id, NSError*) {
3051 return; 3013 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
3052 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); 3014 if (!strongSelf || strongSelf.get()->_isBeingDestroyed)
3053 [strongSelf optOutScrollsToTopForSubviews]; 3015 return;
3054 // Notify the observers. 3016 [strongSelf optOutScrollsToTopForSubviews];
3055 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); 3017 // Notify the observers.
3056 [strongSelf didFinishNavigation]; 3018 strongSelf.get()->_webStateImpl->OnHistoryStateChanged();
3057 }]; 3019 [strongSelf didFinishNavigation];
3020 }];
3058 return YES; 3021 return YES;
3059 } 3022 }
3060 3023
3061 - (BOOL)handleWindowHistoryDidReplaceStateMessage: 3024 - (BOOL)handleWindowHistoryDidReplaceStateMessage:
3062 (base::DictionaryValue*)message 3025 (base::DictionaryValue*)message
3063 context:(NSDictionary*)context { 3026 context:(NSDictionary*)context {
3064 DCHECK(_changingHistoryState); 3027 DCHECK(_changingHistoryState);
3065 _changingHistoryState = NO; 3028 _changingHistoryState = NO;
3066 3029
3067 std::string pageURL; 3030 std::string pageURL;
(...skipping 29 matching lines...) Expand all
3097 if (!message->GetString("stateObject", &stateObjectJSON)) { 3060 if (!message->GetString("stateObject", &stateObjectJSON)) {
3098 DLOG(WARNING) << "JS message parameter not found: stateObject"; 3061 DLOG(WARNING) << "JS message parameter not found: stateObject";
3099 return NO; 3062 return NO;
3100 } 3063 }
3101 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); 3064 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON);
3102 _URLOnStartLoading = replaceURL; 3065 _URLOnStartLoading = replaceURL;
3103 _lastRegisteredRequestURL = replaceURL; 3066 _lastRegisteredRequestURL = replaceURL;
3104 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; 3067 [self replaceStateWithPageURL:replaceURL stateObject:stateObject];
3105 NSString* replaceStateJS = [self javascriptToReplaceWebViewURL:replaceURL 3068 NSString* replaceStateJS = [self javascriptToReplaceWebViewURL:replaceURL
3106 stateObjectJSON:stateObject]; 3069 stateObjectJSON:stateObject];
3107 base::WeakNSObject<CRWWebController> weakSelf(self); 3070 __weak CRWWebController* weakSelf = self;
3108 [self executeJavaScript:replaceStateJS completionHandler:^(id, NSError*) { 3071 [self executeJavaScript:replaceStateJS
3109 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) 3072 completionHandler:^(id, NSError*) {
3110 return; 3073 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
3111 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); 3074 if (!strongSelf || strongSelf.get()->_isBeingDestroyed)
3112 [strongSelf didFinishNavigation]; 3075 return;
3113 }]; 3076 [strongSelf didFinishNavigation];
3077 }];
3114 return YES; 3078 return YES;
3115 } 3079 }
3116 3080
3117 #pragma mark - 3081 #pragma mark -
3118 3082
3119 - (BOOL)wantsKeyboardShield { 3083 - (BOOL)wantsKeyboardShield {
3120 if ([self.nativeController 3084 if ([self.nativeController
3121 respondsToSelector:@selector(wantsKeyboardShield)]) { 3085 respondsToSelector:@selector(wantsKeyboardShield)]) {
3122 return [self.nativeController wantsKeyboardShield]; 3086 return [self.nativeController wantsKeyboardShield];
3123 } 3087 }
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
3519 shouldReceiveTouch:(UITouch*)touch { 3483 shouldReceiveTouch:(UITouch*)touch {
3520 // Expect only _contextMenuRecognizer. 3484 // Expect only _contextMenuRecognizer.
3521 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); 3485 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]);
3522 3486
3523 // 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
3524 // 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
3525 // 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
3526 // 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
3527 // fetched - system context menu will be shown. 3491 // fetched - system context menu will be shown.
3528 [self setDOMElementForLastTouch:nil]; 3492 [self setDOMElementForLastTouch:nil];
3529 base::WeakNSObject<CRWWebController> weakSelf(self); 3493 __weak CRWWebController* weakSelf = self;
3530 [self fetchDOMElementAtPoint:[touch locationInView:_webView] 3494 [self fetchDOMElementAtPoint:[touch locationInView:_webView]
3531 completionHandler:^(NSDictionary* element) { 3495 completionHandler:^(NSDictionary* element) {
3532 [weakSelf setDOMElementForLastTouch:element]; 3496 [weakSelf setDOMElementForLastTouch:element];
3533 }]; 3497 }];
3534 return YES; 3498 return YES;
3535 } 3499 }
3536 3500
3537 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { 3501 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
3538 // Expect only _contextMenuRecognizer. 3502 // Expect only _contextMenuRecognizer.
3539 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); 3503 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3634 return [_delegate webController:self 3598 return [_delegate webController:self
3635 shouldBlockPopupWithURL:popupURL 3599 shouldBlockPopupWithURL:popupURL
3636 sourceURL:sourceURL]; 3600 sourceURL:sourceURL];
3637 } 3601 }
3638 3602
3639 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { 3603 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo {
3640 const GURL url(windowInfo.url); 3604 const GURL url(windowInfo.url);
3641 const GURL currentURL([self currentNavigationURL]); 3605 const GURL currentURL([self currentNavigationURL]);
3642 NSString* windowName = windowInfo.window_name.get(); 3606 NSString* windowName = windowInfo.window_name.get();
3643 web::Referrer referrer(currentURL, windowInfo.referrer_policy); 3607 web::Referrer referrer(currentURL, windowInfo.referrer_policy);
3644 base::WeakNSObject<CRWWebController> weakSelf(self); 3608 __weak CRWWebController* weakSelf = self;
3645 void (^showPopupHandler)() = ^{ 3609 void (^showPopupHandler)() = ^{
3646 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url 3610 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url
3647 referrer:referrer 3611 referrer:referrer
3648 windowName:windowName 3612 windowName:windowName
3649 inBackground:NO]; 3613 inBackground:NO];
3650 DCHECK(!child || child.sessionController.openedByDOM); 3614 DCHECK(!child || child.sessionController.openedByDOM);
3651 }; 3615 };
3652 3616
3653 BOOL showPopup = windowInfo.user_is_interacting || 3617 BOOL showPopup = windowInfo.user_is_interacting ||
3654 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]); 3618 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders(); 3913 return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders();
3950 } 3914 }
3951 3915
3952 #pragma mark - 3916 #pragma mark -
3953 #pragma mark CRWWebViewScrollViewProxyObserver 3917 #pragma mark CRWWebViewScrollViewProxyObserver
3954 3918
3955 - (void)webViewScrollViewDidZoom: 3919 - (void)webViewScrollViewDidZoom:
3956 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { 3920 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy {
3957 _pageHasZoomed = YES; 3921 _pageHasZoomed = YES;
3958 3922
3959 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); 3923 __weak UIScrollView* weakScrollView = self.webScrollView;
3960 [self extractViewportTagWithCompletion:^( 3924 [self extractViewportTagWithCompletion:^(
3961 const web::PageViewportState* viewportState) { 3925 const web::PageViewportState* viewportState) {
3962 if (!weakScrollView) 3926 if (!weakScrollView)
3963 return; 3927 return;
3964 base::scoped_nsobject<UIScrollView> scrollView([weakScrollView retain]); 3928 base::scoped_nsobject<UIScrollView> scrollView(weakScrollView);
3965 if (viewportState && !viewportState->viewport_tag_present() && 3929 if (viewportState && !viewportState->viewport_tag_present() &&
3966 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] && 3930 [scrollView minimumZoomScale] == [scrollView maximumZoomScale] &&
3967 [scrollView zoomScale] > 1.0) { 3931 [scrollView zoomScale] > 1.0) {
3968 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true); 3932 UMA_HISTOGRAM_BOOLEAN(kUMAViewportZoomBugCount, true);
3969 } 3933 }
3970 }]; 3934 }];
3971 } 3935 }
3972 3936
3973 - (void)webViewScrollViewDidResetContentSize: 3937 - (void)webViewScrollViewDidResetContentSize:
3974 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { 3938 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
4069 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion { 4033 - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion {
4070 DCHECK(completion); 4034 DCHECK(completion);
4071 web::NavigationItem* currentItem = [self currentNavItem]; 4035 web::NavigationItem* currentItem = [self currentNavItem];
4072 if (!currentItem) { 4036 if (!currentItem) {
4073 completion(nullptr); 4037 completion(nullptr);
4074 return; 4038 return;
4075 } 4039 }
4076 NSString* const kViewportContentQuery = 4040 NSString* const kViewportContentQuery =
4077 @"var viewport = document.querySelector('meta[name=\"viewport\"]');" 4041 @"var viewport = document.querySelector('meta[name=\"viewport\"]');"
4078 "viewport ? viewport.content : '';"; 4042 "viewport ? viewport.content : '';";
4079 base::WeakNSObject<CRWWebController> weakSelf(self); 4043 __weak CRWWebController* weakSelf = self;
4080 int itemID = currentItem->GetUniqueID(); 4044 int itemID = currentItem->GetUniqueID();
4081 [self executeJavaScript:kViewportContentQuery 4045 [self executeJavaScript:kViewportContentQuery
4082 completionHandler:^(id viewportContent, NSError*) { 4046 completionHandler:^(id viewportContent, NSError*) {
4083 web::NavigationItem* item = [weakSelf currentNavItem]; 4047 web::NavigationItem* item = [weakSelf currentNavItem];
4084 if (item && item->GetUniqueID() == itemID) { 4048 if (item && item->GetUniqueID() == itemID) {
4085 web::PageViewportState viewportState( 4049 web::PageViewportState viewportState(
4086 base::mac::ObjCCast<NSString>(viewportContent)); 4050 base::mac::ObjCCast<NSString>(viewportContent));
4087 completion(&viewportState); 4051 completion(&viewportState);
4088 } else { 4052 } else {
4089 completion(nullptr); 4053 completion(nullptr);
(...skipping 28 matching lines...) Expand all
4118 displayState.zoom_state().set_zoom_scale( 4082 displayState.zoom_state().set_zoom_scale(
4119 displayState.zoom_state().minimum_zoom_scale() + 4083 displayState.zoom_state().minimum_zoom_scale() +
4120 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference()); 4084 zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference());
4121 currentItem->SetPageDisplayState(displayState); 4085 currentItem->SetPageDisplayState(displayState);
4122 [self applyPageDisplayState:currentItem->GetPageDisplayState()]; 4086 [self applyPageDisplayState:currentItem->GetPageDisplayState()];
4123 } 4087 }
4124 4088
4125 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState { 4089 - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState {
4126 if (!displayState.IsValid()) 4090 if (!displayState.IsValid())
4127 return; 4091 return;
4128 base::WeakNSObject<CRWWebController> weakSelf(self); 4092 __weak CRWWebController* weakSelf = self;
4129 web::PageDisplayState displayStateCopy = displayState; 4093 web::PageDisplayState displayStateCopy = displayState;
4130 [self extractViewportTagWithCompletion:^( 4094 [self extractViewportTagWithCompletion:^(
4131 const web::PageViewportState* viewportState) { 4095 const web::PageViewportState* viewportState) {
4132 if (viewportState) { 4096 if (viewportState) {
4133 [weakSelf applyPageDisplayState:displayStateCopy 4097 [weakSelf applyPageDisplayState:displayStateCopy
4134 userScalable:viewportState->user_scalable()]; 4098 userScalable:viewportState->user_scalable()];
4135 } 4099 }
4136 }]; 4100 }];
4137 } 4101 }
4138 4102
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4207 (const web::PageScrollState&)scrollState { 4171 (const web::PageScrollState&)scrollState {
4208 DCHECK(scrollState.IsValid()); 4172 DCHECK(scrollState.IsValid());
4209 CGPoint scrollOffset = 4173 CGPoint scrollOffset =
4210 CGPointMake(scrollState.offset_x(), scrollState.offset_y()); 4174 CGPointMake(scrollState.offset_x(), scrollState.offset_y());
4211 if (_loadPhase == web::PAGE_LOADED) { 4175 if (_loadPhase == web::PAGE_LOADED) {
4212 // If the page is loaded, update the scroll immediately. 4176 // If the page is loaded, update the scroll immediately.
4213 [self.webScrollView setContentOffset:scrollOffset]; 4177 [self.webScrollView setContentOffset:scrollOffset];
4214 } else { 4178 } else {
4215 // 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
4216 // when the page finishes loading. 4180 // when the page finishes loading.
4217 base::WeakNSObject<UIScrollView> weakScrollView(self.webScrollView); 4181 __weak UIScrollView* weakScrollView = self.webScrollView;
4218 base::scoped_nsprotocol<ProceduralBlock> action([^{ 4182 base::scoped_nsprotocol<ProceduralBlock> action([^{
4219 [weakScrollView setContentOffset:scrollOffset]; 4183 [weakScrollView setContentOffset:scrollOffset];
4220 } copy]); 4184 } copy]);
4221 [_pendingLoadCompleteActions addObject:action]; 4185 [_pendingLoadCompleteActions addObject:action];
4222 } 4186 }
4223 } 4187 }
4224 4188
4225 #pragma mark - 4189 #pragma mark -
4226 #pragma mark Web Page Features 4190 #pragma mark Web Page Features
4227 4191
4228 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { 4192 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler {
4229 if (!_webView) { 4193 if (!_webView) {
4230 handler(0); 4194 handler(0);
4231 return; 4195 return;
4232 } 4196 }
4233 4197
4234 [self executeJavaScript:@"__gCrWeb.getPageWidth();" 4198 [self executeJavaScript:@"__gCrWeb.getPageWidth();"
4235 completionHandler:^(id pageWidth, NSError*) { 4199 completionHandler:^(id pageWidth, NSError*) {
4236 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]); 4200 handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]);
4237 }]; 4201 }];
4238 } 4202 }
4239 4203
4240 - (void)fetchDOMElementAtPoint:(CGPoint)point 4204 - (void)fetchDOMElementAtPoint:(CGPoint)point
4241 completionHandler:(void (^)(NSDictionary*))handler { 4205 completionHandler:(void (^)(NSDictionary*))handler {
4242 DCHECK(handler); 4206 DCHECK(handler);
4243 // 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
4244 // scrolled). 4208 // scrolled).
4245 CGPoint scrollOffset = self.scrollPosition; 4209 CGPoint scrollOffset = self.scrollPosition;
4246 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; 4210 CGFloat webViewContentWidth = self.webScrollView.contentSize.width;
4247 base::WeakNSObject<CRWWebController> weakSelf(self); 4211 __weak CRWWebController* weakSelf = self;
4248 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { 4212 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) {
4249 CGFloat scale = pageWidth / webViewContentWidth; 4213 CGFloat scale = pageWidth / webViewContentWidth;
4250 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, 4214 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale,
4251 (point.y + scrollOffset.y) * scale); 4215 (point.y + scrollOffset.y) * scale);
4252 NSString* const kGetElementScript = 4216 NSString* const kGetElementScript =
4253 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", 4217 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);",
4254 localPoint.x, localPoint.y]; 4218 localPoint.x, localPoint.y];
4255 [weakSelf executeJavaScript:kGetElementScript 4219 [weakSelf executeJavaScript:kGetElementScript
4256 completionHandler:^(id element, NSError*) { 4220 completionHandler:^(id element, NSError*) {
4257 handler(base::mac::ObjCCastStrict<NSDictionary>(element)); 4221 handler(base::mac::ObjCCastStrict<NSDictionary>(element));
(...skipping 11 matching lines...) Expand all
4269 title = @"JavaScript"; 4233 title = @"JavaScript";
4270 } else { 4234 } else {
4271 base::string16 URLText = url_formatter::FormatUrl(params.link_url); 4235 base::string16 URLText = url_formatter::FormatUrl(params.link_url);
4272 title = base::SysUTF16ToNSString(URLText); 4236 title = base::SysUTF16ToNSString(URLText);
4273 } 4237 }
4274 } 4238 }
4275 NSString* src = element[@"src"]; 4239 NSString* src = element[@"src"];
4276 if (src) { 4240 if (src) {
4277 params.src_url = GURL(base::SysNSStringToUTF8(src)); 4241 params.src_url = GURL(base::SysNSStringToUTF8(src));
4278 if (!title) 4242 if (!title)
4279 title = [[src copy] autorelease]; 4243 title = [src copy];
4280 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)]) 4244 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)])
4281 title = nil; 4245 title = nil;
4282 } 4246 }
4283 NSString* titleAttribute = element[@"title"]; 4247 NSString* titleAttribute = element[@"title"];
4284 if (titleAttribute) 4248 if (titleAttribute)
4285 title = titleAttribute; 4249 title = titleAttribute;
4286 if (title) { 4250 if (title) {
4287 params.menu_title.reset([title copy]); 4251 params.menu_title.reset([title copy]);
4288 } 4252 }
4289 NSString* referrerPolicy = element[@"referrerPolicy"]; 4253 NSString* referrerPolicy = element[@"referrerPolicy"];
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4344 [_delegate webControllerDidSuppressDialog:self]; 4308 [_delegate webControllerDidSuppressDialog:self];
4345 } 4309 }
4346 4310
4347 - (void)didBlockPopupWithURL:(GURL)popupURL 4311 - (void)didBlockPopupWithURL:(GURL)popupURL
4348 sourceURL:(GURL)sourceURL 4312 sourceURL:(GURL)sourceURL
4349 referrerPolicy:(const std::string&)referrerPolicyString { 4313 referrerPolicy:(const std::string&)referrerPolicyString {
4350 web::ReferrerPolicy referrerPolicy = 4314 web::ReferrerPolicy referrerPolicy =
4351 web::ReferrerPolicyFromString(referrerPolicyString); 4315 web::ReferrerPolicyFromString(referrerPolicyString);
4352 web::Referrer referrer(sourceURL, referrerPolicy); 4316 web::Referrer referrer(sourceURL, referrerPolicy);
4353 NSString* const kWindowName = @""; // obsoleted 4317 NSString* const kWindowName = @""; // obsoleted
4354 base::WeakNSObject<CRWWebController> weakSelf(self); 4318 __weak CRWWebController* weakSelf = self;
4355 void (^showPopupHandler)() = ^{ 4319 void (^showPopupHandler)() = ^{
4356 // On Desktop cross-window comunication is not supported for unblocked 4320 // On Desktop cross-window comunication is not supported for unblocked
4357 // popups; so it's ok to create a new independent page. 4321 // popups; so it's ok to create a new independent page.
4358 CRWWebController* child = 4322 CRWWebController* child =
4359 [[weakSelf delegate] webPageOrderedOpen:popupURL 4323 [[weakSelf delegate] webPageOrderedOpen:popupURL
4360 referrer:referrer 4324 referrer:referrer
4361 windowName:kWindowName 4325 windowName:kWindowName
4362 inBackground:NO]; 4326 inBackground:NO];
4363 DCHECK(!child || child.sessionController.openedByDOM); 4327 DCHECK(!child || child.sessionController.openedByDOM);
4364 }; 4328 };
4365 4329
4366 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); 4330 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler);
4367 [self.delegate webController:self didBlockPopup:info]; 4331 [self.delegate webController:self didBlockPopup:info];
4368 } 4332 }
4369 4333
4370 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { 4334 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL {
4371 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { 4335 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) {
4372 base::WeakNSObject<CRWWebController> weakSelf(self); 4336 __weak CRWWebController* weakSelf = self;
4373 dispatch_async(dispatch_get_main_queue(), ^{ 4337 dispatch_async(dispatch_get_main_queue(), ^{
4374 [self queryPageReferrerPolicy:^(NSString* policy) { 4338 [self queryPageReferrerPolicy:^(NSString* policy) {
4375 [weakSelf didBlockPopupWithURL:popupURL 4339 [weakSelf didBlockPopupWithURL:popupURL
4376 sourceURL:sourceURL 4340 sourceURL:sourceURL
4377 referrerPolicy:base::SysNSStringToUTF8(policy)]; 4341 referrerPolicy:base::SysNSStringToUTF8(policy)];
4378 }]; 4342 }];
4379 }); 4343 });
4380 } 4344 }
4381 } 4345 }
4382 4346
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
4628 [_containerView addToolbars:_webViewToolbars]; 4592 [_containerView addToolbars:_webViewToolbars];
4629 4593
4630 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( 4594 base::scoped_nsobject<CRWWebViewContentView> webViewContentView(
4631 [[CRWWebViewContentView alloc] initWithWebView:_webView 4595 [[CRWWebViewContentView alloc] initWithWebView:_webView
4632 scrollView:self.webScrollView]); 4596 scrollView:self.webScrollView]);
4633 [_containerView displayWebViewContentView:webViewContentView]; 4597 [_containerView displayWebViewContentView:webViewContentView];
4634 } 4598 }
4635 } 4599 }
4636 4600
4637 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { 4601 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config {
4638 return [web::CreateWKWebView(CGRectZero, config, 4602 return web::CreateWKWebView(CGRectZero, config,
4639 self.webStateImpl->GetBrowserState(), 4603 self.webStateImpl->GetBrowserState(),
4640 [self useDesktopUserAgent]) autorelease]; 4604 [self useDesktopUserAgent]);
4641 } 4605 }
4642 4606
4643 - (void)setWebView:(WKWebView*)webView { 4607 - (void)setWebView:(WKWebView*)webView {
4644 DCHECK_NE(_webView.get(), webView); 4608 DCHECK_NE(_webView.get(), webView);
4645 4609
4646 // Unwind the old web view. 4610 // Unwind the old web view.
4647 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is 4611 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is
4648 // fixed. 4612 // fixed.
4649 CRWWKScriptMessageRouter* messageRouter = 4613 CRWWKScriptMessageRouter* messageRouter =
4650 [self webViewConfigurationProvider].GetScriptMessageRouter(); 4614 [self webViewConfigurationProvider].GetScriptMessageRouter();
4651 if (_webView) { 4615 if (_webView) {
4652 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; 4616 [messageRouter removeAllScriptMessageHandlersForWebView:_webView];
4653 } 4617 }
4654 [_webView setNavigationDelegate:nil]; 4618 [_webView setNavigationDelegate:nil];
4655 [_webView setUIDelegate:nil]; 4619 [_webView setUIDelegate:nil];
4656 for (NSString* keyPath in self.WKWebViewObservers) { 4620 for (NSString* keyPath in self.observedKeyPaths) {
4657 [_webView removeObserver:self forKeyPath:keyPath]; 4621 [_webView removeObserver:self forKeyPath:keyPath];
4658 } 4622 }
4659 [self clearActivityIndicatorTasks]; 4623 [self clearActivityIndicatorTasks];
4660 4624
4661 _webView.reset([webView retain]); 4625 _webView.reset(webView);
4662 4626
4663 // Set up the new web view. 4627 // Set up the new web view.
4664 if (webView) { 4628 if (webView) {
4665 base::WeakNSObject<CRWWebController> weakSelf(self); 4629 __weak CRWWebController* weakSelf = self;
4666 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { 4630 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) {
4667 [weakSelf didReceiveScriptMessage:message]; 4631 [weakSelf didReceiveScriptMessage:message];
4668 } 4632 }
4669 name:kScriptMessageName 4633 name:kScriptMessageName
4670 webView:webView]; 4634 webView:webView];
4671 _windowIDJSManager.reset( 4635 _windowIDJSManager.reset(
4672 [[CRWJSWindowIDManager alloc] initWithWebView:webView]); 4636 [[CRWJSWindowIDManager alloc] initWithWebView:webView]);
4673 } else { 4637 } else {
4674 _windowIDJSManager.reset(); 4638 _windowIDJSManager.reset();
4675 } 4639 }
4676 [_webView setNavigationDelegate:self]; 4640 [_webView setNavigationDelegate:self];
4677 [_webView setUIDelegate:self]; 4641 [_webView setUIDelegate:self];
4678 for (NSString* keyPath in self.WKWebViewObservers) { 4642 for (NSString* keyPath in self.observedKeyPaths) {
4679 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; 4643 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr];
4680 } 4644 }
4681 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); 4645 _injectedScriptManagers.reset([[NSMutableSet alloc] init]);
4682 [self setDocumentURL:_defaultURL]; 4646 [self setDocumentURL:_defaultURL];
4683 } 4647 }
4684 4648
4685 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { 4649 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache {
4686 if (!_webView) 4650 if (!_webView)
4687 return; 4651 return;
4688 4652
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4724 // This happens during tests. 4688 // This happens during tests.
4725 if (!_webView) { 4689 if (!_webView) {
4726 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 4690 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
4727 } 4691 }
4728 4692
4729 std::string MIMEType = self.webState->GetContentsMimeType(); 4693 std::string MIMEType = self.webState->GetContentsMimeType();
4730 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; 4694 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)];
4731 } 4695 }
4732 4696
4733 - (void)loadRequest:(NSMutableURLRequest*)request { 4697 - (void)loadRequest:(NSMutableURLRequest*)request {
4734 _latestWKNavigation.reset([[_webView loadRequest:request] retain]); 4698 _latestWKNavigation.reset([_webView loadRequest:request]);
4735 } 4699 }
4736 4700
4737 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { 4701 - (void)loadPOSTRequest:(NSMutableURLRequest*)request {
4738 if (!_POSTRequestLoader) { 4702 if (!_POSTRequestLoader) {
4739 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); 4703 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]);
4740 } 4704 }
4741 4705
4742 CRWWKScriptMessageRouter* messageRouter = 4706 CRWWKScriptMessageRouter* messageRouter =
4743 [self webViewConfigurationProvider].GetScriptMessageRouter(); 4707 [self webViewConfigurationProvider].GetScriptMessageRouter();
4744 4708
(...skipping 25 matching lines...) Expand all
4770 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { 4734 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL {
4771 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); 4735 CHECK(web::GetWebClient()->IsAppSpecificURL(URL));
4772 [self loadHTML:HTML forURL:URL]; 4736 [self loadHTML:HTML forURL:URL];
4773 } 4737 }
4774 4738
4775 - (void)loadHTMLForCurrentURL:(NSString*)HTML { 4739 - (void)loadHTMLForCurrentURL:(NSString*)HTML {
4776 [self loadHTML:HTML forURL:self.currentURL]; 4740 [self loadHTML:HTML forURL:self.currentURL];
4777 } 4741 }
4778 4742
4779 - (void)stopLoading { 4743 - (void)stopLoading {
4780 _stoppedWKNavigation.reset(_latestWKNavigation); 4744 _stoppedWKNavigation = _latestWKNavigation;
4781 4745
4782 base::RecordAction(UserMetricsAction("Stop")); 4746 base::RecordAction(UserMetricsAction("Stop"));
4783 // Discard the pending and transient entried before notifying the tab model 4747 // Discard the pending and transient entried before notifying the tab model
4784 // observers of the change via |-abortLoad|. 4748 // observers of the change via |-abortLoad|.
4785 [[self sessionController] discardNonCommittedEntries]; 4749 [[self sessionController] discardNonCommittedEntries];
4786 [self abortLoad]; 4750 [self abortLoad];
4787 // 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,
4788 // reload it in its native view. 4752 // reload it in its native view.
4789 if (!self.nativeController && 4753 if (!self.nativeController &&
4790 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { 4754 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
5067 [self loadWithParams:params]; 5031 [self loadWithParams:params];
5068 } 5032 }
5069 return; 5033 return;
5070 } else { 5034 } else {
5071 [self registerLoadRequest:webViewURL]; 5035 [self registerLoadRequest:webViewURL];
5072 } 5036 }
5073 } 5037 }
5074 // Ensure the URL is registered and loadPhase is as expected. 5038 // Ensure the URL is registered and loadPhase is as expected.
5075 DCHECK(_lastRegisteredRequestURL == webViewURL); 5039 DCHECK(_lastRegisteredRequestURL == webViewURL);
5076 DCHECK(self.loadPhase == web::LOAD_REQUESTED); 5040 DCHECK(self.loadPhase == web::LOAD_REQUESTED);
5077 _latestWKNavigation.reset([navigation retain]); 5041 _latestWKNavigation.reset(navigation);
5078 } 5042 }
5079 5043
5080 - (void)webView:(WKWebView*)webView 5044 - (void)webView:(WKWebView*)webView
5081 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { 5045 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
5082 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) 5046 [self registerLoadRequest:net::GURLWithNSURL(webView.URL)
5083 referrer:[self currentReferrer] 5047 referrer:[self currentReferrer]
5084 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; 5048 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT];
5085 } 5049 }
5086 5050
5087 - (void)webView:(WKWebView*)webView 5051 - (void)webView:(WKWebView*)webView
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
5213 } 5177 }
5214 5178
5215 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) { 5179 if (![authMethod isEqual:NSURLAuthenticationMethodServerTrust]) {
5216 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); 5180 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
5217 return; 5181 return;
5218 } 5182 }
5219 5183
5220 SecTrustRef trust = challenge.protectionSpace.serverTrust; 5184 SecTrustRef trust = challenge.protectionSpace.serverTrust;
5221 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust, 5185 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust,
5222 base::scoped_policy::RETAIN); 5186 base::scoped_policy::RETAIN);
5223 base::WeakNSObject<CRWWebController> weakSelf(self); 5187 __weak CRWWebController* weakSelf = self;
5224 [_certVerificationController 5188 [_certVerificationController
5225 decideLoadPolicyForTrust:scopedTrust 5189 decideLoadPolicyForTrust:scopedTrust
5226 host:challenge.protectionSpace.host 5190 host:challenge.protectionSpace.host
5227 completionHandler:^(web::CertAcceptPolicy policy, 5191 completionHandler:^(web::CertAcceptPolicy policy,
5228 net::CertStatus status) { 5192 net::CertStatus status) {
5229 base::scoped_nsobject<CRWWebController> strongSelf( 5193 base::scoped_nsobject<CRWWebController> strongSelf(weakSelf);
5230 [weakSelf retain]);
5231 if (!strongSelf) { 5194 if (!strongSelf) {
5232 completionHandler( 5195 completionHandler(
5233 NSURLSessionAuthChallengeRejectProtectionSpace, nil); 5196 NSURLSessionAuthChallengeRejectProtectionSpace, nil);
5234 return; 5197 return;
5235 } 5198 }
5236 [strongSelf processAuthChallenge:challenge 5199 [strongSelf processAuthChallenge:challenge
5237 forCertAcceptPolicy:policy 5200 forCertAcceptPolicy:policy
5238 certStatus:status 5201 certStatus:status
5239 completionHandler:completionHandler]; 5202 completionHandler:completionHandler];
5240 }]; 5203 }];
(...skipping 25 matching lines...) Expand all
5266 } 5229 }
5267 } 5230 }
5268 5231
5269 #pragma mark - 5232 #pragma mark -
5270 #pragma mark KVO Observation 5233 #pragma mark KVO Observation
5271 5234
5272 - (void)observeValueForKeyPath:(NSString*)keyPath 5235 - (void)observeValueForKeyPath:(NSString*)keyPath
5273 ofObject:(id)object 5236 ofObject:(id)object
5274 change:(NSDictionary*)change 5237 change:(NSDictionary*)change
5275 context:(void*)context { 5238 context:(void*)context {
5276 NSString* dispatcherSelectorName = self.WKWebViewObservers[keyPath]; 5239 // All observed keypaths have to be present in |self.observedKeyPaths|.
5277 DCHECK(dispatcherSelectorName); 5240 DCHECK([self.observedKeyPaths containsObject:keyPath]);
5278 if (dispatcherSelectorName) 5241 if ([keyPath isEqualToString:@"certificateChain"]) {
5279 [self performSelector:NSSelectorFromString(dispatcherSelectorName)]; 5242 [self webViewSecurityFeaturesDidChange];
5243 } else if ([keyPath isEqualToString:@"estimatedProgress"]) {
5244 [self webViewEstimatedProgressDidChange];
5245 } else if ([keyPath isEqualToString:@"hasOnlySecureContent"]) {
5246 [self webViewSecurityFeaturesDidChange];
5247 } else if ([keyPath isEqualToString:@"loading"]) {
5248 [self webViewLoadingStateDidChange];
5249 } else if ([keyPath isEqualToString:@"title"]) {
5250 [self webViewTitleDidChange];
5251 } else if ([keyPath isEqualToString:@"URL"]) {
5252 [self webViewURLDidChange];
5253 } else {
5254 NOTREACHED();
5255 }
5280 } 5256 }
5281 5257
5282 - (void)webViewEstimatedProgressDidChange { 5258 - (void)webViewEstimatedProgressDidChange {
5283 if (!_isBeingDestroyed) { 5259 if (!_isBeingDestroyed) {
5284 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]); 5260 self.webStateImpl->SendChangeLoadProgress([_webView estimatedProgress]);
5285 } 5261 }
5286 } 5262 }
5287 5263
5288 - (void)webViewSecurityFeaturesDidChange { 5264 - (void)webViewSecurityFeaturesDidChange {
5289 if (self.loadPhase == web::LOAD_REQUESTED) { 5265 if (self.loadPhase == web::LOAD_REQUESTED) {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
5649 } 5625 }
5650 5626
5651 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5627 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5652 } 5628 }
5653 5629
5654 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5630 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5655 return [action.request valueForHTTPHeaderField:@"Referer"]; 5631 return [action.request valueForHTTPHeaderField:@"Referer"];
5656 } 5632 }
5657 5633
5658 @end 5634 @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