summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw <brettw@chromium.org>2016-01-22 16:46:38 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-23 00:48:00 +0000
commitb65cd5c1a3b0d3fa5700d808afeb111d2f0ef2d0 (patch)
tree8a8616add122edddfb82cc8fcedb865e31fffc77
parentb47b47617273a91db8fd74c357a756cd189a4342 (diff)
downloadchromium_src-b65cd5c1a3b0d3fa5700d808afeb111d2f0ef2d0.zip
chromium_src-b65cd5c1a3b0d3fa5700d808afeb111d2f0ef2d0.tar.gz
chromium_src-b65cd5c1a3b0d3fa5700d808afeb111d2f0ef2d0.tar.bz2
Convert some URL accessors to use StringPieces
Updates some google util, registry controlled domain, and net util code to use string pieces in their APIs. Convert some google util functions to take a const ref GURL instead of a copy. Review URL: https://codereview.chromium.org/1614223003 Cr-Commit-Position: refs/heads/master@{#371101}
-rw-r--r--chrome/browser/android/history_report/delta_file_commons.cc2
-rw-r--r--chrome/browser/android/history_report/usage_report_util.cc2
-rw-r--r--chrome/browser/android/tab_web_contents_delegate_android.cc4
-rw-r--r--chrome/browser/android/url_utilities.cc2
-rw-r--r--chrome/browser/browsing_data/browsing_data_local_storage_helper_browsertest.cc2
-rw-r--r--chrome/browser/chrome_content_browser_client.cc6
-rw-r--r--chrome/browser/chromeos/file_system_provider/request_manager.cc4
-rw-r--r--chrome/browser/chromeos/login/signin/merge_session_throttling_utils.cc2
-rw-r--r--chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc8
-rw-r--r--chrome/browser/custom_home_pages_table_model.cc8
-rw-r--r--chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc2
-rw-r--r--chrome/browser/extensions/extension_override_apitest.cc2
-rw-r--r--chrome/browser/extensions/extension_special_storage_policy.cc2
-rw-r--r--chrome/browser/extensions/ntp_overridden_bubble_delegate.cc2
-rw-r--r--chrome/browser/favicon/favicon_utils.cc2
-rw-r--r--chrome/browser/first_run/first_run.cc4
-rw-r--r--chrome/browser/net/predictor.cc4
-rw-r--r--chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc4
-rw-r--r--chrome/browser/page_load_metrics/observers/google_captcha_observer.cc7
-rw-r--r--chrome/browser/password_manager/chrome_password_manager_client.cc3
-rw-r--r--chrome/browser/plugins/chrome_plugin_service_filter.cc6
-rw-r--r--chrome/browser/policy/cloud/test_request_interceptor.cc2
-rw-r--r--chrome/browser/prerender/prerender_manager.cc2
-rw-r--r--chrome/browser/prerender/prerender_util.cc9
-rw-r--r--chrome/browser/printing/print_preview_dialog_controller.cc2
-rw-r--r--chrome/browser/profiles/profile_io_data.cc4
-rw-r--r--chrome/browser/ui/toolbar/toolbar_model_impl.cc2
-rw-r--r--components/google/core/browser/google_util.cc62
-rw-r--r--components/google/core/browser/google_util.h12
-rw-r--r--net/base/registry_controlled_domains/registry_controlled_domain.cc43
-rw-r--r--net/base/registry_controlled_domains/registry_controlled_domain.h5
-rw-r--r--net/base/url_util.cc6
-rw-r--r--net/base/url_util.h4
33 files changed, 120 insertions, 111 deletions
diff --git a/chrome/browser/android/history_report/delta_file_commons.cc b/chrome/browser/android/history_report/delta_file_commons.cc
index d7d6cba..7f35cb6 100644
--- a/chrome/browser/android/history_report/delta_file_commons.cc
+++ b/chrome/browser/android/history_report/delta_file_commons.cc
@@ -110,7 +110,7 @@ std::string DeltaFileEntryWithData::Url() const {
base::string16 DeltaFileEntryWithData::Title() const {
if (!Valid()) return base::UTF8ToUTF16("");
if (is_bookmark_ && !bookmark_title_.empty()) return bookmark_title_;
- if (data_.title().empty()) return base::UTF8ToUTF16(data_.url().host());
+ if (data_.title().empty()) return base::UTF8ToUTF16(data_.url().host_piece());
return data_.title();
}
diff --git a/chrome/browser/android/history_report/usage_report_util.cc b/chrome/browser/android/history_report/usage_report_util.cc
index 0138426..c2c696e 100644
--- a/chrome/browser/android/history_report/usage_report_util.cc
+++ b/chrome/browser/android/history_report/usage_report_util.cc
@@ -41,7 +41,7 @@ bool ShouldIgnoreUrl(const GURL& url) {
return true;
// Ignore localhost URLs.
- if (net::IsLocalhost(url.host()))
+ if (net::IsLocalhost(url.host_piece()))
return true;
return false;
diff --git a/chrome/browser/android/tab_web_contents_delegate_android.cc b/chrome/browser/android/tab_web_contents_delegate_android.cc
index d2a1e48..664328e 100644
--- a/chrome/browser/android/tab_web_contents_delegate_android.cc
+++ b/chrome/browser/android/tab_web_contents_delegate_android.cc
@@ -153,9 +153,9 @@ bool TabWebContentsDelegateAndroid::ShouldFocusLocationBarByDefault(
GURL url = entry->GetURL();
GURL virtual_url = entry->GetVirtualURL();
if ((url.SchemeIs(chrome::kChromeUINativeScheme) &&
- url.host() == chrome::kChromeUINewTabHost) ||
+ url.host_piece() == chrome::kChromeUINewTabHost) ||
(virtual_url.SchemeIs(chrome::kChromeUINativeScheme) &&
- virtual_url.host() == chrome::kChromeUINewTabHost)) {
+ virtual_url.host_piece() == chrome::kChromeUINewTabHost)) {
return true;
}
}
diff --git a/chrome/browser/android/url_utilities.cc b/chrome/browser/android/url_utilities.cc
index 742cd09..1a3b673 100644
--- a/chrome/browser/android/url_utilities.cc
+++ b/chrome/browser/android/url_utilities.cc
@@ -52,7 +52,7 @@ static jboolean SameHost(JNIEnv* env,
const JavaParamRef<jstring>& url_2_str) {
GURL url_1 = ConvertJavaStringToGURL(env, url_1_str);
GURL url_2 = ConvertJavaStringToGURL(env, url_2_str);
- return url_1.host() == url_2.host();
+ return url_1.host_piece() == url_2.host_piece();
}
static ScopedJavaLocalRef<jstring> GetDomainAndRegistry(
diff --git a/chrome/browser/browsing_data/browsing_data_local_storage_helper_browsertest.cc b/chrome/browser/browsing_data/browsing_data_local_storage_helper_browsertest.cc
index 683c5aa..0851507 100644
--- a/chrome/browser/browsing_data/browsing_data_local_storage_helper_browsertest.cc
+++ b/chrome/browser/browsing_data/browsing_data_local_storage_helper_browsertest.cc
@@ -93,7 +93,7 @@ class StopTestOnCallback {
for (size_t i = 0; i < arraysize(kTestHosts); ++i) {
for (const auto& info : local_storage_info) {
ASSERT_TRUE(info.origin_url.SchemeIs("http"));
- if (info.origin_url.host() == kTestHosts[i]) {
+ if (info.origin_url.host_piece() == kTestHosts[i]) {
ASSERT_FALSE(test_hosts_found[i]);
test_hosts_found[i] = true;
}
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index b3cdde7..4ef4c6f 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -384,7 +384,9 @@ GURL ReplaceURLHostAndPath(const GURL& url,
// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
GURL AddUberHost(const GURL& url) {
const std::string uber_host = chrome::kChromeUIUberHost;
- const std::string new_path = url.host() + url.path();
+ std::string new_path;
+ url.host_piece().AppendToString(&new_path);
+ url.path_piece().AppendToString(&new_path);
return ReplaceURLHostAndPath(url, uber_host, new_path);
}
@@ -1118,7 +1120,7 @@ bool ChromeContentBrowserClient::ShouldAllowOpenURL(
// the signin page may host untrusted web content.
if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
url.SchemeIs(content::kChromeUIScheme) &&
- url.host() != chrome::kChromeUIChromeSigninHost) {
+ url.host_piece() != chrome::kChromeUIChromeSigninHost) {
VLOG(1) << "Blocked navigation to " << url.spec() << " from "
<< chrome::kChromeUIChromeSigninURL;
return false;
diff --git a/chrome/browser/chromeos/file_system_provider/request_manager.cc b/chrome/browser/chromeos/file_system_provider/request_manager.cc
index fb2f141..f54e906 100644
--- a/chrome/browser/chromeos/file_system_provider/request_manager.cc
+++ b/chrome/browser/chromeos/file_system_provider/request_manager.cc
@@ -239,8 +239,8 @@ bool RequestManager::IsInteractingWithUser() const {
const content::WebContents* const web_contents =
tabs->GetWebContentsAt(i);
const GURL& url = web_contents->GetURL();
- if (url.scheme() == extensions::kExtensionScheme &&
- url.host() == extension_id_) {
+ if (url.SchemeIs(extensions::kExtensionScheme) &&
+ url.host_piece() == extension_id_) {
return true;
}
}
diff --git a/chrome/browser/chromeos/login/signin/merge_session_throttling_utils.cc b/chrome/browser/chromeos/login/signin/merge_session_throttling_utils.cc
index 68a74d7..27d0f69 100644
--- a/chrome/browser/chromeos/login/signin/merge_session_throttling_utils.cc
+++ b/chrome/browser/chromeos/login/signin/merge_session_throttling_utils.cc
@@ -172,7 +172,7 @@ bool ShouldDelayUrl(const GURL& url) {
// we will show delayed loading page instead.
return !net::NetworkChangeNotifier::IsOffline() &&
!AreAllSessionMergedAlready() &&
- google_util::IsGoogleHostname(url.host(),
+ google_util::IsGoogleHostname(url.host_piece(),
google_util::ALLOW_SUBDOMAIN);
}
diff --git a/chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc b/chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc
index 4713fde..1f57a8f 100644
--- a/chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc
+++ b/chrome/browser/custom_handlers/register_protocol_handler_permission_request.cc
@@ -66,13 +66,13 @@ RegisterProtocolHandlerPermissionRequest::GetMessageText() const {
return old_handler.IsEmpty() ?
l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
- base::UTF8ToUTF16(handler_.url().host()),
+ base::UTF8ToUTF16(handler_.url().host_piece()),
GetProtocolName(handler_)) :
l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
- base::UTF8ToUTF16(handler_.url().host()),
+ base::UTF8ToUTF16(handler_.url().host_piece()),
GetProtocolName(handler_),
- base::UTF8ToUTF16(old_handler.url().host()));
+ base::UTF8ToUTF16(old_handler.url().host_piece()));
}
base::string16
@@ -85,7 +85,7 @@ RegisterProtocolHandlerPermissionRequest::GetMessageTextFragment() const {
l10n_util::GetStringFUTF16(
IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE_FRAGMENT,
GetProtocolName(handler_),
- base::UTF8ToUTF16(old_handler.url().host()));
+ base::UTF8ToUTF16(old_handler.url().host_piece()));
}
bool RegisterProtocolHandlerPermissionRequest::HasUserGesture() const {
diff --git a/chrome/browser/custom_home_pages_table_model.cc b/chrome/browser/custom_home_pages_table_model.cc
index db31447..c34bf4b 100644
--- a/chrome/browser/custom_home_pages_table_model.cc
+++ b/chrome/browser/custom_home_pages_table_model.cc
@@ -41,15 +41,15 @@ bool ShouldAddPage(const GURL& url) {
return false;
if (url.SchemeIs(content::kChromeUIScheme)) {
- if (url.host() == chrome::kChromeUISettingsHost ||
- url.host() == chrome::kChromeUISettingsFrameHost) {
+ if (url.host_piece() == chrome::kChromeUISettingsHost ||
+ url.host_piece() == chrome::kChromeUISettingsFrameHost) {
return false;
}
// For a settings page, the path will start with "/settings" not "settings"
// so find() will return 1, not 0.
- if (url.host() == chrome::kChromeUIUberHost &&
- url.path().find(chrome::kChromeUISettingsHost) == 1) {
+ if (url.host_piece() == chrome::kChromeUIUberHost &&
+ url.path_piece().find(chrome::kChromeUISettingsHost) == 1) {
return false;
}
}
diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc b/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc
index 5d0fe00..202759c 100644
--- a/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc
+++ b/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc
@@ -175,7 +175,7 @@ void PasswordsPrivateDelegateImpl::SetPasswordList(
if (!federation_url.is_empty()) {
entry->federation_text.reset(new std::string(l10n_util::GetStringFUTF8(
IDS_PASSWORDS_VIA_FEDERATION,
- base::UTF8ToUTF16(federation_url.host()))));
+ base::UTF8ToUTF16(federation_url.host_piece()))));
}
current_entries_.push_back(entry);
diff --git a/chrome/browser/extensions/extension_override_apitest.cc b/chrome/browser/extensions/extension_override_apitest.cc
index 6c47fc9..2f5386f 100644
--- a/chrome/browser/extensions/extension_override_apitest.cc
+++ b/chrome/browser/extensions/extension_override_apitest.cc
@@ -63,7 +63,7 @@ class ExtensionOverrideTest : public ExtensionApiTest {
GURL gurl = web_contents->GetController().GetLastCommittedEntry()->GetURL();
if (!gurl.SchemeIs(kExtensionScheme))
return testing::AssertionFailure() << gurl;
- if (gurl.host() != extension_id)
+ if (gurl.host_piece() != extension_id)
return testing::AssertionFailure() << gurl;
return testing::AssertionSuccess();
}
diff --git a/chrome/browser/extensions/extension_special_storage_policy.cc b/chrome/browser/extensions/extension_special_storage_policy.cc
index 5982232..a45cb9d 100644
--- a/chrome/browser/extensions/extension_special_storage_policy.cc
+++ b/chrome/browser/extensions/extension_special_storage_policy.cc
@@ -101,7 +101,7 @@ bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) {
return true;
if (origin.SchemeIs(content::kChromeDevToolsScheme) &&
- origin.host() == chrome::kChromeUIDevToolsHost)
+ origin.host_piece() == chrome::kChromeUIDevToolsHost)
return true;
base::AutoLock locker(lock_);
diff --git a/chrome/browser/extensions/ntp_overridden_bubble_delegate.cc b/chrome/browser/extensions/ntp_overridden_bubble_delegate.cc
index c2baee0..74e0a4b 100644
--- a/chrome/browser/extensions/ntp_overridden_bubble_delegate.cc
+++ b/chrome/browser/extensions/ntp_overridden_bubble_delegate.cc
@@ -43,7 +43,7 @@ bool NtpOverriddenBubbleDelegate::ShouldIncludeExtension(
if (!ExtensionWebUI::HandleChromeURLOverride(&url, profile()))
return false; // No override for newtab found.
- if (extension->id() != url.host())
+ if (extension->id() != url.host_piece())
return false;
if (HasBubbleInfoBeenAcknowledged(extension->id()))
diff --git a/chrome/browser/favicon/favicon_utils.cc b/chrome/browser/favicon/favicon_utils.cc
index 54b4d33..fc8cd05 100644
--- a/chrome/browser/favicon/favicon_utils.cc
+++ b/chrome/browser/favicon/favicon_utils.cc
@@ -40,7 +40,7 @@ bool ShouldDisplayFavicon(content::WebContents* web_contents) {
GURL url = web_contents->GetURL();
if (url.SchemeIs(content::kChromeUIScheme) &&
- url.host() == chrome::kChromeUINewTabHost) {
+ url.host_piece() == chrome::kChromeUINewTabHost) {
return false;
}
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index 61874cf..7323cae 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -398,13 +398,13 @@ void FirstRunBubbleLauncher::Observe(
if (contents && contents->GetURL().SchemeIs(content::kChromeUIScheme)) {
#if defined(OS_WIN)
// Suppress the first run bubble if 'make chrome metro' flow is showing.
- if (contents->GetURL().host() == chrome::kChromeUIMetroFlowHost)
+ if (contents->GetURL().host_piece() == chrome::kChromeUIMetroFlowHost)
return;
#endif
// Suppress the first run bubble if the NTP sync promo bubble is showing
// or if sign in is in progress.
- if (contents->GetURL().host() == chrome::kChromeUINewTabHost) {
+ if (contents->GetURL().host_piece() == chrome::kChromeUINewTabHost) {
Profile* profile =
Profile::FromBrowserContext(contents->GetBrowserContext());
SigninManagerBase* manager =
diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc
index f2d91b9..42766b2 100644
--- a/chrome/browser/net/predictor.cc
+++ b/chrome/browser/net/predictor.cc
@@ -354,7 +354,7 @@ UrlList Predictor::GetPredictedUrlListAtStartup(PrefService* user_prefs) {
if (SessionStartupPref::URLS == tab_start_pref.type) {
for (size_t i = 0; i < tab_start_pref.urls.size(); i++) {
GURL gurl = tab_start_pref.urls[i];
- if (!gurl.is_valid() || gurl.SchemeIsFile() || gurl.host().empty())
+ if (!gurl.is_valid() || gurl.SchemeIsFile() || gurl.host_piece().empty())
continue;
if (gurl.SchemeIsHTTPOrHTTPS())
urls.push_back(gurl.GetWithEmptyPath());
@@ -966,7 +966,7 @@ void Predictor::PrepareFrameSubresources(const GURL& original_url,
evalution = PRECONNECTION;
future_url->second.IncrementPreconnectionCount();
int count = static_cast<int>(std::ceil(connection_expectation));
- if (url.host() == future_url->first.host())
+ if (url.host_piece() == future_url->first.host_piece())
++count;
PreconnectUrlOnIOThread(future_url->first, first_party_for_cookies,
motivation,
diff --git a/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc
index 583c2b1..d0a5e98 100644
--- a/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc
+++ b/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc
@@ -17,9 +17,9 @@ bool IsFromGoogle(const GURL& url) {
std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
if (!base::StartsWith(domain, "google.", base::CompareCase::SENSITIVE) ||
- !base::StartsWith(url.host(), kGoogleSearchHostnamePrefix,
+ !base::StartsWith(url.host_piece(), kGoogleSearchHostnamePrefix,
base::CompareCase::SENSITIVE) ||
- url.host().length() !=
+ url.host_piece().length() !=
domain.length() + strlen(kGoogleSearchHostnamePrefix)) {
return false;
}
diff --git a/chrome/browser/page_load_metrics/observers/google_captcha_observer.cc b/chrome/browser/page_load_metrics/observers/google_captcha_observer.cc
index 9d47fd04..1cc5e45 100644
--- a/chrome/browser/page_load_metrics/observers/google_captcha_observer.cc
+++ b/chrome/browser/page_load_metrics/observers/google_captcha_observer.cc
@@ -34,11 +34,12 @@ void RecordGoogleCaptchaEvent(GoogleCaptchaEvent event) {
} // namespace
bool IsGoogleCaptcha(const GURL& url) {
- return (base::StartsWith(url.host(), "ipv4.google.",
+ return (base::StartsWith(url.host_piece(), "ipv4.google.",
base::CompareCase::SENSITIVE)
- || base::StartsWith(url.host(), "ipv6.google.",
+ || base::StartsWith(url.host_piece(), "ipv6.google.",
base::CompareCase::SENSITIVE))
- && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE);
+ && base::StartsWith(url.path_piece(), "/sorry",
+ base::CompareCase::SENSITIVE);
}
GoogleCaptchaObserver::GoogleCaptchaObserver() : saw_solution_(false) {}
diff --git a/chrome/browser/password_manager/chrome_password_manager_client.cc b/chrome/browser/password_manager/chrome_password_manager_client.cc
index 4559fda..1ddedc2 100644
--- a/chrome/browser/password_manager/chrome_password_manager_client.cc
+++ b/chrome/browser/password_manager/chrome_password_manager_client.cc
@@ -184,7 +184,8 @@ bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage()
// Do not fill nor save password when a user is signing in for sync. This
// is because users need to remember their password if they are syncing as
// this is effectively their master password.
- is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost;
+ is_enabled =
+ entry->GetURL().host_piece() != chrome::kChromeUIChromeSigninHost;
}
if (log_manager_->IsLoggingActive()) {
password_manager::BrowserSavePasswordProgressLogger logger(
diff --git a/chrome/browser/plugins/chrome_plugin_service_filter.cc b/chrome/browser/plugins/chrome_plugin_service_filter.cc
index fd1fa51..38d87ec 100644
--- a/chrome/browser/plugins/chrome_plugin_service_filter.cc
+++ b/chrome/browser/plugins/chrome_plugin_service_filter.cc
@@ -281,9 +281,9 @@ bool ChromePluginServiceFilter::IsPluginAvailable(
return false;
const GURL& origin = it->second.second;
if (!origin.is_empty() &&
- (policy_url.scheme() != origin.scheme() ||
- policy_url.host() != origin.host() ||
- policy_url.port() != origin.port())) {
+ (policy_url.scheme_piece() != origin.scheme_piece() ||
+ policy_url.host_piece() != origin.host_piece() ||
+ policy_url.port_piece() != origin.port_piece())) {
return false;
}
}
diff --git a/chrome/browser/policy/cloud/test_request_interceptor.cc b/chrome/browser/policy/cloud/test_request_interceptor.cc
index 3da4012c7..e1b4752 100644
--- a/chrome/browser/policy/cloud/test_request_interceptor.cc
+++ b/chrome/browser/policy/cloud/test_request_interceptor.cc
@@ -208,7 +208,7 @@ net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeInterceptRequest(
net::NetworkDelegate* network_delegate) const {
CHECK(io_task_runner_->RunsTasksOnCurrentThread());
- if (request->url().host() != hostname_) {
+ if (request->url().host_piece() != hostname_) {
// Reject requests to other servers.
return ErrorJobCallback(
net::ERR_CONNECTION_REFUSED, request, network_delegate);
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index cc9d619..5c6e0da 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -271,7 +271,7 @@ PrerenderHandle* PrerenderManager::AddPrerenderFromLinkRelPrerender(
if (!source_web_contents)
return NULL;
if (origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN &&
- source_web_contents->GetURL().host() == url.host()) {
+ source_web_contents->GetURL().host_piece() == url.host_piece()) {
origin = ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN;
}
// TODO(ajwong): This does not correctly handle storage for isolated apps.
diff --git a/chrome/browser/prerender/prerender_util.cc b/chrome/browser/prerender/prerender_util.cc
index e708cfdb..503834a 100644
--- a/chrome/browser/prerender/prerender_util.cc
+++ b/chrome/browser/prerender/prerender_util.cc
@@ -72,18 +72,19 @@ bool MaybeGetQueryStringBasedAliasURL(
}
bool IsGoogleDomain(const GURL& url) {
- return base::StartsWith(url.host(), "www.google.",
+ return base::StartsWith(url.host_piece(), "www.google.",
base::CompareCase::SENSITIVE);
}
bool IsGoogleSearchResultURL(const GURL& url) {
if (!IsGoogleDomain(url))
return false;
- return (url.path().empty() ||
- base::StartsWith(url.path(), "/search",
+ return (url.path_piece().empty() ||
+ base::StartsWith(url.path_piece(), "/search",
base::CompareCase::SENSITIVE) ||
(url.path() == "/") ||
- base::StartsWith(url.path(), "/webhp", base::CompareCase::SENSITIVE));
+ base::StartsWith(url.path_piece(), "/webhp",
+ base::CompareCase::SENSITIVE));
}
void ReportPrerenderExternalURL() {
diff --git a/chrome/browser/printing/print_preview_dialog_controller.cc b/chrome/browser/printing/print_preview_dialog_controller.cc
index 7179c34..936cd77 100644
--- a/chrome/browser/printing/print_preview_dialog_controller.cc
+++ b/chrome/browser/printing/print_preview_dialog_controller.cc
@@ -259,7 +259,7 @@ bool PrintPreviewDialogController::IsPrintPreviewDialog(WebContents* contents) {
// static
bool PrintPreviewDialogController::IsPrintPreviewURL(const GURL& url) {
return (url.SchemeIs(content::kChromeUIScheme) &&
- url.host() == chrome::kChromeUIPrintHost);
+ url.host_piece() == chrome::kChromeUIPrintHost);
}
void PrintPreviewDialogController::EraseInitiatorInfo(
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index 20d93b9..3bbb647 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -177,8 +177,8 @@ bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) {
bundled_path_prefix = "/" + bundled_path_prefix + "/";
if (!url.SchemeIs(content::kChromeDevToolsScheme) ||
- url.host() != chrome::kChromeUIDevToolsHost ||
- !base::StartsWith(url.path(), bundled_path_prefix,
+ url.host_piece() != chrome::kChromeUIDevToolsHost ||
+ !base::StartsWith(url.path_piece(), bundled_path_prefix,
base::CompareCase::INSENSITIVE_ASCII)) {
return false;
}
diff --git a/chrome/browser/ui/toolbar/toolbar_model_impl.cc b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
index ddfd315a..e27e2fa 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_impl.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
@@ -96,7 +96,7 @@ base::string16 ToolbarModelImpl::GetCorpusNameForMobile() const {
// If there is a query in the url fragment look for the corpus name there,
// otherwise look for the corpus name in the query parameters.
const std::string& query_str(google_util::HasGoogleSearchQueryParam(
- url.ref()) ? url.ref() : url.query());
+ url.ref_piece()) ? url.ref() : url.query());
url::Component query(0, query_str.length()), key, value;
const char kChipKey[] = "sboxchip";
while (url::ExtractQueryKeyValue(query_str.c_str(), &query, &key, &value)) {
diff --git a/components/google/core/browser/google_util.cc b/components/google/core/browser/google_util.cc
index 581363f..fc253a3 100644
--- a/components/google/core/browser/google_util.cc
+++ b/components/google/core/browser/google_util.cc
@@ -39,15 +39,15 @@ namespace {
bool gUseMockLinkDoctorBaseURLForTesting = false;
-bool IsPathHomePageBase(const std::string& path) {
+bool IsPathHomePageBase(base::StringPiece path) {
return (path == "/") || (path == "/webhp");
}
// True if |host| is "[www.]<domain_in_lower_case>.<TLD>" with a valid TLD. If
// |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host
// "*.<domain_in_lower_case>.<TLD>" instead.
-bool IsValidHostName(const std::string& host,
- const std::string& domain_in_lower_case,
+bool IsValidHostName(base::StringPiece host,
+ base::StringPiece domain_in_lower_case,
google_util::SubdomainPermission subdomain_permission) {
size_t tld_length = net::registry_controlled_domains::GetRegistryLength(
host,
@@ -55,15 +55,23 @@ bool IsValidHostName(const std::string& host,
net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
if ((tld_length == 0) || (tld_length == std::string::npos))
return false;
+
// Removes the tld and the preceding dot.
- std::string host_minus_tld(host, 0, host.length() - tld_length - 1);
- if (base::LowerCaseEqualsASCII(host_minus_tld, domain_in_lower_case.c_str()))
+ base::StringPiece host_minus_tld =
+ host.substr(0, host.length() - tld_length - 1);
+ if (base::LowerCaseEqualsASCII(host_minus_tld, domain_in_lower_case))
return true;
- if (subdomain_permission == google_util::ALLOW_SUBDOMAIN)
- return base::EndsWith(host_minus_tld, "." + domain_in_lower_case,
+
+ if (subdomain_permission == google_util::ALLOW_SUBDOMAIN) {
+ std::string dot_domain(".");
+ domain_in_lower_case.AppendToString(&dot_domain);
+ return base::EndsWith(host_minus_tld, dot_domain,
base::CompareCase::INSENSITIVE_ASCII);
- return base::LowerCaseEqualsASCII(host_minus_tld,
- ("www." + domain_in_lower_case).c_str());
+ }
+
+ std::string www_domain("www.");
+ domain_in_lower_case.AppendToString(&www_domain);
+ return base::LowerCaseEqualsASCII(host_minus_tld, www_domain);
}
// True if |url| is a valid URL with HTTP or HTTPS scheme. If |port_permission|
@@ -82,11 +90,11 @@ namespace google_util {
// Global functions -----------------------------------------------------------
-bool HasGoogleSearchQueryParam(const std::string& str) {
+bool HasGoogleSearchQueryParam(base::StringPiece str) {
url::Component query(0, static_cast<int>(str.length())), key, value;
- while (url::ExtractQueryKeyValue(str.c_str(), &query, &key, &value)) {
+ while (url::ExtractQueryKeyValue(str.data(), &query, &key, &value)) {
if (value.is_nonempty()) {
- base::StringPiece key_str(&str[key.begin], key.len);
+ base::StringPiece key_str = str.substr(key.begin, key.len);
if (key_str == "q" || key_str == "as_q")
return true;
}
@@ -115,13 +123,13 @@ GURL AppendGoogleLocaleParam(const GURL& url,
url, "hl", GetGoogleLocale(application_locale));
}
-std::string GetGoogleCountryCode(GURL google_homepage_url) {
- const std::string google_hostname = google_homepage_url.host();
+std::string GetGoogleCountryCode(const GURL& google_homepage_url) {
+ base::StringPiece google_hostname = google_homepage_url.host_piece();
const size_t last_dot = google_hostname.find_last_of('.');
if (last_dot == std::string::npos) {
NOTREACHED();
}
- std::string country_code = google_hostname.substr(last_dot + 1);
+ base::StringPiece country_code = google_hostname.substr(last_dot + 1);
// Assume the com TLD implies the US.
if (country_code == "com")
return "us";
@@ -133,10 +141,10 @@ std::string GetGoogleCountryCode(GURL google_homepage_url) {
// so use Spain instead.
if (country_code == "cat")
return "es";
- return country_code;
+ return country_code.as_string();
}
-GURL GetGoogleSearchURL(GURL google_homepage_url) {
+GURL GetGoogleSearchURL(const GURL& google_homepage_url) {
// To transform the homepage URL into the corresponding search URL, add the
// "search" and the "q=" query string.
GURL::Replacements replacements;
@@ -145,7 +153,7 @@ GURL GetGoogleSearchURL(GURL google_homepage_url) {
return google_homepage_url.ReplaceComponents(replacements);
}
-GURL CommandLineGoogleBaseURL() {
+const GURL& CommandLineGoogleBaseURL() {
// Unit tests may add command-line flags after the first call to this
// function, so we don't simply initialize a static |base_url| directly and
// then unconditionally return it.
@@ -164,16 +172,16 @@ GURL CommandLineGoogleBaseURL() {
}
bool StartsWithCommandLineGoogleBaseURL(const GURL& url) {
- GURL base_url(CommandLineGoogleBaseURL());
+ const GURL& base_url(CommandLineGoogleBaseURL());
return base_url.is_valid() &&
base::StartsWith(url.possibly_invalid_spec(), base_url.spec(),
base::CompareCase::SENSITIVE);
}
-bool IsGoogleHostname(const std::string& host,
+bool IsGoogleHostname(base::StringPiece host,
SubdomainPermission subdomain_permission) {
- GURL base_url(CommandLineGoogleBaseURL());
- if (base_url.is_valid() && (host == base_url.host()))
+ const GURL& base_url(CommandLineGoogleBaseURL());
+ if (base_url.is_valid() && (host == base_url.host_piece()))
return true;
return IsValidHostName(host, "google", subdomain_permission);
@@ -192,7 +200,7 @@ bool IsGoogleHomePageUrl(const GURL& url) {
return false;
// Make sure the path is a known home page path.
- std::string path(url.path());
+ base::StringPiece path(url.path_piece());
return IsPathHomePageBase(path) ||
base::StartsWith(path, "/ig", base::CompareCase::INSENSITIVE_ASCII);
}
@@ -203,22 +211,22 @@ bool IsGoogleSearchUrl(const GURL& url) {
return false;
// Make sure the path is a known search path.
- std::string path(url.path());
+ base::StringPiece path(url.path_piece());
bool is_home_page_base = IsPathHomePageBase(path);
if (!is_home_page_base && (path != "/search"))
return false;
// Check for query parameter in URL parameter and hash fragment, depending on
// the path type.
- return HasGoogleSearchQueryParam(url.ref()) ||
- (!is_home_page_base && HasGoogleSearchQueryParam(url.query()));
+ return HasGoogleSearchQueryParam(url.ref_piece()) ||
+ (!is_home_page_base && HasGoogleSearchQueryParam(url.query_piece()));
}
bool IsYoutubeDomainUrl(const GURL& url,
SubdomainPermission subdomain_permission,
PortPermission port_permission) {
return IsValidURL(url, port_permission) &&
- IsValidHostName(url.host(), "youtube", subdomain_permission);
+ IsValidHostName(url.host_piece(), "youtube", subdomain_permission);
}
} // namespace google_util
diff --git a/components/google/core/browser/google_util.h b/components/google/core/browser/google_util.h
index aebc5e7..53e58bc 100644
--- a/components/google/core/browser/google_util.h
+++ b/components/google/core/browser/google_util.h
@@ -9,6 +9,8 @@
#include <string>
+#include "base/strings/string_piece.h"
+
class GURL;
// This namespace provides various helpers around handling Google-related URLs.
@@ -17,7 +19,7 @@ namespace google_util {
// True iff |str| contains a "q=" or "as_q=" query parameter with a non-empty
// value. |str| should be a query or a hash fragment, without the ? or # (as
// returned by GURL::query() or GURL::ref().
-bool HasGoogleSearchQueryParam(const std::string& str);
+bool HasGoogleSearchQueryParam(base::StringPiece str);
// The query key that identifies a Google Extended API request for Instant.
const char kInstantExtendedAPIParam[] = "espv";
@@ -36,15 +38,15 @@ GURL AppendGoogleLocaleParam(const GURL& url,
const std::string& application_locale);
// Returns the Google country code string for the given Google homepage URL.
-std::string GetGoogleCountryCode(GURL google_homepage_url);
+std::string GetGoogleCountryCode(const GURL& google_homepage_url);
// Returns the Google search URL for the given Google homepage URL.
-GURL GetGoogleSearchURL(GURL google_homepage_url);
+GURL GetGoogleSearchURL(const GURL& google_homepage_url);
// Returns the Google base URL specified on the command line, if it exists.
// This performs some fixup and sanity-checking to ensure that the resulting URL
// is valid and has no query or ref.
-GURL CommandLineGoogleBaseURL();
+const GURL& CommandLineGoogleBaseURL();
// Returns true if a Google base URL was specified on the command line and |url|
// begins with that base URL. This uses a simple string equality check.
@@ -76,7 +78,7 @@ enum PortPermission {
// will also return true for any URL whose hostname exactly matches the hostname
// of the URL specified on the command line. In this case,
// |subdomain_permission| is ignored.
-bool IsGoogleHostname(const std::string& host,
+bool IsGoogleHostname(base::StringPiece host,
SubdomainPermission subdomain_permission);
// True if |url| is a valid URL with a host that returns true for
diff --git a/net/base/registry_controlled_domains/registry_controlled_domain.cc b/net/base/registry_controlled_domains/registry_controlled_domain.cc
index e2a70c3..0d98ead 100644
--- a/net/base/registry_controlled_domains/registry_controlled_domain.cc
+++ b/net/base/registry_controlled_domains/registry_controlled_domain.cc
@@ -65,10 +65,9 @@ namespace {
const unsigned char* g_graph = kDafsa;
size_t g_graph_length = sizeof(kDafsa);
-size_t GetRegistryLengthImpl(
- const std::string& host,
- UnknownRegistryFilter unknown_filter,
- PrivateRegistryFilter private_filter) {
+size_t GetRegistryLengthImpl(base::StringPiece host,
+ UnknownRegistryFilter unknown_filter,
+ PrivateRegistryFilter private_filter) {
DCHECK(!host.empty());
// Skip leading dots.
@@ -148,8 +147,8 @@ size_t GetRegistryLengthImpl(
(host.length() - curr_start) : 0;
}
-std::string GetDomainAndRegistryImpl(
- const std::string& host, PrivateRegistryFilter private_filter) {
+std::string GetDomainAndRegistryImpl(base::StringPiece host,
+ PrivateRegistryFilter private_filter) {
DCHECK(!host.empty());
// Find the length of the registry for this host.
@@ -171,8 +170,8 @@ std::string GetDomainAndRegistryImpl(
// no dot.
const size_t dot = host.rfind('.', host.length() - registry_length - 2);
if (dot == std::string::npos)
- return host;
- return host.substr(dot + 1);
+ return host.as_string();
+ return host.substr(dot + 1).as_string();
}
} // namespace
@@ -180,16 +179,14 @@ std::string GetDomainAndRegistryImpl(
std::string GetDomainAndRegistry(
const GURL& gurl,
PrivateRegistryFilter filter) {
- const url::Component host = gurl.parsed_for_possibly_invalid_spec().host;
- if ((host.len <= 0) || gurl.HostIsIPAddress())
+ base::StringPiece host = gurl.host_piece();
+ if (host.empty() || gurl.HostIsIPAddress())
return std::string();
- return GetDomainAndRegistryImpl(std::string(
- gurl.possibly_invalid_spec().data() + host.begin, host.len), filter);
+ return GetDomainAndRegistryImpl(host, filter);
}
-std::string GetDomainAndRegistry(
- const std::string& host,
- PrivateRegistryFilter filter) {
+std::string GetDomainAndRegistry(base::StringPiece host,
+ PrivateRegistryFilter filter) {
url::CanonHostInfo host_info;
const std::string canon_host(CanonicalizeHost(host, &host_info));
if (canon_host.empty() || host_info.IsIPAddress())
@@ -222,21 +219,17 @@ size_t GetRegistryLength(
const GURL& gurl,
UnknownRegistryFilter unknown_filter,
PrivateRegistryFilter private_filter) {
- const url::Component host = gurl.parsed_for_possibly_invalid_spec().host;
- if (host.len <= 0)
+ base::StringPiece host = gurl.host_piece();
+ if (host.empty())
return std::string::npos;
if (gurl.HostIsIPAddress())
return 0;
- return GetRegistryLengthImpl(
- std::string(gurl.possibly_invalid_spec().data() + host.begin, host.len),
- unknown_filter,
- private_filter);
+ return GetRegistryLengthImpl(host, unknown_filter, private_filter);
}
-size_t GetRegistryLength(
- const std::string& host,
- UnknownRegistryFilter unknown_filter,
- PrivateRegistryFilter private_filter) {
+size_t GetRegistryLength(base::StringPiece host,
+ UnknownRegistryFilter unknown_filter,
+ PrivateRegistryFilter private_filter) {
url::CanonHostInfo host_info;
const std::string canon_host(CanonicalizeHost(host, &host_info));
if (canon_host.empty())
diff --git a/net/base/registry_controlled_domains/registry_controlled_domain.h b/net/base/registry_controlled_domains/registry_controlled_domain.h
index 67f5e38..fa72f4c 100644
--- a/net/base/registry_controlled_domains/registry_controlled_domain.h
+++ b/net/base/registry_controlled_domains/registry_controlled_domain.h
@@ -117,6 +117,7 @@
#include <string>
+#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
class GURL;
@@ -179,7 +180,7 @@ NET_EXPORT std::string GetDomainAndRegistry(const GURL& gurl,
// Like the GURL version, but takes a host (which is canonicalized internally)
// instead of a full GURL.
-NET_EXPORT std::string GetDomainAndRegistry(const std::string& host,
+NET_EXPORT std::string GetDomainAndRegistry(base::StringPiece host,
PrivateRegistryFilter filter);
// This convenience function returns true if the two GURLs both have hosts
@@ -221,7 +222,7 @@ NET_EXPORT size_t GetRegistryLength(const GURL& gurl,
// Like the GURL version, but takes a host (which is canonicalized internally)
// instead of a full GURL.
-NET_EXPORT size_t GetRegistryLength(const std::string& host,
+NET_EXPORT size_t GetRegistryLength(base::StringPiece host,
UnknownRegistryFilter unknown_filter,
PrivateRegistryFilter private_filter);
diff --git a/net/base/url_util.cc b/net/base/url_util.cc
index 913fe91..2528316 100644
--- a/net/base/url_util.cc
+++ b/net/base/url_util.cc
@@ -231,7 +231,7 @@ std::string GetHostAndOptionalPort(const GURL& url) {
return url.host();
}
-std::string TrimEndingDot(const base::StringPiece& host) {
+std::string TrimEndingDot(base::StringPiece host) {
base::StringPiece host_trimmed = host;
size_t len = host_trimmed.length();
if (len > 1 && host_trimmed[len - 1] == '.') {
@@ -244,13 +244,13 @@ std::string GetHostOrSpecFromURL(const GURL& url) {
return url.has_host() ? TrimEndingDot(url.host_piece()) : url.spec();
}
-std::string CanonicalizeHost(const std::string& host,
+std::string CanonicalizeHost(base::StringPiece host,
url::CanonHostInfo* host_info) {
// Try to canonicalize the host.
const url::Component raw_host_component(0, static_cast<int>(host.length()));
std::string canon_host;
url::StdStringCanonOutput canon_host_output(&canon_host);
- url::CanonicalizeHostVerbose(host.c_str(), raw_host_component,
+ url::CanonicalizeHostVerbose(host.data(), raw_host_component,
&canon_host_output, host_info);
if (host_info->out_host.is_nonempty() &&
diff --git a/net/base/url_util.h b/net/base/url_util.h
index d4a7eef..a86a9e0 100644
--- a/net/base/url_util.h
+++ b/net/base/url_util.h
@@ -110,14 +110,14 @@ NET_EXPORT std::string GetHostAndPort(const GURL& url);
NET_EXPORT std::string GetHostAndOptionalPort(const GURL& url);
// Returns the hostname by trimming the ending dot, if one exists.
-NET_EXPORT std::string TrimEndingDot(const base::StringPiece& host);
+NET_EXPORT std::string TrimEndingDot(base::StringPiece host);
// Returns either the host from |url|, or, if the host is empty, the full spec.
NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url);
// Canonicalizes |host| and returns it. Also fills |host_info| with
// IP address information. |host_info| must not be NULL.
-NET_EXPORT std::string CanonicalizeHost(const std::string& host,
+NET_EXPORT std::string CanonicalizeHost(base::StringPiece host,
url::CanonHostInfo* host_info);
// Returns true if |host| is not an IP address and is compliant with a set of