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 | |
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
31 files changed, 336 insertions, 427 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index b7eccd8..0893b50 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -4080,15 +4080,15 @@ void TestingAutomationProvider::GetThemeInfo( namespace { ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { - URLPatternSet pattern_set; + URLPatternList pattern_list; if (effective_perm) - pattern_set = ext->GetEffectiveHostPermissions(); + pattern_list = ext->GetEffectiveHostPermissions().patterns(); else - pattern_set = ext->permission_set()->explicit_hosts(); + pattern_list = ext->permission_set()->explicit_hosts().patterns(); ListValue* permissions = new ListValue; - for (URLPatternSet::const_iterator perm = pattern_set.begin(); - perm != pattern_set.end(); ++perm) { + for (URLPatternList::const_iterator perm = pattern_list.begin(); + perm != pattern_list.end(); ++perm) { permissions->Append(new StringValue(perm->GetAsString())); } diff --git a/chrome/browser/extensions/convert_user_script.cc b/chrome/browser/extensions/convert_user_script.cc index a8f2427..8d7aafe 100644 --- a/chrome/browser/extensions/convert_user_script.cc +++ b/chrome/browser/extensions/convert_user_script.cc @@ -102,10 +102,10 @@ scoped_refptr<Extension> ConvertUserScriptToExtension( // If the script provides its own match patterns, we use those. Otherwise, we // generate some using the include globs. ListValue* matches = new ListValue(); - if (!script.url_patterns().is_empty()) { - for (URLPatternSet::const_iterator i = script.url_patterns().begin(); - i != script.url_patterns().end(); ++i) { - matches->Append(Value::CreateStringValue(i->GetAsString())); + if (!script.url_patterns().empty()) { + for (size_t i = 0; i < script.url_patterns().size(); ++i) { + matches->Append(Value::CreateStringValue( + script.url_patterns()[i].GetAsString())); } } else { // TODO(aa): Derive tighter matches where possible. diff --git a/chrome/browser/extensions/convert_user_script_unittest.cc b/chrome/browser/extensions/convert_user_script_unittest.cc index 38b106a..a8aab8f 100644 --- a/chrome/browser/extensions/convert_user_script_unittest.cc +++ b/chrome/browser/extensions/convert_user_script_unittest.cc @@ -15,15 +15,6 @@ #include "chrome/common/extensions/extension.h" #include "testing/gtest/include/gtest/gtest.h" -namespace { - -static void AddPattern(URLPatternSet* extent, const std::string& pattern) { - int schemes = URLPattern::SCHEME_ALL; - extent->AddPattern(URLPattern(schemes, pattern)); -} - -} - TEST(ExtensionFromUserScript, Basic) { FilePath test_file; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); @@ -56,9 +47,8 @@ TEST(ExtensionFromUserScript, Basic) { EXPECT_EQ("http://www.yahoo.com/*", script.globs().at(1)); ASSERT_EQ(1u, script.exclude_globs().size()); EXPECT_EQ("*foo*", script.exclude_globs().at(0)); - ASSERT_EQ(1u, script.url_patterns().patterns().size()); - EXPECT_EQ("http://www.google.com/*", - script.url_patterns().begin()->GetAsString()); + ASSERT_EQ(1u, script.url_patterns().size()); + EXPECT_EQ("http://www.google.com/*", script.url_patterns()[0].GetAsString()); // Make sure the files actually exist on disk. EXPECT_TRUE(file_util::PathExists( @@ -96,11 +86,9 @@ TEST(ExtensionFromUserScript, NoMetdata) { ASSERT_EQ(1u, script.globs().size()); EXPECT_EQ("*", script.globs()[0]); EXPECT_EQ(0u, script.exclude_globs().size()); - - URLPatternSet expected; - AddPattern(&expected, "http://*/*"); - AddPattern(&expected, "https://*/*"); - EXPECT_EQ(expected, script.url_patterns()); + ASSERT_EQ(2u, script.url_patterns().size()); + EXPECT_EQ("http://*/*", script.url_patterns()[0].GetAsString()); + EXPECT_EQ("https://*/*", script.url_patterns()[1].GetAsString()); // Make sure the files actually exist on disk. EXPECT_TRUE(file_util::PathExists( diff --git a/chrome/browser/extensions/convert_web_app_unittest.cc b/chrome/browser/extensions/convert_web_app_unittest.cc index 0f3b537..4aafc4f 100644 --- a/chrome/browser/extensions/convert_web_app_unittest.cc +++ b/chrome/browser/extensions/convert_web_app_unittest.cc @@ -128,7 +128,7 @@ TEST(ExtensionFromWebApp, Basic) { EXPECT_TRUE(extension->HasAPIPermission("notifications")); ASSERT_EQ(1u, extension->web_extent().patterns().size()); EXPECT_EQ("http://aaronboodman.com/gearpad/*", - extension->web_extent().patterns().begin()->GetAsString()); + extension->web_extent().patterns()[0].GetAsString()); EXPECT_EQ(web_app.icons.size(), extension->icons().map().size()); for (size_t i = 0; i < web_app.icons.size(); ++i) { @@ -170,5 +170,5 @@ TEST(ExtensionFromWebApp, Minimal) { EXPECT_EQ(0u, extension->permission_set()->apis().size()); ASSERT_EQ(1u, extension->web_extent().patterns().size()); EXPECT_EQ("*://aaronboodman.com/*", - extension->web_extent().patterns().begin()->GetAsString()); + extension->web_extent().patterns()[0].GetAsString()); } diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index a1e3863..3581571 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -283,13 +283,12 @@ bool CrxInstaller::AllowInstall(const Extension* extension, // host (or a subdomain of the host) the download happened from. There's // no way for us to verify that the app controls any other hosts. URLPattern pattern(UserScript::kValidUserScriptSchemes); - pattern.SetHost(original_url_.host()); - pattern.SetMatchSubdomains(true); + pattern.set_host(original_url_.host()); + pattern.set_match_subdomains(true); - URLPatternSet patterns = extension_->web_extent(); - for (URLPatternSet::const_iterator i = patterns.begin(); - i != patterns.end(); ++i) { - if (!pattern.MatchesHost(i->host())) { + URLPatternList patterns = extension_->web_extent().patterns(); + for (size_t i = 0; i < patterns.size(); ++i) { + if (!pattern.MatchesHost(patterns[i].host())) { *error = base::StringPrintf( "Apps must be served from the host that they affect."); return false; diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc index 3955361..9dc479c 100644 --- a/chrome/browser/extensions/extension_management_api.cc +++ b/chrome/browser/extensions/extension_management_api.cc @@ -106,10 +106,10 @@ static DictionaryValue* CreateExtensionInfo(const Extension& extension, ListValue* host_permission_list = new ListValue(); if (!extension.is_hosted_app()) { // Skip host permissions for hosted apps. - const URLPatternSet host_perms = - extension.permission_set()->explicit_hosts(); - if (!host_perms.is_empty()) { - URLPatternSet::const_iterator host_perms_iter; + const URLPatternList host_perms = + extension.permission_set()->explicit_hosts().patterns(); + if (!host_perms.empty()) { + URLPatternList::const_iterator host_perms_iter; for (host_perms_iter = host_perms.begin(); host_perms_iter != host_perms.end(); ++host_perms_iter) { diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index f5e16a5..4a1dd2c 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -394,7 +394,7 @@ bool ExtensionPrefs::ReadExtensionPrefURLPatternSet( return false; } if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { - pattern.SetValidSchemes( + pattern.set_valid_schemes( pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); } result->AddPattern(pattern); @@ -408,8 +408,8 @@ void ExtensionPrefs::SetExtensionPrefURLPatternSet( const std::string& pref_key, const URLPatternSet& new_value) { ListValue* value = new ListValue(); - for (URLPatternSet::const_iterator i = new_value.begin(); - i != new_value.end(); ++i) + for (URLPatternList::const_iterator i = new_value.patterns().begin(); + i != new_value.patterns().end(); ++i) value->AppendIfNotPresent(Value::CreateStringValue(i->GetAsString())); UpdateExtensionPref(extension_id, pref_key, value); diff --git a/chrome/browser/extensions/extension_prefs_unittest.cc b/chrome/browser/extensions/extension_prefs_unittest.cc index 72e65aa..31f86d1 100644 --- a/chrome/browser/extensions/extension_prefs_unittest.cc +++ b/chrome/browser/extensions/extension_prefs_unittest.cc @@ -44,6 +44,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(); + EXPECT_EQ(patterns1.size(), patterns2.size()); + + std::set<std::string> strings1; + 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); +} + // Base class for tests. class ExtensionPrefsTest : public testing::Test { public: @@ -248,10 +265,10 @@ class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { EXPECT_FALSE(granted_permissions->IsEmpty()); EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); EXPECT_EQ(expected_apis, granted_permissions->apis()); - EXPECT_EQ(ehost_perm_set1_, - granted_permissions->explicit_hosts()); - EXPECT_EQ(ehost_perm_set1_, - granted_permissions->effective_hosts()); + AssertEqualExtents(ehost_perm_set1_, + granted_permissions->explicit_hosts()); + AssertEqualExtents(ehost_perm_set1_, + granted_permissions->effective_hosts()); // Add part of the scriptable host permissions. permissions.reset(new ExtensionPermissionSet( @@ -261,14 +278,14 @@ class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { EXPECT_FALSE(granted_permissions->IsEmpty()); EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); EXPECT_EQ(expected_apis, granted_permissions->apis()); - EXPECT_EQ(ehost_perm_set1_, - granted_permissions->explicit_hosts()); - EXPECT_EQ(shost_perm_set1_, - granted_permissions->scriptable_hosts()); - + AssertEqualExtents(ehost_perm_set1_, + granted_permissions->explicit_hosts()); + AssertEqualExtents(shost_perm_set1_, + granted_permissions->scriptable_hosts()); URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, &effective_permissions_); - EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); + AssertEqualExtents(effective_permissions_, + granted_permissions->effective_hosts()); // Add the rest of both the permissions. permissions.reset(new ExtensionPermissionSet( @@ -283,14 +300,15 @@ class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { EXPECT_TRUE(granted_permissions.get()); EXPECT_FALSE(granted_permissions->IsEmpty()); EXPECT_EQ(api_permissions_, granted_permissions->apis()); - EXPECT_EQ(ehost_permissions_, - granted_permissions->explicit_hosts()); - EXPECT_EQ(shost_permissions_, - granted_permissions->scriptable_hosts()); + AssertEqualExtents(ehost_permissions_, + granted_permissions->explicit_hosts()); + AssertEqualExtents(shost_permissions_, + granted_permissions->scriptable_hosts()); effective_permissions_.ClearPatterns(); URLPatternSet::CreateUnion(ehost_permissions_, shost_permissions_, &effective_permissions_); - EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); + AssertEqualExtents(effective_permissions_, + granted_permissions->effective_hosts()); } virtual void Verify() { @@ -299,10 +317,8 @@ class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { EXPECT_TRUE(permissions.get()); EXPECT_FALSE(permissions->HasEffectiveFullAccess()); EXPECT_EQ(api_permissions_, permissions->apis()); - EXPECT_EQ(ehost_permissions_, - permissions->explicit_hosts()); - EXPECT_EQ(shost_permissions_, - permissions->scriptable_hosts()); + AssertEqualExtents(ehost_permissions_, permissions->explicit_hosts()); + AssertEqualExtents(shost_permissions_, permissions->scriptable_hosts()); } private: diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 9d0245e..2bac463 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -114,6 +114,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 MockExtensionProvider : public ExternalExtensionProviderInterface { @@ -983,14 +1000,16 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { ValidateIntegerPref(good2, "state", Extension::ENABLED); ValidateIntegerPref(good2, "location", Extension::INTERNAL); - URLPatternSet expected_patterns; - AddPattern(&expected_patterns, "file:///*"); - AddPattern(&expected_patterns, "http://*.google.com/*"); - AddPattern(&expected_patterns, "https://*.google.com/*"); const Extension* extension = loaded_[0]; const UserScriptList& scripts = extension->content_scripts(); ASSERT_EQ(2u, scripts.size()); - EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); + EXPECT_EQ(3u, scripts[0].url_patterns().size()); + EXPECT_EQ("file:///*", + scripts[0].url_patterns()[0].GetAsString()); + EXPECT_EQ("http://*.google.com/*", + scripts[0].url_patterns()[1].GetAsString()); + EXPECT_EQ("https://*.google.com/*", + scripts[0].url_patterns()[2].GetAsString()); EXPECT_EQ(2u, scripts[0].js_scripts().size()); ExtensionResource resource00(extension->id(), scripts[0].js_scripts()[0].extension_root(), @@ -1005,9 +1024,8 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); EXPECT_TRUE(extension->plugins().empty()); - EXPECT_EQ(1u, scripts[1].url_patterns().patterns().size()); - EXPECT_EQ("http://*.news.com/*", - scripts[1].url_patterns().begin()->GetAsString()); + EXPECT_EQ(1u, scripts[1].url_patterns().size()); + EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString()); ExtensionResource resource10(extension->id(), scripts[1].js_scripts()[0].extension_root(), scripts[1].js_scripts()[0].relative_path()); @@ -1015,11 +1033,11 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { extension->path().AppendASCII("js_files").AppendASCII("script3.js"); ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); - - expected_patterns.ClearPatterns(); - AddPattern(&expected_patterns, "http://*.google.com/*"); - AddPattern(&expected_patterns, "https://*.google.com/*"); - EXPECT_EQ(expected_patterns, extension->permission_set()->explicit_hosts()); + const URLPatternList permissions = + extension->permission_set()->explicit_hosts().patterns(); + ASSERT_EQ(2u, permissions.size()); + EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); + EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); EXPECT_EQ(std::string(good1), loaded_[1]->id()); EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); @@ -1384,7 +1402,7 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) { EXPECT_FALSE(known_perms->IsEmpty()); EXPECT_EQ(expected_api_perms, known_perms->apis()); EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); - EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); + AssertEqualExtents(expected_host_perms, known_perms->effective_hosts()); } #if !defined(OS_CHROMEOS) @@ -1479,7 +1497,8 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { ASSERT_FALSE(current_perms->IsEmpty()); ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); ASSERT_EQ(expected_api_permissions, current_perms->apis()); - ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); + AssertEqualExtents(expected_host_permissions, + current_perms->effective_hosts()); // Tests that the extension is disabled when a host permission is missing from // the extension's granted host permissions preference. (This simulates @@ -1520,7 +1539,8 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { ASSERT_FALSE(current_perms->IsEmpty()); ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); ASSERT_EQ(expected_api_permissions, current_perms->apis()); - ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); + AssertEqualExtents(expected_host_permissions, + current_perms->effective_hosts()); } // Test Packaging and installing an extension. diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index 958e0ab..96ade99b 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -130,7 +130,7 @@ bool UserScriptMaster::ScriptReloader::ParseMetadataHeader( // If no patterns were specified, default to @include *. This is what // Greasemonkey does. - if (script->globs().empty() && script->url_patterns().is_empty()) + if (script->globs().empty() && script->url_patterns().empty()) script->add_glob("*"); return true; diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc index 0ae3a4c..c5d6af1 100644 --- a/chrome/browser/extensions/user_script_master_unittest.cc +++ b/chrome/browser/extensions/user_script_master_unittest.cc @@ -19,15 +19,6 @@ #include "content/common/notification_service.h" #include "testing/gtest/include/gtest/gtest.h" -namespace { - -static void AddPattern(URLPatternSet* extent, const std::string& pattern) { - int schemes = URLPattern::SCHEME_ALL; - extent->AddPattern(URLPattern(schemes, pattern)); -} - -} - // Test bringing up a master on a specific directory, putting a script // in there, etc. @@ -151,15 +142,15 @@ TEST_F(UserScriptMasterTest, Parse4) { "// @match \t http://mail.yahoo.com/*\n" "// ==/UserScript==\n"); - URLPatternSet expected_patterns; - AddPattern(&expected_patterns, "http://*.mail.google.com/*"); - AddPattern(&expected_patterns, "http://mail.yahoo.com/*"); - UserScript script; EXPECT_TRUE(UserScriptMaster::ScriptReloader::ParseMetadataHeader( text, &script)); EXPECT_EQ(0U, script.globs().size()); - EXPECT_EQ(expected_patterns, script.url_patterns()); + ASSERT_EQ(2U, script.url_patterns().size()); + EXPECT_EQ("http://*.mail.google.com/*", + script.url_patterns()[0].GetAsString()); + EXPECT_EQ("http://mail.yahoo.com/*", + script.url_patterns()[1].GetAsString()); } TEST_F(UserScriptMasterTest, Parse5) { @@ -201,9 +192,9 @@ TEST_F(UserScriptMasterTest, Parse7) { text, &script)); ASSERT_EQ("hello", script.name()); ASSERT_EQ("wiggity woo", script.description()); - ASSERT_EQ(1U, script.url_patterns().patterns().size()); + ASSERT_EQ(1U, script.url_patterns().size()); EXPECT_EQ("http://mail.yahoo.com/*", - script.url_patterns().begin()->GetAsString()); + script.url_patterns()[0].GetAsString()); } TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) { 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) { diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc index 098e3e5..e654623 100644 --- a/chrome/renderer/extensions/extension_dispatcher.cc +++ b/chrome/renderer/extensions/extension_dispatcher.cc @@ -243,10 +243,9 @@ void ExtensionDispatcher::InitHostPermissions(const Extension* extension) { false); } - const URLPatternSet& permissions = - extension->permission_set()->explicit_hosts(); - for (URLPatternSet::const_iterator i = permissions.begin(); - i != permissions.end(); ++i) { + const URLPatternList& permissions = + extension->permission_set()->explicit_hosts().patterns(); + for (size_t i = 0; i < permissions.size(); ++i) { const char* schemes[] = { chrome::kHttpScheme, chrome::kHttpsScheme, @@ -254,12 +253,12 @@ void ExtensionDispatcher::InitHostPermissions(const Extension* extension) { chrome::kChromeUIScheme, }; for (size_t j = 0; j < arraysize(schemes); ++j) { - if (i->MatchesScheme(schemes[j])) { + if (permissions[i].MatchesScheme(schemes[j])) { WebSecurityPolicy::addOriginAccessWhitelistEntry( extension->url(), WebString::fromUTF8(schemes[j]), - WebString::fromUTF8(i->host()), - i->match_subdomains()); + WebString::fromUTF8(permissions[i].host()), + permissions[i].match_subdomains()); } } } diff --git a/chrome/renderer/extensions/user_script_slave.cc b/chrome/renderer/extensions/user_script_slave.cc index 48e20ab..6ea6201 100644 --- a/chrome/renderer/extensions/user_script_slave.cc +++ b/chrome/renderer/extensions/user_script_slave.cc @@ -84,10 +84,9 @@ int UserScriptSlave::GetIsolatedWorldId( void UserScriptSlave::InitializeIsolatedWorld( int isolated_world_id, const Extension* extension) { - const URLPatternSet& permissions = - extension->GetEffectiveHostPermissions(); - for (URLPatternSet::const_iterator i = permissions.begin(); - i != permissions.end(); ++i) { + const URLPatternList& permissions = + extension->GetEffectiveHostPermissions().patterns(); + for (size_t i = 0; i < permissions.size(); ++i) { const char* schemes[] = { chrome::kHttpScheme, chrome::kHttpsScheme, @@ -95,12 +94,12 @@ void UserScriptSlave::InitializeIsolatedWorld( chrome::kChromeUIScheme, }; for (size_t j = 0; j < arraysize(schemes); ++j) { - if (i->MatchesScheme(schemes[j])) { + if (permissions[i].MatchesScheme(schemes[j])) { WebSecurityPolicy::addOriginAccessWhitelistEntry( extension->url(), WebString::fromUTF8(schemes[j]), - WebString::fromUTF8(i->host()), - i->match_subdomains()); + WebString::fromUTF8(permissions[i].host()), + permissions[i].match_subdomains()); } } } @@ -199,10 +198,9 @@ bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { WebVector<WebString> patterns; std::vector<WebString> temp_patterns; - const URLPatternSet& url_patterns = script->url_patterns(); - for (URLPatternSet::const_iterator k = url_patterns.begin(); - k != url_patterns.end(); ++k) { - URLPatternList explicit_patterns = k->ConvertToExplicitSchemes(); + for (size_t k = 0; k < script->url_patterns().size(); ++k) { + URLPatternList explicit_patterns = + script->url_patterns()[k].ConvertToExplicitSchemes(); for (size_t m = 0; m < explicit_patterns.size(); ++m) { temp_patterns.push_back(WebString::fromUTF8( explicit_patterns[m].GetAsString())); |