blob: 28b005e2e00ec479bddc225916e6b5ee9ac70f0f [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>
[email protected]58f62cf2012-03-09 10:45:1112#include <utility>
[email protected]7713d632008-12-02 07:52:3313#include <vector>
[email protected]e5cd5502012-02-29 03:56:4314#include <algorithm>
[email protected]7713d632008-12-02 07:52:3315
[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]d83a5602010-09-16 00:22:4823#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4824#include "chrome/common/extensions/extension_icon_set.h"
[email protected]0d3e4a22011-06-23 19:02:5225#include "chrome/common/extensions/extension_permission_set.h"
[email protected]42b6f0f82009-09-18 21:07:3926#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4927#include "chrome/common/extensions/url_pattern.h"
[email protected]cced75a2011-05-20 08:31:1228#include "chrome/common/extensions/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5929#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5530#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3831#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5932
[email protected]942690b132010-05-11 06:42:1433class ExtensionAction;
34class ExtensionResource;
[email protected]b6b805e92011-04-16 09:24:1435class FileBrowserHandler;
[email protected]12802702010-07-09 19:43:0936class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2837class Version;
[email protected]942690b132010-05-11 06:42:1438
[email protected]f3a1c642011-07-12 19:15:0339namespace base {
40class DictionaryValue;
41class ListValue;
42}
43
[email protected]d41e2152012-02-24 04:20:2744namespace extensions {
45class Manifest;
46}
47
[email protected]f0cc7242011-12-13 04:26:1748namespace webkit_glue {
49struct WebIntentServiceData;
50}
51
[email protected]f0755532010-06-22 07:27:2552// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4153class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3354 public:
[email protected]d3cfa482009-10-17 13:54:5755 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1756 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1457 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]b24d8312009-08-27 06:47:4658
[email protected]631cf822009-05-15 07:01:2559 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2360 // NOTE: These values are stored as integers in the preferences and used
61 // in histograms so don't remove or reorder existing items. Just append
62 // to the end.
[email protected]631cf822009-05-15 07:01:2563 enum Location {
64 INVALID,
[email protected]25b34332009-06-05 21:53:1965 INTERNAL, // A crx file from the internal Extensions directory.
66 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
67 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
68 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3469 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3270 COMPONENT, // An integral component of Chrome itself, which
71 // happens to be implemented as an extension. We don't
72 // show these in the management UI.
[email protected]4d2913e32010-11-30 00:28:5573 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via
74 // prefs), installed from an update URL.
75 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via
76 // admin policies), installed from an update URL.
[email protected]04cb7542010-10-25 10:50:0677
78 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1979 };
80
81 enum State {
[email protected]0c6da502009-08-14 22:32:3982 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1983 ENABLED,
[email protected]79c833b52011-04-05 18:31:0184 // An external extension that the user uninstalled. We should not reinstall
85 // such extensions on startup.
86 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:3987 NUM_STATES
[email protected]631cf822009-05-15 07:01:2588 };
[email protected]7713d632008-12-02 07:52:3389
[email protected]fbcc40302009-06-12 20:45:4590 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3791 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4592 DOWNGRADE,
93 REINSTALL,
94 UPGRADE,
95 NEW_INSTALL
96 };
97
[email protected]7fa19f82010-12-21 19:40:0898 // Do not change the order of entries or remove entries in this list
99 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
100 enum Type {
[email protected]9b217652010-10-08 22:04:23101 TYPE_UNKNOWN = 0,
102 TYPE_EXTENSION,
103 TYPE_THEME,
104 TYPE_USER_SCRIPT,
105 TYPE_HOSTED_APP,
[email protected]7d3ed2f2011-11-07 23:33:19106 TYPE_PACKAGED_APP,
107 TYPE_PLATFORM_APP
[email protected]9b217652010-10-08 22:04:23108 };
109
[email protected]3bdba0d2011-08-23 07:17:30110 enum SyncType {
111 SYNC_TYPE_NONE = 0,
112 SYNC_TYPE_EXTENSION,
113 SYNC_TYPE_APP
114 };
115
[email protected]92888082010-10-18 19:24:57116 // An NPAPI plugin included in the extension.
117 struct PluginInfo {
118 FilePath path; // Path to the plugin.
119 bool is_public; // False if only this extension can load this plugin.
120 };
121
[email protected]65378f52011-04-08 02:31:23122 // An NaCl module included in the extension.
123 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42124 GURL url;
[email protected]65378f52011-04-08 02:31:23125 std::string mime_type;
126 };
127
[email protected]b0820372011-06-03 07:05:27128 enum InputComponentType {
[email protected]d45f7512011-06-21 21:18:27129 INPUT_COMPONENT_TYPE_NONE = -1,
130 INPUT_COMPONENT_TYPE_IME,
[email protected]b0820372011-06-03 07:05:27131 INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD,
132 INPUT_COMPONENT_TYPE_COUNT
133 };
134
135 struct InputComponentInfo {
136 // Define out of line constructor/destructor to please Clang.
137 InputComponentInfo();
138 ~InputComponentInfo();
139
140 std::string name;
141 InputComponentType type;
142 std::string id;
143 std::string description;
144 std::string language;
145 std::set<std::string> layouts;
146 std::string shortcut_keycode;
147 bool shortcut_alt;
148 bool shortcut_ctrl;
149 bool shortcut_shift;
150 };
151
[email protected]f5532472012-02-23 13:00:55152 class ExtensionKeybinding {
153 public:
154 // Define out of line constructor/destructor to please Clang.
155 ExtensionKeybinding();
156 ~ExtensionKeybinding();
157
158 // Parse the key binding.
159 bool Parse(base::DictionaryValue* command,
160 const std::string& command_name,
161 int index,
162 string16* error);
163
164 // Accessors:
165 const std::string& command_name() const { return command_name_; }
166 const ui::Accelerator& accelerator() const { return accelerator_; }
167 const std::string& description() const { return description_; }
168
169 private:
[email protected]9c8b54d2012-04-02 10:17:30170 ui::Accelerator ParseImpl(const std::string& shortcut,
171 const std::string& platform_key,
172 int index,
173 string16* error);
[email protected]f5532472012-02-23 13:00:55174 std::string command_name_;
175 ui::Accelerator accelerator_;
176 std::string description_;
177 };
178
[email protected]9c8b54d2012-04-02 10:17:30179 typedef std::map<std::string, ExtensionKeybinding> CommandMap;
180
[email protected]a4a38c12010-12-23 16:43:56181 struct TtsVoice {
[email protected]77a3ecac2011-07-07 05:56:33182 // Define out of line constructor/destructor to please Clang.
183 TtsVoice();
184 ~TtsVoice();
185
[email protected]a4a38c12010-12-23 16:43:56186 std::string voice_name;
[email protected]c63f2b72011-07-07 05:25:00187 std::string lang;
[email protected]a4a38c12010-12-23 16:43:56188 std::string gender;
[email protected]c63f2b72011-07-07 05:25:00189 std::set<std::string> event_types;
[email protected]a4a38c12010-12-23 16:43:56190 };
191
[email protected]a79be1f2012-03-23 22:14:00192 // OAuth2 info included in the extension.
193 struct OAuth2Info {
194 OAuth2Info();
195 ~OAuth2Info();
196
197 std::string client_id;
198 std::vector<std::string> scopes;
199 };
200
[email protected]83048a22011-03-29 00:14:13201 enum InitFromValueFlags {
202 NO_FLAGS = 0,
203
204 // Usually, the id of an extension is generated by the "key" property of
205 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
206 // generated based on the path.
207 REQUIRE_KEY = 1 << 0,
208
[email protected]3f53dfe2011-11-30 01:18:29209 // Requires the extension to have an up-to-date manifest version.
210 // Typically, we'll support multiple manifest versions during a version
211 // transition. This flag signals that we want to require the most modern
212 // manifest version that Chrome understands.
213 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
214
[email protected]83048a22011-03-29 00:14:13215 // |STRICT_ERROR_CHECKS| enables extra error checking, such as
216 // checks that URL patterns do not contain ports. This error
217 // checking may find an error that a previous version of
218 // Chrome did not flag. To avoid errors in installed extensions
219 // when Chrome is upgraded, strict error checking is only enabled
220 // when loading extensions as a developer would (such as loading
221 // an unpacked extension), or when loading an extension that is
222 // tied to a specific version of Chrome (such as a component
223 // extension). Most callers will set the |STRICT_ERROR_CHECKS| bit when
224 // Extension::ShouldDoStrictErrorChecking(location) returns true.
[email protected]3f53dfe2011-11-30 01:18:29225 STRICT_ERROR_CHECKS = 1 << 2,
[email protected]3aff9ad2011-04-01 20:26:48226
227 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
228 // to have file access. If it's not present, then permissions and content
229 // scripts that match file:/// URLs will be filtered out.
[email protected]3f53dfe2011-11-30 01:18:29230 ALLOW_FILE_ACCESS = 1 << 3,
[email protected]620db1762011-07-15 21:57:34231
232 // |FROM_WEBSTORE| indicates that the extension was installed from the
233 // Chrome Web Store.
[email protected]3f53dfe2011-11-30 01:18:29234 FROM_WEBSTORE = 1 << 4,
[email protected]e805baf2011-07-26 18:23:05235
236 // |FROM_BOOKMARK| indicates the extension was created using a mock App
237 // created from a bookmark.
[email protected]3f53dfe2011-11-30 01:18:29238 FROM_BOOKMARK = 1 << 5,
[email protected]83048a22011-03-29 00:14:13239 };
240
[email protected]66e4eb32010-10-27 20:37:41241 static scoped_refptr<Extension> Create(const FilePath& path,
242 Location location,
[email protected]f3a1c642011-07-12 19:15:03243 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13244 int flags,
[email protected]66e4eb32010-10-27 20:37:41245 std::string* error);
246
[email protected]87c655e2011-07-01 21:42:00247 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26248 // an explicit id. Most consumers should just use the other Create() method.
249 static scoped_refptr<Extension> Create(const FilePath& path,
[email protected]58f62cf2012-03-09 10:45:11250 Location location,
251 const base::DictionaryValue& value,
252 int flags,
253 const std::string& explicit_id,
254 std::string* error);
[email protected]87c655e2011-07-01 21:42:00255
[email protected]145a317b2011-04-12 16:03:46256 // Given two install sources, return the one which should take priority
257 // over the other. If an extension is installed from two sources A and B,
258 // its install source should be set to GetHigherPriorityLocation(A, B).
259 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
260
[email protected]4c4f8192009-10-17 01:03:26261 // Max size (both dimensions) for browser and page actions.
262 static const int kPageActionIconMaxSize;
263 static const int kBrowserActionIconMaxSize;
264
[email protected]8d888c12010-11-30 00:00:25265 // Valid schemes for web extent URLPatterns.
266 static const int kValidWebExtentSchemes;
267
[email protected]f71f7e62010-12-07 03:45:33268 // Valid schemes for host permission URLPatterns.
269 static const int kValidHostPermissionSchemes;
270
[email protected]6014d672008-12-05 00:38:25271 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16272 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25273
[email protected]300cc58db2009-08-19 20:45:14274 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16275 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14276
277 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16278 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14279
[email protected]25b34332009-06-05 21:53:19280#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19281 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19282#endif
283
[email protected]37eeb5a2009-02-26 23:36:17284 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48285 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17286
[email protected]e435d6b72009-07-25 03:15:58287 // The mimetype used for extensions.
288 static const char kMimeType[];
289
[email protected]25b34332009-06-05 21:53:19290 // Checks to see if the extension has a valid ID.
291 static bool IdIsValid(const std::string& id);
292
[email protected]4ead6f72010-10-13 19:54:18293 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27294 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18295 static std::string GenerateIdForPath(const FilePath& file_name);
296
[email protected]e435d6b72009-07-25 03:15:58297 // Returns true if the specified file is an extension.
298 static bool IsExtension(const FilePath& file_name);
299
[email protected]25b34332009-06-05 21:53:19300 // Whether the |location| is external or not.
301 static inline bool IsExternalLocation(Location location) {
302 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32303 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06304 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
305 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
306 }
307
308 // Whether extensions with |location| are auto-updatable or not.
309 static inline bool IsAutoUpdateableLocation(Location location) {
310 // Only internal and external extensions can be autoupdated.
311 return location == Extension::INTERNAL ||
312 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19313 }
314
[email protected]95da88c42011-03-31 10:07:33315 // Whether extensions with |location| can be uninstalled or not. Policy
316 // controlled extensions are silently auto-installed and updated, and cannot
317 // be disabled by the user. The same applies for internal components.
318 static inline bool UserMayDisable(Location location) {
319 return location != Extension::EXTERNAL_POLICY_DOWNLOAD &&
320 location != Extension::COMPONENT;
321 }
322
[email protected]542258c2011-03-04 21:25:31323 // Whether extensions with |location| should be loaded with strict
324 // error checking. Strict error checks may flag errors older versions
325 // of chrome did not detect. To avoid breaking installed extensions,
326 // strict checks are disabled unless the location indicates that the
327 // developer is loading the extension, or the extension is a component
328 // of chrome.
329 static inline bool ShouldDoStrictErrorChecking(Location location) {
330 return location == Extension::LOAD ||
331 location == Extension::COMPONENT;
332 }
333
[email protected]cdfca9702011-08-08 16:07:01334 // Unpacked extensions start off with file access since they are a developer
335 // feature.
336 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
337 return location == Extension::LOAD;
338 }
339
[email protected]fc6b0612012-03-29 13:40:06340 // Fills the |info| dictionary with basic information about the extension.
341 // |enabled| is injected for easier testing.
342 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const;
343
[email protected]7fa19f82010-12-21 19:40:08344 // See Type definition above.
345 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23346
[email protected]07c00d992009-03-04 20:27:04347 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59348 // |extension_url| argument should be the url() from an Extension object. The
349 // |relative_path| can be untrusted user input. The returned URL will either
350 // be invalid() or a child of |extension_url|.
351 // NOTE: Static so that it can be used from multiple threads.
352 static GURL GetResourceURL(const GURL& extension_url,
353 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28354 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24355 return GetResourceURL(url(), relative_path);
356 }
[email protected]eab9b452009-01-23 20:48:59357
[email protected]8f270be2011-12-21 21:15:22358 // Returns true if the specified resource is web accessible.
359 bool IsResourceWebAccessible(const std::string& relative_path) const;
360
361 // Returns true when 'web_accessible_resources' are defined for the extension.
362 bool HasWebAccessibleResources() const;
363
[email protected]99efb7b12009-12-18 02:39:16364 // Returns an extension resource object. |relative_path| should be UTF8
365 // encoded.
[email protected]9adb9692010-10-29 23:14:02366 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16367
368 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02369 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59370
[email protected]a17f9462009-06-09 02:56:41371 // |input| is expected to be the text of an rsa public or private key. It
372 // tolerates the presence or absence of bracking header/footer like this:
373 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
374 // and may contain newlines.
375 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
376
377 // Does a simple base64 encoding of |input| into |output|.
378 static bool ProducePEM(const std::string& input, std::string* output);
379
[email protected]84ac7f32009-10-06 06:17:54380 // Generates an extension ID from arbitrary input. The same input string will
381 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15382 static bool GenerateId(const std::string& input,
383 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45384
[email protected]a17f9462009-06-09 02:56:41385 // Expects base64 encoded |input| and formats into |output| including
386 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50387 static bool FormatPEMForFileOutput(const std::string& input,
388 std::string* output,
389 bool is_public);
[email protected]a17f9462009-06-09 02:56:41390
[email protected]58f62cf2012-03-09 10:45:11391 // Given an extension, icon size, and match type, read a valid icon if present
[email protected]e3c0bc22012-02-24 01:34:15392 // and decode it into result. In the browser process, this will DCHECK if not
393 // called on the file thread. To easily load extension images on the UI
394 // thread, see ImageLoadingTracker.
395 static void DecodeIcon(const Extension* extension,
396 ExtensionIconSet::Icons icon_size,
397 ExtensionIconSet::MatchType match_type,
398 scoped_ptr<SkBitmap>* result);
399
[email protected]c690a9812009-12-17 05:55:32400 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23401 // result. In the browser process, this will DCHECK if not called on the
402 // file thread. To easily load extension images on the UI thread, see
403 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02404 static void DecodeIcon(const Extension* extension,
[email protected]e3c0bc22012-02-24 01:34:15405 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32406 scoped_ptr<SkBitmap>* result);
407
408 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23409 // result. In the browser process, this will DCHECK if not called on the
410 // file thread. To easily load extension images on the UI thread, see
411 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32412 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]e3c0bc22012-02-24 01:34:15413 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32414 scoped_ptr<SkBitmap>* result);
415
[email protected]5349ac6d2011-04-05 22:20:17416 // Returns the default extension/app icon (for extensions or apps that don't
417 // have one).
418 static const SkBitmap& GetDefaultIcon(bool is_app);
419
[email protected]a807bbe2010-04-14 10:51:19420 // Returns the base extension url for a given |extension_id|.
421 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
422
[email protected]be7e5cb2010-10-04 12:53:17423 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17424 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21425 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17426
[email protected]902fd7b2011-07-27 18:42:31427 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27428 // from |manifest_|.
429 bool ParsePermissions(const char* key,
[email protected]fc670822011-12-17 09:33:49430 string16* error,
[email protected]902fd7b2011-07-27 18:42:31431 ExtensionAPIPermissionSet* api_permissions,
432 URLPatternSet* host_permissions);
433
[email protected]0d3e4a22011-06-23 19:02:52434 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const;
435 bool HasAPIPermission(const std::string& function_name) const;
[email protected]583d45c12010-08-31 02:48:12436
[email protected]0d3e4a22011-06-23 19:02:52437 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46438
[email protected]902fd7b2011-07-27 18:42:31439 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16440 // Users must approve permissions for unpacked and packed extensions in the
441 // following situations:
442 // - when installing or upgrading packed extensions
443 // - when installing unpacked extensions that have NPAPI plugins
444 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31445 bool CanSilentlyIncreasePermissions() const;
446
[email protected]584b8e3f2010-04-10 00:23:37447 // Whether the extension has access to the given URL.
448 bool HasHostPermission(const GURL& url) const;
449
[email protected]0df165f2010-09-28 16:49:40450 // Whether the extension has effective access to all hosts. This is true if
451 // there is a content script that matches all hosts, if there is a host
452 // permission grants access to all hosts (like <all_urls>) or an api
453 // permission that effectively grants access to all hosts (e.g. proxy,
454 // network, etc.)
455 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46456
[email protected]8d888c12010-11-30 00:00:25457 // Whether the extension effectively has all permissions (for example, by
458 // having an NPAPI plugin).
459 bool HasFullPermissions() const;
460
[email protected]902fd7b2011-07-27 18:42:31461 // Returns the full list of permission messages that this extension
462 // should display at install time.
463 ExtensionPermissionMessages GetPermissionMessages() const;
464
465 // Returns the full list of permission messages that this extension
466 // should display at install time. The messages are returned as strings
467 // for convenience.
468 std::vector<string16> GetPermissionMessageStrings() const;
469
470 // Sets the active |permissions|.
471 void SetActivePermissions(const ExtensionPermissionSet* permissions) const;
472
473 // Gets the extension's active permission set.
474 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
475
[email protected]5df6a5d2011-01-26 07:39:12476 // Whether context menu should be shown for page and browser actions.
477 bool ShowConfigureContextMenus() const;
478
[email protected]37cd64d2010-10-25 18:17:58479 // Returns the Homepage URL for this extension. If homepage_url was not
480 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23481 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58482 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23483
[email protected]facd7a7652009-06-05 23:15:02484 // Returns a list of paths (relative to the extension dir) for images that
485 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02486 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02487
[email protected]807871f2010-09-16 01:04:48488 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02489 ExtensionResource GetIconResource(
490 int size, ExtensionIconSet::MatchType match_type) const;
491 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08492
[email protected]867a73e12010-03-19 20:45:46493 // Gets the fully resolved absolute launch URL.
494 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21495
[email protected]6f229e82010-11-02 17:47:26496 // Image cache related methods. These are only valid on the UI thread and
497 // not maintained by this class. See ImageLoadingTracker for usage. The
498 // |original_size| parameter should be the size of the image at |source|
499 // before any scaling may have been done to produce the pixels in |image|.
500 void SetCachedImage(const ExtensionResource& source,
501 const SkBitmap& image,
502 const gfx::Size& original_size) const;
503 bool HasCachedImage(const ExtensionResource& source,
504 const gfx::Size& max_size) const;
505 SkBitmap GetCachedImage(const ExtensionResource& source,
506 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21507
508 // Returns true if this extension can execute script on a page. If a
509 // UserScript object is passed, permission to run that specific script is
510 // checked (using its matches list). Otherwise, permission to execute script
511 // programmatically is checked (using the extension's host permission).
512 //
513 // This method is also aware of certain special pages that extensions are
514 // usually not allowed to run script on.
515 bool CanExecuteScriptOnPage(const GURL& page_url,
[email protected]3aff9ad2011-04-01 20:26:48516 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21517 std::string* error) const;
518
[email protected]6f229e82010-11-02 17:47:26519 // Returns true if this extension is a COMPONENT extension, or if it is
520 // on the whitelist of extensions that can script all pages.
521 bool CanExecuteScriptEverywhere() const;
522
[email protected]5efbfe012011-02-22 23:07:18523 // Returns true if this extension is allowed to obtain the contents of a
524 // page as an image. Since a page may contain sensitive information, this
525 // is restricted to the extension's host permissions as well as the
526 // extension page itself.
527 bool CanCaptureVisiblePage(const GURL& page_url, std::string* error) const;
528
[email protected]a65882c2010-11-12 15:15:09529 // Returns true if this extension updates itself using the extension
530 // gallery.
531 bool UpdatesFromGallery() const;
532
[email protected]cca147172011-02-17 01:29:29533 // Returns true if this extension or app includes areas within |origin|.
534 bool OverlapsWithOrigin(const GURL& origin) const;
535
[email protected]3bdba0d2011-08-23 07:17:30536 // Returns the sync bucket to use for this extension.
537 SyncType GetSyncType() const;
538
[email protected]b873cd92012-02-09 21:51:48539 // Returns true if the extension should be synced.
540 bool IsSyncable() const;
541
542 // Returns true if the extension should be displayed in the launcher.
543 bool ShouldDisplayInLauncher() const;
544
[email protected]6f229e82010-11-02 17:47:26545 // Accessors:
546
547 const FilePath& path() const { return path_; }
548 const GURL& url() const { return extension_url_; }
[email protected]d41e2152012-02-24 04:20:27549 Location location() const;
550 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26551 const Version* version() const { return version_.get(); }
552 const std::string VersionString() const;
553 const std::string& name() const { return name_; }
[email protected]d41e2152012-02-24 04:20:27554 const std::string public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26555 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31556 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26557 bool converted_from_user_script() const {
558 return converted_from_user_script_;
559 }
560 const UserScriptList& content_scripts() const { return content_scripts_; }
561 ExtensionAction* page_action() const { return page_action_.get(); }
562 ExtensionAction* browser_action() const { return browser_action_.get(); }
[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]9c8b54d2012-04-02 10:17:30573 const ExtensionKeybinding* browser_action_command() const {
574 return browser_action_command_.get();
575 }
576 const ExtensionKeybinding* page_action_command() const {
577 return page_action_command_.get();
578 }
579 const CommandMap& named_commands() const {
580 return named_commands_;
[email protected]f5532472012-02-23 13:00:55581 }
[email protected]a03d4448f2012-01-10 23:25:28582 bool has_background_page() const {
583 return background_url_.is_valid() || !background_scripts_.empty();
584 }
[email protected]7b54ca02012-03-02 18:06:53585 bool allow_background_js_access() const {
586 return allow_background_js_access_;
587 }
[email protected]a03d4448f2012-01-10 23:25:28588 const std::vector<std::string>& background_scripts() const {
589 return background_scripts_;
590 }
[email protected]4762e7902012-03-28 23:34:04591 bool background_page_is_transient() const {
592 return background_page_is_transient_;
593 }
[email protected]d2aa06b2012-03-21 20:57:26594 bool has_persistent_background_page() const {
[email protected]4762e7902012-03-28 23:34:04595 return has_background_page() && !background_page_is_transient();
[email protected]d2aa06b2012-03-21 20:57:26596 }
597 bool has_lazy_background_page() const {
[email protected]4762e7902012-03-28 23:34:04598 return has_background_page() && background_page_is_transient();
[email protected]d2aa06b2012-03-21 20:57:26599 }
[email protected]6f229e82010-11-02 17:47:26600 const GURL& options_url() const { return options_url_; }
601 const GURL& devtools_url() const { return devtools_url_; }
[email protected]902fd7b2011-07-27 18:42:31602 const ExtensionPermissionSet* optional_permission_set() const {
603 return optional_permission_set_.get();
604 }
605 const ExtensionPermissionSet* required_permission_set() const {
606 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26607 }
[email protected]6f229e82010-11-02 17:47:26608 const GURL& update_url() const { return update_url_; }
609 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32610 const extensions::Manifest* manifest() const {
[email protected]d41e2152012-02-24 04:20:27611 return manifest_;
[email protected]6f229e82010-11-02 17:47:26612 }
613 const std::string default_locale() const { return default_locale_; }
614 const URLOverrideMap& GetChromeURLOverrides() const {
615 return chrome_url_overrides_;
616 }
617 const std::string omnibox_keyword() const { return omnibox_keyword_; }
618 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55619 bool offline_enabled() const { return offline_enabled_; }
[email protected]a4a38c12010-12-23 16:43:56620 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]a79be1f2012-03-23 22:14:00621 const OAuth2Info& oauth2_info() const { return oauth2_info_; }
[email protected]56624422011-11-01 22:11:27622 const std::vector<webkit_glue::WebIntentServiceData>&
623 intents_services() const {
624 return intents_services_;
625 }
[email protected]6f229e82010-11-02 17:47:26626
[email protected]3aff9ad2011-04-01 20:26:48627 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23628 int creation_flags() const { return creation_flags_; }
629 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05630 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]3aff9ad2011-04-01 20:26:48631
[email protected]7f7b9d932011-04-20 16:13:26632 const std::string& content_security_policy() const {
633 return content_security_policy_;
634 }
635
[email protected]6f229e82010-11-02 17:47:26636 // App-related.
[email protected]953620b2011-12-04 00:55:32637 bool is_app() const {
638 return is_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39639 }
[email protected]d41e2152012-02-24 04:20:27640 bool is_platform_app() const;
641 bool is_hosted_app() const;
642 bool is_packaged_app() const;
[email protected]d9696672011-03-15 22:45:09643 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12644 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26645 const std::string& launch_local_path() const { return launch_local_path_; }
646 const std::string& launch_web_url() const { return launch_web_url_; }
647 extension_misc::LaunchContainer launch_container() const {
648 return launch_container_;
649 }
[email protected]e5cd5502012-02-29 03:56:43650 int launch_width() const {
[email protected]f8c3aea2012-03-01 07:23:20651 return std::max(launch_min_width_,
652 launch_max_width_ ?
653 std::min(launch_max_width_, launch_width_) :
654 launch_width_);
[email protected]e5cd5502012-02-29 03:56:43655 }
656 int launch_height() const {
[email protected]f8c3aea2012-03-01 07:23:20657 return std::max(launch_min_height_,
658 launch_max_height_ ?
659 std::min(launch_max_height_, launch_height_) :
660 launch_height_);
[email protected]e5cd5502012-02-29 03:56:43661 }
662 int launch_min_width() const { return launch_min_width_; }
663 int launch_min_height() const { return launch_min_height_; }
[email protected]f8c3aea2012-03-01 07:23:20664 int launch_max_width() const { return launch_max_width_; }
665 int launch_max_height() const { return launch_max_height_; }
[email protected]6f229e82010-11-02 17:47:26666
667 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27668 bool is_theme() const;
[email protected]f3a1c642011-07-12 19:15:03669 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
670 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
671 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
672 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26673 return theme_display_properties_.get();
674 }
675
[email protected]a03d4448f2012-01-10 23:25:28676 GURL GetBackgroundURL() const;
677
[email protected]4a8d3272009-03-10 19:15:08678 private:
[email protected]66e4eb32010-10-27 20:37:41679 friend class base::RefCountedThreadSafe<Extension>;
680
[email protected]d7e9a862010-11-03 21:57:49681 // We keep a cache of images loaded from extension resources based on their
682 // path and a string representation of a size that may have been used to
683 // scale it (or the empty string if the image is at its original size).
684 typedef std::pair<FilePath, std::string> ImageCacheKey;
685 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
686
[email protected]902fd7b2011-07-27 18:42:31687 class RuntimeData {
688 public:
689 RuntimeData();
690 explicit RuntimeData(const ExtensionPermissionSet* active);
691 ~RuntimeData();
692
693 void SetActivePermissions(const ExtensionPermissionSet* active);
694 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
695
696 private:
697 friend class base::RefCountedThreadSafe<RuntimeData>;
698 scoped_refptr<const ExtensionPermissionSet> active_permissions_;
699 };
700
[email protected]d41e2152012-02-24 04:20:27701 // Chooses the extension ID for an extension based on a variety of criteria.
702 // The chosen ID will be set in |manifest|.
703 static bool InitExtensionID(extensions::Manifest* manifest,
704 const FilePath& path,
705 const std::string& explicit_id,
706 int creation_flags,
707 string16* error);
708
[email protected]4ead6f72010-10-13 19:54:18709 // Normalize the path for use by the extension. On Windows, this will make
710 // sure the drive letter is uppercase.
711 static FilePath MaybeNormalizePath(const FilePath& path);
712
[email protected]87c655e2011-07-01 21:42:00713 // Returns true if this extension id is from a trusted provider.
714 static bool IsTrustedId(const std::string& id);
715
[email protected]d41e2152012-02-24 04:20:27716 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
[email protected]66e4eb32010-10-27 20:37:41717 ~Extension();
718
719 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27720 // TODO(aa): Rename to just Init()? There's no Value here anymore.
721 // TODO(aa): It is really weird the way this class essentially contains a copy
722 // of the underlying DictionaryValue in its members. We should decide to
723 // either wrap the DictionaryValue and go with that only, or we should parse
724 // into strong types and discard the value. But doing both is bad.
725 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41726
[email protected]58f62cf2012-03-09 10:45:11727 // The following are helpers for InitFromValue to load various features of the
728 // extension from the manifest.
729
730 bool CheckMinimumChromeVersion(string16* error);
731 bool LoadAppIsolation(string16* error);
732
733 bool LoadRequiredFeatures(string16* error);
734 bool LoadName(string16* error);
735 bool LoadVersion(string16* error);
736
737 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27738 bool LoadExtent(const char* key,
739 URLPatternSet* extent,
740 const char* list_error,
741 const char* value_error,
742 string16* error);
743 bool LoadLaunchContainer(string16* error);
744 bool LoadLaunchURL(string16* error);
[email protected]10253da2012-03-09 04:06:42745
[email protected]58f62cf2012-03-09 10:45:11746 bool LoadSharedFeatures(const ExtensionAPIPermissionSet& api_permissions,
747 string16* error);
748 bool LoadDescription(string16* error);
749 bool LoadManifestVersion(string16* error);
750 bool LoadHomepageURL(string16* error);
751 bool LoadUpdateURL(string16* error);
752 bool LoadIcons(string16* error);
753 bool LoadCommands(string16* error);
754 bool LoadPlugins(string16* error);
755 bool LoadNaClModules(string16* error);
756 bool LoadWebAccessibleResources(string16* error);
757 bool CheckRequirements(string16* error);
758 bool LoadDefaultLocale(string16* error);
759 bool LoadOfflineEnabled(string16* error);
760 bool LoadOptionsPage(string16* error);
[email protected]d41e2152012-02-24 04:20:27761 bool LoadBackgroundScripts(string16* error);
762 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions,
763 string16* error);
[email protected]4762e7902012-03-28 23:34:04764 bool LoadBackgroundTransient(
[email protected]d41e2152012-02-24 04:20:27765 const ExtensionAPIPermissionSet& api_permissions,
766 string16* error);
[email protected]58f62cf2012-03-09 10:45:11767 bool LoadBackgroundAllowJSAccess(
[email protected]7b54ca02012-03-02 18:06:53768 const ExtensionAPIPermissionSet& api_permissions,
769 string16* error);
[email protected]58f62cf2012-03-09 10:45:11770 // Parses a single action in the manifest.
771 bool LoadWebIntentAction(const std::string& action_name,
772 const base::DictionaryValue& intent_service,
773 string16* error);
774 bool LoadWebIntentServices(string16* error);
775 bool LoadExtensionFeatures(const ExtensionAPIPermissionSet& api_permissions,
776 string16* error);
777 bool LoadDevToolsPage(string16* error);
778 bool LoadInputComponents(const ExtensionAPIPermissionSet& api_permissions,
779 string16* error);
780 bool LoadContentScripts(string16* error);
781 bool LoadPageAction(string16* error);
782 bool LoadBrowserAction(string16* error);
783 bool LoadFileBrowserHandlers(string16* error);
784 // Helper method to load a FileBrowserHandlerList from the manifest.
785 FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
786 const base::ListValue* extension_actions, string16* error);
787 // Helper method to load an FileBrowserHandler from manifest.
788 FileBrowserHandler* LoadFileBrowserHandler(
789 const base::DictionaryValue* file_browser_handlers, string16* error);
790 bool LoadChromeURLOverrides(string16* error);
791 bool LoadOmnibox(string16* error);
792 bool LoadTextToSpeechVoices(string16* error);
793 bool LoadIncognitoMode(string16* error);
794 bool LoadContentSecurityPolicy(string16* error);
795
796 bool LoadThemeFeatures(string16* error);
797 bool LoadThemeImages(const base::DictionaryValue* theme_value,
798 string16* error);
799 bool LoadThemeColors(const base::DictionaryValue* theme_value,
800 string16* error);
801 bool LoadThemeTints(const base::DictionaryValue* theme_value,
802 string16* error);
803 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value,
804 string16* error);
805
806 // Helper function for implementing HasCachedImage/GetCachedImage. A return
807 // value of NULL means there is no matching image cached (we allow caching an
808 // empty SkBitmap).
809 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
810 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18811
[email protected]3cfbd0e2009-03-18 21:26:24812 // Helper method that loads a UserScript object from a
813 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03814 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24815 int definition_index,
[email protected]fc670822011-12-17 09:33:49816 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24817 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34818
[email protected]6657afa62009-11-04 02:15:20819 // Helper method that loads either the include_globs or exclude_globs list
820 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03821 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20822 int content_script_index,
[email protected]e2194742010-08-12 05:54:34823 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49824 string16* error,
[email protected]11f4857282009-11-13 19:56:17825 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20826 UserScript *instance);
827
[email protected]5d246db22009-10-27 06:17:57828 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08829 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57830 ExtensionAction* LoadExtensionActionHelper(
[email protected]fc670822011-12-17 09:33:49831 const base::DictionaryValue* extension_action, string16* error);
[email protected]92c6f9b92009-10-24 04:35:08832
[email protected]a79be1f2012-03-23 22:14:00833 // Helper method that loads the OAuth2 info from the 'oauth2' manifest key.
834 bool LoadOAuth2Info(string16* error);
835
[email protected]2f6698b2010-10-14 00:58:21836 // Returns true if the extension has more than one "UI surface". For example,
837 // an extension that has a browser action and a page action.
838 bool HasMultipleUISurfaces() const;
839
[email protected]be9d9c82011-07-13 04:17:31840 // Updates the launch URL and extents for the extension using the given
841 // |override_url|.
842 void OverrideLaunchUrl(const GURL& override_url);
843
[email protected]ae655e4e2012-03-16 21:47:55844 // Custom checks for the experimental permission that can't be expressed in
845 // _permission_features.json.
[email protected]5eddc3e2011-10-26 04:33:31846 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31847
848 // Checks whether the host |pattern| is allowed for this extension, given API
849 // permissions |permissions|.
850 bool CanSpecifyHostPermission(const URLPattern& pattern,
851 const ExtensionAPIPermissionSet& permissions) const;
852
[email protected]d7e9a862010-11-03 21:57:49853 // Cached images for this extension. This should only be touched on the UI
854 // thread.
855 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31856
[email protected]6f229e82010-11-02 17:47:26857 // The extension's human-readable name. Name is used for display purpose. It
858 // might be wrapped with unicode bidi control characters so that it is
859 // displayed correctly in RTL context.
860 // NOTE: Name is UTF-8 and may contain non-ascii characters.
861 std::string name_;
862
[email protected]a47c8a22011-11-17 18:40:31863 // The version of this extension's manifest. We increase the manifest
864 // version when making breaking changes to the extension system.
865 // Version 1 was the first manifest version (implied by a lack of a
866 // manifest_version attribute in the extension's manifest). We initialize
867 // this member variable to 0 to distinguish the "uninitialized" case from
868 // the case when we know the manifest version actually is 1.
869 int manifest_version_;
870
[email protected]d41e2152012-02-24 04:20:27871 // The absolute path to the directory the extension is stored in.
872 FilePath path_;
873
[email protected]6f229e82010-11-02 17:47:26874 // Default locale for fall back. Can be empty if extension is not localized.
875 std::string default_locale_;
876
877 // If true, a separate process will be used for the extension in incognito
878 // mode.
879 bool incognito_split_mode_;
880
[email protected]1abdf4f2011-08-16 21:11:55881 // Whether the extension or app should be enabled when offline.
882 bool offline_enabled_;
883
[email protected]6f229e82010-11-02 17:47:26884 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12885 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26886
[email protected]902fd7b2011-07-27 18:42:31887 // The extension runtime data.
888 mutable base::Lock runtime_data_lock_;
889 mutable RuntimeData runtime_data_;
890
891 // The set of permissions the extension can request at runtime.
892 scoped_refptr<const ExtensionPermissionSet> optional_permission_set_;
893
894 // The extension's required / default set of permissions.
895 scoped_refptr<const ExtensionPermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26896
897 // The icons for the extension.
898 ExtensionIconSet icons_;
899
900 // The base extension url for the extension.
901 GURL extension_url_;
902
[email protected]6f229e82010-11-02 17:47:26903 // The extension's version.
904 scoped_ptr<Version> version_;
905
906 // An optional longer description of the extension.
907 std::string description_;
908
909 // True if the extension was generated from a user script. (We show slightly
910 // different UI if so).
911 bool converted_from_user_script_;
912
913 // Paths to the content scripts the extension contains.
914 UserScriptList content_scripts_;
915
916 // The extension's page action, if any.
917 scoped_ptr<ExtensionAction> page_action_;
918
919 // The extension's browser action, if any.
920 scoped_ptr<ExtensionAction> browser_action_;
921
[email protected]b6b805e92011-04-16 09:24:14922 // The extension's file browser actions, if any.
923 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
924
[email protected]6f229e82010-11-02 17:47:26925 // Optional list of NPAPI plugins and associated properties.
926 std::vector<PluginInfo> plugins_;
927
[email protected]65378f52011-04-08 02:31:23928 // Optional list of NaCl modules and associated properties.
929 std::vector<NaClModuleInfo> nacl_modules_;
930
[email protected]b0820372011-06-03 07:05:27931 // Optional list of input components and associated properties.
932 std::vector<InputComponentInfo> input_components_;
933
[email protected]f5532472012-02-23 13:00:55934 // Optional list of commands (keyboard shortcuts).
[email protected]9c8b54d2012-04-02 10:17:30935 scoped_ptr<ExtensionKeybinding> browser_action_command_;
936 scoped_ptr<ExtensionKeybinding> page_action_command_;
937 CommandMap named_commands_;
[email protected]f5532472012-02-23 13:00:55938
[email protected]8f270be2011-12-21 21:15:22939 // Optional list of web accessible extension resources.
940 base::hash_set<std::string> web_accessible_resources_;
941
[email protected]6f229e82010-11-02 17:47:26942 // Optional URL to a master page of which a single instance should be always
943 // loaded in the background.
944 GURL background_url_;
945
[email protected]a03d4448f2012-01-10 23:25:28946 // Optional list of scripts to use to generate a background page. If this is
947 // present, background_url_ will be empty and generated by GetBackgroundURL().
948 std::vector<std::string> background_scripts_;
949
[email protected]4762e7902012-03-28 23:34:04950 // False if the background page should stay loaded forever; true if it should
951 // load on-demand (when it needs to handle an event). Defaults to false.
952 bool background_page_is_transient_;
[email protected]9e6720a2012-01-24 02:30:56953
[email protected]7b54ca02012-03-02 18:06:53954 // True if the background page can be scripted by pages of the app or
955 // extension, in which case all such pages must run in the same process.
956 // False if such pages are not permitted to script the background page,
957 // allowing them to run in different processes.
958 bool allow_background_js_access_;
959
[email protected]6f229e82010-11-02 17:47:26960 // Optional URL to a page for setting options/preferences.
961 GURL options_url_;
962
963 // Optional URL to a devtools extension page.
964 GURL devtools_url_;
965
[email protected]6f229e82010-11-02 17:47:26966 // The public key used to sign the contents of the crx package.
967 std::string public_key_;
968
969 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:03970 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:26971
972 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03973 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:26974
975 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03976 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:26977
978 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:03979 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:26980
[email protected]6f229e82010-11-02 17:47:26981 // The homepage for this extension. Useful if it is not hosted by Google and
982 // therefore does not have a Gallery URL.
983 GURL homepage_url_;
984
985 // URL for fetching an update manifest
986 GURL update_url_;
987
[email protected]58f62cf2012-03-09 10:45:11988 // The manifest from which this extension was created.
[email protected]d41e2152012-02-24 04:20:27989 //
990 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would
991 // require manifest.h, which would in turn create a circulate dependency
992 // between extension.h and manifest.h.
993 //
994 // TODO(aa): Pull Extension::Type and Extension::Location out into their own
995 // files so that manifest.h can rely on them and not get all of extension.h
996 // too, and then change this back to a scoped_ptr.
997 extensions::Manifest* manifest_;
[email protected]6f229e82010-11-02 17:47:26998
999 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
1000 // which override the handling of those URLs. (see ExtensionOverrideUI).
1001 URLOverrideMap chrome_url_overrides_;
1002
[email protected]d9696672011-03-15 22:45:091003 // Whether this extension requests isolated storage.
1004 bool is_storage_isolated_;
1005
[email protected]6f229e82010-11-02 17:47:261006 // The local path inside the extension to use with the launcher.
1007 std::string launch_local_path_;
1008
1009 // A web url to use with the launcher. Note that this might be relative or
1010 // absolute. If relative, it is relative to web_origin.
1011 std::string launch_web_url_;
1012
[email protected]4e595682011-02-09 17:07:021013 // The window type that an app's manifest specifies to launch into.
1014 // This is not always the window type an app will open into, because
1015 // users can override the way each app launches. See
1016 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
1017 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:261018 extension_misc::LaunchContainer launch_container_;
1019
1020 // The default size of the container when launching. Only respected for
1021 // containers like panels and windows.
1022 int launch_width_;
1023 int launch_height_;
1024
[email protected]f8c3aea2012-03-01 07:23:201025 // The minimum and maximum size of the container. Only respected for the
1026 // shell container.
[email protected]e5cd5502012-02-29 03:56:431027 int launch_min_width_;
1028 int launch_min_height_;
[email protected]f8c3aea2012-03-01 07:23:201029 int launch_max_width_;
1030 int launch_max_height_;
[email protected]e5cd5502012-02-29 03:56:431031
[email protected]6f229e82010-11-02 17:47:261032 // The Omnibox keyword for this extension, or empty if there is none.
1033 std::string omnibox_keyword_;
1034
[email protected]a4a38c12010-12-23 16:43:561035 // List of text-to-speech voices that this extension provides, if any.
1036 std::vector<TtsVoice> tts_voices_;
1037
[email protected]a79be1f2012-03-23 22:14:001038 // The OAuth2 client id and scopes, if specified by the extension.
1039 OAuth2Info oauth2_info_;
1040
[email protected]56624422011-11-01 22:11:271041 // List of intent services that this extension provides, if any.
1042 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
[email protected]be5f007862011-09-23 00:35:131043
[email protected]3aff9ad2011-04-01 20:26:481044 // Whether the extension has host permissions or user script patterns that
1045 // imply access to file:/// scheme URLs (the user may not have actually
1046 // granted it that access).
1047 bool wants_file_access_;
1048
[email protected]2af352b2011-07-22 08:21:231049 // The flags that were passed to InitFromValue.
1050 int creation_flags_;
[email protected]620db1762011-07-15 21:57:341051
[email protected]7f7b9d932011-04-20 16:13:261052 // The Content-Security-Policy for this extension. Extensions can use
1053 // Content-Security-Policies to mitigate cross-site scripting and other
1054 // vulnerabilities.
1055 std::string content_security_policy_;
1056
[email protected]19118d52010-07-26 22:13:421057 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
1058 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:581059
[email protected]894bb502009-05-21 22:39:571060 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:331061};
1062
[email protected]9adb9692010-10-29 23:14:021063typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:181064typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:561065
[email protected]c6d474f82009-12-16 21:11:061066// Handy struct to pass core extension info around.
1067struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:031068 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:061069 const std::string& id,
1070 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:461071 Extension::Location location);
1072 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:061073
[email protected]f3a1c642011-07-12 19:15:031074 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:061075 std::string extension_id;
1076 FilePath extension_path;
1077 Extension::Location extension_location;
1078
1079 private:
1080 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
1081};
1082
[email protected]a9f39a312010-12-23 22:14:271083struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:591084 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:271085
1086 // Was the extension already disabled?
1087 bool already_disabled;
1088
1089 // The extension being unloaded - this should always be non-NULL.
1090 const Extension* extension;
1091
[email protected]814a7bf0f2011-08-13 05:30:591092 UnloadedExtensionInfo(
1093 const Extension* extension,
1094 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:271095};
1096
[email protected]902fd7b2011-07-27 18:42:311097// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
1098struct UpdatedExtensionPermissionsInfo {
1099 enum Reason {
[email protected]f5532472012-02-23 13:00:551100 ADDED, // The permissions were added to the extension.
1101 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:311102 };
1103
1104 Reason reason;
1105
1106 // The extension who's permissions have changed.
1107 const Extension* extension;
1108
1109 // The permissions that have changed. For Reason::ADDED, this would contain
1110 // only the permissions that have added, and for Reason::REMOVED, this would
1111 // only contain the removed permissions.
1112 const ExtensionPermissionSet* permissions;
1113
1114 UpdatedExtensionPermissionsInfo(
1115 const Extension* extension,
1116 const ExtensionPermissionSet* permissions,
1117 Reason reason);
1118};
1119
[email protected]5b1a0e22009-05-26 19:00:581120#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_