blob: 046532534a871b94f351a0bd6faf70a26824f481 [file] [log] [blame]
[email protected]7eeab9ec2013-01-15 04:08:331// Copyright (c) 2013 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]7eeab9ec2013-01-15 04:08:3323#include "base/threading/thread_checker.h"
[email protected]d83a5602010-09-16 00:22:4824#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4825#include "chrome/common/extensions/extension_icon_set.h"
[email protected]1d5e58b2013-01-31 08:41:4026#include "chrome/common/extensions/manifest.h"
[email protected]bebe1d02012-08-02 20:17:0927#include "chrome/common/extensions/permissions/api_permission.h"
[email protected]1d8b79a2012-08-16 20:22:5428#include "chrome/common/extensions/permissions/api_permission_set.h"
[email protected]bebe1d02012-08-02 20:17:0929#include "chrome/common/extensions/permissions/permission_message.h"
[email protected]885c0e92012-11-13 20:27:4230#include "chrome/common/extensions/user_script.h"
[email protected]1d5e58b2013-01-31 08:41:4031#include "extensions/common/install_warning.h"
[email protected]885c0e92012-11-13 20:27:4232#include "extensions/common/url_pattern.h"
[email protected]e9f541a2012-11-19 21:52:3133#include "extensions/common/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5934#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5535#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3836#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5937
[email protected]0f34d9082012-10-08 19:16:4438class ExtensionAction;
[email protected]942690b132010-05-11 06:42:1439class ExtensionResource;
[email protected]12802702010-07-09 19:43:0940class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2841class Version;
[email protected]942690b132010-05-11 06:42:1442
[email protected]f3a1c642011-07-12 19:15:0343namespace base {
44class DictionaryValue;
45class ListValue;
46}
47
[email protected]0f34d9082012-10-08 19:16:4448namespace gfx {
49class ImageSkia;
50}
51
[email protected]1c321ee2012-05-21 03:02:3452FORWARD_DECLARE_TEST(TabStripModelTest, Apps);
53
54namespace extensions {
[email protected]972b02f2013-01-28 20:38:1455struct ActionInfo;
[email protected]bebe1d02012-08-02 20:17:0956class PermissionSet;
[email protected]1c321ee2012-05-21 03:02:3457
[email protected]d4a37f1c2012-07-09 21:36:1358typedef std::set<std::string> OAuth2Scopes;
59
[email protected]f0755532010-06-22 07:27:2560// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4161class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3362 public:
[email protected]d356c982012-12-12 19:32:5563 struct ManifestData;
[email protected]1e0f45a2012-06-13 00:31:0664
[email protected]10fb1992010-10-08 09:00:1765 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]d356c982012-12-12 19:32:5566 typedef std::map<const std::string, linked_ptr<ManifestData> >
67 ManifestDataMap;
[email protected]b24d8312009-08-27 06:47:4668
[email protected]25b34332009-06-05 21:53:1969 enum State {
[email protected]0c6da502009-08-14 22:32:3970 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1971 ENABLED,
[email protected]79c833b52011-04-05 18:31:0172 // An external extension that the user uninstalled. We should not reinstall
73 // such extensions on startup.
74 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]8c484b742012-11-29 06:05:3675 // Special state for component extensions, since they are always loaded by
76 // the component loader, and should never be auto-installed on startup.
77 ENABLED_COMPONENT,
[email protected]0c6da502009-08-14 22:32:3978 NUM_STATES
[email protected]631cf822009-05-15 07:01:2579 };
[email protected]7713d632008-12-02 07:52:3380
[email protected]44d62b62012-04-11 00:06:0381 // Used to record the reason an extension was disabled.
[email protected]eb5e4f92012-08-15 23:33:2882 enum DeprecatedDisableReason {
83 DEPRECATED_DISABLE_UNKNOWN,
84 DEPRECATED_DISABLE_USER_ACTION,
85 DEPRECATED_DISABLE_PERMISSIONS_INCREASE,
86 DEPRECATED_DISABLE_RELOAD,
87 DEPRECATED_DISABLE_LAST, // Not used.
88 };
89
[email protected]44d62b62012-04-11 00:06:0390 enum DisableReason {
[email protected]eb5e4f92012-08-15 23:33:2891 DISABLE_NONE = 0,
92 DISABLE_USER_ACTION = 1 << 0,
93 DISABLE_PERMISSIONS_INCREASE = 1 << 1,
94 DISABLE_RELOAD = 1 << 2,
[email protected]215a7be2012-10-22 19:53:4295 DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3,
96 DISABLE_SIDELOAD_WIPEOUT = 1 << 4,
[email protected]f56c65ea62012-12-10 22:57:2197 DISABLE_UNKNOWN_FROM_SYNC = 1 << 5,
[email protected]44d62b62012-04-11 00:06:0398 };
99
[email protected]fbcc40302009-06-12 20:45:45100 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:37101 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:45102 DOWNGRADE,
103 REINSTALL,
104 UPGRADE,
105 NEW_INSTALL
106 };
107
[email protected]3bdba0d2011-08-23 07:17:30108 enum SyncType {
109 SYNC_TYPE_NONE = 0,
110 SYNC_TYPE_EXTENSION,
111 SYNC_TYPE_APP
112 };
113
[email protected]98270432012-09-11 20:51:24114 // Declared requirements for the extension.
115 struct Requirements {
116 Requirements();
117 ~Requirements();
118
119 bool webgl;
120 bool css3d;
121 bool npapi;
122 };
123
[email protected]92888082010-10-18 19:24:57124 // An NPAPI plugin included in the extension.
125 struct PluginInfo {
126 FilePath path; // Path to the plugin.
127 bool is_public; // False if only this extension can load this plugin.
128 };
129
[email protected]65378f52011-04-08 02:31:23130 // An NaCl module included in the extension.
131 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42132 GURL url;
[email protected]65378f52011-04-08 02:31:23133 std::string mime_type;
134 };
135
[email protected]a79be1f2012-03-23 22:14:00136 // OAuth2 info included in the extension.
137 struct OAuth2Info {
138 OAuth2Info();
139 ~OAuth2Info();
140
[email protected]c2e66e12012-06-27 06:27:06141 OAuth2Scopes GetScopesAsSet();
[email protected]b6f38622012-04-25 03:20:19142
[email protected]a79be1f2012-03-23 22:14:00143 std::string client_id;
144 std::vector<std::string> scopes;
145 };
146
[email protected]d356c982012-12-12 19:32:55147 // A base class for parsed manifest data that APIs want to store on
148 // the extension. Related to base::SupportsUserData, but with an immutable
149 // thread-safe interface to match Extension.
150 struct ManifestData {
151 virtual ~ManifestData() {}
152 };
153
[email protected]83048a22011-03-29 00:14:13154 enum InitFromValueFlags {
155 NO_FLAGS = 0,
156
157 // Usually, the id of an extension is generated by the "key" property of
158 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
159 // generated based on the path.
160 REQUIRE_KEY = 1 << 0,
161
[email protected]3f53dfe2011-11-30 01:18:29162 // Requires the extension to have an up-to-date manifest version.
163 // Typically, we'll support multiple manifest versions during a version
[email protected]26367b62012-10-04 23:03:32164 // transition. This flag signals that we want to require the most modern
[email protected]3f53dfe2011-11-30 01:18:29165 // manifest version that Chrome understands.
166 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
167
[email protected]3aff9ad2011-04-01 20:26:48168 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
169 // to have file access. If it's not present, then permissions and content
170 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51171 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34172
173 // |FROM_WEBSTORE| indicates that the extension was installed from the
174 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51175 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05176
177 // |FROM_BOOKMARK| indicates the extension was created using a mock App
178 // created from a bookmark.
[email protected]ed3b9b12012-05-31 18:37:51179 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58180
181 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
182 // anywhere in the filesystem, rather than being restricted to the
183 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51184 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03185
186 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
187 // extension should be errors rather than warnings.
188 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]e33bbc22012-08-27 22:05:46189
190 // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was
191 // created.
192 WAS_INSTALLED_BY_DEFAULT = 1 << 7,
[email protected]83048a22011-03-29 00:14:13193 };
194
[email protected]66e4eb32010-10-27 20:37:41195 static scoped_refptr<Extension> Create(const FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40196 Manifest::Location location,
[email protected]f3a1c642011-07-12 19:15:03197 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13198 int flags,
[email protected]66e4eb32010-10-27 20:37:41199 std::string* error);
200
[email protected]87c655e2011-07-01 21:42:00201 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26202 // an explicit id. Most consumers should just use the other Create() method.
203 static scoped_refptr<Extension> Create(const FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40204 Manifest::Location location,
[email protected]58f62cf2012-03-09 10:45:11205 const base::DictionaryValue& value,
206 int flags,
207 const std::string& explicit_id,
208 std::string* error);
[email protected]87c655e2011-07-01 21:42:00209
[email protected]4c4f8192009-10-17 01:03:26210 // Max size (both dimensions) for browser and page actions.
211 static const int kPageActionIconMaxSize;
212 static const int kBrowserActionIconMaxSize;
213
[email protected]8d888c12010-11-30 00:00:25214 // Valid schemes for web extent URLPatterns.
215 static const int kValidWebExtentSchemes;
216
[email protected]f71f7e62010-12-07 03:45:33217 // Valid schemes for host permission URLPatterns.
218 static const int kValidHostPermissionSchemes;
219
[email protected]6014d672008-12-05 00:38:25220 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16221 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25222
[email protected]300cc58db2009-08-19 20:45:14223 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16224 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14225
226 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16227 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14228
[email protected]25b34332009-06-05 21:53:19229#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19230 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19231#endif
232
[email protected]37eeb5a2009-02-26 23:36:17233 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48234 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17235
[email protected]e435d6b72009-07-25 03:15:58236 // The mimetype used for extensions.
237 static const char kMimeType[];
238
[email protected]25b34332009-06-05 21:53:19239 // Checks to see if the extension has a valid ID.
240 static bool IdIsValid(const std::string& id);
241
[email protected]4ead6f72010-10-13 19:54:18242 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27243 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18244 static std::string GenerateIdForPath(const FilePath& file_name);
245
[email protected]e435d6b72009-07-25 03:15:58246 // Returns true if the specified file is an extension.
247 static bool IsExtension(const FilePath& file_name);
248
[email protected]fc6b0612012-03-29 13:40:06249 // Fills the |info| dictionary with basic information about the extension.
250 // |enabled| is injected for easier testing.
251 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const;
252
[email protected]1d5e58b2013-01-31 08:41:40253 // See Type definition in Manifest.
254 Manifest::Type GetType() const;
[email protected]9b217652010-10-08 22:04:23255
[email protected]07c00d992009-03-04 20:27:04256 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59257 // |extension_url| argument should be the url() from an Extension object. The
258 // |relative_path| can be untrusted user input. The returned URL will either
259 // be invalid() or a child of |extension_url|.
260 // NOTE: Static so that it can be used from multiple threads.
261 static GURL GetResourceURL(const GURL& extension_url,
262 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28263 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24264 return GetResourceURL(url(), relative_path);
265 }
[email protected]eab9b452009-01-23 20:48:59266
[email protected]f59a8052012-06-20 22:25:00267 // Returns true if the resource matches a pattern in the pattern_set.
268 bool ResourceMatches(const URLPatternSet& pattern_set,
269 const std::string& resource) const;
270
[email protected]dbb24162012-06-06 01:41:22271 // Returns true if the specified page is sandboxed (served in a unique
272 // origin).
273 bool IsSandboxedPage(const std::string& relative_path) const;
274
275 // Returns the Content Security Policy that the specified resource should be
276 // served with.
277 std::string GetResourceContentSecurityPolicy(const std::string& relative_path)
278 const;
279
[email protected]99efb7b12009-12-18 02:39:16280 // Returns an extension resource object. |relative_path| should be UTF8
281 // encoded.
[email protected]9adb9692010-10-29 23:14:02282 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16283
284 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02285 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59286
[email protected]a17f9462009-06-09 02:56:41287 // |input| is expected to be the text of an rsa public or private key. It
288 // tolerates the presence or absence of bracking header/footer like this:
289 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
290 // and may contain newlines.
291 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
292
293 // Does a simple base64 encoding of |input| into |output|.
294 static bool ProducePEM(const std::string& input, std::string* output);
295
[email protected]84ac7f32009-10-06 06:17:54296 // Generates an extension ID from arbitrary input. The same input string will
297 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15298 static bool GenerateId(const std::string& input,
299 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45300
[email protected]a17f9462009-06-09 02:56:41301 // Expects base64 encoded |input| and formats into |output| including
302 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50303 static bool FormatPEMForFileOutput(const std::string& input,
304 std::string* output,
305 bool is_public);
[email protected]a17f9462009-06-09 02:56:41306
[email protected]58f62cf2012-03-09 10:45:11307 // Given an extension, icon size, and match type, read a valid icon if present
[email protected]e3c0bc22012-02-24 01:34:15308 // and decode it into result. In the browser process, this will DCHECK if not
309 // called on the file thread. To easily load extension images on the UI
310 // thread, see ImageLoadingTracker.
311 static void DecodeIcon(const Extension* extension,
[email protected]faf87192012-08-17 00:07:59312 int icon_size,
[email protected]e3c0bc22012-02-24 01:34:15313 ExtensionIconSet::MatchType match_type,
314 scoped_ptr<SkBitmap>* result);
315
[email protected]c690a9812009-12-17 05:55:32316 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23317 // result. In the browser process, this will DCHECK if not called on the
318 // file thread. To easily load extension images on the UI thread, see
319 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02320 static void DecodeIcon(const Extension* extension,
[email protected]faf87192012-08-17 00:07:59321 int icon_size,
[email protected]c690a9812009-12-17 05:55:32322 scoped_ptr<SkBitmap>* result);
323
324 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23325 // result. In the browser process, this will DCHECK if not called on the
326 // file thread. To easily load extension images on the UI thread, see
327 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32328 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]faf87192012-08-17 00:07:59329 int icon_size,
[email protected]c690a9812009-12-17 05:55:32330 scoped_ptr<SkBitmap>* result);
331
[email protected]5349ac6d2011-04-05 22:20:17332 // Returns the default extension/app icon (for extensions or apps that don't
333 // have one).
[email protected]dd46a4ce2012-09-15 10:50:50334 static const gfx::ImageSkia& GetDefaultIcon(bool is_app);
[email protected]5349ac6d2011-04-05 22:20:17335
[email protected]a807bbe2010-04-14 10:51:19336 // Returns the base extension url for a given |extension_id|.
337 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
338
[email protected]be7e5cb2010-10-04 12:53:17339 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17340 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21341 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17342
[email protected]902fd7b2011-07-27 18:42:31343 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27344 // from |manifest_|.
345 bool ParsePermissions(const char* key,
[email protected]fc670822011-12-17 09:33:49346 string16* error,
[email protected]c2e66e12012-06-27 06:27:06347 APIPermissionSet* api_permissions,
[email protected]902fd7b2011-07-27 18:42:31348 URLPatternSet* host_permissions);
349
[email protected]d624b0b2012-12-12 04:05:19350 // Returns true if this extension has the given permission. Prefer
351 // IsExtensionWithPermissionOrSuggestInConsole when developers may be using an
352 // api that requires a permission they didn't know about, e.g. open web apis.
[email protected]c2e66e12012-06-27 06:27:06353 bool HasAPIPermission(APIPermission::ID permission) const;
[email protected]0d3e4a22011-06-23 19:02:52354 bool HasAPIPermission(const std::string& function_name) const;
[email protected]3d0e2262012-08-02 15:32:16355 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const;
[email protected]583d45c12010-08-31 02:48:12356
[email protected]ecb9ad12012-08-21 13:02:15357 bool CheckAPIPermissionWithParam(APIPermission::ID permission,
358 const APIPermission::CheckParam* param) const;
[email protected]1d8b79a2012-08-16 20:22:54359
[email protected]0d3e4a22011-06-23 19:02:52360 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46361
[email protected]902fd7b2011-07-27 18:42:31362 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16363 // Users must approve permissions for unpacked and packed extensions in the
364 // following situations:
365 // - when installing or upgrading packed extensions
366 // - when installing unpacked extensions that have NPAPI plugins
367 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31368 bool CanSilentlyIncreasePermissions() const;
369
[email protected]584b8e3f2010-04-10 00:23:37370 // Whether the extension has access to the given URL.
371 bool HasHostPermission(const GURL& url) const;
372
[email protected]0df165f2010-09-28 16:49:40373 // Whether the extension has effective access to all hosts. This is true if
374 // there is a content script that matches all hosts, if there is a host
375 // permission grants access to all hosts (like <all_urls>) or an api
376 // permission that effectively grants access to all hosts (e.g. proxy,
377 // network, etc.)
378 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46379
[email protected]8d888c12010-11-30 00:00:25380 // Whether the extension effectively has all permissions (for example, by
381 // having an NPAPI plugin).
382 bool HasFullPermissions() const;
383
[email protected]902fd7b2011-07-27 18:42:31384 // Returns the full list of permission messages that this extension
385 // should display at install time.
[email protected]c2e66e12012-06-27 06:27:06386 PermissionMessages GetPermissionMessages() const;
[email protected]902fd7b2011-07-27 18:42:31387
388 // Returns the full list of permission messages that this extension
389 // should display at install time. The messages are returned as strings
390 // for convenience.
391 std::vector<string16> GetPermissionMessageStrings() const;
392
[email protected]b0d1d0b2012-11-02 21:19:03393 // Returns true if the extension does not require permission warnings
394 // to be displayed at install time.
395 bool ShouldSkipPermissionWarnings() const;
396
[email protected]902fd7b2011-07-27 18:42:31397 // Sets the active |permissions|.
[email protected]c2e66e12012-06-27 06:27:06398 void SetActivePermissions(const PermissionSet* permissions) const;
[email protected]902fd7b2011-07-27 18:42:31399
400 // Gets the extension's active permission set.
[email protected]c2e66e12012-06-27 06:27:06401 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31402
[email protected]5df6a5d2011-01-26 07:39:12403 // Whether context menu should be shown for page and browser actions.
404 bool ShowConfigureContextMenus() const;
405
[email protected]facd7a7652009-06-05 23:15:02406 // Returns a list of paths (relative to the extension dir) for images that
407 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02408 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02409
[email protected]807871f2010-09-16 01:04:48410 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02411 ExtensionResource GetIconResource(
412 int size, ExtensionIconSet::MatchType match_type) const;
413 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08414
[email protected]867a73e12010-03-19 20:45:46415 // Gets the fully resolved absolute launch URL.
416 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21417
[email protected]6f229e82010-11-02 17:47:26418 // Image cache related methods. These are only valid on the UI thread and
419 // not maintained by this class. See ImageLoadingTracker for usage. The
420 // |original_size| parameter should be the size of the image at |source|
421 // before any scaling may have been done to produce the pixels in |image|.
422 void SetCachedImage(const ExtensionResource& source,
423 const SkBitmap& image,
424 const gfx::Size& original_size) const;
425 bool HasCachedImage(const ExtensionResource& source,
426 const gfx::Size& max_size) const;
427 SkBitmap GetCachedImage(const ExtensionResource& source,
428 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21429
430 // Returns true if this extension can execute script on a page. If a
431 // UserScript object is passed, permission to run that specific script is
432 // checked (using its matches list). Otherwise, permission to execute script
433 // programmatically is checked (using the extension's host permission).
434 //
435 // This method is also aware of certain special pages that extensions are
436 // usually not allowed to run script on.
[email protected]78bdfd662012-08-23 05:53:18437 bool CanExecuteScriptOnPage(const GURL& document_url,
438 const GURL& top_document_url,
[email protected]fc5e65d6b2012-06-13 00:22:57439 int tab_id,
[email protected]3aff9ad2011-04-01 20:26:48440 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21441 std::string* error) const;
442
[email protected]6f229e82010-11-02 17:47:26443 // Returns true if this extension is a COMPONENT extension, or if it is
444 // on the whitelist of extensions that can script all pages.
445 bool CanExecuteScriptEverywhere() const;
446
[email protected]5efbfe012011-02-22 23:07:18447 // Returns true if this extension is allowed to obtain the contents of a
448 // page as an image. Since a page may contain sensitive information, this
449 // is restricted to the extension's host permissions as well as the
450 // extension page itself.
[email protected]fc5e65d6b2012-06-13 00:22:57451 bool CanCaptureVisiblePage(const GURL& page_url,
452 int tab_id,
453 std::string* error) const;
[email protected]5efbfe012011-02-22 23:07:18454
[email protected]a65882c2010-11-12 15:15:09455 // Returns true if this extension updates itself using the extension
456 // gallery.
457 bool UpdatesFromGallery() const;
458
[email protected]cca147172011-02-17 01:29:29459 // Returns true if this extension or app includes areas within |origin|.
460 bool OverlapsWithOrigin(const GURL& origin) const;
461
[email protected]3bdba0d2011-08-23 07:17:30462 // Returns the sync bucket to use for this extension.
463 SyncType GetSyncType() const;
464
[email protected]b873cd92012-02-09 21:51:48465 // Returns true if the extension should be synced.
466 bool IsSyncable() const;
467
[email protected]7e0f92b2012-11-09 03:51:04468 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
469 // for displaying in a launcher or new tab page.
470 bool RequiresSortOrdinal() const;
471
472 // Returns true if the extension should be displayed in the app launcher.
473 bool ShouldDisplayInAppLauncher() const;
474
475 // Returns true if the extension should be displayed in the browser NTP.
476 bool ShouldDisplayInNewTabPage() const;
[email protected]b873cd92012-02-09 21:51:48477
[email protected]e0b3de72012-05-01 01:21:34478 // Returns true if the extension should be displayed in the extension
479 // settings page (i.e. chrome://extensions).
480 bool ShouldDisplayInExtensionSettings() const;
481
[email protected]4f886012012-05-19 03:51:10482 // Returns true if the extension has a content script declared at |url|.
483 bool HasContentScriptAtURL(const GURL& url) const;
484
[email protected]fc5e65d6b2012-06-13 00:22:57485 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
486 // aren't any.
[email protected]3d0e2262012-08-02 15:32:16487 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
488 const;
[email protected]fc5e65d6b2012-06-13 00:22:57489
[email protected]3d0e2262012-08-02 15:32:16490 // Updates the tab-specific permissions of |tab_id| to include those from
491 // |permissions|.
[email protected]6144057e2012-08-02 19:02:37492 void UpdateTabSpecificPermissions(
493 int tab_id,
494 scoped_refptr<const PermissionSet> permissions) const;
[email protected]fc5e65d6b2012-06-13 00:22:57495
[email protected]3d0e2262012-08-02 15:32:16496 // Clears the tab-specific permissions of |tab_id|.
497 void ClearTabSpecificPermissions(int tab_id) const;
[email protected]fc5e65d6b2012-06-13 00:22:57498
[email protected]d356c982012-12-12 19:32:55499 // Get the manifest data associated with the key, or NULL if there is none.
500 // Can only be called after InitValue is finished.
501 ManifestData* GetManifestData(const std::string& key) const;
502
503 // Sets |data| to be associated with the key. Takes ownership of |data|.
504 // Can only be called before InitValue is finished. Not thread-safe;
505 // all SetManifestData calls should be on only one thread.
506 void SetManifestData(const std::string& key, ManifestData* data);
507
[email protected]6f229e82010-11-02 17:47:26508 // Accessors:
509
[email protected]98270432012-09-11 20:51:24510 const Requirements& requirements() const { return requirements_; }
[email protected]6f229e82010-11-02 17:47:26511 const FilePath& path() const { return path_; }
512 const GURL& url() const { return extension_url_; }
[email protected]1d5e58b2013-01-31 08:41:40513 Manifest::Location location() const;
[email protected]d41e2152012-02-24 04:20:27514 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26515 const Version* version() const { return version_.get(); }
516 const std::string VersionString() const;
517 const std::string& name() const { return name_; }
[email protected]701d1e82012-05-14 05:34:19518 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06519 // Base64-encoded version of the key used to sign this extension.
520 // In pseudocode, returns
521 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
522 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26523 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31524 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26525 bool converted_from_user_script() const {
526 return converted_from_user_script_;
527 }
528 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]0f34d9082012-10-08 19:16:44529 const ActionInfo* page_action_info() const { return page_action_info_.get(); }
[email protected]ad12b6b2012-11-28 23:21:15530 const ActionInfo* system_indicator_info() const {
531 return system_indicator_info_.get();
532 }
[email protected]6f229e82010-11-02 17:47:26533 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23534 const std::vector<NaClModuleInfo>& nacl_modules() const {
535 return nacl_modules_;
536 }
[email protected]a03d4448f2012-01-10 23:25:28537 bool has_background_page() const {
538 return background_url_.is_valid() || !background_scripts_.empty();
539 }
[email protected]7b54ca02012-03-02 18:06:53540 bool allow_background_js_access() const {
541 return allow_background_js_access_;
542 }
[email protected]a03d4448f2012-01-10 23:25:28543 const std::vector<std::string>& background_scripts() const {
544 return background_scripts_;
545 }
[email protected]d2aa06b2012-03-21 20:57:26546 bool has_persistent_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00547 return has_background_page() && background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26548 }
549 bool has_lazy_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00550 return has_background_page() && !background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26551 }
[email protected]c2e66e12012-06-27 06:27:06552 const PermissionSet* optional_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31553 return optional_permission_set_.get();
554 }
[email protected]c2e66e12012-06-27 06:27:06555 const PermissionSet* required_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31556 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26557 }
[email protected]23b3c0a2013-01-16 23:36:36558 // Appends |new_warning[s]| to install_warnings_.
559 void AddInstallWarning(const InstallWarning& new_warning);
[email protected]1d5e58b2013-01-31 08:41:40560 void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings);
561 const std::vector<InstallWarning>& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03562 return install_warnings_;
563 }
[email protected]6f229e82010-11-02 17:47:26564 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32565 const extensions::Manifest* manifest() const {
[email protected]e9629d772012-08-06 19:44:46566 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26567 }
[email protected]6f229e82010-11-02 17:47:26568 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55569 bool offline_enabled() const { return offline_enabled_; }
[email protected]a79be1f2012-03-23 22:14:00570 const OAuth2Info& oauth2_info() const { return oauth2_info_; }
[email protected]3aff9ad2011-04-01 20:26:48571 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23572 int creation_flags() const { return creation_flags_; }
573 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05574 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]e33bbc22012-08-27 22:05:46575 bool was_installed_by_default() const {
576 return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0;
577 }
[email protected]3aff9ad2011-04-01 20:26:48578
[email protected]6f229e82010-11-02 17:47:26579 // App-related.
[email protected]953620b2011-12-04 00:55:32580 bool is_app() const {
[email protected]c4f459d2012-09-28 04:40:10581 return is_legacy_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39582 }
[email protected]d41e2152012-02-24 04:20:27583 bool is_platform_app() const;
584 bool is_hosted_app() const;
[email protected]c4f459d2012-09-28 04:40:10585 bool is_legacy_packaged_app() const;
[email protected]ff05a4b102012-12-19 00:12:06586 bool is_extension() const;
[email protected]605fb8102012-05-04 01:36:55587 bool is_storage_isolated() const { return is_storage_isolated_; }
[email protected]cdc7b1f42012-12-07 19:39:48588 bool can_be_incognito_enabled() const;
[email protected]636ee43282013-01-12 15:58:00589 void AddWebExtentPattern(const URLPattern& pattern);
[email protected]cced75a2011-05-20 08:31:12590 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26591 const std::string& launch_local_path() const { return launch_local_path_; }
592 const std::string& launch_web_url() const { return launch_web_url_; }
593 extension_misc::LaunchContainer launch_container() const {
594 return launch_container_;
595 }
[email protected]dc37b002012-04-23 23:02:26596 int launch_width() const { return launch_width_; }
597 int launch_height() const { return launch_height_; }
[email protected]6f229e82010-11-02 17:47:26598
599 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27600 bool is_theme() const;
[email protected]f3a1c642011-07-12 19:15:03601 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
602 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
603 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
604 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26605 return theme_display_properties_.get();
606 }
607
[email protected]6d55bd62012-11-21 17:52:03608 // Content Security Policy!
609 const std::string& content_security_policy() const {
610 return content_security_policy_;
611 }
612
[email protected]66008002013-01-08 09:09:13613 // Content pack related.
[email protected]fbb620832013-01-25 17:20:35614 bool is_content_pack() const;
[email protected]66008002013-01-08 09:09:13615 ExtensionResource GetContentPackSiteList() const;
616
[email protected]a03d4448f2012-01-10 23:25:28617 GURL GetBackgroundURL() const;
618
[email protected]4a8d3272009-03-10 19:15:08619 private:
[email protected]66e4eb32010-10-27 20:37:41620 friend class base::RefCountedThreadSafe<Extension>;
621
[email protected]d7e9a862010-11-03 21:57:49622 // We keep a cache of images loaded from extension resources based on their
623 // path and a string representation of a size that may have been used to
624 // scale it (or the empty string if the image is at its original size).
625 typedef std::pair<FilePath, std::string> ImageCacheKey;
626 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
627
[email protected]902fd7b2011-07-27 18:42:31628 class RuntimeData {
629 public:
630 RuntimeData();
[email protected]c2e66e12012-06-27 06:27:06631 explicit RuntimeData(const PermissionSet* active);
[email protected]902fd7b2011-07-27 18:42:31632 ~RuntimeData();
633
[email protected]c2e66e12012-06-27 06:27:06634 void SetActivePermissions(const PermissionSet* active);
635 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31636
[email protected]3d0e2262012-08-02 15:32:16637 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
638 const;
[email protected]6144057e2012-08-02 19:02:37639 void UpdateTabSpecificPermissions(
640 int tab_id,
641 scoped_refptr<const PermissionSet> permissions);
[email protected]3d0e2262012-08-02 15:32:16642 void ClearTabSpecificPermissions(int tab_id);
[email protected]fc5e65d6b2012-06-13 00:22:57643
[email protected]902fd7b2011-07-27 18:42:31644 private:
645 friend class base::RefCountedThreadSafe<RuntimeData>;
[email protected]fc5e65d6b2012-06-13 00:22:57646
[email protected]c2e66e12012-06-27 06:27:06647 scoped_refptr<const PermissionSet> active_permissions_;
[email protected]fc5e65d6b2012-06-13 00:22:57648
[email protected]3d0e2262012-08-02 15:32:16649 typedef std::map<int, scoped_refptr<const PermissionSet> >
650 TabPermissionsMap;
651 TabPermissionsMap tab_specific_permissions_;
[email protected]902fd7b2011-07-27 18:42:31652 };
653
[email protected]d41e2152012-02-24 04:20:27654 // Chooses the extension ID for an extension based on a variety of criteria.
655 // The chosen ID will be set in |manifest|.
656 static bool InitExtensionID(extensions::Manifest* manifest,
657 const FilePath& path,
658 const std::string& explicit_id,
659 int creation_flags,
660 string16* error);
661
[email protected]4ead6f72010-10-13 19:54:18662 // Normalize the path for use by the extension. On Windows, this will make
663 // sure the drive letter is uppercase.
664 static FilePath MaybeNormalizePath(const FilePath& path);
665
[email protected]87c655e2011-07-01 21:42:00666 // Returns true if this extension id is from a trusted provider.
667 static bool IsTrustedId(const std::string& id);
668
[email protected]d41e2152012-02-24 04:20:27669 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
[email protected]d356c982012-12-12 19:32:55670 virtual ~Extension();
[email protected]66e4eb32010-10-27 20:37:41671
672 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27673 // TODO(aa): Rename to just Init()? There's no Value here anymore.
674 // TODO(aa): It is really weird the way this class essentially contains a copy
675 // of the underlying DictionaryValue in its members. We should decide to
676 // either wrap the DictionaryValue and go with that only, or we should parse
677 // into strong types and discard the value. But doing both is bad.
678 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41679
[email protected]58f62cf2012-03-09 10:45:11680 // The following are helpers for InitFromValue to load various features of the
681 // extension from the manifest.
682
[email protected]c2e66e12012-06-27 06:27:06683 bool LoadAppIsolation(const APIPermissionSet& api_permissions,
[email protected]605fb8102012-05-04 01:36:55684 string16* error);
[email protected]58f62cf2012-03-09 10:45:11685
686 bool LoadRequiredFeatures(string16* error);
687 bool LoadName(string16* error);
688 bool LoadVersion(string16* error);
689
690 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27691 bool LoadExtent(const char* key,
692 URLPatternSet* extent,
693 const char* list_error,
694 const char* value_error,
695 string16* error);
696 bool LoadLaunchContainer(string16* error);
697 bool LoadLaunchURL(string16* error);
[email protected]10253da2012-03-09 04:06:42698
[email protected]c2e66e12012-06-27 06:27:06699 bool LoadSharedFeatures(const APIPermissionSet& api_permissions,
[email protected]58f62cf2012-03-09 10:45:11700 string16* error);
701 bool LoadDescription(string16* error);
702 bool LoadManifestVersion(string16* error);
[email protected]58f62cf2012-03-09 10:45:11703 bool LoadIcons(string16* error);
[email protected]58f62cf2012-03-09 10:45:11704 bool LoadPlugins(string16* error);
705 bool LoadNaClModules(string16* error);
[email protected]dbb24162012-06-06 01:41:22706 bool LoadSandboxedPages(string16* error);
[email protected]98270432012-09-11 20:51:24707 // Must be called after LoadPlugins().
708 bool LoadRequirements(string16* error);
[email protected]58f62cf2012-03-09 10:45:11709 bool LoadOfflineEnabled(string16* error);
[email protected]d41e2152012-02-24 04:20:27710 bool LoadBackgroundScripts(string16* error);
[email protected]756038532012-06-08 05:45:03711 bool LoadBackgroundScripts(const std::string& key, string16* error);
[email protected]c2e66e12012-06-27 06:27:06712 bool LoadBackgroundPage(const APIPermissionSet& api_permissions,
[email protected]d41e2152012-02-24 04:20:27713 string16* error);
[email protected]756038532012-06-08 05:45:03714 bool LoadBackgroundPage(const std::string& key,
[email protected]c2e66e12012-06-27 06:27:06715 const APIPermissionSet& api_permissions,
[email protected]756038532012-06-08 05:45:03716 string16* error);
[email protected]dd62fa802012-04-25 18:37:00717 bool LoadBackgroundPersistent(
[email protected]c2e66e12012-06-27 06:27:06718 const APIPermissionSet& api_permissions,
[email protected]d41e2152012-02-24 04:20:27719 string16* error);
[email protected]58f62cf2012-03-09 10:45:11720 bool LoadBackgroundAllowJSAccess(
[email protected]c2e66e12012-06-27 06:27:06721 const APIPermissionSet& api_permissions,
[email protected]7b54ca02012-03-02 18:06:53722 string16* error);
[email protected]ad12b6b2012-11-28 23:21:15723 bool LoadExtensionFeatures(APIPermissionSet* api_permissions,
[email protected]58f62cf2012-03-09 10:45:11724 string16* error);
[email protected]58f62cf2012-03-09 10:45:11725 bool LoadContentScripts(string16* error);
726 bool LoadPageAction(string16* error);
727 bool LoadBrowserAction(string16* error);
[email protected]ad12b6b2012-11-28 23:21:15728 bool LoadSystemIndicator(APIPermissionSet* api_permissions, string16* error);
[email protected]58f62cf2012-03-09 10:45:11729 bool LoadTextToSpeechVoices(string16* error);
730 bool LoadIncognitoMode(string16* error);
731 bool LoadContentSecurityPolicy(string16* error);
732
733 bool LoadThemeFeatures(string16* error);
734 bool LoadThemeImages(const base::DictionaryValue* theme_value,
735 string16* error);
736 bool LoadThemeColors(const base::DictionaryValue* theme_value,
737 string16* error);
738 bool LoadThemeTints(const base::DictionaryValue* theme_value,
739 string16* error);
740 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value,
741 string16* error);
742
[email protected]66008002013-01-08 09:09:13743 bool LoadManagedModeFeatures(string16* error);
744 bool LoadManagedModeSites(
745 const base::DictionaryValue* content_pack_value,
746 string16* error);
747 bool LoadManagedModeConfigurations(
748 const base::DictionaryValue* content_pack_value,
749 string16* error);
750
[email protected]58f62cf2012-03-09 10:45:11751 // Helper function for implementing HasCachedImage/GetCachedImage. A return
752 // value of NULL means there is no matching image cached (we allow caching an
753 // empty SkBitmap).
754 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
755 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18756
[email protected]3cfbd0e2009-03-18 21:26:24757 // Helper method that loads a UserScript object from a
758 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03759 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24760 int definition_index,
[email protected]fc670822011-12-17 09:33:49761 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24762 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34763
[email protected]6657afa62009-11-04 02:15:20764 // Helper method that loads either the include_globs or exclude_globs list
765 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03766 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20767 int content_script_index,
[email protected]e2194742010-08-12 05:54:34768 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49769 string16* error,
[email protected]11f4857282009-11-13 19:56:17770 void(UserScript::*add_method)(const std::string& glob),
[email protected]488e6502012-09-07 14:17:34771 UserScript* instance);
[email protected]6657afa62009-11-04 02:15:20772
[email protected]a79be1f2012-03-23 22:14:00773 // Helper method that loads the OAuth2 info from the 'oauth2' manifest key.
774 bool LoadOAuth2Info(string16* error);
775
[email protected]2f6698b2010-10-14 00:58:21776 // Returns true if the extension has more than one "UI surface". For example,
777 // an extension that has a browser action and a page action.
778 bool HasMultipleUISurfaces() const;
779
[email protected]be9d9c82011-07-13 04:17:31780 // Updates the launch URL and extents for the extension using the given
781 // |override_url|.
782 void OverrideLaunchUrl(const GURL& override_url);
783
[email protected]ae655e4e2012-03-16 21:47:55784 // Custom checks for the experimental permission that can't be expressed in
785 // _permission_features.json.
[email protected]5eddc3e2011-10-26 04:33:31786 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31787
788 // Checks whether the host |pattern| is allowed for this extension, given API
789 // permissions |permissions|.
790 bool CanSpecifyHostPermission(const URLPattern& pattern,
[email protected]c2e66e12012-06-27 06:27:06791 const APIPermissionSet& permissions) const;
[email protected]5eddc3e2011-10-26 04:33:31792
[email protected]488e6502012-09-07 14:17:34793 bool CheckMinimumChromeVersion(string16* error) const;
[email protected]488e6502012-09-07 14:17:34794
[email protected]e92169e2012-05-04 22:49:32795 // Check that platform app features are valid. Called after InitFromValue.
[email protected]488e6502012-09-07 14:17:34796 bool CheckPlatformAppFeatures(std::string* utf8_error) const;
[email protected]e92169e2012-05-04 22:49:32797
[email protected]f1bab9c92012-05-11 21:15:10798 // Check that features don't conflict. Called after InitFromValue.
[email protected]488e6502012-09-07 14:17:34799 bool CheckConflictingFeatures(std::string* utf8_error) const;
[email protected]f1bab9c92012-05-11 21:15:10800
[email protected]d7e9a862010-11-03 21:57:49801 // Cached images for this extension. This should only be touched on the UI
802 // thread.
803 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31804
[email protected]6f229e82010-11-02 17:47:26805 // The extension's human-readable name. Name is used for display purpose. It
806 // might be wrapped with unicode bidi control characters so that it is
807 // displayed correctly in RTL context.
808 // NOTE: Name is UTF-8 and may contain non-ascii characters.
809 std::string name_;
810
[email protected]701d1e82012-05-14 05:34:19811 // A non-localized version of the extension's name. This is useful for
812 // debug output.
813 std::string non_localized_name_;
814
[email protected]a47c8a22011-11-17 18:40:31815 // The version of this extension's manifest. We increase the manifest
816 // version when making breaking changes to the extension system.
817 // Version 1 was the first manifest version (implied by a lack of a
818 // manifest_version attribute in the extension's manifest). We initialize
819 // this member variable to 0 to distinguish the "uninitialized" case from
820 // the case when we know the manifest version actually is 1.
821 int manifest_version_;
822
[email protected]98270432012-09-11 20:51:24823 // The requirements declared in the manifest.
824 Requirements requirements_;
825
[email protected]d41e2152012-02-24 04:20:27826 // The absolute path to the directory the extension is stored in.
827 FilePath path_;
828
[email protected]6f229e82010-11-02 17:47:26829 // If true, a separate process will be used for the extension in incognito
830 // mode.
831 bool incognito_split_mode_;
832
[email protected]1abdf4f2011-08-16 21:11:55833 // Whether the extension or app should be enabled when offline.
834 bool offline_enabled_;
835
[email protected]6f229e82010-11-02 17:47:26836 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12837 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26838
[email protected]902fd7b2011-07-27 18:42:31839 // The extension runtime data.
840 mutable base::Lock runtime_data_lock_;
841 mutable RuntimeData runtime_data_;
842
843 // The set of permissions the extension can request at runtime.
[email protected]c2e66e12012-06-27 06:27:06844 scoped_refptr<const PermissionSet> optional_permission_set_;
[email protected]902fd7b2011-07-27 18:42:31845
846 // The extension's required / default set of permissions.
[email protected]c2e66e12012-06-27 06:27:06847 scoped_refptr<const PermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26848
[email protected]8629c542012-04-20 03:40:03849 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1d5e58b2013-01-31 08:41:40850 std::vector<InstallWarning> install_warnings_;
[email protected]8629c542012-04-20 03:40:03851
[email protected]6f229e82010-11-02 17:47:26852 // The icons for the extension.
853 ExtensionIconSet icons_;
854
855 // The base extension url for the extension.
856 GURL extension_url_;
857
[email protected]6f229e82010-11-02 17:47:26858 // The extension's version.
859 scoped_ptr<Version> version_;
860
861 // An optional longer description of the extension.
862 std::string description_;
863
864 // True if the extension was generated from a user script. (We show slightly
865 // different UI if so).
866 bool converted_from_user_script_;
867
868 // Paths to the content scripts the extension contains.
869 UserScriptList content_scripts_;
870
871 // The extension's page action, if any.
[email protected]0f34d9082012-10-08 19:16:44872 scoped_ptr<ActionInfo> page_action_info_;
[email protected]6f229e82010-11-02 17:47:26873
[email protected]ad12b6b2012-11-28 23:21:15874 // The extension's system indicator, if any.
875 scoped_ptr<ActionInfo> system_indicator_info_;
876
[email protected]6f229e82010-11-02 17:47:26877 // Optional list of NPAPI plugins and associated properties.
878 std::vector<PluginInfo> plugins_;
879
[email protected]65378f52011-04-08 02:31:23880 // Optional list of NaCl modules and associated properties.
881 std::vector<NaClModuleInfo> nacl_modules_;
882
[email protected]dbb24162012-06-06 01:41:22883 // Optional list of extension pages that are sandboxed (served from a unique
884 // origin with a different Content Security Policy).
[email protected]f59a8052012-06-20 22:25:00885 URLPatternSet sandboxed_pages_;
[email protected]dbb24162012-06-06 01:41:22886
887 // Content Security Policy that should be used to enforce the sandbox used
888 // by sandboxed pages (guaranteed to have the "sandbox" directive without the
889 // "allow-same-origin" token).
890 std::string sandboxed_pages_content_security_policy_;
891
[email protected]6f229e82010-11-02 17:47:26892 // Optional URL to a master page of which a single instance should be always
893 // loaded in the background.
894 GURL background_url_;
895
[email protected]a03d4448f2012-01-10 23:25:28896 // Optional list of scripts to use to generate a background page. If this is
897 // present, background_url_ will be empty and generated by GetBackgroundURL().
898 std::vector<std::string> background_scripts_;
899
[email protected]dd62fa802012-04-25 18:37:00900 // True if the background page should stay loaded forever; false if it should
901 // load on-demand (when it needs to handle an event). Defaults to true.
902 bool background_page_is_persistent_;
[email protected]9e6720a2012-01-24 02:30:56903
[email protected]7b54ca02012-03-02 18:06:53904 // True if the background page can be scripted by pages of the app or
905 // extension, in which case all such pages must run in the same process.
906 // False if such pages are not permitted to script the background page,
907 // allowing them to run in different processes.
908 bool allow_background_js_access_;
909
[email protected]6f229e82010-11-02 17:47:26910 // The public key used to sign the contents of the crx package.
911 std::string public_key_;
912
913 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:03914 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:26915
916 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03917 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:26918
919 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:03920 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:26921
922 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:03923 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:26924
[email protected]66008002013-01-08 09:09:13925 // A file containing a list of sites for Managed Mode.
926 FilePath content_pack_site_list_;
927
[email protected]58f62cf2012-03-09 10:45:11928 // The manifest from which this extension was created.
[email protected]e9629d772012-08-06 19:44:46929 scoped_ptr<Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:26930
[email protected]d356c982012-12-12 19:32:55931 // Stored parsed manifest data.
932 ManifestDataMap manifest_data_;
933
934 // Set to true at the end of InitValue when initialization is finished.
935 bool finished_parsing_manifest_;
936
[email protected]7eeab9ec2013-01-15 04:08:33937 // Ensures that any call to GetManifestData() prior to finishing
938 // initialization happens from the same thread (this can happen when certain
939 // parts of the initialization process need information from previous parts).
940 base::ThreadChecker thread_checker_;
941
[email protected]d9696672011-03-15 22:45:09942 // Whether this extension requests isolated storage.
943 bool is_storage_isolated_;
944
[email protected]6f229e82010-11-02 17:47:26945 // The local path inside the extension to use with the launcher.
946 std::string launch_local_path_;
947
948 // A web url to use with the launcher. Note that this might be relative or
949 // absolute. If relative, it is relative to web_origin.
950 std::string launch_web_url_;
951
[email protected]4e595682011-02-09 17:07:02952 // The window type that an app's manifest specifies to launch into.
953 // This is not always the window type an app will open into, because
954 // users can override the way each app launches. See
955 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
956 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:26957 extension_misc::LaunchContainer launch_container_;
958
959 // The default size of the container when launching. Only respected for
960 // containers like panels and windows.
961 int launch_width_;
962 int launch_height_;
963
[email protected]7e0f92b2012-11-09 03:51:04964 // Should this app be shown in the app launcher.
[email protected]ed1a204f2012-09-22 00:28:44965 bool display_in_launcher_;
966
[email protected]7e0f92b2012-11-09 03:51:04967 // Should this app be shown in the browser New Tab Page.
968 bool display_in_new_tab_page_;
969
[email protected]a79be1f2012-03-23 22:14:00970 // The OAuth2 client id and scopes, if specified by the extension.
971 OAuth2Info oauth2_info_;
972
[email protected]3aff9ad2011-04-01 20:26:48973 // Whether the extension has host permissions or user script patterns that
974 // imply access to file:/// scheme URLs (the user may not have actually
975 // granted it that access).
976 bool wants_file_access_;
977
[email protected]2af352b2011-07-22 08:21:23978 // The flags that were passed to InitFromValue.
979 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34980
[email protected]7f7b9d932011-04-20 16:13:26981 // The Content-Security-Policy for this extension. Extensions can use
982 // Content-Security-Policies to mitigate cross-site scripting and other
983 // vulnerabilities.
984 std::string content_security_policy_;
985
[email protected]19118d52010-07-26 22:13:42986 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
[email protected]1c321ee2012-05-21 03:02:34987 FRIEND_TEST_ALL_PREFIXES(::TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58988
[email protected]894bb502009-05-21 22:39:57989 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33990};
991
[email protected]9adb9692010-10-29 23:14:02992typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:18993typedef std::set<std::string> ExtensionIdSet;
[email protected]82590cb2012-09-28 04:14:08994typedef std::vector<std::string> ExtensionIdList;
[email protected]b1748b1d82009-11-30 20:32:56995
[email protected]c6d474f82009-12-16 21:11:06996// Handy struct to pass core extension info around.
997struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03998 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:06999 const std::string& id,
1000 const FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:401001 Manifest::Location location);
[email protected]3bb84992010-08-26 17:23:461002 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:061003
[email protected]f3a1c642011-07-12 19:15:031004 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:061005 std::string extension_id;
1006 FilePath extension_path;
[email protected]1d5e58b2013-01-31 08:41:401007 Manifest::Location extension_location;
[email protected]c6d474f82009-12-16 21:11:061008
1009 private:
1010 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
1011};
1012
[email protected]a9f39a312010-12-23 22:14:271013struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:591014 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:271015
1016 // Was the extension already disabled?
1017 bool already_disabled;
1018
1019 // The extension being unloaded - this should always be non-NULL.
1020 const Extension* extension;
1021
[email protected]814a7bf0f2011-08-13 05:30:591022 UnloadedExtensionInfo(
1023 const Extension* extension,
1024 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:271025};
1026
[email protected]902fd7b2011-07-27 18:42:311027// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
1028struct UpdatedExtensionPermissionsInfo {
1029 enum Reason {
[email protected]f5532472012-02-23 13:00:551030 ADDED, // The permissions were added to the extension.
1031 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:311032 };
1033
1034 Reason reason;
1035
1036 // The extension who's permissions have changed.
1037 const Extension* extension;
1038
1039 // The permissions that have changed. For Reason::ADDED, this would contain
1040 // only the permissions that have added, and for Reason::REMOVED, this would
1041 // only contain the removed permissions.
[email protected]c2e66e12012-06-27 06:27:061042 const PermissionSet* permissions;
[email protected]902fd7b2011-07-27 18:42:311043
1044 UpdatedExtensionPermissionsInfo(
1045 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:061046 const PermissionSet* permissions,
[email protected]902fd7b2011-07-27 18:42:311047 Reason reason);
1048};
1049
[email protected]488e6502012-09-07 14:17:341050} // namespace extensions
[email protected]1c321ee2012-05-21 03:02:341051
[email protected]5b1a0e22009-05-26 19:00:581052#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_