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

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

Issue 1806043004: [ios] Refactored dialogs suppression. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments Created 4 years, 9 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 <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // The time of the last page transfer start, measured in seconds since Jan 1 234 // The time of the last page transfer start, measured in seconds since Jan 1
235 // 2001. 235 // 2001.
236 CFAbsoluteTime _lastTransferTimeInSeconds; 236 CFAbsoluteTime _lastTransferTimeInSeconds;
237 // Default URL (about:blank). 237 // Default URL (about:blank).
238 GURL _defaultURL; 238 GURL _defaultURL;
239 // Show overlay view, don't reload web page. 239 // Show overlay view, don't reload web page.
240 BOOL _overlayPreviewMode; 240 BOOL _overlayPreviewMode;
241 // If |YES|, call setSuppressDialogs when core.js is injected into the web 241 // If |YES|, call setSuppressDialogs when core.js is injected into the web
242 // view. 242 // view.
243 BOOL _setSuppressDialogsLater; 243 BOOL _setSuppressDialogsLater;
244 // If |YES|, call setSuppressDialogs when core.js is injected into the web
245 // view.
246 BOOL _setNotifyAboutDialogsLater;
247 // The URL of an expected future recreation of the |webView|. Valid 244 // The URL of an expected future recreation of the |webView|. Valid
248 // only if the web view was discarded for non-user-visible reasons, such that 245 // only if the web view was discarded for non-user-visible reasons, such that
249 // if the next load request is for that URL, it should be treated as a 246 // if the next load request is for that URL, it should be treated as a
250 // reconstruction that should use cache aggressively. 247 // reconstruction that should use cache aggressively.
251 GURL _expectedReconstructionURL; 248 GURL _expectedReconstructionURL;
252 249
253 scoped_ptr<web::NewWindowInfo> _externalRequest; 250 scoped_ptr<web::NewWindowInfo> _externalRequest;
254 251
255 // The WebStateImpl instance associated with this CRWWebController. 252 // The WebStateImpl instance associated with this CRWWebController.
256 scoped_ptr<WebStateImpl> _webStateImpl; 253 scoped_ptr<WebStateImpl> _webStateImpl;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 423
427 // Handles 'addPluginPlaceholders' message. 424 // Handles 'addPluginPlaceholders' message.
428 - (BOOL)handleAddPluginPlaceholdersMessage:(base::DictionaryValue*)message 425 - (BOOL)handleAddPluginPlaceholdersMessage:(base::DictionaryValue*)message
429 context:(NSDictionary*)context; 426 context:(NSDictionary*)context;
430 // Handles 'chrome.send' message. 427 // Handles 'chrome.send' message.
431 - (BOOL)handleChromeSendMessage:(base::DictionaryValue*)message 428 - (BOOL)handleChromeSendMessage:(base::DictionaryValue*)message
432 context:(NSDictionary*)context; 429 context:(NSDictionary*)context;
433 // Handles 'console' message. 430 // Handles 'console' message.
434 - (BOOL)handleConsoleMessage:(base::DictionaryValue*)message 431 - (BOOL)handleConsoleMessage:(base::DictionaryValue*)message
435 context:(NSDictionary*)context; 432 context:(NSDictionary*)context;
436 // Handles 'dialog.suppressed' message. 433 // Handles 'geolocationDialog.suppressed' message.
437 - (BOOL)handleDialogSuppressedMessage:(base::DictionaryValue*)message 434 - (BOOL)handleGeolocationDialogSuppressedMessage:(base::DictionaryValue*)message
438 context:(NSDictionary*)context; 435 context:(NSDictionary*)context;
439 // Handles 'document.favicons' message. 436 // Handles 'document.favicons' message.
440 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message 437 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message
441 context:(NSDictionary*)context; 438 context:(NSDictionary*)context;
442 // Handles 'document.submit' message. 439 // Handles 'document.submit' message.
443 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message 440 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message
444 context:(NSDictionary*)context; 441 context:(NSDictionary*)context;
445 // Handles 'externalRequest' message. 442 // Handles 'externalRequest' message.
446 - (BOOL)handleExternalRequestMessage:(base::DictionaryValue*)message 443 - (BOOL)handleExternalRequestMessage:(base::DictionaryValue*)message
447 context:(NSDictionary*)context; 444 context:(NSDictionary*)context;
448 // Handles 'form.activity' message. 445 // Handles 'form.activity' message.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // Transition to fade snapshot overlay. 511 // Transition to fade snapshot overlay.
515 const NSTimeInterval kSnapshotOverlayTransition = 0.5; 512 const NSTimeInterval kSnapshotOverlayTransition = 0.5;
516 513
517 } // namespace 514 } // namespace
518 515
519 @implementation CRWWebController 516 @implementation CRWWebController
520 517
521 @synthesize webUsageEnabled = _webUsageEnabled; 518 @synthesize webUsageEnabled = _webUsageEnabled;
522 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay; 519 @synthesize usePlaceholderOverlay = _usePlaceholderOverlay;
523 @synthesize loadPhase = _loadPhase; 520 @synthesize loadPhase = _loadPhase;
521 @synthesize suppressDialogs = _suppressDialogs;
524 522
525 // Implemented by subclasses. 523 // Implemented by subclasses.
526 @dynamic keyboardDisplayRequiresUserAction; 524 @dynamic keyboardDisplayRequiresUserAction;
527 525
528 + (instancetype)allocWithZone:(struct _NSZone*)zone { 526 + (instancetype)allocWithZone:(struct _NSZone*)zone {
529 if (self == [CRWWebController class]) { 527 if (self == [CRWWebController class]) {
530 // This is an abstract class which should not be instantiated directly. 528 // This is an abstract class which should not be instantiated directly.
531 // Callers should create concrete subclasses instead. 529 // Callers should create concrete subclasses instead.
532 NOTREACHED(); 530 NOTREACHED();
533 return nil; 531 return nil;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 return self.webScrollView.contentOffset; 933 return self.webScrollView.contentOffset;
936 } 934 }
937 935
938 - (BOOL)atTop { 936 - (BOOL)atTop {
939 if (!self.webView) 937 if (!self.webView)
940 return YES; 938 return YES;
941 UIScrollView* scrollView = self.webScrollView; 939 UIScrollView* scrollView = self.webScrollView;
942 return scrollView.contentOffset.y == -scrollView.contentInset.top; 940 return scrollView.contentOffset.y == -scrollView.contentInset.top;
943 } 941 }
944 942
943 - (void)setSuppressDialogs:(BOOL)suppressDialogs {
944 _suppressDialogs = suppressDialogs;
945 if (self.webView) {
946 NSString* const kSetSuppressDialogs = [NSString
947 stringWithFormat:@"__gCrWeb.setSuppressGeolocationDialogs(%d);",
948 suppressDialogs];
949 [self evaluateJavaScript:kSetSuppressDialogs stringResultHandler:nil];
950 } else {
951 _setSuppressDialogsLater = suppressDialogs;
952 }
953 }
954
945 - (void)presentSpoofingError { 955 - (void)presentSpoofingError {
946 UMA_HISTOGRAM_ENUMERATION("Web.URLVerificationFailure", 956 UMA_HISTOGRAM_ENUMERATION("Web.URLVerificationFailure",
947 [self webViewDocumentType], 957 [self webViewDocumentType],
948 web::WEB_VIEW_DOCUMENT_TYPE_COUNT); 958 web::WEB_VIEW_DOCUMENT_TYPE_COUNT);
949 if (self.webView) { 959 if (self.webView) {
950 [self removeWebViewAllowingCachedReconstruction:NO]; 960 [self removeWebViewAllowingCachedReconstruction:NO];
951 [_delegate presentSpoofingError]; 961 [_delegate presentSpoofingError];
952 } 962 }
953 } 963 }
954 964
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 } 1057 }
1048 [self injectWindowID]; 1058 [self injectWindowID];
1049 } 1059 }
1050 1060
1051 - (void)injectWindowID { 1061 - (void)injectWindowID {
1052 if (![_windowIDJSManager hasBeenInjected]) { 1062 if (![_windowIDJSManager hasBeenInjected]) {
1053 // If the window ID wasn't present, this is a new page. 1063 // If the window ID wasn't present, this is a new page.
1054 [self setPageChangeProbability:web::PAGE_CHANGE_PROBABILITY_LOW]; 1064 [self setPageChangeProbability:web::PAGE_CHANGE_PROBABILITY_LOW];
1055 // Default values for suppressDialogs and notifyAboutDialogs are NO, 1065 // Default values for suppressDialogs and notifyAboutDialogs are NO,
1056 // so updating them only when necessary is a good optimization. 1066 // so updating them only when necessary is a good optimization.
1057 if (_setSuppressDialogsLater || _setNotifyAboutDialogsLater) { 1067 if (_setSuppressDialogsLater) {
1058 [self setSuppressDialogs:_setSuppressDialogsLater 1068 [self setSuppressDialogs:YES];
1059 notify:_setNotifyAboutDialogsLater];
1060 _setSuppressDialogsLater = NO; 1069 _setSuppressDialogsLater = NO;
1061 _setNotifyAboutDialogsLater = NO;
1062 } 1070 }
1063 1071
1064 [_windowIDJSManager inject]; 1072 [_windowIDJSManager inject];
1065 DCHECK([_windowIDJSManager hasBeenInjected]); 1073 DCHECK([_windowIDJSManager hasBeenInjected]);
1066 } 1074 }
1067 } 1075 }
1068 1076
1069 // Set the specified recognizer to take priority over any recognizers in the 1077 // Set the specified recognizer to take priority over any recognizers in the
1070 // view that have a description containing the specified text fragment. 1078 // view that have a description containing the specified text fragment.
1071 + (void)requireGestureRecognizerToFail:(UIGestureRecognizer*)recognizer 1079 + (void)requireGestureRecognizerToFail:(UIGestureRecognizer*)recognizer
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 2015
2008 - (SEL)selectorToHandleJavaScriptCommand:(const std::string&)command { 2016 - (SEL)selectorToHandleJavaScriptCommand:(const std::string&)command {
2009 static std::map<std::string, SEL>* handlers = nullptr; 2017 static std::map<std::string, SEL>* handlers = nullptr;
2010 static dispatch_once_t onceToken; 2018 static dispatch_once_t onceToken;
2011 dispatch_once(&onceToken, ^{ 2019 dispatch_once(&onceToken, ^{
2012 handlers = new std::map<std::string, SEL>(); 2020 handlers = new std::map<std::string, SEL>();
2013 (*handlers)["addPluginPlaceholders"] = 2021 (*handlers)["addPluginPlaceholders"] =
2014 @selector(handleAddPluginPlaceholdersMessage:context:); 2022 @selector(handleAddPluginPlaceholdersMessage:context:);
2015 (*handlers)["chrome.send"] = @selector(handleChromeSendMessage:context:); 2023 (*handlers)["chrome.send"] = @selector(handleChromeSendMessage:context:);
2016 (*handlers)["console"] = @selector(handleConsoleMessage:context:); 2024 (*handlers)["console"] = @selector(handleConsoleMessage:context:);
2017 (*handlers)["dialog.suppressed"] = 2025 (*handlers)["geolocationDialog.suppressed"] =
2018 @selector(handleDialogSuppressedMessage:context:); 2026 @selector(handleGeolocationDialogSuppressedMessage:context:);
2019 (*handlers)["document.favicons"] = 2027 (*handlers)["document.favicons"] =
2020 @selector(handleDocumentFaviconsMessage:context:); 2028 @selector(handleDocumentFaviconsMessage:context:);
2021 (*handlers)["document.retitled"] = 2029 (*handlers)["document.retitled"] =
2022 @selector(handleDocumentRetitledMessage:context:); 2030 @selector(handleDocumentRetitledMessage:context:);
2023 (*handlers)["document.submit"] = 2031 (*handlers)["document.submit"] =
2024 @selector(handleDocumentSubmitMessage:context:); 2032 @selector(handleDocumentSubmitMessage:context:);
2025 (*handlers)["externalRequest"] = 2033 (*handlers)["externalRequest"] =
2026 @selector(handleExternalRequestMessage:context:); 2034 @selector(handleExternalRequestMessage:context:);
2027 (*handlers)["form.activity"] = 2035 (*handlers)["form.activity"] =
2028 @selector(handleFormActivityMessage:context:); 2036 @selector(handleFormActivityMessage:context:);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 std::string origin; 2125 std::string origin;
2118 if (!message->GetString("origin", &origin)) { 2126 if (!message->GetString("origin", &origin)) {
2119 DLOG(WARNING) << "JS message parameter not found: origin"; 2127 DLOG(WARNING) << "JS message parameter not found: origin";
2120 return NO; 2128 return NO;
2121 } 2129 }
2122 2130
2123 DVLOG(0) << origin << " [" << method << "] " << consoleMessage; 2131 DVLOG(0) << origin << " [" << method << "] " << consoleMessage;
2124 return YES; 2132 return YES;
2125 } 2133 }
2126 2134
2127 - (BOOL)handleDialogSuppressedMessage:(base::DictionaryValue*)message 2135 - (BOOL)handleGeolocationDialogSuppressedMessage:(base::DictionaryValue*)message
2128 context:(NSDictionary*)context { 2136 context:(NSDictionary*)context {
2129 if ([_delegate 2137 [self didSuppressDialog];
2130 respondsToSelector:@selector(webControllerDidSuppressDialog:)]) {
2131 [_delegate webControllerDidSuppressDialog:self];
2132 }
2133 return YES; 2138 return YES;
2134 } 2139 }
2135 2140
2136 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message 2141 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message
2137 context:(NSDictionary*)context { 2142 context:(NSDictionary*)context {
2138 base::ListValue* favicons = nullptr; 2143 base::ListValue* favicons = nullptr;
2139 if (!message->GetList("favicons", &favicons)) { 2144 if (!message->GetList("favicons", &favicons)) {
2140 DLOG(WARNING) << "JS message parameter not found: favicons"; 2145 DLOG(WARNING) << "JS message parameter not found: favicons";
2141 return NO; 2146 return NO;
2142 } 2147 }
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
3180 _placeholderOverlayView.reset(); 3185 _placeholderOverlayView.reset();
3181 // There are cases when resetting the contentView, above, may happen after 3186 // There are cases when resetting the contentView, above, may happen after
3182 // the web view has been created. Re-add it here, rather than 3187 // the web view has been created. Re-add it here, rather than
3183 // relying on a subsequent call to loadCurrentURLInWebView. 3188 // relying on a subsequent call to loadCurrentURLInWebView.
3184 if (self.webView) { 3189 if (self.webView) {
3185 [[self view] addSubview:self.webView]; 3190 [[self view] addSubview:self.webView];
3186 } 3191 }
3187 } 3192 }
3188 } 3193 }
3189 3194
3190 - (void)internalSuppressDialogs:(BOOL)suppressFlag notify:(BOOL)notifyFlag {
3191 NSString* const kSetSuppressDialogs =
3192 [NSString stringWithFormat:@"__gCrWeb.setSuppressDialogs(%d, %d);",
3193 suppressFlag, notifyFlag];
3194 [self setSuppressDialogsWithHelperScript:kSetSuppressDialogs];
3195 }
3196
3197 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { 3195 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy {
3198 switch (policy) { 3196 switch (policy) {
3199 case web::DIALOG_POLICY_ALLOW: 3197 case web::DIALOG_POLICY_ALLOW:
3200 [self setSuppressDialogs:NO notify:NO]; 3198 [self setSuppressDialogs:NO];
3201 return; 3199 return;
3202 case web::DIALOG_POLICY_SUPPRESS: 3200 case web::DIALOG_POLICY_SUPPRESS:
3203 [self setSuppressDialogs:YES notify:YES]; 3201 [self setSuppressDialogs:YES];
3204 return; 3202 return;
3205 } 3203 }
3206 NOTREACHED(); 3204 NOTREACHED();
3207 } 3205 }
3208 3206
3209 - (void)setSuppressDialogs:(BOOL)suppressFlag notify:(BOOL)notifyFlag {
3210 if (self.webView && [_earlyScriptManager hasBeenInjected]) {
3211 [self internalSuppressDialogs:suppressFlag notify:notifyFlag];
3212 } else {
3213 _setSuppressDialogsLater = suppressFlag;
3214 _setNotifyAboutDialogsLater = notifyFlag;
3215 }
3216 }
3217
3218 #pragma mark - 3207 #pragma mark -
3219 #pragma mark Session Information 3208 #pragma mark Session Information
3220 3209
3221 - (CRWSessionController*)sessionController { 3210 - (CRWSessionController*)sessionController {
3222 return _webStateImpl 3211 return _webStateImpl
3223 ? _webStateImpl->GetNavigationManagerImpl().GetSessionController() 3212 ? _webStateImpl->GetNavigationManagerImpl().GetSessionController()
3224 : nil; 3213 : nil;
3225 } 3214 }
3226 3215
3227 - (CRWSessionEntry*)currentSessionEntry { 3216 - (CRWSessionEntry*)currentSessionEntry {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 mainDocumentURL: 3600 mainDocumentURL:
3612 linkClicked:)]) { 3601 linkClicked:)]) {
3613 return YES; 3602 return YES;
3614 } 3603 }
3615 return [_delegate webController:self 3604 return [_delegate webController:self
3616 shouldOpenURL:url 3605 shouldOpenURL:url
3617 mainDocumentURL:mainDocumentURL 3606 mainDocumentURL:mainDocumentURL
3618 linkClicked:linkClicked]; 3607 linkClicked:linkClicked];
3619 } 3608 }
3620 3609
3610 - (void)didSuppressDialog {
3611 if ([_delegate respondsToSelector:@selector(webControllerDidSuppressDialog:)])
3612 [_delegate webControllerDidSuppressDialog:self];
3613 }
3614
3621 - (BOOL)isPutativeMainFrameRequest:(NSURLRequest*)request 3615 - (BOOL)isPutativeMainFrameRequest:(NSURLRequest*)request
3622 targetFrame:(const web::FrameInfo*)targetFrame { 3616 targetFrame:(const web::FrameInfo*)targetFrame {
3623 // Determine whether the request is for the main frame using frame info if 3617 // Determine whether the request is for the main frame using frame info if
3624 // available. In the case of missing frame info, the request is considered to 3618 // available. In the case of missing frame info, the request is considered to
3625 // have originated from the main frame if either of the following is true: 3619 // have originated from the main frame if either of the following is true:
3626 // (a) The request's URL matches the request's main document URL 3620 // (a) The request's URL matches the request's main document URL
3627 // (b) The request's URL resourceSpecifier matches the request's 3621 // (b) The request's URL resourceSpecifier matches the request's
3628 // mainDocumentURL specifier, as is the case upon redirect from http 3622 // mainDocumentURL specifier, as is the case upon redirect from http
3629 // App Store links to a URL with itms-apps scheme. This appears to be is 3623 // App Store links to a URL with itms-apps scheme. This appears to be is
3630 // App Store specific behavior, specially handled by web view. 3624 // App Store specific behavior, specially handled by web view.
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3844 if ([MIMEType isEqualToString:@"text/html"] || 3838 if ([MIMEType isEqualToString:@"text/html"] ||
3845 [MIMEType isEqualToString:@"application/xhtml+xml"] || 3839 [MIMEType isEqualToString:@"application/xhtml+xml"] ||
3846 [MIMEType isEqualToString:@"application/xml"]) { 3840 [MIMEType isEqualToString:@"application/xml"]) {
3847 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; 3841 return web::WEB_VIEW_DOCUMENT_TYPE_HTML;
3848 } 3842 }
3849 3843
3850 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 3844 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
3851 } 3845 }
3852 3846
3853 @end 3847 @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+protected.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698