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