Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: chrome/browser/host_content_settings_map.h

Issue 2878075: Introduce a resource identifier for content settings. (Closed)
Patch Set: updates Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/host_content_settings_map.h
diff --git a/chrome/browser/host_content_settings_map.h b/chrome/browser/host_content_settings_map.h
index 23481387b83a2ea36d525aa212278d92e9790267..0bf8044753b47941fb14a0a9acd4755b70d5f5bd 100644
--- a/chrome/browser/host_content_settings_map.h
+++ b/chrome/browser/host_content_settings_map.h
@@ -73,15 +73,13 @@ class HostContentSettingsMap
// for each pattern.
class ContentSettingsDetails {
public:
- // Update the setting that matches this pattern/content type.
- ContentSettingsDetails(const Pattern& pattern, ContentSettingsType type)
- : pattern_(pattern), type_(type) {}
-
- // No pattern is specified. Update all settings for this content type.
- explicit ContentSettingsDetails(ContentSettingsType type) : type_(type) {}
-
- // No content type or pattern is specified. Update all settings.
- ContentSettingsDetails() : type_(CONTENT_SETTINGS_TYPE_DEFAULT) {}
+ // Update the setting that matches this pattern/content type/resource.
+ ContentSettingsDetails(const Pattern& pattern,
+ ContentSettingsType type,
+ const std::string& resource_identifier)
+ : pattern_(pattern),
+ type_(type),
+ resource_identifier_(resource_identifier) {}
// The pattern whose settings have changed.
const Pattern& pattern() const { return pattern_; }
@@ -92,6 +90,11 @@ class HostContentSettingsMap
// The type of the pattern whose settings have changed.
ContentSettingsType type() const { return type_; }
+ // The resource identifier for the settings type that has changed.
+ const std::string& resource_identifier() const {
+ return resource_identifier_;
+ }
+
// True if all types should be updated. If update_all() is false, this will
// be false as well (although the reverse does not hold true).
bool update_all_types() const {
@@ -101,6 +104,7 @@ class HostContentSettingsMap
private:
Pattern pattern_;
ContentSettingsType type_;
+ std::string resource_identifier_;
};
@@ -119,25 +123,52 @@ class HostContentSettingsMap
ContentSettingsType content_type) const;
// Returns a single ContentSetting which applies to a given URL. Note that
- // certain internal schemes are whitelisted.
+ // certain internal schemes are whitelisted. For ContentSettingsTypes that
+ // require an resource identifier to be specified, the |resource_identifier|
+ // must be non-empty.
//
// This may be called on any thread.
- ContentSetting GetContentSetting(const GURL& url,
- ContentSettingsType content_type) const;
-
- // Returns all ContentSettings which apply to a given URL.
+ ContentSetting GetContentSetting(
+ const GURL& url,
+ ContentSettingsType content_type,
+ const std::string& resource_identifier) const;
+
+ // Returns a single ContentSetting which applies to a given URL or
+ // CONTENT_SETTING_DEFAULT, if no exception applies. Note that certain
+ // internal schemes are whitelisted. For ContentSettingsTypes that require an
+ // resource identifier to be specified, the |resource_identifier| must be
+ // non-empty.
+ //
+ // This may be called on any thread.
+ ContentSetting GetNonDefaultContentSetting(
+ const GURL& url,
+ ContentSettingsType content_type,
+ const std::string& resource_identifier) const;
+
+ // Returns all ContentSettings which apply to a given URL. For content
+ // setting types that require an additional resource identifier, the default
+ // content setting is returned.
//
// This may be called on any thread.
ContentSettings GetContentSettings(const GURL& url) const;
+ // Returns all non-default ContentSettings which apply to a given URL. For
+ // content setting types that require an additional resource identifier,
+ // CONTENT_SETTING_DEFAULT is returned.
+ //
+ // This may be called on any thread.
+ ContentSettings GetNonDefaultContentSettings(const GURL& url) const;
+
// For a given content type, returns all patterns with a non-default setting,
// mapped to their actual settings, in lexicographical order. |settings|
// must be a non-NULL outparam. If this map was created for the
// off-the-record profile, it will only return those settings differing from
- // the main map.
+ // the main map. For ContentSettingsTypes that require an resource identifier
+ // to be specified, the |resource_identifier| must be non-empty.
//
// This may be called on any thread.
void GetSettingsForOneType(ContentSettingsType content_type,
+ const std::string& resource_identifier,
SettingsForOneType* settings) const;
// Sets the default setting for a particular content type. This method must
@@ -148,19 +179,26 @@ class HostContentSettingsMap
ContentSetting setting);
// Sets the blocking setting for a particular pattern and content type.
- // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting for
- // that type to be used when loading pages matching this pattern.
+ // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting
+ // for that type to be used when loading pages matching this pattern. For
+ // ContentSettingsTypes that require an resource identifier to be specified,
+ // the |resource_identifier| must be non-empty.
//
// This should only be called on the UI thread.
void SetContentSetting(const Pattern& pattern,
ContentSettingsType content_type,
+ const std::string& resource_identifier,
ContentSetting setting);
// Convenience method to add a content setting for a given URL, making sure
- // that there is no setting overriding it.
+ // that there is no setting overriding it. For ContentSettingsTypes that
+ // require an resource identifier to be specified, the |resource_identifier|
+ // must be non-empty.
+ //
// This should only be called on the UI thread.
void AddExceptionForURL(const GURL& url,
ContentSettingsType content_type,
+ const std::string& resource_identifier,
ContentSetting setting);
// Clears all host-specific settings for one content type.
@@ -168,6 +206,10 @@ class HostContentSettingsMap
// This should only be called on the UI thread.
void ClearSettingsForOneType(ContentSettingsType content_type);
+ // Whether the |content_type| requires an additional resource identifier for
+ // accessing content settings.
+ bool RequiresResourceIdentifier(ContentSettingsType content_type) const;
+
// This setting trumps any host-specific settings.
bool BlockThirdPartyCookies() const { return block_third_party_cookies_; }
@@ -193,29 +235,32 @@ class HostContentSettingsMap
private:
friend class base::RefCountedThreadSafe<HostContentSettingsMap>;
- typedef std::map<std::string, ContentSettings> HostContentSettings;
+ typedef std::pair<ContentSettingsType, std::string>
+ ContentSettingsTypeResourceIdentifierPair;
+ typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting>
+ ResourceContentSettings;
- // The names of the ContentSettingsType values, for use with dictionary prefs.
- static const wchar_t* kTypeNames[CONTENT_SETTINGS_NUM_TYPES];
-
- // The default setting for each content type.
- static const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES];
+ struct ExtendedContentSettings {
+ ContentSettings content_settings;
+ ResourceContentSettings content_settings_for_resources;
+ };
- // Returns true if we should allow all content types for this URL. This is
- // true for various internal objects like chrome:// URLs, so UI and other
- // things users think of as "not webpages" don't break.
- static bool ShouldAllowAllContent(const GURL& url);
+ typedef std::map<std::string, ExtendedContentSettings> HostContentSettings;
// Sets the fields of |settings| based on the values in |dictionary|.
void GetSettingsFromDictionary(const DictionaryValue* dictionary,
ContentSettings* settings);
+ // Populates |settings| based on the values in |dictionary|.
+ void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary,
+ ResourceContentSettings* settings);
+
// Forces the default settings to be explicitly set instead of themselves
// being CONTENT_SETTING_DEFAULT.
void ForceDefaultsToBeExplicit();
// Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT.
- bool AllDefault(const ContentSettings& settings) const;
+ bool AllDefault(const ExtendedContentSettings& settings) const;
// Reads the default settings from the prefereces service. If |overwrite| is
// true and the preference is missing, the local copy will be cleared as well.
« no previous file with comments | « chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc ('k') | chrome/browser/host_content_settings_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698