blob: 030277168d3655054ff2d1e4e27da0f02194aa89 [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]9b217652010-10-08 22:04:2339 // NOTE: These values are stored as integers in the preferences and used
40 // in histograms so don't remove or reorder existing items. Just append
41 // to the end.
[email protected]631cf822009-05-15 07:01:2542 enum Location {
43 INVALID,
[email protected]25b34332009-06-05 21:53:1944 INTERNAL, // A crx file from the internal Extensions directory.
45 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
46 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
47 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3448 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3249 COMPONENT, // An integral component of Chrome itself, which
50 // happens to be implemented as an extension. We don't
51 // show these in the management UI.
52 EXTERNAL_PREF_DOWNLOAD // A crx file from an external directory (via
53 // prefs), installed from an update URL.
[email protected]25b34332009-06-05 21:53:1954 };
55
56 enum State {
[email protected]0c6da502009-08-14 22:32:3957 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1958 ENABLED,
59 KILLBIT, // Don't install/upgrade (applies to external extensions only).
[email protected]0c6da502009-08-14 22:32:3960
61 NUM_STATES
[email protected]631cf822009-05-15 07:01:2562 };
[email protected]7713d632008-12-02 07:52:3363
[email protected]fbcc40302009-06-12 20:45:4564 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3765 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4566 DOWNGRADE,
67 REINSTALL,
68 UPGRADE,
69 NEW_INSTALL
70 };
71
[email protected]d2817012009-08-04 06:46:2172 // NOTE: If you change this list, you should also change kIconSizes in the cc
73 // file.
74 enum Icons {
75 EXTENSION_ICON_LARGE = 128,
76 EXTENSION_ICON_MEDIUM = 48,
77 EXTENSION_ICON_SMALL = 32,
[email protected]39382942010-03-23 15:57:0978 EXTENSION_ICON_SMALLISH = 24,
[email protected]d2817012009-08-04 06:46:2179 EXTENSION_ICON_BITTY = 16,
80 };
81
[email protected]9b217652010-10-08 22:04:2382 // Type used for UMA_HISTOGRAM_ENUMERATION about extensions.
83 // Do not change the order of entries or remove entries in this list.
84 enum HistogramType {
85 TYPE_UNKNOWN = 0,
86 TYPE_EXTENSION,
87 TYPE_THEME,
88 TYPE_USER_SCRIPT,
89 TYPE_HOSTED_APP,
90 TYPE_PACKAGED_APP
91 };
92
[email protected]4361c7c2010-09-30 21:57:5393 // Contains a subset of the extension's data that doesn't change once
94 // initialized, and therefore shareable across threads without locking.
95 struct StaticData : public base::RefCountedThreadSafe<StaticData> {
96 StaticData();
97
98 // TODO(mpcomplete): RefCountedThreadSafe does not allow AddRef/Release on
99 // const objects. I think that is a mistake. Until we can fix that, here's
100 // a workaround.
101 void AddRef() const {
102 const_cast<StaticData*>(this)->
103 base::RefCountedThreadSafe<StaticData>::AddRef();
104 }
105 void Release() const {
106 const_cast<StaticData*>(this)->
107 base::RefCountedThreadSafe<StaticData>::Release();
108 }
109
110 // A persistent, globally unique ID. An extension's ID is used in things
111 // like directory structures and URLs, and is expected to not change across
112 // versions. It is generated as a SHA-256 hash of the extension's public
113 // key, or as a hash of the path in the case of unpacked extensions.
114 std::string id;
115
116 // The extension's human-readable name. Name is used for display purpose. It
117 // might be wrapped with unicode bidi control characters so that it is
118 // displayed correctly in RTL context.
119 // NOTE: Name is UTF-8 and may contain non-ascii characters.
120 std::string name;
121
122 // The absolute path to the directory the extension is stored in.
123 FilePath path;
124
125 // Default locale for fall back. Can be empty if extension is not localized.
126 std::string default_locale;
127
128 // If true, a separate process will be used for the extension in incognito
129 // mode.
130 bool incognito_split_mode;
131
132 // Defines the set of URLs in the extension's web content.
133 ExtensionExtent extent;
134
135 // The set of hosts that the extension effectively has access to. This is
136 // used in the permissions UI and is a combination of the hosts accessible
137 // through content scripts and the hosts accessible through XHR.
138 ExtensionExtent effective_host_permissions;
139
140 // The set of module-level APIs this extension can use.
141 std::set<std::string> api_permissions;
142
143 // The icons for the extension.
144 ExtensionIconSet icons;
145
146 protected:
147 friend class base::RefCountedThreadSafe<StaticData>;
148 ~StaticData();
149 };
150
[email protected]0df165f2010-09-28 16:49:40151 // A permission is defined by its |name| (what is used in the manifest),
152 // and the |message_id| that's used by install/update UI.
153 struct Permission {
154 const char* const name;
155 const int message_id;
156 };
157
158 // The install message id for |permission|. Returns 0 if none exists.
159 static int GetPermissionMessageId(const std::string& permission);
160
[email protected]a2a098d2010-09-29 19:42:55161 // Returns the full list of permission messages that this extension
162 // should display at install time.
163 std::vector<string16> GetPermissionMessages();
164
165 // Returns the distinct hosts that should be displayed in the install UI. This
166 // discards some of the detail that is present in the manifest to make it as
167 // easy as possible to process by users. In particular we disregard the scheme
168 // and path components of URLPatterns and de-dupe the result.
169 static std::vector<std::string> GetDistinctHosts(
170 const URLPatternList& host_patterns);
171 std::vector<std::string> GetDistinctHosts();
[email protected]0df165f2010-09-28 16:49:40172
[email protected]c3e3def742009-07-17 07:51:06173 // Icon sizes used by the extension system.
[email protected]d2817012009-08-04 06:46:21174 static const int kIconSizes[];
[email protected]c3e3def742009-07-17 07:51:06175
[email protected]4c4f8192009-10-17 01:03:26176 // Max size (both dimensions) for browser and page actions.
177 static const int kPageActionIconMaxSize;
178 static const int kBrowserActionIconMaxSize;
179
[email protected]35506352009-08-07 18:58:19180 // Each permission is a module that the extension is permitted to use.
[email protected]218990c2010-06-26 01:21:07181 //
[email protected]0df165f2010-09-28 16:49:40182 // NOTE: To add a new permission, define it here, and add an entry to
183 // Extension::kPermissions.
[email protected]9dcf8f12010-09-02 20:39:19184 static const char kBackgroundPermission[];
185 static const char kBookmarkPermission[];
186 static const char kContextMenusPermission[];
187 static const char kCookiePermission[];
188 static const char kExperimentalPermission[];
189 static const char kGeolocationPermission[];
190 static const char kHistoryPermission[];
191 static const char kIdlePermission[];
[email protected]eb255772010-10-04 22:10:46192 static const char kManagementPermission[];
[email protected]9dcf8f12010-09-02 20:39:19193 static const char kNotificationPermission[];
194 static const char kProxyPermission[];
195 static const char kTabPermission[];
196 static const char kUnlimitedStoragePermission[];
[email protected]9dcf8f12010-09-02 20:39:19197 static const char kWebstorePrivatePermission[];
[email protected]aeb53b32009-10-29 07:34:45198
[email protected]0df165f2010-09-28 16:49:40199 static const Permission kPermissions[];
[email protected]35506352009-08-07 18:58:19200 static const size_t kNumPermissions;
[email protected]9dcf8f12010-09-02 20:39:19201 static const char* const kHostedAppPermissionNames[];
[email protected]b746f372010-08-29 21:39:32202 static const size_t kNumHostedAppPermissions;
[email protected]35506352009-08-07 18:58:19203
[email protected]03b612f2010-08-13 21:09:21204 // The old name for the unlimited storage permission, which is deprecated but
205 // still accepted as meaning the same thing as kUnlimitedStoragePermission.
[email protected]9dcf8f12010-09-02 20:39:19206 static const char kOldUnlimitedStoragePermission[];
[email protected]03b612f2010-08-13 21:09:21207
[email protected]b746f372010-08-29 21:39:32208 // Returns true if the string is one of the known hosted app permissions (see
209 // kHostedAppPermissionNames).
210 static bool IsHostedAppPermission(const std::string& permission);
211
[email protected]c533bb22009-06-03 19:06:11212 // An NPAPI plugin included in the extension.
213 struct PluginInfo {
214 FilePath path; // Path to the plugin.
215 bool is_public; // False if only this extension can load this plugin.
216 };
217
[email protected]6014d672008-12-05 00:38:25218 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16219 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25220
[email protected]300cc58db2009-08-19 20:45:14221 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16222 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14223
224 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16225 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14226
[email protected]25b34332009-06-05 21:53:19227#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19228 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19229#endif
230
[email protected]37eeb5a2009-02-26 23:36:17231 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48232 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17233
[email protected]e435d6b72009-07-25 03:15:58234 // The mimetype used for extensions.
235 static const char kMimeType[];
236
[email protected]631cf822009-05-15 07:01:25237 explicit Extension(const FilePath& path);
[email protected]631cf822009-05-15 07:01:25238 virtual ~Extension();
239
[email protected]25b34332009-06-05 21:53:19240 // Checks to see if the extension has a valid ID.
241 static bool IdIsValid(const std::string& id);
242
[email protected]e435d6b72009-07-25 03:15:58243 // Returns true if the specified file is an extension.
244 static bool IsExtension(const FilePath& file_name);
245
[email protected]25b34332009-06-05 21:53:19246 // Whether the |location| is external or not.
247 static inline bool IsExternalLocation(Location location) {
248 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32249 location == Extension::EXTERNAL_REGISTRY ||
250 location == Extension::EXTERNAL_PREF_DOWNLOAD;
[email protected]25b34332009-06-05 21:53:19251 }
252
[email protected]9b217652010-10-08 22:04:23253 // See HistogramType definition above.
254 HistogramType GetHistogramType();
255
[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]99efb7b12009-12-18 02:39:16267 // Returns an extension resource object. |relative_path| should be UTF8
268 // encoded.
269 ExtensionResource GetResource(const std::string& relative_path);
270
271 // As above, but with |relative_path| following the file system's encoding.
272 ExtensionResource GetResource(const FilePath& relative_path);
[email protected]eab9b452009-01-23 20:48:59273
[email protected]a17f9462009-06-09 02:56:41274 // |input| is expected to be the text of an rsa public or private key. It
275 // tolerates the presence or absence of bracking header/footer like this:
276 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
277 // and may contain newlines.
278 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
279
280 // Does a simple base64 encoding of |input| into |output|.
281 static bool ProducePEM(const std::string& input, std::string* output);
282
[email protected]84ac7f32009-10-06 06:17:54283 // Generates an extension ID from arbitrary input. The same input string will
284 // always generate the same output ID.
285 static bool GenerateId(const std::string& input, std::string* output);
[email protected]fbcc40302009-06-12 20:45:45286
[email protected]a17f9462009-06-09 02:56:41287 // Expects base64 encoded |input| and formats into |output| including
288 // the appropriate header & footer.
289 static bool FormatPEMForFileOutput(const std::string input,
290 std::string* output, bool is_public);
291
[email protected]2a409532009-08-28 19:39:44292 // Determine whether |new_extension| has increased privileges compared to
293 // |old_extension|.
294 static bool IsPrivilegeIncrease(Extension* old_extension,
295 Extension* new_extension);
[email protected]b24d8312009-08-27 06:47:46296
[email protected]c690a9812009-12-17 05:55:32297 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23298 // result. In the browser process, this will DCHECK if not called on the
299 // file thread. To easily load extension images on the UI thread, see
300 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32301 static void DecodeIcon(Extension* extension,
302 Icons icon_size,
303 scoped_ptr<SkBitmap>* result);
304
305 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23306 // result. In the browser process, this will DCHECK if not called on the
307 // file thread. To easily load extension images on the UI thread, see
308 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32309 static void DecodeIconFromPath(const FilePath& icon_path,
310 Icons icon_size,
311 scoped_ptr<SkBitmap>* result);
312
[email protected]a807bbe2010-04-14 10:51:19313 // Returns the base extension url for a given |extension_id|.
314 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
315
[email protected]ec5b50d2010-10-09 16:35:18316 // Returns the url prefix for the extension/apps gallery. Can be set via the
[email protected]ce3eb7b62010-09-14 13:57:44317 // --apps-gallery-url switch. The URL returned will not contain a trailing
[email protected]d3071992010-10-08 15:24:07318 // slash. Do not use this as a prefix/extent for the store. Instead see
319 // ExtensionsService::GetWebStoreApp or
320 // ExtensionsService::IsDownloadFromGallery
321 static std::string ChromeStoreLaunchURL();
[email protected]a0cf04a2010-06-23 03:29:55322
[email protected]be7e5cb2010-10-04 12:53:17323 // Helper function that consolidates the check for whether the script can
324 // execute into one location. |page_url| is the page that is the candidate
325 // for running the script, |can_execute_script_everywhere| specifies whether
326 // the extension is on the whitelist, |allowed_pages| is a vector of
327 // URLPatterns, listing what access the extension has, |script| is the script
328 // pointer (if content script) and |error| is an optional parameter, which
329 // will receive the error string listing why access was denied.
330 static bool CanExecuteScriptOnPage(
331 const GURL& page_url,
332 bool can_execute_script_everywhere,
333 const std::vector<URLPattern>* allowed_pages,
334 UserScript* script,
335 std::string* error);
336
337 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17338 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]be7e5cb2010-10-04 12:53:17339
[email protected]4a8d3272009-03-10 19:15:08340 // Initialize the extension from a parsed manifest.
[email protected]1952c7d2010-03-04 23:48:34341 // Usually, the id of an extension is generated by the "key" property of
342 // its manifest, but if |require_key| is |false|, a temporary ID will be
343 // generated based on the path.
344 bool InitFromValue(const DictionaryValue& value, bool require_key,
[email protected]5bfb1eb0a2009-04-08 18:33:30345 std::string* error);
[email protected]4a8d3272009-03-10 19:15:08346
[email protected]4361c7c2010-09-30 21:57:53347 const StaticData* static_data() const { return static_data_; }
348
349 const FilePath& path() const { return static_data_->path; }
[email protected]5bfb1eb0a2009-04-08 18:33:30350 const GURL& url() const { return extension_url_; }
[email protected]225c8f52010-02-05 22:23:20351 Location location() const { return location_; }
[email protected]631cf822009-05-15 07:01:25352 void set_location(Location location) { location_ = location; }
[email protected]4361c7c2010-09-30 21:57:53353 const std::string& id() const { return static_data_->id; }
[email protected]4a8d3272009-03-10 19:15:08354 const Version* version() const { return version_.get(); }
355 // String representation of the version number.
356 const std::string VersionString() const;
[email protected]4361c7c2010-09-30 21:57:53357 const std::string& name() const { return static_data_->name; }
[email protected]fbcc40302009-06-12 20:45:45358 const std::string& public_key() const { return public_key_; }
[email protected]4a8d3272009-03-10 19:15:08359 const std::string& description() const { return description_; }
[email protected]6657afa62009-11-04 02:15:20360 bool converted_from_user_script() const {
361 return converted_from_user_script_;
362 }
[email protected]4a8d3272009-03-10 19:15:08363 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]5d246db22009-10-27 06:17:57364 ExtensionAction* page_action() const { return page_action_.get(); }
365 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]c533bb22009-06-03 19:06:11366 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]c64631652009-04-29 22:24:31367 const GURL& background_url() const { return background_url_; }
[email protected]43919ac92009-10-16 18:34:28368 const GURL& options_url() const { return options_url_; }
[email protected]c0821052010-08-06 11:44:57369 const GURL& devtools_url() const { return devtools_url_; }
[email protected]6d7a6042010-08-12 20:12:42370 const std::vector<GURL>& toolstrips() const { return toolstrips_; }
[email protected]0df165f2010-09-28 16:49:40371 const std::set<std::string>& api_permissions() const {
[email protected]4361c7c2010-09-30 21:57:53372 return static_data_->api_permissions;
[email protected]35506352009-08-07 18:58:19373 }
[email protected]b30e0dd2010-01-29 23:33:21374 const URLPatternList& host_permissions() const {
[email protected]c7ad50f2009-09-11 06:28:15375 return host_permissions_;
376 }
377
[email protected]aeb53b32009-10-29 07:34:45378 // Returns true if the extension has the specified API permission.
[email protected]0df165f2010-09-28 16:49:40379 static bool HasApiPermission(const std::set<std::string>& api_permissions,
[email protected]246c05f2010-09-10 09:12:11380 const std::string& function_name);
[email protected]583d45c12010-08-31 02:48:12381
[email protected]246c05f2010-09-10 09:12:11382 bool HasApiPermission(const std::string& function_name) const {
383 return HasApiPermission(this->api_permissions(), function_name);
[email protected]aeb53b32009-10-29 07:34:45384 }
385
[email protected]4361c7c2010-09-30 21:57:53386 const ExtensionExtent& GetEffectiveHostPermissions() const {
387 return static_data_->effective_host_permissions;
388 }
[email protected]b24d8312009-08-27 06:47:46389
[email protected]fbd17cf2010-04-28 23:52:56390 // Whether or not the extension is allowed permission for a URL pattern from
391 // the manifest. http, https, and chrome://favicon/ is allowed for all
392 // extensions, while component extensions are allowed access to
393 // chrome://resources.
[email protected]be7e5cb2010-10-04 12:53:17394 bool CanSpecifyHostPermission(const URLPattern pattern) const;
[email protected]fbd17cf2010-04-28 23:52:56395
[email protected]584b8e3f2010-04-10 00:23:37396 // Whether the extension has access to the given URL.
397 bool HasHostPermission(const GURL& url) const;
398
[email protected]0df165f2010-09-28 16:49:40399 // Whether the extension has effective access to all hosts. This is true if
400 // there is a content script that matches all hosts, if there is a host
401 // permission grants access to all hosts (like <all_urls>) or an api
402 // permission that effectively grants access to all hosts (e.g. proxy,
403 // network, etc.)
404 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46405
[email protected]b29682ba22009-06-18 19:53:56406 const GURL& update_url() const { return update_url_; }
[email protected]807871f2010-09-16 01:04:48407
[email protected]4361c7c2010-09-30 21:57:53408 const ExtensionIconSet& icons() const { return static_data_->icons; }
[email protected]4a8d3272009-03-10 19:15:08409
[email protected]bfa90a3a2010-04-28 15:43:23410 // Returns the Google Gallery URL for this extension, if one exists. For
411 // third-party extensions, this returns a blank GURL.
412 GURL GalleryUrl() const;
413
[email protected]25b34332009-06-05 21:53:19414 // Theme-related.
[email protected]631cf822009-05-15 07:01:25415 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
416 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
417 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
[email protected]7895ea22009-06-02 20:53:50418 DictionaryValue* GetThemeDisplayProperties() const {
419 return theme_display_properties_.get();
420 }
[email protected]3ba0fd32010-06-19 05:39:10421 bool is_theme() const { return is_theme_; }
[email protected]631cf822009-05-15 07:01:25422
[email protected]facd7a7652009-06-05 23:15:02423 // Returns a list of paths (relative to the extension dir) for images that
424 // the browser might load (like themes and page action icons).
425 std::set<FilePath> GetBrowserImages();
426
[email protected]807871f2010-09-16 01:04:48427 // Get an extension icon as a resource or URL.
428 ExtensionResource GetIconResource(int size,
429 ExtensionIconSet::MatchType match_type);
430 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type);
[email protected]f34e79632010-03-17 02:34:08431
[email protected]b6ab96d2009-08-20 18:58:19432 const DictionaryValue* manifest_value() const {
433 return manifest_value_.get();
434 }
435
[email protected]4361c7c2010-09-30 21:57:53436 const std::string default_locale() const {
437 return static_data_->default_locale;
438 }
[email protected]9428edc2009-11-18 18:02:47439
[email protected]86c008e82009-08-28 20:26:05440 // Chrome URL overrides (see ExtensionOverrideUI).
[email protected]d3cfa482009-10-17 13:54:57441 const URLOverrideMap& GetChromeURLOverrides() const {
442 return chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05443 }
444
[email protected]56ad3792010-05-28 17:45:33445 const std::string omnibox_keyword() const { return omnibox_keyword_; }
446
[email protected]3ba0fd32010-06-19 05:39:10447 bool is_app() const { return is_app_; }
[email protected]4361c7c2010-09-30 21:57:53448 const ExtensionExtent& web_extent() const { return static_data_->extent; }
[email protected]867a73e12010-03-19 20:45:46449 const std::string& launch_local_path() const { return launch_local_path_; }
450 const std::string& launch_web_url() const { return launch_web_url_; }
[email protected]fe13bf62010-08-26 14:33:19451 void set_launch_web_url(const std::string& launch_web_url) {
452 launch_web_url_ = launch_web_url;
453 }
[email protected]d83a5602010-09-16 00:22:48454 extension_misc::LaunchContainer launch_container() const {
455 return launch_container_;
456 }
[email protected]605cfad2010-06-22 20:49:35457 int launch_width() const { return launch_width_; }
458 int launch_height() const { return launch_height_; }
[email protected]4361c7c2010-09-30 21:57:53459 bool incognito_split_mode() const {
460 return static_data_->incognito_split_mode;
461 }
[email protected]867a73e12010-03-19 20:45:46462
463 // Gets the fully resolved absolute launch URL.
464 GURL GetFullLaunchURL() const;
[email protected]ceefd3d2010-03-12 09:10:29465
[email protected]e95ad332009-08-03 19:44:25466 // Runtime data:
467 // Put dynamic data about the state of a running extension below.
468
469 // Whether the background page, if any, is ready. We don't load other
470 // components until then. If there is no background page, we consider it to
471 // be ready.
472 bool GetBackgroundPageReady();
473 void SetBackgroundPageReady();
474
[email protected]1e8c93f2010-02-08 22:58:31475 // Getter and setter for the flag that specifies whether the extension is
476 // being upgraded.
477 bool being_upgraded() const { return being_upgraded_; }
478 void set_being_upgraded(bool value) { being_upgraded_ = value; }
479
[email protected]d9ad80f2010-03-30 20:40:18480 // Image cache related methods. These are only valid on the UI thread and
[email protected]052c92702010-06-25 07:25:52481 // not maintained by this class. See ImageLoadingTracker for usage. The
482 // |original_size| parameter should be the size of the image at |source|
483 // before any scaling may have been done to produce the pixels in |image|.
[email protected]d9ad80f2010-03-30 20:40:18484 void SetCachedImage(const ExtensionResource& source,
[email protected]052c92702010-06-25 07:25:52485 const SkBitmap& image,
486 const gfx::Size& original_size);
487 bool HasCachedImage(const ExtensionResource& source,
488 const gfx::Size& max_size);
489 SkBitmap GetCachedImage(const ExtensionResource& source,
490 const gfx::Size& max_size);
[email protected]4361c7c2010-09-30 21:57:53491 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); }
492 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); }
493
[email protected]be7e5cb2010-10-04 12:53:17494 // Returns true if this extension is a COMPONENT extension, or if it is
495 // on the whitelist of extensions that can script all pages.
496 bool CanExecuteScriptEverywhere() const;
497
[email protected]4a8d3272009-03-10 19:15:08498 private:
[email protected]052c92702010-06-25 07:25:52499 // We keep a cache of images loaded from extension resources based on their
500 // path and a string representation of a size that may have been used to
501 // scale it (or the empty string if the image is at its original size).
502 typedef std::pair<FilePath, std::string> ImageCacheKey;
503 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
504
505 // Helper function for implementing HasCachedImage/GetCachedImage. A return
506 // value of NULL means there is no matching image cached (we allow caching an
507 // empty SkBitmap).
508 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
509 const gfx::Size& max_size);
[email protected]d9ad80f2010-03-30 20:40:18510
[email protected]3cfbd0e2009-03-18 21:26:24511 // Helper method that loads a UserScript object from a
512 // dictionary in the content_script list of the manifest.
513 bool LoadUserScriptHelper(const DictionaryValue* content_script,
514 int definition_index,
515 std::string* error,
516 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34517
[email protected]6657afa62009-11-04 02:15:20518 // Helper method that loads either the include_globs or exclude_globs list
519 // from an entry in the content_script lists of the manifest.
520 bool LoadGlobsHelper(const DictionaryValue* content_script,
521 int content_script_index,
[email protected]e2194742010-08-12 05:54:34522 const char* globs_property_name,
[email protected]6657afa62009-11-04 02:15:20523 std::string* error,
[email protected]11f4857282009-11-13 19:56:17524 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20525 UserScript *instance);
526
[email protected]867a73e12010-03-19 20:45:46527 // Helpers to load various chunks of the manifest.
[email protected]3ba0fd32010-06-19 05:39:10528 bool LoadIsApp(const DictionaryValue* manifest, std::string* error);
[email protected]e2194742010-08-12 05:54:34529 bool LoadExtent(const DictionaryValue* manifest, const char* key,
[email protected]4fdbc1492010-07-01 01:20:59530 ExtensionExtent* extent, const char* list_error,
531 const char* value_error, std::string* error);
[email protected]867a73e12010-03-19 20:45:46532 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
533 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error);
[email protected]cbf4d1912010-08-12 18:24:57534 bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46535
[email protected]5d246db22009-10-27 06:17:57536 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08537 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57538 ExtensionAction* LoadExtensionActionHelper(
[email protected]92c6f9b92009-10-24 04:35:08539 const DictionaryValue* extension_action, std::string* error);
540
[email protected]4361c7c2010-09-30 21:57:53541 // Calculates the effective host permissions from the permissions and content
542 // script petterns.
543 void InitEffectiveHostPermissions();
544
[email protected]e2eb43112009-05-29 21:19:54545 // Figures out if a source contains keys not associated with themes - we
546 // don't want to allow scripts and such to be bundled with themes.
547 bool ContainsNonThemeKeys(const DictionaryValue& source);
548
[email protected]1952c7d2010-03-04 23:48:34549 // Returns true if the string is one of the known api permissions (see
[email protected]0df165f2010-09-28 16:49:40550 // kPermissions).
[email protected]1952c7d2010-03-04 23:48:34551 bool IsAPIPermission(const std::string& permission);
552
[email protected]a2a098d2010-09-29 19:42:55553 // The set of unique API install messages that the extension has.
554 // NOTE: This only includes messages related to permissions declared in the
555 // "permissions" key in the manifest. Permissions implied from other features
556 // of the manifest, like plugins and content scripts are not included.
557 std::set<string16> GetSimplePermissionMessages();
558
559 // The permission message displayed related to the host permissions for
560 // this extension.
561 string16 GetHostPermissionMessage();
562
[email protected]4361c7c2010-09-30 21:57:53563 // Collection of extension data that doesn't change doesn't change once an
564 // Extension object has been initialized. The mutable version is valid only
565 // until InitFromValue finishes, to ensure we don't accidentally modify it
566 // post-initialization.
567 StaticData* mutable_static_data_;
568 scoped_refptr<const StaticData> static_data_;
[email protected]4a8d3272009-03-10 19:15:08569
570 // The base extension url for the extension.
571 GURL extension_url_;
[email protected]eab9b452009-01-23 20:48:59572
[email protected]631cf822009-05-15 07:01:25573 // The location the extension was loaded from.
574 Location location_;
575
[email protected]64a02b802009-01-12 19:36:42576 // The extension's version.
[email protected]cc655912009-01-29 23:19:19577 scoped_ptr<Version> version_;
[email protected]64a02b802009-01-12 19:36:42578
[email protected]4a8d3272009-03-10 19:15:08579 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:23580 std::string description_;
[email protected]82891262008-12-24 00:21:26581
[email protected]6657afa62009-11-04 02:15:20582 // True if the extension was generated from a user script. (We show slightly
583 // different UI if so).
584 bool converted_from_user_script_;
585
[email protected]82891262008-12-24 00:21:26586 // Paths to the content scripts the extension contains.
[email protected]34aa8dc2009-02-19 07:03:05587 UserScriptList content_scripts_;
[email protected]7713d632008-12-02 07:52:33588
[email protected]37e960e2009-10-13 23:17:50589 // The extension's page action, if any.
[email protected]5d246db22009-10-27 06:17:57590 scoped_ptr<ExtensionAction> page_action_;
[email protected]671e6c1ce2009-09-26 03:18:46591
592 // The extension's browser action, if any.
[email protected]5d246db22009-10-27 06:17:57593 scoped_ptr<ExtensionAction> browser_action_;
[email protected]ec9ac0df2009-10-01 18:06:47594
[email protected]c533bb22009-06-03 19:06:11595 // Optional list of NPAPI plugins and associated properties.
596 std::vector<PluginInfo> plugins_;
[email protected]367230c52009-02-21 01:44:30597
[email protected]c64631652009-04-29 22:24:31598 // Optional URL to a master page of which a single instance should be always
599 // loaded in the background.
600 GURL background_url_;
601
[email protected]43919ac92009-10-16 18:34:28602 // Optional URL to a page for setting options/preferences.
603 GURL options_url_;
604
[email protected]c0821052010-08-06 11:44:57605 // Optional URL to a devtools extension page.
606 GURL devtools_url_;
607
[email protected]bbc945542009-07-26 00:11:42608 // Optional list of toolstrips_ and associated properties.
[email protected]6d7a6042010-08-12 20:12:42609 std::vector<GURL> toolstrips_;
[email protected]4a8d3272009-03-10 19:15:08610
[email protected]fbcc40302009-06-12 20:45:45611 // The public key ('key' in the manifest) used to sign the contents of the
612 // crx package ('signature' in the manifest)
613 std::string public_key_;
[email protected]cc655912009-01-29 23:19:19614
[email protected]07c00d992009-03-04 20:27:04615 // A map of resource id's to relative file paths.
[email protected]bbb436f2009-05-09 16:51:07616 scoped_ptr<DictionaryValue> theme_images_;
[email protected]4a190632009-05-09 01:07:42617
618 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07619 scoped_ptr<DictionaryValue> theme_colors_;
[email protected]4a190632009-05-09 01:07:42620
621 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07622 scoped_ptr<DictionaryValue> theme_tints_;
[email protected]4a190632009-05-09 01:07:42623
[email protected]7895ea22009-06-02 20:53:50624 // A map of display properties.
625 scoped_ptr<DictionaryValue> theme_display_properties_;
626
[email protected]4a190632009-05-09 01:07:42627 // Whether the extension is a theme - if it is, certain things are disabled.
628 bool is_theme_;
[email protected]07c00d992009-03-04 20:27:04629
[email protected]c64631652009-04-29 22:24:31630 // The sites this extension has permission to talk to (using XHR, etc).
[email protected]b30e0dd2010-01-29 23:33:21631 URLPatternList host_permissions_;
[email protected]7197f4992009-03-23 05:05:49632
[email protected]b29682ba22009-06-18 19:53:56633 // URL for fetching an update manifest
634 GURL update_url_;
[email protected]d6336a92009-08-13 17:25:12635
[email protected]b6ab96d2009-08-20 18:58:19636 // A copy of the manifest that this extension was created from.
637 scoped_ptr<DictionaryValue> manifest_value_;
638
[email protected]86c008e82009-08-28 20:26:05639 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
640 // which override the handling of those URLs.
[email protected]d3cfa482009-10-17 13:54:57641 URLOverrideMap chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05642
[email protected]3ba0fd32010-06-19 05:39:10643 // Whether this extension uses app features.
644 bool is_app_;
[email protected]3b355642010-02-05 16:01:49645
[email protected]867a73e12010-03-19 20:45:46646 // The local path inside the extension to use with the launcher.
647 std::string launch_local_path_;
648
649 // A web url to use with the launcher. Note that this might be relative or
650 // absolute. If relative, it is relative to web_origin_.
651 std::string launch_web_url_;
652
653 // The type of container to launch into.
[email protected]d83a5602010-09-16 00:22:48654 extension_misc::LaunchContainer launch_container_;
[email protected]867a73e12010-03-19 20:45:46655
[email protected]605cfad2010-06-22 20:49:35656 // The default size of the container when launching. Only respected for
657 // containers like panels and windows.
658 int launch_width_;
659 int launch_height_;
660
[email protected]052c92702010-06-25 07:25:52661 // Cached images for this extension.
[email protected]d9ad80f2010-03-30 20:40:18662 ImageCache image_cache_;
[email protected]ceefd3d2010-03-12 09:10:29663
[email protected]be7e5cb2010-10-04 12:53:17664 // The Omnibox keyword for this extension, or empty if there is none.
[email protected]56ad3792010-05-28 17:45:33665 std::string omnibox_keyword_;
666
[email protected]e95ad332009-08-03 19:44:25667 // Runtime data:
668
669 // True if the background page is ready.
670 bool background_page_ready_;
[email protected]b29682ba22009-06-18 19:53:56671
[email protected]1e8c93f2010-02-08 22:58:31672 // True while the extension is being upgraded.
673 bool being_upgraded_;
674
[email protected]19118d52010-07-26 22:13:42675 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
676 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58677
[email protected]894bb502009-05-21 22:39:57678 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33679};
680
[email protected]b1748b1d82009-11-30 20:32:56681typedef std::vector<Extension*> ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:18682typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:56683
[email protected]c6d474f82009-12-16 21:11:06684// Handy struct to pass core extension info around.
685struct ExtensionInfo {
686 ExtensionInfo(const DictionaryValue* manifest,
687 const std::string& id,
688 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:46689 Extension::Location location);
690 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06691
692 scoped_ptr<DictionaryValue> extension_manifest;
693 std::string extension_id;
694 FilePath extension_path;
695 Extension::Location extension_location;
696
697 private:
698 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
699};
700
[email protected]211030342010-09-30 18:41:06701// Struct used for the details of the EXTENSION_UNINSTALLED
702// notification.
703struct UninstalledExtensionInfo {
704 explicit UninstalledExtensionInfo(const Extension& extension);
[email protected]9b2331d92010-10-04 23:11:19705 ~UninstalledExtensionInfo();
[email protected]211030342010-09-30 18:41:06706
707 std::string extension_id;
708 std::set<std::string> extension_api_permissions;
[email protected]76c25112010-10-01 22:37:21709 // TODO(akalin): Once we have a unified ExtensionType, replace the
710 // below member variables with a member of that type.
711 bool is_theme;
712 bool is_app;
713 bool converted_from_user_script;
714 GURL update_url;
[email protected]211030342010-09-30 18:41:06715};
716
[email protected]5b1a0e22009-05-26 19:00:58717#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_