OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ |
6 #define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 class Extension; | 26 class Extension; |
27 class ExtensionRegistryObserver; | 27 class ExtensionRegistryObserver; |
28 | 28 |
29 // ExtensionRegistry holds sets of the installed extensions for a given | 29 // ExtensionRegistry holds sets of the installed extensions for a given |
30 // BrowserContext. An incognito browser context and its master browser context | 30 // BrowserContext. An incognito browser context and its master browser context |
31 // share a single registry. | 31 // share a single registry. |
32 class ExtensionRegistry : public KeyedService { | 32 class ExtensionRegistry : public KeyedService { |
33 public: | 33 public: |
34 // Flags to pass to GetExtensionById() to select which sets to look in. | 34 // Flags to pass to GetExtensionById() to select which sets to look in. |
35 enum IncludeFlag { | 35 enum IncludeFlag { |
36 NONE = 0, | 36 NONE = 0, |
37 ENABLED = 1 << 0, | 37 ENABLED = 1 << 0, |
38 DISABLED = 1 << 1, | 38 DISABLED = 1 << 1, |
39 TERMINATED = 1 << 2, | 39 TERMINATED = 1 << 2, |
40 BLACKLISTED = 1 << 3, | 40 BLACKLISTED = 1 << 3, |
41 EVERYTHING = (1 << 4) - 1, | 41 BLOCKED = 1 << 4, |
| 42 EVERYTHING = (1 << 5) - 1, |
42 }; | 43 }; |
43 | 44 |
44 explicit ExtensionRegistry(content::BrowserContext* browser_context); | 45 explicit ExtensionRegistry(content::BrowserContext* browser_context); |
45 ~ExtensionRegistry() override; | 46 ~ExtensionRegistry() override; |
46 | 47 |
47 // Returns the instance for the given |browser_context|. | 48 // Returns the instance for the given |browser_context|. |
48 static ExtensionRegistry* Get(content::BrowserContext* browser_context); | 49 static ExtensionRegistry* Get(content::BrowserContext* browser_context); |
49 | 50 |
50 content::BrowserContext* browser_context() const { return browser_context_; } | 51 content::BrowserContext* browser_context() const { return browser_context_; } |
51 | 52 |
52 // NOTE: These sets are *eventually* mutually exclusive, but an extension can | 53 // NOTE: These sets are *eventually* mutually exclusive, but an extension can |
53 // appear in two sets for short periods of time. | 54 // appear in two sets for short periods of time. |
54 const ExtensionSet& enabled_extensions() const { | 55 const ExtensionSet& enabled_extensions() const { |
55 return enabled_extensions_; | 56 return enabled_extensions_; |
56 } | 57 } |
57 const ExtensionSet& disabled_extensions() const { | 58 const ExtensionSet& disabled_extensions() const { |
58 return disabled_extensions_; | 59 return disabled_extensions_; |
59 } | 60 } |
60 const ExtensionSet& terminated_extensions() const { | 61 const ExtensionSet& terminated_extensions() const { |
61 return terminated_extensions_; | 62 return terminated_extensions_; |
62 } | 63 } |
63 const ExtensionSet& blacklisted_extensions() const { | 64 const ExtensionSet& blacklisted_extensions() const { |
64 return blacklisted_extensions_; | 65 return blacklisted_extensions_; |
65 } | 66 } |
| 67 const ExtensionSet& blocked_extensions() const { return blocked_extensions_; } |
66 | 68 |
67 // Returns a set of all installed, disabled, blacklisted, and terminated | 69 // Returns the set of all installed extensions, regardless of state (enabled, |
68 // extensions. | 70 // disabled, etc). Equivalent to GenerateInstalledExtensionSet(EVERYTHING). |
69 scoped_ptr<ExtensionSet> GenerateInstalledExtensionsSet() const; | 71 scoped_ptr<ExtensionSet> GenerateInstalledExtensionsSet() const; |
70 | 72 |
| 73 // Returns a set of all extensions in the subsets specified by |include_mask|. |
| 74 // * enabled_extensions() --> ExtensionRegistry::ENABLED |
| 75 // * disabled_extensions() --> ExtensionRegistry::DISABLED |
| 76 // * terminated_extensions() --> ExtensionRegistry::TERMINATED |
| 77 // * blacklisted_extensions() --> ExtensionRegistry::BLACKLISTED |
| 78 // * blocked_extensions() --> ExtensionRegistry::BLOCKED |
| 79 scoped_ptr<ExtensionSet> GenerateInstalledExtensionsSet( |
| 80 int include_mask) const; |
| 81 |
71 // The usual observer interface. | 82 // The usual observer interface. |
72 void AddObserver(ExtensionRegistryObserver* observer); | 83 void AddObserver(ExtensionRegistryObserver* observer); |
73 void RemoveObserver(ExtensionRegistryObserver* observer); | 84 void RemoveObserver(ExtensionRegistryObserver* observer); |
74 | 85 |
75 // Invokes the observer method OnExtensionLoaded(). The extension must be | 86 // Invokes the observer method OnExtensionLoaded(). The extension must be |
76 // enabled at the time of the call. | 87 // enabled at the time of the call. |
77 void TriggerOnLoaded(const Extension* extension); | 88 void TriggerOnLoaded(const Extension* extension); |
78 | 89 |
79 // Invokes the observer method OnExtensionUnloaded(). The extension must not | 90 // Invokes the observer method OnExtensionUnloaded(). The extension must not |
80 // be enabled at the time of the call. | 91 // be enabled at the time of the call. |
(...skipping 19 matching lines...) Expand all Loading... |
100 | 111 |
101 // Invokes the observer method OnExtensionUninstalled(). The extension must | 112 // Invokes the observer method OnExtensionUninstalled(). The extension must |
102 // not be any installed extension with |extension|'s ID. | 113 // not be any installed extension with |extension|'s ID. |
103 void TriggerOnUninstalled(const Extension* extension, UninstallReason reason); | 114 void TriggerOnUninstalled(const Extension* extension, UninstallReason reason); |
104 | 115 |
105 // Find an extension by ID using |include_mask| to pick the sets to search: | 116 // Find an extension by ID using |include_mask| to pick the sets to search: |
106 // * enabled_extensions() --> ExtensionRegistry::ENABLED | 117 // * enabled_extensions() --> ExtensionRegistry::ENABLED |
107 // * disabled_extensions() --> ExtensionRegistry::DISABLED | 118 // * disabled_extensions() --> ExtensionRegistry::DISABLED |
108 // * terminated_extensions() --> ExtensionRegistry::TERMINATED | 119 // * terminated_extensions() --> ExtensionRegistry::TERMINATED |
109 // * blacklisted_extensions() --> ExtensionRegistry::BLACKLISTED | 120 // * blacklisted_extensions() --> ExtensionRegistry::BLACKLISTED |
| 121 // * blocked_extensions() --> ExtensionRegistry::BLOCKED |
110 // Returns NULL if the extension is not found in the selected sets. | 122 // Returns NULL if the extension is not found in the selected sets. |
111 const Extension* GetExtensionById(const std::string& id, | 123 const Extension* GetExtensionById(const std::string& id, |
112 int include_mask) const; | 124 int include_mask) const; |
113 | 125 |
114 // Adds the specified extension to the enabled set. The registry becomes an | 126 // Adds the specified extension to the enabled set. The registry becomes an |
115 // owner. Any previous extension with the same ID is removed. | 127 // owner. Any previous extension with the same ID is removed. |
116 // Returns true if there is no previous extension. | 128 // Returns true if there is no previous extension. |
117 // NOTE: You probably want to use ExtensionService instead of calling this | 129 // NOTE: You probably want to use ExtensionService instead of calling this |
118 // method directly. | 130 // method directly. |
119 bool AddEnabled(const scoped_refptr<const Extension>& extension); | 131 bool AddEnabled(const scoped_refptr<const Extension>& extension); |
120 | 132 |
121 // Removes the specified extension from the enabled set. | 133 // Removes the specified extension from the enabled set. |
122 // Returns true if the set contained the specified extension. | 134 // Returns true if the set contained the specified extension. |
123 // NOTE: You probably want to use ExtensionService instead of calling this | 135 // NOTE: You probably want to use ExtensionService instead of calling this |
124 // method directly. | 136 // method directly. |
125 bool RemoveEnabled(const std::string& id); | 137 bool RemoveEnabled(const std::string& id); |
126 | 138 |
127 // As above, but for the disabled set. | 139 // As above, but for the disabled set. |
128 bool AddDisabled(const scoped_refptr<const Extension>& extension); | 140 bool AddDisabled(const scoped_refptr<const Extension>& extension); |
129 bool RemoveDisabled(const std::string& id); | 141 bool RemoveDisabled(const std::string& id); |
130 | 142 |
131 // As above, but for the terminated set. | 143 // As above, but for the terminated set. |
132 bool AddTerminated(const scoped_refptr<const Extension>& extension); | 144 bool AddTerminated(const scoped_refptr<const Extension>& extension); |
133 bool RemoveTerminated(const std::string& id); | 145 bool RemoveTerminated(const std::string& id); |
134 | 146 |
135 // As above, but for the blacklisted set. | 147 // As above, but for the blacklisted set. |
136 bool AddBlacklisted(const scoped_refptr<const Extension>& extension); | 148 bool AddBlacklisted(const scoped_refptr<const Extension>& extension); |
137 bool RemoveBlacklisted(const std::string& id); | 149 bool RemoveBlacklisted(const std::string& id); |
138 | 150 |
| 151 // As above, but for the blocked set. |
| 152 bool AddBlocked(const scoped_refptr<const Extension>& extension); |
| 153 bool RemoveBlocked(const std::string& id); |
| 154 |
139 // Removes all extensions from all sets. | 155 // Removes all extensions from all sets. |
140 void ClearAll(); | 156 void ClearAll(); |
141 | 157 |
142 // Sets a callback to run when the disabled extension set is modified. | 158 // Sets a callback to run when the disabled extension set is modified. |
143 // TODO(jamescook): This is too specific for a generic registry; find some | 159 // TODO(jamescook): This is too specific for a generic registry; find some |
144 // other way to do this. | 160 // other way to do this. |
145 void SetDisabledModificationCallback( | 161 void SetDisabledModificationCallback( |
146 const ExtensionSet::ModificationCallback& callback); | 162 const ExtensionSet::ModificationCallback& callback); |
147 | 163 |
148 // KeyedService implementation: | 164 // KeyedService implementation: |
149 void Shutdown() override; | 165 void Shutdown() override; |
150 | 166 |
151 private: | 167 private: |
152 // Extensions that are installed, enabled and not terminated. | 168 // Extensions that are installed, enabled and not terminated. |
153 ExtensionSet enabled_extensions_; | 169 ExtensionSet enabled_extensions_; |
154 | 170 |
155 // Extensions that are installed and disabled. | 171 // Extensions that are installed and disabled. |
156 ExtensionSet disabled_extensions_; | 172 ExtensionSet disabled_extensions_; |
157 | 173 |
158 // Extensions that are installed and terminated. | 174 // Extensions that are installed and terminated. |
159 ExtensionSet terminated_extensions_; | 175 ExtensionSet terminated_extensions_; |
160 | 176 |
161 // Extensions that are installed and blacklisted. Generally these shouldn't be | 177 // Extensions that are installed and blacklisted. Generally these shouldn't be |
162 // considered as installed by the extension platform: we only keep them around | 178 // considered as installed by the extension platform: we only keep them around |
163 // so that if extensions are blacklisted by mistake they can easily be | 179 // so that if extensions are blacklisted by mistake they can easily be |
164 // un-blacklisted. | 180 // un-blacklisted. |
165 ExtensionSet blacklisted_extensions_; | 181 ExtensionSet blacklisted_extensions_; |
166 | 182 |
| 183 // Extensions that are installed and blocked. Will never be loaded. |
| 184 ExtensionSet blocked_extensions_; |
| 185 |
167 ObserverList<ExtensionRegistryObserver> observers_; | 186 ObserverList<ExtensionRegistryObserver> observers_; |
168 | 187 |
169 content::BrowserContext* const browser_context_; | 188 content::BrowserContext* const browser_context_; |
170 | 189 |
171 DISALLOW_COPY_AND_ASSIGN(ExtensionRegistry); | 190 DISALLOW_COPY_AND_ASSIGN(ExtensionRegistry); |
172 }; | 191 }; |
173 | 192 |
174 } // namespace extensions | 193 } // namespace extensions |
175 | 194 |
176 #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ | 195 #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ |
OLD | NEW |