blob: e4c8cf6d59c052c886712b4188567f25bb01d5b4 [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>
[email protected]e5cd5502012-02-29 03:56:4313#include <algorithm>
[email protected]7713d632008-12-02 07:52:3314
[email protected]6014d672008-12-05 00:38:2515#include "base/file_path.h"
[email protected]19118d52010-07-26 22:13:4216#include "base/gtest_prod_util.h"
[email protected]8f270be2011-12-21 21:15:2217#include "base/hash_tables.h"
[email protected]b6b805e92011-04-16 09:24:1418#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1519#include "base/memory/ref_counted.h"
20#include "base/memory/scoped_ptr.h"
[email protected]902fd7b2011-07-27 18:42:3121#include "base/synchronization/lock.h"
[email protected]d83a5602010-09-16 00:22:4822#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4823#include "chrome/common/extensions/extension_icon_set.h"
[email protected]0d3e4a22011-06-23 19:02:5224#include "chrome/common/extensions/extension_permission_set.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]d41e2152012-02-24 04:20:2743namespace extensions {
44class Manifest;
45}
46
[email protected]f0cc7242011-12-13 04:26:1747namespace webkit_glue {
48struct WebIntentServiceData;
49}
50
[email protected]f0755532010-06-22 07:27:2551// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4152class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3353 public:
[email protected]d3cfa482009-10-17 13:54:5754 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1755 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1456 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]b24d8312009-08-27 06:47:4657
[email protected]631cf822009-05-15 07:01:2558 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2359 // NOTE: These values are stored as integers in the preferences and used
60 // in histograms so don't remove or reorder existing items. Just append
61 // to the end.
[email protected]631cf822009-05-15 07:01:2562 enum Location {
63 INVALID,
[email protected]25b34332009-06-05 21:53:1964 INTERNAL, // A crx file from the internal Extensions directory.
65 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
66 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
67 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3468 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3269 COMPONENT, // An integral component of Chrome itself, which
70 // happens to be implemented as an extension. We don't
71 // show these in the management UI.
[email protected]4d2913e32010-11-30 00:28:5572 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via
73 // prefs), installed from an update URL.
74 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via
75 // admin policies), installed from an update URL.
[email protected]04cb7542010-10-25 10:50:0676
77 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1978 };
79
80 enum State {
[email protected]0c6da502009-08-14 22:32:3981 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1982 ENABLED,
[email protected]79c833b52011-04-05 18:31:0183 // An external extension that the user uninstalled. We should not reinstall
84 // such extensions on startup.
85 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:3986 NUM_STATES
[email protected]631cf822009-05-15 07:01:2587 };
[email protected]7713d632008-12-02 07:52:3388
[email protected]fbcc40302009-06-12 20:45:4589 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3790 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4591 DOWNGRADE,
92 REINSTALL,
93 UPGRADE,
94 NEW_INSTALL
95 };
96
[email protected]7fa19f82010-12-21 19:40:0897 // Do not change the order of entries or remove entries in this list
98 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
99 enum Type {
[email protected]9b217652010-10-08 22:04:23100 TYPE_UNKNOWN = 0,
101 TYPE_EXTENSION,
102 TYPE_THEME,
103 TYPE_USER_SCRIPT,
104 TYPE_HOSTED_APP,
[email protected]7d3ed2f2011-11-07 23:33:19105 TYPE_PACKAGED_APP,
106 TYPE_PLATFORM_APP
[email protected]9b217652010-10-08 22:04:23107 };
108
[email protected]3bdba0d2011-08-23 07:17:30109 enum SyncType {
110 SYNC_TYPE_NONE = 0,
111 SYNC_TYPE_EXTENSION,
112 SYNC_TYPE_APP
113 };
114
[email protected]92888082010-10-18 19:24:57115 // An NPAPI plugin included in the extension.
116 struct PluginInfo {
117 FilePath path; // Path to the plugin.
118 bool is_public; // False if only this extension can load this plugin.
119 };
120
[email protected]65378f52011-04-08 02:31:23121 // An NaCl module included in the extension.
122 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42123 GURL url;
[email protected]65378f52011-04-08 02:31:23124 std::string mime_type;
125 };
126
[email protected]b0820372011-06-03 07:05:27127 enum InputComponentType {
[email protected]d45f7512011-06-21 21:18:27128 INPUT_COMPONENT_TYPE_NONE = -1,
129 INPUT_COMPONENT_TYPE_IME,
[email protected]b0820372011-06-03 07:05:27130 INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD,
131 INPUT_COMPONENT_TYPE_COUNT
132 };
133
134 struct InputComponentInfo {
135 // Define out of line constructor/destructor to please Clang.
136 InputComponentInfo();
137 ~InputComponentInfo();
138
139 std::string name;
140 InputComponentType type;
141 std::string id;
142 std::string description;
143 std::string language;
144 std::set<std::string> layouts;
145 std::string shortcut_keycode;
146 bool shortcut_alt;
147 bool shortcut_ctrl;
148 bool shortcut_shift;
149 };
150
[email protected]f5532472012-02-23 13:00:55151 class ExtensionKeybinding {
152 public:
153 // Define out of line constructor/destructor to please Clang.
154 ExtensionKeybinding();
155 ~ExtensionKeybinding();
156
157 // Parse the key binding.
158 bool Parse(base::DictionaryValue* command,
159 const std::string& command_name,
160 int index,
161 string16* error);
162
163 // Accessors:
164 const std::string& command_name() const { return command_name_; }
165 const ui::Accelerator& accelerator() const { return accelerator_; }
166 const std::string& description() const { return description_; }
167
168 private:
169 std::string command_name_;
170 ui::Accelerator accelerator_;
171 std::string description_;
172 };
173
[email protected]a4a38c12010-12-23 16:43:56174 struct TtsVoice {
[email protected]77a3ecac2011-07-07 05:56:33175 // Define out of line constructor/destructor to please Clang.
176 TtsVoice();
177 ~TtsVoice();
178
[email protected]a4a38c12010-12-23 16:43:56179 std::string voice_name;
[email protected]c63f2b72011-07-07 05:25:00180 std::string lang;
[email protected]a4a38c12010-12-23 16:43:56181 std::string gender;
[email protected]c63f2b72011-07-07 05:25:00182 std::set<std::string> event_types;
[email protected]a4a38c12010-12-23 16:43:56183 };
184
[email protected]83048a22011-03-29 00:14:13185 enum InitFromValueFlags {
186 NO_FLAGS = 0,
187
188 // Usually, the id of an extension is generated by the "key" property of
189 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
190 // generated based on the path.
191 REQUIRE_KEY = 1 << 0,
192
[email protected]3f53dfe2011-11-30 01:18:29193 // Requires the extension to have an up-to-date manifest version.
194 // Typically, we'll support multiple manifest versions during a version
195 // transition. This flag signals that we want to require the most modern
196 // manifest version that Chrome understands.
197 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
198
[email protected]83048a22011-03-29 00:14:13199 // |STRICT_ERROR_CHECKS| enables extra error checking, such as
200 // checks that URL patterns do not contain ports. This error
201 // checking may find an error that a previous version of
202 // Chrome did not flag. To avoid errors in installed extensions
203 // when Chrome is upgraded, strict error checking is only enabled
204 // when loading extensions as a developer would (such as loading
205 // an unpacked extension), or when loading an extension that is
206 // tied to a specific version of Chrome (such as a component
207 // extension). Most callers will set the |STRICT_ERROR_CHECKS| bit when
208 // Extension::ShouldDoStrictErrorChecking(location) returns true.
[email protected]3f53dfe2011-11-30 01:18:29209 STRICT_ERROR_CHECKS = 1 << 2,
[email protected]3aff9ad2011-04-01 20:26:48210
211 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
212 // to have file access. If it's not present, then permissions and content
213 // scripts that match file:/// URLs will be filtered out.
[email protected]3f53dfe2011-11-30 01:18:29214 ALLOW_FILE_ACCESS = 1 << 3,
[email protected]620db1762011-07-15 21:57:34215
216 // |FROM_WEBSTORE| indicates that the extension was installed from the
217 // Chrome Web Store.
[email protected]3f53dfe2011-11-30 01:18:29218 FROM_WEBSTORE = 1 << 4,
[email protected]e805baf2011-07-26 18:23:05219
220 // |FROM_BOOKMARK| indicates the extension was created using a mock App
221 // created from a bookmark.
[email protected]3f53dfe2011-11-30 01:18:29222 FROM_BOOKMARK = 1 << 5,
[email protected]83048a22011-03-29 00:14:13223 };
224
[email protected]66e4eb32010-10-27 20:37:41225 static scoped_refptr<Extension> Create(const FilePath& path,
226 Location location,
[email protected]f3a1c642011-07-12 19:15:03227 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13228 int flags,
[email protected]66e4eb32010-10-27 20:37:41229 std::string* error);
230
[email protected]87c655e2011-07-01 21:42:00231 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26232 // an explicit id. Most consumers should just use the other Create() method.
233 static scoped_refptr<Extension> Create(const FilePath& path,
234 Location location,
235 const base::DictionaryValue& value,
236 int flags,
237 const std::string& explicit_id,
238 std::string* error);
[email protected]87c655e2011-07-01 21:42:00239
[email protected]145a317b2011-04-12 16:03:46240 // Given two install sources, return the one which should take priority
241 // over the other. If an extension is installed from two sources A and B,
242 // its install source should be set to GetHigherPriorityLocation(A, B).
243 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
244
[email protected]4c4f8192009-10-17 01:03:26245 // Max size (both dimensions) for browser and page actions.
246 static const int kPageActionIconMaxSize;
247 static const int kBrowserActionIconMaxSize;
248
[email protected]8d888c12010-11-30 00:00:25249 // Valid schemes for web extent URLPatterns.
250 static const int kValidWebExtentSchemes;
251
[email protected]f71f7e62010-12-07 03:45:33252 // Valid schemes for host permission URLPatterns.
253 static const int kValidHostPermissionSchemes;
254
[email protected]6014d672008-12-05 00:38:25255 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16256 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25257
[email protected]300cc58db2009-08-19 20:45:14258 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16259 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14260
261 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16262 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14263
[email protected]25b34332009-06-05 21:53:19264#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19265 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19266#endif
267
[email protected]37eeb5a2009-02-26 23:36:17268 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48269 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17270
[email protected]e435d6b72009-07-25 03:15:58271 // The mimetype used for extensions.
272 static const char kMimeType[];
273
[email protected]25b34332009-06-05 21:53:19274 // Checks to see if the extension has a valid ID.
275 static bool IdIsValid(const std::string& id);
276
[email protected]4ead6f72010-10-13 19:54:18277 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27278 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18279 static std::string GenerateIdForPath(const FilePath& file_name);
280
[email protected]e435d6b72009-07-25 03:15:58281 // Returns true if the specified file is an extension.
282 static bool IsExtension(const FilePath& file_name);
283
[email protected]25b34332009-06-05 21:53:19284 // Whether the |location| is external or not.
285 static inline bool IsExternalLocation(Location location) {
286 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32287 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06288 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
289 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
290 }
291
292 // Whether extensions with |location| are auto-updatable or not.
293 static inline bool IsAutoUpdateableLocation(Location location) {
294 // Only internal and external extensions can be autoupdated.
295 return location == Extension::INTERNAL ||
296 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19297 }
298
[email protected]95da88c42011-03-31 10:07:33299 // Whether extensions with |location| can be uninstalled or not. Policy
300 // controlled extensions are silently auto-installed and updated, and cannot
301 // be disabled by the user. The same applies for internal components.
302 static inline bool UserMayDisable(Location location) {
303 return location != Extension::EXTERNAL_POLICY_DOWNLOAD &&
304 location != Extension::COMPONENT;
305 }
306
[email protected]542258c2011-03-04 21:25:31307 // Whether extensions with |location| should be loaded with strict
308 // error checking. Strict error checks may flag errors older versions
309 // of chrome did not detect. To avoid breaking installed extensions,
310 // strict checks are disabled unless the location indicates that the
311 // developer is loading the extension, or the extension is a component
312 // of chrome.
313 static inline bool ShouldDoStrictErrorChecking(Location location) {
314 return location == Extension::LOAD ||
315 location == Extension::COMPONENT;
316 }
317
[email protected]cdfca9702011-08-08 16:07:01318 // Unpacked extensions start off with file access since they are a developer
319 // feature.
320 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
321 return location == Extension::LOAD;
322 }
323
[email protected]7fa19f82010-12-21 19:40:08324 // See Type definition above.
325 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23326
[email protected]07c00d992009-03-04 20:27:04327 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59328 // |extension_url| argument should be the url() from an Extension object. The
329 // |relative_path| can be untrusted user input. The returned URL will either
330 // be invalid() or a child of |extension_url|.
331 // NOTE: Static so that it can be used from multiple threads.
332 static GURL GetResourceURL(const GURL& extension_url,
333 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28334 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24335 return GetResourceURL(url(), relative_path);
336 }
[email protected]eab9b452009-01-23 20:48:59337
[email protected]8f270be2011-12-21 21:15:22338 // Returns true if the specified resource is web accessible.
339 bool IsResourceWebAccessible(const std::string& relative_path) const;
340
341 // Returns true when 'web_accessible_resources' are defined for the extension.
342 bool HasWebAccessibleResources() const;
343
[email protected]99efb7b12009-12-18 02:39:16344 // Returns an extension resource object. |relative_path| should be UTF8
345 // encoded.
[email protected]9adb9692010-10-29 23:14:02346 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16347
348 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02349 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59350
[email protected]a17f9462009-06-09 02:56:41351 // |input| is expected to be the text of an rsa public or private key. It
352 // tolerates the presence or absence of bracking header/footer like this:
353 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
354 // and may contain newlines.
355 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
356
357 // Does a simple base64 encoding of |input| into |output|.
358 static bool ProducePEM(const std::string& input, std::string* output);
359
[email protected]84ac7f32009-10-06 06:17:54360 // Generates an extension ID from arbitrary input. The same input string will
361 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15362 static bool GenerateId(const std::string& input,
363 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45364
[email protected]a17f9462009-06-09 02:56:41365 // Expects base64 encoded |input| and formats into |output| including
366 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50367 static bool FormatPEMForFileOutput(const std::string& input,
368 std::string* output,
369 bool is_public);
[email protected]a17f9462009-06-09 02:56:41370
[email protected]e3c0bc22012-02-24 01:34:15371 // Given an extension, icon size and match type, read a valid icon if present
372 // and decode it into result. In the browser process, this will DCHECK if not
373 // called on the file thread. To easily load extension images on the UI
374 // thread, see ImageLoadingTracker.
375 static void DecodeIcon(const Extension* extension,
376 ExtensionIconSet::Icons icon_size,
377 ExtensionIconSet::MatchType match_type,
378 scoped_ptr<SkBitmap>* result);
379
[email protected]c690a9812009-12-17 05:55:32380 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23381 // result. In the browser process, this will DCHECK if not called on the
382 // file thread. To easily load extension images on the UI thread, see
383 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02384 static void DecodeIcon(const Extension* extension,
[email protected]e3c0bc22012-02-24 01:34:15385 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32386 scoped_ptr<SkBitmap>* result);
387
388 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23389 // result. In the browser process, this will DCHECK if not called on the
390 // file thread. To easily load extension images on the UI thread, see
391 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32392 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]e3c0bc22012-02-24 01:34:15393 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32394 scoped_ptr<SkBitmap>* result);
395
[email protected]5349ac6d2011-04-05 22:20:17396 // Returns the default extension/app icon (for extensions or apps that don't
397 // have one).
398 static const SkBitmap& GetDefaultIcon(bool is_app);
399
[email protected]a807bbe2010-04-14 10:51:19400 // Returns the base extension url for a given |extension_id|.
401 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
402
[email protected]be7e5cb2010-10-04 12:53:17403 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17404 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21405 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17406
[email protected]902fd7b2011-07-27 18:42:31407 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27408 // from |manifest_|.
409 bool ParsePermissions(const char* key,
[email protected]902fd7b2011-07-27 18:42:31410 int flags,
[email protected]fc670822011-12-17 09:33:49411 string16* error,
[email protected]902fd7b2011-07-27 18:42:31412 ExtensionAPIPermissionSet* api_permissions,
413 URLPatternSet* host_permissions);
414
[email protected]0d3e4a22011-06-23 19:02:52415 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const;
416 bool HasAPIPermission(const std::string& function_name) const;
[email protected]583d45c12010-08-31 02:48:12417
[email protected]0d3e4a22011-06-23 19:02:52418 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46419
[email protected]902fd7b2011-07-27 18:42:31420 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16421 // Users must approve permissions for unpacked and packed extensions in the
422 // following situations:
423 // - when installing or upgrading packed extensions
424 // - when installing unpacked extensions that have NPAPI plugins
425 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31426 bool CanSilentlyIncreasePermissions() const;
427
[email protected]584b8e3f2010-04-10 00:23:37428 // Whether the extension has access to the given URL.
429 bool HasHostPermission(const GURL& url) const;
430
[email protected]0df165f2010-09-28 16:49:40431 // Whether the extension has effective access to all hosts. This is true if
432 // there is a content script that matches all hosts, if there is a host
433 // permission grants access to all hosts (like <all_urls>) or an api
434 // permission that effectively grants access to all hosts (e.g. proxy,
435 // network, etc.)
436 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46437
[email protected]8d888c12010-11-30 00:00:25438 // Whether the extension effectively has all permissions (for example, by
439 // having an NPAPI plugin).
440 bool HasFullPermissions() const;
441
[email protected]902fd7b2011-07-27 18:42:31442 // Returns the full list of permission messages that this extension
443 // should display at install time.
444 ExtensionPermissionMessages GetPermissionMessages() const;
445
446 // Returns the full list of permission messages that this extension
447 // should display at install time. The messages are returned as strings
448 // for convenience.
449 std::vector<string16> GetPermissionMessageStrings() const;
450
451 // Sets the active |permissions|.
452 void SetActivePermissions(const ExtensionPermissionSet* permissions) const;
453
454 // Gets the extension's active permission set.
455 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
456
[email protected]5df6a5d2011-01-26 07:39:12457 // Whether context menu should be shown for page and browser actions.
458 bool ShowConfigureContextMenus() const;
459
[email protected]37cd64d2010-10-25 18:17:58460 // Returns the Homepage URL for this extension. If homepage_url was not
461 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23462 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58463 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23464
[email protected]facd7a7652009-06-05 23:15:02465 // Returns a list of paths (relative to the extension dir) for images that
466 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02467 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02468
[email protected]807871f2010-09-16 01:04:48469 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02470 ExtensionResource GetIconResource(
471 int size, ExtensionIconSet::MatchType match_type) const;
472 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08473
[email protected]867a73e12010-03-19 20:45:46474 // Gets the fully resolved absolute launch URL.
475 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21476
[email protected]6f229e82010-11-02 17:47:26477 // Image cache related methods. These are only valid on the UI thread and
478 // not maintained by this class. See ImageLoadingTracker for usage. The
479 // |original_size| parameter should be the size of the image at |source|
480 // before any scaling may have been done to produce the pixels in |image|.
481 void SetCachedImage(const ExtensionResource& source,
482 const SkBitmap& image,
483 const gfx::Size& original_size) const;
484 bool HasCachedImage(const ExtensionResource& source,
485 const gfx::Size& max_size) const;
486 SkBitmap GetCachedImage(const ExtensionResource& source,
487 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21488
489 // Returns true if this extension can execute script on a page. If a
490 // UserScript object is passed, permission to run that specific script is
491 // checked (using its matches list). Otherwise, permission to execute script
492 // programmatically is checked (using the extension's host permission).
493 //
494 // This method is also aware of certain special pages that extensions are
495 // usually not allowed to run script on.
496 bool CanExecuteScriptOnPage(const GURL& page_url,
[email protected]3aff9ad2011-04-01 20:26:48497 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21498 std::string* error) const;
499
[email protected]6f229e82010-11-02 17:47:26500 // Returns true if this extension is a COMPONENT extension, or if it is
501 // on the whitelist of extensions that can script all pages.
502 bool CanExecuteScriptEverywhere() const;
503
[email protected]5efbfe012011-02-22 23:07:18504 // Returns true if this extension is allowed to obtain the contents of a
505 // page as an image. Since a page may contain sensitive information, this
506 // is restricted to the extension's host permissions as well as the
507 // extension page itself.
508 bool CanCaptureVisiblePage(const GURL& page_url, std::string* error) const;
509
[email protected]a65882c2010-11-12 15:15:09510 // Returns true if this extension updates itself using the extension
511 // gallery.
512 bool UpdatesFromGallery() const;
513
[email protected]cca147172011-02-17 01:29:29514 // Returns true if this extension or app includes areas within |origin|.
515 bool OverlapsWithOrigin(const GURL& origin) const;
516
[email protected]3bdba0d2011-08-23 07:17:30517 // Returns the sync bucket to use for this extension.
518 SyncType GetSyncType() const;
519
[email protected]b873cd92012-02-09 21:51:48520 // Returns true if the extension should be synced.
521 bool IsSyncable() const;
522
523 // Returns true if the extension should be displayed in the launcher.
524 bool ShouldDisplayInLauncher() const;
525
[email protected]6f229e82010-11-02 17:47:26526 // Accessors:
527
528 const FilePath& path() const { return path_; }
529 const GURL& url() const { return extension_url_; }
[email protected]d41e2152012-02-24 04:20:27530 Location location() const;
531 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26532 const Version* version() const { return version_.get(); }
533 const std::string VersionString() const;
534 const std::string& name() const { return name_; }
[email protected]d41e2152012-02-24 04:20:27535 const std::string public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26536 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31537 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26538 bool converted_from_user_script() const {
539 return converted_from_user_script_;
540 }
541 const UserScriptList& content_scripts() const { return content_scripts_; }
542 ExtensionAction* page_action() const { return page_action_.get(); }
543 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]b6b805e92011-04-16 09:24:14544 const FileBrowserHandlerList* file_browser_handlers() const {
545 return file_browser_handlers_.get();
546 }
[email protected]6f229e82010-11-02 17:47:26547 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23548 const std::vector<NaClModuleInfo>& nacl_modules() const {
549 return nacl_modules_;
550 }
[email protected]b0820372011-06-03 07:05:27551 const std::vector<InputComponentInfo>& input_components() const {
552 return input_components_;
553 }
[email protected]f5532472012-02-23 13:00:55554 const std::vector<ExtensionKeybinding>& keybindings() const {
555 return commands_;
556 }
[email protected]a03d4448f2012-01-10 23:25:28557 bool has_background_page() const {
558 return background_url_.is_valid() || !background_scripts_.empty();
559 }
[email protected]7b54ca02012-03-02 18:06:53560 bool allow_background_js_access() const {
561 return allow_background_js_access_;
562 }
[email protected]a03d4448f2012-01-10 23:25:28563 const std::vector<std::string>& background_scripts() const {
564 return background_scripts_;
565 }
[email protected]9e6720a2012-01-24 02:30:56566 bool background_page_persists() const { return background_page_persists_; }
[email protected]6f229e82010-11-02 17:47:26567 const GURL& options_url() const { return options_url_; }
568 const GURL& devtools_url() const { return devtools_url_; }
[email protected]902fd7b2011-07-27 18:42:31569 const ExtensionPermissionSet* optional_permission_set() const {
570 return optional_permission_set_.get();
571 }
572 const ExtensionPermissionSet* required_permission_set() const {
573 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26574 }
[email protected]6f229e82010-11-02 17:47:26575 const GURL& update_url() const { return update_url_; }
576 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32577 const extensions::Manifest* manifest() const {
[email protected]d41e2152012-02-24 04:20:27578 return manifest_;
[email protected]6f229e82010-11-02 17:47:26579 }
580 const std::string default_locale() const { return default_locale_; }
581 const URLOverrideMap& GetChromeURLOverrides() const {
582 return chrome_url_overrides_;
583 }
584 const std::string omnibox_keyword() const { return omnibox_keyword_; }
585 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55586 bool offline_enabled() const { return offline_enabled_; }
[email protected]a4a38c12010-12-23 16:43:56587 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]56624422011-11-01 22:11:27588 const std::vector<webkit_glue::WebIntentServiceData>&
589 intents_services() const {
590 return intents_services_;
591 }
[email protected]6f229e82010-11-02 17:47:26592
[email protected]3aff9ad2011-04-01 20:26:48593 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23594 int creation_flags() const { return creation_flags_; }
595 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05596 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]3aff9ad2011-04-01 20:26:48597
[email protected]7f7b9d932011-04-20 16:13:26598 const std::string& content_security_policy() const {
599 return content_security_policy_;
600 }
601
[email protected]6f229e82010-11-02 17:47:26602 // App-related.
[email protected]953620b2011-12-04 00:55:32603 bool is_app() const {
604 return is_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39605 }
[email protected]d41e2152012-02-24 04:20:27606 bool is_platform_app() const;
607 bool is_hosted_app() const;
608 bool is_packaged_app() const;
[email protected]d9696672011-03-15 22:45:09609 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12610 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26611 const std::string& launch_local_path() const { return launch_local_path_; }
612 const std::string& launch_web_url() const { return launch_web_url_; }
613 extension_misc::LaunchContainer launch_container() const {
614 return launch_container_;
615 }
[email protected]e5cd5502012-02-29 03:56:43616 int launch_width() const {
[email protected]f8c3aea2012-03-01 07:23:20617 return std::max(launch_min_width_,
618 launch_max_width_ ?
619 std::min(launch_max_width_, launch_width_) :
620 launch_width_);
[email protected]e5cd5502012-02-29 03:56:43621 }
622 int launch_height() const {
[email protected]f8c3aea2012-03-01 07:23:20623 return std::max(launch_min_height_,
624 launch_max_height_ ?
625 std::min(launch_max_height_, launch_height_) :
626 launch_height_);
[email protected]e5cd5502012-02-29 03:56:43627 }
628 int launch_min_width() const { return launch_min_width_; }
629 int launch_min_height() const { return launch_min_height_; }
[email protected]f8c3aea2012-03-01 07:23:20630 int launch_max_width() const { return launch_max_width_; }
631 int launch_max_height() const { return launch_max_height_; }
[email protected]6f229e82010-11-02 17:47:26632
633 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27634 bool is_theme() const;
[email protected]f3a1c642011-07-12 19:15:03635 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
636 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
637 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
638 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26639 return theme_display_properties_.get();
640 }
641
[email protected]a03d4448f2012-01-10 23:25:28642 GURL GetBackgroundURL() const;
643
[email protected]4a8d3272009-03-10 19:15:08644 private:
[email protected]66e4eb32010-10-27 20:37:41645 friend class base::RefCountedThreadSafe<Extension>;
646
[email protected]d7e9a862010-11-03 21:57:49647 // We keep a cache of images loaded from extension resources based on their
648 // path and a string representation of a size that may have been used to
649 // scale it (or the empty string if the image is at its original size).
650 typedef std::pair<FilePath, std::string> ImageCacheKey;
651 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
652
[email protected]902fd7b2011-07-27 18:42:31653 class RuntimeData {
654 public:
655 RuntimeData();
656 explicit RuntimeData(const ExtensionPermissionSet* active);
657 ~RuntimeData();
658
659 void SetActivePermissions(const ExtensionPermissionSet* active);
660 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
661
662 private:
663 friend class base::RefCountedThreadSafe<RuntimeData>;
664 scoped_refptr<const ExtensionPermissionSet> active_permissions_;
665 };
666
[email protected]d41e2152012-02-24 04:20:27667 // Chooses the extension ID for an extension based on a variety of criteria.
668 // The chosen ID will be set in |manifest|.
669 static bool InitExtensionID(extensions::Manifest* manifest,
670 const FilePath& path,
671 const std::string& explicit_id,
672 int creation_flags,
673 string16* error);
674
[email protected]4ead6f72010-10-13 19:54:18675 // Normalize the path for use by the extension. On Windows, this will make
676 // sure the drive letter is uppercase.
677 static FilePath MaybeNormalizePath(const FilePath& path);
678
[email protected]87c655e2011-07-01 21:42:00679 // Returns true if this extension id is from a trusted provider.
680 static bool IsTrustedId(const std::string& id);
681
[email protected]d41e2152012-02-24 04:20:27682 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
[email protected]66e4eb32010-10-27 20:37:41683 ~Extension();
684
685 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27686 // TODO(aa): Rename to just Init()? There's no Value here anymore.
687 // TODO(aa): It is really weird the way this class essentially contains a copy
688 // of the underlying DictionaryValue in its members. We should decide to
689 // either wrap the DictionaryValue and go with that only, or we should parse
690 // into strong types and discard the value. But doing both is bad.
691 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41692
[email protected]d41e2152012-02-24 04:20:27693 // Helpers to load various chunks of the manifest.
694 bool LoadManifestVersion(string16* error);
695 bool LoadExtent(const char* key,
696 URLPatternSet* extent,
697 const char* list_error,
698 const char* value_error,
699 string16* error);
700 bool LoadLaunchContainer(string16* error);
701 bool LoadLaunchURL(string16* error);
702 bool LoadAppIsolation(string16* error);
[email protected]10253da2012-03-09 04:06:42703
704 // Parses a single action in the manifest.
705 bool LoadWebIntentAction(const std::string& action_name,
706 const base::DictionaryValue& intent_service,
707 string16* error);
[email protected]d41e2152012-02-24 04:20:27708 bool LoadWebIntentServices(string16* error);
709 bool LoadBackgroundScripts(string16* error);
710 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions,
711 string16* error);
712 bool LoadBackgroundPersistent(
713 const ExtensionAPIPermissionSet& api_permissions,
714 string16* error);
[email protected]7b54ca02012-03-02 18:06:53715 bool LoadBackgroundAllowJsAccess(
716 const ExtensionAPIPermissionSet& api_permissions,
717 string16* error);
[email protected]d9ad80f2010-03-30 20:40:18718
[email protected]3cfbd0e2009-03-18 21:26:24719 // Helper method that loads a UserScript object from a
720 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03721 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24722 int definition_index,
[email protected]3aff9ad2011-04-01 20:26:48723 int flags,
[email protected]fc670822011-12-17 09:33:49724 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24725 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34726
[email protected]6657afa62009-11-04 02:15:20727 // Helper method that loads either the include_globs or exclude_globs list
728 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03729 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20730 int content_script_index,
[email protected]e2194742010-08-12 05:54:34731 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49732 string16* error,
[email protected]11f4857282009-11-13 19:56:17733 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20734 UserScript *instance);
735
[email protected]5d246db22009-10-27 06:17:57736 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08737 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57738 ExtensionAction* LoadExtensionActionHelper(
[email protected]fc670822011-12-17 09:33:49739 const base::DictionaryValue* extension_action, string16* error);
[email protected]92c6f9b92009-10-24 04:35:08740
[email protected]b6b805e92011-04-16 09:24:14741 // Helper method to load an FileBrowserHandlerList from the manifest.
742 FileBrowserHandlerList* LoadFileBrowserHandlers(
[email protected]fc670822011-12-17 09:33:49743 const base::ListValue* extension_actions, string16* error);
[email protected]b6b805e92011-04-16 09:24:14744 // Helper method to load an FileBrowserHandler from manifest.
745 FileBrowserHandler* LoadFileBrowserHandler(
[email protected]fc670822011-12-17 09:33:49746 const base::DictionaryValue* file_browser_handlers, string16* error);
[email protected]b6b805e92011-04-16 09:24:14747
[email protected]2f6698b2010-10-14 00:58:21748 // Returns true if the extension has more than one "UI surface". For example,
749 // an extension that has a browser action and a page action.
750 bool HasMultipleUISurfaces() const;
751
[email protected]be9d9c82011-07-13 04:17:31752 // Updates the launch URL and extents for the extension using the given
753 // |override_url|.
754 void OverrideLaunchUrl(const GURL& override_url);
755
[email protected]5eddc3e2011-10-26 04:33:31756 // Returns true if this extension can specify |api|.
757 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api,
[email protected]fc670822011-12-17 09:33:49758 string16* error) const;
[email protected]5eddc3e2011-10-26 04:33:31759 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31760
761 // Checks whether the host |pattern| is allowed for this extension, given API
762 // permissions |permissions|.
763 bool CanSpecifyHostPermission(const URLPattern& pattern,
764 const ExtensionAPIPermissionSet& permissions) const;
765
[email protected]d41e2152012-02-24 04:20:27766 // Helper function for implementing HasCachedImage/GetCachedImage. A return
767 // value of NULL means there is no matching image cached (we allow caching an
768 // empty SkBitmap).
769 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
770 const gfx::Size& max_size) const;
771
[email protected]d7e9a862010-11-03 21:57:49772 // Cached images for this extension. This should only be touched on the UI
773 // thread.
774 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31775
[email protected]6f229e82010-11-02 17:47:26776 // The extension's human-readable name. Name is used for display purpose. It
777 // might be wrapped with unicode bidi control characters so that it is
778 // displayed correctly in RTL context.
779 // NOTE: Name is UTF-8 and may contain non-ascii characters.
780 std::string name_;
781
[email protected]a47c8a22011-11-17 18:40:31782 // The version of this extension's manifest. We increase the manifest
783 // version when making breaking changes to the extension system.
784 // Version 1 was the first manifest version (implied by a lack of a
785 // manifest_version attribute in the extension's manifest). We initialize
786 // this member variable to 0 to distinguish the "uninitialized" case from
787 // the case when we know the manifest version actually is 1.
788 int manifest_version_;
789
[email protected]d41e2152012-02-24 04:20:27790 // The absolute path to the directory the extension is stored in.
791 FilePath path_;
792
[email protected]6f229e82010-11-02 17:47:26793 // Default locale for fall back. Can be empty if extension is not localized.
794 std::string default_locale_;
795
796 // If true, a separate process will be used for the extension in incognito
797 // mode.
798 bool incognito_split_mode_;
799
[email protected]1abdf4f2011-08-16 21:11:55800 // Whether the extension or app should be enabled when offline.
801 bool offline_enabled_;
802
[email protected]6f229e82010-11-02 17:47:26803 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12804 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26805
[email protected]902fd7b2011-07-27 18:42:31806 // The extension runtime data.
807 mutable base::Lock runtime_data_lock_;
808 mutable RuntimeData runtime_data_;
809
810 // The set of permissions the extension can request at runtime.
811 scoped_refptr<const ExtensionPermissionSet> optional_permission_set_;
812
813 // The extension's required / default set of permissions.
814 scoped_refptr<const ExtensionPermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26815
816 // The icons for the extension.
817 ExtensionIconSet icons_;
818
819 // The base extension url for the extension.
820 GURL extension_url_;
821
[email protected]6f229e82010-11-02 17:47:26822 // The extension's version.
823 scoped_ptr<Version> version_;
824
825 // An optional longer description of the extension.
826 std::string description_;
827
828 // True if the extension was generated from a user script. (We show slightly
829 // different UI if so).
830 bool converted_from_user_script_;
831
832 // Paths to the content scripts the extension contains.
833 UserScriptList content_scripts_;
834
835 // The extension's page action, if any.
836 scoped_ptr<ExtensionAction> page_action_;
837
838 // The extension's browser action, if any.
839 scoped_ptr<ExtensionAction> browser_action_;
840
[email protected]b6b805e92011-04-16 09:24:14841 // The extension's file browser actions, if any.
842 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
843
[email protected]6f229e82010-11-02 17:47:26844 // Optional list of NPAPI plugins and associated properties.
845 std::vector<PluginInfo> plugins_;
846
[email protected]65378f52011-04-08 02:31:23847 // Optional list of NaCl modules and associated properties.
848 std::vector<NaClModuleInfo> nacl_modules_;
849
[email protected]b0820372011-06-03 07:05:27850 // Optional list of input components and associated properties.
851 std::vector<InputComponentInfo> input_components_;
852
[email protected]f5532472012-02-23 13:00:55853 // Optional list of commands (keyboard shortcuts).
854 std::vector<ExtensionKeybinding> commands_;
855
[email protected]8f270be2011-12-21 21:15:22856 // Optional list of web accessible extension resources.
857 base::hash_set<std::string> web_accessible_resources_;
858
[email protected]6f229e82010-11-02 17:47:26859 // Optional URL to a master page of which a single instance should be always
860 // loaded in the background.
861 GURL background_url_;
862
[email protected]a03d4448f2012-01-10 23:25:28863 // Optional list of scripts to use to generate a background page. If this is
864 // present, background_url_ will be empty and generated by GetBackgroundURL().
865 std::vector<std::string> background_scripts_;
866
[email protected]9e6720a2012-01-24 02:30:56867 // True if the background page should stay loaded forever; false if it should
868 // load on-demand (when it needs to handle an event). Defaults to true.
869 bool background_page_persists_;
870
[email protected]7b54ca02012-03-02 18:06:53871 // True if the background page can be scripted by pages of the app or
872 // extension, in which case all such pages must run in the same process.
873 // False if such pages are not permitted to script the background page,
874 // allowing them to run in different processes.
875 bool allow_background_js_access_;
876
[email protected]6f229e82010-11-02 17:47:26877 // Optional URL to a page for setting options/preferences.
878 GURL options_url_;
879
880 // Optional URL to a devtools extension page.
881 GURL devtools_url_;
882
[email protected]6f229e82010-11-02 17:47:26883 // The public key used to sign the contents of the crx package.
884 std::string public_key_;
885
886 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:03887 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:26888
889 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03890 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:26891
892 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03893 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:26894
895 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:03896 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:26897
[email protected]6f229e82010-11-02 17:47:26898 // The homepage for this extension. Useful if it is not hosted by Google and
899 // therefore does not have a Gallery URL.
900 GURL homepage_url_;
901
902 // URL for fetching an update manifest
903 GURL update_url_;
904
[email protected]953620b2011-12-04 00:55:32905 // The manifest that this extension was created from.
[email protected]d41e2152012-02-24 04:20:27906 //
907 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would
908 // require manifest.h, which would in turn create a circulate dependency
909 // between extension.h and manifest.h.
910 //
911 // TODO(aa): Pull Extension::Type and Extension::Location out into their own
912 // files so that manifest.h can rely on them and not get all of extension.h
913 // too, and then change this back to a scoped_ptr.
914 extensions::Manifest* manifest_;
[email protected]6f229e82010-11-02 17:47:26915
916 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
917 // which override the handling of those URLs. (see ExtensionOverrideUI).
918 URLOverrideMap chrome_url_overrides_;
919
[email protected]d9696672011-03-15 22:45:09920 // Whether this extension requests isolated storage.
921 bool is_storage_isolated_;
922
[email protected]6f229e82010-11-02 17:47:26923 // The local path inside the extension to use with the launcher.
924 std::string launch_local_path_;
925
926 // A web url to use with the launcher. Note that this might be relative or
927 // absolute. If relative, it is relative to web_origin.
928 std::string launch_web_url_;
929
[email protected]4e595682011-02-09 17:07:02930 // The window type that an app's manifest specifies to launch into.
931 // This is not always the window type an app will open into, because
932 // users can override the way each app launches. See
933 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
934 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:26935 extension_misc::LaunchContainer launch_container_;
936
937 // The default size of the container when launching. Only respected for
938 // containers like panels and windows.
939 int launch_width_;
940 int launch_height_;
941
[email protected]f8c3aea2012-03-01 07:23:20942 // The minimum and maximum size of the container. Only respected for the
943 // shell container.
[email protected]e5cd5502012-02-29 03:56:43944 int launch_min_width_;
945 int launch_min_height_;
[email protected]f8c3aea2012-03-01 07:23:20946 int launch_max_width_;
947 int launch_max_height_;
[email protected]e5cd5502012-02-29 03:56:43948
[email protected]6f229e82010-11-02 17:47:26949 // The Omnibox keyword for this extension, or empty if there is none.
950 std::string omnibox_keyword_;
951
[email protected]a4a38c12010-12-23 16:43:56952 // List of text-to-speech voices that this extension provides, if any.
953 std::vector<TtsVoice> tts_voices_;
954
[email protected]56624422011-11-01 22:11:27955 // List of intent services that this extension provides, if any.
956 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
[email protected]be5f007862011-09-23 00:35:13957
[email protected]3aff9ad2011-04-01 20:26:48958 // Whether the extension has host permissions or user script patterns that
959 // imply access to file:/// scheme URLs (the user may not have actually
960 // granted it that access).
961 bool wants_file_access_;
962
[email protected]2af352b2011-07-22 08:21:23963 // The flags that were passed to InitFromValue.
964 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34965
[email protected]7f7b9d932011-04-20 16:13:26966 // The Content-Security-Policy for this extension. Extensions can use
967 // Content-Security-Policies to mitigate cross-site scripting and other
968 // vulnerabilities.
969 std::string content_security_policy_;
970
[email protected]19118d52010-07-26 22:13:42971 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
972 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58973
[email protected]894bb502009-05-21 22:39:57974 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33975};
976
[email protected]9adb9692010-10-29 23:14:02977typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:18978typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:56979
[email protected]c6d474f82009-12-16 21:11:06980// Handy struct to pass core extension info around.
981struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03982 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:06983 const std::string& id,
984 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:46985 Extension::Location location);
986 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06987
[email protected]f3a1c642011-07-12 19:15:03988 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:06989 std::string extension_id;
990 FilePath extension_path;
991 Extension::Location extension_location;
992
993 private:
994 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
995};
996
[email protected]a9f39a312010-12-23 22:14:27997struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:59998 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:27999
1000 // Was the extension already disabled?
1001 bool already_disabled;
1002
1003 // The extension being unloaded - this should always be non-NULL.
1004 const Extension* extension;
1005
[email protected]814a7bf0f2011-08-13 05:30:591006 UnloadedExtensionInfo(
1007 const Extension* extension,
1008 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:271009};
1010
[email protected]902fd7b2011-07-27 18:42:311011// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
1012struct UpdatedExtensionPermissionsInfo {
1013 enum Reason {
[email protected]f5532472012-02-23 13:00:551014 ADDED, // The permissions were added to the extension.
1015 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:311016 };
1017
1018 Reason reason;
1019
1020 // The extension who's permissions have changed.
1021 const Extension* extension;
1022
1023 // The permissions that have changed. For Reason::ADDED, this would contain
1024 // only the permissions that have added, and for Reason::REMOVED, this would
1025 // only contain the removed permissions.
1026 const ExtensionPermissionSet* permissions;
1027
1028 UpdatedExtensionPermissionsInfo(
1029 const Extension* extension,
1030 const ExtensionPermissionSet* permissions,
1031 Reason reason);
1032};
1033
[email protected]5b1a0e22009-05-26 19:00:581034#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_