Commit ac787558 authored by Livvie Lin's avatar Livvie Lin Committed by Commit Bot

[iOS] Don't display URL on lookalike URL blocking pages

Desktop/Android clears the URL from the omnibox for lookalike
interstitials to avoid showing a confusing punycode URL, so this
CL updates the iOS behavior to match.

Screenshots:
Before - https://drive.google.com/file/d/17wb35L2MsB8Kh4CGb_tvY370KGuXd_Xa/view?usp=sharing
After - https://drive.google.com/file/d/1NDXYXPse94sriH4pseR9g1ir114tOPJD/view?usp=sharing

Change-Id: I8962711b331e7d267f38576072868439500f45c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351968Reviewed-by: default avatarRobbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Commit-Queue: Livvie Lin <livvielin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801222}
parent 012c8f90
...@@ -116,6 +116,7 @@ source_set("location_bar_model_delegate") { ...@@ -116,6 +116,7 @@ source_set("location_bar_model_delegate") {
"//ios/chrome/browser/reading_list", "//ios/chrome/browser/reading_list",
"//ios/chrome/browser/ssl", "//ios/chrome/browser/ssl",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
"//ios/components/security_interstitials",
"//ios/components/webui:url_constants", "//ios/components/webui:url_constants",
"//ios/web/public", "//ios/web/public",
"//ios/web/public/security", "//ios/web/public/security",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/reading_list/offline_page_tab_helper.h" #import "ios/chrome/browser/reading_list/offline_page_tab_helper.h"
#include "ios/chrome/browser/web_state_list/web_state_list.h" #include "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/components/security_interstitials/ios_blocking_page_tab_helper.h"
#include "ios/components/webui/web_ui_url_constants.h" #include "ios/components/webui/web_ui_url_constants.h"
#import "ios/web/public/navigation/navigation_item.h" #import "ios/web/public/navigation/navigation_item.h"
#import "ios/web/public/navigation/navigation_manager.h" #import "ios/web/public/navigation/navigation_manager.h"
...@@ -66,6 +67,15 @@ bool LocationBarModelDelegateIOS::GetURL(GURL* url) const { ...@@ -66,6 +67,15 @@ bool LocationBarModelDelegateIOS::GetURL(GURL* url) const {
} }
bool LocationBarModelDelegateIOS::ShouldDisplayURL() const { bool LocationBarModelDelegateIOS::ShouldDisplayURL() const {
if (web::WebState* web_state = GetActiveWebState()) {
security_interstitials::IOSBlockingPageTabHelper* tab_helper =
security_interstitials::IOSBlockingPageTabHelper::FromWebState(
web_state);
if (tab_helper && tab_helper->GetCurrentBlockingPage()) {
return tab_helper->ShouldDisplayURL();
}
}
web::NavigationItem* item = GetNavigationItem(); web::NavigationItem* item = GetNavigationItem();
if (item) { if (item) {
GURL url = item->GetURL(); GURL url = item->GetURL();
......
...@@ -35,6 +35,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(LookalikeUrlAppInterface); ...@@ -35,6 +35,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(LookalikeUrlAppInterface);
using chrome_test_util::BackButton; using chrome_test_util::BackButton;
using chrome_test_util::ForwardButton; using chrome_test_util::ForwardButton;
using chrome_test_util::Omnibox;
using chrome_test_util::OmniboxText;
namespace { namespace {
// Relative paths used for a page that opens a lookalike in a new tab. // Relative paths used for a page that opens a lookalike in a new tab.
...@@ -119,6 +121,11 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -119,6 +121,11 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown. // Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL]; [ChromeEarlGrey loadURL:_lookalikeURL];
[ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent]; [ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent];
// Lookalike URL blocking pages should not display URL.
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:Omnibox()]
assertWithMatcher:OmniboxText("")];
// Tap on the "Go to" button and verify that the suggested page // Tap on the "Go to" button and verify that the suggested page
// contents are loaded. // contents are loaded.
...@@ -132,6 +139,8 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -132,6 +139,8 @@ const char kLookalikeInNewTabContent[] = "New tab";
[[EarlGrey selectElementWithMatcher:ForwardButton()] [[EarlGrey selectElementWithMatcher:ForwardButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent]; [ChromeEarlGrey waitForWebStateContainingText:_safeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_safeURL.GetContent())]
assertWithMatcher:grey_notNil()];
} }
// Tests that a lookalike URL navigation is blocked, and the text link for // Tests that a lookalike URL navigation is blocked, and the text link for
...@@ -141,11 +150,18 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -141,11 +150,18 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown. // Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL]; [ChromeEarlGrey loadURL:_lookalikeURL];
[ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent]; [ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent];
// Lookalike URL blocking pages should not display URL.
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:Omnibox()]
assertWithMatcher:OmniboxText("")];
// Tap on the site suggestion link and verify that the suggested page // Tap on the site suggestion link and verify that the suggested page
// contents are loaded. // contents are loaded.
[ChromeEarlGrey tapWebStateElementWithID:@"dont-proceed-link"]; [ChromeEarlGrey tapWebStateElementWithID:@"dont-proceed-link"];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent]; [ChromeEarlGrey waitForWebStateContainingText:_safeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_safeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// Verify that the warning is shown when navigating back and that safe // Verify that the warning is shown when navigating back and that safe
// content is shown when navigating forward again. // content is shown when navigating forward again.
...@@ -174,11 +190,18 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -174,11 +190,18 @@ const char kLookalikeInNewTabContent[] = "New tab";
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:l10n_util::GetStringUTF8( waitForWebStateContainingText:l10n_util::GetStringUTF8(
IDS_LOOKALIKE_URL_BACK_TO_SAFETY)]; IDS_LOOKALIKE_URL_BACK_TO_SAFETY)];
// Lookalike URL blocking pages should not display URL.
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:Omnibox()]
assertWithMatcher:OmniboxText("")];
// Tap on the "Back to safety" button and verify that the safe content // Tap on the "Back to safety" button and verify that the safe content
// is loaded. // is loaded.
[ChromeEarlGrey tapWebStateElementWithID:@"primary-button"]; [ChromeEarlGrey tapWebStateElementWithID:@"primary-button"];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent]; [ChromeEarlGrey waitForWebStateContainingText:_safeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_safeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// Verify that the warning is shown when navigating forward and that safe // Verify that the warning is shown when navigating forward and that safe
// content is shown when navigating back again. // content is shown when navigating back again.
...@@ -211,6 +234,11 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -211,6 +234,11 @@ const char kLookalikeInNewTabContent[] = "New tab";
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:l10n_util::GetStringUTF8( waitForWebStateContainingText:l10n_util::GetStringUTF8(
IDS_LOOKALIKE_URL_CLOSE_PAGE)]; IDS_LOOKALIKE_URL_CLOSE_PAGE)];
// Lookalike URL blocking pages should not display URL.
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:Omnibox()]
assertWithMatcher:OmniboxText("")];
// Tap on the "Close" button and verify that the page closes. // Tap on the "Close" button and verify that the page closes.
[ChromeEarlGrey tapWebStateElementWithID:@"primary-button"]; [ChromeEarlGrey tapWebStateElementWithID:@"primary-button"];
...@@ -223,10 +251,17 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -223,10 +251,17 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown. // Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL]; [ChromeEarlGrey loadURL:_lookalikeURL];
[ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent]; [ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent];
// Lookalike URL blocking pages should not display URL.
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:Omnibox()]
assertWithMatcher:OmniboxText("")];
// Tap on the link to ignore the warning, and verify that the page is loaded. // Tap on the link to ignore the warning, and verify that the page is loaded.
[ChromeEarlGrey tapWebStateElementWithID:@"proceed-button"]; [ChromeEarlGrey tapWebStateElementWithID:@"proceed-button"];
[ChromeEarlGrey waitForWebStateContainingText:kLookalikeContent]; [ChromeEarlGrey waitForWebStateContainingText:kLookalikeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// In a new tab, the warning should not be shown. // In a new tab, the warning should not be shown.
[ChromeEarlGrey openNewTab]; [ChromeEarlGrey openNewTab];
...@@ -248,10 +283,17 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -248,10 +283,17 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown. // Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL]; [ChromeEarlGrey loadURL:_lookalikeURL];
[ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent]; [ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent];
// Lookalike URL blocking pages should not display URL.
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:Omnibox()]
assertWithMatcher:OmniboxText("")];
// Tap on the link to ignore the warning, and verify that the page is loaded. // Tap on the link to ignore the warning, and verify that the page is loaded.
[ChromeEarlGrey tapWebStateElementWithID:@"proceed-button"]; [ChromeEarlGrey tapWebStateElementWithID:@"proceed-button"];
[ChromeEarlGrey waitForWebStateContainingText:kLookalikeContent]; [ChromeEarlGrey waitForWebStateContainingText:kLookalikeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// Verify that no warning is shown when navigating back and then forward to // Verify that no warning is shown when navigating back and then forward to
// the unsafe page. // the unsafe page.
...@@ -274,6 +316,11 @@ const char kLookalikeInNewTabContent[] = "New tab"; ...@@ -274,6 +316,11 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike URL page and verify a warning is shown. // Load the lookalike URL page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL]; [ChromeEarlGrey loadURL:_lookalikeURL];
[ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent]; [ChromeEarlGrey waitForWebStateContainingText:_lookalikeBlockingPageContent];
// Lookalike URL blocking pages should not display URL.
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:Omnibox()]
assertWithMatcher:OmniboxText("")];
// Tap on the "Go to" button and verify that the suggested page contents // Tap on the "Go to" button and verify that the suggested page contents
// are loaded. // are loaded.
......
...@@ -32,6 +32,9 @@ class IOSBlockingPageTabHelper ...@@ -32,6 +32,9 @@ class IOSBlockingPageTabHelper
int64_t navigation_id, int64_t navigation_id,
std::unique_ptr<IOSSecurityInterstitialPage> blocking_page); std::unique_ptr<IOSSecurityInterstitialPage> blocking_page);
// Determines whether a URL should be shown on the current navigation page.
bool ShouldDisplayURL() const;
// Returns the blocking page for the currently-visible interstitial, if any. // Returns the blocking page for the currently-visible interstitial, if any.
IOSSecurityInterstitialPage* GetCurrentBlockingPage() const; IOSSecurityInterstitialPage* GetCurrentBlockingPage() const;
......
...@@ -48,6 +48,10 @@ void IOSBlockingPageTabHelper::AssociateBlockingPage( ...@@ -48,6 +48,10 @@ void IOSBlockingPageTabHelper::AssociateBlockingPage(
} }
} }
bool IOSBlockingPageTabHelper::ShouldDisplayURL() const {
return blocking_page_for_currently_committed_navigation_->ShouldDisplayURL();
}
IOSSecurityInterstitialPage* IOSBlockingPageTabHelper::GetCurrentBlockingPage() IOSSecurityInterstitialPage* IOSBlockingPageTabHelper::GetCurrentBlockingPage()
const { const {
return blocking_page_for_currently_committed_navigation_.get(); return blocking_page_for_currently_committed_navigation_.get();
......
...@@ -38,6 +38,10 @@ class IOSSecurityInterstitialPage : public web::WebInterstitialDelegate { ...@@ -38,6 +38,10 @@ class IOSSecurityInterstitialPage : public web::WebInterstitialDelegate {
// web::WebInterstitialDelegate implementation. // web::WebInterstitialDelegate implementation.
std::string GetHtmlContents() const override; std::string GetHtmlContents() const override;
// Whether a URL should be displayed on this interstitial page. This is
// respected by committed interstitials only.
virtual bool ShouldDisplayURL() const;
// Handles JS commands from the interstitial page. Overridden in subclasses // Handles JS commands from the interstitial page. Overridden in subclasses
// to handle actions specific to the type of interstitial. // to handle actions specific to the type of interstitial.
virtual void HandleScriptCommand(const base::DictionaryValue& message, virtual void HandleScriptCommand(const base::DictionaryValue& message,
......
...@@ -87,6 +87,10 @@ std::string IOSSecurityInterstitialPage::GetHtmlContents() const { ...@@ -87,6 +87,10 @@ std::string IOSSecurityInterstitialPage::GetHtmlContents() const {
return webui::GetI18nTemplateHtml(html, &load_time_data); return webui::GetI18nTemplateHtml(html, &load_time_data);
} }
bool IOSSecurityInterstitialPage::ShouldDisplayURL() const {
return true;
}
base::string16 IOSSecurityInterstitialPage::GetFormattedHostName() const { base::string16 IOSSecurityInterstitialPage::GetFormattedHostName() const {
return security_interstitials::common_string_util::GetFormattedHostName( return security_interstitials::common_string_util::GetFormattedHostName(
request_url_); request_url_);
......
...@@ -33,6 +33,7 @@ class LookalikeUrlBlockingPage ...@@ -33,6 +33,7 @@ class LookalikeUrlBlockingPage
bool ShouldCreateNewNavigation() const override; bool ShouldCreateNewNavigation() const override;
void PopulateInterstitialStrings( void PopulateInterstitialStrings(
base::DictionaryValue* load_time_data) const override; base::DictionaryValue* load_time_data) const override;
bool ShouldDisplayURL() const override;
private: private:
void HandleScriptCommand(const base::DictionaryValue& message, void HandleScriptCommand(const base::DictionaryValue& message,
......
...@@ -70,6 +70,10 @@ void LookalikeUrlBlockingPage::PopulateInterstitialStrings( ...@@ -70,6 +70,10 @@ void LookalikeUrlBlockingPage::PopulateInterstitialStrings(
request_url()); request_url());
} }
bool LookalikeUrlBlockingPage::ShouldDisplayURL() const {
return false;
}
void LookalikeUrlBlockingPage::HandleScriptCommand( void LookalikeUrlBlockingPage::HandleScriptCommand(
const base::DictionaryValue& message, const base::DictionaryValue& message,
const GURL& origin_url, const GURL& origin_url,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment