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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/ui/crw_web_controller.mm
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index a1f5aa0211eef998ec0e47ebedb88e7325a85d75..4b3851642a5e02d492e6878998756f4ae43df959 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -4963,6 +4963,19 @@ - (void)webView:(WKWebView*)webView
// retrieved state will be pending until |didCommitNavigation| callback.
[self updatePendingNavigationInfoFromNavigationAction:action];
+ // Invalid URLs should not be loaded. However, simply doing nothing upon
+ // tapping a link or button is a jarring user experience. Instead, cancel
+ // the invalid navigation and load about:blank.
+ GURL requestURL = net::GURLWithNSURL(action.request.URL);
+ if (!requestURL.is_valid()) {
+ decisionHandler(WKNavigationActionPolicyCancel);
+ GURL aboutBlankURL(url::kAboutBlankURL);
+ web::NavigationManager::WebLoadParams loadParams(aboutBlankURL);
+ loadParams.referrer = [self currentReferrer];
+ self.webState->GetNavigationManager()->LoadURLWithParams(loadParams);
+ return;
+ }
+
BOOL allowLoad = [self shouldAllowLoadWithNavigationAction:action];
if (allowLoad) {
« 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