blob: f55ffe02c27411dcd553b52155e3f1121e0e5346 [file] [log] [blame]
[email protected]225c8f52010-02-05 22:23:201// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]7713d632008-12-02 07:52:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5b1a0e22009-05-26 19:00:585#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_
6#define CHROME_COMMON_EXTENSIONS_EXTENSION_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]7713d632008-12-02 07:52:338
[email protected]300cc58db2009-08-19 20:45:149#include <map>
[email protected]facd7a7652009-06-05 23:15:0210#include <set>
[email protected]7713d632008-12-02 07:52:3311#include <string>
12#include <vector>
13
[email protected]6014d672008-12-05 00:38:2514#include "base/file_path.h"
[email protected]19118d52010-07-26 22:13:4215#include "base/gtest_prod_util.h"
[email protected]cc655912009-01-29 23:19:1916#include "base/scoped_ptr.h"
[email protected]4361c7c2010-09-30 21:57:5317#include "base/ref_counted.h"
[email protected]d83a5602010-09-16 00:22:4818#include "chrome/common/extensions/extension_constants.h"
[email protected]867a73e12010-03-19 20:45:4619#include "chrome/common/extensions/extension_extent.h"
[email protected]807871f2010-09-16 01:04:4820#include "chrome/common/extensions/extension_icon_set.h"
[email protected]42b6f0f82009-09-18 21:07:3921#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4922#include "chrome/common/extensions/url_pattern.h"
[email protected]052c92702010-06-25 07:25:5223#include "gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5924#include "googleurl/src/gurl.h"
25
[email protected]3bb84992010-08-26 17:23:4626class DictionaryValue;
[email protected]942690b132010-05-11 06:42:1427class ExtensionAction;
28class ExtensionResource;
[email protected]12802702010-07-09 19:43:0929class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2830class Version;
[email protected]942690b132010-05-11 06:42:1431
[email protected]f0755532010-06-22 07:27:2532// Represents a Chrome extension.
[email protected]7713d632008-12-02 07:52:3333class Extension {
34 public:
[email protected]d3cfa482009-10-17 13:54:5735 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]b24d8312009-08-27 06:47:4636
[email protected]631cf822009-05-15 07:01:2537 // What an extension was loaded from.
[email protected]1952c7d2010-03-04 23:48:3438 // NOTE: These values are stored as integers in the preferences, so you
39 // really don't want to change any existing ones.
[email protected]631cf822009-05-15 07:01:2540 enum Location {
41 INVALID,
[email protected]25b34332009-06-05 21:53:1942 INTERNAL, // A crx file from the internal Extensions directory.
43 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
44 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
45 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3446 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3247 COMPONENT, // An integral component of Chrome itself, which
48 // happens to be implemented as an extension. We don't
49 // show these in the management UI.
50 EXTERNAL_PREF_DOWNLOAD // A crx file from an external directory (via
51 // prefs), installed from an update URL.
[email protected]25b34332009-06-05 21:53:1952 };
53
54 enum State {
[email protected]0c6da502009-08-14 22:32:3955 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1956 ENABLED,
57 KILLBIT, // Don't install/upgrade (applies to external extensions only).
[email protected]0c6da502009-08-14 22:32:3958
59 NUM_STATES
[email protected]631cf822009-05-15 07:01:2560 };
[email protected]7713d632008-12-02 07:52:3361
[email protected]fbcc40302009-06-12 20:45:4562 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3763 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4564 DOWNGRADE,
65 REINSTALL,
66 UPGRADE,
67 NEW_INSTALL
68 };
69
[email protected]d2817012009-08-04 06:46:2170 // NOTE: If you change this list, you should also change kIconSizes in the cc
71 // file.
72 enum Icons {
73 EXTENSION_ICON_LARGE = 128,
74 EXTENSION_ICON_MEDIUM = 48,
75 EXTENSION_ICON_SMALL = 32,
[email protected]39382942010-03-23 15:57:0976 EXTENSION_ICON_SMALLISH = 24,
[email protected]d2817012009-08-04 06:46:2177 EXTENSION_ICON_BITTY = 16,
78 };
79
[email protected]4361c7c2010-09-30 21:57:5380 // Contains a subset of the extension's data that doesn't change once
81 // initialized, and therefore shareable across threads without locking.
82 struct StaticData : public base::RefCountedThreadSafe<StaticData> {
83 StaticData();
84
85 // TODO(mpcomplete): RefCountedThreadSafe does not allow AddRef/Release on
86 // const objects. I think that is a mistake. Until we can fix that, here's
87 // a workaround.
88 void AddRef() const {
89 const_cast<StaticData*>(this)->
90 base::RefCountedThreadSafe<StaticData>::AddRef();
91 }
92 void Release() const {
93 const_cast<StaticData*>(this)->
94 base::RefCountedThreadSafe<StaticData>::Release();
95 }
96
97 // A persistent, globally unique ID. An extension's ID is used in things
98 // like directory structures and URLs, and is expected to not change across
99 // versions. It is generated as a SHA-256 hash of the extension's public
100 // key, or as a hash of the path in the case of unpacked extensions.
101 std::string id;
102
103 // The extension's human-readable name. Name is used for display purpose. It
104 // might be wrapped with unicode bidi control characters so that it is
105 // displayed correctly in RTL context.
106 // NOTE: Name is UTF-8 and may contain non-ascii characters.
107 std::string name;
108
109 // The absolute path to the directory the extension is stored in.
110 FilePath path;
111
112 // Default locale for fall back. Can be empty if extension is not localized.
113 std::string default_locale;
114
115 // If true, a separate process will be used for the extension in incognito
116 // mode.
117 bool incognito_split_mode;
118
119 // Defines the set of URLs in the extension's web content.
120 ExtensionExtent extent;
121
122 // The set of hosts that the extension effectively has access to. This is
123 // used in the permissions UI and is a combination of the hosts accessible
124 // through content scripts and the hosts accessible through XHR.
125 ExtensionExtent effective_host_permissions;
126
127 // The set of module-level APIs this extension can use.
128 std::set<std::string> api_permissions;
129
130 // The icons for the extension.
131 ExtensionIconSet icons;
132
133 protected:
134 friend class base::RefCountedThreadSafe<StaticData>;
135 ~StaticData();
136 };
137
[email protected]0df165f2010-09-28 16:49:40138 // A permission is defined by its |name| (what is used in the manifest),
139 // and the |message_id| that's used by install/update UI.
140 struct Permission {
141 const char* const name;
142 const int message_id;
143 };
144
145 // The install message id for |permission|. Returns 0 if none exists.
146 static int GetPermissionMessageId(const std::string& permission);
147
[email protected]a2a098d2010-09-29 19:42:55148 // Returns the full list of permission messages that this extension
149 // should display at install time.
150 std::vector<string16> GetPermissionMessages();
151
152 // Returns the distinct hosts that should be displayed in the install UI. This
153 // discards some of the detail that is present in the manifest to make it as
154 // easy as possible to process by users. In particular we disregard the scheme
155 // and path components of URLPatterns and de-dupe the result.
156 static std::vector<std::string> GetDistinctHosts(
157 const URLPatternList& host_patterns);
158 std::vector<std::string> GetDistinctHosts();
[email protected]0df165f2010-09-28 16:49:40159
[email protected]867a73e12010-03-19 20:45:46160 bool apps_enabled() const { return apps_enabled_; }
161 void set_apps_enabled(bool val) { apps_enabled_ = val; }
162
[email protected]c3e3def742009-07-17 07:51:06163 // Icon sizes used by the extension system.
[email protected]d2817012009-08-04 06:46:21164 static const int kIconSizes[];
[email protected]c3e3def742009-07-17 07:51:06165
[email protected]4c4f8192009-10-17 01:03:26166 // Max size (both dimensions) for browser and page actions.
167 static const int kPageActionIconMaxSize;
168 static const int kBrowserActionIconMaxSize;
169
[email protected]35506352009-08-07 18:58:19170 // Each permission is a module that the extension is permitted to use.
[email protected]218990c2010-06-26 01:21:07171 //
[email protected]0df165f2010-09-28 16:49:40172 // NOTE: To add a new permission, define it here, and add an entry to
173 // Extension::kPermissions.
[email protected]9dcf8f12010-09-02 20:39:19174 static const char kBackgroundPermission[];
175 static const char kBookmarkPermission[];
176 static const char kContextMenusPermission[];
177 static const char kCookiePermission[];
178 static const char kExperimentalPermission[];
179 static const char kGeolocationPermission[];
180 static const char kHistoryPermission[];
181 static const char kIdlePermission[];
182 static const char kNotificationPermission[];
183 static const char kProxyPermission[];
184 static const char kTabPermission[];
185 static const char kUnlimitedStoragePermission[];
[email protected]9dcf8f12010-09-02 20:39:19186 static const char kWebstorePrivatePermission[];
[email protected]aeb53b32009-10-29 07:34:45187
[email protected]0df165f2010-09-28 16:49:40188 static const Permission kPermissions[];
[email protected]35506352009-08-07 18:58:19189 static const size_t kNumPermissions;
[email protected]9dcf8f12010-09-02 20:39:19190 static const char* const kHostedAppPermissionNames[];
[email protected]b746f372010-08-29 21:39:32191 static const size_t kNumHostedAppPermissions;
[email protected]35506352009-08-07 18:58:19192
[email protected]03b612f2010-08-13 21:09:21193 // The old name for the unlimited storage permission, which is deprecated but
194 // still accepted as meaning the same thing as kUnlimitedStoragePermission.
[email protected]9dcf8f12010-09-02 20:39:19195 static const char kOldUnlimitedStoragePermission[];
[email protected]03b612f2010-08-13 21:09:21196
[email protected]b746f372010-08-29 21:39:32197 // Returns true if the string is one of the known hosted app permissions (see
198 // kHostedAppPermissionNames).
199 static bool IsHostedAppPermission(const std::string& permission);
200
[email protected]c533bb22009-06-03 19:06:11201 // An NPAPI plugin included in the extension.
202 struct PluginInfo {
203 FilePath path; // Path to the plugin.
204 bool is_public; // False if only this extension can load this plugin.
205 };
206
[email protected]6014d672008-12-05 00:38:25207 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16208 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25209
[email protected]300cc58db2009-08-19 20:45:14210 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16211 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14212
213 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16214 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14215
[email protected]25b34332009-06-05 21:53:19216#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19217 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19218#endif
219
[email protected]37eeb5a2009-02-26 23:36:17220 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48221 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17222
[email protected]e435d6b72009-07-25 03:15:58223 // The mimetype used for extensions.
224 static const char kMimeType[];
225
[email protected]631cf822009-05-15 07:01:25226 explicit Extension(const FilePath& path);
[email protected]631cf822009-05-15 07:01:25227 virtual ~Extension();
228
[email protected]25b34332009-06-05 21:53:19229 // Checks to see if the extension has a valid ID.
230 static bool IdIsValid(const std::string& id);
231
[email protected]e435d6b72009-07-25 03:15:58232 // Returns true if the specified file is an extension.
233 static bool IsExtension(const FilePath& file_name);
234
[email protected]25b34332009-06-05 21:53:19235 // Whether the |location| is external or not.
236 static inline bool IsExternalLocation(Location location) {
237 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32238 location == Extension::EXTERNAL_REGISTRY ||
239 location == Extension::EXTERNAL_PREF_DOWNLOAD;
[email protected]25b34332009-06-05 21:53:19240 }
241
[email protected]07c00d992009-03-04 20:27:04242 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59243 // |extension_url| argument should be the url() from an Extension object. The
244 // |relative_path| can be untrusted user input. The returned URL will either
245 // be invalid() or a child of |extension_url|.
246 // NOTE: Static so that it can be used from multiple threads.
247 static GURL GetResourceURL(const GURL& extension_url,
248 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28249 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24250 return GetResourceURL(url(), relative_path);
251 }
[email protected]eab9b452009-01-23 20:48:59252
[email protected]99efb7b12009-12-18 02:39:16253 // Returns an extension resource object. |relative_path| should be UTF8
254 // encoded.
255 ExtensionResource GetResource(const std::string& relative_path);
256
257 // As above, but with |relative_path| following the file system's encoding.
258 ExtensionResource GetResource(const FilePath& relative_path);
[email protected]eab9b452009-01-23 20:48:59259
[email protected]a17f9462009-06-09 02:56:41260 // |input| is expected to be the text of an rsa public or private key. It
261 // tolerates the presence or absence of bracking header/footer like this:
262 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
263 // and may contain newlines.
264 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
265
266 // Does a simple base64 encoding of |input| into |output|.
267 static bool ProducePEM(const std::string& input, std::string* output);
268
[email protected]84ac7f32009-10-06 06:17:54269 // Generates an extension ID from arbitrary input. The same input string will
270 // always generate the same output ID.
271 static bool GenerateId(const std::string& input, std::string* output);
[email protected]fbcc40302009-06-12 20:45:45272
[email protected]a17f9462009-06-09 02:56:41273 // Expects base64 encoded |input| and formats into |output| including
274 // the appropriate header & footer.
275 static bool FormatPEMForFileOutput(const std::string input,
276 std::string* output, bool is_public);
277
[email protected]2a409532009-08-28 19:39:44278 // Determine whether |new_extension| has increased privileges compared to
279 // |old_extension|.
280 static bool IsPrivilegeIncrease(Extension* old_extension,
281 Extension* new_extension);
[email protected]b24d8312009-08-27 06:47:46282
[email protected]c690a9812009-12-17 05:55:32283 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23284 // result. In the browser process, this will DCHECK if not called on the
285 // file thread. To easily load extension images on the UI thread, see
286 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32287 static void DecodeIcon(Extension* extension,
288 Icons icon_size,
289 scoped_ptr<SkBitmap>* result);
290
291 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23292 // result. In the browser process, this will DCHECK if not called on the
293 // file thread. To easily load extension images on the UI thread, see
294 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32295 static void DecodeIconFromPath(const FilePath& icon_path,
296 Icons icon_size,
297 scoped_ptr<SkBitmap>* result);
298
[email protected]a807bbe2010-04-14 10:51:19299 // Returns the base extension url for a given |extension_id|.
300 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
301
[email protected]596c6aa2010-05-25 15:56:26302 // Returns whether the browser has apps enabled (either as the default or if
[email protected]ce3eb7b62010-09-14 13:57:44303 // it was explicitly turned on via a command line switch).
[email protected]596c6aa2010-05-25 15:56:26304 static bool AppsAreEnabled();
305
[email protected]a0cf04a2010-06-23 03:29:55306 // Returns the url prefix for the extension/apps gallery. Can be set via the
[email protected]ce3eb7b62010-09-14 13:57:44307 // --apps-gallery-url switch. The URL returned will not contain a trailing
308 // slash.
[email protected]a0cf04a2010-06-23 03:29:55309 static std::string ChromeStoreURL();
310
[email protected]4a8d3272009-03-10 19:15:08311 // Initialize the extension from a parsed manifest.
[email protected]1952c7d2010-03-04 23:48:34312 // Usually, the id of an extension is generated by the "key" property of
313 // its manifest, but if |require_key| is |false|, a temporary ID will be
314 // generated based on the path.
315 bool InitFromValue(const DictionaryValue& value, bool require_key,
[email protected]5bfb1eb0a2009-04-08 18:33:30316 std::string* error);
[email protected]4a8d3272009-03-10 19:15:08317
[email protected]4361c7c2010-09-30 21:57:53318 const StaticData* static_data() const { return static_data_; }
319
320 const FilePath& path() const { return static_data_->path; }
[email protected]5bfb1eb0a2009-04-08 18:33:30321 const GURL& url() const { return extension_url_; }
[email protected]225c8f52010-02-05 22:23:20322 Location location() const { return location_; }
[email protected]631cf822009-05-15 07:01:25323 void set_location(Location location) { location_ = location; }
[email protected]4361c7c2010-09-30 21:57:53324 const std::string& id() const { return static_data_->id; }
[email protected]4a8d3272009-03-10 19:15:08325 const Version* version() const { return version_.get(); }
326 // String representation of the version number.
327 const std::string VersionString() const;
[email protected]4361c7c2010-09-30 21:57:53328 const std::string& name() const { return static_data_->name; }
[email protected]fbcc40302009-06-12 20:45:45329 const std::string& public_key() const { return public_key_; }
[email protected]4a8d3272009-03-10 19:15:08330 const std::string& description() const { return description_; }
[email protected]6657afa62009-11-04 02:15:20331 bool converted_from_user_script() const {
332 return converted_from_user_script_;
333 }
[email protected]4a8d3272009-03-10 19:15:08334 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]5d246db22009-10-27 06:17:57335 ExtensionAction* page_action() const { return page_action_.get(); }
336 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]c533bb22009-06-03 19:06:11337 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]c64631652009-04-29 22:24:31338 const GURL& background_url() const { return background_url_; }
[email protected]43919ac92009-10-16 18:34:28339 const GURL& options_url() const { return options_url_; }
[email protected]c0821052010-08-06 11:44:57340 const GURL& devtools_url() const { return devtools_url_; }
[email protected]6d7a6042010-08-12 20:12:42341 const std::vector<GURL>& toolstrips() const { return toolstrips_; }
[email protected]0df165f2010-09-28 16:49:40342 const std::set<std::string>& api_permissions() const {
[email protected]4361c7c2010-09-30 21:57:53343 return static_data_->api_permissions;
[email protected]35506352009-08-07 18:58:19344 }
[email protected]b30e0dd2010-01-29 23:33:21345 const URLPatternList& host_permissions() const {
[email protected]c7ad50f2009-09-11 06:28:15346 return host_permissions_;
347 }
348
[email protected]aeb53b32009-10-29 07:34:45349 // Returns true if the extension has the specified API permission.
[email protected]0df165f2010-09-28 16:49:40350 static bool HasApiPermission(const std::set<std::string>& api_permissions,
[email protected]246c05f2010-09-10 09:12:11351 const std::string& function_name);
[email protected]583d45c12010-08-31 02:48:12352
[email protected]246c05f2010-09-10 09:12:11353 bool HasApiPermission(const std::string& function_name) const {
354 return HasApiPermission(this->api_permissions(), function_name);
[email protected]aeb53b32009-10-29 07:34:45355 }
356
[email protected]4361c7c2010-09-30 21:57:53357 const ExtensionExtent& GetEffectiveHostPermissions() const {
358 return static_data_->effective_host_permissions;
359 }
[email protected]b24d8312009-08-27 06:47:46360
[email protected]fbd17cf2010-04-28 23:52:56361 // Whether or not the extension is allowed permission for a URL pattern from
362 // the manifest. http, https, and chrome://favicon/ is allowed for all
363 // extensions, while component extensions are allowed access to
364 // chrome://resources.
365 bool CanAccessURL(const URLPattern pattern) const;
366
[email protected]584b8e3f2010-04-10 00:23:37367 // Whether the extension has access to the given URL.
368 bool HasHostPermission(const GURL& url) const;
369
[email protected]0df165f2010-09-28 16:49:40370 // Whether the extension has effective access to all hosts. This is true if
371 // there is a content script that matches all hosts, if there is a host
372 // permission grants access to all hosts (like <all_urls>) or an api
373 // permission that effectively grants access to all hosts (e.g. proxy,
374 // network, etc.)
375 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46376
[email protected]b29682ba22009-06-18 19:53:56377 const GURL& update_url() const { return update_url_; }
[email protected]807871f2010-09-16 01:04:48378
[email protected]4361c7c2010-09-30 21:57:53379 const ExtensionIconSet& icons() const { return static_data_->icons; }
[email protected]4a8d3272009-03-10 19:15:08380
[email protected]bfa90a3a2010-04-28 15:43:23381 // Returns the Google Gallery URL for this extension, if one exists. For
382 // third-party extensions, this returns a blank GURL.
383 GURL GalleryUrl() const;
384
[email protected]25b34332009-06-05 21:53:19385 // Theme-related.
[email protected]631cf822009-05-15 07:01:25386 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
387 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
388 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
[email protected]7895ea22009-06-02 20:53:50389 DictionaryValue* GetThemeDisplayProperties() const {
390 return theme_display_properties_.get();
391 }
[email protected]3ba0fd32010-06-19 05:39:10392 bool is_theme() const { return is_theme_; }
[email protected]631cf822009-05-15 07:01:25393
[email protected]facd7a7652009-06-05 23:15:02394 // Returns a list of paths (relative to the extension dir) for images that
395 // the browser might load (like themes and page action icons).
396 std::set<FilePath> GetBrowserImages();
397
[email protected]807871f2010-09-16 01:04:48398 // Get an extension icon as a resource or URL.
399 ExtensionResource GetIconResource(int size,
400 ExtensionIconSet::MatchType match_type);
401 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type);
[email protected]f34e79632010-03-17 02:34:08402
[email protected]b6ab96d2009-08-20 18:58:19403 const DictionaryValue* manifest_value() const {
404 return manifest_value_.get();
405 }
406
[email protected]4361c7c2010-09-30 21:57:53407 const std::string default_locale() const {
408 return static_data_->default_locale;
409 }
[email protected]9428edc2009-11-18 18:02:47410
[email protected]86c008e82009-08-28 20:26:05411 // Chrome URL overrides (see ExtensionOverrideUI).
[email protected]d3cfa482009-10-17 13:54:57412 const URLOverrideMap& GetChromeURLOverrides() const {
413 return chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05414 }
415
[email protected]56ad3792010-05-28 17:45:33416 const std::string omnibox_keyword() const { return omnibox_keyword_; }
417
[email protected]3ba0fd32010-06-19 05:39:10418 bool is_app() const { return is_app_; }
[email protected]4361c7c2010-09-30 21:57:53419 const ExtensionExtent& web_extent() const { return static_data_->extent; }
[email protected]867a73e12010-03-19 20:45:46420 const std::string& launch_local_path() const { return launch_local_path_; }
421 const std::string& launch_web_url() const { return launch_web_url_; }
[email protected]fe13bf62010-08-26 14:33:19422 void set_launch_web_url(const std::string& launch_web_url) {
423 launch_web_url_ = launch_web_url;
424 }
[email protected]d83a5602010-09-16 00:22:48425 extension_misc::LaunchContainer launch_container() const {
426 return launch_container_;
427 }
[email protected]605cfad2010-06-22 20:49:35428 int launch_width() const { return launch_width_; }
429 int launch_height() const { return launch_height_; }
[email protected]4361c7c2010-09-30 21:57:53430 bool incognito_split_mode() const {
431 return static_data_->incognito_split_mode;
432 }
[email protected]867a73e12010-03-19 20:45:46433
434 // Gets the fully resolved absolute launch URL.
435 GURL GetFullLaunchURL() const;
[email protected]ceefd3d2010-03-12 09:10:29436
[email protected]e95ad332009-08-03 19:44:25437 // Runtime data:
438 // Put dynamic data about the state of a running extension below.
439
440 // Whether the background page, if any, is ready. We don't load other
441 // components until then. If there is no background page, we consider it to
442 // be ready.
443 bool GetBackgroundPageReady();
444 void SetBackgroundPageReady();
445
[email protected]1e8c93f2010-02-08 22:58:31446 // Getter and setter for the flag that specifies whether the extension is
447 // being upgraded.
448 bool being_upgraded() const { return being_upgraded_; }
449 void set_being_upgraded(bool value) { being_upgraded_ = value; }
450
[email protected]d9ad80f2010-03-30 20:40:18451 // Image cache related methods. These are only valid on the UI thread and
[email protected]052c92702010-06-25 07:25:52452 // not maintained by this class. See ImageLoadingTracker for usage. The
453 // |original_size| parameter should be the size of the image at |source|
454 // before any scaling may have been done to produce the pixels in |image|.
[email protected]d9ad80f2010-03-30 20:40:18455 void SetCachedImage(const ExtensionResource& source,
[email protected]052c92702010-06-25 07:25:52456 const SkBitmap& image,
457 const gfx::Size& original_size);
458 bool HasCachedImage(const ExtensionResource& source,
459 const gfx::Size& max_size);
460 SkBitmap GetCachedImage(const ExtensionResource& source,
461 const gfx::Size& max_size);
[email protected]4361c7c2010-09-30 21:57:53462 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); }
463 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); }
464
[email protected]4a8d3272009-03-10 19:15:08465 private:
[email protected]052c92702010-06-25 07:25:52466 // We keep a cache of images loaded from extension resources based on their
467 // path and a string representation of a size that may have been used to
468 // scale it (or the empty string if the image is at its original size).
469 typedef std::pair<FilePath, std::string> ImageCacheKey;
470 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
471
472 // Helper function for implementing HasCachedImage/GetCachedImage. A return
473 // value of NULL means there is no matching image cached (we allow caching an
474 // empty SkBitmap).
475 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
476 const gfx::Size& max_size);
[email protected]d9ad80f2010-03-30 20:40:18477
[email protected]3cfbd0e2009-03-18 21:26:24478 // Helper method that loads a UserScript object from a
479 // dictionary in the content_script list of the manifest.
480 bool LoadUserScriptHelper(const DictionaryValue* content_script,
481 int definition_index,
482 std::string* error,
483 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34484
[email protected]6657afa62009-11-04 02:15:20485 // Helper method that loads either the include_globs or exclude_globs list
486 // from an entry in the content_script lists of the manifest.
487 bool LoadGlobsHelper(const DictionaryValue* content_script,
488 int content_script_index,
[email protected]e2194742010-08-12 05:54:34489 const char* globs_property_name,
[email protected]6657afa62009-11-04 02:15:20490 std::string* error,
[email protected]11f4857282009-11-13 19:56:17491 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20492 UserScript *instance);
493
[email protected]867a73e12010-03-19 20:45:46494 // Helpers to load various chunks of the manifest.
[email protected]3ba0fd32010-06-19 05:39:10495 bool LoadIsApp(const DictionaryValue* manifest, std::string* error);
[email protected]e2194742010-08-12 05:54:34496 bool LoadExtent(const DictionaryValue* manifest, const char* key,
[email protected]4fdbc1492010-07-01 01:20:59497 ExtensionExtent* extent, const char* list_error,
498 const char* value_error, std::string* error);
[email protected]867a73e12010-03-19 20:45:46499 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46500 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error);
[email protected]cbf4d1912010-08-12 18:24:57501 bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46502
[email protected]5d246db22009-10-27 06:17:57503 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08504 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57505 ExtensionAction* LoadExtensionActionHelper(
[email protected]92c6f9b92009-10-24 04:35:08506 const DictionaryValue* extension_action, std::string* error);
507
[email protected]4361c7c2010-09-30 21:57:53508 // Calculates the effective host permissions from the permissions and content
509 // script petterns.
510 void InitEffectiveHostPermissions();
511
[email protected]e2eb43112009-05-29 21:19:54512 // Figures out if a source contains keys not associated with themes - we
513 // don't want to allow scripts and such to be bundled with themes.
514 bool ContainsNonThemeKeys(const DictionaryValue& source);
515
[email protected]1952c7d2010-03-04 23:48:34516 // Returns true if the string is one of the known api permissions (see
[email protected]0df165f2010-09-28 16:49:40517 // kPermissions).
[email protected]1952c7d2010-03-04 23:48:34518 bool IsAPIPermission(const std::string& permission);
519
[email protected]a2a098d2010-09-29 19:42:55520 // The set of unique API install messages that the extension has.
521 // NOTE: This only includes messages related to permissions declared in the
522 // "permissions" key in the manifest. Permissions implied from other features
523 // of the manifest, like plugins and content scripts are not included.
524 std::set<string16> GetSimplePermissionMessages();
525
526 // The permission message displayed related to the host permissions for
527 // this extension.
528 string16 GetHostPermissionMessage();
529
[email protected]4361c7c2010-09-30 21:57:53530 // Collection of extension data that doesn't change doesn't change once an
531 // Extension object has been initialized. The mutable version is valid only
532 // until InitFromValue finishes, to ensure we don't accidentally modify it
533 // post-initialization.
534 StaticData* mutable_static_data_;
535 scoped_refptr<const StaticData> static_data_;
[email protected]4a8d3272009-03-10 19:15:08536
537 // The base extension url for the extension.
538 GURL extension_url_;
[email protected]eab9b452009-01-23 20:48:59539
[email protected]631cf822009-05-15 07:01:25540 // The location the extension was loaded from.
541 Location location_;
542
[email protected]64a02b802009-01-12 19:36:42543 // The extension's version.
[email protected]cc655912009-01-29 23:19:19544 scoped_ptr<Version> version_;
[email protected]64a02b802009-01-12 19:36:42545
[email protected]4a8d3272009-03-10 19:15:08546 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:23547 std::string description_;
[email protected]82891262008-12-24 00:21:26548
[email protected]6657afa62009-11-04 02:15:20549 // True if the extension was generated from a user script. (We show slightly
550 // different UI if so).
551 bool converted_from_user_script_;
552
[email protected]82891262008-12-24 00:21:26553 // Paths to the content scripts the extension contains.
[email protected]34aa8dc2009-02-19 07:03:05554 UserScriptList content_scripts_;
[email protected]7713d632008-12-02 07:52:33555
[email protected]37e960e2009-10-13 23:17:50556 // The extension's page action, if any.
[email protected]5d246db22009-10-27 06:17:57557 scoped_ptr<ExtensionAction> page_action_;
[email protected]671e6c1ce2009-09-26 03:18:46558
559 // The extension's browser action, if any.
[email protected]5d246db22009-10-27 06:17:57560 scoped_ptr<ExtensionAction> browser_action_;
[email protected]ec9ac0df2009-10-01 18:06:47561
[email protected]c533bb22009-06-03 19:06:11562 // Optional list of NPAPI plugins and associated properties.
563 std::vector<PluginInfo> plugins_;
[email protected]367230c52009-02-21 01:44:30564
[email protected]c64631652009-04-29 22:24:31565 // Optional URL to a master page of which a single instance should be always
566 // loaded in the background.
567 GURL background_url_;
568
[email protected]43919ac92009-10-16 18:34:28569 // Optional URL to a page for setting options/preferences.
570 GURL options_url_;
571
[email protected]c0821052010-08-06 11:44:57572 // Optional URL to a devtools extension page.
573 GURL devtools_url_;
574
[email protected]bbc945542009-07-26 00:11:42575 // Optional list of toolstrips_ and associated properties.
[email protected]6d7a6042010-08-12 20:12:42576 std::vector<GURL> toolstrips_;
[email protected]4a8d3272009-03-10 19:15:08577
[email protected]fbcc40302009-06-12 20:45:45578 // The public key ('key' in the manifest) used to sign the contents of the
579 // crx package ('signature' in the manifest)
580 std::string public_key_;
[email protected]cc655912009-01-29 23:19:19581
[email protected]07c00d992009-03-04 20:27:04582 // A map of resource id's to relative file paths.
[email protected]bbb436f2009-05-09 16:51:07583 scoped_ptr<DictionaryValue> theme_images_;
[email protected]4a190632009-05-09 01:07:42584
585 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07586 scoped_ptr<DictionaryValue> theme_colors_;
[email protected]4a190632009-05-09 01:07:42587
588 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07589 scoped_ptr<DictionaryValue> theme_tints_;
[email protected]4a190632009-05-09 01:07:42590
[email protected]7895ea22009-06-02 20:53:50591 // A map of display properties.
592 scoped_ptr<DictionaryValue> theme_display_properties_;
593
[email protected]4a190632009-05-09 01:07:42594 // Whether the extension is a theme - if it is, certain things are disabled.
595 bool is_theme_;
[email protected]07c00d992009-03-04 20:27:04596
[email protected]c64631652009-04-29 22:24:31597 // The sites this extension has permission to talk to (using XHR, etc).
[email protected]b30e0dd2010-01-29 23:33:21598 URLPatternList host_permissions_;
[email protected]7197f4992009-03-23 05:05:49599
[email protected]b29682ba22009-06-18 19:53:56600 // URL for fetching an update manifest
601 GURL update_url_;
[email protected]d6336a92009-08-13 17:25:12602
[email protected]b6ab96d2009-08-20 18:58:19603 // A copy of the manifest that this extension was created from.
604 scoped_ptr<DictionaryValue> manifest_value_;
605
[email protected]86c008e82009-08-28 20:26:05606 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
607 // which override the handling of those URLs.
[email protected]d3cfa482009-10-17 13:54:57608 URLOverrideMap chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05609
[email protected]867a73e12010-03-19 20:45:46610 // Whether apps-related features can be parsed during InitFromValue().
611 // Defaults to the value from --enable-extension-apps.
612 bool apps_enabled_;
[email protected]581b0ad2010-01-12 21:54:38613
[email protected]3ba0fd32010-06-19 05:39:10614 // Whether this extension uses app features.
615 bool is_app_;
[email protected]3b355642010-02-05 16:01:49616
[email protected]867a73e12010-03-19 20:45:46617 // The local path inside the extension to use with the launcher.
618 std::string launch_local_path_;
619
620 // A web url to use with the launcher. Note that this might be relative or
621 // absolute. If relative, it is relative to web_origin_.
622 std::string launch_web_url_;
623
624 // The type of container to launch into.
[email protected]d83a5602010-09-16 00:22:48625 extension_misc::LaunchContainer launch_container_;
[email protected]867a73e12010-03-19 20:45:46626
[email protected]605cfad2010-06-22 20:49:35627 // The default size of the container when launching. Only respected for
628 // containers like panels and windows.
629 int launch_width_;
630 int launch_height_;
631
[email protected]052c92702010-06-25 07:25:52632 // Cached images for this extension.
[email protected]d9ad80f2010-03-30 20:40:18633 ImageCache image_cache_;
[email protected]ceefd3d2010-03-12 09:10:29634
[email protected]56ad3792010-05-28 17:45:33635 // The omnibox keyword for this extension, or empty if there is none.
636 std::string omnibox_keyword_;
637
[email protected]e95ad332009-08-03 19:44:25638 // Runtime data:
639
640 // True if the background page is ready.
641 bool background_page_ready_;
[email protected]b29682ba22009-06-18 19:53:56642
[email protected]1e8c93f2010-02-08 22:58:31643 // True while the extension is being upgraded.
644 bool being_upgraded_;
645
[email protected]19118d52010-07-26 22:13:42646 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
647 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58648
[email protected]894bb502009-05-21 22:39:57649 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33650};
651
[email protected]b1748b1d82009-11-30 20:32:56652typedef std::vector<Extension*> ExtensionList;
653
[email protected]c6d474f82009-12-16 21:11:06654// Handy struct to pass core extension info around.
655struct ExtensionInfo {
656 ExtensionInfo(const DictionaryValue* manifest,
657 const std::string& id,
658 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:46659 Extension::Location location);
660 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06661
662 scoped_ptr<DictionaryValue> extension_manifest;
663 std::string extension_id;
664 FilePath extension_path;
665 Extension::Location extension_location;
666
667 private:
668 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
669};
670
[email protected]211030342010-09-30 18:41:06671// Struct used for the details of the EXTENSION_UNINSTALLED
672// notification.
673struct UninstalledExtensionInfo {
674 explicit UninstalledExtensionInfo(const Extension& extension);
[email protected]211030342010-09-30 18:41:06675
676 std::string extension_id;
677 std::set<std::string> extension_api_permissions;
[email protected]76c25112010-10-01 22:37:21678 // TODO(akalin): Once we have a unified ExtensionType, replace the
679 // below member variables with a member of that type.
680 bool is_theme;
681 bool is_app;
682 bool converted_from_user_script;
683 GURL update_url;
[email protected]211030342010-09-30 18:41:06684};
685
[email protected]5b1a0e22009-05-26 19:00:58686#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_