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

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

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

Powered by Google App Engine
This is Rietveld 408576698