blob: 234407ccbac6b5e3d7bb2ccbd4fd017509e63419 [file] [log] [blame]
[email protected]eb75f7b2012-01-04 09:07:281// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7713d632008-12-02 07:52:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5b1a0e22009-05-26 19:00:585#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_
6#define CHROME_COMMON_EXTENSIONS_EXTENSION_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]7713d632008-12-02 07:52:338
[email protected]300cc58db2009-08-19 20:45:149#include <map>
[email protected]facd7a7652009-06-05 23:15:0210#include <set>
[email protected]7713d632008-12-02 07:52:3311#include <string>
12#include <vector>
13
[email protected]6014d672008-12-05 00:38:2514#include "base/file_path.h"
[email protected]19118d52010-07-26 22:13:4215#include "base/gtest_prod_util.h"
[email protected]8f270be2011-12-21 21:15:2216#include "base/hash_tables.h"
[email protected]b6b805e92011-04-16 09:24:1417#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1518#include "base/memory/ref_counted.h"
19#include "base/memory/scoped_ptr.h"
[email protected]902fd7b2011-07-27 18:42:3120#include "base/synchronization/lock.h"
[email protected]d83a5602010-09-16 00:22:4821#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4822#include "chrome/common/extensions/extension_icon_set.h"
[email protected]0d3e4a22011-06-23 19:02:5223#include "chrome/common/extensions/extension_permission_set.h"
[email protected]953620b2011-12-04 00:55:3224#include "chrome/common/extensions/manifest.h"
[email protected]42b6f0f82009-09-18 21:07:3925#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4926#include "chrome/common/extensions/url_pattern.h"
[email protected]cced75a2011-05-20 08:31:1227#include "chrome/common/extensions/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5928#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5529#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3830#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5931
[email protected]942690b132010-05-11 06:42:1432class ExtensionAction;
33class ExtensionResource;
[email protected]b6b805e92011-04-16 09:24:1434class FileBrowserHandler;
[email protected]12802702010-07-09 19:43:0935class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2836class Version;
[email protected]942690b132010-05-11 06:42:1437
[email protected]f3a1c642011-07-12 19:15:0338namespace base {
39class DictionaryValue;
40class ListValue;
41}
42
[email protected]f0cc7242011-12-13 04:26:1743namespace webkit_glue {
44struct WebIntentServiceData;
45}
46
[email protected]f0755532010-06-22 07:27:2547// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4148class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3349 public:
[email protected]d3cfa482009-10-17 13:54:5750 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1751 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1452 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]b24d8312009-08-27 06:47:4653
[email protected]631cf822009-05-15 07:01:2554 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2355 // NOTE: These values are stored as integers in the preferences and used
56 // in histograms so don't remove or reorder existing items. Just append
57 // to the end.
[email protected]631cf822009-05-15 07:01:2558 enum Location {
59 INVALID,
[email protected]25b34332009-06-05 21:53:1960 INTERNAL, // A crx file from the internal Extensions directory.
61 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
62 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
63 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3464 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3265 COMPONENT, // An integral component of Chrome itself, which
66 // happens to be implemented as an extension. We don't
67 // show these in the management UI.
[email protected]4d2913e32010-11-30 00:28:5568 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via
69 // prefs), installed from an update URL.
70 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via
71 // admin policies), installed from an update URL.
[email protected]04cb7542010-10-25 10:50:0672
73 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1974 };
75
76 enum State {
[email protected]0c6da502009-08-14 22:32:3977 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1978 ENABLED,
[email protected]79c833b52011-04-05 18:31:0179 // An external extension that the user uninstalled. We should not reinstall
80 // such extensions on startup.
81 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:3982 NUM_STATES
[email protected]631cf822009-05-15 07:01:2583 };
[email protected]7713d632008-12-02 07:52:3384
[email protected]fbcc40302009-06-12 20:45:4585 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3786 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4587 DOWNGRADE,
88 REINSTALL,
89 UPGRADE,
90 NEW_INSTALL
91 };
92
[email protected]7fa19f82010-12-21 19:40:0893 // Do not change the order of entries or remove entries in this list
94 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
95 enum Type {
[email protected]9b217652010-10-08 22:04:2396 TYPE_UNKNOWN = 0,
97 TYPE_EXTENSION,
98 TYPE_THEME,
99 TYPE_USER_SCRIPT,
100 TYPE_HOSTED_APP,
[email protected]7d3ed2f2011-11-07 23:33:19101 TYPE_PACKAGED_APP,
102 TYPE_PLATFORM_APP
[email protected]9b217652010-10-08 22:04:23103 };
104
[email protected]3bdba0d2011-08-23 07:17:30105 enum SyncType {
106 SYNC_TYPE_NONE = 0,
107 SYNC_TYPE_EXTENSION,
108 SYNC_TYPE_APP
109 };
110
[email protected]92888082010-10-18 19:24:57111 // An NPAPI plugin included in the extension.
112 struct PluginInfo {
113 FilePath path; // Path to the plugin.
114 bool is_public; // False if only this extension can load this plugin.
115 };
116
[email protected]65378f52011-04-08 02:31:23117 // An NaCl module included in the extension.
118 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42119 GURL url;
[email protected]65378f52011-04-08 02:31:23120 std::string mime_type;
121 };
122
[email protected]b0820372011-06-03 07:05:27123 enum InputComponentType {
[email protected]d45f7512011-06-21 21:18:27124 INPUT_COMPONENT_TYPE_NONE = -1,
125 INPUT_COMPONENT_TYPE_IME,
[email protected]b0820372011-06-03 07:05:27126 INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD,
127 INPUT_COMPONENT_TYPE_COUNT
128 };
129
130 struct InputComponentInfo {
131 // Define out of line constructor/destructor to please Clang.
132 InputComponentInfo();
133 ~InputComponentInfo();
134
135 std::string name;
136 InputComponentType type;
137 std::string id;
138 std::string description;
139 std::string language;
140 std::set<std::string> layouts;
141 std::string shortcut_keycode;
142 bool shortcut_alt;
143 bool shortcut_ctrl;
144 bool shortcut_shift;
145 };
146
[email protected]f5532472012-02-23 13:00:55147 class ExtensionKeybinding {
148 public:
149 // Define out of line constructor/destructor to please Clang.
150 ExtensionKeybinding();
151 ~ExtensionKeybinding();
152
153 // Parse the key binding.
154 bool Parse(base::DictionaryValue* command,
155 const std::string& command_name,
156 int index,
157 string16* error);
158
159 // Accessors:
160 const std::string& command_name() const { return command_name_; }
161 const ui::Accelerator& accelerator() const { return accelerator_; }
162 const std::string& description() const { return description_; }
163
164 private:
165 std::string command_name_;
166 ui::Accelerator accelerator_;
167 std::string description_;
168 };
169
[email protected]a4a38c12010-12-23 16:43:56170 struct TtsVoice {
[email protected]77a3ecac2011-07-07 05:56:33171 // Define out of line constructor/destructor to please Clang.
172 TtsVoice();
173 ~TtsVoice();
174
[email protected]a4a38c12010-12-23 16:43:56175 std::string voice_name;
[email protected]c63f2b72011-07-07 05:25:00176 std::string lang;
[email protected]a4a38c12010-12-23 16:43:56177 std::string gender;
[email protected]c63f2b72011-07-07 05:25:00178 std::set<std::string> event_types;
[email protected]a4a38c12010-12-23 16:43:56179 };
180
[email protected]83048a22011-03-29 00:14:13181 enum InitFromValueFlags {
182 NO_FLAGS = 0,
183
184 // Usually, the id of an extension is generated by the "key" property of
185 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
186 // generated based on the path.
187 REQUIRE_KEY = 1 << 0,
188
[email protected]3f53dfe2011-11-30 01:18:29189 // Requires the extension to have an up-to-date manifest version.
190 // Typically, we'll support multiple manifest versions during a version
191 // transition. This flag signals that we want to require the most modern
192 // manifest version that Chrome understands.
193 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
194
[email protected]83048a22011-03-29 00:14:13195 // |STRICT_ERROR_CHECKS| enables extra error checking, such as
196 // checks that URL patterns do not contain ports. This error
197 // checking may find an error that a previous version of
198 // Chrome did not flag. To avoid errors in installed extensions
199 // when Chrome is upgraded, strict error checking is only enabled
200 // when loading extensions as a developer would (such as loading
201 // an unpacked extension), or when loading an extension that is
202 // tied to a specific version of Chrome (such as a component
203 // extension). Most callers will set the |STRICT_ERROR_CHECKS| bit when
204 // Extension::ShouldDoStrictErrorChecking(location) returns true.
[email protected]3f53dfe2011-11-30 01:18:29205 STRICT_ERROR_CHECKS = 1 << 2,
[email protected]3aff9ad2011-04-01 20:26:48206
207 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
208 // to have file access. If it's not present, then permissions and content
209 // scripts that match file:/// URLs will be filtered out.
[email protected]3f53dfe2011-11-30 01:18:29210 ALLOW_FILE_ACCESS = 1 << 3,
[email protected]620db1762011-07-15 21:57:34211
212 // |FROM_WEBSTORE| indicates that the extension was installed from the
213 // Chrome Web Store.
[email protected]3f53dfe2011-11-30 01:18:29214 FROM_WEBSTORE = 1 << 4,
[email protected]e805baf2011-07-26 18:23:05215
216 // |FROM_BOOKMARK| indicates the extension was created using a mock App
217 // created from a bookmark.
[email protected]3f53dfe2011-11-30 01:18:29218 FROM_BOOKMARK = 1 << 5,
[email protected]83048a22011-03-29 00:14:13219 };
220
[email protected]66e4eb32010-10-27 20:37:41221 static scoped_refptr<Extension> Create(const FilePath& path,
222 Location location,
[email protected]f3a1c642011-07-12 19:15:03223 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13224 int flags,
[email protected]66e4eb32010-10-27 20:37:41225 std::string* error);
226
[email protected]87c655e2011-07-01 21:42:00227 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26228 // an explicit id. Most consumers should just use the other Create() method.
229 static scoped_refptr<Extension> Create(const FilePath& path,
230 Location location,
231 const base::DictionaryValue& value,
232 int flags,
233 const std::string& explicit_id,
234 std::string* error);
[email protected]87c655e2011-07-01 21:42:00235
[email protected]145a317b2011-04-12 16:03:46236 // Given two install sources, return the one which should take priority
237 // over the other. If an extension is installed from two sources A and B,
238 // its install source should be set to GetHigherPriorityLocation(A, B).
239 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
240
[email protected]4c4f8192009-10-17 01:03:26241 // Max size (both dimensions) for browser and page actions.
242 static const int kPageActionIconMaxSize;
243 static const int kBrowserActionIconMaxSize;
244
[email protected]8d888c12010-11-30 00:00:25245 // Valid schemes for web extent URLPatterns.
246 static const int kValidWebExtentSchemes;
247
[email protected]f71f7e62010-12-07 03:45:33248 // Valid schemes for host permission URLPatterns.
249 static const int kValidHostPermissionSchemes;
250
[email protected]6014d672008-12-05 00:38:25251 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16252 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25253
[email protected]300cc58db2009-08-19 20:45:14254 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16255 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14256
257 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16258 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14259
[email protected]25b34332009-06-05 21:53:19260#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19261 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19262#endif
263
[email protected]37eeb5a2009-02-26 23:36:17264 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48265 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17266
[email protected]e435d6b72009-07-25 03:15:58267 // The mimetype used for extensions.
268 static const char kMimeType[];
269
[email protected]25b34332009-06-05 21:53:19270 // Checks to see if the extension has a valid ID.
271 static bool IdIsValid(const std::string& id);
272
[email protected]4ead6f72010-10-13 19:54:18273 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27274 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18275 static std::string GenerateIdForPath(const FilePath& file_name);
276
[email protected]e435d6b72009-07-25 03:15:58277 // Returns true if the specified file is an extension.
278 static bool IsExtension(const FilePath& file_name);
279
[email protected]25b34332009-06-05 21:53:19280 // Whether the |location| is external or not.
281 static inline bool IsExternalLocation(Location location) {
282 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32283 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06284 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
285 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
286 }
287
288 // Whether extensions with |location| are auto-updatable or not.
289 static inline bool IsAutoUpdateableLocation(Location location) {
290 // Only internal and external extensions can be autoupdated.
291 return location == Extension::INTERNAL ||
292 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19293 }
294
[email protected]95da88c42011-03-31 10:07:33295 // Whether extensions with |location| can be uninstalled or not. Policy
296 // controlled extensions are silently auto-installed and updated, and cannot
297 // be disabled by the user. The same applies for internal components.
298 static inline bool UserMayDisable(Location location) {
299 return location != Extension::EXTERNAL_POLICY_DOWNLOAD &&
300 location != Extension::COMPONENT;
301 }
302
[email protected]542258c2011-03-04 21:25:31303 // Whether extensions with |location| should be loaded with strict
304 // error checking. Strict error checks may flag errors older versions
305 // of chrome did not detect. To avoid breaking installed extensions,
306 // strict checks are disabled unless the location indicates that the
307 // developer is loading the extension, or the extension is a component
308 // of chrome.
309 static inline bool ShouldDoStrictErrorChecking(Location location) {
310 return location == Extension::LOAD ||
311 location == Extension::COMPONENT;
312 }
313
[email protected]cdfca9702011-08-08 16:07:01314 // Unpacked extensions start off with file access since they are a developer
315 // feature.
316 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
317 return location == Extension::LOAD;
318 }
319
[email protected]7fa19f82010-12-21 19:40:08320 // See Type definition above.
321 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23322
[email protected]07c00d992009-03-04 20:27:04323 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59324 // |extension_url| argument should be the url() from an Extension object. The
325 // |relative_path| can be untrusted user input. The returned URL will either
326 // be invalid() or a child of |extension_url|.
327 // NOTE: Static so that it can be used from multiple threads.
328 static GURL GetResourceURL(const GURL& extension_url,
329 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28330 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24331 return GetResourceURL(url(), relative_path);
332 }
[email protected]eab9b452009-01-23 20:48:59333
[email protected]8f270be2011-12-21 21:15:22334 // Returns true if the specified resource is web accessible.
335 bool IsResourceWebAccessible(const std::string& relative_path) const;
336
337 // Returns true when 'web_accessible_resources' are defined for the extension.
338 bool HasWebAccessibleResources() const;
339
[email protected]99efb7b12009-12-18 02:39:16340 // Returns an extension resource object. |relative_path| should be UTF8
341 // encoded.
[email protected]9adb9692010-10-29 23:14:02342 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16343
344 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02345 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59346
[email protected]a17f9462009-06-09 02:56:41347 // |input| is expected to be the text of an rsa public or private key. It
348 // tolerates the presence or absence of bracking header/footer like this:
349 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
350 // and may contain newlines.
351 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
352
353 // Does a simple base64 encoding of |input| into |output|.
354 static bool ProducePEM(const std::string& input, std::string* output);
355
[email protected]84ac7f32009-10-06 06:17:54356 // Generates an extension ID from arbitrary input. The same input string will
357 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15358 static bool GenerateId(const std::string& input,
359 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45360
[email protected]a17f9462009-06-09 02:56:41361 // Expects base64 encoded |input| and formats into |output| including
362 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50363 static bool FormatPEMForFileOutput(const std::string& input,
364 std::string* output,
365 bool is_public);
[email protected]a17f9462009-06-09 02:56:41366
[email protected]e3c0bc22012-02-24 01:34:15367 // Given an extension, icon size and match type, read a valid icon if present
368 // and decode it into result. In the browser process, this will DCHECK if not
369 // called on the file thread. To easily load extension images on the UI
370 // thread, see ImageLoadingTracker.
371 static void DecodeIcon(const Extension* extension,
372 ExtensionIconSet::Icons icon_size,
373 ExtensionIconSet::MatchType match_type,
374 scoped_ptr<SkBitmap>* result);
375
[email protected]c690a9812009-12-17 05:55:32376 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23377 // result. In the browser process, this will DCHECK if not called on the
378 // file thread. To easily load extension images on the UI thread, see
379 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02380 static void DecodeIcon(const Extension* extension,
[email protected]e3c0bc22012-02-24 01:34:15381 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32382 scoped_ptr<SkBitmap>* result);
383
384 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23385 // result. In the browser process, this will DCHECK if not called on the
386 // file thread. To easily load extension images on the UI thread, see
387 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32388 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]e3c0bc22012-02-24 01:34:15389 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32390 scoped_ptr<SkBitmap>* result);
391
[email protected]5349ac6d2011-04-05 22:20:17392 // Returns the default extension/app icon (for extensions or apps that don't
393 // have one).
394 static const SkBitmap& GetDefaultIcon(bool is_app);
395
[email protected]a807bbe2010-04-14 10:51:19396 // Returns the base extension url for a given |extension_id|.
397 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
398
[email protected]be7e5cb2010-10-04 12:53:17399 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17400 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21401 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17402
[email protected]902fd7b2011-07-27 18:42:31403 // Parses the host and api permissions from the specified permission |key|
404 // in the manifest |source|.
[email protected]953620b2011-12-04 00:55:32405 bool ParsePermissions(const extensions::Manifest* source,
[email protected]902fd7b2011-07-27 18:42:31406 const char* key,
407 int flags,
[email protected]fc670822011-12-17 09:33:49408 string16* error,
[email protected]902fd7b2011-07-27 18:42:31409 ExtensionAPIPermissionSet* api_permissions,
410 URLPatternSet* host_permissions);
411
[email protected]0d3e4a22011-06-23 19:02:52412 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const;
413 bool HasAPIPermission(const std::string& function_name) const;
[email protected]583d45c12010-08-31 02:48:12414
[email protected]0d3e4a22011-06-23 19:02:52415 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46416
[email protected]902fd7b2011-07-27 18:42:31417 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16418 // Users must approve permissions for unpacked and packed extensions in the
419 // following situations:
420 // - when installing or upgrading packed extensions
421 // - when installing unpacked extensions that have NPAPI plugins
422 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31423 bool CanSilentlyIncreasePermissions() const;
424
[email protected]584b8e3f2010-04-10 00:23:37425 // Whether the extension has access to the given URL.
426 bool HasHostPermission(const GURL& url) const;
427
[email protected]0df165f2010-09-28 16:49:40428 // Whether the extension has effective access to all hosts. This is true if
429 // there is a content script that matches all hosts, if there is a host
430 // permission grants access to all hosts (like <all_urls>) or an api
431 // permission that effectively grants access to all hosts (e.g. proxy,
432 // network, etc.)
433 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46434
[email protected]8d888c12010-11-30 00:00:25435 // Whether the extension effectively has all permissions (for example, by
436 // having an NPAPI plugin).
437 bool HasFullPermissions() const;
438
[email protected]902fd7b2011-07-27 18:42:31439 // Returns the full list of permission messages that this extension
440 // should display at install time.
441 ExtensionPermissionMessages GetPermissionMessages() const;
442
443 // Returns the full list of permission messages that this extension
444 // should display at install time. The messages are returned as strings
445 // for convenience.
446 std::vector<string16> GetPermissionMessageStrings() const;
447
448 // Sets the active |permissions|.
449 void SetActivePermissions(const ExtensionPermissionSet* permissions) const;
450
451 // Gets the extension's active permission set.
452 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
453
[email protected]5df6a5d2011-01-26 07:39:12454 // Whether context menu should be shown for page and browser actions.
455 bool ShowConfigureContextMenus() const;
456
[email protected]37cd64d2010-10-25 18:17:58457 // Returns the Homepage URL for this extension. If homepage_url was not
458 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23459 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58460 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23461
[email protected]facd7a7652009-06-05 23:15:02462 // Returns a list of paths (relative to the extension dir) for images that
463 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02464 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02465
[email protected]807871f2010-09-16 01:04:48466 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02467 ExtensionResource GetIconResource(
468 int size, ExtensionIconSet::MatchType match_type) const;
469 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08470
[email protected]867a73e12010-03-19 20:45:46471 // Gets the fully resolved absolute launch URL.
472 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21473
[email protected]6f229e82010-11-02 17:47:26474 // Image cache related methods. These are only valid on the UI thread and
475 // not maintained by this class. See ImageLoadingTracker for usage. The
476 // |original_size| parameter should be the size of the image at |source|
477 // before any scaling may have been done to produce the pixels in |image|.
478 void SetCachedImage(const ExtensionResource& source,
479 const SkBitmap& image,
480 const gfx::Size& original_size) const;
481 bool HasCachedImage(const ExtensionResource& source,
482 const gfx::Size& max_size) const;
483 SkBitmap GetCachedImage(const ExtensionResource& source,
484 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21485
486 // Returns true if this extension can execute script on a page. If a
487 // UserScript object is passed, permission to run that specific script is
488 // checked (using its matches list). Otherwise, permission to execute script
489 // programmatically is checked (using the extension's host permission).
490 //
491 // This method is also aware of certain special pages that extensions are
492 // usually not allowed to run script on.
493 bool CanExecuteScriptOnPage(const GURL& page_url,
[email protected]3aff9ad2011-04-01 20:26:48494 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21495 std::string* error) const;
496
[email protected]6f229e82010-11-02 17:47:26497 // Returns true if this extension is a COMPONENT extension, or if it is
498 // on the whitelist of extensions that can script all pages.
499 bool CanExecuteScriptEverywhere() const;
500
[email protected]5efbfe012011-02-22 23:07:18501 // Returns true if this extension is allowed to obtain the contents of a
502 // page as an image. Since a page may contain sensitive information, this
503 // is restricted to the extension's host permissions as well as the
504 // extension page itself.
505 bool CanCaptureVisiblePage(const GURL& page_url, std::string* error) const;
506
[email protected]a65882c2010-11-12 15:15:09507 // Returns true if this extension updates itself using the extension
508 // gallery.
509 bool UpdatesFromGallery() const;
510
[email protected]cca147172011-02-17 01:29:29511 // Returns true if this extension or app includes areas within |origin|.
512 bool OverlapsWithOrigin(const GURL& origin) const;
513
[email protected]3bdba0d2011-08-23 07:17:30514 // Returns the sync bucket to use for this extension.
515 SyncType GetSyncType() const;
516
[email protected]b873cd92012-02-09 21:51:48517 // Returns true if the extension should be synced.
518 bool IsSyncable() const;
519
520 // Returns true if the extension should be displayed in the launcher.
521 bool ShouldDisplayInLauncher() const;
522
[email protected]6f229e82010-11-02 17:47:26523 // Accessors:
524
525 const FilePath& path() const { return path_; }
526 const GURL& url() const { return extension_url_; }
527 Location location() const { return location_; }
528 const std::string& id() const { return id_; }
529 const Version* version() const { return version_.get(); }
530 const std::string VersionString() const;
531 const std::string& name() const { return name_; }
532 const std::string& public_key() const { return public_key_; }
533 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31534 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26535 bool converted_from_user_script() const {
536 return converted_from_user_script_;
537 }
538 const UserScriptList& content_scripts() const { return content_scripts_; }
539 ExtensionAction* page_action() const { return page_action_.get(); }
540 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]b6b805e92011-04-16 09:24:14541 const FileBrowserHandlerList* file_browser_handlers() const {
542 return file_browser_handlers_.get();
543 }
[email protected]6f229e82010-11-02 17:47:26544 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23545 const std::vector<NaClModuleInfo>& nacl_modules() const {
546 return nacl_modules_;
547 }
[email protected]b0820372011-06-03 07:05:27548 const std::vector<InputComponentInfo>& input_components() const {
549 return input_components_;
550 }
[email protected]f5532472012-02-23 13:00:55551 const std::vector<ExtensionKeybinding>& keybindings() const {
552 return commands_;
553 }
[email protected]a03d4448f2012-01-10 23:25:28554 bool has_background_page() const {
555 return background_url_.is_valid() || !background_scripts_.empty();
556 }
557 const std::vector<std::string>& background_scripts() const {
558 return background_scripts_;
559 }
[email protected]9e6720a2012-01-24 02:30:56560 bool background_page_persists() const { return background_page_persists_; }
[email protected]6f229e82010-11-02 17:47:26561 const GURL& options_url() const { return options_url_; }
562 const GURL& devtools_url() const { return devtools_url_; }
[email protected]902fd7b2011-07-27 18:42:31563 const ExtensionPermissionSet* optional_permission_set() const {
564 return optional_permission_set_.get();
565 }
566 const ExtensionPermissionSet* required_permission_set() const {
567 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26568 }
[email protected]6f229e82010-11-02 17:47:26569 const GURL& update_url() const { return update_url_; }
570 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32571 const extensions::Manifest* manifest() const {
572 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26573 }
574 const std::string default_locale() const { return default_locale_; }
575 const URLOverrideMap& GetChromeURLOverrides() const {
576 return chrome_url_overrides_;
577 }
578 const std::string omnibox_keyword() const { return omnibox_keyword_; }
579 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55580 bool offline_enabled() const { return offline_enabled_; }
[email protected]a4a38c12010-12-23 16:43:56581 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]56624422011-11-01 22:11:27582 const std::vector<webkit_glue::WebIntentServiceData>&
583 intents_services() const {
584 return intents_services_;
585 }
[email protected]6f229e82010-11-02 17:47:26586
[email protected]3aff9ad2011-04-01 20:26:48587 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23588 int creation_flags() const { return creation_flags_; }
589 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05590 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]3aff9ad2011-04-01 20:26:48591
[email protected]7f7b9d932011-04-20 16:13:26592 const std::string& content_security_policy() const {
593 return content_security_policy_;
594 }
595
[email protected]6f229e82010-11-02 17:47:26596 // App-related.
[email protected]953620b2011-12-04 00:55:32597 bool is_app() const {
598 return is_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39599 }
[email protected]953620b2011-12-04 00:55:32600 bool is_platform_app() const { return manifest()->IsPlatformApp(); }
601 bool is_hosted_app() const { return manifest()->IsHostedApp(); }
602 bool is_packaged_app() const { return manifest()->IsPackagedApp(); }
[email protected]d9696672011-03-15 22:45:09603 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12604 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26605 const std::string& launch_local_path() const { return launch_local_path_; }
606 const std::string& launch_web_url() const { return launch_web_url_; }
607 extension_misc::LaunchContainer launch_container() const {
608 return launch_container_;
609 }
610 int launch_width() const { return launch_width_; }
611 int launch_height() const { return launch_height_; }
612
613 // Theme-related.
[email protected]953620b2011-12-04 00:55:32614 bool is_theme() const { return manifest()->IsTheme(); }
[email protected]f3a1c642011-07-12 19:15:03615 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
616 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
617 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
618 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26619 return theme_display_properties_.get();
620 }
621
[email protected]a03d4448f2012-01-10 23:25:28622 GURL GetBackgroundURL() const;
623
[email protected]4a8d3272009-03-10 19:15:08624 private:
[email protected]66e4eb32010-10-27 20:37:41625 friend class base::RefCountedThreadSafe<Extension>;
626
[email protected]d7e9a862010-11-03 21:57:49627 // We keep a cache of images loaded from extension resources based on their
628 // path and a string representation of a size that may have been used to
629 // scale it (or the empty string if the image is at its original size).
630 typedef std::pair<FilePath, std::string> ImageCacheKey;
631 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
632
[email protected]902fd7b2011-07-27 18:42:31633 class RuntimeData {
634 public:
635 RuntimeData();
636 explicit RuntimeData(const ExtensionPermissionSet* active);
637 ~RuntimeData();
638
639 void SetActivePermissions(const ExtensionPermissionSet* active);
640 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
641
642 private:
643 friend class base::RefCountedThreadSafe<RuntimeData>;
644 scoped_refptr<const ExtensionPermissionSet> active_permissions_;
645 };
646
[email protected]4ead6f72010-10-13 19:54:18647 // Normalize the path for use by the extension. On Windows, this will make
648 // sure the drive letter is uppercase.
649 static FilePath MaybeNormalizePath(const FilePath& path);
650
[email protected]87c655e2011-07-01 21:42:00651 // Returns true if this extension id is from a trusted provider.
652 static bool IsTrustedId(const std::string& id);
653
[email protected]66e4eb32010-10-27 20:37:41654 Extension(const FilePath& path, Location location);
655 ~Extension();
656
657 // Initialize the extension from a parsed manifest.
[email protected]953620b2011-12-04 00:55:32658 // Takes ownership of the manifest |value|.
659 bool InitFromValue(extensions::Manifest* value, int flags,
[email protected]fc670822011-12-17 09:33:49660 string16* error);
[email protected]66e4eb32010-10-27 20:37:41661
[email protected]052c92702010-06-25 07:25:52662 // Helper function for implementing HasCachedImage/GetCachedImage. A return
663 // value of NULL means there is no matching image cached (we allow caching an
664 // empty SkBitmap).
665 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
[email protected]9adb9692010-10-29 23:14:02666 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18667
[email protected]3cfbd0e2009-03-18 21:26:24668 // Helper method that loads a UserScript object from a
669 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03670 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24671 int definition_index,
[email protected]3aff9ad2011-04-01 20:26:48672 int flags,
[email protected]fc670822011-12-17 09:33:49673 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24674 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34675
[email protected]6657afa62009-11-04 02:15:20676 // Helper method that loads either the include_globs or exclude_globs list
677 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03678 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20679 int content_script_index,
[email protected]e2194742010-08-12 05:54:34680 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49681 string16* error,
[email protected]11f4857282009-11-13 19:56:17682 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20683 UserScript *instance);
684
[email protected]867a73e12010-03-19 20:45:46685 // Helpers to load various chunks of the manifest.
[email protected]953620b2011-12-04 00:55:32686 bool LoadExtent(const extensions::Manifest* manifest,
[email protected]542258c2011-03-04 21:25:31687 const char* key,
[email protected]cced75a2011-05-20 08:31:12688 URLPatternSet* extent,
[email protected]542258c2011-03-04 21:25:31689 const char* list_error,
690 const char* value_error,
[email protected]fc670822011-12-17 09:33:49691 string16* error);
[email protected]953620b2011-12-04 00:55:32692 bool LoadLaunchContainer(const extensions::Manifest* manifest,
[email protected]fc670822011-12-17 09:33:49693 string16* error);
[email protected]953620b2011-12-04 00:55:32694 bool LoadLaunchURL(const extensions::Manifest* manifest,
[email protected]fc670822011-12-17 09:33:49695 string16* error);
[email protected]953620b2011-12-04 00:55:32696 bool LoadAppIsolation(const extensions::Manifest* manifest,
[email protected]fc670822011-12-17 09:33:49697 string16* error);
[email protected]953620b2011-12-04 00:55:32698 bool LoadWebIntentServices(const extensions::Manifest* manifest,
[email protected]fc670822011-12-17 09:33:49699 string16* error);
[email protected]a03d4448f2012-01-10 23:25:28700 bool LoadBackgroundScripts(const extensions::Manifest* manifest,
701 string16* error);
[email protected]eb75f7b2012-01-04 09:07:28702 bool LoadBackgroundPage(const extensions::Manifest* manifest,
703 const ExtensionAPIPermissionSet& api_permissions,
704 string16* error);
[email protected]9e6720a2012-01-24 02:30:56705 bool LoadBackgroundPersistent(
706 const extensions::Manifest* manifest,
707 const ExtensionAPIPermissionSet& api_permissions,
708 string16* error);
[email protected]867a73e12010-03-19 20:45:46709
[email protected]5d246db22009-10-27 06:17:57710 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08711 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57712 ExtensionAction* LoadExtensionActionHelper(
[email protected]fc670822011-12-17 09:33:49713 const base::DictionaryValue* extension_action, string16* error);
[email protected]92c6f9b92009-10-24 04:35:08714
[email protected]b6b805e92011-04-16 09:24:14715 // Helper method to load an FileBrowserHandlerList from the manifest.
716 FileBrowserHandlerList* LoadFileBrowserHandlers(
[email protected]fc670822011-12-17 09:33:49717 const base::ListValue* extension_actions, string16* error);
[email protected]b6b805e92011-04-16 09:24:14718 // Helper method to load an FileBrowserHandler from manifest.
719 FileBrowserHandler* LoadFileBrowserHandler(
[email protected]fc670822011-12-17 09:33:49720 const base::DictionaryValue* file_browser_handlers, string16* error);
[email protected]b6b805e92011-04-16 09:24:14721
[email protected]2f6698b2010-10-14 00:58:21722 // Returns true if the extension has more than one "UI surface". For example,
723 // an extension that has a browser action and a page action.
724 bool HasMultipleUISurfaces() const;
725
[email protected]be9d9c82011-07-13 04:17:31726 // Updates the launch URL and extents for the extension using the given
727 // |override_url|.
728 void OverrideLaunchUrl(const GURL& override_url);
729
[email protected]5eddc3e2011-10-26 04:33:31730 // Returns true if this extension can specify |api|.
731 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api,
[email protected]fc670822011-12-17 09:33:49732 string16* error) const;
[email protected]5eddc3e2011-10-26 04:33:31733 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31734
735 // Checks whether the host |pattern| is allowed for this extension, given API
736 // permissions |permissions|.
737 bool CanSpecifyHostPermission(const URLPattern& pattern,
738 const ExtensionAPIPermissionSet& permissions) const;
739
[email protected]d7e9a862010-11-03 21:57:49740 // Cached images for this extension. This should only be touched on the UI
741 // thread.
742 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31743
[email protected]6f229e82010-11-02 17:47:26744 // A persistent, globally unique ID. An extension's ID is used in things
745 // like directory structures and URLs, and is expected to not change across
746 // versions. It is generated as a SHA-256 hash of the extension's public
747 // key, or as a hash of the path in the case of unpacked extensions.
748 std::string id_;
749
750 // The extension's human-readable name. Name is used for display purpose. It
751 // might be wrapped with unicode bidi control characters so that it is
752 // displayed correctly in RTL context.
753 // NOTE: Name is UTF-8 and may contain non-ascii characters.
754 std::string name_;
755
756 // The absolute path to the directory the extension is stored in.
757 FilePath path_;
758
[email protected]a47c8a22011-11-17 18:40:31759 // The version of this extension's manifest. We increase the manifest
760 // version when making breaking changes to the extension system.
761 // Version 1 was the first manifest version (implied by a lack of a
762 // manifest_version attribute in the extension's manifest). We initialize
763 // this member variable to 0 to distinguish the "uninitialized" case from
764 // the case when we know the manifest version actually is 1.
765 int manifest_version_;
766
[email protected]6f229e82010-11-02 17:47:26767 // Default locale for fall back. Can be empty if extension is not localized.
768 std::string default_locale_;
769
770 // If true, a separate process will be used for the extension in incognito
771 // mode.
772 bool incognito_split_mode_;
773
[email protected]1abdf4f2011-08-16 21:11:55774 // Whether the extension or app should be enabled when offline.
775 bool offline_enabled_;
776
[email protected]6f229e82010-11-02 17:47:26777 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12778 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26779
[email protected]902fd7b2011-07-27 18:42:31780 // The extension runtime data.
781 mutable base::Lock runtime_data_lock_;
782 mutable RuntimeData runtime_data_;
783
784 // The set of permissions the extension can request at runtime.
785 scoped_refptr<const ExtensionPermissionSet> optional_permission_set_;
786
787 // The extension's required / default set of permissions.
788 scoped_refptr<const ExtensionPermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26789
790 // The icons for the extension.
791 ExtensionIconSet icons_;
792
793 // The base extension url for the extension.
794 GURL extension_url_;
795
796 // The location the extension was loaded from.
797 Location location_;
798
799 // The extension's version.
800 scoped_ptr<Version> version_;
801
802 // An optional longer description of the extension.
803 std::string description_;
804
805 // True if the extension was generated from a user script. (We show slightly
806 // different UI if so).
807 bool converted_from_user_script_;
808
809 // Paths to the content scripts the extension contains.
810 UserScriptList content_scripts_;
811
812 // The extension's page action, if any.
813 scoped_ptr<ExtensionAction> page_action_;
814
815 // The extension's browser action, if any.
816 scoped_ptr<ExtensionAction> browser_action_;
817
[email protected]b6b805e92011-04-16 09:24:14818 // The extension's file browser actions, if any.
819 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
820
[email protected]6f229e82010-11-02 17:47:26821 // Optional list of NPAPI plugins and associated properties.
822 std::vector<PluginInfo> plugins_;
823
[email protected]65378f52011-04-08 02:31:23824 // Optional list of NaCl modules and associated properties.
825 std::vector<NaClModuleInfo> nacl_modules_;
826
[email protected]b0820372011-06-03 07:05:27827 // Optional list of input components and associated properties.
828 std::vector<InputComponentInfo> input_components_;
829
[email protected]f5532472012-02-23 13:00:55830 // Optional list of commands (keyboard shortcuts).
831 std::vector<ExtensionKeybinding> commands_;
832
[email protected]8f270be2011-12-21 21:15:22833 // Optional list of web accessible extension resources.
834 base::hash_set<std::string> web_accessible_resources_;
835
[email protected]6f229e82010-11-02 17:47:26836 // Optional URL to a master page of which a single instance should be always
837 // loaded in the background.
838 GURL background_url_;
839
[email protected]a03d4448f2012-01-10 23:25:28840 // Optional list of scripts to use to generate a background page. If this is
841 // present, background_url_ will be empty and generated by GetBackgroundURL().
842 std::vector<std::string> background_scripts_;
843
[email protected]9e6720a2012-01-24 02:30:56844 // True if the background page should stay loaded forever; false if it should
845 // load on-demand (when it needs to handle an event). Defaults to true.
846 bool background_page_persists_;
847
[email protected]6f229e82010-11-02 17:47:26848 // Optional URL to a page for setting options/preferences.
849 GURL options_url_;
850
851 // Optional URL to a devtools extension page.
852 GURL devtools_url_;
853
[email protected]6f229e82010-11-02 17:47:26854 // The public key used to sign the contents of the crx package.
855 std::string public_key_;
856
857 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:03858 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:26859
860 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03861 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:26862
863 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03864 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:26865
866 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:03867 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:26868
[email protected]6f229e82010-11-02 17:47:26869 // The homepage for this extension. Useful if it is not hosted by Google and
870 // therefore does not have a Gallery URL.
871 GURL homepage_url_;
872
873 // URL for fetching an update manifest
874 GURL update_url_;
875
[email protected]953620b2011-12-04 00:55:32876 // The manifest that this extension was created from.
877 scoped_ptr<extensions::Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:26878
879 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
880 // which override the handling of those URLs. (see ExtensionOverrideUI).
881 URLOverrideMap chrome_url_overrides_;
882
[email protected]d9696672011-03-15 22:45:09883 // Whether this extension requests isolated storage.
884 bool is_storage_isolated_;
885
[email protected]6f229e82010-11-02 17:47:26886 // The local path inside the extension to use with the launcher.
887 std::string launch_local_path_;
888
889 // A web url to use with the launcher. Note that this might be relative or
890 // absolute. If relative, it is relative to web_origin.
891 std::string launch_web_url_;
892
[email protected]4e595682011-02-09 17:07:02893 // The window type that an app's manifest specifies to launch into.
894 // This is not always the window type an app will open into, because
895 // users can override the way each app launches. See
896 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
897 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:26898 extension_misc::LaunchContainer launch_container_;
899
900 // The default size of the container when launching. Only respected for
901 // containers like panels and windows.
902 int launch_width_;
903 int launch_height_;
904
905 // The Omnibox keyword for this extension, or empty if there is none.
906 std::string omnibox_keyword_;
907
[email protected]a4a38c12010-12-23 16:43:56908 // List of text-to-speech voices that this extension provides, if any.
909 std::vector<TtsVoice> tts_voices_;
910
[email protected]56624422011-11-01 22:11:27911 // List of intent services that this extension provides, if any.
912 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
[email protected]be5f007862011-09-23 00:35:13913
[email protected]3aff9ad2011-04-01 20:26:48914 // Whether the extension has host permissions or user script patterns that
915 // imply access to file:/// scheme URLs (the user may not have actually
916 // granted it that access).
917 bool wants_file_access_;
918
[email protected]2af352b2011-07-22 08:21:23919 // The flags that were passed to InitFromValue.
920 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34921
[email protected]7f7b9d932011-04-20 16:13:26922 // The Content-Security-Policy for this extension. Extensions can use
923 // Content-Security-Policies to mitigate cross-site scripting and other
924 // vulnerabilities.
925 std::string content_security_policy_;
926
[email protected]eaa7dd182010-12-14 11:09:00927 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]5eb375e92010-11-26 07:50:41928 UpdateExtensionPreservesLocation);
[email protected]19118d52010-07-26 22:13:42929 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
930 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58931
[email protected]894bb502009-05-21 22:39:57932 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33933};
934
[email protected]9adb9692010-10-29 23:14:02935typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:18936typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:56937
[email protected]c6d474f82009-12-16 21:11:06938// Handy struct to pass core extension info around.
939struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03940 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:06941 const std::string& id,
942 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:46943 Extension::Location location);
944 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06945
[email protected]f3a1c642011-07-12 19:15:03946 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:06947 std::string extension_id;
948 FilePath extension_path;
949 Extension::Location extension_location;
950
951 private:
952 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
953};
954
[email protected]a9f39a312010-12-23 22:14:27955struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:59956 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:27957
958 // Was the extension already disabled?
959 bool already_disabled;
960
961 // The extension being unloaded - this should always be non-NULL.
962 const Extension* extension;
963
[email protected]814a7bf0f2011-08-13 05:30:59964 UnloadedExtensionInfo(
965 const Extension* extension,
966 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:27967};
968
[email protected]902fd7b2011-07-27 18:42:31969// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
970struct UpdatedExtensionPermissionsInfo {
971 enum Reason {
[email protected]f5532472012-02-23 13:00:55972 ADDED, // The permissions were added to the extension.
973 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:31974 };
975
976 Reason reason;
977
978 // The extension who's permissions have changed.
979 const Extension* extension;
980
981 // The permissions that have changed. For Reason::ADDED, this would contain
982 // only the permissions that have added, and for Reason::REMOVED, this would
983 // only contain the removed permissions.
984 const ExtensionPermissionSet* permissions;
985
986 UpdatedExtensionPermissionsInfo(
987 const Extension* extension,
988 const ExtensionPermissionSet* permissions,
989 Reason reason);
990};
991
[email protected]5b1a0e22009-05-26 19:00:58992#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_