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

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

Issue 2669303004: Removed externalRequest code from CRWWebController. (Closed)
Patch Set: Removed kWindowNameSeparator Created 3 years, 10 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
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web/web_state/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #import <objc/runtime.h> 9 #import <objc/runtime.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 #include "url/url_constants.h" 109 #include "url/url_constants.h"
110 110
111 using base::UserMetricsAction; 111 using base::UserMetricsAction;
112 using web::NavigationManager; 112 using web::NavigationManager;
113 using web::NavigationManagerImpl; 113 using web::NavigationManagerImpl;
114 using web::WebState; 114 using web::WebState;
115 using web::WebStateImpl; 115 using web::WebStateImpl;
116 116
117 namespace web { 117 namespace web {
118 NSString* const kContainerViewID = @"Container View"; 118 NSString* const kContainerViewID = @"Container View";
119 const char* kWindowNameSeparator = "#";
120 NSString* const kUserIsInteractingKey = @"userIsInteracting"; 119 NSString* const kUserIsInteractingKey = @"userIsInteracting";
121 NSString* const kOriginURLKey = @"originURL"; 120 NSString* const kOriginURLKey = @"originURL";
122 NSString* const kLogJavaScript = @"LogJavascript"; 121 NSString* const kLogJavaScript = @"LogJavascript";
123 122
124 struct NewWindowInfo {
125 GURL url;
126 base::scoped_nsobject<NSString> window_name;
127 web::ReferrerPolicy referrer_policy;
128 bool user_is_interacting;
129 NewWindowInfo(GURL url,
130 NSString* window_name,
131 web::ReferrerPolicy referrer_policy,
132 bool user_is_interacting);
133 ~NewWindowInfo();
134 };
135
136 NewWindowInfo::NewWindowInfo(GURL target_url,
137 NSString* target_window_name,
138 web::ReferrerPolicy target_referrer_policy,
139 bool target_user_is_interacting)
140 : url(target_url),
141 window_name([target_window_name copy]),
142 referrer_policy(target_referrer_policy),
143 user_is_interacting(target_user_is_interacting) {
144 }
145
146 NewWindowInfo::~NewWindowInfo() {
147 }
148
149 // Struct to capture data about a user interaction. Records the time of the 123 // Struct to capture data about a user interaction. Records the time of the
150 // interaction and the main document URL at that time. 124 // interaction and the main document URL at that time.
151 struct UserInteractionEvent { 125 struct UserInteractionEvent {
152 UserInteractionEvent(GURL url) 126 UserInteractionEvent(GURL url)
153 : main_document_url(url), time(CFAbsoluteTimeGetCurrent()) {} 127 : main_document_url(url), time(CFAbsoluteTimeGetCurrent()) {}
154 // Main document URL at the time the interaction occurred. 128 // Main document URL at the time the interaction occurred.
155 GURL main_document_url; 129 GURL main_document_url;
156 // Time that the interaction occured, measured in seconds since Jan 1 2001. 130 // Time that the interaction occured, measured in seconds since Jan 1 2001.
157 CFAbsoluteTime time; 131 CFAbsoluteTime time;
158 }; 132 };
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // window.history.replaceState 356 // window.history.replaceState
383 // Set to YES on window.history.willChangeState message. To NO on 357 // Set to YES on window.history.willChangeState message. To NO on
384 // window.history.didPushState or window.history.didReplaceState. 358 // window.history.didPushState or window.history.didReplaceState.
385 BOOL _changingHistoryState; 359 BOOL _changingHistoryState;
386 // Set to YES when a hashchange event is manually dispatched for same-document 360 // Set to YES when a hashchange event is manually dispatched for same-document
387 // history navigations. 361 // history navigations.
388 BOOL _dispatchingSameDocumentHashChangeEvent; 362 BOOL _dispatchingSameDocumentHashChangeEvent;
389 // YES if the web process backing _wkWebView is believed to currently be dead. 363 // YES if the web process backing _wkWebView is believed to currently be dead.
390 BOOL _webProcessIsDead; 364 BOOL _webProcessIsDead;
391 365
392 std::unique_ptr<web::NewWindowInfo> _externalRequest;
393 // Object for loading POST requests with body. 366 // Object for loading POST requests with body.
394 base::scoped_nsobject<CRWJSPOSTRequestLoader> _POSTRequestLoader; 367 base::scoped_nsobject<CRWJSPOSTRequestLoader> _POSTRequestLoader;
395 368
396 // WebStateImpl instance associated with this CRWWebController, web controller 369 // WebStateImpl instance associated with this CRWWebController, web controller
397 // does not own this pointer. 370 // does not own this pointer.
398 WebStateImpl* _webStateImpl; 371 WebStateImpl* _webStateImpl;
399 372
400 // A set of URLs opened in external applications; stored so that errors 373 // A set of URLs opened in external applications; stored so that errors
401 // from the web view can be identified as resulting from these events. 374 // from the web view can be identified as resulting from these events.
402 base::scoped_nsobject<NSMutableSet> _openedApplicationURL; 375 base::scoped_nsobject<NSMutableSet> _openedApplicationURL;
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 // provided by web view. 775 // provided by web view.
803 - (void)updateSSLStatusForCurrentNavigationItem; 776 - (void)updateSSLStatusForCurrentNavigationItem;
804 // Called when SSL status has been updated for the current navigation item. 777 // Called when SSL status has been updated for the current navigation item.
805 - (void)didUpdateSSLStatusForCurrentNavigationItem; 778 - (void)didUpdateSSLStatusForCurrentNavigationItem;
806 // Called when a load ends in an SSL error and certificate chain. 779 // Called when a load ends in an SSL error and certificate chain.
807 - (void)handleSSLCertError:(NSError*)error; 780 - (void)handleSSLCertError:(NSError*)error;
808 781
809 // Returns YES if the popup should be blocked, NO otherwise. 782 // Returns YES if the popup should be blocked, NO otherwise.
810 - (BOOL)shouldBlockPopupWithURL:(const GURL&)popupURL 783 - (BOOL)shouldBlockPopupWithURL:(const GURL&)popupURL
811 sourceURL:(const GURL&)sourceURL; 784 sourceURL:(const GURL&)sourceURL;
812 // Tries to open a popup with the given new window information.
813 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo;
814 785
815 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to 786 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to
816 // reply with NSURLSessionAuthChallengeDisposition and credentials. 787 // reply with NSURLSessionAuthChallengeDisposition and credentials.
817 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge 788 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge
818 forCertAcceptPolicy:(web::CertAcceptPolicy)policy 789 forCertAcceptPolicy:(web::CertAcceptPolicy)policy
819 certStatus:(net::CertStatus)certStatus 790 certStatus:(net::CertStatus)certStatus
820 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, 791 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition,
821 NSURLCredential*))completionHandler; 792 NSURLCredential*))completionHandler;
822 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply 793 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply
823 // with NSURLSessionAuthChallengeDisposition and credentials. 794 // with NSURLSessionAuthChallengeDisposition and credentials.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 context:(NSDictionary*)context; 854 context:(NSDictionary*)context;
884 // Handles 'geolocationDialog.suppressed' message. 855 // Handles 'geolocationDialog.suppressed' message.
885 - (BOOL)handleGeolocationDialogSuppressedMessage:(base::DictionaryValue*)message 856 - (BOOL)handleGeolocationDialogSuppressedMessage:(base::DictionaryValue*)message
886 context:(NSDictionary*)context; 857 context:(NSDictionary*)context;
887 // Handles 'document.favicons' message. 858 // Handles 'document.favicons' message.
888 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message 859 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message
889 context:(NSDictionary*)context; 860 context:(NSDictionary*)context;
890 // Handles 'document.submit' message. 861 // Handles 'document.submit' message.
891 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message 862 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message
892 context:(NSDictionary*)context; 863 context:(NSDictionary*)context;
893 // Handles 'externalRequest' message.
894 - (BOOL)handleExternalRequestMessage:(base::DictionaryValue*)message
895 context:(NSDictionary*)context;
896 // Handles 'form.activity' message. 864 // Handles 'form.activity' message.
897 - (BOOL)handleFormActivityMessage:(base::DictionaryValue*)message 865 - (BOOL)handleFormActivityMessage:(base::DictionaryValue*)message
898 context:(NSDictionary*)context; 866 context:(NSDictionary*)context;
899 // Handles 'navigator.credentials.request' message. 867 // Handles 'navigator.credentials.request' message.
900 - (BOOL)handleCredentialsRequestedMessage:(base::DictionaryValue*)message 868 - (BOOL)handleCredentialsRequestedMessage:(base::DictionaryValue*)message
901 context:(NSDictionary*)context; 869 context:(NSDictionary*)context;
902 // Handles 'navigator.credentials.notifySignedIn' message. 870 // Handles 'navigator.credentials.notifySignedIn' message.
903 - (BOOL)handleSignedInMessage:(base::DictionaryValue*)message 871 - (BOOL)handleSignedInMessage:(base::DictionaryValue*)message
904 context:(NSDictionary*)context; 872 context:(NSDictionary*)context;
905 // Handles 'navigator.credentials.notifySignedOut' message. 873 // Handles 'navigator.credentials.notifySignedOut' message.
906 - (BOOL)handleSignedOutMessage:(base::DictionaryValue*)message 874 - (BOOL)handleSignedOutMessage:(base::DictionaryValue*)message
907 context:(NSDictionary*)context; 875 context:(NSDictionary*)context;
908 // Handles 'navigator.credentials.notifyFailedSignIn' message. 876 // Handles 'navigator.credentials.notifyFailedSignIn' message.
909 - (BOOL)handleSignInFailedMessage:(base::DictionaryValue*)message 877 - (BOOL)handleSignInFailedMessage:(base::DictionaryValue*)message
910 context:(NSDictionary*)context; 878 context:(NSDictionary*)context;
911 // Handles 'resetExternalRequest' message.
912 - (BOOL)handleResetExternalRequestMessage:(base::DictionaryValue*)message
913 context:(NSDictionary*)context;
914 // Handles 'window.error' message. 879 // Handles 'window.error' message.
915 - (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message 880 - (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message
916 context:(NSDictionary*)context; 881 context:(NSDictionary*)context;
917 // Handles 'window.hashchange' message. 882 // Handles 'window.hashchange' message.
918 - (BOOL)handleWindowHashChangeMessage:(base::DictionaryValue*)message 883 - (BOOL)handleWindowHashChangeMessage:(base::DictionaryValue*)message
919 context:(NSDictionary*)context; 884 context:(NSDictionary*)context;
920 // Handles 'window.history.back' message. 885 // Handles 'window.history.back' message.
921 - (BOOL)handleWindowHistoryBackMessage:(base::DictionaryValue*)message 886 - (BOOL)handleWindowHistoryBackMessage:(base::DictionaryValue*)message
922 context:(NSDictionary*)context; 887 context:(NSDictionary*)context;
923 // Handles 'window.history.forward' message. 888 // Handles 'window.history.forward' message.
(...skipping 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 (*handlers)["addPluginPlaceholders"] = 2492 (*handlers)["addPluginPlaceholders"] =
2528 @selector(handleAddPluginPlaceholdersMessage:context:); 2493 @selector(handleAddPluginPlaceholdersMessage:context:);
2529 (*handlers)["chrome.send"] = @selector(handleChromeSendMessage:context:); 2494 (*handlers)["chrome.send"] = @selector(handleChromeSendMessage:context:);
2530 (*handlers)["console"] = @selector(handleConsoleMessage:context:); 2495 (*handlers)["console"] = @selector(handleConsoleMessage:context:);
2531 (*handlers)["geolocationDialog.suppressed"] = 2496 (*handlers)["geolocationDialog.suppressed"] =
2532 @selector(handleGeolocationDialogSuppressedMessage:context:); 2497 @selector(handleGeolocationDialogSuppressedMessage:context:);
2533 (*handlers)["document.favicons"] = 2498 (*handlers)["document.favicons"] =
2534 @selector(handleDocumentFaviconsMessage:context:); 2499 @selector(handleDocumentFaviconsMessage:context:);
2535 (*handlers)["document.submit"] = 2500 (*handlers)["document.submit"] =
2536 @selector(handleDocumentSubmitMessage:context:); 2501 @selector(handleDocumentSubmitMessage:context:);
2537 (*handlers)["externalRequest"] =
2538 @selector(handleExternalRequestMessage:context:);
2539 (*handlers)["form.activity"] = 2502 (*handlers)["form.activity"] =
2540 @selector(handleFormActivityMessage:context:); 2503 @selector(handleFormActivityMessage:context:);
2541 (*handlers)["navigator.credentials.request"] = 2504 (*handlers)["navigator.credentials.request"] =
2542 @selector(handleCredentialsRequestedMessage:context:); 2505 @selector(handleCredentialsRequestedMessage:context:);
2543 (*handlers)["navigator.credentials.notifySignedIn"] = 2506 (*handlers)["navigator.credentials.notifySignedIn"] =
2544 @selector(handleSignedInMessage:context:); 2507 @selector(handleSignedInMessage:context:);
2545 (*handlers)["navigator.credentials.notifySignedOut"] = 2508 (*handlers)["navigator.credentials.notifySignedOut"] =
2546 @selector(handleSignedOutMessage:context:); 2509 @selector(handleSignedOutMessage:context:);
2547 (*handlers)["navigator.credentials.notifyFailedSignIn"] = 2510 (*handlers)["navigator.credentials.notifyFailedSignIn"] =
2548 @selector(handleSignInFailedMessage:context:); 2511 @selector(handleSignInFailedMessage:context:);
2549 (*handlers)["resetExternalRequest"] =
2550 @selector(handleResetExternalRequestMessage:context:);
2551 (*handlers)["window.error"] = @selector(handleWindowErrorMessage:context:); 2512 (*handlers)["window.error"] = @selector(handleWindowErrorMessage:context:);
2552 (*handlers)["window.hashchange"] = 2513 (*handlers)["window.hashchange"] =
2553 @selector(handleWindowHashChangeMessage:context:); 2514 @selector(handleWindowHashChangeMessage:context:);
2554 (*handlers)["window.history.back"] = 2515 (*handlers)["window.history.back"] =
2555 @selector(handleWindowHistoryBackMessage:context:); 2516 @selector(handleWindowHistoryBackMessage:context:);
2556 (*handlers)["window.history.willChangeState"] = 2517 (*handlers)["window.history.willChangeState"] =
2557 @selector(handleWindowHistoryWillChangeStateMessage:context:); 2518 @selector(handleWindowHistoryWillChangeStateMessage:context:);
2558 (*handlers)["window.history.didPushState"] = 2519 (*handlers)["window.history.didPushState"] =
2559 @selector(handleWindowHistoryDidPushStateMessage:context:); 2520 @selector(handleWindowHistoryDidPushStateMessage:context:);
2560 (*handlers)["window.history.didReplaceState"] = 2521 (*handlers)["window.history.didReplaceState"] =
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 base::scoped_nsobject<NSSet> observers([_observers copy]); 2709 base::scoped_nsobject<NSSet> observers([_observers copy]);
2749 // We decide the form is user-submitted if the user has interacted with 2710 // We decide the form is user-submitted if the user has interacted with
2750 // the main page (using logic from the popup blocker), or if the keyboard 2711 // the main page (using logic from the popup blocker), or if the keyboard
2751 // is visible. 2712 // is visible.
2752 BOOL submittedByUser = [context[web::kUserIsInteractingKey] boolValue] || 2713 BOOL submittedByUser = [context[web::kUserIsInteractingKey] boolValue] ||
2753 [_webViewProxy keyboardAccessory]; 2714 [_webViewProxy keyboardAccessory];
2754 _webStateImpl->OnDocumentSubmitted(formName, submittedByUser); 2715 _webStateImpl->OnDocumentSubmitted(formName, submittedByUser);
2755 return YES; 2716 return YES;
2756 } 2717 }
2757 2718
2758 - (BOOL)handleExternalRequestMessage:(base::DictionaryValue*)message
2759 context:(NSDictionary*)context {
2760 std::string href;
2761 std::string target;
2762 std::string referrerPolicy;
2763 if (!message->GetString("href", &href)) {
2764 DLOG(WARNING) << "JS message parameter not found: href";
2765 return NO;
2766 }
2767 if (!message->GetString("target", &target)) {
2768 DLOG(WARNING) << "JS message parameter not found: target";
2769 return NO;
2770 }
2771 if (!message->GetString("referrerPolicy", &referrerPolicy)) {
2772 DLOG(WARNING) << "JS message parameter not found: referrerPolicy";
2773 return NO;
2774 }
2775 // Round-trip the href through NSURL; this URL will be compared as a
2776 // string against a UIWebView-provided NSURL later, and must match exactly
2777 // for the new window to trigger, so the escaping needs to be NSURL-style.
2778 // TODO(stuartmorgan): Comparing against a URL whose exact formatting we
2779 // don't control is fundamentally fragile; try to find another
2780 // way of handling this.
2781 DCHECK(context[web::kUserIsInteractingKey]);
2782 NSString* windowName =
2783 base::SysUTF8ToNSString(href + web::kWindowNameSeparator + target);
2784 _externalRequest.reset(new web::NewWindowInfo(
2785 net::GURLWithNSURL(net::NSURLWithGURL(GURL(href))), windowName,
2786 web::ReferrerPolicyFromString(referrerPolicy),
2787 [context[web::kUserIsInteractingKey] boolValue]));
2788 return YES;
2789 }
2790
2791 - (BOOL)handleFormActivityMessage:(base::DictionaryValue*)message 2719 - (BOOL)handleFormActivityMessage:(base::DictionaryValue*)message
2792 context:(NSDictionary*)context { 2720 context:(NSDictionary*)context {
2793 std::string formName; 2721 std::string formName;
2794 std::string fieldName; 2722 std::string fieldName;
2795 std::string type; 2723 std::string type;
2796 std::string value; 2724 std::string value;
2797 bool inputMissing = false; 2725 bool inputMissing = false;
2798 if (!message->GetString("formName", &formName) || 2726 if (!message->GetString("formName", &formName) ||
2799 !message->GetString("fieldName", &fieldName) || 2727 !message->GetString("fieldName", &fieldName) ||
2800 !message->GetString("type", &type) || 2728 !message->GetString("type", &type) ||
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 static_cast<int>(request_id), 2823 static_cast<int>(request_id),
2896 net::GURLWithNSURL(context[web::kOriginURLKey]), credential); 2824 net::GURLWithNSURL(context[web::kOriginURLKey]), credential);
2897 } else { 2825 } else {
2898 _webStateImpl->OnSignInFailed( 2826 _webStateImpl->OnSignInFailed(
2899 static_cast<int>(request_id), 2827 static_cast<int>(request_id),
2900 net::GURLWithNSURL(context[web::kOriginURLKey])); 2828 net::GURLWithNSURL(context[web::kOriginURLKey]));
2901 } 2829 }
2902 return YES; 2830 return YES;
2903 } 2831 }
2904 2832
2905 - (BOOL)handleResetExternalRequestMessage:(base::DictionaryValue*)message
2906 context:(NSDictionary*)context {
2907 _externalRequest.reset();
2908 return YES;
2909 }
2910
2911 - (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message 2833 - (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message
2912 context:(NSDictionary*)context { 2834 context:(NSDictionary*)context {
2913 std::string errorMessage; 2835 std::string errorMessage;
2914 if (!message->GetString("message", &errorMessage)) { 2836 if (!message->GetString("message", &errorMessage)) {
2915 DLOG(WARNING) << "JS message parameter not found: message"; 2837 DLOG(WARNING) << "JS message parameter not found: message";
2916 return NO; 2838 return NO;
2917 } 2839 }
2918 DLOG(ERROR) << "JavaScript error: " << errorMessage 2840 DLOG(ERROR) << "JavaScript error: " << errorMessage
2919 << " URL:" << [self currentURL].spec(); 2841 << " URL:" << [self currentURL].spec();
2920 return YES; 2842 return YES;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3238 // this for things that should be handled in the subclass instead. 3160 // this for things that should be handled in the subclass instead.
3239 - (BOOL)shouldAllowLoadWithNavigationAction:(WKNavigationAction*)action { 3161 - (BOOL)shouldAllowLoadWithNavigationAction:(WKNavigationAction*)action {
3240 NSURLRequest* request = action.request; 3162 NSURLRequest* request = action.request;
3241 GURL requestURL = net::GURLWithNSURL(request.URL); 3163 GURL requestURL = net::GURLWithNSURL(request.URL);
3242 3164
3243 // External application launcher needs |isNavigationTypeLinkActivated| to 3165 // External application launcher needs |isNavigationTypeLinkActivated| to
3244 // decide if the user intended to open the application by clicking on a link. 3166 // decide if the user intended to open the application by clicking on a link.
3245 BOOL isNavigationTypeLinkActivated = 3167 BOOL isNavigationTypeLinkActivated =
3246 action.navigationType == WKNavigationTypeLinkActivated; 3168 action.navigationType == WKNavigationTypeLinkActivated;
3247 3169
3248 // Check if the request should be delayed.
3249 if (_externalRequest && _externalRequest->url == requestURL) {
3250 // Links that can't be shown in a tab by Chrome but can be handled by
3251 // external apps (e.g. tel:, mailto:) are opened directly despite the target
3252 // attribute on the link. We don't open a new tab for them because Mobile
3253 // Safari doesn't do that (and sites are expecting us to do the same) and
3254 // also because there would be nothing shown in that new tab; it would
3255 // remain on about:blank (see crbug.com/240178)
3256 if ([CRWWebController webControllerCanShow:requestURL] ||
3257 ![_delegate openExternalURL:requestURL
3258 linkClicked:isNavigationTypeLinkActivated]) {
3259 web::NewWindowInfo windowInfo = *_externalRequest;
3260 dispatch_async(dispatch_get_main_queue(), ^{
3261 [self openPopupWithInfo:windowInfo];
3262 });
3263 }
3264 _externalRequest.reset();
3265 return NO;
3266 }
3267
3268 // Check if the link navigation leads to a launch of an external app. 3170 // Check if the link navigation leads to a launch of an external app.
3269 // TODO(crbug.com/607780): Revise the logic of allowing external app launch 3171 // TODO(crbug.com/607780): Revise the logic of allowing external app launch
3270 // and move it to externalAppLauncher. 3172 // and move it to externalAppLauncher.
3271 BOOL isOpenInNewTabNavigation = 3173 BOOL isOpenInNewTabNavigation =
3272 !_webStateImpl->GetNavigationManager()->GetItemCount(); 3174 !_webStateImpl->GetNavigationManager()->GetItemCount();
3273 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; 3175 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType];
3274 if (isPossibleLinkClick || isOpenInNewTabNavigation || 3176 if (isPossibleLinkClick || isOpenInNewTabNavigation ||
3275 PageTransitionCoreTypeIs([self currentTransition], 3177 PageTransitionCoreTypeIs([self currentTransition],
3276 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { 3178 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) {
3277 web::NavigationItem* item = [self currentNavItem]; 3179 web::NavigationItem* item = [self currentNavItem];
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
3503 if (![_delegate respondsToSelector:@selector(webController: 3405 if (![_delegate respondsToSelector:@selector(webController:
3504 shouldBlockPopupWithURL: 3406 shouldBlockPopupWithURL:
3505 sourceURL:)]) { 3407 sourceURL:)]) {
3506 return NO; 3408 return NO;
3507 } 3409 }
3508 return [_delegate webController:self 3410 return [_delegate webController:self
3509 shouldBlockPopupWithURL:popupURL 3411 shouldBlockPopupWithURL:popupURL
3510 sourceURL:sourceURL]; 3412 sourceURL:sourceURL];
3511 } 3413 }
3512 3414
3513 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo {
3514 const GURL url(windowInfo.url);
3515 web::NavigationItem* item = [self currentNavItem];
3516 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
3517 NSString* windowName = windowInfo.window_name.get();
3518 web::Referrer referrer(currentURL, windowInfo.referrer_policy);
3519 base::WeakNSObject<CRWWebController> weakSelf(self);
3520 void (^showPopupHandler)() = ^{
3521 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url
3522 referrer:referrer
3523 windowName:windowName
3524 inBackground:NO];
3525 DCHECK(!child || child.sessionController.openedByDOM);
3526 };
3527
3528 BOOL showPopup = windowInfo.user_is_interacting ||
3529 (![self shouldBlockPopupWithURL:url sourceURL:currentURL]);
3530 if (showPopup) {
3531 showPopupHandler();
3532 } else if ([_delegate
3533 respondsToSelector:@selector(webController:didBlockPopup:)]) {
3534 web::BlockedPopupInfo blockedPopupInfo(url, referrer, windowName,
3535 showPopupHandler);
3536 [_delegate webController:self didBlockPopup:blockedPopupInfo];
3537 }
3538 }
3539
3540 #pragma mark - 3415 #pragma mark -
3541 #pragma mark Auth Challenge 3416 #pragma mark Auth Challenge
3542 3417
3543 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge 3418 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge
3544 forCertAcceptPolicy:(web::CertAcceptPolicy)policy 3419 forCertAcceptPolicy:(web::CertAcceptPolicy)policy
3545 certStatus:(net::CertStatus)certStatus 3420 certStatus:(net::CertStatus)certStatus
3546 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, 3421 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition,
3547 NSURLCredential*))completionHandler { 3422 NSURLCredential*))completionHandler {
3548 SecTrustRef trust = challenge.protectionSpace.serverTrust; 3423 SecTrustRef trust = challenge.protectionSpace.serverTrust;
3549 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) { 3424 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) {
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after
5427 - (NSUInteger)observerCount { 5302 - (NSUInteger)observerCount {
5428 DCHECK_EQ(_observerBridges.size(), [_observers count]); 5303 DCHECK_EQ(_observerBridges.size(), [_observers count]);
5429 return [_observers count]; 5304 return [_observers count];
5430 } 5305 }
5431 5306
5432 - (void)simulateLoadRequestWithURL:(const GURL&)URL { 5307 - (void)simulateLoadRequestWithURL:(const GURL&)URL {
5433 _lastRegisteredRequestURL = URL; 5308 _lastRegisteredRequestURL = URL;
5434 _loadPhase = web::LOAD_REQUESTED; 5309 _loadPhase = web::LOAD_REQUESTED;
5435 } 5310 }
5436 5311
5437 - (NSString*)externalRequestWindowName {
5438 if (!_externalRequest || !_externalRequest->window_name)
5439 return @"";
5440 return _externalRequest->window_name;
5441 }
5442
5443 - (web::WebViewDocumentType)documentTypeFromMIMEType:(NSString*)MIMEType { 5312 - (web::WebViewDocumentType)documentTypeFromMIMEType:(NSString*)MIMEType {
5444 if (!MIMEType.length) { 5313 if (!MIMEType.length) {
5445 return web::WEB_VIEW_DOCUMENT_TYPE_UNKNOWN; 5314 return web::WEB_VIEW_DOCUMENT_TYPE_UNKNOWN;
5446 } 5315 }
5447 5316
5448 if ([MIMEType isEqualToString:@"text/html"] || 5317 if ([MIMEType isEqualToString:@"text/html"] ||
5449 [MIMEType isEqualToString:@"application/xhtml+xml"] || 5318 [MIMEType isEqualToString:@"application/xhtml+xml"] ||
5450 [MIMEType isEqualToString:@"application/xml"]) { 5319 [MIMEType isEqualToString:@"application/xml"]) {
5451 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; 5320 return web::WEB_VIEW_DOCUMENT_TYPE_HTML;
5452 } 5321 }
5453 5322
5454 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5323 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5455 } 5324 }
5456 5325
5457 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5326 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5458 return [action.request valueForHTTPHeaderField:@"Referer"]; 5327 return [action.request valueForHTTPHeaderField:@"Referer"];
5459 } 5328 }
5460 5329
5461 @end 5330 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698