• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Interface for objects providing content setting rules.
6 
7 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
8 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
9 #pragma once
10 
11 #define NO_RESOURCE_IDENTIFIER ""
12 
13 #include <string>
14 #include <vector>
15 
16 #include "chrome/browser/content_settings/content_settings_pattern.h"
17 #include "chrome/common/content_settings.h"
18 
19 class GURL;
20 
21 namespace content_settings {
22 
23 class DefaultProviderInterface {
24  public:
~DefaultProviderInterface()25   virtual ~DefaultProviderInterface() {}
26 
27   // Returns the default content setting this provider has for the given
28   // |content_type|, or CONTENT_SETTING_DEFAULT if nothing be provided for this
29   // type.
30   virtual ContentSetting ProvideDefaultSetting(
31       ContentSettingsType content_type) const = 0;
32 
33   // Notifies the provider that the host content settings map would like to
34   // update the default setting for the given |content_type|. The provider may
35   // ignore this.
36   virtual void UpdateDefaultSetting(ContentSettingsType content_type,
37                                     ContentSetting setting) = 0;
38 
39   // Resets the state of the provider to the default.
40   virtual void ResetToDefaults() = 0;
41 
42   // True if the default setting for the |content_type| is policy managed, i.e.,
43   // there shouldn't be any UI shown to modify this setting.
44   virtual bool DefaultSettingIsManaged(
45       ContentSettingsType content_type) const = 0;
46 };
47 
48 class ProviderInterface {
49  public:
50   typedef std::string ResourceIdentifier;
51 
52   struct Rule {
RuleRule53     Rule() {}
RuleRule54     Rule(const ContentSettingsPattern& requesting_pattern,
55          const ContentSettingsPattern& embedding_pattern,
56          ContentSetting setting)
57       : requesting_url_pattern(requesting_pattern),
58         embedding_url_pattern(embedding_pattern),
59         content_setting(setting) {}
60 
61     ContentSettingsPattern requesting_url_pattern;
62     ContentSettingsPattern embedding_url_pattern;
63     ContentSetting content_setting;
64   };
65 
66   typedef std::vector<Rule> Rules;
67 
~ProviderInterface()68   virtual ~ProviderInterface() {}
69 
70   // Returns true whether the content settings provider manages the
71   // |content_type|.
72   virtual bool ContentSettingsTypeIsManaged(
73       ContentSettingsType content_type) = 0;
74 
75   // Returns a single ContentSetting which applies to a given |requesting_url|,
76   // |embedding_url| pair or CONTENT_SETTING_DEFAULT, if no rule applies. For
77   // ContentSettingsTypes that require a resource identifier to be specified,
78   // the |resource_identifier| must be non-empty.
79   //
80   // This may be called on any thread.
81   virtual ContentSetting GetContentSetting(
82       const GURL& requesting_url,
83       const GURL& embedding_url,
84       ContentSettingsType content_type,
85       const ResourceIdentifier& resource_identifier) const = 0;
86 
87   // Sets the content setting for a particular |requesting_pattern|,
88   // |embedding_pattern|, |content_type| tuple. For ContentSettingsTypes that
89   // require a resource identifier to be specified, the |resource_identifier|
90   // must be non-empty.
91   //
92   // This should only be called on the UI thread.
93   virtual void SetContentSetting(
94       const ContentSettingsPattern& requesting_url_pattern,
95       const ContentSettingsPattern& embedding_url_pattern,
96       ContentSettingsType content_type,
97       const ResourceIdentifier& resource_identifier,
98       ContentSetting content_setting) = 0;
99 
100   // For a given content type, returns all content setting rules with a
101   // non-default setting, mapped to their actual settings.
102   // |content_settings_rules| must be non-NULL. If this provider was created for
103   // the incognito profile, it will only return those settings differing
104   // from the corresponding regular provider. For ContentSettingsTypes that
105   // require a resource identifier to be specified, the |resource_identifier|
106   // must be non-empty.
107   //
108   // This may be called on any thread.
109   virtual void GetAllContentSettingsRules(
110       ContentSettingsType content_type,
111       const ResourceIdentifier& resource_identifier,
112       Rules* content_setting_rules) const = 0;
113 
114   // Resets all content settings for the given |content_type| to
115   // CONTENT_SETTING_DEFAULT. For content types that require a resource
116   // identifier all content settings for any resource identifieres of the given
117   // |content_type| will be reset to CONTENT_SETTING_DEFAULT.
118   //
119   // This should only be called on the UI thread.
120   virtual void ClearAllContentSettingsRules(
121       ContentSettingsType content_type) = 0;
122 
123   // Resets all content settings to CONTENT_SETTINGS_DEFAULT.
124   //
125   // This should only be called on the UI thread.
126   virtual void ResetToDefaults() = 0;
127 };
128 
129 }  // namespace content_settings
130 
131 #endif  // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
132