blob: 8190b3cd204b6fc6eca0c3a1c079e32cbec4772a [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]10fb1992010-10-08 09:00:1736 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b24d8312009-08-27 06:47:4637
[email protected]631cf822009-05-15 07:01:2538 // What an extension was loaded from.
[email protected]1952c7d2010-03-04 23:48:3439 // NOTE: These values are stored as integers in the preferences, so you
40 // really don't want to change any existing ones.
[email protected]631cf822009-05-15 07:01:2541 enum Location {
42 INVALID,
[email protected]25b34332009-06-05 21:53:1943 INTERNAL, // A crx file from the internal Extensions directory.
44 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
45 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
46 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3447 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3248 COMPONENT, // An integral component of Chrome itself, which
49 // happens to be implemented as an extension. We don't
50 // show these in the management UI.
51 EXTERNAL_PREF_DOWNLOAD // A crx file from an external directory (via
52 // prefs), installed from an update URL.
[email protected]25b34332009-06-05 21:53:1953 };
54
55 enum State {
[email protected]0c6da502009-08-14 22:32:3956 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1957 ENABLED,
58 KILLBIT, // Don't install/upgrade (applies to external extensions only).
[email protected]0c6da502009-08-14 22:32:3959
60 NUM_STATES
[email protected]631cf822009-05-15 07:01:2561 };
[email protected]7713d632008-12-02 07:52:3362
[email protected]fbcc40302009-06-12 20:45:4563 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3764 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4565 DOWNGRADE,
66 REINSTALL,
67 UPGRADE,
68 NEW_INSTALL
69 };
70
[email protected]d2817012009-08-04 06:46:2171 // NOTE: If you change this list, you should also change kIconSizes in the cc
72 // file.
73 enum Icons {
74 EXTENSION_ICON_LARGE = 128,
75 EXTENSION_ICON_MEDIUM = 48,
76 EXTENSION_ICON_SMALL = 32,
[email protected]39382942010-03-23 15:57:0977 EXTENSION_ICON_SMALLISH = 24,
[email protected]d2817012009-08-04 06:46:2178 EXTENSION_ICON_BITTY = 16,
79 };
80
[email protected]4361c7c2010-09-30 21:57:5381 // Contains a subset of the extension's data that doesn't change once
82 // initialized, and therefore shareable across threads without locking.
83 struct StaticData : public base::RefCountedThreadSafe<StaticData> {
84 StaticData();
85
86 // TODO(mpcomplete): RefCountedThreadSafe does not allow AddRef/Release on
87 // const objects. I think that is a mistake. Until we can fix that, here's
88 // a workaround.
89 void AddRef() const {
90 const_cast<StaticData*>(this)->
91 base::RefCountedThreadSafe<StaticData>::AddRef();
92 }
93 void Release() const {
94 const_cast<StaticData*>(this)->
95 base::RefCountedThreadSafe<StaticData>::Release();
96 }
97
98 // A persistent, globally unique ID. An extension's ID is used in things
99 // like directory structures and URLs, and is expected to not change across
100 // versions. It is generated as a SHA-256 hash of the extension's public
101 // key, or as a hash of the path in the case of unpacked extensions.
102 std::string id;
103
104 // The extension's human-readable name. Name is used for display purpose. It
105 // might be wrapped with unicode bidi control characters so that it is
106 // displayed correctly in RTL context.
107 // NOTE: Name is UTF-8 and may contain non-ascii characters.
108 std::string name;
109
110 // The absolute path to the directory the extension is stored in.
111 FilePath path;
112
113 // Default locale for fall back. Can be empty if extension is not localized.
114 std::string default_locale;
115
116 // If true, a separate process will be used for the extension in incognito
117 // mode.
118 bool incognito_split_mode;
119
120 // Defines the set of URLs in the extension's web content.
121 ExtensionExtent extent;
122
123 // The set of hosts that the extension effectively has access to. This is
124 // used in the permissions UI and is a combination of the hosts accessible
125 // through content scripts and the hosts accessible through XHR.
126 ExtensionExtent effective_host_permissions;
127
128 // The set of module-level APIs this extension can use.
129 std::set<std::string> api_permissions;
130
131 // The icons for the extension.
132 ExtensionIconSet icons;
133
134 protected:
135 friend class base::RefCountedThreadSafe<StaticData>;
136 ~StaticData();
137 };
138
[email protected]0df165f2010-09-28 16:49:40139 // A permission is defined by its |name| (what is used in the manifest),
140 // and the |message_id| that's used by install/update UI.
141 struct Permission {
142 const char* const name;
143 const int message_id;
144 };
145
146 // The install message id for |permission|. Returns 0 if none exists.
147 static int GetPermissionMessageId(const std::string& permission);
148
[email protected]a2a098d2010-09-29 19:42:55149 // Returns the full list of permission messages that this extension
150 // should display at install time.
151 std::vector<string16> GetPermissionMessages();
152
153 // Returns the distinct hosts that should be displayed in the install UI. This
154 // discards some of the detail that is present in the manifest to make it as
155 // easy as possible to process by users. In particular we disregard the scheme
156 // and path components of URLPatterns and de-dupe the result.
157 static std::vector<std::string> GetDistinctHosts(
158 const URLPatternList& host_patterns);
159 std::vector<std::string> GetDistinctHosts();
[email protected]0df165f2010-09-28 16:49:40160
[email protected]867a73e12010-03-19 20:45:46161 bool apps_enabled() const { return apps_enabled_; }
162 void set_apps_enabled(bool val) { apps_enabled_ = val; }
163
[email protected]c3e3def742009-07-17 07:51:06164 // Icon sizes used by the extension system.
[email protected]d2817012009-08-04 06:46:21165 static const int kIconSizes[];
[email protected]c3e3def742009-07-17 07:51:06166
[email protected]4c4f8192009-10-17 01:03:26167 // Max size (both dimensions) for browser and page actions.
168 static const int kPageActionIconMaxSize;
169 static const int kBrowserActionIconMaxSize;
170
[email protected]35506352009-08-07 18:58:19171 // Each permission is a module that the extension is permitted to use.
[email protected]218990c2010-06-26 01:21:07172 //
[email protected]0df165f2010-09-28 16:49:40173 // NOTE: To add a new permission, define it here, and add an entry to
174 // Extension::kPermissions.
[email protected]9dcf8f12010-09-02 20:39:19175 static const char kBackgroundPermission[];
176 static const char kBookmarkPermission[];
177 static const char kContextMenusPermission[];
178 static const char kCookiePermission[];
179 static const char kExperimentalPermission[];
180 static const char kGeolocationPermission[];
181 static const char kHistoryPermission[];
182 static const char kIdlePermission[];
[email protected]eb255772010-10-04 22:10:46183 static const char kManagementPermission[];
[email protected]9dcf8f12010-09-02 20:39:19184 static const char kNotificationPermission[];
185 static const char kProxyPermission[];
186 static const char kTabPermission[];
187 static const char kUnlimitedStoragePermission[];
[email protected]9dcf8f12010-09-02 20:39:19188 static const char kWebstorePrivatePermission[];
[email protected]aeb53b32009-10-29 07:34:45189
[email protected]0df165f2010-09-28 16:49:40190 static const Permission kPermissions[];
[email protected]35506352009-08-07 18:58:19191 static const size_t kNumPermissions;
[email protected]9dcf8f12010-09-02 20:39:19192 static const char* const kHostedAppPermissionNames[];
[email protected]b746f372010-08-29 21:39:32193 static const size_t kNumHostedAppPermissions;
[email protected]35506352009-08-07 18:58:19194
[email protected]03b612f2010-08-13 21:09:21195 // The old name for the unlimited storage permission, which is deprecated but
196 // still accepted as meaning the same thing as kUnlimitedStoragePermission.
[email protected]9dcf8f12010-09-02 20:39:19197 static const char kOldUnlimitedStoragePermission[];
[email protected]03b612f2010-08-13 21:09:21198
[email protected]b746f372010-08-29 21:39:32199 // Returns true if the string is one of the known hosted app permissions (see
200 // kHostedAppPermissionNames).
201 static bool IsHostedAppPermission(const std::string& permission);
202
[email protected]c533bb22009-06-03 19:06:11203 // An NPAPI plugin included in the extension.
204 struct PluginInfo {
205 FilePath path; // Path to the plugin.
206 bool is_public; // False if only this extension can load this plugin.
207 };
208
[email protected]6014d672008-12-05 00:38:25209 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16210 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25211
[email protected]300cc58db2009-08-19 20:45:14212 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16213 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14214
215 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16216 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14217
[email protected]25b34332009-06-05 21:53:19218#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19219 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19220#endif
221
[email protected]37eeb5a2009-02-26 23:36:17222 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48223 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17224
[email protected]e435d6b72009-07-25 03:15:58225 // The mimetype used for extensions.
226 static const char kMimeType[];
227
[email protected]631cf822009-05-15 07:01:25228 explicit Extension(const FilePath& path);
[email protected]631cf822009-05-15 07:01:25229 virtual ~Extension();
230
[email protected]25b34332009-06-05 21:53:19231 // Checks to see if the extension has a valid ID.
232 static bool IdIsValid(const std::string& id);
233
[email protected]e435d6b72009-07-25 03:15:58234 // Returns true if the specified file is an extension.
235 static bool IsExtension(const FilePath& file_name);
236
[email protected]25b34332009-06-05 21:53:19237 // Whether the |location| is external or not.
238 static inline bool IsExternalLocation(Location location) {
239 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32240 location == Extension::EXTERNAL_REGISTRY ||
241 location == Extension::EXTERNAL_PREF_DOWNLOAD;
[email protected]25b34332009-06-05 21:53:19242 }
243
[email protected]07c00d992009-03-04 20:27:04244 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59245 // |extension_url| argument should be the url() from an Extension object. The
246 // |relative_path| can be untrusted user input. The returned URL will either
247 // be invalid() or a child of |extension_url|.
248 // NOTE: Static so that it can be used from multiple threads.
249 static GURL GetResourceURL(const GURL& extension_url,
250 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28251 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24252 return GetResourceURL(url(), relative_path);
253 }
[email protected]eab9b452009-01-23 20:48:59254
[email protected]99efb7b12009-12-18 02:39:16255 // Returns an extension resource object. |relative_path| should be UTF8
256 // encoded.
257 ExtensionResource GetResource(const std::string& relative_path);
258
259 // As above, but with |relative_path| following the file system's encoding.
260 ExtensionResource GetResource(const FilePath& relative_path);
[email protected]eab9b452009-01-23 20:48:59261
[email protected]a17f9462009-06-09 02:56:41262 // |input| is expected to be the text of an rsa public or private key. It
263 // tolerates the presence or absence of bracking header/footer like this:
264 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
265 // and may contain newlines.
266 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
267
268 // Does a simple base64 encoding of |input| into |output|.
269 static bool ProducePEM(const std::string& input, std::string* output);
270
[email protected]84ac7f32009-10-06 06:17:54271 // Generates an extension ID from arbitrary input. The same input string will
272 // always generate the same output ID.
273 static bool GenerateId(const std::string& input, std::string* output);
[email protected]fbcc40302009-06-12 20:45:45274
[email protected]a17f9462009-06-09 02:56:41275 // Expects base64 encoded |input| and formats into |output| including
276 // the appropriate header & footer.
277 static bool FormatPEMForFileOutput(const std::string input,
278 std::string* output, bool is_public);
279
[email protected]2a409532009-08-28 19:39:44280 // Determine whether |new_extension| has increased privileges compared to
281 // |old_extension|.
282 static bool IsPrivilegeIncrease(Extension* old_extension,
283 Extension* new_extension);
[email protected]b24d8312009-08-27 06:47:46284
[email protected]c690a9812009-12-17 05:55:32285 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23286 // result. In the browser process, this will DCHECK if not called on the
287 // file thread. To easily load extension images on the UI thread, see
288 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32289 static void DecodeIcon(Extension* extension,
290 Icons icon_size,
291 scoped_ptr<SkBitmap>* result);
292
293 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23294 // result. In the browser process, this will DCHECK if not called on the
295 // file thread. To easily load extension images on the UI thread, see
296 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32297 static void DecodeIconFromPath(const FilePath& icon_path,
298 Icons icon_size,
299 scoped_ptr<SkBitmap>* result);
300
[email protected]a807bbe2010-04-14 10:51:19301 // Returns the base extension url for a given |extension_id|.
302 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
303
[email protected]596c6aa2010-05-25 15:56:26304 // Returns whether the browser has apps enabled (either as the default or if
[email protected]ce3eb7b62010-09-14 13:57:44305 // it was explicitly turned on via a command line switch).
[email protected]596c6aa2010-05-25 15:56:26306 static bool AppsAreEnabled();
307
[email protected]a0cf04a2010-06-23 03:29:55308 // Returns the url prefix for the extension/apps gallery. Can be set via the
[email protected]ce3eb7b62010-09-14 13:57:44309 // --apps-gallery-url switch. The URL returned will not contain a trailing
310 // slash.
[email protected]a0cf04a2010-06-23 03:29:55311 static std::string ChromeStoreURL();
312
[email protected]be7e5cb2010-10-04 12:53:17313 // Helper function that consolidates the check for whether the script can
314 // execute into one location. |page_url| is the page that is the candidate
315 // for running the script, |can_execute_script_everywhere| specifies whether
316 // the extension is on the whitelist, |allowed_pages| is a vector of
317 // URLPatterns, listing what access the extension has, |script| is the script
318 // pointer (if content script) and |error| is an optional parameter, which
319 // will receive the error string listing why access was denied.
320 static bool CanExecuteScriptOnPage(
321 const GURL& page_url,
322 bool can_execute_script_everywhere,
323 const std::vector<URLPattern>* allowed_pages,
324 UserScript* script,
325 std::string* error);
326
327 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17328 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]be7e5cb2010-10-04 12:53:17329
[email protected]4a8d3272009-03-10 19:15:08330 // Initialize the extension from a parsed manifest.
[email protected]1952c7d2010-03-04 23:48:34331 // Usually, the id of an extension is generated by the "key" property of
332 // its manifest, but if |require_key| is |false|, a temporary ID will be
333 // generated based on the path.
334 bool InitFromValue(const DictionaryValue& value, bool require_key,
[email protected]5bfb1eb0a2009-04-08 18:33:30335 std::string* error);
[email protected]4a8d3272009-03-10 19:15:08336
[email protected]4361c7c2010-09-30 21:57:53337 const StaticData* static_data() const { return static_data_; }
338
339 const FilePath& path() const { return static_data_->path; }
[email protected]5bfb1eb0a2009-04-08 18:33:30340 const GURL& url() const { return extension_url_; }
[email protected]225c8f52010-02-05 22:23:20341 Location location() const { return location_; }
[email protected]631cf822009-05-15 07:01:25342 void set_location(Location location) { location_ = location; }
[email protected]4361c7c2010-09-30 21:57:53343 const std::string& id() const { return static_data_->id; }
[email protected]4a8d3272009-03-10 19:15:08344 const Version* version() const { return version_.get(); }
345 // String representation of the version number.
346 const std::string VersionString() const;
[email protected]4361c7c2010-09-30 21:57:53347 const std::string& name() const { return static_data_->name; }
[email protected]fbcc40302009-06-12 20:45:45348 const std::string& public_key() const { return public_key_; }
[email protected]4a8d3272009-03-10 19:15:08349 const std::string& description() const { return description_; }
[email protected]6657afa62009-11-04 02:15:20350 bool converted_from_user_script() const {
351 return converted_from_user_script_;
352 }
[email protected]4a8d3272009-03-10 19:15:08353 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]5d246db22009-10-27 06:17:57354 ExtensionAction* page_action() const { return page_action_.get(); }
355 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]c533bb22009-06-03 19:06:11356 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]c64631652009-04-29 22:24:31357 const GURL& background_url() const { return background_url_; }
[email protected]43919ac92009-10-16 18:34:28358 const GURL& options_url() const { return options_url_; }
[email protected]c0821052010-08-06 11:44:57359 const GURL& devtools_url() const { return devtools_url_; }
[email protected]6d7a6042010-08-12 20:12:42360 const std::vector<GURL>& toolstrips() const { return toolstrips_; }
[email protected]0df165f2010-09-28 16:49:40361 const std::set<std::string>& api_permissions() const {
[email protected]4361c7c2010-09-30 21:57:53362 return static_data_->api_permissions;
[email protected]35506352009-08-07 18:58:19363 }
[email protected]b30e0dd2010-01-29 23:33:21364 const URLPatternList& host_permissions() const {
[email protected]c7ad50f2009-09-11 06:28:15365 return host_permissions_;
366 }
367
[email protected]aeb53b32009-10-29 07:34:45368 // Returns true if the extension has the specified API permission.
[email protected]0df165f2010-09-28 16:49:40369 static bool HasApiPermission(const std::set<std::string>& api_permissions,
[email protected]246c05f2010-09-10 09:12:11370 const std::string& function_name);
[email protected]583d45c12010-08-31 02:48:12371
[email protected]246c05f2010-09-10 09:12:11372 bool HasApiPermission(const std::string& function_name) const {
373 return HasApiPermission(this->api_permissions(), function_name);
[email protected]aeb53b32009-10-29 07:34:45374 }
375
[email protected]4361c7c2010-09-30 21:57:53376 const ExtensionExtent& GetEffectiveHostPermissions() const {
377 return static_data_->effective_host_permissions;
378 }
[email protected]b24d8312009-08-27 06:47:46379
[email protected]fbd17cf2010-04-28 23:52:56380 // Whether or not the extension is allowed permission for a URL pattern from
381 // the manifest. http, https, and chrome://favicon/ is allowed for all
382 // extensions, while component extensions are allowed access to
383 // chrome://resources.
[email protected]be7e5cb2010-10-04 12:53:17384 bool CanSpecifyHostPermission(const URLPattern pattern) const;
[email protected]fbd17cf2010-04-28 23:52:56385
[email protected]584b8e3f2010-04-10 00:23:37386 // Whether the extension has access to the given URL.
387 bool HasHostPermission(const GURL& url) const;
388
[email protected]0df165f2010-09-28 16:49:40389 // Whether the extension has effective access to all hosts. This is true if
390 // there is a content script that matches all hosts, if there is a host
391 // permission grants access to all hosts (like <all_urls>) or an api
392 // permission that effectively grants access to all hosts (e.g. proxy,
393 // network, etc.)
394 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46395
[email protected]b29682ba22009-06-18 19:53:56396 const GURL& update_url() const { return update_url_; }
[email protected]807871f2010-09-16 01:04:48397
[email protected]4361c7c2010-09-30 21:57:53398 const ExtensionIconSet& icons() const { return static_data_->icons; }
[email protected]4a8d3272009-03-10 19:15:08399
[email protected]bfa90a3a2010-04-28 15:43:23400 // Returns the Google Gallery URL for this extension, if one exists. For
401 // third-party extensions, this returns a blank GURL.
402 GURL GalleryUrl() const;
403
[email protected]25b34332009-06-05 21:53:19404 // Theme-related.
[email protected]631cf822009-05-15 07:01:25405 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
406 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
407 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
[email protected]7895ea22009-06-02 20:53:50408 DictionaryValue* GetThemeDisplayProperties() const {
409 return theme_display_properties_.get();
410 }
[email protected]3ba0fd32010-06-19 05:39:10411 bool is_theme() const { return is_theme_; }
[email protected]631cf822009-05-15 07:01:25412
[email protected]facd7a7652009-06-05 23:15:02413 // Returns a list of paths (relative to the extension dir) for images that
414 // the browser might load (like themes and page action icons).
415 std::set<FilePath> GetBrowserImages();
416
[email protected]807871f2010-09-16 01:04:48417 // Get an extension icon as a resource or URL.
418 ExtensionResource GetIconResource(int size,
419 ExtensionIconSet::MatchType match_type);
420 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type);
[email protected]f34e79632010-03-17 02:34:08421
[email protected]b6ab96d2009-08-20 18:58:19422 const DictionaryValue* manifest_value() const {
423 return manifest_value_.get();
424 }
425
[email protected]4361c7c2010-09-30 21:57:53426 const std::string default_locale() const {
427 return static_data_->default_locale;
428 }
[email protected]9428edc2009-11-18 18:02:47429
[email protected]86c008e82009-08-28 20:26:05430 // Chrome URL overrides (see ExtensionOverrideUI).
[email protected]d3cfa482009-10-17 13:54:57431 const URLOverrideMap& GetChromeURLOverrides() const {
432 return chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05433 }
434
[email protected]56ad3792010-05-28 17:45:33435 const std::string omnibox_keyword() const { return omnibox_keyword_; }
436
[email protected]3ba0fd32010-06-19 05:39:10437 bool is_app() const { return is_app_; }
[email protected]4361c7c2010-09-30 21:57:53438 const ExtensionExtent& web_extent() const { return static_data_->extent; }
[email protected]867a73e12010-03-19 20:45:46439 const std::string& launch_local_path() const { return launch_local_path_; }
440 const std::string& launch_web_url() const { return launch_web_url_; }
[email protected]fe13bf62010-08-26 14:33:19441 void set_launch_web_url(const std::string& launch_web_url) {
442 launch_web_url_ = launch_web_url;
443 }
[email protected]d83a5602010-09-16 00:22:48444 extension_misc::LaunchContainer launch_container() const {
445 return launch_container_;
446 }
[email protected]605cfad2010-06-22 20:49:35447 int launch_width() const { return launch_width_; }
448 int launch_height() const { return launch_height_; }
[email protected]4361c7c2010-09-30 21:57:53449 bool incognito_split_mode() const {
450 return static_data_->incognito_split_mode;
451 }
[email protected]867a73e12010-03-19 20:45:46452
453 // Gets the fully resolved absolute launch URL.
454 GURL GetFullLaunchURL() const;
[email protected]ceefd3d2010-03-12 09:10:29455
[email protected]e95ad332009-08-03 19:44:25456 // Runtime data:
457 // Put dynamic data about the state of a running extension below.
458
459 // Whether the background page, if any, is ready. We don't load other
460 // components until then. If there is no background page, we consider it to
461 // be ready.
462 bool GetBackgroundPageReady();
463 void SetBackgroundPageReady();
464
[email protected]1e8c93f2010-02-08 22:58:31465 // Getter and setter for the flag that specifies whether the extension is
466 // being upgraded.
467 bool being_upgraded() const { return being_upgraded_; }
468 void set_being_upgraded(bool value) { being_upgraded_ = value; }
469
[email protected]d9ad80f2010-03-30 20:40:18470 // Image cache related methods. These are only valid on the UI thread and
[email protected]052c92702010-06-25 07:25:52471 // not maintained by this class. See ImageLoadingTracker for usage. The
472 // |original_size| parameter should be the size of the image at |source|
473 // before any scaling may have been done to produce the pixels in |image|.
[email protected]d9ad80f2010-03-30 20:40:18474 void SetCachedImage(const ExtensionResource& source,
[email protected]052c92702010-06-25 07:25:52475 const SkBitmap& image,
476 const gfx::Size& original_size);
477 bool HasCachedImage(const ExtensionResource& source,
478 const gfx::Size& max_size);
479 SkBitmap GetCachedImage(const ExtensionResource& source,
480 const gfx::Size& max_size);
[email protected]4361c7c2010-09-30 21:57:53481 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); }
482 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); }
483
[email protected]be7e5cb2010-10-04 12:53:17484 // Returns true if this extension is a COMPONENT extension, or if it is
485 // on the whitelist of extensions that can script all pages.
486 bool CanExecuteScriptEverywhere() const;
487
[email protected]4a8d3272009-03-10 19:15:08488 private:
[email protected]052c92702010-06-25 07:25:52489 // We keep a cache of images loaded from extension resources based on their
490 // path and a string representation of a size that may have been used to
491 // scale it (or the empty string if the image is at its original size).
492 typedef std::pair<FilePath, std::string> ImageCacheKey;
493 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
494
495 // Helper function for implementing HasCachedImage/GetCachedImage. A return
496 // value of NULL means there is no matching image cached (we allow caching an
497 // empty SkBitmap).
498 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
499 const gfx::Size& max_size);
[email protected]d9ad80f2010-03-30 20:40:18500
[email protected]3cfbd0e2009-03-18 21:26:24501 // Helper method that loads a UserScript object from a
502 // dictionary in the content_script list of the manifest.
503 bool LoadUserScriptHelper(const DictionaryValue* content_script,
504 int definition_index,
505 std::string* error,
506 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34507
[email protected]6657afa62009-11-04 02:15:20508 // Helper method that loads either the include_globs or exclude_globs list
509 // from an entry in the content_script lists of the manifest.
510 bool LoadGlobsHelper(const DictionaryValue* content_script,
511 int content_script_index,
[email protected]e2194742010-08-12 05:54:34512 const char* globs_property_name,
[email protected]6657afa62009-11-04 02:15:20513 std::string* error,
[email protected]11f4857282009-11-13 19:56:17514 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20515 UserScript *instance);
516
[email protected]867a73e12010-03-19 20:45:46517 // Helpers to load various chunks of the manifest.
[email protected]3ba0fd32010-06-19 05:39:10518 bool LoadIsApp(const DictionaryValue* manifest, std::string* error);
[email protected]e2194742010-08-12 05:54:34519 bool LoadExtent(const DictionaryValue* manifest, const char* key,
[email protected]4fdbc1492010-07-01 01:20:59520 ExtensionExtent* extent, const char* list_error,
521 const char* value_error, std::string* error);
[email protected]867a73e12010-03-19 20:45:46522 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
523 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error);
[email protected]cbf4d1912010-08-12 18:24:57524 bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46525
[email protected]5d246db22009-10-27 06:17:57526 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08527 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57528 ExtensionAction* LoadExtensionActionHelper(
[email protected]92c6f9b92009-10-24 04:35:08529 const DictionaryValue* extension_action, std::string* error);
530
[email protected]4361c7c2010-09-30 21:57:53531 // Calculates the effective host permissions from the permissions and content
532 // script petterns.
533 void InitEffectiveHostPermissions();
534
[email protected]e2eb43112009-05-29 21:19:54535 // Figures out if a source contains keys not associated with themes - we
536 // don't want to allow scripts and such to be bundled with themes.
537 bool ContainsNonThemeKeys(const DictionaryValue& source);
538
[email protected]1952c7d2010-03-04 23:48:34539 // Returns true if the string is one of the known api permissions (see
[email protected]0df165f2010-09-28 16:49:40540 // kPermissions).
[email protected]1952c7d2010-03-04 23:48:34541 bool IsAPIPermission(const std::string& permission);
542
[email protected]a2a098d2010-09-29 19:42:55543 // The set of unique API install messages that the extension has.
544 // NOTE: This only includes messages related to permissions declared in the
545 // "permissions" key in the manifest. Permissions implied from other features
546 // of the manifest, like plugins and content scripts are not included.
547 std::set<string16> GetSimplePermissionMessages();
548
549 // The permission message displayed related to the host permissions for
550 // this extension.
551 string16 GetHostPermissionMessage();
552
[email protected]4361c7c2010-09-30 21:57:53553 // Collection of extension data that doesn't change doesn't change once an
554 // Extension object has been initialized. The mutable version is valid only
555 // until InitFromValue finishes, to ensure we don't accidentally modify it
556 // post-initialization.
557 StaticData* mutable_static_data_;
558 scoped_refptr<const StaticData> static_data_;
[email protected]4a8d3272009-03-10 19:15:08559
560 // The base extension url for the extension.
561 GURL extension_url_;
[email protected]eab9b452009-01-23 20:48:59562
[email protected]631cf822009-05-15 07:01:25563 // The location the extension was loaded from.
564 Location location_;
565
[email protected]64a02b802009-01-12 19:36:42566 // The extension's version.
[email protected]cc655912009-01-29 23:19:19567 scoped_ptr<Version> version_;
[email protected]64a02b802009-01-12 19:36:42568
[email protected]4a8d3272009-03-10 19:15:08569 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:23570 std::string description_;
[email protected]82891262008-12-24 00:21:26571
[email protected]6657afa62009-11-04 02:15:20572 // True if the extension was generated from a user script. (We show slightly
573 // different UI if so).
574 bool converted_from_user_script_;
575
[email protected]82891262008-12-24 00:21:26576 // Paths to the content scripts the extension contains.
[email protected]34aa8dc2009-02-19 07:03:05577 UserScriptList content_scripts_;
[email protected]7713d632008-12-02 07:52:33578
[email protected]37e960e2009-10-13 23:17:50579 // The extension's page action, if any.
[email protected]5d246db22009-10-27 06:17:57580 scoped_ptr<ExtensionAction> page_action_;
[email protected]671e6c1ce2009-09-26 03:18:46581
582 // The extension's browser action, if any.
[email protected]5d246db22009-10-27 06:17:57583 scoped_ptr<ExtensionAction> browser_action_;
[email protected]ec9ac0df2009-10-01 18:06:47584
[email protected]c533bb22009-06-03 19:06:11585 // Optional list of NPAPI plugins and associated properties.
586 std::vector<PluginInfo> plugins_;
[email protected]367230c52009-02-21 01:44:30587
[email protected]c64631652009-04-29 22:24:31588 // Optional URL to a master page of which a single instance should be always
589 // loaded in the background.
590 GURL background_url_;
591
[email protected]43919ac92009-10-16 18:34:28592 // Optional URL to a page for setting options/preferences.
593 GURL options_url_;
594
[email protected]c0821052010-08-06 11:44:57595 // Optional URL to a devtools extension page.
596 GURL devtools_url_;
597
[email protected]bbc945542009-07-26 00:11:42598 // Optional list of toolstrips_ and associated properties.
[email protected]6d7a6042010-08-12 20:12:42599 std::vector<GURL> toolstrips_;
[email protected]4a8d3272009-03-10 19:15:08600
[email protected]fbcc40302009-06-12 20:45:45601 // The public key ('key' in the manifest) used to sign the contents of the
602 // crx package ('signature' in the manifest)
603 std::string public_key_;
[email protected]cc655912009-01-29 23:19:19604
[email protected]07c00d992009-03-04 20:27:04605 // A map of resource id's to relative file paths.
[email protected]bbb436f2009-05-09 16:51:07606 scoped_ptr<DictionaryValue> theme_images_;
[email protected]4a190632009-05-09 01:07:42607
608 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07609 scoped_ptr<DictionaryValue> theme_colors_;
[email protected]4a190632009-05-09 01:07:42610
611 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07612 scoped_ptr<DictionaryValue> theme_tints_;
[email protected]4a190632009-05-09 01:07:42613
[email protected]7895ea22009-06-02 20:53:50614 // A map of display properties.
615 scoped_ptr<DictionaryValue> theme_display_properties_;
616
[email protected]4a190632009-05-09 01:07:42617 // Whether the extension is a theme - if it is, certain things are disabled.
618 bool is_theme_;
[email protected]07c00d992009-03-04 20:27:04619
[email protected]c64631652009-04-29 22:24:31620 // The sites this extension has permission to talk to (using XHR, etc).
[email protected]b30e0dd2010-01-29 23:33:21621 URLPatternList host_permissions_;
[email protected]7197f4992009-03-23 05:05:49622
[email protected]b29682ba22009-06-18 19:53:56623 // URL for fetching an update manifest
624 GURL update_url_;
[email protected]d6336a92009-08-13 17:25:12625
[email protected]b6ab96d2009-08-20 18:58:19626 // A copy of the manifest that this extension was created from.
627 scoped_ptr<DictionaryValue> manifest_value_;
628
[email protected]86c008e82009-08-28 20:26:05629 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
630 // which override the handling of those URLs.
[email protected]d3cfa482009-10-17 13:54:57631 URLOverrideMap chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05632
[email protected]867a73e12010-03-19 20:45:46633 // Whether apps-related features can be parsed during InitFromValue().
634 // Defaults to the value from --enable-extension-apps.
635 bool apps_enabled_;
[email protected]581b0ad2010-01-12 21:54:38636
[email protected]3ba0fd32010-06-19 05:39:10637 // Whether this extension uses app features.
638 bool is_app_;
[email protected]3b355642010-02-05 16:01:49639
[email protected]867a73e12010-03-19 20:45:46640 // The local path inside the extension to use with the launcher.
641 std::string launch_local_path_;
642
643 // A web url to use with the launcher. Note that this might be relative or
644 // absolute. If relative, it is relative to web_origin_.
645 std::string launch_web_url_;
646
647 // The type of container to launch into.
[email protected]d83a5602010-09-16 00:22:48648 extension_misc::LaunchContainer launch_container_;
[email protected]867a73e12010-03-19 20:45:46649
[email protected]605cfad2010-06-22 20:49:35650 // The default size of the container when launching. Only respected for
651 // containers like panels and windows.
652 int launch_width_;
653 int launch_height_;
654
[email protected]052c92702010-06-25 07:25:52655 // Cached images for this extension.
[email protected]d9ad80f2010-03-30 20:40:18656 ImageCache image_cache_;
[email protected]ceefd3d2010-03-12 09:10:29657
[email protected]be7e5cb2010-10-04 12:53:17658 // The Omnibox keyword for this extension, or empty if there is none.
[email protected]56ad3792010-05-28 17:45:33659 std::string omnibox_keyword_;
660
[email protected]e95ad332009-08-03 19:44:25661 // Runtime data:
662
663 // True if the background page is ready.
664 bool background_page_ready_;
[email protected]b29682ba22009-06-18 19:53:56665
[email protected]1e8c93f2010-02-08 22:58:31666 // True while the extension is being upgraded.
667 bool being_upgraded_;
668
[email protected]19118d52010-07-26 22:13:42669 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
670 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58671
[email protected]894bb502009-05-21 22:39:57672 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33673};
674
[email protected]b1748b1d82009-11-30 20:32:56675typedef std::vector<Extension*> ExtensionList;
676
[email protected]c6d474f82009-12-16 21:11:06677// Handy struct to pass core extension info around.
678struct ExtensionInfo {
679 ExtensionInfo(const DictionaryValue* manifest,
680 const std::string& id,
681 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:46682 Extension::Location location);
683 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06684
685 scoped_ptr<DictionaryValue> extension_manifest;
686 std::string extension_id;
687 FilePath extension_path;
688 Extension::Location extension_location;
689
690 private:
691 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
692};
693
[email protected]211030342010-09-30 18:41:06694// Struct used for the details of the EXTENSION_UNINSTALLED
695// notification.
696struct UninstalledExtensionInfo {
697 explicit UninstalledExtensionInfo(const Extension& extension);
[email protected]9b2331d92010-10-04 23:11:19698 ~UninstalledExtensionInfo();
[email protected]211030342010-09-30 18:41:06699
700 std::string extension_id;
701 std::set<std::string> extension_api_permissions;
[email protected]76c25112010-10-01 22:37:21702 // TODO(akalin): Once we have a unified ExtensionType, replace the
703 // below member variables with a member of that type.
704 bool is_theme;
705 bool is_app;
706 bool converted_from_user_script;
707 GURL update_url;
[email protected]211030342010-09-30 18:41:06708};
709
[email protected]5b1a0e22009-05-26 19:00:58710#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_