diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-30 09:31:30 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-30 09:31:30 +0000 |
commit | 0d462462ec30bf81d47c79617beb4fff6eff3624 (patch) | |
tree | 453ebfbb763923091016aeb44b3c441cac5a3eee /chrome/browser | |
parent | 0397077945597d982f61aa3f2114f59e4c78336b (diff) | |
download | chromium_src-0d462462ec30bf81d47c79617beb4fff6eff3624.zip chromium_src-0d462462ec30bf81d47c79617beb4fff6eff3624.tar.gz chromium_src-0d462462ec30bf81d47c79617beb4fff6eff3624.tar.bz2 |
Use primary/secondary for URLs and patterns everywhere in the content settings extension API.
BUG=71067
Review URL: http://codereview.chromium.org/7253041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91106 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
5 files changed, 101 insertions, 80 deletions
diff --git a/chrome/browser/extensions/extension_content_settings_api.cc b/chrome/browser/extensions/extension_content_settings_api.cc index 58f8343..b76024e 100644 --- a/chrome/browser/extensions/extension_content_settings_api.cc +++ b/chrome/browser/extensions/extension_content_settings_api.cc @@ -85,24 +85,25 @@ bool GetContentSettingFunction::RunImpl() { DictionaryValue* details = NULL; EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); - std::string embedded_url_spec; + std::string primary_url_spec; EXTENSION_FUNCTION_VALIDATE( - details->GetString(keys::kEmbeddedUrlKey, &embedded_url_spec)); - GURL embedded_url(embedded_url_spec); - if (!embedded_url.is_valid()) { + details->GetString(keys::kPrimaryUrlKey, &primary_url_spec)); + GURL primary_url(primary_url_spec); + if (!primary_url.is_valid()) { error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, - embedded_url_spec); + primary_url_spec); return false; } - std::string top_level_url_spec; - EXTENSION_FUNCTION_VALIDATE( - details->GetString(keys::kTopLevelUrlKey, &top_level_url_spec)); - GURL top_level_url(top_level_url_spec); - if (!top_level_url.is_valid()) { - error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, - top_level_url_spec); - return false; + GURL secondary_url(primary_url); + std::string secondary_url_spec; + if (details->GetString(keys::kSecondaryUrlKey, &secondary_url_spec)) { + secondary_url = GURL(secondary_url_spec); + if (!secondary_url.is_valid()) { + error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, + secondary_url_spec); + return false; + } } std::string resource_identifier; @@ -143,10 +144,10 @@ bool GetContentSettingFunction::RunImpl() { if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { // TODO(jochen): Do we return the value for setting or for reading cookies? bool setting_cookie = false; - setting = map->GetCookieContentSetting(embedded_url, top_level_url, + setting = map->GetCookieContentSetting(primary_url, secondary_url, setting_cookie); } else { - setting = map->GetContentSetting(embedded_url, top_level_url, content_type, + setting = map->GetContentSetting(primary_url, secondary_url, content_type, resource_identifier); } @@ -169,26 +170,27 @@ bool SetContentSettingFunction::RunImpl() { DictionaryValue* details = NULL; EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); - std::string top_level_pattern_str; - std::string top_level_error; + std::string primary_pattern_str; EXTENSION_FUNCTION_VALIDATE( - details->GetString(keys::kTopLevelPatternKey, &top_level_pattern_str)); - ContentSettingsPattern top_level_pattern = - helpers::ParseExtensionPattern(top_level_pattern_str, &top_level_error); - if (!top_level_pattern.IsValid()) { - error_ = top_level_error; + details->GetString(keys::kPrimaryPatternKey, &primary_pattern_str)); + std::string primary_error; + ContentSettingsPattern primary_pattern = + helpers::ParseExtensionPattern(primary_pattern_str, &primary_error); + if (!primary_pattern.IsValid()) { + error_ = primary_error; return false; } - std::string embedded_pattern_str; - std::string embedded_error; - EXTENSION_FUNCTION_VALIDATE( - details->GetString(keys::kEmbeddedPatternKey, &embedded_pattern_str)); - ContentSettingsPattern embedded_pattern = - helpers::ParseExtensionPattern(embedded_pattern_str, &embedded_error); - if (!embedded_pattern.IsValid()) { - error_ = embedded_error; - return false; + ContentSettingsPattern secondary_pattern = ContentSettingsPattern::Wildcard(); + std::string secondary_pattern_str; + if (details->GetString(keys::kSecondaryPatternKey, &secondary_pattern_str)) { + std::string secondary_error; + secondary_pattern = + helpers::ParseExtensionPattern(secondary_pattern_str, &secondary_error); + if (!secondary_pattern.IsValid()) { + error_ = secondary_error; + return false; + } } std::string resource_identifier; @@ -247,8 +249,8 @@ bool SetContentSettingFunction::RunImpl() { ExtensionContentSettingsStore* store = profile_->GetExtensionService()->GetExtensionContentSettingsStore(); - store->SetExtensionContentSetting(extension_id(), top_level_pattern, - embedded_pattern, content_type, + store->SetExtensionContentSetting(extension_id(), primary_pattern, + secondary_pattern, content_type, resource_identifier, setting, scope); return true; } diff --git a/chrome/browser/extensions/extension_content_settings_api_constants.cc b/chrome/browser/extensions/extension_content_settings_api_constants.cc index 3e7c638..c01b3c90 100644 --- a/chrome/browser/extensions/extension_content_settings_api_constants.cc +++ b/chrome/browser/extensions/extension_content_settings_api_constants.cc @@ -10,14 +10,14 @@ namespace extension_content_settings_api_constants { const char kContentSettingKey[] = "setting"; const char kContentSettingsTypeKey[] = "type"; const char kDescriptionKey[] = "description"; -const char kEmbeddedPatternKey[] = "embeddedPattern"; -const char kEmbeddedUrlKey[] = "embeddedUrl"; const char kIdKey[] = "id"; const char kPatternKey[] = "pattern"; +const char kPrimaryPatternKey[] = "primaryPattern"; +const char kPrimaryUrlKey[] = "primaryUrl"; const char kResourceIdentifierKey[] = "resourceIdentifier"; const char kRuleKey[] = "rule"; -const char kTopLevelPatternKey[] = "topLevelPattern"; -const char kTopLevelUrlKey[] = "topLevelUrl"; +const char kSecondaryPatternKey[] = "secondaryPattern"; +const char kSecondaryUrlKey[] = "secondaryUrl"; // Errors. const char kIncognitoContextError[] = diff --git a/chrome/browser/extensions/extension_content_settings_api_constants.h b/chrome/browser/extensions/extension_content_settings_api_constants.h index 8938f85..4ada146 100644 --- a/chrome/browser/extensions/extension_content_settings_api_constants.h +++ b/chrome/browser/extensions/extension_content_settings_api_constants.h @@ -14,14 +14,14 @@ namespace extension_content_settings_api_constants { extern const char kContentSettingKey[]; extern const char kContentSettingsTypeKey[]; extern const char kDescriptionKey[]; -extern const char kEmbeddedPatternKey[]; -extern const char kEmbeddedUrlKey[]; extern const char kIdKey[]; extern const char kPatternKey[]; +extern const char kPrimaryPatternKey[]; +extern const char kPrimaryUrlKey[]; extern const char kResourceIdentifierKey[]; extern const char kRuleKey[]; -extern const char kTopLevelPatternKey[]; -extern const char kTopLevelUrlKey[]; +extern const char kSecondaryPatternKey[]; +extern const char kSecondaryUrlKey[]; // Errors. extern const char kIncognitoContextError[]; diff --git a/chrome/browser/extensions/extension_content_settings_store.cc b/chrome/browser/extensions/extension_content_settings_store.cc index ee02ce4..d8617b6 100644 --- a/chrome/browser/extensions/extension_content_settings_store.cc +++ b/chrome/browser/extensions/extension_content_settings_store.cc @@ -16,6 +16,24 @@ namespace helpers = extension_content_settings_helpers; namespace keys = extension_content_settings_api_constants; +namespace { + +bool ComparePatternPairs(const ContentSettingsPattern& first_primary, + const ContentSettingsPattern& first_secondary, + const ContentSettingsPattern& second_primary, + const ContentSettingsPattern& second_secondary) { + ContentSettingsPattern::Relation relation = + first_primary.Compare(second_primary); + if (relation == ContentSettingsPattern::SUCCESSOR) + return true; + if (relation == ContentSettingsPattern::PREDECESSOR) + return false; + return (first_secondary.Compare(second_secondary) == + ContentSettingsPattern::SUCCESSOR); +} + +} // namespace + using content_settings::ResourceIdentifier; struct ExtensionContentSettingsStore::ExtensionEntry { @@ -43,8 +61,8 @@ ExtensionContentSettingsStore::~ExtensionContentSettingsStore() { void ExtensionContentSettingsStore::SetExtensionContentSetting( const std::string& ext_id, - const ContentSettingsPattern& embedded_pattern, - const ContentSettingsPattern& top_level_pattern, + const ContentSettingsPattern& primary_pattern, + const ContentSettingsPattern& secondary_pattern, ContentSettingsType type, const content_settings::ResourceIdentifier& identifier, ContentSetting setting, @@ -57,8 +75,8 @@ void ExtensionContentSettingsStore::SetExtensionContentSetting( // Find |ContentSettingSpec|. ContentSettingSpecList::iterator setting_spec = setting_spec_list->begin(); while (setting_spec != setting_spec_list->end()) { - if (setting_spec->embedded_pattern == embedded_pattern && - setting_spec->top_level_pattern == top_level_pattern && + if (setting_spec->primary_pattern == primary_pattern && + setting_spec->secondary_pattern == secondary_pattern && setting_spec->content_type == type && setting_spec->resource_identifier == identifier) { break; @@ -66,8 +84,8 @@ void ExtensionContentSettingsStore::SetExtensionContentSetting( ++setting_spec; } if (setting_spec == setting_spec_list->end()) { - setting_spec_list->push_back(ContentSettingSpec(embedded_pattern, - top_level_pattern, + setting_spec_list->push_back(ContentSettingSpec(primary_pattern, + secondary_pattern, type, identifier, setting)); @@ -181,8 +199,8 @@ const ExtensionContentSettingsStore::ContentSettingSpecList* } ContentSetting ExtensionContentSettingsStore::GetContentSettingFromSpecList( - const GURL& embedded_url, - const GURL& top_level_url, + const GURL& primary_url, + const GURL& secondary_url, ContentSettingsType type, const content_settings::ResourceIdentifier& identifier, const ContentSettingSpecList& setting_spec_list) const { @@ -190,17 +208,18 @@ ContentSetting ExtensionContentSettingsStore::GetContentSettingFromSpecList( for (ContentSettingSpecList::const_iterator spec = setting_spec_list.begin(); spec != setting_spec_list.end(); ++spec) { - if (!spec->embedded_pattern.Matches(embedded_url) || - !spec->top_level_pattern.Matches(top_level_url) || + if (!spec->primary_pattern.Matches(primary_url) || + !spec->secondary_pattern.Matches(secondary_url) || spec->content_type != type || spec->resource_identifier != identifier) { continue; } - // TODO(markusheintz): Compare embedded patterns as well? if (winner_spec == setting_spec_list.end() || - winner_spec->top_level_pattern.Compare(spec->top_level_pattern) == - ContentSettingsPattern::SUCCESSOR) { + ComparePatternPairs(winner_spec->primary_pattern, + winner_spec->secondary_pattern, + spec->primary_pattern, + spec->secondary_pattern)) { winner_spec = spec; } } @@ -284,7 +303,7 @@ void ExtensionContentSettingsStore::AddRules( for (it = setting_spec_list->begin(); it != setting_spec_list->end(); ++it) { if (it->content_type == type && it->resource_identifier == identifier) { rules->push_back(content_settings::ProviderInterface::Rule( - it->embedded_pattern, it->top_level_pattern, it->setting)); + it->primary_pattern, it->secondary_pattern, it->setting)); } } } @@ -328,10 +347,10 @@ ListValue* ExtensionContentSettingsStore::GetSettingsForExtension( ContentSettingSpecList::const_iterator it; for (it = setting_spec_list->begin(); it != setting_spec_list->end(); ++it) { DictionaryValue* setting_dict = new DictionaryValue(); - setting_dict->SetString(keys::kEmbeddedPatternKey, - it->embedded_pattern.ToString()); - setting_dict->SetString(keys::kTopLevelPatternKey, - it->top_level_pattern.ToString()); + setting_dict->SetString(keys::kPrimaryPatternKey, + it->primary_pattern.ToString()); + setting_dict->SetString(keys::kSecondaryPatternKey, + it->secondary_pattern.ToString()); setting_dict->SetString( keys::kContentSettingsTypeKey, helpers::ContentSettingsTypeToString(it->content_type)); @@ -354,17 +373,17 @@ void ExtensionContentSettingsStore::SetExtensionContentSettingsFromList( continue; } DictionaryValue* dict = static_cast<DictionaryValue*>(*it); - std::string pattern_str; - dict->GetString(keys::kTopLevelPatternKey, &pattern_str); - ContentSettingsPattern pattern = - ContentSettingsPattern::LegacyFromString(pattern_str); - DCHECK(pattern.IsValid()); - - std::string embedded_pattern_str; - dict->GetString(keys::kEmbeddedPatternKey, &embedded_pattern_str); - ContentSettingsPattern embedded_pattern = - ContentSettingsPattern::LegacyFromString(embedded_pattern_str); - DCHECK(embedded_pattern.IsValid()); + std::string primary_pattern_str; + dict->GetString(keys::kPrimaryPatternKey, &primary_pattern_str); + ContentSettingsPattern primary_pattern = + ContentSettingsPattern::LegacyFromString(primary_pattern_str); + DCHECK(primary_pattern.IsValid()); + + std::string secondary_pattern_str; + dict->GetString(keys::kSecondaryPatternKey, &secondary_pattern_str); + ContentSettingsPattern secondary_pattern = + ContentSettingsPattern::LegacyFromString(secondary_pattern_str); + DCHECK(secondary_pattern.IsValid()); std::string content_settings_type_str; dict->GetString(keys::kContentSettingsTypeKey, &content_settings_type_str); @@ -383,8 +402,8 @@ void ExtensionContentSettingsStore::SetExtensionContentSettingsFromList( DCHECK(result); SetExtensionContentSetting(extension_id, - pattern, - embedded_pattern, + primary_pattern, + secondary_pattern, content_settings_type, resource_identifier, setting, @@ -403,13 +422,13 @@ void ExtensionContentSettingsStore::RemoveObserver(Observer* observer) { } ExtensionContentSettingsStore::ContentSettingSpec::ContentSettingSpec( - const ContentSettingsPattern& embedded_pattern, - const ContentSettingsPattern& top_level_pattern, + const ContentSettingsPattern& primary_pattern, + const ContentSettingsPattern& secondary_pattern, ContentSettingsType type, const content_settings::ResourceIdentifier& identifier, ContentSetting setting) - : embedded_pattern(embedded_pattern), - top_level_pattern(top_level_pattern), + : primary_pattern(primary_pattern), + secondary_pattern(secondary_pattern), content_type(type), resource_identifier(identifier), setting(setting) { diff --git a/chrome/browser/extensions/extension_content_settings_store.h b/chrome/browser/extensions/extension_content_settings_store.h index 67ec02c..1f090a6 100644 --- a/chrome/browser/extensions/extension_content_settings_store.h +++ b/chrome/browser/extensions/extension_content_settings_store.h @@ -118,14 +118,14 @@ class ExtensionContentSettingsStore { private: struct ExtensionEntry; struct ContentSettingSpec { - ContentSettingSpec(const ContentSettingsPattern& pattern, - const ContentSettingsPattern& embedder_pattern, + ContentSettingSpec(const ContentSettingsPattern& primary_pattern, + const ContentSettingsPattern& secondary_pattern, ContentSettingsType type, const content_settings::ResourceIdentifier& identifier, ContentSetting setting); - ContentSettingsPattern embedded_pattern; - ContentSettingsPattern top_level_pattern; + ContentSettingsPattern primary_pattern; + ContentSettingsPattern secondary_pattern; ContentSettingsType content_type; content_settings::ResourceIdentifier resource_identifier; ContentSetting setting; |