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

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

Issue 2397623002: Don't allow link navigations for invalid URLs. (Closed)
Patch Set: compilation fix 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
« no previous file with comments | « no previous file | 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 4945 matching lines...) Expand 10 before | Expand all | Expand 10 after
4956 _webProcessIsDead = NO; 4956 _webProcessIsDead = NO;
4957 if (_isBeingDestroyed) { 4957 if (_isBeingDestroyed) {
4958 decisionHandler(WKNavigationActionPolicyCancel); 4958 decisionHandler(WKNavigationActionPolicyCancel);
4959 return; 4959 return;
4960 } 4960 }
4961 4961
4962 // The page will not be changed until this navigation is commited, so the 4962 // The page will not be changed until this navigation is commited, so the
4963 // retrieved state will be pending until |didCommitNavigation| callback. 4963 // retrieved state will be pending until |didCommitNavigation| callback.
4964 [self updatePendingNavigationInfoFromNavigationAction:action]; 4964 [self updatePendingNavigationInfoFromNavigationAction:action];
4965 4965
4966 // Invalid URLs should not be loaded. However, simply doing nothing upon
4967 // tapping a link or button is a jarring user experience. Instead, cancel
4968 // the invalid navigation and load about:blank.
4969 GURL requestURL = net::GURLWithNSURL(action.request.URL);
4970 if (!requestURL.is_valid()) {
4971 decisionHandler(WKNavigationActionPolicyCancel);
4972 GURL aboutBlankURL(url::kAboutBlankURL);
4973 web::NavigationManager::WebLoadParams loadParams(aboutBlankURL);
4974 loadParams.referrer = [self currentReferrer];
4975 self.webState->GetNavigationManager()->LoadURLWithParams(loadParams);
4976 return;
4977 }
4978
4966 BOOL allowLoad = [self shouldAllowLoadWithNavigationAction:action]; 4979 BOOL allowLoad = [self shouldAllowLoadWithNavigationAction:action];
4967 4980
4968 if (allowLoad) { 4981 if (allowLoad) {
4969 allowLoad = self.webStateImpl->ShouldAllowRequest(action.request); 4982 allowLoad = self.webStateImpl->ShouldAllowRequest(action.request);
4970 if (!allowLoad && action.targetFrame.mainFrame) { 4983 if (!allowLoad && action.targetFrame.mainFrame) {
4971 [_pendingNavigationInfo setCancelled:YES]; 4984 [_pendingNavigationInfo setCancelled:YES];
4972 } 4985 }
4973 } 4986 }
4974 4987
4975 decisionHandler(allowLoad ? WKNavigationActionPolicyAllow 4988 decisionHandler(allowLoad ? WKNavigationActionPolicyAllow
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
5632 } 5645 }
5633 5646
5634 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5647 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5635 } 5648 }
5636 5649
5637 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5650 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5638 return [action.request valueForHTTPHeaderField:@"Referer"]; 5651 return [action.request valueForHTTPHeaderField:@"Referer"];
5639 } 5652 }
5640 5653
5641 @end 5654 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698