OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTENT_SETTINGS_STORE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_STORE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTENT_SETTINGS_STORE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_STORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/tuple.h" | 15 #include "base/tuple.h" |
16 #include "chrome/browser/content_settings/content_settings_provider.h" | 16 #include "chrome/browser/content_settings/content_settings_provider.h" |
17 #include "chrome/browser/extensions/extension_prefs_scope.h" | 17 #include "chrome/browser/extensions/extension_prefs_scope.h" |
18 #include "chrome/common/content_settings.h" | 18 #include "chrome/common/content_settings.h" |
19 #include "chrome/common/content_settings_pattern.h" | 19 #include "chrome/common/content_settings_pattern.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class ListValue; | 23 class ListValue; |
24 } | 24 } |
25 | 25 |
26 namespace content_settings { | 26 namespace content_settings { |
27 class OriginIdentifierValueMap; | 27 class OriginIdentifierValueMap; |
28 class RuleIterator; | 28 class RuleIterator; |
29 } | 29 } |
30 | 30 |
| 31 namespace extensions { |
| 32 |
31 // This class is the backend for extension-defined content settings. It is used | 33 // This class is the backend for extension-defined content settings. It is used |
32 // by the content_settings::ExtensionProvider to integrate its settings into the | 34 // by the content_settings::ExtensionProvider to integrate its settings into the |
33 // HostContentSettingsMap and by the content settings extension API to provide | 35 // HostContentSettingsMap and by the content settings extension API to provide |
34 // extensions with access to content settings. | 36 // extensions with access to content settings. |
35 class ExtensionContentSettingsStore | 37 class ContentSettingsStore |
36 : public base::RefCountedThreadSafe<ExtensionContentSettingsStore> { | 38 : public base::RefCountedThreadSafe<ContentSettingsStore> { |
37 public: | 39 public: |
38 class Observer { | 40 class Observer { |
39 public: | 41 public: |
40 virtual ~Observer() {} | 42 virtual ~Observer() {} |
41 | 43 |
42 // Called when a content setting changes in the | 44 // Called when a content setting changes in the |
43 // ExtensionContentSettingsStore. | 45 // ContentSettingsStore. |
44 virtual void OnContentSettingChanged( | 46 virtual void OnContentSettingChanged( |
45 const std::string& extension_id, | 47 const std::string& extension_id, |
46 bool incognito) = 0; | 48 bool incognito) = 0; |
47 }; | 49 }; |
48 | 50 |
49 ExtensionContentSettingsStore(); | 51 ContentSettingsStore(); |
50 | 52 |
51 // ////////////////////////////////////////////////////////////////////////// | 53 // ////////////////////////////////////////////////////////////////////////// |
52 | 54 |
53 content_settings::RuleIterator* GetRuleIterator( | 55 content_settings::RuleIterator* GetRuleIterator( |
54 ContentSettingsType type, | 56 ContentSettingsType type, |
55 const content_settings::ResourceIdentifier& identifier, | 57 const content_settings::ResourceIdentifier& identifier, |
56 bool incognito) const; | 58 bool incognito) const; |
57 | 59 |
58 // Sets the content |setting| for |pattern| of extension |ext_id|. The | 60 // Sets the content |setting| for |pattern| of extension |ext_id|. The |
59 // |incognito| flag allow to set whether the provided setting is for | 61 // |incognito| flag allow to set whether the provided setting is for |
(...skipping 14 matching lines...) Expand all Loading... |
74 ExtensionPrefsScope scope); | 76 ExtensionPrefsScope scope); |
75 | 77 |
76 // Serializes all content settings set by the extension with ID |extension_id| | 78 // Serializes all content settings set by the extension with ID |extension_id| |
77 // and returns them as a ListValue. The caller takes ownership of the returned | 79 // and returns them as a ListValue. The caller takes ownership of the returned |
78 // value. | 80 // value. |
79 base::ListValue* GetSettingsForExtension(const std::string& extension_id, | 81 base::ListValue* GetSettingsForExtension(const std::string& extension_id, |
80 ExtensionPrefsScope scope) const; | 82 ExtensionPrefsScope scope) const; |
81 | 83 |
82 // Deserializes content settings rules from |list| and applies them as set by | 84 // Deserializes content settings rules from |list| and applies them as set by |
83 // the extension with ID |extension_id|. | 85 // the extension with ID |extension_id|. |
84 void SetExtensionContentSettingsFromList(const std::string& extension_id, | 86 void SetExtensionContentSettingFromList(const std::string& extension_id, |
85 const base::ListValue* list, | 87 const base::ListValue* list, |
86 ExtensionPrefsScope scope); | 88 ExtensionPrefsScope scope); |
87 | 89 |
88 // ////////////////////////////////////////////////////////////////////////// | 90 // ////////////////////////////////////////////////////////////////////////// |
89 | 91 |
90 // Registers the time when an extension |ext_id| is installed. | 92 // Registers the time when an extension |ext_id| is installed. |
91 void RegisterExtension(const std::string& ext_id, | 93 void RegisterExtension(const std::string& ext_id, |
92 const base::Time& install_time, | 94 const base::Time& install_time, |
93 bool is_enabled); | 95 bool is_enabled); |
94 | 96 |
95 // Deletes all entries related to extension |ext_id|. | 97 // Deletes all entries related to extension |ext_id|. |
96 void UnregisterExtension(const std::string& ext_id); | 98 void UnregisterExtension(const std::string& ext_id); |
97 | 99 |
98 // Hides or makes the extension content settings of the specified extension | 100 // Hides or makes the extension content settings of the specified extension |
99 // visible. | 101 // visible. |
100 void SetExtensionState(const std::string& ext_id, bool is_enabled); | 102 void SetExtensionState(const std::string& ext_id, bool is_enabled); |
101 | 103 |
102 // Adds |observer|. This method should only be called on the UI thread. | 104 // Adds |observer|. This method should only be called on the UI thread. |
103 void AddObserver(Observer* observer); | 105 void AddObserver(Observer* observer); |
104 | 106 |
105 // Remove |observer|. This method should only be called on the UI thread. | 107 // Remove |observer|. This method should only be called on the UI thread. |
106 void RemoveObserver(Observer* observer); | 108 void RemoveObserver(Observer* observer); |
107 | 109 |
108 private: | 110 private: |
109 friend class base::RefCountedThreadSafe<ExtensionContentSettingsStore>; | 111 friend class base::RefCountedThreadSafe<ContentSettingsStore>; |
110 | 112 |
111 struct ExtensionEntry; | 113 struct ExtensionEntry; |
112 | 114 |
113 typedef std::multimap<base::Time, ExtensionEntry*> ExtensionEntryMap; | 115 typedef std::multimap<base::Time, ExtensionEntry*> ExtensionEntryMap; |
114 | 116 |
115 virtual ~ExtensionContentSettingsStore(); | 117 virtual ~ContentSettingsStore(); |
116 | 118 |
117 content_settings::OriginIdentifierValueMap* GetValueMap( | 119 content_settings::OriginIdentifierValueMap* GetValueMap( |
118 const std::string& ext_id, | 120 const std::string& ext_id, |
119 ExtensionPrefsScope scope); | 121 ExtensionPrefsScope scope); |
120 | 122 |
121 const content_settings::OriginIdentifierValueMap* GetValueMap( | 123 const content_settings::OriginIdentifierValueMap* GetValueMap( |
122 const std::string& ext_id, | 124 const std::string& ext_id, |
123 ExtensionPrefsScope scope) const; | 125 ExtensionPrefsScope scope) const; |
124 | 126 |
125 void NotifyOfContentSettingChanged(const std::string& extension_id, | 127 void NotifyOfContentSettingChanged(const std::string& extension_id, |
126 bool incognito); | 128 bool incognito); |
127 | 129 |
128 bool OnCorrectThread(); | 130 bool OnCorrectThread(); |
129 | 131 |
130 ExtensionEntryMap::iterator FindEntry(const std::string& ext_id); | 132 ExtensionEntryMap::iterator FindEntry(const std::string& ext_id); |
131 ExtensionEntryMap::const_iterator FindEntry(const std::string& ext_id) const; | 133 ExtensionEntryMap::const_iterator FindEntry(const std::string& ext_id) const; |
132 | 134 |
133 ExtensionEntryMap entries_; | 135 ExtensionEntryMap entries_; |
134 | 136 |
135 ObserverList<Observer, false> observers_; | 137 ObserverList<Observer, false> observers_; |
136 | 138 |
137 mutable base::Lock lock_; | 139 mutable base::Lock lock_; |
138 | 140 |
139 DISALLOW_COPY_AND_ASSIGN(ExtensionContentSettingsStore); | 141 DISALLOW_COPY_AND_ASSIGN(ContentSettingsStore); |
140 }; | 142 }; |
141 | 143 |
142 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTENT_SETTINGS_STORE_H_ | 144 } // namespace extensions |
| 145 |
| 146 #endif // CHROME_BROWSER_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_STORE
_H_ |
OLD | NEW |