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") {
"//ios/chrome/browser/reading_list",
"//ios/chrome/browser/ssl",
"//ios/chrome/browser/web_state_list",
"//ios/components/security_interstitials",
"//ios/components/webui:url_constants",
"//ios/web/public",
"//ios/web/public/security",
......
......@@ -16,6 +16,7 @@
#include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/reading_list/offline_page_tab_helper.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"
#import "ios/web/public/navigation/navigation_item.h"
#import "ios/web/public/navigation/navigation_manager.h"
......@@ -66,6 +67,15 @@ bool LocationBarModelDelegateIOS::GetURL(GURL* url) 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();
if (item) {
GURL url = item->GetURL();
......
......@@ -35,6 +35,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(LookalikeUrlAppInterface);
using chrome_test_util::BackButton;
using chrome_test_util::ForwardButton;
using chrome_test_util::Omnibox;
using chrome_test_util::OmniboxText;
namespace {
// Relative paths used for a page that opens a lookalike in a new tab.
......@@ -119,6 +121,11 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL];
[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 are loaded.
......@@ -132,6 +139,8 @@ const char kLookalikeInNewTabContent[] = "New tab";
[[EarlGrey selectElementWithMatcher:ForwardButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_safeURL.GetContent())]
assertWithMatcher:grey_notNil()];
}
// Tests that a lookalike URL navigation is blocked, and the text link for
......@@ -141,11 +150,18 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL];
[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
// contents are loaded.
[ChromeEarlGrey tapWebStateElementWithID:@"dont-proceed-link"];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_safeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// Verify that the warning is shown when navigating back and that safe
// content is shown when navigating forward again.
......@@ -174,11 +190,18 @@ const char kLookalikeInNewTabContent[] = "New tab";
[ChromeEarlGrey
waitForWebStateContainingText:l10n_util::GetStringUTF8(
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
// is loaded.
[ChromeEarlGrey tapWebStateElementWithID:@"primary-button"];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_safeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// Verify that the warning is shown when navigating forward and that safe
// content is shown when navigating back again.
......@@ -211,6 +234,11 @@ const char kLookalikeInNewTabContent[] = "New tab";
[ChromeEarlGrey
waitForWebStateContainingText:l10n_util::GetStringUTF8(
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.
[ChromeEarlGrey tapWebStateElementWithID:@"primary-button"];
......@@ -223,10 +251,17 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL];
[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.
[ChromeEarlGrey tapWebStateElementWithID:@"proceed-button"];
[ChromeEarlGrey waitForWebStateContainingText:kLookalikeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// In a new tab, the warning should not be shown.
[ChromeEarlGrey openNewTab];
......@@ -248,10 +283,17 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL];
[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.
[ChromeEarlGrey tapWebStateElementWithID:@"proceed-button"];
[ChromeEarlGrey waitForWebStateContainingText:kLookalikeContent];
[[EarlGrey selectElementWithMatcher:OmniboxText(_lookalikeURL.GetContent())]
assertWithMatcher:grey_notNil()];
// Verify that no warning is shown when navigating back and then forward to
// the unsafe page.
......@@ -274,6 +316,11 @@ const char kLookalikeInNewTabContent[] = "New tab";
// Load the lookalike URL page and verify a warning is shown.
[ChromeEarlGrey loadURL:_lookalikeURL];
[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
// are loaded.
......
......@@ -32,6 +32,9 @@ class IOSBlockingPageTabHelper
int64_t navigation_id,
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.
IOSSecurityInterstitialPage* GetCurrentBlockingPage() const;
......
......@@ -48,6 +48,10 @@ void IOSBlockingPageTabHelper::AssociateBlockingPage(
}
}
bool IOSBlockingPageTabHelper::ShouldDisplayURL() const {
return blocking_page_for_currently_committed_navigation_->ShouldDisplayURL();
}
IOSSecurityInterstitialPage* IOSBlockingPageTabHelper::GetCurrentBlockingPage()
const {
return blocking_page_for_currently_committed_navigation_.get();
......
......@@ -38,6 +38,10 @@ class IOSSecurityInterstitialPage : public web::WebInterstitialDelegate {
// web::WebInterstitialDelegate implementation.
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
// to handle actions specific to the type of interstitial.
virtual void HandleScriptCommand(const base::DictionaryValue& message,
......
......@@ -87,6 +87,10 @@ std::string IOSSecurityInterstitialPage::GetHtmlContents() const {
return webui::GetI18nTemplateHtml(html, &load_time_data);
}
bool IOSSecurityInterstitialPage::ShouldDisplayURL() const {
return true;
}
base::string16 IOSSecurityInterstitialPage::GetFormattedHostName() const {
return security_interstitials::common_string_util::GetFormattedHostName(
request_url_);
......
......@@ -33,6 +33,7 @@ class LookalikeUrlBlockingPage
bool ShouldCreateNewNavigation() const override;
void PopulateInterstitialStrings(
base::DictionaryValue* load_time_data) const override;
bool ShouldDisplayURL() const override;
private:
void HandleScriptCommand(const base::DictionaryValue& message,
......
......@@ -70,6 +70,10 @@ void LookalikeUrlBlockingPage::PopulateInterstitialStrings(
request_url());
}
bool LookalikeUrlBlockingPage::ShouldDisplayURL() const {
return false;
}
void LookalikeUrlBlockingPage::HandleScriptCommand(
const base::DictionaryValue& message,
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