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

Unelide URLs when specified extension enabled

When go/herd-immunity (Google internal doc) extension is enabled,
unelide URLs and turn off Query in Omnibox. We're choosing to hard-code
the extension id since only one extension needs this, and we don't need
the added complexity of making this an extension API.

Bug: 914422
Change-Id: I1c8f3ddd6f236d2812adad6272225aa07d47fb54
Reviewed-on: https://chromium-review.googlesource.com/c/1415751
Commit-Queue: Livvie Lin <livvielin@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625451}
parent 068db411
...@@ -34,6 +34,13 @@ ...@@ -34,6 +34,13 @@
#include "chrome/browser/offline_pages/offline_page_utils.h" #include "chrome/browser/offline_pages/offline_page_utils.h"
#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_registry.h"
// Id for extension that enables users to report sites to Safe Browsing.
const char kPreventElisionExtensionId[] = "ekpgepffboojnckiahkpangdldnjafnj";
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
ChromeLocationBarModelDelegate::ChromeLocationBarModelDelegate() {} ChromeLocationBarModelDelegate::ChromeLocationBarModelDelegate() {}
ChromeLocationBarModelDelegate::~ChromeLocationBarModelDelegate() {} ChromeLocationBarModelDelegate::~ChromeLocationBarModelDelegate() {}
...@@ -63,6 +70,17 @@ bool ChromeLocationBarModelDelegate::GetURL(GURL* url) const { ...@@ -63,6 +70,17 @@ bool ChromeLocationBarModelDelegate::GetURL(GURL* url) const {
return true; return true;
} }
bool ChromeLocationBarModelDelegate::ShouldPreventElision() const {
#if BUILDFLAG(ENABLE_EXTENSIONS)
Profile* const profile = GetProfile();
return profile && extensions::ExtensionRegistry::Get(profile)
->enabled_extensions()
.Contains(kPreventElisionExtensionId);
#else
return false;
#endif
}
bool ChromeLocationBarModelDelegate::ShouldDisplayURL() const { bool ChromeLocationBarModelDelegate::ShouldDisplayURL() const {
// Note: The order here is important. // Note: The order here is important.
// - The WebUI test must come before the extension scheme test because there // - The WebUI test must come before the extension scheme test because there
......
...@@ -23,6 +23,9 @@ class ChromeLocationBarModelDelegate : public LocationBarModelDelegate { ...@@ -23,6 +23,9 @@ class ChromeLocationBarModelDelegate : public LocationBarModelDelegate {
// Returns active WebContents. // Returns active WebContents.
virtual content::WebContents* GetActiveWebContents() const = 0; virtual content::WebContents* GetActiveWebContents() const = 0;
// Prevents URL elision depending on whether a specified extension installed.
bool ShouldPreventElision() const override;
// LocationBarModelDelegate: // LocationBarModelDelegate:
bool ShouldDisplayURL() const override; bool ShouldDisplayURL() const override;
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include "components/omnibox/browser/location_bar_model_delegate.h" #include "components/omnibox/browser/location_bar_model_delegate.h"
bool LocationBarModelDelegate::ShouldPreventElision() const {
return false;
}
bool LocationBarModelDelegate::ShouldDisplayURL() const { bool LocationBarModelDelegate::ShouldDisplayURL() const {
return true; return true;
} }
......
...@@ -36,6 +36,10 @@ class LocationBarModelDelegate { ...@@ -36,6 +36,10 @@ class LocationBarModelDelegate {
// exists. Otherwise returns false and leaves |url| unmodified. // exists. Otherwise returns false and leaves |url| unmodified.
virtual bool GetURL(GURL* url) const = 0; virtual bool GetURL(GURL* url) const = 0;
// Returns whether we should prevent elision of the display URL and turn off
// query in omnibox. Based on whether user has a specified extension enabled.
virtual bool ShouldPreventElision() const;
// Returns whether the URL for the current navigation entry should be // Returns whether the URL for the current navigation entry should be
// in the location bar. // in the location bar.
virtual bool ShouldDisplayURL() const; virtual bool ShouldDisplayURL() const;
......
...@@ -48,6 +48,11 @@ base::string16 LocationBarModelImpl::GetURLForDisplay() const { ...@@ -48,6 +48,11 @@ base::string16 LocationBarModelImpl::GetURLForDisplay() const {
url_formatter::FormatUrlTypes format_types = url_formatter::FormatUrlTypes format_types =
url_formatter::kFormatUrlOmitDefaults; url_formatter::kFormatUrlOmitDefaults;
// Early exit to prevent elision of URLs when relevant extension is enabled.
if (delegate_->ShouldPreventElision()) {
return GetFormattedURL(format_types);
}
#if defined(OS_IOS) #if defined(OS_IOS)
format_types |= url_formatter::kFormatUrlTrimAfterHost; format_types |= url_formatter::kFormatUrlTrimAfterHost;
#endif #endif
...@@ -102,7 +107,8 @@ security_state::SecurityLevel LocationBarModelImpl::GetSecurityLevel( ...@@ -102,7 +107,8 @@ security_state::SecurityLevel LocationBarModelImpl::GetSecurityLevel(
} }
bool LocationBarModelImpl::GetDisplaySearchTerms(base::string16* search_terms) { bool LocationBarModelImpl::GetDisplaySearchTerms(base::string16* search_terms) {
if (!base::FeatureList::IsEnabled(omnibox::kQueryInOmnibox)) if (!base::FeatureList::IsEnabled(omnibox::kQueryInOmnibox) ||
delegate_->ShouldPreventElision())
return false; return false;
// Only show the search terms if the site is secure. However, make an // Only show the search terms if the site is secure. However, make an
......
...@@ -18,6 +18,9 @@ namespace { ...@@ -18,6 +18,9 @@ namespace {
class FakeLocationBarModelDelegate : public LocationBarModelDelegate { class FakeLocationBarModelDelegate : public LocationBarModelDelegate {
public: public:
void SetURL(const GURL& url) { url_ = url; } void SetURL(const GURL& url) { url_ = url; }
void SetShouldPreventElision(bool should_prevent_elision) {
should_prevent_elision_ = should_prevent_elision;
}
void SetSecurityInfo(const security_state::SecurityInfo& info) { void SetSecurityInfo(const security_state::SecurityInfo& info) {
security_info_ = info; security_info_ = info;
} }
...@@ -34,6 +37,8 @@ class FakeLocationBarModelDelegate : public LocationBarModelDelegate { ...@@ -34,6 +37,8 @@ class FakeLocationBarModelDelegate : public LocationBarModelDelegate {
return true; return true;
} }
bool ShouldPreventElision() const override { return should_prevent_elision_; }
void GetSecurityInfo(security_state::SecurityInfo* result) const override { void GetSecurityInfo(security_state::SecurityInfo* result) const override {
*result = security_info_; *result = security_info_;
} }
...@@ -50,6 +55,7 @@ class FakeLocationBarModelDelegate : public LocationBarModelDelegate { ...@@ -50,6 +55,7 @@ class FakeLocationBarModelDelegate : public LocationBarModelDelegate {
GURL url_; GURL url_;
security_state::SecurityInfo security_info_; security_state::SecurityInfo security_info_;
TestOmniboxClient omnibox_client_; TestOmniboxClient omnibox_client_;
bool should_prevent_elision_ = false;
}; };
class LocationBarModelImplTest : public testing::Test { class LocationBarModelImplTest : public testing::Test {
...@@ -86,6 +92,28 @@ TEST_F(LocationBarModelImplTest, ...@@ -86,6 +92,28 @@ TEST_F(LocationBarModelImplTest,
model()->GetURLForDisplay()); model()->GetURLForDisplay());
} }
TEST_F(LocationBarModelImplTest, PreventElisionWorks) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
{omnibox::kHideSteadyStateUrlScheme,
omnibox::kHideSteadyStateUrlTrivialSubdomains, omnibox::kQueryInOmnibox},
{});
delegate()->SetShouldPreventElision(true);
delegate()->SetURL(GURL("https://www.google.com/search?q=foo+query+unelide"));
EXPECT_EQ(base::ASCIIToUTF16(
"https://www.google.com/search?q=foo+query+unelide/TestSuffix"),
model()->GetURLForDisplay());
// Verify that query in omnibox is turned off.
security_state::SecurityInfo info;
info.connection_info_initialized = true;
info.security_level = security_state::SecurityLevel::SECURE;
delegate()->SetSecurityInfo(info);
EXPECT_FALSE(model()->GetDisplaySearchTerms(nullptr));
}
TEST_F(LocationBarModelImplTest, QueryInOmniboxFeatureFlagWorks) { TEST_F(LocationBarModelImplTest, QueryInOmniboxFeatureFlagWorks) {
delegate()->SetURL(kValidSearchResultsPage); delegate()->SetURL(kValidSearchResultsPage);
security_state::SecurityInfo info; security_state::SecurityInfo info;
......
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