blob: 1184b17d11dd6cbe3927a38d8ee64c4d639b1dec [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]7713d632008-12-02 07:52:337
[email protected]8629c542012-04-20 03:40:038#include <algorithm>
[email protected]18049dc2012-06-19 23:12:559#include <iosfwd>
[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]bebe1d02012-08-02 20:17:0927#include "chrome/common/extensions/permissions/api_permission.h"
28#include "chrome/common/extensions/permissions/permission_message.h"
[email protected]42b6f0f82009-09-18 21:07:3929#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4930#include "chrome/common/extensions/url_pattern.h"
[email protected]cced75a2011-05-20 08:31:1231#include "chrome/common/extensions/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5932#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5533#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3834#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5935
[email protected]942690b132010-05-11 06:42:1436class ExtensionResource;
[email protected]b6b805e92011-04-16 09:24:1437class FileBrowserHandler;
[email protected]12802702010-07-09 19:43:0938class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2839class Version;
[email protected]942690b132010-05-11 06:42:1440
[email protected]f3a1c642011-07-12 19:15:0341namespace base {
42class DictionaryValue;
43class ListValue;
44}
45
[email protected]f0cc7242011-12-13 04:26:1746namespace webkit_glue {
47struct WebIntentServiceData;
48}
49
[email protected]1c321ee2012-05-21 03:02:3450FORWARD_DECLARE_TEST(TabStripModelTest, Apps);
51
52namespace extensions {
53
54class Manifest;
[email protected]bebe1d02012-08-02 20:17:0955class PermissionSet;
[email protected]1c321ee2012-05-21 03:02:3456
[email protected]d4a37f1c2012-07-09 21:36:1357typedef std::set<std::string> OAuth2Scopes;
58
[email protected]f0755532010-06-22 07:27:2559// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4160class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3361 public:
[email protected]1e0f45a2012-06-13 00:31:0662 struct InstallWarning;
63
[email protected]d3cfa482009-10-17 13:54:5764 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1765 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1466 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]1e0f45a2012-06-13 00:31:0667 typedef std::vector<InstallWarning> InstallWarningVector;
[email protected]b24d8312009-08-27 06:47:4668
[email protected]631cf822009-05-15 07:01:2569 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2370 // NOTE: These values are stored as integers in the preferences and used
71 // in histograms so don't remove or reorder existing items. Just append
72 // to the end.
[email protected]631cf822009-05-15 07:01:2573 enum Location {
74 INVALID,
[email protected]25b34332009-06-05 21:53:1975 INTERNAL, // A crx file from the internal Extensions directory.
76 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
77 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
78 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3479 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3280 COMPONENT, // An integral component of Chrome itself, which
81 // happens to be implemented as an extension. We don't
82 // show these in the management UI.
[email protected]4d2913e32010-11-30 00:28:5583 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via
84 // prefs), installed from an update URL.
85 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via
86 // admin policies), installed from an update URL.
[email protected]04cb7542010-10-25 10:50:0687
88 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1989 };
90
91 enum State {
[email protected]0c6da502009-08-14 22:32:3992 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1993 ENABLED,
[email protected]79c833b52011-04-05 18:31:0194 // An external extension that the user uninstalled. We should not reinstall
95 // such extensions on startup.
96 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:3997 NUM_STATES
[email protected]631cf822009-05-15 07:01:2598 };
[email protected]7713d632008-12-02 07:52:3399
[email protected]44d62b62012-04-11 00:06:03100 // Used to record the reason an extension was disabled.
101 enum DisableReason {
102 DISABLE_UNKNOWN,
103 DISABLE_USER_ACTION,
104 DISABLE_PERMISSIONS_INCREASE,
105 DISABLE_RELOAD,
106 DISABLE_LAST, // Not used.
107 };
108
[email protected]fbcc40302009-06-12 20:45:45109 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:37110 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:45111 DOWNGRADE,
112 REINSTALL,
113 UPGRADE,
114 NEW_INSTALL
115 };
116
[email protected]7fa19f82010-12-21 19:40:08117 // Do not change the order of entries or remove entries in this list
118 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
119 enum Type {
[email protected]9b217652010-10-08 22:04:23120 TYPE_UNKNOWN = 0,
121 TYPE_EXTENSION,
122 TYPE_THEME,
123 TYPE_USER_SCRIPT,
124 TYPE_HOSTED_APP,
[email protected]7d3ed2f2011-11-07 23:33:19125 TYPE_PACKAGED_APP,
126 TYPE_PLATFORM_APP
[email protected]9b217652010-10-08 22:04:23127 };
128
[email protected]3bdba0d2011-08-23 07:17:30129 enum SyncType {
130 SYNC_TYPE_NONE = 0,
131 SYNC_TYPE_EXTENSION,
132 SYNC_TYPE_APP
133 };
134
[email protected]92888082010-10-18 19:24:57135 // An NPAPI plugin included in the extension.
136 struct PluginInfo {
137 FilePath path; // Path to the plugin.
138 bool is_public; // False if only this extension can load this plugin.
139 };
140
[email protected]65378f52011-04-08 02:31:23141 // An NaCl module included in the extension.
142 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42143 GURL url;
[email protected]65378f52011-04-08 02:31:23144 std::string mime_type;
145 };
146
[email protected]b0820372011-06-03 07:05:27147 enum InputComponentType {
[email protected]d45f7512011-06-21 21:18:27148 INPUT_COMPONENT_TYPE_NONE = -1,
149 INPUT_COMPONENT_TYPE_IME,
[email protected]b0820372011-06-03 07:05:27150 INPUT_COMPONENT_TYPE_COUNT
151 };
152
153 struct InputComponentInfo {
154 // Define out of line constructor/destructor to please Clang.
155 InputComponentInfo();
156 ~InputComponentInfo();
157
158 std::string name;
159 InputComponentType type;
160 std::string id;
161 std::string description;
162 std::string language;
163 std::set<std::string> layouts;
164 std::string shortcut_keycode;
165 bool shortcut_alt;
166 bool shortcut_ctrl;
167 bool shortcut_shift;
168 };
169
[email protected]a4a38c12010-12-23 16:43:56170 struct TtsVoice {
[email protected]77a3ecac2011-07-07 05:56:33171 // Define out of line constructor/destructor to please Clang.
172 TtsVoice();
173 ~TtsVoice();
174
[email protected]a4a38c12010-12-23 16:43:56175 std::string voice_name;
[email protected]c63f2b72011-07-07 05:25:00176 std::string lang;
[email protected]a4a38c12010-12-23 16:43:56177 std::string gender;
[email protected]c63f2b72011-07-07 05:25:00178 std::set<std::string> event_types;
[email protected]a4a38c12010-12-23 16:43:56179 };
180
[email protected]a79be1f2012-03-23 22:14:00181 // OAuth2 info included in the extension.
182 struct OAuth2Info {
183 OAuth2Info();
184 ~OAuth2Info();
185
[email protected]c2e66e12012-06-27 06:27:06186 OAuth2Scopes GetScopesAsSet();
[email protected]b6f38622012-04-25 03:20:19187
[email protected]a79be1f2012-03-23 22:14:00188 std::string client_id;
189 std::vector<std::string> scopes;
190 };
191
[email protected]1e0f45a2012-06-13 00:31:06192 struct InstallWarning {
193 enum Format {
194 // IMPORTANT: Do not build HTML strings from user or developer-supplied
195 // input.
196 FORMAT_TEXT,
197 FORMAT_HTML,
198 };
199 InstallWarning(Format format, const std::string& message)
200 : format(format), message(message) {
201 }
[email protected]18049dc2012-06-19 23:12:55202 bool operator==(const InstallWarning& other) const;
[email protected]1e0f45a2012-06-13 00:31:06203 Format format;
204 std::string message;
205 };
206
[email protected]83048a22011-03-29 00:14:13207 enum InitFromValueFlags {
208 NO_FLAGS = 0,
209
210 // Usually, the id of an extension is generated by the "key" property of
211 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
212 // generated based on the path.
213 REQUIRE_KEY = 1 << 0,
214
[email protected]3f53dfe2011-11-30 01:18:29215 // Requires the extension to have an up-to-date manifest version.
216 // Typically, we'll support multiple manifest versions during a version
217 // transition. This flag signals that we want to require the most modern
218 // manifest version that Chrome understands.
219 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
220
[email protected]3aff9ad2011-04-01 20:26:48221 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
222 // to have file access. If it's not present, then permissions and content
223 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51224 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34225
226 // |FROM_WEBSTORE| indicates that the extension was installed from the
227 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51228 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05229
230 // |FROM_BOOKMARK| indicates the extension was created using a mock App
231 // created from a bookmark.
[email protected]ed3b9b12012-05-31 18:37:51232 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58233
234 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
235 // anywhere in the filesystem, rather than being restricted to the
236 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51237 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03238
239 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
240 // extension should be errors rather than warnings.
241 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]83048a22011-03-29 00:14:13242 };
243
[email protected]66e4eb32010-10-27 20:37:41244 static scoped_refptr<Extension> Create(const FilePath& path,
245 Location location,
[email protected]f3a1c642011-07-12 19:15:03246 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13247 int flags,
[email protected]66e4eb32010-10-27 20:37:41248 std::string* error);
249
[email protected]87c655e2011-07-01 21:42:00250 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26251 // an explicit id. Most consumers should just use the other Create() method.
252 static scoped_refptr<Extension> Create(const FilePath& path,
[email protected]58f62cf2012-03-09 10:45:11253 Location location,
254 const base::DictionaryValue& value,
255 int flags,
256 const std::string& explicit_id,
257 std::string* error);
[email protected]87c655e2011-07-01 21:42:00258
[email protected]145a317b2011-04-12 16:03:46259 // Given two install sources, return the one which should take priority
260 // over the other. If an extension is installed from two sources A and B,
261 // its install source should be set to GetHigherPriorityLocation(A, B).
262 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
263
[email protected]4c4f8192009-10-17 01:03:26264 // Max size (both dimensions) for browser and page actions.
265 static const int kPageActionIconMaxSize;
266 static const int kBrowserActionIconMaxSize;
267
[email protected]8d888c12010-11-30 00:00:25268 // Valid schemes for web extent URLPatterns.
269 static const int kValidWebExtentSchemes;
270
[email protected]f71f7e62010-12-07 03:45:33271 // Valid schemes for host permission URLPatterns.
272 static const int kValidHostPermissionSchemes;
273
[email protected]6014d672008-12-05 00:38:25274 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16275 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25276
[email protected]300cc58db2009-08-19 20:45:14277 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16278 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14279
280 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16281 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14282
[email protected]25b34332009-06-05 21:53:19283#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19284 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19285#endif
286
[email protected]37eeb5a2009-02-26 23:36:17287 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48288 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17289
[email protected]e435d6b72009-07-25 03:15:58290 // The mimetype used for extensions.
291 static const char kMimeType[];
292
[email protected]25b34332009-06-05 21:53:19293 // Checks to see if the extension has a valid ID.
294 static bool IdIsValid(const std::string& id);
295
[email protected]4ead6f72010-10-13 19:54:18296 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27297 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18298 static std::string GenerateIdForPath(const FilePath& file_name);
299
[email protected]e435d6b72009-07-25 03:15:58300 // Returns true if the specified file is an extension.
301 static bool IsExtension(const FilePath& file_name);
302
[email protected]25b34332009-06-05 21:53:19303 // Whether the |location| is external or not.
304 static inline bool IsExternalLocation(Location location) {
305 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32306 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06307 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
308 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
309 }
310
311 // Whether extensions with |location| are auto-updatable or not.
312 static inline bool IsAutoUpdateableLocation(Location location) {
313 // Only internal and external extensions can be autoupdated.
314 return location == Extension::INTERNAL ||
315 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19316 }
317
[email protected]65187152012-06-02 13:14:14318 // Policy-required extensions are silently auto-installed and updated, and
319 // cannot be disabled or modified by the user in any way. The same applies
320 // to internal components.
321 // This method is not generally called directly; instead, it is accessed
322 // through the ManagementPolicy held by the ExtensionSystem.
323 static inline bool IsRequired(Location location) {
324 return location == Extension::EXTERNAL_POLICY_DOWNLOAD ||
325 location == Extension::COMPONENT;
[email protected]95da88c42011-03-31 10:07:33326 }
327
[email protected]cdfca9702011-08-08 16:07:01328 // Unpacked extensions start off with file access since they are a developer
329 // feature.
330 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
331 return location == Extension::LOAD;
332 }
333
[email protected]fc6b0612012-03-29 13:40:06334 // Fills the |info| dictionary with basic information about the extension.
335 // |enabled| is injected for easier testing.
336 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const;
337
[email protected]7fa19f82010-12-21 19:40:08338 // See Type definition above.
339 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23340
[email protected]07c00d992009-03-04 20:27:04341 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59342 // |extension_url| argument should be the url() from an Extension object. The
343 // |relative_path| can be untrusted user input. The returned URL will either
344 // be invalid() or a child of |extension_url|.
345 // NOTE: Static so that it can be used from multiple threads.
346 static GURL GetResourceURL(const GURL& extension_url,
347 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28348 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24349 return GetResourceURL(url(), relative_path);
350 }
[email protected]eab9b452009-01-23 20:48:59351
[email protected]f59a8052012-06-20 22:25:00352 // Returns true if the resource matches a pattern in the pattern_set.
353 bool ResourceMatches(const URLPatternSet& pattern_set,
354 const std::string& resource) const;
355
[email protected]8f270be2011-12-21 21:15:22356 // Returns true if the specified resource is web accessible.
357 bool IsResourceWebAccessible(const std::string& relative_path) const;
358
[email protected]dbb24162012-06-06 01:41:22359 // Returns true if the specified page is sandboxed (served in a unique
360 // origin).
361 bool IsSandboxedPage(const std::string& relative_path) const;
362
363 // Returns the Content Security Policy that the specified resource should be
364 // served with.
365 std::string GetResourceContentSecurityPolicy(const std::string& relative_path)
366 const;
367
[email protected]8f270be2011-12-21 21:15:22368 // Returns true when 'web_accessible_resources' are defined for the extension.
369 bool HasWebAccessibleResources() const;
370
[email protected]99efb7b12009-12-18 02:39:16371 // Returns an extension resource object. |relative_path| should be UTF8
372 // encoded.
[email protected]9adb9692010-10-29 23:14:02373 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16374
375 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02376 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59377
[email protected]a17f9462009-06-09 02:56:41378 // |input| is expected to be the text of an rsa public or private key. It
379 // tolerates the presence or absence of bracking header/footer like this:
380 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
381 // and may contain newlines.
382 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
383
384 // Does a simple base64 encoding of |input| into |output|.
385 static bool ProducePEM(const std::string& input, std::string* output);
386
[email protected]84ac7f32009-10-06 06:17:54387 // Generates an extension ID from arbitrary input. The same input string will
388 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15389 static bool GenerateId(const std::string& input,
390 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45391
[email protected]a17f9462009-06-09 02:56:41392 // Expects base64 encoded |input| and formats into |output| including
393 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50394 static bool FormatPEMForFileOutput(const std::string& input,
395 std::string* output,
396 bool is_public);
[email protected]a17f9462009-06-09 02:56:41397
[email protected]58f62cf2012-03-09 10:45:11398 // Given an extension, icon size, and match type, read a valid icon if present
[email protected]e3c0bc22012-02-24 01:34:15399 // and decode it into result. In the browser process, this will DCHECK if not
400 // called on the file thread. To easily load extension images on the UI
401 // thread, see ImageLoadingTracker.
402 static void DecodeIcon(const Extension* extension,
403 ExtensionIconSet::Icons icon_size,
404 ExtensionIconSet::MatchType match_type,
405 scoped_ptr<SkBitmap>* result);
406
[email protected]c690a9812009-12-17 05:55:32407 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23408 // result. In the browser process, this will DCHECK if not called on the
409 // file thread. To easily load extension images on the UI thread, see
410 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02411 static void DecodeIcon(const Extension* extension,
[email protected]e3c0bc22012-02-24 01:34:15412 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32413 scoped_ptr<SkBitmap>* result);
414
415 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23416 // result. In the browser process, this will DCHECK if not called on the
417 // file thread. To easily load extension images on the UI thread, see
418 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32419 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]e3c0bc22012-02-24 01:34:15420 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32421 scoped_ptr<SkBitmap>* result);
422
[email protected]5349ac6d2011-04-05 22:20:17423 // Returns the default extension/app icon (for extensions or apps that don't
424 // have one).
425 static const SkBitmap& GetDefaultIcon(bool is_app);
426
[email protected]a807bbe2010-04-14 10:51:19427 // Returns the base extension url for a given |extension_id|.
428 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
429
[email protected]be7e5cb2010-10-04 12:53:17430 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17431 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21432 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17433
[email protected]902fd7b2011-07-27 18:42:31434 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27435 // from |manifest_|.
436 bool ParsePermissions(const char* key,
[email protected]fc670822011-12-17 09:33:49437 string16* error,
[email protected]c2e66e12012-06-27 06:27:06438 APIPermissionSet* api_permissions,
[email protected]902fd7b2011-07-27 18:42:31439 URLPatternSet* host_permissions);
440
[email protected]c2e66e12012-06-27 06:27:06441 bool HasAPIPermission(APIPermission::ID permission) const;
[email protected]0d3e4a22011-06-23 19:02:52442 bool HasAPIPermission(const std::string& function_name) const;
[email protected]3d0e2262012-08-02 15:32:16443 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const;
[email protected]583d45c12010-08-31 02:48:12444
[email protected]0d3e4a22011-06-23 19:02:52445 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46446
[email protected]902fd7b2011-07-27 18:42:31447 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16448 // Users must approve permissions for unpacked and packed extensions in the
449 // following situations:
450 // - when installing or upgrading packed extensions
451 // - when installing unpacked extensions that have NPAPI plugins
452 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31453 bool CanSilentlyIncreasePermissions() const;
454
[email protected]584b8e3f2010-04-10 00:23:37455 // Whether the extension has access to the given URL.
456 bool HasHostPermission(const GURL& url) const;
457
[email protected]0df165f2010-09-28 16:49:40458 // Whether the extension has effective access to all hosts. This is true if
459 // there is a content script that matches all hosts, if there is a host
460 // permission grants access to all hosts (like <all_urls>) or an api
461 // permission that effectively grants access to all hosts (e.g. proxy,
462 // network, etc.)
463 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46464
[email protected]8d888c12010-11-30 00:00:25465 // Whether the extension effectively has all permissions (for example, by
466 // having an NPAPI plugin).
467 bool HasFullPermissions() const;
468
[email protected]902fd7b2011-07-27 18:42:31469 // Returns the full list of permission messages that this extension
470 // should display at install time.
[email protected]c2e66e12012-06-27 06:27:06471 PermissionMessages GetPermissionMessages() const;
[email protected]902fd7b2011-07-27 18:42:31472
473 // Returns the full list of permission messages that this extension
474 // should display at install time. The messages are returned as strings
475 // for convenience.
476 std::vector<string16> GetPermissionMessageStrings() const;
477
478 // Sets the active |permissions|.
[email protected]c2e66e12012-06-27 06:27:06479 void SetActivePermissions(const PermissionSet* permissions) const;
[email protected]902fd7b2011-07-27 18:42:31480
481 // Gets the extension's active permission set.
[email protected]c2e66e12012-06-27 06:27:06482 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31483
[email protected]5df6a5d2011-01-26 07:39:12484 // Whether context menu should be shown for page and browser actions.
485 bool ShowConfigureContextMenus() const;
486
[email protected]37cd64d2010-10-25 18:17:58487 // Returns the Homepage URL for this extension. If homepage_url was not
488 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23489 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58490 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23491
[email protected]facd7a7652009-06-05 23:15:02492 // Returns a list of paths (relative to the extension dir) for images that
493 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02494 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02495
[email protected]807871f2010-09-16 01:04:48496 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02497 ExtensionResource GetIconResource(
498 int size, ExtensionIconSet::MatchType match_type) const;
499 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08500
[email protected]867a73e12010-03-19 20:45:46501 // Gets the fully resolved absolute launch URL.
502 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21503
[email protected]6f229e82010-11-02 17:47:26504 // Image cache related methods. These are only valid on the UI thread and
505 // not maintained by this class. See ImageLoadingTracker for usage. The
506 // |original_size| parameter should be the size of the image at |source|
507 // before any scaling may have been done to produce the pixels in |image|.
508 void SetCachedImage(const ExtensionResource& source,
509 const SkBitmap& image,
510 const gfx::Size& original_size) const;
511 bool HasCachedImage(const ExtensionResource& source,
512 const gfx::Size& max_size) const;
513 SkBitmap GetCachedImage(const ExtensionResource& source,
514 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21515
516 // Returns true if this extension can execute script on a page. If a
517 // UserScript object is passed, permission to run that specific script is
518 // checked (using its matches list). Otherwise, permission to execute script
519 // programmatically is checked (using the extension's host permission).
520 //
521 // This method is also aware of certain special pages that extensions are
522 // usually not allowed to run script on.
523 bool CanExecuteScriptOnPage(const GURL& page_url,
[email protected]fc5e65d6b2012-06-13 00:22:57524 int tab_id,
[email protected]3aff9ad2011-04-01 20:26:48525 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21526 std::string* error) const;
527
[email protected]6f229e82010-11-02 17:47:26528 // Returns true if this extension is a COMPONENT extension, or if it is
529 // on the whitelist of extensions that can script all pages.
530 bool CanExecuteScriptEverywhere() const;
531
[email protected]5efbfe012011-02-22 23:07:18532 // Returns true if this extension is allowed to obtain the contents of a
533 // page as an image. Since a page may contain sensitive information, this
534 // is restricted to the extension's host permissions as well as the
535 // extension page itself.
[email protected]fc5e65d6b2012-06-13 00:22:57536 bool CanCaptureVisiblePage(const GURL& page_url,
537 int tab_id,
538 std::string* error) const;
[email protected]5efbfe012011-02-22 23:07:18539
[email protected]a65882c2010-11-12 15:15:09540 // Returns true if this extension updates itself using the extension
541 // gallery.
542 bool UpdatesFromGallery() const;
543
[email protected]cca147172011-02-17 01:29:29544 // Returns true if this extension or app includes areas within |origin|.
545 bool OverlapsWithOrigin(const GURL& origin) const;
546
[email protected]3bdba0d2011-08-23 07:17:30547 // Returns the sync bucket to use for this extension.
548 SyncType GetSyncType() const;
549
[email protected]b873cd92012-02-09 21:51:48550 // Returns true if the extension should be synced.
551 bool IsSyncable() const;
552
553 // Returns true if the extension should be displayed in the launcher.
554 bool ShouldDisplayInLauncher() const;
555
[email protected]e0b3de72012-05-01 01:21:34556 // Returns true if the extension should be displayed in the extension
557 // settings page (i.e. chrome://extensions).
558 bool ShouldDisplayInExtensionSettings() const;
559
[email protected]4f886012012-05-19 03:51:10560 // Returns true if the extension has a content script declared at |url|.
561 bool HasContentScriptAtURL(const GURL& url) const;
562
[email protected]fc5e65d6b2012-06-13 00:22:57563 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
564 // aren't any.
[email protected]3d0e2262012-08-02 15:32:16565 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
566 const;
[email protected]fc5e65d6b2012-06-13 00:22:57567
[email protected]3d0e2262012-08-02 15:32:16568 // Updates the tab-specific permissions of |tab_id| to include those from
569 // |permissions|.
[email protected]6144057e2012-08-02 19:02:37570 void UpdateTabSpecificPermissions(
571 int tab_id,
572 scoped_refptr<const PermissionSet> permissions) const;
[email protected]fc5e65d6b2012-06-13 00:22:57573
[email protected]3d0e2262012-08-02 15:32:16574 // Clears the tab-specific permissions of |tab_id|.
575 void ClearTabSpecificPermissions(int tab_id) const;
[email protected]fc5e65d6b2012-06-13 00:22:57576
[email protected]6f229e82010-11-02 17:47:26577 // Accessors:
578
579 const FilePath& path() const { return path_; }
580 const GURL& url() const { return extension_url_; }
[email protected]d41e2152012-02-24 04:20:27581 Location location() const;
582 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26583 const Version* version() const { return version_.get(); }
584 const std::string VersionString() const;
585 const std::string& name() const { return name_; }
[email protected]701d1e82012-05-14 05:34:19586 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06587 // Base64-encoded version of the key used to sign this extension.
588 // In pseudocode, returns
589 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
590 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26591 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31592 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26593 bool converted_from_user_script() const {
594 return converted_from_user_script_;
595 }
596 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]18049dc2012-06-19 23:12:55597 ExtensionAction* script_badge() const { return script_badge_.get(); }
[email protected]6f229e82010-11-02 17:47:26598 ExtensionAction* page_action() const { return page_action_.get(); }
599 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]b6b805e92011-04-16 09:24:14600 const FileBrowserHandlerList* file_browser_handlers() const {
601 return file_browser_handlers_.get();
602 }
[email protected]6f229e82010-11-02 17:47:26603 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23604 const std::vector<NaClModuleInfo>& nacl_modules() const {
605 return nacl_modules_;
606 }
[email protected]b0820372011-06-03 07:05:27607 const std::vector<InputComponentInfo>& input_components() const {
608 return input_components_;
609 }
[email protected]7c519ab2012-05-04 10:02:51610 // The browser action command that the extension wants to use, which is not
611 // necessarily the one it can use, as it might be inactive (see also
[email protected]d179cdd2012-08-03 08:32:52612 // GetBrowserActionCommand in CommandService).
[email protected]3fc5f6a2012-05-04 14:23:59613 const extensions::Command* browser_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30614 return browser_action_command_.get();
615 }
[email protected]7c519ab2012-05-04 10:02:51616 // The page action command that the extension wants to use, which is not
617 // necessarily the one it can use, as it might be inactive (see also
[email protected]d179cdd2012-08-03 08:32:52618 // GetPageActionCommand in CommandService).
[email protected]3fc5f6a2012-05-04 14:23:59619 const extensions::Command* page_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30620 return page_action_command_.get();
621 }
[email protected]d179cdd2012-08-03 08:32:52622 // The script badge command that the extension wants to use, which is not
623 // necessarily the one it can use, as it might be inactive (see also
624 // GetScriptBadgeCommand in CommandService).
625 const extensions::Command* script_badge_command() const {
626 return script_badge_command_.get();
627 }
[email protected]7c519ab2012-05-04 10:02:51628 // The map (of command names to commands) that the extension wants to use,
[email protected]422656932012-05-03 09:31:51629 // which is not necessarily the one it can use, as they might be inactive
[email protected]d179cdd2012-08-03 08:32:52630 // (see also GetNamedCommands in CommandService).
[email protected]3fc5f6a2012-05-04 14:23:59631 const extensions::CommandMap& named_commands() const {
[email protected]9c8b54d2012-04-02 10:17:30632 return named_commands_;
[email protected]f5532472012-02-23 13:00:55633 }
[email protected]a03d4448f2012-01-10 23:25:28634 bool has_background_page() const {
635 return background_url_.is_valid() || !background_scripts_.empty();
636 }
[email protected]7b54ca02012-03-02 18:06:53637 bool allow_background_js_access() const {
638 return allow_background_js_access_;
639 }
[email protected]a03d4448f2012-01-10 23:25:28640 const std::vector<std::string>& background_scripts() const {
641 return background_scripts_;
642 }
[email protected]d2aa06b2012-03-21 20:57:26643 bool has_persistent_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00644 return has_background_page() && background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26645 }
646 bool has_lazy_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00647 return has_background_page() && !background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26648 }
[email protected]6f229e82010-11-02 17:47:26649 const GURL& options_url() const { return options_url_; }
650 const GURL& devtools_url() const { return devtools_url_; }
[email protected]c2e66e12012-06-27 06:27:06651 const PermissionSet* optional_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31652 return optional_permission_set_.get();
653 }
[email protected]c2e66e12012-06-27 06:27:06654 const PermissionSet* required_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31655 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26656 }
[email protected]ab55c2b2012-06-01 23:55:03657 // Appends |new_warnings| to install_warnings().
[email protected]1e0f45a2012-06-13 00:31:06658 void AddInstallWarnings(const InstallWarningVector& new_warnings);
659 const InstallWarningVector& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03660 return install_warnings_;
661 }
[email protected]6f229e82010-11-02 17:47:26662 const GURL& update_url() const { return update_url_; }
663 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32664 const extensions::Manifest* manifest() const {
[email protected]d41e2152012-02-24 04:20:27665 return manifest_;
[email protected]6f229e82010-11-02 17:47:26666 }
667 const std::string default_locale() const { return default_locale_; }
668 const URLOverrideMap& GetChromeURLOverrides() const {
669 return chrome_url_overrides_;
670 }
671 const std::string omnibox_keyword() const { return omnibox_keyword_; }
672 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55673 bool offline_enabled() const { return offline_enabled_; }
[email protected]a4a38c12010-12-23 16:43:56674 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]a79be1f2012-03-23 22:14:00675 const OAuth2Info& oauth2_info() const { return oauth2_info_; }
[email protected]56624422011-11-01 22:11:27676 const std::vector<webkit_glue::WebIntentServiceData>&
677 intents_services() const {
678 return intents_services_;
679 }
[email protected]6f229e82010-11-02 17:47:26680
[email protected]3aff9ad2011-04-01 20:26:48681 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23682 int creation_flags() const { return creation_flags_; }
683 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05684 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]3aff9ad2011-04-01 20:26:48685
[email protected]6f229e82010-11-02 17:47:26686 // App-related.
[email protected]953620b2011-12-04 00:55:32687 bool is_app() const {
688 return is_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39689 }
[email protected]d41e2152012-02-24 04:20:27690 bool is_platform_app() const;
691 bool is_hosted_app() const;
692 bool is_packaged_app() const;
[email protected]605fb8102012-05-04 01:36:55693 bool is_storage_isolated() const { return is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12694 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26695 const std::string& launch_local_path() const { return launch_local_path_; }
696 const std::string& launch_web_url() const { return launch_web_url_; }
697 extension_misc::LaunchContainer launch_container() const {
698 return launch_container_;
699 }
[email protected]dc37b002012-04-23 23:02:26700 int launch_width() const { return launch_width_; }
701 int launch_height() const { return launch_height_; }
[email protected]6f229e82010-11-02 17:47:26702
703 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27704 bool is_theme() const;
[email protected]f3a1c642011-07-12 19:15:03705 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
706 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
707 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
708 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26709 return theme_display_properties_.get();
710 }
711
[email protected]a03d4448f2012-01-10 23:25:28712 GURL GetBackgroundURL() const;
713
[email protected]4a8d3272009-03-10 19:15:08714 private:
[email protected]66e4eb32010-10-27 20:37:41715 friend class base::RefCountedThreadSafe<Extension>;
716
[email protected]d7e9a862010-11-03 21:57:49717 // We keep a cache of images loaded from extension resources based on their
718 // path and a string representation of a size that may have been used to
719 // scale it (or the empty string if the image is at its original size).
720 typedef std::pair<FilePath, std::string> ImageCacheKey;
721 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
722
[email protected]902fd7b2011-07-27 18:42:31723 class RuntimeData {
724 public:
725 RuntimeData();
[email protected]c2e66e12012-06-27 06:27:06726 explicit RuntimeData(const PermissionSet* active);
[email protected]902fd7b2011-07-27 18:42:31727 ~RuntimeData();
728
[email protected]c2e66e12012-06-27 06:27:06729 void SetActivePermissions(const PermissionSet* active);
730 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31731
[email protected]3d0e2262012-08-02 15:32:16732 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
733 const;
[email protected]6144057e2012-08-02 19:02:37734 void UpdateTabSpecificPermissions(
735 int tab_id,
736 scoped_refptr<const PermissionSet> permissions);
[email protected]3d0e2262012-08-02 15:32:16737 void ClearTabSpecificPermissions(int tab_id);
[email protected]fc5e65d6b2012-06-13 00:22:57738
[email protected]902fd7b2011-07-27 18:42:31739 private:
740 friend class base::RefCountedThreadSafe<RuntimeData>;
[email protected]fc5e65d6b2012-06-13 00:22:57741
[email protected]c2e66e12012-06-27 06:27:06742 scoped_refptr<const PermissionSet> active_permissions_;
[email protected]fc5e65d6b2012-06-13 00:22:57743
[email protected]3d0e2262012-08-02 15:32:16744 typedef std::map<int, scoped_refptr<const PermissionSet> >
745 TabPermissionsMap;
746 TabPermissionsMap tab_specific_permissions_;
[email protected]902fd7b2011-07-27 18:42:31747 };
748
[email protected]d41e2152012-02-24 04:20:27749 // Chooses the extension ID for an extension based on a variety of criteria.
750 // The chosen ID will be set in |manifest|.
751 static bool InitExtensionID(extensions::Manifest* manifest,
752 const FilePath& path,
753 const std::string& explicit_id,
754 int creation_flags,
755 string16* error);
756
[email protected]4ead6f72010-10-13 19:54:18757 // Normalize the path for use by the extension. On Windows, this will make
758 // sure the drive letter is uppercase.
759 static FilePath MaybeNormalizePath(const FilePath& path);
760
[email protected]87c655e2011-07-01 21:42:00761 // Returns true if this extension id is from a trusted provider.
762 static bool IsTrustedId(const std::string& id);
763
[email protected]d41e2152012-02-24 04:20:27764 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
[email protected]66e4eb32010-10-27 20:37:41765 ~Extension();
766
767 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27768 // TODO(aa): Rename to just Init()? There's no Value here anymore.
769 // TODO(aa): It is really weird the way this class essentially contains a copy
770 // of the underlying DictionaryValue in its members. We should decide to
771 // either wrap the DictionaryValue and go with that only, or we should parse
772 // into strong types and discard the value. But doing both is bad.
773 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41774
[email protected]58f62cf2012-03-09 10:45:11775 // The following are helpers for InitFromValue to load various features of the
776 // extension from the manifest.
777
778 bool CheckMinimumChromeVersion(string16* error);
[email protected]c2e66e12012-06-27 06:27:06779 bool LoadAppIsolation(const APIPermissionSet& api_permissions,
[email protected]605fb8102012-05-04 01:36:55780 string16* error);
[email protected]58f62cf2012-03-09 10:45:11781
782 bool LoadRequiredFeatures(string16* error);
783 bool LoadName(string16* error);
784 bool LoadVersion(string16* error);
785
786 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27787 bool LoadExtent(const char* key,
788 URLPatternSet* extent,
789 const char* list_error,
790 const char* value_error,
791 string16* error);
792 bool LoadLaunchContainer(string16* error);
793 bool LoadLaunchURL(string16* error);
[email protected]10253da2012-03-09 04:06:42794
[email protected]c2e66e12012-06-27 06:27:06795 bool LoadSharedFeatures(const APIPermissionSet& api_permissions,
[email protected]58f62cf2012-03-09 10:45:11796 string16* error);
797 bool LoadDescription(string16* error);
798 bool LoadManifestVersion(string16* error);
799 bool LoadHomepageURL(string16* error);
800 bool LoadUpdateURL(string16* error);
801 bool LoadIcons(string16* error);
802 bool LoadCommands(string16* error);
803 bool LoadPlugins(string16* error);
804 bool LoadNaClModules(string16* error);
805 bool LoadWebAccessibleResources(string16* error);
[email protected]dbb24162012-06-06 01:41:22806 bool LoadSandboxedPages(string16* error);
[email protected]58f62cf2012-03-09 10:45:11807 bool CheckRequirements(string16* error);
808 bool LoadDefaultLocale(string16* error);
809 bool LoadOfflineEnabled(string16* error);
810 bool LoadOptionsPage(string16* error);
[email protected]d41e2152012-02-24 04:20:27811 bool LoadBackgroundScripts(string16* error);
[email protected]756038532012-06-08 05:45:03812 bool LoadBackgroundScripts(const std::string& key, string16* error);
[email protected]c2e66e12012-06-27 06:27:06813 bool LoadBackgroundPage(const APIPermissionSet& api_permissions,
[email protected]d41e2152012-02-24 04:20:27814 string16* error);
[email protected]756038532012-06-08 05:45:03815 bool LoadBackgroundPage(const std::string& key,
[email protected]c2e66e12012-06-27 06:27:06816 const APIPermissionSet& api_permissions,
[email protected]756038532012-06-08 05:45:03817 string16* error);
[email protected]dd62fa802012-04-25 18:37:00818 bool LoadBackgroundPersistent(
[email protected]c2e66e12012-06-27 06:27:06819 const APIPermissionSet& api_permissions,
[email protected]d41e2152012-02-24 04:20:27820 string16* error);
[email protected]58f62cf2012-03-09 10:45:11821 bool LoadBackgroundAllowJSAccess(
[email protected]c2e66e12012-06-27 06:27:06822 const APIPermissionSet& api_permissions,
[email protected]7b54ca02012-03-02 18:06:53823 string16* error);
[email protected]58f62cf2012-03-09 10:45:11824 // Parses a single action in the manifest.
825 bool LoadWebIntentAction(const std::string& action_name,
826 const base::DictionaryValue& intent_service,
827 string16* error);
828 bool LoadWebIntentServices(string16* error);
[email protected]c2e66e12012-06-27 06:27:06829 bool LoadExtensionFeatures(const APIPermissionSet& api_permissions,
[email protected]58f62cf2012-03-09 10:45:11830 string16* error);
831 bool LoadDevToolsPage(string16* error);
[email protected]c2e66e12012-06-27 06:27:06832 bool LoadInputComponents(const APIPermissionSet& api_permissions,
[email protected]58f62cf2012-03-09 10:45:11833 string16* error);
834 bool LoadContentScripts(string16* error);
835 bool LoadPageAction(string16* error);
836 bool LoadBrowserAction(string16* error);
[email protected]18049dc2012-06-19 23:12:55837 bool LoadScriptBadge(string16* error);
[email protected]58f62cf2012-03-09 10:45:11838 bool LoadFileBrowserHandlers(string16* error);
839 // Helper method to load a FileBrowserHandlerList from the manifest.
840 FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
841 const base::ListValue* extension_actions, string16* error);
842 // Helper method to load an FileBrowserHandler from manifest.
843 FileBrowserHandler* LoadFileBrowserHandler(
844 const base::DictionaryValue* file_browser_handlers, string16* error);
845 bool LoadChromeURLOverrides(string16* error);
846 bool LoadOmnibox(string16* error);
847 bool LoadTextToSpeechVoices(string16* error);
848 bool LoadIncognitoMode(string16* error);
849 bool LoadContentSecurityPolicy(string16* error);
850
851 bool LoadThemeFeatures(string16* error);
852 bool LoadThemeImages(const base::DictionaryValue* theme_value,
853 string16* error);
854 bool LoadThemeColors(const base::DictionaryValue* theme_value,
855 string16* error);
856 bool LoadThemeTints(const base::DictionaryValue* theme_value,
857 string16* error);
858 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value,
859 string16* error);
860
861 // Helper function for implementing HasCachedImage/GetCachedImage. A return
862 // value of NULL means there is no matching image cached (we allow caching an
863 // empty SkBitmap).
864 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
865 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18866
[email protected]3cfbd0e2009-03-18 21:26:24867 // Helper method that loads a UserScript object from a
868 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03869 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24870 int definition_index,
[email protected]fc670822011-12-17 09:33:49871 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24872 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34873
[email protected]6657afa62009-11-04 02:15:20874 // Helper method that loads either the include_globs or exclude_globs list
875 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03876 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20877 int content_script_index,
[email protected]e2194742010-08-12 05:54:34878 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49879 string16* error,
[email protected]11f4857282009-11-13 19:56:17880 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20881 UserScript *instance);
882
[email protected]5d246db22009-10-27 06:17:57883 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08884 // browser_action entries in the manifest.
[email protected]3349b592012-04-26 12:35:28885 scoped_ptr<ExtensionAction> LoadExtensionActionHelper(
[email protected]18049dc2012-06-19 23:12:55886 const base::DictionaryValue* extension_action,
887 ExtensionAction::Type action_type,
888 string16* error);
[email protected]92c6f9b92009-10-24 04:35:08889
[email protected]a79be1f2012-03-23 22:14:00890 // Helper method that loads the OAuth2 info from the 'oauth2' manifest key.
891 bool LoadOAuth2Info(string16* error);
892
[email protected]2f6698b2010-10-14 00:58:21893 // Returns true if the extension has more than one "UI surface". For example,
894 // an extension that has a browser action and a page action.
895 bool HasMultipleUISurfaces() const;
896
[email protected]be9d9c82011-07-13 04:17:31897 // Updates the launch URL and extents for the extension using the given
898 // |override_url|.
899 void OverrideLaunchUrl(const GURL& override_url);
900
[email protected]ae655e4e2012-03-16 21:47:55901 // Custom checks for the experimental permission that can't be expressed in
902 // _permission_features.json.
[email protected]5eddc3e2011-10-26 04:33:31903 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31904
905 // Checks whether the host |pattern| is allowed for this extension, given API
906 // permissions |permissions|.
907 bool CanSpecifyHostPermission(const URLPattern& pattern,
[email protected]c2e66e12012-06-27 06:27:06908 const APIPermissionSet& permissions) const;
[email protected]5eddc3e2011-10-26 04:33:31909
[email protected]e92169e2012-05-04 22:49:32910 // Check that platform app features are valid. Called after InitFromValue.
911 bool CheckPlatformAppFeatures(std::string* utf8_error);
912
[email protected]f1bab9c92012-05-11 21:15:10913 // Check that features don't conflict. Called after InitFromValue.
914 bool CheckConflictingFeatures(std::string* utf8_error);
915
[email protected]d7e9a862010-11-03 21:57:49916 // Cached images for this extension. This should only be touched on the UI
917 // thread.
918 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31919
[email protected]6f229e82010-11-02 17:47:26920 // The extension's human-readable name. Name is used for display purpose. It
921 // might be wrapped with unicode bidi control characters so that it is
922 // displayed correctly in RTL context.
923 // NOTE: Name is UTF-8 and may contain non-ascii characters.
924 std::string name_;
925
[email protected]701d1e82012-05-14 05:34:19926 // A non-localized version of the extension's name. This is useful for
927 // debug output.
928 std::string non_localized_name_;
929
[email protected]a47c8a22011-11-17 18:40:31930 // The version of this extension's manifest. We increase the manifest
931 // version when making breaking changes to the extension system.
932 // Version 1 was the first manifest version (implied by a lack of a
933 // manifest_version attribute in the extension's manifest). We initialize
934 // this member variable to 0 to distinguish the "uninitialized" case from
935 // the case when we know the manifest version actually is 1.
936 int manifest_version_;
937
[email protected]d41e2152012-02-24 04:20:27938 // The absolute path to the directory the extension is stored in.
939 FilePath path_;
940
[email protected]6f229e82010-11-02 17:47:26941 // Default locale for fall back. Can be empty if extension is not localized.
942 std::string default_locale_;
943
944 // If true, a separate process will be used for the extension in incognito
945 // mode.
946 bool incognito_split_mode_;
947
[email protected]1abdf4f2011-08-16 21:11:55948 // Whether the extension or app should be enabled when offline.
949 bool offline_enabled_;
950
[email protected]6f229e82010-11-02 17:47:26951 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12952 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26953
[email protected]902fd7b2011-07-27 18:42:31954 // The extension runtime data.
955 mutable base::Lock runtime_data_lock_;
956 mutable RuntimeData runtime_data_;
957
958 // The set of permissions the extension can request at runtime.
[email protected]c2e66e12012-06-27 06:27:06959 scoped_refptr<const PermissionSet> optional_permission_set_;
[email protected]902fd7b2011-07-27 18:42:31960
961 // The extension's required / default set of permissions.
[email protected]c2e66e12012-06-27 06:27:06962 scoped_refptr<const PermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26963
[email protected]8629c542012-04-20 03:40:03964 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1e0f45a2012-06-13 00:31:06965 InstallWarningVector install_warnings_;
[email protected]8629c542012-04-20 03:40:03966
[email protected]6f229e82010-11-02 17:47:26967 // The icons for the extension.
968 ExtensionIconSet icons_;
969
970 // The base extension url for the extension.
971 GURL extension_url_;
972
[email protected]6f229e82010-11-02 17:47:26973 // The extension's version.
974 scoped_ptr<Version> version_;
975
976 // An optional longer description of the extension.
977 std::string description_;
978
979 // True if the extension was generated from a user script. (We show slightly
980 // different UI if so).
981 bool converted_from_user_script_;
982
983 // Paths to the content scripts the extension contains.
984 UserScriptList content_scripts_;
985
986 // The extension's page action, if any.
987 scoped_ptr<ExtensionAction> page_action_;
988
989 // The extension's browser action, if any.
990 scoped_ptr<ExtensionAction> browser_action_;
991
[email protected]18049dc2012-06-19 23:12:55992 // The extension's script badge. Never NULL.
993 scoped_ptr<ExtensionAction> script_badge_;
[email protected]0f156a62012-05-28 16:36:36994
[email protected]b6b805e92011-04-16 09:24:14995 // The extension's file browser actions, if any.
996 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
997
[email protected]6f229e82010-11-02 17:47:26998 // Optional list of NPAPI plugins and associated properties.
999 std::vector<PluginInfo> plugins_;
1000
[email protected]65378f52011-04-08 02:31:231001 // Optional list of NaCl modules and associated properties.
1002 std::vector<NaClModuleInfo> nacl_modules_;
1003
[email protected]b0820372011-06-03 07:05:271004 // Optional list of input components and associated properties.
1005 std::vector<InputComponentInfo> input_components_;
1006
[email protected]f5532472012-02-23 13:00:551007 // Optional list of commands (keyboard shortcuts).
[email protected]3fc5f6a2012-05-04 14:23:591008 scoped_ptr<extensions::Command> browser_action_command_;
1009 scoped_ptr<extensions::Command> page_action_command_;
[email protected]d179cdd2012-08-03 08:32:521010 scoped_ptr<extensions::Command> script_badge_command_;
[email protected]3fc5f6a2012-05-04 14:23:591011 extensions::CommandMap named_commands_;
[email protected]f5532472012-02-23 13:00:551012
[email protected]8f270be2011-12-21 21:15:221013 // Optional list of web accessible extension resources.
[email protected]f59a8052012-06-20 22:25:001014 URLPatternSet web_accessible_resources_;
[email protected]8f270be2011-12-21 21:15:221015
[email protected]dbb24162012-06-06 01:41:221016 // Optional list of extension pages that are sandboxed (served from a unique
1017 // origin with a different Content Security Policy).
[email protected]f59a8052012-06-20 22:25:001018 URLPatternSet sandboxed_pages_;
[email protected]dbb24162012-06-06 01:41:221019
1020 // Content Security Policy that should be used to enforce the sandbox used
1021 // by sandboxed pages (guaranteed to have the "sandbox" directive without the
1022 // "allow-same-origin" token).
1023 std::string sandboxed_pages_content_security_policy_;
1024
[email protected]6f229e82010-11-02 17:47:261025 // Optional URL to a master page of which a single instance should be always
1026 // loaded in the background.
1027 GURL background_url_;
1028
[email protected]a03d4448f2012-01-10 23:25:281029 // Optional list of scripts to use to generate a background page. If this is
1030 // present, background_url_ will be empty and generated by GetBackgroundURL().
1031 std::vector<std::string> background_scripts_;
1032
[email protected]dd62fa802012-04-25 18:37:001033 // True if the background page should stay loaded forever; false if it should
1034 // load on-demand (when it needs to handle an event). Defaults to true.
1035 bool background_page_is_persistent_;
[email protected]9e6720a2012-01-24 02:30:561036
[email protected]7b54ca02012-03-02 18:06:531037 // True if the background page can be scripted by pages of the app or
1038 // extension, in which case all such pages must run in the same process.
1039 // False if such pages are not permitted to script the background page,
1040 // allowing them to run in different processes.
1041 bool allow_background_js_access_;
1042
[email protected]6f229e82010-11-02 17:47:261043 // Optional URL to a page for setting options/preferences.
1044 GURL options_url_;
1045
1046 // Optional URL to a devtools extension page.
1047 GURL devtools_url_;
1048
[email protected]6f229e82010-11-02 17:47:261049 // The public key used to sign the contents of the crx package.
1050 std::string public_key_;
1051
1052 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:031053 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:261054
1055 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:031056 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:261057
1058 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:031059 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:261060
1061 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:031062 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:261063
[email protected]6f229e82010-11-02 17:47:261064 // The homepage for this extension. Useful if it is not hosted by Google and
1065 // therefore does not have a Gallery URL.
1066 GURL homepage_url_;
1067
1068 // URL for fetching an update manifest
1069 GURL update_url_;
1070
[email protected]58f62cf2012-03-09 10:45:111071 // The manifest from which this extension was created.
[email protected]d41e2152012-02-24 04:20:271072 //
1073 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would
1074 // require manifest.h, which would in turn create a circulate dependency
1075 // between extension.h and manifest.h.
1076 //
1077 // TODO(aa): Pull Extension::Type and Extension::Location out into their own
1078 // files so that manifest.h can rely on them and not get all of extension.h
1079 // too, and then change this back to a scoped_ptr.
1080 extensions::Manifest* manifest_;
[email protected]6f229e82010-11-02 17:47:261081
1082 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
1083 // which override the handling of those URLs. (see ExtensionOverrideUI).
1084 URLOverrideMap chrome_url_overrides_;
1085
[email protected]d9696672011-03-15 22:45:091086 // Whether this extension requests isolated storage.
1087 bool is_storage_isolated_;
1088
[email protected]6f229e82010-11-02 17:47:261089 // The local path inside the extension to use with the launcher.
1090 std::string launch_local_path_;
1091
1092 // A web url to use with the launcher. Note that this might be relative or
1093 // absolute. If relative, it is relative to web_origin.
1094 std::string launch_web_url_;
1095
[email protected]4e595682011-02-09 17:07:021096 // The window type that an app's manifest specifies to launch into.
1097 // This is not always the window type an app will open into, because
1098 // users can override the way each app launches. See
1099 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
1100 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:261101 extension_misc::LaunchContainer launch_container_;
1102
1103 // The default size of the container when launching. Only respected for
1104 // containers like panels and windows.
1105 int launch_width_;
1106 int launch_height_;
1107
1108 // The Omnibox keyword for this extension, or empty if there is none.
1109 std::string omnibox_keyword_;
1110
[email protected]a4a38c12010-12-23 16:43:561111 // List of text-to-speech voices that this extension provides, if any.
1112 std::vector<TtsVoice> tts_voices_;
1113
[email protected]a79be1f2012-03-23 22:14:001114 // The OAuth2 client id and scopes, if specified by the extension.
1115 OAuth2Info oauth2_info_;
1116
[email protected]56624422011-11-01 22:11:271117 // List of intent services that this extension provides, if any.
1118 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
[email protected]be5f007862011-09-23 00:35:131119
[email protected]3aff9ad2011-04-01 20:26:481120 // Whether the extension has host permissions or user script patterns that
1121 // imply access to file:/// scheme URLs (the user may not have actually
1122 // granted it that access).
1123 bool wants_file_access_;
1124
[email protected]2af352b2011-07-22 08:21:231125 // The flags that were passed to InitFromValue.
1126 int creation_flags_;
[email protected]620db1762011-07-15 21:57:341127
[email protected]7f7b9d932011-04-20 16:13:261128 // The Content-Security-Policy for this extension. Extensions can use
1129 // Content-Security-Policies to mitigate cross-site scripting and other
1130 // vulnerabilities.
1131 std::string content_security_policy_;
1132
[email protected]19118d52010-07-26 22:13:421133 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
[email protected]1c321ee2012-05-21 03:02:341134 FRIEND_TEST_ALL_PREFIXES(::TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:581135
[email protected]894bb502009-05-21 22:39:571136 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:331137};
1138
[email protected]9adb9692010-10-29 23:14:021139typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:181140typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:561141
[email protected]18049dc2012-06-19 23:12:551142// Let gtest print InstallWarnings.
1143void PrintTo(const Extension::InstallWarning&, ::std::ostream* os);
1144
[email protected]c6d474f82009-12-16 21:11:061145// Handy struct to pass core extension info around.
1146struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:031147 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:061148 const std::string& id,
1149 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:461150 Extension::Location location);
1151 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:061152
[email protected]f3a1c642011-07-12 19:15:031153 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:061154 std::string extension_id;
1155 FilePath extension_path;
1156 Extension::Location extension_location;
1157
1158 private:
1159 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
1160};
1161
[email protected]a9f39a312010-12-23 22:14:271162struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:591163 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:271164
1165 // Was the extension already disabled?
1166 bool already_disabled;
1167
1168 // The extension being unloaded - this should always be non-NULL.
1169 const Extension* extension;
1170
[email protected]814a7bf0f2011-08-13 05:30:591171 UnloadedExtensionInfo(
1172 const Extension* extension,
1173 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:271174};
1175
[email protected]902fd7b2011-07-27 18:42:311176// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
1177struct UpdatedExtensionPermissionsInfo {
1178 enum Reason {
[email protected]f5532472012-02-23 13:00:551179 ADDED, // The permissions were added to the extension.
1180 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:311181 };
1182
1183 Reason reason;
1184
1185 // The extension who's permissions have changed.
1186 const Extension* extension;
1187
1188 // The permissions that have changed. For Reason::ADDED, this would contain
1189 // only the permissions that have added, and for Reason::REMOVED, this would
1190 // only contain the removed permissions.
[email protected]c2e66e12012-06-27 06:27:061191 const PermissionSet* permissions;
[email protected]902fd7b2011-07-27 18:42:311192
1193 UpdatedExtensionPermissionsInfo(
1194 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:061195 const PermissionSet* permissions,
[email protected]902fd7b2011-07-27 18:42:311196 Reason reason);
1197};
1198
[email protected]1c321ee2012-05-21 03:02:341199} // namespace extensions
1200
[email protected]5b1a0e22009-05-26 19:00:581201#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_