diff options
author | jstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 20:25:22 +0000 |
---|---|---|
committer | jstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 20:25:22 +0000 |
commit | b791effd60d54492f0e7cacf4c10d286fcd76ffe (patch) | |
tree | d14aa43185a3f2c04951e1fd68c49bdf60e5ecd0 /chrome/common/extensions | |
parent | f760afdeb4ce5e734c605719be2e66de048c5555 (diff) | |
download | chromium_src-b791effd60d54492f0e7cacf4c10d286fcd76ffe.zip chromium_src-b791effd60d54492f0e7cacf4c10d286fcd76ffe.tar.gz chromium_src-b791effd60d54492f0e7cacf4c10d286fcd76ffe.tar.bz2 |
Revert 92219 - Update URLPatternSet to contain a std::set instead of std::vector.
This updates URLPatternSet to contain a std::set instead of a std::vector, making it easier to implement the set operations in ExtensionPermissionSet.
BUG=84507
TEST=unit_tests
Review URL: http://codereview.chromium.org/7347011
TBR=jstritar@chromium.org
Review URL: http://codereview.chromium.org/7346019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
18 files changed, 214 insertions, 316 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 9a2aae2f..f61f789 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -458,7 +458,7 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, URLPattern pattern(UserScript::kValidUserScriptSchemes); if (CanExecuteScriptEverywhere()) - pattern.SetValidSchemes(URLPattern::SCHEME_ALL); + pattern.set_valid_schemes(URLPattern::SCHEME_ALL); URLPattern::ParseResult parse_result = pattern.Parse(match_str, parse_strictness); @@ -475,7 +475,7 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, !CanExecuteScriptEverywhere()) { wants_file_access_ = true; if (!(flags & ALLOW_FILE_ACCESS)) - pattern.SetValidSchemes( + pattern.set_valid_schemes( pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); } @@ -505,7 +505,7 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, URLPattern pattern(UserScript::kValidUserScriptSchemes); if (CanExecuteScriptEverywhere()) - pattern.SetValidSchemes(URLPattern::SCHEME_ALL); + pattern.set_valid_schemes(URLPattern::SCHEME_ALL); URLPattern::ParseResult parse_result = pattern.Parse(match_str, parse_strictness); if (parse_result != URLPattern::PARSE_SUCCESS) { @@ -1026,7 +1026,7 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest, *error = errors::kInvalidLaunchWebURL; return false; } - pattern.SetHost(launch_url.host()); + pattern.set_host(launch_url.host()); pattern.SetPath("/*"); extent_.AddPattern(pattern); } @@ -1956,7 +1956,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags, !CanExecuteScriptEverywhere()) { wants_file_access_ = true; if (!(flags & ALLOW_FILE_ACCESS)) - pattern.SetValidSchemes( + pattern.set_valid_schemes( pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); } @@ -2705,7 +2705,7 @@ bool Extension::OverlapsWithOrigin(const GURL& origin) const { URLPattern origin_only_pattern(kValidWebExtentSchemes); if (!origin_only_pattern.SetScheme(origin.scheme())) return false; - origin_only_pattern.SetHost(origin.host()); + origin_only_pattern.set_host(origin.host()); origin_only_pattern.SetPath("/*"); URLPatternSet origin_only_pattern_list; diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index bde6707..c1543da 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -544,6 +544,22 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // sure the drive letter is uppercase. static FilePath MaybeNormalizePath(const FilePath& path); + // Returns the distinct hosts that can be displayed in the install UI or be + // used for privilege comparisons. This discards some of the detail that is + // present in the manifest to make it as easy as possible to process by users. + // In particular we disregard the scheme and path components of URLPatterns + // and de-dupe the result, which includes filtering out common hosts with + // differing RCDs. If |include_rcd| is true, then the de-duped result + // will be the first full entry, including its RCD. So if the list was + // "*.google.co.uk" and "*.google.com", the returned value would just be + // "*.google.co.uk". Keeping the RCD in the result is useful for display + // purposes when you want to show the user one sample hostname from the list. + // If you need to compare two URLPatternLists for security equality, then set + // |include_rcd| to false, which will return a result like "*.google.", + // regardless of the order of the patterns. + static std::vector<std::string> GetDistinctHosts( + const URLPatternList& host_patterns, bool include_rcd); + // Returns true if this extension id is from a trusted provider. static bool IsTrustedId(const std::string& id); diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc index 3209ba5..1184d52 100644 --- a/chrome/common/extensions/extension_manifests_unittest.cc +++ b/chrome/common/extensions/extension_manifests_unittest.cc @@ -30,16 +30,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" - -namespace { - -static void AddPattern(URLPatternSet* extent, const std::string& pattern) { - int schemes = URLPattern::SCHEME_ALL; - extent->AddPattern(URLPattern(schemes, pattern)); -} - -} - namespace errors = extension_manifest_errors; namespace keys = extension_manifest_keys; @@ -312,10 +302,11 @@ TEST_F(ExtensionManifestTest, OldUnlimitedStoragePermission) { TEST_F(ExtensionManifestTest, ValidApp) { scoped_refptr<Extension> extension(LoadAndExpectSuccess("valid_app.json")); - URLPatternSet expected_patterns; - AddPattern(&expected_patterns, "http://www.google.com/mail/*"); - AddPattern(&expected_patterns, "http://www.google.com/foobar/*"); - EXPECT_EQ(expected_patterns, extension->web_extent()); + ASSERT_EQ(2u, extension->web_extent().patterns().size()); + EXPECT_EQ("http://www.google.com/mail/*", + extension->web_extent().patterns()[0].GetAsString()); + EXPECT_EQ("http://www.google.com/foobar/*", + extension->web_extent().patterns()[1].GetAsString()); EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); EXPECT_EQ("http://www.google.com/mail/", extension->launch_web_url()); } @@ -374,7 +365,7 @@ TEST_F(ExtensionManifestTest, AppWebUrls) { LoadAndExpectSuccess("web_urls_default.json")); ASSERT_EQ(1u, extension->web_extent().patterns().size()); EXPECT_EQ("*://www.google.com/*", - extension->web_extent().patterns().begin()->GetAsString()); + extension->web_extent().patterns()[0].GetAsString()); } TEST_F(ExtensionManifestTest, AppLaunchContainer) { @@ -701,7 +692,7 @@ TEST_F(ExtensionManifestTest, DefaultPathForExtent) { LoadAndExpectSuccess("default_path_for_extent.json")); ASSERT_EQ(1u, extension->web_extent().patterns().size()); - EXPECT_EQ("/*", extension->web_extent().patterns().begin()->path()); + EXPECT_EQ("/*", extension->web_extent().patterns()[0].path()); EXPECT_TRUE(extension->web_extent().MatchesURL( GURL("http://www.google.com/monkey"))); } @@ -799,8 +790,8 @@ TEST_F(ExtensionManifestTest, FileBrowserHandlers) { extension->file_browser_handlers()->at(0).get(); EXPECT_EQ(action->title(), "Default title"); EXPECT_EQ(action->icon_path(), "icon.png"); - const URLPatternSet& patterns = action->file_url_patterns(); - ASSERT_EQ(patterns.patterns().size(), 1U); + const URLPatternList& patterns = action->file_url_patterns(); + ASSERT_EQ(patterns.size(), 1U); ASSERT_TRUE(action->MatchesURL( GURL("filesystem:chrome-extension://foo/local/test.txt"))); } diff --git a/chrome/common/extensions/extension_messages.cc b/chrome/common/extensions/extension_messages.cc index d7f4e52..268d06f 100644 --- a/chrome/common/extensions/extension_messages.cc +++ b/chrome/common/extensions/extension_messages.cc @@ -99,7 +99,7 @@ bool ParamTraits<URLPattern>::Read(const Message* m, void** iter, !ReadParam(m, iter, &spec)) return false; - p->SetValidSchemes(valid_schemes); + p->set_valid_schemes(valid_schemes); return URLPattern::PARSE_SUCCESS == p->Parse(spec, URLPattern::IGNORE_PORTS); } @@ -113,15 +113,14 @@ void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { bool ParamTraits<URLPatternSet>::Read(const Message* m, void** iter, param_type* p) { - URLPatternSet patterns; + URLPatternList patterns; bool success = ReadParam(m, iter, &patterns); if (!success) return false; - for (URLPatternSet::const_iterator i = patterns.begin(); - i != patterns.end(); ++i) - p->AddPattern(*i); + for (size_t i = 0; i < patterns.size(); ++i) + p->AddPattern(patterns[i]); return true; } diff --git a/chrome/common/extensions/extension_permission_set.cc b/chrome/common/extensions/extension_permission_set.cc index dbe321e..d87e9e3 100644 --- a/chrome/common/extensions/extension_permission_set.cc +++ b/chrome/common/extensions/extension_permission_set.cc @@ -81,8 +81,9 @@ const char kWindowsPermission[] = "windows"; void AddPatternsAndRemovePaths(const URLPatternSet& set, URLPatternSet* out) { CHECK(out); - for (URLPatternSet::const_iterator i = set.begin(); i != set.end(); ++i) { - URLPattern p = *i; + const URLPatternList& patterns = set.patterns(); + for (size_t i = 0; i < patterns.size(); ++i) { + URLPattern p = patterns.at(i); p.SetPath("/*"); out->AddPattern(p); } @@ -96,37 +97,35 @@ void AddPatternsAndRemovePaths(const URLPatternSet& set, URLPatternSet* out) { // static ExtensionPermissionMessage ExtensionPermissionMessage::CreateFromHostList( - const std::set<std::string>& hosts) { - std::vector<std::string> host_list(hosts.begin(), hosts.end()); - CHECK(host_list.size() > 0); + const std::vector<std::string>& hosts) { + CHECK(hosts.size() > 0); ID message_id; string16 message; - - switch (host_list.size()) { + switch (hosts.size()) { case 1: message_id = kHosts1; message = l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST, - UTF8ToUTF16(host_list[0])); + UTF8ToUTF16(hosts[0])); break; case 2: message_id = kHosts2; message = l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS, - UTF8ToUTF16(host_list[0]), - UTF8ToUTF16(host_list[1])); + UTF8ToUTF16(hosts[0]), + UTF8ToUTF16(hosts[1])); break; case 3: message_id = kHosts3; message = l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS, - UTF8ToUTF16(host_list[0]), - UTF8ToUTF16(host_list[1]), - UTF8ToUTF16(host_list[2])); + UTF8ToUTF16(hosts[0]), + UTF8ToUTF16(hosts[1]), + UTF8ToUTF16(hosts[2])); break; default: message_id = kHosts4OrMore; message = l10n_util::GetStringFUTF16( IDS_EXTENSION_PROMPT_WARNING_4_OR_MORE_HOSTS, - UTF8ToUTF16(host_list[0]), - UTF8ToUTF16(host_list[1]), + UTF8ToUTF16(hosts[0]), + UTF8ToUTF16(hosts[1]), base::IntToString16(hosts.size() - 2)); break; } @@ -455,9 +454,9 @@ std::set<std::string> ExtensionPermissionSet::GetAPIsAsStrings() const { return apis_str; } -std::set<std::string> +std::vector<std::string> ExtensionPermissionSet::GetDistinctHostsForDisplay() const { - return GetDistinctHosts(effective_hosts_, true); + return GetDistinctHosts(effective_hosts_.patterns(), true); } ExtensionPermissionMessages @@ -476,7 +475,7 @@ ExtensionPermissionMessages ExtensionPermissionMessage::kHostsAll, l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS))); } else { - std::set<std::string> hosts = GetDistinctHostsForDisplay(); + std::vector<std::string> hosts = GetDistinctHostsForDisplay(); if (!hosts.empty()) messages.push_back(ExtensionPermissionMessage::CreateFromHostList(hosts)); } @@ -562,8 +561,9 @@ bool ExtensionPermissionSet::HasEffectiveAccessToAllHosts() const { // There are two ways this set can have effective access to all hosts: // 1) it has an <all_urls> URL pattern. // 2) it has a named permission with implied full URL access. - for (URLPatternSet::const_iterator host = effective_hosts().begin(); - host != effective_hosts().end(); ++host) { + const URLPatternList patterns = effective_hosts().patterns(); + for (URLPatternList::const_iterator host = patterns.begin(); + host != patterns.end(); ++host) { if (host->match_all_urls() || (host->match_subdomains() && host->host().empty())) return true; @@ -626,19 +626,18 @@ bool ExtensionPermissionSet::HasLessPrivilegesThan( } // static -std::set<std::string> ExtensionPermissionSet::GetDistinctHosts( - const URLPatternSet& host_patterns, bool include_rcd) { +std::vector<std::string> ExtensionPermissionSet::GetDistinctHosts( + const URLPatternList& host_patterns, bool include_rcd) { // Use a vector to preserve order (also faster than a map on small sets). // Each item is a host split into two parts: host without RCDs and // current best RCD. typedef std::vector<std::pair<std::string, std::string> > HostVector; HostVector hosts_best_rcd; - for (URLPatternSet::const_iterator i = host_patterns.begin(); - i != host_patterns.end(); ++i) { - std::string host = i->host(); + for (size_t i = 0; i < host_patterns.size(); ++i) { + std::string host = host_patterns[i].host(); // Add the subdomain wildcard back to the host, if necessary. - if (i->match_subdomains()) + if (host_patterns[i].match_subdomains()) host = "*." + host; // If the host has an RCD, split it off so we can detect duplicates. @@ -667,10 +666,10 @@ std::set<std::string> ExtensionPermissionSet::GetDistinctHosts( } // Build up the final vector by concatenating hosts and RCDs. - std::set<std::string> distinct_hosts; + std::vector<std::string> distinct_hosts; for (HostVector::iterator it = hosts_best_rcd.begin(); it != hosts_best_rcd.end(); ++it) - distinct_hosts.insert(it->first + it->second); + distinct_hosts.push_back(it->first + it->second); return distinct_hosts; } @@ -679,7 +678,7 @@ void ExtensionPermissionSet::InitEffectiveHosts() { if (HasEffectiveAccessToAllHosts()) { URLPattern all_urls(URLPattern::SCHEME_ALL); - all_urls.SetMatchAllURLs(true); + all_urls.set_match_all_urls(true); effective_hosts_.AddPattern(all_urls); return; } @@ -701,7 +700,7 @@ void ExtensionPermissionSet::InitImplicitExtensionPermissions( for (UserScriptList::const_iterator content_script = extension->content_scripts().begin(); content_script != extension->content_scripts().end(); ++content_script) { - URLPatternSet::const_iterator pattern = + URLPatternList::const_iterator pattern = content_script->url_patterns().begin(); for (; pattern != content_script->url_patterns().end(); ++pattern) scriptable_hosts_.AddPattern(*pattern); @@ -758,14 +757,17 @@ bool ExtensionPermissionSet::HasLessHostPrivilegesThan( if (permissions->HasEffectiveAccessToAllHosts()) return true; - const URLPatternSet& old_list = effective_hosts(); - const URLPatternSet& new_list = permissions->effective_hosts(); + const URLPatternList old_list = effective_hosts().patterns(); + const URLPatternList new_list = permissions->effective_hosts().patterns(); // TODO(jstritar): This is overly conservative with respect to subdomains. // For example, going from *.google.com to www.google.com will be // considered an elevation, even though it is not (http://crbug.com/65337). - std::set<std::string> new_hosts_set = GetDistinctHosts(new_list, false); - std::set<std::string> old_hosts_set = GetDistinctHosts(old_list, false); + std::vector<std::string> new_hosts = GetDistinctHosts(new_list, false); + std::vector<std::string> old_hosts = GetDistinctHosts(old_list, false); + + std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end()); + std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end()); std::set<std::string> new_hosts_only; std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), diff --git a/chrome/common/extensions/extension_permission_set.h b/chrome/common/extensions/extension_permission_set.h index 0e46168..5cd331a 100644 --- a/chrome/common/extensions/extension_permission_set.h +++ b/chrome/common/extensions/extension_permission_set.h @@ -51,7 +51,7 @@ class ExtensionPermissionMessage { // simply a convenience method around the constructor, since the messages // change depending on what hosts are present. static ExtensionPermissionMessage CreateFromHostList( - const std::set<std::string>& hosts); + const std::vector<std::string>& hosts); // Creates the corresponding permission message. ExtensionPermissionMessage(ID id, const string16& message); @@ -292,7 +292,7 @@ class ExtensionPermissionSet { // Gets a list of the distinct hosts for displaying to the user. // NOTE: do not use this for comparing permissions, since this disgards some // information. - std::set<std::string> GetDistinctHostsForDisplay() const; + std::vector<std::string> GetDistinctHostsForDisplay() const; // Gets the localized permission messages that represent this set. ExtensionPermissionMessages GetPermissionMessages() const; @@ -348,8 +348,8 @@ class ExtensionPermissionSet { FRIEND_TEST_ALL_PREFIXES(ExtensionPermissionSetTest, HasLessHostPrivilegesThan); - static std::set<std::string> GetDistinctHosts( - const URLPatternSet& host_patterns, bool include_rcd); + static std::vector<std::string> GetDistinctHosts( + const URLPatternList& host_patterns, bool include_rcd); // Initializes the set based on |extension|'s manifest data. void InitImplicitExtensionPermissions(const Extension* extension); diff --git a/chrome/common/extensions/extension_permission_set_unittest.cc b/chrome/common/extensions/extension_permission_set_unittest.cc index 6140bec..9cfa698 100644 --- a/chrome/common/extensions/extension_permission_set_unittest.cc +++ b/chrome/common/extensions/extension_permission_set_unittest.cc @@ -58,6 +58,23 @@ static void AddPattern(URLPatternSet* extent, const std::string& pattern) { extent->AddPattern(URLPattern(schemes, pattern)); } +static void AssertEqualExtents(const URLPatternSet& extent1, + const URLPatternSet& extent2) { + URLPatternList patterns1 = extent1.patterns(); + URLPatternList patterns2 = extent2.patterns(); + std::set<std::string> strings1; + EXPECT_EQ(patterns1.size(), patterns2.size()); + + for (size_t i = 0; i < patterns1.size(); ++i) + strings1.insert(patterns1.at(i).GetAsString()); + + std::set<std::string> strings2; + for (size_t i = 0; i < patterns2.size(); ++i) + strings2.insert(patterns2.at(i).GetAsString()); + + EXPECT_EQ(strings1, strings2); +} + } // namespace class ExtensionAPIPermissionTest : public testing::Test { @@ -319,9 +336,9 @@ TEST(ExtensionPermissionSetTest, CreateUnion) { EXPECT_FALSE(union_set->HasEffectiveFullAccess()); EXPECT_EQ(expected_apis, union_set->apis()); - EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); - EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); - EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); + AssertEqualExtents(expected_explicit_hosts, union_set->explicit_hosts()); + AssertEqualExtents(expected_scriptable_hosts, union_set->scriptable_hosts()); + AssertEqualExtents(expected_explicit_hosts, union_set->effective_hosts()); // Now use a real second set. apis2.insert(ExtensionAPIPermission::kTab); @@ -347,9 +364,9 @@ TEST(ExtensionPermissionSetTest, CreateUnion) { EXPECT_TRUE(union_set->HasEffectiveFullAccess()); EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); EXPECT_EQ(expected_apis, union_set->apis()); - EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); - EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); - EXPECT_EQ(effective_hosts, union_set->effective_hosts()); + AssertEqualExtents(expected_explicit_hosts, union_set->explicit_hosts()); + AssertEqualExtents(expected_scriptable_hosts, union_set->scriptable_hosts()); + AssertEqualExtents(effective_hosts, union_set->effective_hosts()); } TEST(ExtensionPermissionSetTest, HasLessPrivilegesThan) { @@ -547,7 +564,7 @@ TEST(ExtensionPermissionSetTest, GetWarningMessages_ManyHosts) { std::vector<string16> warnings = extension->permission_set()->GetWarningMessages(); ASSERT_EQ(1u, warnings.size()); - EXPECT_EQ("Your data on encrypted.google.com and www.google.com", + EXPECT_EQ("Your data on www.google.com and encrypted.google.com", UTF16ToUTF8(warnings[0])); } @@ -572,10 +589,10 @@ TEST(ExtensionPermissionSetTest, GetWarningMessages_Plugins) { TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { scoped_ptr<ExtensionPermissionSet> perm_set; ExtensionAPIPermissionSet empty_perms; - std::set<std::string> expected; - expected.insert("www.foo.com"); - expected.insert("www.bar.com"); - expected.insert("www.baz.com"); + std::vector<std::string> expected; + expected.push_back("www.foo.com"); + expected.push_back("www.bar.com"); + expected.push_back("www.baz.com"); URLPatternSet explicit_hosts; URLPatternSet scriptable_hosts; @@ -591,7 +608,7 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } { @@ -604,7 +621,7 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } { @@ -615,7 +632,7 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path")); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } { @@ -626,7 +643,7 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath")); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } { @@ -638,12 +655,12 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { explicit_hosts.AddPattern( URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path")); - expected.insert("monkey.www.bar.com"); - expected.insert("bar.com"); + expected.push_back("monkey.www.bar.com"); + expected.push_back("bar.com"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } { @@ -670,11 +687,11 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { explicit_hosts.AddPattern( URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); - expected.insert("www.foo.xyzzy"); + expected.push_back("www.foo.xyzzy"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } { @@ -683,11 +700,11 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { explicit_hosts.AddPattern( URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); - expected.insert("*.google.com"); + expected.push_back("*.google.com"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } { @@ -701,12 +718,12 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { scriptable_hosts.AddPattern( URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); - expected.insert("*.google.com"); - expected.insert("*.example.com"); + expected.push_back("*.google.com"); + expected.push_back("*.example.com"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } } @@ -728,11 +745,11 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_ComIsBestRcd) { explicit_hosts.AddPattern( URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); - std::set<std::string> expected; - expected.insert("www.foo.com"); + std::vector<std::string> expected; + expected.push_back("www.foo.com"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) { @@ -752,11 +769,11 @@ TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) { URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); // No http://www.foo.com/path - std::set<std::string> expected; - expected.insert("www.foo.net"); + std::vector<std::string> expected; + expected.push_back("www.foo.net"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } TEST(ExtensionPermissionSetTest, @@ -776,11 +793,11 @@ TEST(ExtensionPermissionSetTest, URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); // No http://www.foo.com/path - std::set<std::string> expected; - expected.insert("www.foo.org"); + std::vector<std::string> expected; + expected.push_back("www.foo.org"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } TEST(ExtensionPermissionSetTest, @@ -799,11 +816,11 @@ TEST(ExtensionPermissionSetTest, URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); // No http://www.foo.com/path - std::set<std::string> expected; - expected.insert("www.foo.ca"); + std::vector<std::string> expected; + expected.push_back("www.foo.ca"); perm_set.reset(new ExtensionPermissionSet( empty_perms, explicit_hosts, scriptable_hosts)); - EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); + CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); } TEST(ExtensionPermissionSetTest, HasLessHostPrivilegesThan) { diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc index 9ad2a60..aa8555c 100644 --- a/chrome/common/extensions/extension_unittest.cc +++ b/chrome/common/extensions/extension_unittest.cc @@ -551,7 +551,7 @@ TEST(ExtensionTest, GetHostPermissionMessages_ManyHosts) { extension = LoadManifest("permissions", "many-hosts.json"); std::vector<string16> warnings = extension->GetPermissionMessageStrings(); ASSERT_EQ(1u, warnings.size()); - EXPECT_EQ("Your data on encrypted.google.com and www.google.com", + EXPECT_EQ("Your data on www.google.com and encrypted.google.com", UTF16ToUTF8(warnings[0])); } diff --git a/chrome/common/extensions/file_browser_handler.h b/chrome/common/extensions/file_browser_handler.h index d407bf89..74e478c 100644 --- a/chrome/common/extensions/file_browser_handler.h +++ b/chrome/common/extensions/file_browser_handler.h @@ -37,8 +37,8 @@ class FileBrowserHandler { void set_title(const std::string& title) { title_ = title; } // File schema URL patterns. - const URLPatternSet& file_url_patterns() const { - return url_set_; + const URLPatternList& file_url_patterns() const { + return url_set_.patterns(); } void AddPattern(const URLPattern& pattern); bool MatchesURL(const GURL& url) const; diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc index 6731ab8..af0fd0a 100644 --- a/chrome/common/extensions/url_pattern.cc +++ b/chrome/common/extensions/url_pattern.cc @@ -124,18 +124,8 @@ URLPattern::URLPattern(int valid_schemes, const std::string& pattern) URLPattern::~URLPattern() { } -bool URLPattern::operator<(const URLPattern& other) const { - return GetAsString() < other.GetAsString(); -} - -bool URLPattern::operator==(const URLPattern& other) const { - return GetAsString() == other.GetAsString(); -} - URLPattern::ParseResult URLPattern::Parse(const std::string& pattern, ParseOption strictness) { - spec_.clear(); - // Special case pattern to match every valid URL. if (pattern == kAllUrlsPattern) { match_all_urls_ = true; @@ -244,28 +234,7 @@ URLPattern::ParseResult URLPattern::Parse(const std::string& pattern, return PARSE_SUCCESS; } -void URLPattern::SetValidSchemes(int valid_schemes) { - spec_.clear(); - valid_schemes_ = valid_schemes; -} - -void URLPattern::SetHost(const std::string& host) { - spec_.clear(); - host_ = host; -} - -void URLPattern::SetMatchAllURLs(bool val) { - spec_.clear(); - match_all_urls_ = val; -} - -void URLPattern::SetMatchSubdomains(bool val) { - spec_.clear(); - match_subdomains_ = val; -} - bool URLPattern::SetScheme(const std::string& scheme) { - spec_.clear(); scheme_ = scheme; if (scheme_ == "*") { valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS); @@ -288,7 +257,6 @@ bool URLPattern::IsValidScheme(const std::string& scheme) const { } void URLPattern::SetPath(const std::string& path) { - spec_.clear(); path_ = path; path_escaped_ = path_; ReplaceSubstringsAfterOffset(&path_escaped_, 0, "\\", "\\\\"); @@ -296,7 +264,6 @@ void URLPattern::SetPath(const std::string& path) { } bool URLPattern::SetPort(const std::string& port) { - spec_.clear(); if (IsValidPortForScheme(scheme_, port)) { port_ = port; return true; @@ -384,15 +351,9 @@ bool URLPattern::MatchesPort(int port) const { return port_ == "*" || port_ == base::IntToString(port); } - -const std::string& URLPattern::GetAsString() const { - if (!spec_.empty()) - return spec_; - - if (match_all_urls_) { - spec_ = kAllUrlsPattern; - return spec_; - } +std::string URLPattern::GetAsString() const { + if (match_all_urls_) + return kAllUrlsPattern; bool standard_scheme = IsStandardScheme(scheme_); @@ -418,8 +379,7 @@ const std::string& URLPattern::GetAsString() const { if (!path_.empty()) spec += path_; - spec_ = spec; - return spec_; + return spec; } bool URLPattern::OverlapsWith(const URLPattern& other) const { @@ -485,7 +445,7 @@ std::vector<URLPattern> URLPattern::ConvertToExplicitSchemes() const { i != explicit_schemes.end(); ++i) { URLPattern temp = *this; temp.SetScheme(*i); - temp.SetMatchAllURLs(false); + temp.set_match_all_urls(false); result.push_back(temp); } diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h index 21ae210..113d266 100644 --- a/chrome/common/extensions/url_pattern.h +++ b/chrome/common/extensions/url_pattern.h @@ -142,35 +142,18 @@ class URLPattern { ~URLPattern(); - bool operator<(const URLPattern& other) const; - bool operator==(const URLPattern& other) const; - - // Initializes this instance by parsing the provided string. Returns - // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On - // failure, this instance will have some intermediate values and is in an - // invalid state. Adding error checks to URLPattern::Parse() can cause - // patterns in installed extensions to fail. If an installed extension - // uses a pattern that was valid but fails a new error check, the - // extension will fail to load when chrome is auto-updated. To avoid - // this, new parse checks are enabled only when |strictness| is - // OPTION_STRICT. OPTION_STRICT should be used when loading in developer - // mode, or when an extension's patterns are controlled by chrome (such - // as component extensions). - ParseResult Parse(const std::string& pattern_str, - ParseOption strictness); - // Gets the bitmask of valid schemes. int valid_schemes() const { return valid_schemes_; } - void SetValidSchemes(int valid_schemes); + void set_valid_schemes(int valid_schemes) { valid_schemes_ = valid_schemes; } // Gets the host the pattern matches. This can be an empty string if the // pattern matches all hosts (the input was <scheme>://*/<whatever>). const std::string& host() const { return host_; } - void SetHost(const std::string& host); + void set_host(const std::string& host) { host_ = host; } // Gets whether to match subdomains of host(). bool match_subdomains() const { return match_subdomains_; } - void SetMatchSubdomains(bool val); + void set_match_subdomains(bool val) { match_subdomains_ = val; } // Gets the path the pattern matches with the leading slash. This can have // embedded asterisks which are interpreted using glob rules. @@ -179,7 +162,21 @@ class URLPattern { // Returns true if this pattern matches all urls. bool match_all_urls() const { return match_all_urls_; } - void SetMatchAllURLs(bool val); + void set_match_all_urls(bool val) { match_all_urls_ = val; } + + // Initializes this instance by parsing the provided string. Returns + // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On + // failure, this instance will have some intermediate values and is in an + // invalid state. Adding error checks to URLPattern::Parse() can cause + // patterns in installed extensions to fail. If an installed extension + // uses a pattern that was valid but fails a new error check, the + // extension will fail to load when chrome is auto-updated. To avoid + // this, new parse checks are enabled only when |strictness| is + // OPTION_STRICT. OPTION_STRICT should be used when loading in developer + // mode, or when an extension's patterns are controlled by chrome (such + // as component extensions). + ParseResult Parse(const std::string& pattern_str, + ParseOption strictness); // Sets the scheme for pattern matches. This can be a single '*' if the // pattern matches all valid schemes (as defined by the valid_schemes_ @@ -214,7 +211,7 @@ class URLPattern { const std::string& port() const { return port_; } // Returns a string representing this instance. - const std::string& GetAsString() const; + std::string GetAsString() const; // Determine whether there is a URL that would match this instance and another // instance. This method is symmetrical: Calling other.OverlapsWith(this) @@ -290,9 +287,6 @@ class URLPattern { // The path with "?" and "\" characters escaped for use with the // MatchPattern() function. std::string path_escaped_; - - // A string representing this URLPattern. - mutable std::string spec_; }; typedef std::vector<URLPattern> URLPatternList; diff --git a/chrome/common/extensions/url_pattern_set.cc b/chrome/common/extensions/url_pattern_set.cc index 3c8f52c..65f8635 100644 --- a/chrome/common/extensions/url_pattern_set.cc +++ b/chrome/common/extensions/url_pattern_set.cc @@ -4,9 +4,6 @@ #include "chrome/common/extensions/url_pattern_set.h" -#include <algorithm> -#include <iterator> - #include "chrome/common/extensions/url_pattern.h" #include "googleurl/src/gurl.h" @@ -14,38 +11,39 @@ void URLPatternSet::CreateUnion(const URLPatternSet& set1, const URLPatternSet& set2, URLPatternSet* out) { + const URLPatternList list1 = set1.patterns(); + const URLPatternList list2 = set2.patterns(); + out->ClearPatterns(); - std::set_union(set1.patterns_.begin(), set1.patterns_.end(), - set2.patterns_.begin(), set2.patterns_.end(), - std::inserter<std::set<URLPattern> >( - out->patterns_, out->patterns_.begin())); + + for (size_t i = 0; i < list1.size(); ++i) + out->AddPattern(list1.at(i)); + + for (size_t i = 0; i < list2.size(); ++i) + out->AddPattern(list2.at(i)); } -URLPatternSet::URLPatternSet() {} +URLPatternSet::URLPatternSet() { +} URLPatternSet::URLPatternSet(const URLPatternSet& rhs) - : patterns_(rhs.patterns_) {} - -URLPatternSet::URLPatternSet(const std::set<URLPattern>& patterns) - : patterns_(patterns) {} + : patterns_(rhs.patterns_) { +} -URLPatternSet::~URLPatternSet() {} +URLPatternSet::~URLPatternSet() { +} URLPatternSet& URLPatternSet::operator=(const URLPatternSet& rhs) { patterns_ = rhs.patterns_; return *this; } -bool URLPatternSet::operator==(const URLPatternSet& other) const { - return patterns_ == other.patterns_; -} - bool URLPatternSet::is_empty() const { return patterns_.empty(); } void URLPatternSet::AddPattern(const URLPattern& pattern) { - patterns_.insert(pattern); + patterns_.push_back(pattern); } void URLPatternSet::ClearPatterns() { @@ -53,7 +51,7 @@ void URLPatternSet::ClearPatterns() { } bool URLPatternSet::MatchesURL(const GURL& url) const { - for (URLPatternSet::const_iterator pattern = patterns_.begin(); + for (URLPatternList::const_iterator pattern = patterns_.begin(); pattern != patterns_.end(); ++pattern) { if (pattern->MatchesURL(url)) return true; @@ -65,9 +63,9 @@ bool URLPatternSet::MatchesURL(const GURL& url) const { bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const { // Two extension extents overlap if there is any one URL that would match at // least one pattern in each of the extents. - for (URLPatternSet::const_iterator i = patterns_.begin(); + for (URLPatternList::const_iterator i = patterns_.begin(); i != patterns_.end(); ++i) { - for (URLPatternSet::const_iterator j = other.patterns().begin(); + for (URLPatternList::const_iterator j = other.patterns().begin(); j != other.patterns().end(); ++j) { if (i->OverlapsWith(*j)) return true; diff --git a/chrome/common/extensions/url_pattern_set.h b/chrome/common/extensions/url_pattern_set.h index 0c8be44..2120e547 100644 --- a/chrome/common/extensions/url_pattern_set.h +++ b/chrome/common/extensions/url_pattern_set.h @@ -6,7 +6,6 @@ #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ #pragma once -#include <set> #include <vector> #include "chrome/common/extensions/url_pattern.h" @@ -16,27 +15,20 @@ class GURL; // Represents the set of URLs an extension uses for web content. class URLPatternSet { public: - typedef std::set<URLPattern>::const_iterator const_iterator; - typedef std::set<URLPattern>::iterator iterator; - // Clears |out| and populates the set with the union of |set1| and |set2|. + // NOTE: this does not discard duplicates. static void CreateUnion(const URLPatternSet& set1, const URLPatternSet& set2, URLPatternSet* out); URLPatternSet(); URLPatternSet(const URLPatternSet& rhs); - explicit URLPatternSet(const std::set<URLPattern>& patterns); ~URLPatternSet(); - URLPatternSet& operator=(const URLPatternSet& rhs); - bool operator==(const URLPatternSet& rhs) const; bool is_empty() const; - const std::set<URLPattern>& patterns() const { return patterns_; } - const_iterator begin() const { return patterns_.begin(); } - const_iterator end() const { return patterns_.end(); } + const URLPatternList& patterns() const { return patterns_; } void AddPattern(const URLPattern& pattern); void ClearPatterns(); @@ -48,7 +40,7 @@ class URLPatternSet { private: // The list of URL patterns that comprise the extent. - std::set<URLPattern> patterns_; + URLPatternList patterns_; }; #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ diff --git a/chrome/common/extensions/url_pattern_set_unittest.cc b/chrome/common/extensions/url_pattern_set_unittest.cc index f9717ef..8c05f2c 100644 --- a/chrome/common/extensions/url_pattern_set_unittest.cc +++ b/chrome/common/extensions/url_pattern_set_unittest.cc @@ -7,6 +7,27 @@ #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" +namespace { + +static void AssertEqualExtents(const URLPatternSet& extent1, + const URLPatternSet& extent2) { + URLPatternList patterns1 = extent1.patterns(); + URLPatternList patterns2 = extent2.patterns(); + std::set<std::string> strings1; + EXPECT_EQ(patterns1.size(), patterns2.size()); + + for (size_t i = 0; i < patterns1.size(); ++i) + strings1.insert(patterns1.at(i).GetAsString()); + + std::set<std::string> strings2; + for (size_t i = 0; i < patterns2.size(); ++i) + strings2.insert(patterns2.at(i).GetAsString()); + + EXPECT_EQ(strings1, strings2); +} + +} // namespace + static const int kAllSchemes = URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | @@ -75,7 +96,7 @@ TEST(URLPatternSetTest, CreateUnion) { // Union with an empty set. URLPatternSet result; URLPatternSet::CreateUnion(extent1, empty_extent, &result); - EXPECT_EQ(expected, result); + AssertEqualExtents(expected, result); // Union with a real set (including a duplicate). URLPatternSet extent2; @@ -90,5 +111,5 @@ TEST(URLPatternSetTest, CreateUnion) { result.ClearPatterns(); URLPatternSet::CreateUnion(extent1, extent2, &result); - EXPECT_EQ(expected, result); + AssertEqualExtents(expected, result); } diff --git a/chrome/common/extensions/url_pattern_unittest.cc b/chrome/common/extensions/url_pattern_unittest.cc index 5c72a05..0903395 100644 --- a/chrome/common/extensions/url_pattern_unittest.cc +++ b/chrome/common/extensions/url_pattern_unittest.cc @@ -580,97 +580,3 @@ TEST(ExtensionURLPatternTest, IgnorePorts) { EXPECT_FALSE(pattern1.MatchesURL(url)); EXPECT_FALSE(pattern2.MatchesURL(url)); } - -TEST(ExtensionURLPatternTest, Equals) { - const struct { - const char* pattern1; - const char* pattern2; - bool expected_equal; - } kEqualsTestCases[] = { - // schemes - { "http://en.google.com/blah/*/foo", - "https://en.google.com/blah/*/foo", - false - }, - { "https://en.google.com/blah/*/foo", - "https://en.google.com/blah/*/foo", - true - }, - { "https://en.google.com/blah/*/foo", - "ftp://en.google.com/blah/*/foo", - false - }, - - // subdomains - { "https://en.google.com/blah/*/foo", - "https://fr.google.com/blah/*/foo", - false - }, - { "https://www.google.com/blah/*/foo", - "https://*.google.com/blah/*/foo", - false - }, - { "https://*.google.com/blah/*/foo", - "https://*.google.com/blah/*/foo", - true - }, - - // domains - { "http://en.example.com/blah/*/foo", - "http://en.google.com/blah/*/foo", - false - }, - - // ports - { "http://en.google.com:8000/blah/*/foo", - "http://en.google.com/blah/*/foo", - false - }, - { "http://fr.google.com:8000/blah/*/foo", - "http://fr.google.com:8000/blah/*/foo", - true - }, - { "http://en.google.com:8000/blah/*/foo", - "http://en.google.com:8080/blah/*/foo", - false - }, - - // paths - { "http://en.google.com/blah/*/foo", - "http://en.google.com/blah/*", - false - }, - { "http://en.google.com/*", - "http://en.google.com/", - false - }, - { "http://en.google.com/*", - "http://en.google.com/*", - true - }, - - // all_urls - { "<all_urls>", - "<all_urls>", - true - }, - { "<all_urls>", - "http://*/*", - false - } - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEqualsTestCases); ++i) { - std::string message = kEqualsTestCases[i].pattern1; - message += " "; - message += kEqualsTestCases[i].pattern2; - - URLPattern pattern1(URLPattern::SCHEME_ALL); - URLPattern pattern2(URLPattern::SCHEME_ALL); - - pattern1.Parse(kEqualsTestCases[i].pattern1, URLPattern::USE_PORTS); - pattern2.Parse(kEqualsTestCases[i].pattern2, URLPattern::USE_PORTS); - EXPECT_EQ(kEqualsTestCases[i].expected_equal, pattern1 == pattern2) - << message; - } -} diff --git a/chrome/common/extensions/user_script.cc b/chrome/common/extensions/user_script.cc index 77fd715..17aadbc 100644 --- a/chrome/common/extensions/user_script.cc +++ b/chrome/common/extensions/user_script.cc @@ -121,9 +121,9 @@ void UserScript::Pickle(::Pickle* pickle) const { } // Write url patterns. - URLPatternSet pattern_list = url_set_; - pickle->WriteSize(pattern_list.patterns().size()); - for (URLPatternSet::const_iterator pattern = pattern_list.begin(); + URLPatternList pattern_list = url_set_.patterns(); + pickle->WriteSize(pattern_list.size()); + for (URLPatternList::const_iterator pattern = pattern_list.begin(); pattern != pattern_list.end(); ++pattern) { pickle->WriteInt(pattern->valid_schemes()); pickle->WriteString(pattern->GetAsString()); @@ -191,11 +191,11 @@ void UserScript::Unpickle(const ::Pickle& pickle, void** iter) { // pattern so that it's valid. bool had_file_scheme = (valid_schemes & URLPattern::SCHEME_FILE) != 0; if (!had_file_scheme) - pattern.SetValidSchemes(valid_schemes | URLPattern::SCHEME_FILE); + pattern.set_valid_schemes(valid_schemes | URLPattern::SCHEME_FILE); CHECK(URLPattern::PARSE_SUCCESS == pattern.Parse(pattern_str, URLPattern::IGNORE_PORTS)); if (!had_file_scheme) - pattern.SetValidSchemes(valid_schemes); + pattern.set_valid_schemes(valid_schemes); url_set_.AddPattern(pattern); } diff --git a/chrome/common/extensions/user_script.h b/chrome/common/extensions/user_script.h index 6153f4b..ab42e0b 100644 --- a/chrome/common/extensions/user_script.h +++ b/chrome/common/extensions/user_script.h @@ -149,11 +149,10 @@ class UserScript { // The URLPatterns, if any, that determine which pages this script runs // against. - const URLPatternSet& url_patterns() const { return url_set_; } + const URLPatternList& url_patterns() const { return url_set_.patterns(); } void add_url_pattern(const URLPattern& pattern); - const URLPatternSet& exclude_url_patterns() const { - return exclude_url_set_; - } + const URLPatternList& exclude_url_patterns() const { + return exclude_url_set_.patterns(); } void add_exclude_url_pattern(const URLPattern& pattern); // List of js scripts for this user script diff --git a/chrome/common/extensions/user_script_unittest.cc b/chrome/common/extensions/user_script_unittest.cc index f3eb5fe..c04e54d 100644 --- a/chrome/common/extensions/user_script_unittest.cc +++ b/chrome/common/extensions/user_script_unittest.cc @@ -208,8 +208,11 @@ TEST(ExtensionUserScriptTest, Pickle) { for (size_t i = 0; i < script1.globs().size(); ++i) { EXPECT_EQ(script1.globs()[i], script2.globs()[i]); } - - ASSERT_EQ(script1.url_patterns(), script2.url_patterns()); + ASSERT_EQ(script1.url_patterns().size(), script2.url_patterns().size()); + for (size_t i = 0; i < script1.url_patterns().size(); ++i) { + EXPECT_EQ(script1.url_patterns()[i].GetAsString(), + script2.url_patterns()[i].GetAsString()); + } } TEST(ExtensionUserScriptTest, Defaults) { |