diff options
author | brettw <brettw@chromium.org> | 2015-07-16 10:49:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-16 17:50:12 +0000 |
commit | a7ff1b291cd328e9584779a4bb9101fa9a3c01ad (patch) | |
tree | d010374be1ca156ea26405ae7b0aa85e48bb4bba /extensions | |
parent | 7befa9cf85342a0409502ed2c05d7610afec7844 (diff) | |
download | chromium_src-a7ff1b291cd328e9584779a4bb9101fa9a3c01ad.zip chromium_src-a7ff1b291cd328e9584779a4bb9101fa9a3c01ad.tar.gz chromium_src-a7ff1b291cd328e9584779a4bb9101fa9a3c01ad.tar.bz2 |
Remove some legacy versions of StartsWith and EndsWith.
This just replaces
true -> base::CompareCase::SENSITIVE
false -> base::CompareCase::INSENSITIVE_ASCII
I checked the insensitive cases to make sure they're not doing anything suspicious. The old version is a sometimes-correct Unicode comparison so converting to INSENSTITIVE_ASCII isn't a no-op. However, generally the prefix/suffix checking is done against a hardcoded string so there were very few cases to actually look at.
extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc has a not-quite search-and-replace change where I changed the type of a class variable.
BUG=506255
TBR=jam
Reland of http://crrev.com/1239493005
Review URL: https://codereview.chromium.org/1233043003
Cr-Commit-Position: refs/heads/master@{#339071}
Diffstat (limited to 'extensions')
4 files changed, 18 insertions, 12 deletions
diff --git a/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc index 615090a..430a05c 100644 --- a/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc +++ b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc @@ -330,7 +330,7 @@ class HeaderMatcher { const std::string data_; const MatchType type_; - const bool case_sensitive_; + const base::CompareCase case_sensitive_; DISALLOW_COPY_AND_ASSIGN(StringMatchTest); }; @@ -422,14 +422,14 @@ bool HeaderMatcher::StringMatchTest::Matches( const std::string& str) const { switch (type_) { case kPrefix: - return base::StartsWithASCII(str, data_, case_sensitive_); + return base::StartsWith(str, data_, case_sensitive_); case kSuffix: return base::EndsWith(str, data_, case_sensitive_); case kEquals: return str.size() == data_.size() && - base::StartsWithASCII(str, data_, case_sensitive_); + base::StartsWith(str, data_, case_sensitive_); case kContains: - if (!case_sensitive_) { + if (case_sensitive_ == base::CompareCase::INSENSITIVE_ASCII) { return std::search(str.begin(), str.end(), data_.begin(), data_.end(), CaseInsensitiveCompareASCII<char>()) != str.end(); } else { @@ -446,7 +446,8 @@ HeaderMatcher::StringMatchTest::StringMatchTest(const std::string& data, bool case_sensitive) : data_(data), type_(type), - case_sensitive_(case_sensitive) {} + case_sensitive_(case_sensitive ? base::CompareCase::SENSITIVE + : base::CompareCase::INSENSITIVE_ASCII) {} // HeaderMatcher::HeaderMatchTest implementation. diff --git a/extensions/browser/api/web_request/web_request_permissions.cc b/extensions/browser/api/web_request/web_request_permissions.cc index 2f57d63..fd73304 100644 --- a/extensions/browser/api/web_request/web_request_permissions.cc +++ b/extensions/browser/api/web_request/web_request_permissions.cc @@ -30,12 +30,12 @@ bool IsSensitiveURL(const GURL& url) { const std::string host = url.host(); const char kGoogleCom[] = ".google.com"; const char kClient[] = "clients"; - if (base::EndsWith(host, kGoogleCom, true)) { + if (base::EndsWith(host, kGoogleCom, base::CompareCase::SENSITIVE)) { // Check for "clients[0-9]*.google.com" hosts. // This protects requests to several internal services such as sync, // extension update pings, captive portal detection, fraudulent certificate // reporting, autofill and others. - if (base::StartsWithASCII(host, kClient, true)) { + if (base::StartsWith(host, kClient, base::CompareCase::SENSITIVE)) { bool match = true; for (std::string::const_iterator i = host.begin() + strlen(kClient), end = host.end() - strlen(kGoogleCom); i != end; ++i) { @@ -50,10 +50,12 @@ bool IsSensitiveURL(const GURL& url) { // others. sensitive_chrome_url = sensitive_chrome_url || - base::EndsWith(url.host(), ".clients.google.com", true) || + base::EndsWith(url.host(), ".clients.google.com", + base::CompareCase::SENSITIVE) || url.host() == "sb-ssl.google.com" || (url.host() == "chrome.google.com" && - base::StartsWithASCII(url.path(), "/webstore", true)); + base::StartsWith(url.path(), "/webstore", + base::CompareCase::SENSITIVE)); } GURL::Replacements replacements; replacements.ClearQuery(); diff --git a/extensions/common/user_script.cc b/extensions/common/user_script.cc index b3d82bb..6b64741 100644 --- a/extensions/common/user_script.cc +++ b/extensions/common/user_script.cc @@ -52,7 +52,8 @@ int UserScript::GenerateUserScriptID() { bool UserScript::IsURLUserScript(const GURL& url, const std::string& mime_type) { - return base::EndsWith(url.ExtractFileName(), kFileExtension, false) && + return base::EndsWith(url.ExtractFileName(), kFileExtension, + base::CompareCase::INSENSITIVE_ASCII) && mime_type != "text/html"; } diff --git a/extensions/utility/unpacker_unittest.cc b/extensions/utility/unpacker_unittest.cc index bb99aae..82e5a1f7 100644 --- a/extensions/utility/unpacker_unittest.cc +++ b/extensions/utility/unpacker_unittest.cc @@ -171,7 +171,8 @@ TEST_F(UnpackerTest, BadPathError) { EXPECT_FALSE(unpacker_->Run()); EXPECT_TRUE(base::StartsWith(unpacker_->error_message(), - ASCIIToUTF16(kExpected), false)) + ASCIIToUTF16(kExpected), + base::CompareCase::INSENSITIVE_ASCII)) << "Expected prefix: \"" << kExpected << "\", actual error: \"" << unpacker_->error_message() << "\""; } @@ -181,7 +182,8 @@ TEST_F(UnpackerTest, ImageDecodingError) { SetupUnpacker("bad_image.crx"); EXPECT_FALSE(unpacker_->Run()); EXPECT_TRUE(base::StartsWith(unpacker_->error_message(), - ASCIIToUTF16(kExpected), false)) + ASCIIToUTF16(kExpected), + base::CompareCase::INSENSITIVE_ASCII)) << "Expected prefix: \"" << kExpected << "\", actual error: \"" << unpacker_->error_message() << "\""; } |