blob: 0239b80174dc4c38a5badb49aa0c186d3dfc1c7c [file] [log] [blame]
[email protected]eb75f7b2012-01-04 09:07:281// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7713d632008-12-02 07:52:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5b1a0e22009-05-26 19:00:585#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_
6#define CHROME_COMMON_EXTENSIONS_EXTENSION_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]7713d632008-12-02 07:52:338
[email protected]8629c542012-04-20 03:40:039#include <algorithm>
[email protected]300cc58db2009-08-19 20:45:1410#include <map>
[email protected]facd7a7652009-06-05 23:15:0211#include <set>
[email protected]7713d632008-12-02 07:52:3312#include <string>
[email protected]58f62cf2012-03-09 10:45:1113#include <utility>
[email protected]7713d632008-12-02 07:52:3314#include <vector>
15
[email protected]6014d672008-12-05 00:38:2516#include "base/file_path.h"
[email protected]19118d52010-07-26 22:13:4217#include "base/gtest_prod_util.h"
[email protected]8f270be2011-12-21 21:15:2218#include "base/hash_tables.h"
[email protected]b6b805e92011-04-16 09:24:1419#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1520#include "base/memory/ref_counted.h"
21#include "base/memory/scoped_ptr.h"
[email protected]902fd7b2011-07-27 18:42:3122#include "base/synchronization/lock.h"
[email protected]65907942012-05-22 19:59:4723#include "chrome/common/extensions/command.h"
[email protected]3349b592012-04-26 12:35:2824#include "chrome/common/extensions/extension_action.h"
[email protected]d83a5602010-09-16 00:22:4825#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4826#include "chrome/common/extensions/extension_icon_set.h"
[email protected]0d3e4a22011-06-23 19:02:5227#include "chrome/common/extensions/extension_permission_set.h"
[email protected]42b6f0f82009-09-18 21:07:3928#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4929#include "chrome/common/extensions/url_pattern.h"
[email protected]cced75a2011-05-20 08:31:1230#include "chrome/common/extensions/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5931#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5532#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3833#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5934
[email protected]942690b132010-05-11 06:42:1435class ExtensionResource;
[email protected]b6b805e92011-04-16 09:24:1436class FileBrowserHandler;
[email protected]12802702010-07-09 19:43:0937class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2838class Version;
[email protected]942690b132010-05-11 06:42:1439
[email protected]f3a1c642011-07-12 19:15:0340namespace base {
41class DictionaryValue;
42class ListValue;
43}
44
[email protected]f0cc7242011-12-13 04:26:1745namespace webkit_glue {
46struct WebIntentServiceData;
47}
48
[email protected]1c321ee2012-05-21 03:02:3449FORWARD_DECLARE_TEST(TabStripModelTest, Apps);
50
51namespace extensions {
52
53class Manifest;
54
[email protected]f0755532010-06-22 07:27:2555// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4156class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3357 public:
[email protected]d3cfa482009-10-17 13:54:5758 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1759 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1460 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]b24d8312009-08-27 06:47:4661
[email protected]631cf822009-05-15 07:01:2562 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2363 // NOTE: These values are stored as integers in the preferences and used
64 // in histograms so don't remove or reorder existing items. Just append
65 // to the end.
[email protected]631cf822009-05-15 07:01:2566 enum Location {
67 INVALID,
[email protected]25b34332009-06-05 21:53:1968 INTERNAL, // A crx file from the internal Extensions directory.
69 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
70 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
71 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3472 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3273 COMPONENT, // An integral component of Chrome itself, which
74 // happens to be implemented as an extension. We don't
75 // show these in the management UI.
[email protected]4d2913e32010-11-30 00:28:5576 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via
77 // prefs), installed from an update URL.
78 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via
79 // admin policies), installed from an update URL.
[email protected]04cb7542010-10-25 10:50:0680
81 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1982 };
83
84 enum State {
[email protected]0c6da502009-08-14 22:32:3985 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1986 ENABLED,
[email protected]79c833b52011-04-05 18:31:0187 // An external extension that the user uninstalled. We should not reinstall
88 // such extensions on startup.
89 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:3990 NUM_STATES
[email protected]631cf822009-05-15 07:01:2591 };
[email protected]7713d632008-12-02 07:52:3392
[email protected]44d62b62012-04-11 00:06:0393 // Used to record the reason an extension was disabled.
94 enum DisableReason {
95 DISABLE_UNKNOWN,
96 DISABLE_USER_ACTION,
97 DISABLE_PERMISSIONS_INCREASE,
98 DISABLE_RELOAD,
99 DISABLE_LAST, // Not used.
100 };
101
[email protected]fbcc40302009-06-12 20:45:45102 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:37103 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:45104 DOWNGRADE,
105 REINSTALL,
106 UPGRADE,
107 NEW_INSTALL
108 };
109
[email protected]7fa19f82010-12-21 19:40:08110 // Do not change the order of entries or remove entries in this list
111 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
112 enum Type {
[email protected]9b217652010-10-08 22:04:23113 TYPE_UNKNOWN = 0,
114 TYPE_EXTENSION,
115 TYPE_THEME,
116 TYPE_USER_SCRIPT,
117 TYPE_HOSTED_APP,
[email protected]7d3ed2f2011-11-07 23:33:19118 TYPE_PACKAGED_APP,
119 TYPE_PLATFORM_APP
[email protected]9b217652010-10-08 22:04:23120 };
121
[email protected]3bdba0d2011-08-23 07:17:30122 enum SyncType {
123 SYNC_TYPE_NONE = 0,
124 SYNC_TYPE_EXTENSION,
125 SYNC_TYPE_APP
126 };
127
[email protected]92888082010-10-18 19:24:57128 // An NPAPI plugin included in the extension.
129 struct PluginInfo {
130 FilePath path; // Path to the plugin.
131 bool is_public; // False if only this extension can load this plugin.
132 };
133
[email protected]65378f52011-04-08 02:31:23134 // An NaCl module included in the extension.
135 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42136 GURL url;
[email protected]65378f52011-04-08 02:31:23137 std::string mime_type;
138 };
139
[email protected]b0820372011-06-03 07:05:27140 enum InputComponentType {
[email protected]d45f7512011-06-21 21:18:27141 INPUT_COMPONENT_TYPE_NONE = -1,
142 INPUT_COMPONENT_TYPE_IME,
[email protected]b0820372011-06-03 07:05:27143 INPUT_COMPONENT_TYPE_COUNT
144 };
145
146 struct InputComponentInfo {
147 // Define out of line constructor/destructor to please Clang.
148 InputComponentInfo();
149 ~InputComponentInfo();
150
151 std::string name;
152 InputComponentType type;
153 std::string id;
154 std::string description;
155 std::string language;
156 std::set<std::string> layouts;
157 std::string shortcut_keycode;
158 bool shortcut_alt;
159 bool shortcut_ctrl;
160 bool shortcut_shift;
161 };
162
[email protected]a4a38c12010-12-23 16:43:56163 struct TtsVoice {
[email protected]77a3ecac2011-07-07 05:56:33164 // Define out of line constructor/destructor to please Clang.
165 TtsVoice();
166 ~TtsVoice();
167
[email protected]a4a38c12010-12-23 16:43:56168 std::string voice_name;
[email protected]c63f2b72011-07-07 05:25:00169 std::string lang;
[email protected]a4a38c12010-12-23 16:43:56170 std::string gender;
[email protected]c63f2b72011-07-07 05:25:00171 std::set<std::string> event_types;
[email protected]a4a38c12010-12-23 16:43:56172 };
173
[email protected]a79be1f2012-03-23 22:14:00174 // OAuth2 info included in the extension.
175 struct OAuth2Info {
176 OAuth2Info();
177 ~OAuth2Info();
178
[email protected]b6f38622012-04-25 03:20:19179 ExtensionOAuth2Scopes GetScopesAsSet();
180
[email protected]a79be1f2012-03-23 22:14:00181 std::string client_id;
182 std::vector<std::string> scopes;
183 };
184
[email protected]83048a22011-03-29 00:14:13185 enum InitFromValueFlags {
186 NO_FLAGS = 0,
187
188 // Usually, the id of an extension is generated by the "key" property of
189 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
190 // generated based on the path.
191 REQUIRE_KEY = 1 << 0,
192
[email protected]3f53dfe2011-11-30 01:18:29193 // Requires the extension to have an up-to-date manifest version.
194 // Typically, we'll support multiple manifest versions during a version
195 // transition. This flag signals that we want to require the most modern
196 // manifest version that Chrome understands.
197 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
198
[email protected]3aff9ad2011-04-01 20:26:48199 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
200 // to have file access. If it's not present, then permissions and content
201 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51202 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34203
204 // |FROM_WEBSTORE| indicates that the extension was installed from the
205 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51206 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05207
208 // |FROM_BOOKMARK| indicates the extension was created using a mock App
209 // created from a bookmark.
[email protected]ed3b9b12012-05-31 18:37:51210 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58211
212 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
213 // anywhere in the filesystem, rather than being restricted to the
214 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51215 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03216
217 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
218 // extension should be errors rather than warnings.
219 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]83048a22011-03-29 00:14:13220 };
221
[email protected]66e4eb32010-10-27 20:37:41222 static scoped_refptr<Extension> Create(const FilePath& path,
223 Location location,
[email protected]f3a1c642011-07-12 19:15:03224 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13225 int flags,
[email protected]66e4eb32010-10-27 20:37:41226 std::string* error);
227
[email protected]87c655e2011-07-01 21:42:00228 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26229 // an explicit id. Most consumers should just use the other Create() method.
230 static scoped_refptr<Extension> Create(const FilePath& path,
[email protected]58f62cf2012-03-09 10:45:11231 Location location,
232 const base::DictionaryValue& value,
233 int flags,
234 const std::string& explicit_id,
235 std::string* error);
[email protected]87c655e2011-07-01 21:42:00236
[email protected]145a317b2011-04-12 16:03:46237 // Given two install sources, return the one which should take priority
238 // over the other. If an extension is installed from two sources A and B,
239 // its install source should be set to GetHigherPriorityLocation(A, B).
240 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
241
[email protected]4c4f8192009-10-17 01:03:26242 // Max size (both dimensions) for browser and page actions.
243 static const int kPageActionIconMaxSize;
244 static const int kBrowserActionIconMaxSize;
245
[email protected]8d888c12010-11-30 00:00:25246 // Valid schemes for web extent URLPatterns.
247 static const int kValidWebExtentSchemes;
248
[email protected]f71f7e62010-12-07 03:45:33249 // Valid schemes for host permission URLPatterns.
250 static const int kValidHostPermissionSchemes;
251
[email protected]6014d672008-12-05 00:38:25252 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16253 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25254
[email protected]300cc58db2009-08-19 20:45:14255 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16256 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14257
258 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16259 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14260
[email protected]25b34332009-06-05 21:53:19261#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19262 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19263#endif
264
[email protected]37eeb5a2009-02-26 23:36:17265 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48266 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17267
[email protected]e435d6b72009-07-25 03:15:58268 // The mimetype used for extensions.
269 static const char kMimeType[];
270
[email protected]25b34332009-06-05 21:53:19271 // Checks to see if the extension has a valid ID.
272 static bool IdIsValid(const std::string& id);
273
[email protected]4ead6f72010-10-13 19:54:18274 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27275 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18276 static std::string GenerateIdForPath(const FilePath& file_name);
277
[email protected]e435d6b72009-07-25 03:15:58278 // Returns true if the specified file is an extension.
279 static bool IsExtension(const FilePath& file_name);
280
[email protected]25b34332009-06-05 21:53:19281 // Whether the |location| is external or not.
282 static inline bool IsExternalLocation(Location location) {
283 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32284 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06285 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
286 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
287 }
288
289 // Whether extensions with |location| are auto-updatable or not.
290 static inline bool IsAutoUpdateableLocation(Location location) {
291 // Only internal and external extensions can be autoupdated.
292 return location == Extension::INTERNAL ||
293 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19294 }
295
[email protected]65187152012-06-02 13:14:14296 // Policy-required extensions are silently auto-installed and updated, and
297 // cannot be disabled or modified by the user in any way. The same applies
298 // to internal components.
299 // This method is not generally called directly; instead, it is accessed
300 // through the ManagementPolicy held by the ExtensionSystem.
301 static inline bool IsRequired(Location location) {
302 return location == Extension::EXTERNAL_POLICY_DOWNLOAD ||
303 location == Extension::COMPONENT;
[email protected]95da88c42011-03-31 10:07:33304 }
305
[email protected]cdfca9702011-08-08 16:07:01306 // Unpacked extensions start off with file access since they are a developer
307 // feature.
308 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
309 return location == Extension::LOAD;
310 }
311
[email protected]fc6b0612012-03-29 13:40:06312 // Fills the |info| dictionary with basic information about the extension.
313 // |enabled| is injected for easier testing.
314 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const;
315
[email protected]7fa19f82010-12-21 19:40:08316 // See Type definition above.
317 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23318
[email protected]07c00d992009-03-04 20:27:04319 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59320 // |extension_url| argument should be the url() from an Extension object. The
321 // |relative_path| can be untrusted user input. The returned URL will either
322 // be invalid() or a child of |extension_url|.
323 // NOTE: Static so that it can be used from multiple threads.
324 static GURL GetResourceURL(const GURL& extension_url,
325 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28326 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24327 return GetResourceURL(url(), relative_path);
328 }
[email protected]eab9b452009-01-23 20:48:59329
[email protected]8f270be2011-12-21 21:15:22330 // Returns true if the specified resource is web accessible.
331 bool IsResourceWebAccessible(const std::string& relative_path) const;
332
[email protected]dbb24162012-06-06 01:41:22333 // Returns true if the specified page is sandboxed (served in a unique
334 // origin).
335 bool IsSandboxedPage(const std::string& relative_path) const;
336
337 // Returns the Content Security Policy that the specified resource should be
338 // served with.
339 std::string GetResourceContentSecurityPolicy(const std::string& relative_path)
340 const;
341
[email protected]8f270be2011-12-21 21:15:22342 // Returns true when 'web_accessible_resources' are defined for the extension.
343 bool HasWebAccessibleResources() const;
344
[email protected]99efb7b12009-12-18 02:39:16345 // Returns an extension resource object. |relative_path| should be UTF8
346 // encoded.
[email protected]9adb9692010-10-29 23:14:02347 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16348
349 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02350 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59351
[email protected]a17f9462009-06-09 02:56:41352 // |input| is expected to be the text of an rsa public or private key. It
353 // tolerates the presence or absence of bracking header/footer like this:
354 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
355 // and may contain newlines.
356 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
357
358 // Does a simple base64 encoding of |input| into |output|.
359 static bool ProducePEM(const std::string& input, std::string* output);
360
[email protected]84ac7f32009-10-06 06:17:54361 // Generates an extension ID from arbitrary input. The same input string will
362 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15363 static bool GenerateId(const std::string& input,
364 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45365
[email protected]a17f9462009-06-09 02:56:41366 // Expects base64 encoded |input| and formats into |output| including
367 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50368 static bool FormatPEMForFileOutput(const std::string& input,
369 std::string* output,
370 bool is_public);
[email protected]a17f9462009-06-09 02:56:41371
[email protected]58f62cf2012-03-09 10:45:11372 // Given an extension, icon size, and match type, read a valid icon if present
[email protected]e3c0bc22012-02-24 01:34:15373 // and decode it into result. In the browser process, this will DCHECK if not
374 // called on the file thread. To easily load extension images on the UI
375 // thread, see ImageLoadingTracker.
376 static void DecodeIcon(const Extension* extension,
377 ExtensionIconSet::Icons icon_size,
378 ExtensionIconSet::MatchType match_type,
379 scoped_ptr<SkBitmap>* result);
380
[email protected]c690a9812009-12-17 05:55:32381 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23382 // result. In the browser process, this will DCHECK if not called on the
383 // file thread. To easily load extension images on the UI thread, see
384 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02385 static void DecodeIcon(const Extension* extension,
[email protected]e3c0bc22012-02-24 01:34:15386 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32387 scoped_ptr<SkBitmap>* result);
388
389 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23390 // result. In the browser process, this will DCHECK if not called on the
391 // file thread. To easily load extension images on the UI thread, see
392 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32393 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]e3c0bc22012-02-24 01:34:15394 ExtensionIconSet::Icons icon_size,
[email protected]c690a9812009-12-17 05:55:32395 scoped_ptr<SkBitmap>* result);
396
[email protected]5349ac6d2011-04-05 22:20:17397 // Returns the default extension/app icon (for extensions or apps that don't
398 // have one).
399 static const SkBitmap& GetDefaultIcon(bool is_app);
400
[email protected]a807bbe2010-04-14 10:51:19401 // Returns the base extension url for a given |extension_id|.
402 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
403
[email protected]be7e5cb2010-10-04 12:53:17404 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17405 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21406 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17407
[email protected]902fd7b2011-07-27 18:42:31408 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27409 // from |manifest_|.
410 bool ParsePermissions(const char* key,
[email protected]fc670822011-12-17 09:33:49411 string16* error,
[email protected]902fd7b2011-07-27 18:42:31412 ExtensionAPIPermissionSet* api_permissions,
413 URLPatternSet* host_permissions);
414
[email protected]0d3e4a22011-06-23 19:02:52415 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const;
416 bool HasAPIPermission(const std::string& function_name) const;
[email protected]583d45c12010-08-31 02:48:12417
[email protected]0d3e4a22011-06-23 19:02:52418 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46419
[email protected]902fd7b2011-07-27 18:42:31420 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16421 // Users must approve permissions for unpacked and packed extensions in the
422 // following situations:
423 // - when installing or upgrading packed extensions
424 // - when installing unpacked extensions that have NPAPI plugins
425 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31426 bool CanSilentlyIncreasePermissions() const;
427
[email protected]584b8e3f2010-04-10 00:23:37428 // Whether the extension has access to the given URL.
429 bool HasHostPermission(const GURL& url) const;
430
[email protected]0df165f2010-09-28 16:49:40431 // Whether the extension has effective access to all hosts. This is true if
432 // there is a content script that matches all hosts, if there is a host
433 // permission grants access to all hosts (like <all_urls>) or an api
434 // permission that effectively grants access to all hosts (e.g. proxy,
435 // network, etc.)
436 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46437
[email protected]8d888c12010-11-30 00:00:25438 // Whether the extension effectively has all permissions (for example, by
439 // having an NPAPI plugin).
440 bool HasFullPermissions() const;
441
[email protected]902fd7b2011-07-27 18:42:31442 // Returns the full list of permission messages that this extension
443 // should display at install time.
444 ExtensionPermissionMessages GetPermissionMessages() const;
445
446 // Returns the full list of permission messages that this extension
447 // should display at install time. The messages are returned as strings
448 // for convenience.
449 std::vector<string16> GetPermissionMessageStrings() const;
450
451 // Sets the active |permissions|.
452 void SetActivePermissions(const ExtensionPermissionSet* permissions) const;
453
454 // Gets the extension's active permission set.
455 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
456
[email protected]5df6a5d2011-01-26 07:39:12457 // Whether context menu should be shown for page and browser actions.
458 bool ShowConfigureContextMenus() const;
459
[email protected]37cd64d2010-10-25 18:17:58460 // Returns the Homepage URL for this extension. If homepage_url was not
461 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23462 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58463 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23464
[email protected]facd7a7652009-06-05 23:15:02465 // Returns a list of paths (relative to the extension dir) for images that
466 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02467 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02468
[email protected]807871f2010-09-16 01:04:48469 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02470 ExtensionResource GetIconResource(
471 int size, ExtensionIconSet::MatchType match_type) const;
472 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08473
[email protected]867a73e12010-03-19 20:45:46474 // Gets the fully resolved absolute launch URL.
475 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21476
[email protected]6f229e82010-11-02 17:47:26477 // Image cache related methods. These are only valid on the UI thread and
478 // not maintained by this class. See ImageLoadingTracker for usage. The
479 // |original_size| parameter should be the size of the image at |source|
480 // before any scaling may have been done to produce the pixels in |image|.
481 void SetCachedImage(const ExtensionResource& source,
482 const SkBitmap& image,
483 const gfx::Size& original_size) const;
484 bool HasCachedImage(const ExtensionResource& source,
485 const gfx::Size& max_size) const;
486 SkBitmap GetCachedImage(const ExtensionResource& source,
487 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21488
489 // Returns true if this extension can execute script on a page. If a
490 // UserScript object is passed, permission to run that specific script is
491 // checked (using its matches list). Otherwise, permission to execute script
492 // programmatically is checked (using the extension's host permission).
493 //
494 // This method is also aware of certain special pages that extensions are
495 // usually not allowed to run script on.
496 bool CanExecuteScriptOnPage(const GURL& page_url,
[email protected]fc5e65d6b2012-06-13 00:22:57497 int tab_id,
[email protected]3aff9ad2011-04-01 20:26:48498 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21499 std::string* error) const;
500
[email protected]6f229e82010-11-02 17:47:26501 // Returns true if this extension is a COMPONENT extension, or if it is
502 // on the whitelist of extensions that can script all pages.
503 bool CanExecuteScriptEverywhere() const;
504
[email protected]5efbfe012011-02-22 23:07:18505 // Returns true if this extension is allowed to obtain the contents of a
506 // page as an image. Since a page may contain sensitive information, this
507 // is restricted to the extension's host permissions as well as the
508 // extension page itself.
[email protected]fc5e65d6b2012-06-13 00:22:57509 bool CanCaptureVisiblePage(const GURL& page_url,
510 int tab_id,
511 std::string* error) const;
[email protected]5efbfe012011-02-22 23:07:18512
[email protected]a65882c2010-11-12 15:15:09513 // Returns true if this extension updates itself using the extension
514 // gallery.
515 bool UpdatesFromGallery() const;
516
[email protected]cca147172011-02-17 01:29:29517 // Returns true if this extension or app includes areas within |origin|.
518 bool OverlapsWithOrigin(const GURL& origin) const;
519
[email protected]3bdba0d2011-08-23 07:17:30520 // Returns the sync bucket to use for this extension.
521 SyncType GetSyncType() const;
522
[email protected]b873cd92012-02-09 21:51:48523 // Returns true if the extension should be synced.
524 bool IsSyncable() const;
525
526 // Returns true if the extension should be displayed in the launcher.
527 bool ShouldDisplayInLauncher() const;
528
[email protected]e0b3de72012-05-01 01:21:34529 // Returns true if the extension should be displayed in the extension
530 // settings page (i.e. chrome://extensions).
531 bool ShouldDisplayInExtensionSettings() const;
532
[email protected]4f886012012-05-19 03:51:10533 // Returns true if the extension has a content script declared at |url|.
534 bool HasContentScriptAtURL(const GURL& url) const;
535
[email protected]0f156a62012-05-28 16:36:36536 // Returns an ExtensionAction representing the script badge that should be
537 // shown for this extension in the location bar.
538 ExtensionAction* GetScriptBadge() const;
539
[email protected]fc5e65d6b2012-06-13 00:22:57540 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
541 // aren't any.
542 //
543 // This is a weak pointer. Callers should create a copy before mutating any
544 // tab specific permissions.
545 const URLPatternSet* GetTabSpecificHostPermissions(int tab_id) const;
546
547 // Sets the tab-specific host permissions of |tab_id| to |permissions|.
548 void SetTabSpecificHostPermissions(int tab_id,
549 const URLPatternSet& permissions) const;
550
551 // Clears the tab-specific host permissions of |tab_id|.
552 void ClearTabSpecificHostPermissions(int tab_id) const;
553
[email protected]6f229e82010-11-02 17:47:26554 // Accessors:
555
556 const FilePath& path() const { return path_; }
557 const GURL& url() const { return extension_url_; }
[email protected]d41e2152012-02-24 04:20:27558 Location location() const;
559 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26560 const Version* version() const { return version_.get(); }
561 const std::string VersionString() const;
562 const std::string& name() const { return name_; }
[email protected]701d1e82012-05-14 05:34:19563 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06564 // Base64-encoded version of the key used to sign this extension.
565 // In pseudocode, returns
566 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
567 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26568 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31569 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26570 bool converted_from_user_script() const {
571 return converted_from_user_script_;
572 }
573 const UserScriptList& content_scripts() const { return content_scripts_; }
574 ExtensionAction* page_action() const { return page_action_.get(); }
575 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]3e819002012-04-30 07:57:55576 ExtensionAction::Type declared_action_type() const {
577 return declared_action_type_;
[email protected]3349b592012-04-26 12:35:28578 }
[email protected]b6b805e92011-04-16 09:24:14579 const FileBrowserHandlerList* file_browser_handlers() const {
580 return file_browser_handlers_.get();
581 }
[email protected]6f229e82010-11-02 17:47:26582 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23583 const std::vector<NaClModuleInfo>& nacl_modules() const {
584 return nacl_modules_;
585 }
[email protected]b0820372011-06-03 07:05:27586 const std::vector<InputComponentInfo>& input_components() const {
587 return input_components_;
588 }
[email protected]7c519ab2012-05-04 10:02:51589 // The browser action command that the extension wants to use, which is not
590 // necessarily the one it can use, as it might be inactive (see also
591 // GetActiveBrowserActionCommand in ExtensionKeybindingRegistry).
[email protected]3fc5f6a2012-05-04 14:23:59592 const extensions::Command* browser_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30593 return browser_action_command_.get();
594 }
[email protected]7c519ab2012-05-04 10:02:51595 // The page action command that the extension wants to use, which is not
596 // necessarily the one it can use, as it might be inactive (see also
597 // GetActivePageActionCommand in ExtensionKeybindingRegistry).
[email protected]3fc5f6a2012-05-04 14:23:59598 const extensions::Command* page_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30599 return page_action_command_.get();
600 }
[email protected]7c519ab2012-05-04 10:02:51601 // The map (of command names to commands) that the extension wants to use,
[email protected]422656932012-05-03 09:31:51602 // which is not necessarily the one it can use, as they might be inactive
603 // (see also GetActiveNamedCommands in ExtensionKeybindingRegistry).
[email protected]3fc5f6a2012-05-04 14:23:59604 const extensions::CommandMap& named_commands() const {
[email protected]9c8b54d2012-04-02 10:17:30605 return named_commands_;
[email protected]f5532472012-02-23 13:00:55606 }
[email protected]a03d4448f2012-01-10 23:25:28607 bool has_background_page() const {
608 return background_url_.is_valid() || !background_scripts_.empty();
609 }
[email protected]7b54ca02012-03-02 18:06:53610 bool allow_background_js_access() const {
611 return allow_background_js_access_;
612 }
[email protected]a03d4448f2012-01-10 23:25:28613 const std::vector<std::string>& background_scripts() const {
614 return background_scripts_;
615 }
[email protected]d2aa06b2012-03-21 20:57:26616 bool has_persistent_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00617 return has_background_page() && background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26618 }
619 bool has_lazy_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00620 return has_background_page() && !background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26621 }
[email protected]6f229e82010-11-02 17:47:26622 const GURL& options_url() const { return options_url_; }
623 const GURL& devtools_url() const { return devtools_url_; }
[email protected]902fd7b2011-07-27 18:42:31624 const ExtensionPermissionSet* optional_permission_set() const {
625 return optional_permission_set_.get();
626 }
627 const ExtensionPermissionSet* required_permission_set() const {
628 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26629 }
[email protected]ab55c2b2012-06-01 23:55:03630 // Appends |new_warnings| to install_warnings().
631 void AddInstallWarnings(const std::vector<std::string>& new_warnings);
[email protected]8629c542012-04-20 03:40:03632 const std::vector<std::string>& install_warnings() const {
633 return install_warnings_;
634 }
[email protected]6f229e82010-11-02 17:47:26635 const GURL& update_url() const { return update_url_; }
636 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32637 const extensions::Manifest* manifest() const {
[email protected]d41e2152012-02-24 04:20:27638 return manifest_;
[email protected]6f229e82010-11-02 17:47:26639 }
640 const std::string default_locale() const { return default_locale_; }
641 const URLOverrideMap& GetChromeURLOverrides() const {
642 return chrome_url_overrides_;
643 }
644 const std::string omnibox_keyword() const { return omnibox_keyword_; }
645 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55646 bool offline_enabled() const { return offline_enabled_; }
[email protected]a4a38c12010-12-23 16:43:56647 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]a79be1f2012-03-23 22:14:00648 const OAuth2Info& oauth2_info() const { return oauth2_info_; }
[email protected]56624422011-11-01 22:11:27649 const std::vector<webkit_glue::WebIntentServiceData>&
650 intents_services() const {
651 return intents_services_;
652 }
[email protected]6f229e82010-11-02 17:47:26653
[email protected]3aff9ad2011-04-01 20:26:48654 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23655 int creation_flags() const { return creation_flags_; }
656 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05657 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]3aff9ad2011-04-01 20:26:48658
[email protected]6f229e82010-11-02 17:47:26659 // App-related.
[email protected]953620b2011-12-04 00:55:32660 bool is_app() const {
661 return is_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39662 }
[email protected]d41e2152012-02-24 04:20:27663 bool is_platform_app() const;
664 bool is_hosted_app() const;
665 bool is_packaged_app() const;
[email protected]605fb8102012-05-04 01:36:55666 bool is_storage_isolated() const { return is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12667 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26668 const std::string& launch_local_path() const { return launch_local_path_; }
669 const std::string& launch_web_url() const { return launch_web_url_; }
670 extension_misc::LaunchContainer launch_container() const {
671 return launch_container_;
672 }
[email protected]dc37b002012-04-23 23:02:26673 int launch_width() const { return launch_width_; }
674 int launch_height() const { return launch_height_; }
[email protected]6f229e82010-11-02 17:47:26675
676 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27677 bool is_theme() const;
[email protected]f3a1c642011-07-12 19:15:03678 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
679 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
680 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
681 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26682 return theme_display_properties_.get();
683 }
684
[email protected]a03d4448f2012-01-10 23:25:28685 GURL GetBackgroundURL() const;
686
[email protected]4a8d3272009-03-10 19:15:08687 private:
[email protected]66e4eb32010-10-27 20:37:41688 friend class base::RefCountedThreadSafe<Extension>;
689
[email protected]d7e9a862010-11-03 21:57:49690 // We keep a cache of images loaded from extension resources based on their
691 // path and a string representation of a size that may have been used to
692 // scale it (or the empty string if the image is at its original size).
693 typedef std::pair<FilePath, std::string> ImageCacheKey;
694 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
695
[email protected]902fd7b2011-07-27 18:42:31696 class RuntimeData {
697 public:
698 RuntimeData();
699 explicit RuntimeData(const ExtensionPermissionSet* active);
700 ~RuntimeData();
701
702 void SetActivePermissions(const ExtensionPermissionSet* active);
703 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
704
[email protected]fc5e65d6b2012-06-13 00:22:57705 const URLPatternSet* GetTabSpecificHostPermissions(int tab_id) const;
706 void SetTabSpecificHostPermissions(int tab_id,
707 const URLPatternSet& permissions);
708 void ClearTabSpecificHostPermissions(int tab_id);
709
[email protected]902fd7b2011-07-27 18:42:31710 private:
711 friend class base::RefCountedThreadSafe<RuntimeData>;
[email protected]fc5e65d6b2012-06-13 00:22:57712
[email protected]902fd7b2011-07-27 18:42:31713 scoped_refptr<const ExtensionPermissionSet> active_permissions_;
[email protected]fc5e65d6b2012-06-13 00:22:57714
715 typedef std::map<int, linked_ptr<const URLPatternSet> >
716 TabHostPermissionsMap;
717 TabHostPermissionsMap tab_specific_host_permissions_;
[email protected]902fd7b2011-07-27 18:42:31718 };
719
[email protected]d41e2152012-02-24 04:20:27720 // Chooses the extension ID for an extension based on a variety of criteria.
721 // The chosen ID will be set in |manifest|.
722 static bool InitExtensionID(extensions::Manifest* manifest,
723 const FilePath& path,
724 const std::string& explicit_id,
725 int creation_flags,
726 string16* error);
727
[email protected]4ead6f72010-10-13 19:54:18728 // Normalize the path for use by the extension. On Windows, this will make
729 // sure the drive letter is uppercase.
730 static FilePath MaybeNormalizePath(const FilePath& path);
731
[email protected]87c655e2011-07-01 21:42:00732 // Returns true if this extension id is from a trusted provider.
733 static bool IsTrustedId(const std::string& id);
734
[email protected]d41e2152012-02-24 04:20:27735 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
[email protected]66e4eb32010-10-27 20:37:41736 ~Extension();
737
738 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27739 // TODO(aa): Rename to just Init()? There's no Value here anymore.
740 // TODO(aa): It is really weird the way this class essentially contains a copy
741 // of the underlying DictionaryValue in its members. We should decide to
742 // either wrap the DictionaryValue and go with that only, or we should parse
743 // into strong types and discard the value. But doing both is bad.
744 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41745
[email protected]58f62cf2012-03-09 10:45:11746 // The following are helpers for InitFromValue to load various features of the
747 // extension from the manifest.
748
749 bool CheckMinimumChromeVersion(string16* error);
[email protected]605fb8102012-05-04 01:36:55750 bool LoadAppIsolation(const ExtensionAPIPermissionSet& api_permissions,
751 string16* error);
[email protected]58f62cf2012-03-09 10:45:11752
753 bool LoadRequiredFeatures(string16* error);
754 bool LoadName(string16* error);
755 bool LoadVersion(string16* error);
756
757 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27758 bool LoadExtent(const char* key,
759 URLPatternSet* extent,
760 const char* list_error,
761 const char* value_error,
762 string16* error);
763 bool LoadLaunchContainer(string16* error);
764 bool LoadLaunchURL(string16* error);
[email protected]10253da2012-03-09 04:06:42765
[email protected]58f62cf2012-03-09 10:45:11766 bool LoadSharedFeatures(const ExtensionAPIPermissionSet& api_permissions,
767 string16* error);
768 bool LoadDescription(string16* error);
769 bool LoadManifestVersion(string16* error);
770 bool LoadHomepageURL(string16* error);
771 bool LoadUpdateURL(string16* error);
772 bool LoadIcons(string16* error);
773 bool LoadCommands(string16* error);
774 bool LoadPlugins(string16* error);
775 bool LoadNaClModules(string16* error);
776 bool LoadWebAccessibleResources(string16* error);
[email protected]dbb24162012-06-06 01:41:22777 bool LoadSandboxedPages(string16* error);
[email protected]58f62cf2012-03-09 10:45:11778 bool CheckRequirements(string16* error);
779 bool LoadDefaultLocale(string16* error);
780 bool LoadOfflineEnabled(string16* error);
781 bool LoadOptionsPage(string16* error);
[email protected]d41e2152012-02-24 04:20:27782 bool LoadBackgroundScripts(string16* error);
[email protected]756038532012-06-08 05:45:03783 bool LoadBackgroundScripts(const std::string& key, string16* error);
[email protected]d41e2152012-02-24 04:20:27784 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions,
785 string16* error);
[email protected]756038532012-06-08 05:45:03786 bool LoadBackgroundPage(const std::string& key,
787 const ExtensionAPIPermissionSet& api_permissions,
788 string16* error);
[email protected]dd62fa802012-04-25 18:37:00789 bool LoadBackgroundPersistent(
[email protected]d41e2152012-02-24 04:20:27790 const ExtensionAPIPermissionSet& api_permissions,
791 string16* error);
[email protected]58f62cf2012-03-09 10:45:11792 bool LoadBackgroundAllowJSAccess(
[email protected]7b54ca02012-03-02 18:06:53793 const ExtensionAPIPermissionSet& api_permissions,
794 string16* error);
[email protected]58f62cf2012-03-09 10:45:11795 // Parses a single action in the manifest.
796 bool LoadWebIntentAction(const std::string& action_name,
797 const base::DictionaryValue& intent_service,
798 string16* error);
799 bool LoadWebIntentServices(string16* error);
800 bool LoadExtensionFeatures(const ExtensionAPIPermissionSet& api_permissions,
801 string16* error);
802 bool LoadDevToolsPage(string16* error);
803 bool LoadInputComponents(const ExtensionAPIPermissionSet& api_permissions,
804 string16* error);
805 bool LoadContentScripts(string16* error);
806 bool LoadPageAction(string16* error);
807 bool LoadBrowserAction(string16* error);
808 bool LoadFileBrowserHandlers(string16* error);
809 // Helper method to load a FileBrowserHandlerList from the manifest.
810 FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
811 const base::ListValue* extension_actions, string16* error);
812 // Helper method to load an FileBrowserHandler from manifest.
813 FileBrowserHandler* LoadFileBrowserHandler(
814 const base::DictionaryValue* file_browser_handlers, string16* error);
815 bool LoadChromeURLOverrides(string16* error);
816 bool LoadOmnibox(string16* error);
817 bool LoadTextToSpeechVoices(string16* error);
818 bool LoadIncognitoMode(string16* error);
819 bool LoadContentSecurityPolicy(string16* error);
820
821 bool LoadThemeFeatures(string16* error);
822 bool LoadThemeImages(const base::DictionaryValue* theme_value,
823 string16* error);
824 bool LoadThemeColors(const base::DictionaryValue* theme_value,
825 string16* error);
826 bool LoadThemeTints(const base::DictionaryValue* theme_value,
827 string16* error);
828 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value,
829 string16* error);
830
831 // Helper function for implementing HasCachedImage/GetCachedImage. A return
832 // value of NULL means there is no matching image cached (we allow caching an
833 // empty SkBitmap).
834 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
835 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18836
[email protected]3cfbd0e2009-03-18 21:26:24837 // Helper method that loads a UserScript object from a
838 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03839 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24840 int definition_index,
[email protected]fc670822011-12-17 09:33:49841 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24842 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34843
[email protected]6657afa62009-11-04 02:15:20844 // Helper method that loads either the include_globs or exclude_globs list
845 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03846 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20847 int content_script_index,
[email protected]e2194742010-08-12 05:54:34848 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49849 string16* error,
[email protected]11f4857282009-11-13 19:56:17850 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20851 UserScript *instance);
852
[email protected]5d246db22009-10-27 06:17:57853 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08854 // browser_action entries in the manifest.
[email protected]3349b592012-04-26 12:35:28855 scoped_ptr<ExtensionAction> LoadExtensionActionHelper(
[email protected]fc670822011-12-17 09:33:49856 const base::DictionaryValue* extension_action, string16* error);
[email protected]92c6f9b92009-10-24 04:35:08857
[email protected]a79be1f2012-03-23 22:14:00858 // Helper method that loads the OAuth2 info from the 'oauth2' manifest key.
859 bool LoadOAuth2Info(string16* error);
860
[email protected]2f6698b2010-10-14 00:58:21861 // Returns true if the extension has more than one "UI surface". For example,
862 // an extension that has a browser action and a page action.
863 bool HasMultipleUISurfaces() const;
864
[email protected]be9d9c82011-07-13 04:17:31865 // Updates the launch URL and extents for the extension using the given
866 // |override_url|.
867 void OverrideLaunchUrl(const GURL& override_url);
868
[email protected]ae655e4e2012-03-16 21:47:55869 // Custom checks for the experimental permission that can't be expressed in
870 // _permission_features.json.
[email protected]5eddc3e2011-10-26 04:33:31871 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31872
873 // Checks whether the host |pattern| is allowed for this extension, given API
874 // permissions |permissions|.
875 bool CanSpecifyHostPermission(const URLPattern& pattern,
876 const ExtensionAPIPermissionSet& permissions) const;
877
[email protected]e92169e2012-05-04 22:49:32878 // Check that platform app features are valid. Called after InitFromValue.
879 bool CheckPlatformAppFeatures(std::string* utf8_error);
880
[email protected]f1bab9c92012-05-11 21:15:10881 // Check that features don't conflict. Called after InitFromValue.
882 bool CheckConflictingFeatures(std::string* utf8_error);
883
[email protected]d7e9a862010-11-03 21:57:49884 // Cached images for this extension. This should only be touched on the UI
885 // thread.
886 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31887
[email protected]6f229e82010-11-02 17:47:26888 // The extension's human-readable name. Name is used for display purpose. It
889 // might be wrapped with unicode bidi control characters so that it is
890 // displayed correctly in RTL context.
891 // NOTE: Name is UTF-8 and may contain non-ascii characters.
892 std::string name_;
893
[email protected]701d1e82012-05-14 05:34:19894 // A non-localized version of the extension's name. This is useful for
895 // debug output.
896 std::string non_localized_name_;
897
[email protected]a47c8a22011-11-17 18:40:31898 // The version of this extension's manifest. We increase the manifest
899 // version when making breaking changes to the extension system.
900 // Version 1 was the first manifest version (implied by a lack of a
901 // manifest_version attribute in the extension's manifest). We initialize
902 // this member variable to 0 to distinguish the "uninitialized" case from
903 // the case when we know the manifest version actually is 1.
904 int manifest_version_;
905
[email protected]d41e2152012-02-24 04:20:27906 // The absolute path to the directory the extension is stored in.
907 FilePath path_;
908
[email protected]6f229e82010-11-02 17:47:26909 // Default locale for fall back. Can be empty if extension is not localized.
910 std::string default_locale_;
911
912 // If true, a separate process will be used for the extension in incognito
913 // mode.
914 bool incognito_split_mode_;
915
[email protected]1abdf4f2011-08-16 21:11:55916 // Whether the extension or app should be enabled when offline.
917 bool offline_enabled_;
918
[email protected]6f229e82010-11-02 17:47:26919 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12920 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26921
[email protected]902fd7b2011-07-27 18:42:31922 // The extension runtime data.
923 mutable base::Lock runtime_data_lock_;
924 mutable RuntimeData runtime_data_;
925
926 // The set of permissions the extension can request at runtime.
927 scoped_refptr<const ExtensionPermissionSet> optional_permission_set_;
928
929 // The extension's required / default set of permissions.
930 scoped_refptr<const ExtensionPermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26931
[email protected]8629c542012-04-20 03:40:03932 // Any warnings that occurred when trying to create/parse the extension.
933 std::vector<std::string> install_warnings_;
934
[email protected]6f229e82010-11-02 17:47:26935 // The icons for the extension.
936 ExtensionIconSet icons_;
937
938 // The base extension url for the extension.
939 GURL extension_url_;
940
[email protected]6f229e82010-11-02 17:47:26941 // The extension's version.
942 scoped_ptr<Version> version_;
943
944 // An optional longer description of the extension.
945 std::string description_;
946
947 // True if the extension was generated from a user script. (We show slightly
948 // different UI if so).
949 bool converted_from_user_script_;
950
951 // Paths to the content scripts the extension contains.
952 UserScriptList content_scripts_;
953
954 // The extension's page action, if any.
955 scoped_ptr<ExtensionAction> page_action_;
956
957 // The extension's browser action, if any.
958 scoped_ptr<ExtensionAction> browser_action_;
959
[email protected]3e819002012-04-30 07:57:55960 // Indicates the type of action (browser or page) that the extension declared
961 // in its manifest. This doesn't imply any value for page_action or
962 // browser_action, since page actions may be turned into browser actions and
963 // browser actions may be generated without any action declared.
964 ExtensionAction::Type declared_action_type_;
[email protected]3349b592012-04-26 12:35:28965
[email protected]0f156a62012-05-28 16:36:36966 // The extension's script badge. Lazily populated (and subsequently updated)
967 // as required by GetScriptBadge.
968 mutable scoped_ptr<ExtensionAction> script_badge_;
969
[email protected]b6b805e92011-04-16 09:24:14970 // The extension's file browser actions, if any.
971 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
972
[email protected]6f229e82010-11-02 17:47:26973 // Optional list of NPAPI plugins and associated properties.
974 std::vector<PluginInfo> plugins_;
975
[email protected]65378f52011-04-08 02:31:23976 // Optional list of NaCl modules and associated properties.
977 std::vector<NaClModuleInfo> nacl_modules_;
978
[email protected]b0820372011-06-03 07:05:27979 // Optional list of input components and associated properties.
980 std::vector<InputComponentInfo> input_components_;
981
[email protected]f5532472012-02-23 13:00:55982 // Optional list of commands (keyboard shortcuts).
[email protected]3fc5f6a2012-05-04 14:23:59983 scoped_ptr<extensions::Command> browser_action_command_;
984 scoped_ptr<extensions::Command> page_action_command_;
985 extensions::CommandMap named_commands_;
[email protected]f5532472012-02-23 13:00:55986
[email protected]8f270be2011-12-21 21:15:22987 // Optional list of web accessible extension resources.
988 base::hash_set<std::string> web_accessible_resources_;
989
[email protected]dbb24162012-06-06 01:41:22990 // Optional list of extension pages that are sandboxed (served from a unique
991 // origin with a different Content Security Policy).
992 base::hash_set<std::string> sandboxed_pages_;
993
994 // Content Security Policy that should be used to enforce the sandbox used
995 // by sandboxed pages (guaranteed to have the "sandbox" directive without the
996 // "allow-same-origin" token).
997 std::string sandboxed_pages_content_security_policy_;
998
[email protected]6f229e82010-11-02 17:47:26999 // Optional URL to a master page of which a single instance should be always
1000 // loaded in the background.
1001 GURL background_url_;
1002
[email protected]a03d4448f2012-01-10 23:25:281003 // Optional list of scripts to use to generate a background page. If this is
1004 // present, background_url_ will be empty and generated by GetBackgroundURL().
1005 std::vector<std::string> background_scripts_;
1006
[email protected]dd62fa802012-04-25 18:37:001007 // True if the background page should stay loaded forever; false if it should
1008 // load on-demand (when it needs to handle an event). Defaults to true.
1009 bool background_page_is_persistent_;
[email protected]9e6720a2012-01-24 02:30:561010
[email protected]7b54ca02012-03-02 18:06:531011 // True if the background page can be scripted by pages of the app or
1012 // extension, in which case all such pages must run in the same process.
1013 // False if such pages are not permitted to script the background page,
1014 // allowing them to run in different processes.
1015 bool allow_background_js_access_;
1016
[email protected]6f229e82010-11-02 17:47:261017 // Optional URL to a page for setting options/preferences.
1018 GURL options_url_;
1019
1020 // Optional URL to a devtools extension page.
1021 GURL devtools_url_;
1022
[email protected]6f229e82010-11-02 17:47:261023 // The public key used to sign the contents of the crx package.
1024 std::string public_key_;
1025
1026 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:031027 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:261028
1029 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:031030 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:261031
1032 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:031033 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:261034
1035 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:031036 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:261037
[email protected]6f229e82010-11-02 17:47:261038 // The homepage for this extension. Useful if it is not hosted by Google and
1039 // therefore does not have a Gallery URL.
1040 GURL homepage_url_;
1041
1042 // URL for fetching an update manifest
1043 GURL update_url_;
1044
[email protected]58f62cf2012-03-09 10:45:111045 // The manifest from which this extension was created.
[email protected]d41e2152012-02-24 04:20:271046 //
1047 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would
1048 // require manifest.h, which would in turn create a circulate dependency
1049 // between extension.h and manifest.h.
1050 //
1051 // TODO(aa): Pull Extension::Type and Extension::Location out into their own
1052 // files so that manifest.h can rely on them and not get all of extension.h
1053 // too, and then change this back to a scoped_ptr.
1054 extensions::Manifest* manifest_;
[email protected]6f229e82010-11-02 17:47:261055
1056 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
1057 // which override the handling of those URLs. (see ExtensionOverrideUI).
1058 URLOverrideMap chrome_url_overrides_;
1059
[email protected]d9696672011-03-15 22:45:091060 // Whether this extension requests isolated storage.
1061 bool is_storage_isolated_;
1062
[email protected]6f229e82010-11-02 17:47:261063 // The local path inside the extension to use with the launcher.
1064 std::string launch_local_path_;
1065
1066 // A web url to use with the launcher. Note that this might be relative or
1067 // absolute. If relative, it is relative to web_origin.
1068 std::string launch_web_url_;
1069
[email protected]4e595682011-02-09 17:07:021070 // The window type that an app's manifest specifies to launch into.
1071 // This is not always the window type an app will open into, because
1072 // users can override the way each app launches. See
1073 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
1074 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:261075 extension_misc::LaunchContainer launch_container_;
1076
1077 // The default size of the container when launching. Only respected for
1078 // containers like panels and windows.
1079 int launch_width_;
1080 int launch_height_;
1081
1082 // The Omnibox keyword for this extension, or empty if there is none.
1083 std::string omnibox_keyword_;
1084
[email protected]a4a38c12010-12-23 16:43:561085 // List of text-to-speech voices that this extension provides, if any.
1086 std::vector<TtsVoice> tts_voices_;
1087
[email protected]a79be1f2012-03-23 22:14:001088 // The OAuth2 client id and scopes, if specified by the extension.
1089 OAuth2Info oauth2_info_;
1090
[email protected]56624422011-11-01 22:11:271091 // List of intent services that this extension provides, if any.
1092 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
[email protected]be5f007862011-09-23 00:35:131093
[email protected]3aff9ad2011-04-01 20:26:481094 // Whether the extension has host permissions or user script patterns that
1095 // imply access to file:/// scheme URLs (the user may not have actually
1096 // granted it that access).
1097 bool wants_file_access_;
1098
[email protected]2af352b2011-07-22 08:21:231099 // The flags that were passed to InitFromValue.
1100 int creation_flags_;
[email protected]620db1762011-07-15 21:57:341101
[email protected]7f7b9d932011-04-20 16:13:261102 // The Content-Security-Policy for this extension. Extensions can use
1103 // Content-Security-Policies to mitigate cross-site scripting and other
1104 // vulnerabilities.
1105 std::string content_security_policy_;
1106
[email protected]19118d52010-07-26 22:13:421107 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
[email protected]1c321ee2012-05-21 03:02:341108 FRIEND_TEST_ALL_PREFIXES(::TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:581109
[email protected]894bb502009-05-21 22:39:571110 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:331111};
1112
[email protected]9adb9692010-10-29 23:14:021113typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:181114typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:561115
[email protected]c6d474f82009-12-16 21:11:061116// Handy struct to pass core extension info around.
1117struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:031118 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:061119 const std::string& id,
1120 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:461121 Extension::Location location);
1122 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:061123
[email protected]f3a1c642011-07-12 19:15:031124 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:061125 std::string extension_id;
1126 FilePath extension_path;
1127 Extension::Location extension_location;
1128
1129 private:
1130 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
1131};
1132
[email protected]a9f39a312010-12-23 22:14:271133struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:591134 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:271135
1136 // Was the extension already disabled?
1137 bool already_disabled;
1138
1139 // The extension being unloaded - this should always be non-NULL.
1140 const Extension* extension;
1141
[email protected]814a7bf0f2011-08-13 05:30:591142 UnloadedExtensionInfo(
1143 const Extension* extension,
1144 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:271145};
1146
[email protected]902fd7b2011-07-27 18:42:311147// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
1148struct UpdatedExtensionPermissionsInfo {
1149 enum Reason {
[email protected]f5532472012-02-23 13:00:551150 ADDED, // The permissions were added to the extension.
1151 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:311152 };
1153
1154 Reason reason;
1155
1156 // The extension who's permissions have changed.
1157 const Extension* extension;
1158
1159 // The permissions that have changed. For Reason::ADDED, this would contain
1160 // only the permissions that have added, and for Reason::REMOVED, this would
1161 // only contain the removed permissions.
1162 const ExtensionPermissionSet* permissions;
1163
1164 UpdatedExtensionPermissionsInfo(
1165 const Extension* extension,
1166 const ExtensionPermissionSet* permissions,
1167 Reason reason);
1168};
1169
[email protected]1c321ee2012-05-21 03:02:341170} // namespace extensions
1171
[email protected]5b1a0e22009-05-26 19:00:581172#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_