blob: ce5dbf5e1502e2a9a7eee8ffdf5625b9ac90a60b [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]8629c542012-04-20 03:40:039#include <algorithm>
[email protected]300cc58db2009-08-19 20:45:1410#include <map>
[email protected]facd7a7652009-06-05 23:15:0211#include <set>
[email protected]7713d632008-12-02 07:52:3312#include <string>
[email protected]58f62cf2012-03-09 10:45:1113#include <utility>
[email protected]7713d632008-12-02 07:52:3314#include <vector>
15
[email protected]6014d672008-12-05 00:38:2516#include "base/file_path.h"
[email protected]19118d52010-07-26 22:13:4217#include "base/gtest_prod_util.h"
[email protected]8f270be2011-12-21 21:15:2218#include "base/hash_tables.h"
[email protected]b6b805e92011-04-16 09:24:1419#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1520#include "base/memory/ref_counted.h"
21#include "base/memory/scoped_ptr.h"
[email protected]902fd7b2011-07-27 18:42:3122#include "base/synchronization/lock.h"
[email protected]65907942012-05-22 19:59:4723#include "chrome/common/extensions/command.h"
[email protected]3349b592012-04-26 12:35:2824#include "chrome/common/extensions/extension_action.h"
[email protected]d83a5602010-09-16 00:22:4825#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4826#include "chrome/common/extensions/extension_icon_set.h"
[email protected]0d3e4a22011-06-23 19:02:5227#include "chrome/common/extensions/extension_permission_set.h"
[email protected]42b6f0f82009-09-18 21:07:3928#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4929#include "chrome/common/extensions/url_pattern.h"
[email protected]cced75a2011-05-20 08:31:1230#include "chrome/common/extensions/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5931#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5532#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3833#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5934
[email protected]942690b132010-05-11 06:42:1435class ExtensionResource;
[email protected]b6b805e92011-04-16 09:24:1436class FileBrowserHandler;
[email protected]12802702010-07-09 19:43:0937class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2838class Version;
[email protected]942690b132010-05-11 06:42:1439
[email protected]f3a1c642011-07-12 19:15:0340namespace base {
41class DictionaryValue;
42class ListValue;
43}
44
[email protected]f0cc7242011-12-13 04:26:1745namespace webkit_glue {
46struct WebIntentServiceData;
47}
48
[email protected]1c321ee2012-05-21 03:02:3449FORWARD_DECLARE_TEST(TabStripModelTest, Apps);
50
51namespace extensions {
52
53class Manifest;
54
[email protected]f0755532010-06-22 07:27:2555// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4156class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3357 public:
[email protected]d3cfa482009-10-17 13:54:5758 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1759 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1460 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]b24d8312009-08-27 06:47:4661
[email protected]631cf822009-05-15 07:01:2562 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2363 // NOTE: These values are stored as integers in the preferences and used
64 // in histograms so don't remove or reorder existing items. Just append
65 // to the end.
[email protected]631cf822009-05-15 07:01:2566 enum Location {
67 INVALID,
[email protected]25b34332009-06-05 21:53:1968 INTERNAL, // A crx file from the internal Extensions directory.
69 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
70 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
71 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3472 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3273 COMPONENT, // An integral component of Chrome itself, which
74 // happens to be implemented as an extension. We don't
75 // show these in the management UI.
[email protected]4d2913e32010-11-30 00:28:5576 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via
77 // prefs), installed from an update URL.
78 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via
79 // admin policies), installed from an update URL.
[email protected]04cb7542010-10-25 10:50:0680
81 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1982 };
83
84 enum State {
[email protected]0c6da502009-08-14 22:32:3985 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1986 ENABLED,
[email protected]79c833b52011-04-05 18:31:0187 // An external extension that the user uninstalled. We should not reinstall
88 // such extensions on startup.
89 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:3990 NUM_STATES
[email protected]631cf822009-05-15 07:01:2591 };
[email protected]7713d632008-12-02 07:52:3392
[email protected]44d62b62012-04-11 00:06:0393 // Used to record the reason an extension was disabled.
94 enum DisableReason {
95 DISABLE_UNKNOWN,
96 DISABLE_USER_ACTION,
97 DISABLE_PERMISSIONS_INCREASE,
98 DISABLE_RELOAD,
99 DISABLE_LAST, // Not used.
100 };
101
[email protected]fbcc40302009-06-12 20:45:45102 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:37103 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:45104 DOWNGRADE,
105 REINSTALL,
106 UPGRADE,
107 NEW_INSTALL
108 };
109
[email protected]7fa19f82010-12-21 19:40:08110 // Do not change the order of entries or remove entries in this list
111 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
112 enum Type {
[email protected]9b217652010-10-08 22:04:23113 TYPE_UNKNOWN = 0,
114 TYPE_EXTENSION,
115 TYPE_THEME,
116 TYPE_USER_SCRIPT,
117 TYPE_HOSTED_APP,
[email protected]7d3ed2f2011-11-07 23:33:19118 TYPE_PACKAGED_APP,
119 TYPE_PLATFORM_APP
[email protected]9b217652010-10-08 22:04:23120 };
121
[email protected]3bdba0d2011-08-23 07:17:30122 enum SyncType {
123 SYNC_TYPE_NONE = 0,
124 SYNC_TYPE_EXTENSION,
125 SYNC_TYPE_APP
126 };
127
[email protected]92888082010-10-18 19:24:57128 // An NPAPI plugin included in the extension.
129 struct PluginInfo {
130 FilePath path; // Path to the plugin.
131 bool is_public; // False if only this extension can load this plugin.
132 };
133
[email protected]65378f52011-04-08 02:31:23134 // An NaCl module included in the extension.
135 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42136 GURL url;
[email protected]65378f52011-04-08 02:31:23137 std::string mime_type;
138 };
139
[email protected]b0820372011-06-03 07:05:27140 enum InputComponentType {
[email protected]d45f7512011-06-21 21:18:27141 INPUT_COMPONENT_TYPE_NONE = -1,
142 INPUT_COMPONENT_TYPE_IME,
[email protected]b0820372011-06-03 07:05:27143 INPUT_COMPONENT_TYPE_COUNT
144 };
145
146 struct InputComponentInfo {
147 // Define out of line constructor/destructor to please Clang.
148 InputComponentInfo();
149 ~InputComponentInfo();
150
151 std::string name;
152 InputComponentType type;
153 std::string id;
154 std::string description;
155 std::string language;
156 std::set<std::string> layouts;
157 std::string shortcut_keycode;
158 bool shortcut_alt;
159 bool shortcut_ctrl;
160 bool shortcut_shift;
161 };
162
[email protected]a4a38c12010-12-23 16:43:56163 struct TtsVoice {
[email protected]77a3ecac2011-07-07 05:56:33164 // Define out of line constructor/destructor to please Clang.
165 TtsVoice();
166 ~TtsVoice();
167
[email protected]a4a38c12010-12-23 16:43:56168 std::string voice_name;
[email protected]c63f2b72011-07-07 05:25:00169 std::string lang;
[email protected]a4a38c12010-12-23 16:43:56170 std::string gender;
[email protected]c63f2b72011-07-07 05:25:00171 std::set<std::string> event_types;
[email protected]a4a38c12010-12-23 16:43:56172 };
173
[email protected]a79be1f2012-03-23 22:14:00174 // OAuth2 info included in the extension.
175 struct OAuth2Info {
176 OAuth2Info();
177 ~OAuth2Info();
178
[email protected]b6f38622012-04-25 03:20:19179 ExtensionOAuth2Scopes GetScopesAsSet();
180
[email protected]a79be1f2012-03-23 22:14:00181 std::string client_id;
182 std::vector<std::string> scopes;
183 };
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]3d41d432012-04-20 20:47:58223
224 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
225 // anywhere in the filesystem, rather than being restricted to the
226 // extension directory.
227 FOLLOW_SYMLINKS_ANYWHERE = 1 << 6,
[email protected]83048a22011-03-29 00:14:13228 };
229
[email protected]66e4eb32010-10-27 20:37:41230 static scoped_refptr<Extension> Create(const FilePath& path,
231 Location location,
[email protected]f3a1c642011-07-12 19:15:03232 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13233 int flags,
[email protected]66e4eb32010-10-27 20:37:41234 std::string* error);
235
[email protected]87c655e2011-07-01 21:42:00236 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26237 // an explicit id. Most consumers should just use the other Create() method.
238 static scoped_refptr<Extension> Create(const FilePath& path,
[email protected]58f62cf2012-03-09 10:45:11239 Location location,
240 const base::DictionaryValue& value,
241 int flags,
242 const std::string& explicit_id,
243 std::string* error);
[email protected]87c655e2011-07-01 21:42:00244
[email protected]145a317b2011-04-12 16:03:46245 // Given two install sources, return the one which should take priority
246 // over the other. If an extension is installed from two sources A and B,
247 // its install source should be set to GetHigherPriorityLocation(A, B).
248 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
249
[email protected]4c4f8192009-10-17 01:03:26250 // Max size (both dimensions) for browser and page actions.
251 static const int kPageActionIconMaxSize;
252 static const int kBrowserActionIconMaxSize;
253
[email protected]8d888c12010-11-30 00:00:25254 // Valid schemes for web extent URLPatterns.
255 static const int kValidWebExtentSchemes;
256
[email protected]f71f7e62010-12-07 03:45:33257 // Valid schemes for host permission URLPatterns.
258 static const int kValidHostPermissionSchemes;
259
[email protected]6014d672008-12-05 00:38:25260 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16261 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25262
[email protected]300cc58db2009-08-19 20:45:14263 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16264 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14265
266 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16267 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14268
[email protected]25b34332009-06-05 21:53:19269#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19270 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19271#endif
272
[email protected]37eeb5a2009-02-26 23:36:17273 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48274 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17275
[email protected]e435d6b72009-07-25 03:15:58276 // The mimetype used for extensions.
277 static const char kMimeType[];
278
[email protected]25b34332009-06-05 21:53:19279 // Checks to see if the extension has a valid ID.
280 static bool IdIsValid(const std::string& id);
281
[email protected]4ead6f72010-10-13 19:54:18282 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27283 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18284 static std::string GenerateIdForPath(const FilePath& file_name);
285
[email protected]e435d6b72009-07-25 03:15:58286 // Returns true if the specified file is an extension.
287 static bool IsExtension(const FilePath& file_name);
288
[email protected]25b34332009-06-05 21:53:19289 // Whether the |location| is external or not.
290 static inline bool IsExternalLocation(Location location) {
291 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32292 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06293 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
294 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
295 }
296
297 // Whether extensions with |location| are auto-updatable or not.
298 static inline bool IsAutoUpdateableLocation(Location location) {
299 // Only internal and external extensions can be autoupdated.
300 return location == Extension::INTERNAL ||
301 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19302 }
303
[email protected]95da88c42011-03-31 10:07:33304 // Whether extensions with |location| can be uninstalled or not. Policy
305 // controlled extensions are silently auto-installed and updated, and cannot
306 // be disabled by the user. The same applies for internal components.
307 static inline bool UserMayDisable(Location location) {
308 return location != Extension::EXTERNAL_POLICY_DOWNLOAD &&
309 location != Extension::COMPONENT;
310 }
311
[email protected]542258c2011-03-04 21:25:31312 // Whether extensions with |location| should be loaded with strict
313 // error checking. Strict error checks may flag errors older versions
314 // of chrome did not detect. To avoid breaking installed extensions,
315 // strict checks are disabled unless the location indicates that the
316 // developer is loading the extension, or the extension is a component
317 // of chrome.
318 static inline bool ShouldDoStrictErrorChecking(Location location) {
319 return location == Extension::LOAD ||
320 location == Extension::COMPONENT;
321 }
322
[email protected]cdfca9702011-08-08 16:07:01323 // Unpacked extensions start off with file access since they are a developer
324 // feature.
325 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
326 return location == Extension::LOAD;
327 }
328
[email protected]fc6b0612012-03-29 13:40:06329 // Fills the |info| dictionary with basic information about the extension.
330 // |enabled| is injected for easier testing.
331 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const;
332
[email protected]7fa19f82010-12-21 19:40:08333 // See Type definition above.
334 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23335
[email protected]07c00d992009-03-04 20:27:04336 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59337 // |extension_url| argument should be the url() from an Extension object. The
338 // |relative_path| can be untrusted user input. The returned URL will either
339 // be invalid() or a child of |extension_url|.
340 // NOTE: Static so that it can be used from multiple threads.
341 static GURL GetResourceURL(const GURL& extension_url,
342 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28343 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24344 return GetResourceURL(url(), relative_path);
345 }
[email protected]eab9b452009-01-23 20:48:59346
[email protected]8f270be2011-12-21 21:15:22347 // Returns true if the specified resource is web accessible.
348 bool IsResourceWebAccessible(const std::string& relative_path) const;
349
350 // Returns true when 'web_accessible_resources' are defined for the extension.
351 bool HasWebAccessibleResources() const;
352
[email protected]99efb7b12009-12-18 02:39:16353 // Returns an extension resource object. |relative_path| should be UTF8
354 // encoded.
[email protected]9adb9692010-10-29 23:14:02355 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16356
357 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02358 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59359
[email protected]a17f9462009-06-09 02:56:41360 // |input| is expected to be the text of an rsa public or private key. It
361 // tolerates the presence or absence of bracking header/footer like this:
362 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
363 // and may contain newlines.
364 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
365
366 // Does a simple base64 encoding of |input| into |output|.
367 static bool ProducePEM(const std::string& input, std::string* output);
368
[email protected]84ac7f32009-10-06 06:17:54369 // Generates an extension ID from arbitrary input. The same input string will
370 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15371 static bool GenerateId(const std::string& input,
372 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45373
[email protected]a17f9462009-06-09 02:56:41374 // Expects base64 encoded |input| and formats into |output| including
375 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50376 static bool FormatPEMForFileOutput(const std::string& input,
377 std::string* output,
378 bool is_public);
[email protected]a17f9462009-06-09 02:56:41379
[email protected]58f62cf2012-03-09 10:45:11380 // Given an extension, icon size, and match type, read a valid icon if present
[email protected]e3c0bc22012-02-24 01:34:15381 // and decode it into result. In the browser process, this will DCHECK if not
382 // called on the file thread. To easily load extension images on the UI
383 // thread, see ImageLoadingTracker.
384 static void DecodeIcon(const Extension* extension,
385 ExtensionIconSet::Icons icon_size,
386 ExtensionIconSet::MatchType match_type,
387 scoped_ptr<SkBitmap>* result);
388
[email protected]c690a9812009-12-17 05:55:32389 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23390 // result. In the browser process, this will DCHECK if not called on the
391 // file thread. To easily load extension images on the UI thread, see
392 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02393 static void DecodeIcon(const Extension* extension,
[email protected]e3c0bc22012-02-24 01:34:15394 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32395 scoped_ptr<SkBitmap>* result);
396
397 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23398 // result. In the browser process, this will DCHECK if not called on the
399 // file thread. To easily load extension images on the UI thread, see
400 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32401 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]e3c0bc22012-02-24 01:34:15402 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32403 scoped_ptr<SkBitmap>* result);
404
[email protected]5349ac6d2011-04-05 22:20:17405 // Returns the default extension/app icon (for extensions or apps that don't
406 // have one).
407 static const SkBitmap& GetDefaultIcon(bool is_app);
408
[email protected]a807bbe2010-04-14 10:51:19409 // Returns the base extension url for a given |extension_id|.
410 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
411
[email protected]be7e5cb2010-10-04 12:53:17412 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17413 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21414 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17415
[email protected]902fd7b2011-07-27 18:42:31416 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27417 // from |manifest_|.
418 bool ParsePermissions(const char* key,
[email protected]fc670822011-12-17 09:33:49419 string16* error,
[email protected]902fd7b2011-07-27 18:42:31420 ExtensionAPIPermissionSet* api_permissions,
421 URLPatternSet* host_permissions);
422
[email protected]0d3e4a22011-06-23 19:02:52423 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const;
424 bool HasAPIPermission(const std::string& function_name) const;
[email protected]583d45c12010-08-31 02:48:12425
[email protected]0d3e4a22011-06-23 19:02:52426 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46427
[email protected]902fd7b2011-07-27 18:42:31428 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16429 // Users must approve permissions for unpacked and packed extensions in the
430 // following situations:
431 // - when installing or upgrading packed extensions
432 // - when installing unpacked extensions that have NPAPI plugins
433 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31434 bool CanSilentlyIncreasePermissions() const;
435
[email protected]584b8e3f2010-04-10 00:23:37436 // Whether the extension has access to the given URL.
437 bool HasHostPermission(const GURL& url) const;
438
[email protected]0df165f2010-09-28 16:49:40439 // Whether the extension has effective access to all hosts. This is true if
440 // there is a content script that matches all hosts, if there is a host
441 // permission grants access to all hosts (like <all_urls>) or an api
442 // permission that effectively grants access to all hosts (e.g. proxy,
443 // network, etc.)
444 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46445
[email protected]8d888c12010-11-30 00:00:25446 // Whether the extension effectively has all permissions (for example, by
447 // having an NPAPI plugin).
448 bool HasFullPermissions() const;
449
[email protected]902fd7b2011-07-27 18:42:31450 // Returns the full list of permission messages that this extension
451 // should display at install time.
452 ExtensionPermissionMessages GetPermissionMessages() const;
453
454 // Returns the full list of permission messages that this extension
455 // should display at install time. The messages are returned as strings
456 // for convenience.
457 std::vector<string16> GetPermissionMessageStrings() const;
458
459 // Sets the active |permissions|.
460 void SetActivePermissions(const ExtensionPermissionSet* permissions) const;
461
462 // Gets the extension's active permission set.
463 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
464
[email protected]5df6a5d2011-01-26 07:39:12465 // Whether context menu should be shown for page and browser actions.
466 bool ShowConfigureContextMenus() const;
467
[email protected]37cd64d2010-10-25 18:17:58468 // Returns the Homepage URL for this extension. If homepage_url was not
469 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23470 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58471 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23472
[email protected]facd7a7652009-06-05 23:15:02473 // Returns a list of paths (relative to the extension dir) for images that
474 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02475 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02476
[email protected]807871f2010-09-16 01:04:48477 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02478 ExtensionResource GetIconResource(
479 int size, ExtensionIconSet::MatchType match_type) const;
480 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08481
[email protected]867a73e12010-03-19 20:45:46482 // Gets the fully resolved absolute launch URL.
483 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21484
[email protected]6f229e82010-11-02 17:47:26485 // Image cache related methods. These are only valid on the UI thread and
486 // not maintained by this class. See ImageLoadingTracker for usage. The
487 // |original_size| parameter should be the size of the image at |source|
488 // before any scaling may have been done to produce the pixels in |image|.
489 void SetCachedImage(const ExtensionResource& source,
490 const SkBitmap& image,
491 const gfx::Size& original_size) const;
492 bool HasCachedImage(const ExtensionResource& source,
493 const gfx::Size& max_size) const;
494 SkBitmap GetCachedImage(const ExtensionResource& source,
495 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21496
497 // Returns true if this extension can execute script on a page. If a
498 // UserScript object is passed, permission to run that specific script is
499 // checked (using its matches list). Otherwise, permission to execute script
500 // programmatically is checked (using the extension's host permission).
501 //
502 // This method is also aware of certain special pages that extensions are
503 // usually not allowed to run script on.
504 bool CanExecuteScriptOnPage(const GURL& page_url,
[email protected]3aff9ad2011-04-01 20:26:48505 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21506 std::string* error) const;
507
[email protected]6f229e82010-11-02 17:47:26508 // Returns true if this extension is a COMPONENT extension, or if it is
509 // on the whitelist of extensions that can script all pages.
510 bool CanExecuteScriptEverywhere() const;
511
[email protected]5efbfe012011-02-22 23:07:18512 // Returns true if this extension is allowed to obtain the contents of a
513 // page as an image. Since a page may contain sensitive information, this
514 // is restricted to the extension's host permissions as well as the
515 // extension page itself.
516 bool CanCaptureVisiblePage(const GURL& page_url, std::string* error) const;
517
[email protected]a65882c2010-11-12 15:15:09518 // Returns true if this extension updates itself using the extension
519 // gallery.
520 bool UpdatesFromGallery() const;
521
[email protected]cca147172011-02-17 01:29:29522 // Returns true if this extension or app includes areas within |origin|.
523 bool OverlapsWithOrigin(const GURL& origin) const;
524
[email protected]3bdba0d2011-08-23 07:17:30525 // Returns the sync bucket to use for this extension.
526 SyncType GetSyncType() const;
527
[email protected]b873cd92012-02-09 21:51:48528 // Returns true if the extension should be synced.
529 bool IsSyncable() const;
530
531 // Returns true if the extension should be displayed in the launcher.
532 bool ShouldDisplayInLauncher() const;
533
[email protected]e0b3de72012-05-01 01:21:34534 // Returns true if the extension should be displayed in the extension
535 // settings page (i.e. chrome://extensions).
536 bool ShouldDisplayInExtensionSettings() const;
537
[email protected]4f886012012-05-19 03:51:10538 // Returns true if the extension has a content script declared at |url|.
539 bool HasContentScriptAtURL(const GURL& url) const;
540
[email protected]6f229e82010-11-02 17:47:26541 // Accessors:
542
543 const FilePath& path() const { return path_; }
544 const GURL& url() const { return extension_url_; }
[email protected]d41e2152012-02-24 04:20:27545 Location location() const;
546 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26547 const Version* version() const { return version_.get(); }
548 const std::string VersionString() const;
549 const std::string& name() const { return name_; }
[email protected]701d1e82012-05-14 05:34:19550 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]d41e2152012-02-24 04:20:27551 const std::string public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26552 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31553 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26554 bool converted_from_user_script() const {
555 return converted_from_user_script_;
556 }
557 const UserScriptList& content_scripts() const { return content_scripts_; }
558 ExtensionAction* page_action() const { return page_action_.get(); }
559 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]3e819002012-04-30 07:57:55560 ExtensionAction::Type declared_action_type() const {
561 return declared_action_type_;
[email protected]3349b592012-04-26 12:35:28562 }
[email protected]b6b805e92011-04-16 09:24:14563 const FileBrowserHandlerList* file_browser_handlers() const {
564 return file_browser_handlers_.get();
565 }
[email protected]6f229e82010-11-02 17:47:26566 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23567 const std::vector<NaClModuleInfo>& nacl_modules() const {
568 return nacl_modules_;
569 }
[email protected]b0820372011-06-03 07:05:27570 const std::vector<InputComponentInfo>& input_components() const {
571 return input_components_;
572 }
[email protected]7c519ab2012-05-04 10:02:51573 // The browser action command that the extension wants to use, which is not
574 // necessarily the one it can use, as it might be inactive (see also
575 // GetActiveBrowserActionCommand in ExtensionKeybindingRegistry).
[email protected]3fc5f6a2012-05-04 14:23:59576 const extensions::Command* browser_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30577 return browser_action_command_.get();
578 }
[email protected]7c519ab2012-05-04 10:02:51579 // The page action command that the extension wants to use, which is not
580 // necessarily the one it can use, as it might be inactive (see also
581 // GetActivePageActionCommand in ExtensionKeybindingRegistry).
[email protected]3fc5f6a2012-05-04 14:23:59582 const extensions::Command* page_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30583 return page_action_command_.get();
584 }
[email protected]7c519ab2012-05-04 10:02:51585 // The map (of command names to commands) that the extension wants to use,
[email protected]422656932012-05-03 09:31:51586 // which is not necessarily the one it can use, as they might be inactive
587 // (see also GetActiveNamedCommands in ExtensionKeybindingRegistry).
[email protected]3fc5f6a2012-05-04 14:23:59588 const extensions::CommandMap& named_commands() const {
[email protected]9c8b54d2012-04-02 10:17:30589 return named_commands_;
[email protected]f5532472012-02-23 13:00:55590 }
[email protected]a03d4448f2012-01-10 23:25:28591 bool has_background_page() const {
592 return background_url_.is_valid() || !background_scripts_.empty();
593 }
[email protected]7b54ca02012-03-02 18:06:53594 bool allow_background_js_access() const {
595 return allow_background_js_access_;
596 }
[email protected]a03d4448f2012-01-10 23:25:28597 const std::vector<std::string>& background_scripts() const {
598 return background_scripts_;
599 }
[email protected]d2aa06b2012-03-21 20:57:26600 bool has_persistent_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00601 return has_background_page() && background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26602 }
603 bool has_lazy_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00604 return has_background_page() && !background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26605 }
[email protected]6f229e82010-11-02 17:47:26606 const GURL& options_url() const { return options_url_; }
607 const GURL& devtools_url() const { return devtools_url_; }
[email protected]902fd7b2011-07-27 18:42:31608 const ExtensionPermissionSet* optional_permission_set() const {
609 return optional_permission_set_.get();
610 }
611 const ExtensionPermissionSet* required_permission_set() const {
612 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26613 }
[email protected]8629c542012-04-20 03:40:03614 const std::vector<std::string>& install_warnings() const {
615 return install_warnings_;
616 }
[email protected]6f229e82010-11-02 17:47:26617 const GURL& update_url() const { return update_url_; }
618 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32619 const extensions::Manifest* manifest() const {
[email protected]d41e2152012-02-24 04:20:27620 return manifest_;
[email protected]6f229e82010-11-02 17:47:26621 }
622 const std::string default_locale() const { return default_locale_; }
623 const URLOverrideMap& GetChromeURLOverrides() const {
624 return chrome_url_overrides_;
625 }
626 const std::string omnibox_keyword() const { return omnibox_keyword_; }
627 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55628 bool offline_enabled() const { return offline_enabled_; }
[email protected]a4a38c12010-12-23 16:43:56629 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]a79be1f2012-03-23 22:14:00630 const OAuth2Info& oauth2_info() const { return oauth2_info_; }
[email protected]56624422011-11-01 22:11:27631 const std::vector<webkit_glue::WebIntentServiceData>&
632 intents_services() const {
633 return intents_services_;
634 }
[email protected]6f229e82010-11-02 17:47:26635
[email protected]3aff9ad2011-04-01 20:26:48636 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23637 int creation_flags() const { return creation_flags_; }
638 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05639 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]3aff9ad2011-04-01 20:26:48640
[email protected]7f7b9d932011-04-20 16:13:26641 const std::string& content_security_policy() const {
642 return content_security_policy_;
643 }
644
[email protected]6f229e82010-11-02 17:47:26645 // App-related.
[email protected]953620b2011-12-04 00:55:32646 bool is_app() const {
647 return is_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39648 }
[email protected]d41e2152012-02-24 04:20:27649 bool is_platform_app() const;
650 bool is_hosted_app() const;
651 bool is_packaged_app() const;
[email protected]605fb8102012-05-04 01:36:55652 bool is_storage_isolated() const { return is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12653 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26654 const std::string& launch_local_path() const { return launch_local_path_; }
655 const std::string& launch_web_url() const { return launch_web_url_; }
656 extension_misc::LaunchContainer launch_container() const {
657 return launch_container_;
658 }
[email protected]dc37b002012-04-23 23:02:26659 int launch_width() const { return launch_width_; }
660 int launch_height() const { return launch_height_; }
[email protected]6f229e82010-11-02 17:47:26661
662 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27663 bool is_theme() const;
[email protected]f3a1c642011-07-12 19:15:03664 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
665 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
666 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
667 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26668 return theme_display_properties_.get();
669 }
670
[email protected]a03d4448f2012-01-10 23:25:28671 GURL GetBackgroundURL() const;
672
[email protected]4a8d3272009-03-10 19:15:08673 private:
[email protected]66e4eb32010-10-27 20:37:41674 friend class base::RefCountedThreadSafe<Extension>;
675
[email protected]d7e9a862010-11-03 21:57:49676 // We keep a cache of images loaded from extension resources based on their
677 // path and a string representation of a size that may have been used to
678 // scale it (or the empty string if the image is at its original size).
679 typedef std::pair<FilePath, std::string> ImageCacheKey;
680 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
681
[email protected]902fd7b2011-07-27 18:42:31682 class RuntimeData {
683 public:
684 RuntimeData();
685 explicit RuntimeData(const ExtensionPermissionSet* active);
686 ~RuntimeData();
687
688 void SetActivePermissions(const ExtensionPermissionSet* active);
689 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
690
691 private:
692 friend class base::RefCountedThreadSafe<RuntimeData>;
693 scoped_refptr<const ExtensionPermissionSet> active_permissions_;
694 };
695
[email protected]d41e2152012-02-24 04:20:27696 // Chooses the extension ID for an extension based on a variety of criteria.
697 // The chosen ID will be set in |manifest|.
698 static bool InitExtensionID(extensions::Manifest* manifest,
699 const FilePath& path,
700 const std::string& explicit_id,
701 int creation_flags,
702 string16* error);
703
[email protected]4ead6f72010-10-13 19:54:18704 // Normalize the path for use by the extension. On Windows, this will make
705 // sure the drive letter is uppercase.
706 static FilePath MaybeNormalizePath(const FilePath& path);
707
[email protected]87c655e2011-07-01 21:42:00708 // Returns true if this extension id is from a trusted provider.
709 static bool IsTrustedId(const std::string& id);
710
[email protected]d41e2152012-02-24 04:20:27711 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
[email protected]66e4eb32010-10-27 20:37:41712 ~Extension();
713
714 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27715 // TODO(aa): Rename to just Init()? There's no Value here anymore.
716 // TODO(aa): It is really weird the way this class essentially contains a copy
717 // of the underlying DictionaryValue in its members. We should decide to
718 // either wrap the DictionaryValue and go with that only, or we should parse
719 // into strong types and discard the value. But doing both is bad.
720 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41721
[email protected]58f62cf2012-03-09 10:45:11722 // The following are helpers for InitFromValue to load various features of the
723 // extension from the manifest.
724
725 bool CheckMinimumChromeVersion(string16* error);
[email protected]605fb8102012-05-04 01:36:55726 bool LoadAppIsolation(const ExtensionAPIPermissionSet& api_permissions,
727 string16* error);
[email protected]58f62cf2012-03-09 10:45:11728
729 bool LoadRequiredFeatures(string16* error);
730 bool LoadName(string16* error);
731 bool LoadVersion(string16* error);
732
733 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27734 bool LoadExtent(const char* key,
735 URLPatternSet* extent,
736 const char* list_error,
737 const char* value_error,
738 string16* error);
739 bool LoadLaunchContainer(string16* error);
740 bool LoadLaunchURL(string16* error);
[email protected]10253da2012-03-09 04:06:42741
[email protected]58f62cf2012-03-09 10:45:11742 bool LoadSharedFeatures(const ExtensionAPIPermissionSet& api_permissions,
743 string16* error);
744 bool LoadDescription(string16* error);
745 bool LoadManifestVersion(string16* error);
746 bool LoadHomepageURL(string16* error);
747 bool LoadUpdateURL(string16* error);
748 bool LoadIcons(string16* error);
749 bool LoadCommands(string16* error);
750 bool LoadPlugins(string16* error);
751 bool LoadNaClModules(string16* error);
752 bool LoadWebAccessibleResources(string16* error);
753 bool CheckRequirements(string16* error);
754 bool LoadDefaultLocale(string16* error);
755 bool LoadOfflineEnabled(string16* error);
756 bool LoadOptionsPage(string16* error);
[email protected]d41e2152012-02-24 04:20:27757 bool LoadBackgroundScripts(string16* error);
758 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions,
759 string16* error);
[email protected]dd62fa802012-04-25 18:37:00760 bool LoadBackgroundPersistent(
[email protected]d41e2152012-02-24 04:20:27761 const ExtensionAPIPermissionSet& api_permissions,
762 string16* error);
[email protected]58f62cf2012-03-09 10:45:11763 bool LoadBackgroundAllowJSAccess(
[email protected]7b54ca02012-03-02 18:06:53764 const ExtensionAPIPermissionSet& api_permissions,
765 string16* error);
[email protected]58f62cf2012-03-09 10:45:11766 // Parses a single action in the manifest.
767 bool LoadWebIntentAction(const std::string& action_name,
768 const base::DictionaryValue& intent_service,
769 string16* error);
770 bool LoadWebIntentServices(string16* error);
771 bool LoadExtensionFeatures(const ExtensionAPIPermissionSet& api_permissions,
772 string16* error);
773 bool LoadDevToolsPage(string16* error);
774 bool LoadInputComponents(const ExtensionAPIPermissionSet& api_permissions,
775 string16* error);
776 bool LoadContentScripts(string16* error);
777 bool LoadPageAction(string16* error);
778 bool LoadBrowserAction(string16* error);
[email protected]58f62cf2012-03-09 10:45:11779 bool LoadFileBrowserHandlers(string16* error);
780 // Helper method to load a FileBrowserHandlerList from the manifest.
781 FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
782 const base::ListValue* extension_actions, string16* error);
783 // Helper method to load an FileBrowserHandler from manifest.
784 FileBrowserHandler* LoadFileBrowserHandler(
785 const base::DictionaryValue* file_browser_handlers, string16* error);
786 bool LoadChromeURLOverrides(string16* error);
787 bool LoadOmnibox(string16* error);
788 bool LoadTextToSpeechVoices(string16* error);
789 bool LoadIncognitoMode(string16* error);
790 bool LoadContentSecurityPolicy(string16* error);
791
792 bool LoadThemeFeatures(string16* error);
793 bool LoadThemeImages(const base::DictionaryValue* theme_value,
794 string16* error);
795 bool LoadThemeColors(const base::DictionaryValue* theme_value,
796 string16* error);
797 bool LoadThemeTints(const base::DictionaryValue* theme_value,
798 string16* error);
799 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value,
800 string16* error);
801
802 // Helper function for implementing HasCachedImage/GetCachedImage. A return
803 // value of NULL means there is no matching image cached (we allow caching an
804 // empty SkBitmap).
805 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
806 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18807
[email protected]3cfbd0e2009-03-18 21:26:24808 // Helper method that loads a UserScript object from a
809 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03810 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24811 int definition_index,
[email protected]fc670822011-12-17 09:33:49812 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24813 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34814
[email protected]6657afa62009-11-04 02:15:20815 // Helper method that loads either the include_globs or exclude_globs list
816 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03817 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20818 int content_script_index,
[email protected]e2194742010-08-12 05:54:34819 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49820 string16* error,
[email protected]11f4857282009-11-13 19:56:17821 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20822 UserScript *instance);
823
[email protected]5d246db22009-10-27 06:17:57824 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08825 // browser_action entries in the manifest.
[email protected]3349b592012-04-26 12:35:28826 scoped_ptr<ExtensionAction> LoadExtensionActionHelper(
[email protected]fc670822011-12-17 09:33:49827 const base::DictionaryValue* extension_action, string16* error);
[email protected]92c6f9b92009-10-24 04:35:08828
[email protected]a79be1f2012-03-23 22:14:00829 // Helper method that loads the OAuth2 info from the 'oauth2' manifest key.
830 bool LoadOAuth2Info(string16* error);
831
[email protected]2f6698b2010-10-14 00:58:21832 // Returns true if the extension has more than one "UI surface". For example,
833 // an extension that has a browser action and a page action.
834 bool HasMultipleUISurfaces() const;
835
[email protected]be9d9c82011-07-13 04:17:31836 // Updates the launch URL and extents for the extension using the given
837 // |override_url|.
838 void OverrideLaunchUrl(const GURL& override_url);
839
[email protected]ae655e4e2012-03-16 21:47:55840 // Custom checks for the experimental permission that can't be expressed in
841 // _permission_features.json.
[email protected]5eddc3e2011-10-26 04:33:31842 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31843
844 // Checks whether the host |pattern| is allowed for this extension, given API
845 // permissions |permissions|.
846 bool CanSpecifyHostPermission(const URLPattern& pattern,
847 const ExtensionAPIPermissionSet& permissions) const;
848
[email protected]e92169e2012-05-04 22:49:32849 // Check that platform app features are valid. Called after InitFromValue.
850 bool CheckPlatformAppFeatures(std::string* utf8_error);
851
[email protected]f1bab9c92012-05-11 21:15:10852 // Check that features don't conflict. Called after InitFromValue.
853 bool CheckConflictingFeatures(std::string* utf8_error);
854
[email protected]d7e9a862010-11-03 21:57:49855 // Cached images for this extension. This should only be touched on the UI
856 // thread.
857 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31858
[email protected]6f229e82010-11-02 17:47:26859 // The extension's human-readable name. Name is used for display purpose. It
860 // might be wrapped with unicode bidi control characters so that it is
861 // displayed correctly in RTL context.
862 // NOTE: Name is UTF-8 and may contain non-ascii characters.
863 std::string name_;
864
[email protected]701d1e82012-05-14 05:34:19865 // A non-localized version of the extension's name. This is useful for
866 // debug output.
867 std::string non_localized_name_;
868
[email protected]a47c8a22011-11-17 18:40:31869 // The version of this extension's manifest. We increase the manifest
870 // version when making breaking changes to the extension system.
871 // Version 1 was the first manifest version (implied by a lack of a
872 // manifest_version attribute in the extension's manifest). We initialize
873 // this member variable to 0 to distinguish the "uninitialized" case from
874 // the case when we know the manifest version actually is 1.
875 int manifest_version_;
876
[email protected]d41e2152012-02-24 04:20:27877 // The absolute path to the directory the extension is stored in.
878 FilePath path_;
879
[email protected]6f229e82010-11-02 17:47:26880 // Default locale for fall back. Can be empty if extension is not localized.
881 std::string default_locale_;
882
883 // If true, a separate process will be used for the extension in incognito
884 // mode.
885 bool incognito_split_mode_;
886
[email protected]1abdf4f2011-08-16 21:11:55887 // Whether the extension or app should be enabled when offline.
888 bool offline_enabled_;
889
[email protected]6f229e82010-11-02 17:47:26890 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12891 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26892
[email protected]902fd7b2011-07-27 18:42:31893 // The extension runtime data.
894 mutable base::Lock runtime_data_lock_;
895 mutable RuntimeData runtime_data_;
896
897 // The set of permissions the extension can request at runtime.
898 scoped_refptr<const ExtensionPermissionSet> optional_permission_set_;
899
900 // The extension's required / default set of permissions.
901 scoped_refptr<const ExtensionPermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26902
[email protected]8629c542012-04-20 03:40:03903 // Any warnings that occurred when trying to create/parse the extension.
904 std::vector<std::string> install_warnings_;
905
[email protected]6f229e82010-11-02 17:47:26906 // The icons for the extension.
907 ExtensionIconSet icons_;
908
909 // The base extension url for the extension.
910 GURL extension_url_;
911
[email protected]6f229e82010-11-02 17:47:26912 // The extension's version.
913 scoped_ptr<Version> version_;
914
915 // An optional longer description of the extension.
916 std::string description_;
917
918 // True if the extension was generated from a user script. (We show slightly
919 // different UI if so).
920 bool converted_from_user_script_;
921
922 // Paths to the content scripts the extension contains.
923 UserScriptList content_scripts_;
924
925 // The extension's page action, if any.
926 scoped_ptr<ExtensionAction> page_action_;
927
928 // The extension's browser action, if any.
929 scoped_ptr<ExtensionAction> browser_action_;
930
[email protected]3e819002012-04-30 07:57:55931 // Indicates the type of action (browser or page) that the extension declared
932 // in its manifest. This doesn't imply any value for page_action or
933 // browser_action, since page actions may be turned into browser actions and
934 // browser actions may be generated without any action declared.
935 ExtensionAction::Type declared_action_type_;
[email protected]3349b592012-04-26 12:35:28936
[email protected]b6b805e92011-04-16 09:24:14937 // The extension's file browser actions, if any.
938 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
939
[email protected]6f229e82010-11-02 17:47:26940 // Optional list of NPAPI plugins and associated properties.
941 std::vector<PluginInfo> plugins_;
942
[email protected]65378f52011-04-08 02:31:23943 // Optional list of NaCl modules and associated properties.
944 std::vector<NaClModuleInfo> nacl_modules_;
945
[email protected]b0820372011-06-03 07:05:27946 // Optional list of input components and associated properties.
947 std::vector<InputComponentInfo> input_components_;
948
[email protected]f5532472012-02-23 13:00:55949 // Optional list of commands (keyboard shortcuts).
[email protected]3fc5f6a2012-05-04 14:23:59950 scoped_ptr<extensions::Command> browser_action_command_;
951 scoped_ptr<extensions::Command> page_action_command_;
952 extensions::CommandMap named_commands_;
[email protected]f5532472012-02-23 13:00:55953
[email protected]8f270be2011-12-21 21:15:22954 // Optional list of web accessible extension resources.
955 base::hash_set<std::string> web_accessible_resources_;
956
[email protected]6f229e82010-11-02 17:47:26957 // Optional URL to a master page of which a single instance should be always
958 // loaded in the background.
959 GURL background_url_;
960
[email protected]a03d4448f2012-01-10 23:25:28961 // Optional list of scripts to use to generate a background page. If this is
962 // present, background_url_ will be empty and generated by GetBackgroundURL().
963 std::vector<std::string> background_scripts_;
964
[email protected]dd62fa802012-04-25 18:37:00965 // True if the background page should stay loaded forever; false if it should
966 // load on-demand (when it needs to handle an event). Defaults to true.
967 bool background_page_is_persistent_;
[email protected]9e6720a2012-01-24 02:30:56968
[email protected]7b54ca02012-03-02 18:06:53969 // True if the background page can be scripted by pages of the app or
970 // extension, in which case all such pages must run in the same process.
971 // False if such pages are not permitted to script the background page,
972 // allowing them to run in different processes.
973 bool allow_background_js_access_;
974
[email protected]6f229e82010-11-02 17:47:26975 // Optional URL to a page for setting options/preferences.
976 GURL options_url_;
977
978 // Optional URL to a devtools extension page.
979 GURL devtools_url_;
980
[email protected]6f229e82010-11-02 17:47:26981 // The public key used to sign the contents of the crx package.
982 std::string public_key_;
983
984 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:03985 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:26986
987 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03988 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:26989
990 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03991 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:26992
993 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:03994 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:26995
[email protected]6f229e82010-11-02 17:47:26996 // The homepage for this extension. Useful if it is not hosted by Google and
997 // therefore does not have a Gallery URL.
998 GURL homepage_url_;
999
1000 // URL for fetching an update manifest
1001 GURL update_url_;
1002
[email protected]58f62cf2012-03-09 10:45:111003 // The manifest from which this extension was created.
[email protected]d41e2152012-02-24 04:20:271004 //
1005 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would
1006 // require manifest.h, which would in turn create a circulate dependency
1007 // between extension.h and manifest.h.
1008 //
1009 // TODO(aa): Pull Extension::Type and Extension::Location out into their own
1010 // files so that manifest.h can rely on them and not get all of extension.h
1011 // too, and then change this back to a scoped_ptr.
1012 extensions::Manifest* manifest_;
[email protected]6f229e82010-11-02 17:47:261013
1014 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
1015 // which override the handling of those URLs. (see ExtensionOverrideUI).
1016 URLOverrideMap chrome_url_overrides_;
1017
[email protected]d9696672011-03-15 22:45:091018 // Whether this extension requests isolated storage.
1019 bool is_storage_isolated_;
1020
[email protected]6f229e82010-11-02 17:47:261021 // The local path inside the extension to use with the launcher.
1022 std::string launch_local_path_;
1023
1024 // A web url to use with the launcher. Note that this might be relative or
1025 // absolute. If relative, it is relative to web_origin.
1026 std::string launch_web_url_;
1027
[email protected]4e595682011-02-09 17:07:021028 // The window type that an app's manifest specifies to launch into.
1029 // This is not always the window type an app will open into, because
1030 // users can override the way each app launches. See
1031 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
1032 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:261033 extension_misc::LaunchContainer launch_container_;
1034
1035 // The default size of the container when launching. Only respected for
1036 // containers like panels and windows.
1037 int launch_width_;
1038 int launch_height_;
1039
1040 // The Omnibox keyword for this extension, or empty if there is none.
1041 std::string omnibox_keyword_;
1042
[email protected]a4a38c12010-12-23 16:43:561043 // List of text-to-speech voices that this extension provides, if any.
1044 std::vector<TtsVoice> tts_voices_;
1045
[email protected]a79be1f2012-03-23 22:14:001046 // The OAuth2 client id and scopes, if specified by the extension.
1047 OAuth2Info oauth2_info_;
1048
[email protected]56624422011-11-01 22:11:271049 // List of intent services that this extension provides, if any.
1050 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
[email protected]be5f007862011-09-23 00:35:131051
[email protected]3aff9ad2011-04-01 20:26:481052 // Whether the extension has host permissions or user script patterns that
1053 // imply access to file:/// scheme URLs (the user may not have actually
1054 // granted it that access).
1055 bool wants_file_access_;
1056
[email protected]2af352b2011-07-22 08:21:231057 // The flags that were passed to InitFromValue.
1058 int creation_flags_;
[email protected]620db1762011-07-15 21:57:341059
[email protected]7f7b9d932011-04-20 16:13:261060 // The Content-Security-Policy for this extension. Extensions can use
1061 // Content-Security-Policies to mitigate cross-site scripting and other
1062 // vulnerabilities.
1063 std::string content_security_policy_;
1064
[email protected]19118d52010-07-26 22:13:421065 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
[email protected]1c321ee2012-05-21 03:02:341066 FRIEND_TEST_ALL_PREFIXES(::TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:581067
[email protected]894bb502009-05-21 22:39:571068 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:331069};
1070
[email protected]9adb9692010-10-29 23:14:021071typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:181072typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:561073
[email protected]c6d474f82009-12-16 21:11:061074// Handy struct to pass core extension info around.
1075struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:031076 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:061077 const std::string& id,
1078 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:461079 Extension::Location location);
1080 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:061081
[email protected]f3a1c642011-07-12 19:15:031082 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:061083 std::string extension_id;
1084 FilePath extension_path;
1085 Extension::Location extension_location;
1086
1087 private:
1088 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
1089};
1090
[email protected]a9f39a312010-12-23 22:14:271091struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:591092 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:271093
1094 // Was the extension already disabled?
1095 bool already_disabled;
1096
1097 // The extension being unloaded - this should always be non-NULL.
1098 const Extension* extension;
1099
[email protected]814a7bf0f2011-08-13 05:30:591100 UnloadedExtensionInfo(
1101 const Extension* extension,
1102 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:271103};
1104
[email protected]902fd7b2011-07-27 18:42:311105// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
1106struct UpdatedExtensionPermissionsInfo {
1107 enum Reason {
[email protected]f5532472012-02-23 13:00:551108 ADDED, // The permissions were added to the extension.
1109 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:311110 };
1111
1112 Reason reason;
1113
1114 // The extension who's permissions have changed.
1115 const Extension* extension;
1116
1117 // The permissions that have changed. For Reason::ADDED, this would contain
1118 // only the permissions that have added, and for Reason::REMOVED, this would
1119 // only contain the removed permissions.
1120 const ExtensionPermissionSet* permissions;
1121
1122 UpdatedExtensionPermissionsInfo(
1123 const Extension* extension,
1124 const ExtensionPermissionSet* permissions,
1125 Reason reason);
1126};
1127
[email protected]1c321ee2012-05-21 03:02:341128} // namespace extensions
1129
[email protected]5b1a0e22009-05-26 19:00:581130#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_