blob: 8f96120597eecad35ce64cce9c92aac9bdbf0887 [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]867a73e12010-03-19 20:45:4617#include "chrome/common/extensions/extension_extent.h"
[email protected]42b6f0f82009-09-18 21:07:3918#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4919#include "chrome/common/extensions/url_pattern.h"
[email protected]052c92702010-06-25 07:25:5220#include "gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5921#include "googleurl/src/gurl.h"
22
[email protected]3bb84992010-08-26 17:23:4623class DictionaryValue;
[email protected]942690b132010-05-11 06:42:1424class ExtensionAction;
25class ExtensionResource;
[email protected]12802702010-07-09 19:43:0926class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2827class Version;
[email protected]942690b132010-05-11 06:42:1428
[email protected]f0755532010-06-22 07:27:2529// Represents a Chrome extension.
[email protected]7713d632008-12-02 07:52:3330class Extension {
31 public:
[email protected]b30e0dd2010-01-29 23:33:2132 typedef std::vector<URLPattern> URLPatternList;
[email protected]d3cfa482009-10-17 13:54:5733 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]b24d8312009-08-27 06:47:4634
[email protected]631cf822009-05-15 07:01:2535 // What an extension was loaded from.
[email protected]1952c7d2010-03-04 23:48:3436 // NOTE: These values are stored as integers in the preferences, so you
37 // really don't want to change any existing ones.
[email protected]631cf822009-05-15 07:01:2538 enum Location {
39 INVALID,
[email protected]25b34332009-06-05 21:53:1940 INTERNAL, // A crx file from the internal Extensions directory.
41 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
42 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
43 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3444 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3245 COMPONENT, // An integral component of Chrome itself, which
46 // happens to be implemented as an extension. We don't
47 // show these in the management UI.
48 EXTERNAL_PREF_DOWNLOAD // A crx file from an external directory (via
49 // prefs), installed from an update URL.
[email protected]25b34332009-06-05 21:53:1950 };
51
52 enum State {
[email protected]0c6da502009-08-14 22:32:3953 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1954 ENABLED,
55 KILLBIT, // Don't install/upgrade (applies to external extensions only).
[email protected]0c6da502009-08-14 22:32:3956
57 NUM_STATES
[email protected]631cf822009-05-15 07:01:2558 };
[email protected]7713d632008-12-02 07:52:3359
[email protected]fbcc40302009-06-12 20:45:4560 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3761 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4562 DOWNGRADE,
63 REINSTALL,
64 UPGRADE,
65 NEW_INSTALL
66 };
67
[email protected]d2817012009-08-04 06:46:2168 // NOTE: If you change this list, you should also change kIconSizes in the cc
69 // file.
70 enum Icons {
71 EXTENSION_ICON_LARGE = 128,
72 EXTENSION_ICON_MEDIUM = 48,
73 EXTENSION_ICON_SMALL = 32,
[email protected]39382942010-03-23 15:57:0974 EXTENSION_ICON_SMALLISH = 24,
[email protected]d2817012009-08-04 06:46:2175 EXTENSION_ICON_BITTY = 16,
76 };
77
[email protected]867a73e12010-03-19 20:45:4678 enum LaunchContainer {
[email protected]c28071ad2010-03-12 17:28:5679 LAUNCH_WINDOW,
80 LAUNCH_PANEL,
81 LAUNCH_TAB
[email protected]28375ae2010-02-05 04:45:5082 };
83
[email protected]867a73e12010-03-19 20:45:4684 bool apps_enabled() const { return apps_enabled_; }
85 void set_apps_enabled(bool val) { apps_enabled_ = val; }
86
[email protected]c3e3def742009-07-17 07:51:0687 // Icon sizes used by the extension system.
[email protected]d2817012009-08-04 06:46:2188 static const int kIconSizes[];
[email protected]c3e3def742009-07-17 07:51:0689
[email protected]4c4f8192009-10-17 01:03:2690 // Max size (both dimensions) for browser and page actions.
91 static const int kPageActionIconMaxSize;
92 static const int kBrowserActionIconMaxSize;
93
[email protected]35506352009-08-07 18:58:1994 // Each permission is a module that the extension is permitted to use.
[email protected]218990c2010-06-26 01:21:0795 //
96 // NOTE: If you add a permission, consider also changing:
97 // - Extension::GetSimplePermissions()
98 // - Extension::IsPrivilegeIncrease()
99 // - ExtensionInstallUI::GetV2Warnings()
[email protected]9dcf8f12010-09-02 20:39:19100 static const char kBackgroundPermission[];
101 static const char kBookmarkPermission[];
102 static const char kContextMenusPermission[];
103 static const char kCookiePermission[];
104 static const char kExperimentalPermission[];
105 static const char kGeolocationPermission[];
106 static const char kHistoryPermission[];
107 static const char kIdlePermission[];
108 static const char kNotificationPermission[];
109 static const char kProxyPermission[];
110 static const char kTabPermission[];
111 static const char kUnlimitedStoragePermission[];
[email protected]9dcf8f12010-09-02 20:39:19112 static const char kWebstorePrivatePermission[];
[email protected]aeb53b32009-10-29 07:34:45113
[email protected]9dcf8f12010-09-02 20:39:19114 static const char* const kPermissionNames[];
[email protected]35506352009-08-07 18:58:19115 static const size_t kNumPermissions;
[email protected]9dcf8f12010-09-02 20:39:19116 static const char* const kHostedAppPermissionNames[];
[email protected]b746f372010-08-29 21:39:32117 static const size_t kNumHostedAppPermissions;
[email protected]35506352009-08-07 18:58:19118
[email protected]03b612f2010-08-13 21:09:21119 // The old name for the unlimited storage permission, which is deprecated but
120 // still accepted as meaning the same thing as kUnlimitedStoragePermission.
[email protected]9dcf8f12010-09-02 20:39:19121 static const char kOldUnlimitedStoragePermission[];
[email protected]03b612f2010-08-13 21:09:21122
[email protected]218990c2010-06-26 01:21:07123 // A "simple permission" is one that has a one-to-one mapping with a message
124 // that is displayed in the install UI. This is in contrast to more complex
125 // permissions like http access, where the exact message displayed depends on
126 // several factors.
127 typedef std::map<std::string, string16> SimplePermissions;
128 static const SimplePermissions& GetSimplePermissions();
129
[email protected]b746f372010-08-29 21:39:32130 // Returns true if the string is one of the known hosted app permissions (see
131 // kHostedAppPermissionNames).
132 static bool IsHostedAppPermission(const std::string& permission);
133
[email protected]c533bb22009-06-03 19:06:11134 // An NPAPI plugin included in the extension.
135 struct PluginInfo {
136 FilePath path; // Path to the plugin.
137 bool is_public; // False if only this extension can load this plugin.
138 };
139
[email protected]6014d672008-12-05 00:38:25140 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16141 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25142
[email protected]300cc58db2009-08-19 20:45:14143 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16144 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14145
146 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16147 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14148
[email protected]25b34332009-06-05 21:53:19149#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19150 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19151#endif
152
[email protected]37eeb5a2009-02-26 23:36:17153 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48154 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17155
[email protected]e435d6b72009-07-25 03:15:58156 // The mimetype used for extensions.
157 static const char kMimeType[];
158
[email protected]631cf822009-05-15 07:01:25159 explicit Extension(const FilePath& path);
[email protected]631cf822009-05-15 07:01:25160 virtual ~Extension();
161
[email protected]25b34332009-06-05 21:53:19162 // Checks to see if the extension has a valid ID.
163 static bool IdIsValid(const std::string& id);
164
[email protected]e435d6b72009-07-25 03:15:58165 // Returns true if the specified file is an extension.
166 static bool IsExtension(const FilePath& file_name);
167
[email protected]25b34332009-06-05 21:53:19168 // Whether the |location| is external or not.
169 static inline bool IsExternalLocation(Location location) {
170 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32171 location == Extension::EXTERNAL_REGISTRY ||
172 location == Extension::EXTERNAL_PREF_DOWNLOAD;
[email protected]25b34332009-06-05 21:53:19173 }
174
[email protected]07c00d992009-03-04 20:27:04175 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59176 // |extension_url| argument should be the url() from an Extension object. The
177 // |relative_path| can be untrusted user input. The returned URL will either
178 // be invalid() or a child of |extension_url|.
179 // NOTE: Static so that it can be used from multiple threads.
180 static GURL GetResourceURL(const GURL& extension_url,
181 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28182 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24183 return GetResourceURL(url(), relative_path);
184 }
[email protected]eab9b452009-01-23 20:48:59185
[email protected]99efb7b12009-12-18 02:39:16186 // Returns an extension resource object. |relative_path| should be UTF8
187 // encoded.
188 ExtensionResource GetResource(const std::string& relative_path);
189
190 // As above, but with |relative_path| following the file system's encoding.
191 ExtensionResource GetResource(const FilePath& relative_path);
[email protected]eab9b452009-01-23 20:48:59192
[email protected]a17f9462009-06-09 02:56:41193 // |input| is expected to be the text of an rsa public or private key. It
194 // tolerates the presence or absence of bracking header/footer like this:
195 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
196 // and may contain newlines.
197 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
198
199 // Does a simple base64 encoding of |input| into |output|.
200 static bool ProducePEM(const std::string& input, std::string* output);
201
[email protected]84ac7f32009-10-06 06:17:54202 // Generates an extension ID from arbitrary input. The same input string will
203 // always generate the same output ID.
204 static bool GenerateId(const std::string& input, std::string* output);
[email protected]fbcc40302009-06-12 20:45:45205
[email protected]a17f9462009-06-09 02:56:41206 // Expects base64 encoded |input| and formats into |output| including
207 // the appropriate header & footer.
208 static bool FormatPEMForFileOutput(const std::string input,
209 std::string* output, bool is_public);
210
[email protected]2a409532009-08-28 19:39:44211 // Determine whether |new_extension| has increased privileges compared to
212 // |old_extension|.
213 static bool IsPrivilegeIncrease(Extension* old_extension,
214 Extension* new_extension);
[email protected]b24d8312009-08-27 06:47:46215
[email protected]c690a9812009-12-17 05:55:32216 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23217 // result. In the browser process, this will DCHECK if not called on the
218 // file thread. To easily load extension images on the UI thread, see
219 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32220 static void DecodeIcon(Extension* extension,
221 Icons icon_size,
222 scoped_ptr<SkBitmap>* result);
223
224 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23225 // result. In the browser process, this will DCHECK if not called on the
226 // file thread. To easily load extension images on the UI thread, see
227 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32228 static void DecodeIconFromPath(const FilePath& icon_path,
229 Icons icon_size,
230 scoped_ptr<SkBitmap>* result);
231
[email protected]a807bbe2010-04-14 10:51:19232 // Returns the base extension url for a given |extension_id|.
233 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
234
[email protected]596c6aa2010-05-25 15:56:26235 // Returns whether the browser has apps enabled (either as the default or if
236 // it was explictly turned on via a command line switch).
237 static bool AppsAreEnabled();
238
[email protected]a0cf04a2010-06-23 03:29:55239 // Returns the url prefix for the extension/apps gallery. Can be set via the
240 // --apps-gallery-url switch.
241 static std::string ChromeStoreURL();
242
[email protected]4a8d3272009-03-10 19:15:08243 // Initialize the extension from a parsed manifest.
[email protected]1952c7d2010-03-04 23:48:34244 // Usually, the id of an extension is generated by the "key" property of
245 // its manifest, but if |require_key| is |false|, a temporary ID will be
246 // generated based on the path.
247 bool InitFromValue(const DictionaryValue& value, bool require_key,
[email protected]5bfb1eb0a2009-04-08 18:33:30248 std::string* error);
[email protected]4a8d3272009-03-10 19:15:08249
[email protected]82891262008-12-24 00:21:26250 const FilePath& path() const { return path_; }
[email protected]af1277b2009-07-28 00:47:53251 void set_path(const FilePath& path) { path_ = path; }
[email protected]5bfb1eb0a2009-04-08 18:33:30252 const GURL& url() const { return extension_url_; }
[email protected]225c8f52010-02-05 22:23:20253 Location location() const { return location_; }
[email protected]631cf822009-05-15 07:01:25254 void set_location(Location location) { location_ = location; }
[email protected]4a8d3272009-03-10 19:15:08255 const std::string& id() const { return id_; }
256 const Version* version() const { return version_.get(); }
257 // String representation of the version number.
258 const std::string VersionString() const;
259 const std::string& name() const { return name_; }
[email protected]fbcc40302009-06-12 20:45:45260 const std::string& public_key() const { return public_key_; }
[email protected]4a8d3272009-03-10 19:15:08261 const std::string& description() const { return description_; }
[email protected]6657afa62009-11-04 02:15:20262 bool converted_from_user_script() const {
263 return converted_from_user_script_;
264 }
[email protected]4a8d3272009-03-10 19:15:08265 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]5d246db22009-10-27 06:17:57266 ExtensionAction* page_action() const { return page_action_.get(); }
267 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]c533bb22009-06-03 19:06:11268 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]c64631652009-04-29 22:24:31269 const GURL& background_url() const { return background_url_; }
[email protected]43919ac92009-10-16 18:34:28270 const GURL& options_url() const { return options_url_; }
[email protected]c0821052010-08-06 11:44:57271 const GURL& devtools_url() const { return devtools_url_; }
[email protected]6d7a6042010-08-12 20:12:42272 const std::vector<GURL>& toolstrips() const { return toolstrips_; }
[email protected]35506352009-08-07 18:58:19273 const std::vector<std::string>& api_permissions() const {
274 return api_permissions_;
275 }
[email protected]b30e0dd2010-01-29 23:33:21276 const URLPatternList& host_permissions() const {
[email protected]c7ad50f2009-09-11 06:28:15277 return host_permissions_;
278 }
279
[email protected]aeb53b32009-10-29 07:34:45280 // Returns true if the extension has the specified API permission.
[email protected]583d45c12010-08-31 02:48:12281 static bool HasApiPermission(const std::vector<std::string>& api_permissions,
[email protected]246c05f2010-09-10 09:12:11282 const std::string& function_name);
[email protected]583d45c12010-08-31 02:48:12283
[email protected]246c05f2010-09-10 09:12:11284 bool HasApiPermission(const std::string& function_name) const {
285 return HasApiPermission(this->api_permissions(), function_name);
[email protected]aeb53b32009-10-29 07:34:45286 }
287
[email protected]b24d8312009-08-27 06:47:46288 // Returns the set of hosts that the extension effectively has access to. This
289 // is used in the permissions UI and is a combination of the hosts accessible
290 // through content scripts and the hosts accessible through XHR.
[email protected]8b3b54b2010-08-05 18:28:48291 const ExtensionExtent GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46292
[email protected]fbd17cf2010-04-28 23:52:56293 // Whether or not the extension is allowed permission for a URL pattern from
294 // the manifest. http, https, and chrome://favicon/ is allowed for all
295 // extensions, while component extensions are allowed access to
296 // chrome://resources.
297 bool CanAccessURL(const URLPattern pattern) const;
298
[email protected]584b8e3f2010-04-10 00:23:37299 // Whether the extension has access to the given URL.
300 bool HasHostPermission(const GURL& url) const;
301
[email protected]215160af2010-04-03 06:02:34302 // Returns true if the extension effectively has access to the user's browsing
303 // history. There are several permissions that we group together into this
304 // bucket. For example: tabs, bookmarks, and history.
305 bool HasEffectiveBrowsingHistoryPermission() const;
306
[email protected]b24d8312009-08-27 06:47:46307 // Whether the extension has access to all hosts. This is true if there is
308 // a content script that matches all hosts, or if there is a host permission
309 // for all hosts.
310 bool HasAccessToAllHosts() const;
311
[email protected]b29682ba22009-06-18 19:53:56312 const GURL& update_url() const { return update_url_; }
[email protected]0cb5f502009-10-21 21:35:47313 const std::map<int, std::string>& icons() const { return icons_; }
[email protected]4a8d3272009-03-10 19:15:08314
[email protected]bfa90a3a2010-04-28 15:43:23315 // Returns the Google Gallery URL for this extension, if one exists. For
316 // third-party extensions, this returns a blank GURL.
317 GURL GalleryUrl() const;
318
[email protected]25b34332009-06-05 21:53:19319 // Theme-related.
[email protected]631cf822009-05-15 07:01:25320 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
321 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
322 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
[email protected]7895ea22009-06-02 20:53:50323 DictionaryValue* GetThemeDisplayProperties() const {
324 return theme_display_properties_.get();
325 }
[email protected]3ba0fd32010-06-19 05:39:10326 bool is_theme() const { return is_theme_; }
[email protected]631cf822009-05-15 07:01:25327
[email protected]facd7a7652009-06-05 23:15:02328 // Returns a list of paths (relative to the extension dir) for images that
329 // the browser might load (like themes and page action icons).
330 std::set<FilePath> GetBrowserImages();
331
[email protected]866930682009-08-18 22:53:47332 // Returns an absolute path to the given icon inside of the extension. Returns
333 // an empty FilePath if the extension does not have that icon.
[email protected]5351dbc2010-08-27 15:22:11334 ExtensionResource GetIconResource(Icons icon);
[email protected]866930682009-08-18 22:53:47335
[email protected]f34e79632010-03-17 02:34:08336 // Looks for an extension icon of dimension |icon|. If not found, checks if
337 // the next larger size exists (until one is found or the end is reached). If
338 // an icon is found, the path is returned in |resource| and the dimension
339 // found is returned to the caller (as function return value).
340 // NOTE: |resource| is not guaranteed to be non-empty.
[email protected]5351dbc2010-08-27 15:22:11341 Icons GetIconResourceAllowLargerSize(ExtensionResource* resource, Icons icon);
342
[email protected]969894ab2010-08-29 00:35:01343 GURL GetIconURL(Icons icon);
344 GURL GetIconURLAllowLargerSize(Icons icon);
[email protected]f34e79632010-03-17 02:34:08345
[email protected]b6ab96d2009-08-20 18:58:19346 const DictionaryValue* manifest_value() const {
347 return manifest_value_.get();
348 }
349
[email protected]9428edc2009-11-18 18:02:47350 const std::string default_locale() const { return default_locale_; }
351
[email protected]86c008e82009-08-28 20:26:05352 // Chrome URL overrides (see ExtensionOverrideUI).
[email protected]d3cfa482009-10-17 13:54:57353 const URLOverrideMap& GetChromeURLOverrides() const {
354 return chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05355 }
356
[email protected]56ad3792010-05-28 17:45:33357 const std::string omnibox_keyword() const { return omnibox_keyword_; }
358
[email protected]3ba0fd32010-06-19 05:39:10359 bool is_app() const { return is_app_; }
[email protected]fe13bf62010-08-26 14:33:19360 ExtensionExtent& web_extent() { return web_extent_; }
[email protected]867a73e12010-03-19 20:45:46361 const std::string& launch_local_path() const { return launch_local_path_; }
362 const std::string& launch_web_url() const { return launch_web_url_; }
[email protected]fe13bf62010-08-26 14:33:19363 void set_launch_web_url(const std::string& launch_web_url) {
364 launch_web_url_ = launch_web_url;
365 }
[email protected]98254d22010-03-26 00:03:50366 LaunchContainer launch_container() const { return launch_container_; }
[email protected]605cfad2010-06-22 20:49:35367 int launch_width() const { return launch_width_; }
368 int launch_height() const { return launch_height_; }
[email protected]bc535ee52010-08-31 18:40:32369 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]867a73e12010-03-19 20:45:46370
371 // Gets the fully resolved absolute launch URL.
372 GURL GetFullLaunchURL() const;
[email protected]ceefd3d2010-03-12 09:10:29373
[email protected]e95ad332009-08-03 19:44:25374 // Runtime data:
375 // Put dynamic data about the state of a running extension below.
376
377 // Whether the background page, if any, is ready. We don't load other
378 // components until then. If there is no background page, we consider it to
379 // be ready.
380 bool GetBackgroundPageReady();
381 void SetBackgroundPageReady();
382
[email protected]1e8c93f2010-02-08 22:58:31383 // Getter and setter for the flag that specifies whether the extension is
384 // being upgraded.
385 bool being_upgraded() const { return being_upgraded_; }
386 void set_being_upgraded(bool value) { being_upgraded_ = value; }
387
[email protected]d9ad80f2010-03-30 20:40:18388 // Image cache related methods. These are only valid on the UI thread and
[email protected]052c92702010-06-25 07:25:52389 // not maintained by this class. See ImageLoadingTracker for usage. The
390 // |original_size| parameter should be the size of the image at |source|
391 // before any scaling may have been done to produce the pixels in |image|.
[email protected]d9ad80f2010-03-30 20:40:18392 void SetCachedImage(const ExtensionResource& source,
[email protected]052c92702010-06-25 07:25:52393 const SkBitmap& image,
394 const gfx::Size& original_size);
395 bool HasCachedImage(const ExtensionResource& source,
396 const gfx::Size& max_size);
397 SkBitmap GetCachedImage(const ExtensionResource& source,
398 const gfx::Size& max_size);
[email protected]270979d2010-09-01 04:34:33399 bool is_hosted_app() { return is_app() && !web_extent().is_empty(); }
400 bool is_packaged_app() { return is_app() && web_extent().is_empty(); }
[email protected]4a8d3272009-03-10 19:15:08401 private:
[email protected]052c92702010-06-25 07:25:52402 // We keep a cache of images loaded from extension resources based on their
403 // path and a string representation of a size that may have been used to
404 // scale it (or the empty string if the image is at its original size).
405 typedef std::pair<FilePath, std::string> ImageCacheKey;
406 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
407
408 // Helper function for implementing HasCachedImage/GetCachedImage. A return
409 // value of NULL means there is no matching image cached (we allow caching an
410 // empty SkBitmap).
411 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
412 const gfx::Size& max_size);
[email protected]d9ad80f2010-03-30 20:40:18413
[email protected]3cfbd0e2009-03-18 21:26:24414 // Helper method that loads a UserScript object from a
415 // dictionary in the content_script list of the manifest.
416 bool LoadUserScriptHelper(const DictionaryValue* content_script,
417 int definition_index,
418 std::string* error,
419 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34420
[email protected]6657afa62009-11-04 02:15:20421 // Helper method that loads either the include_globs or exclude_globs list
422 // from an entry in the content_script lists of the manifest.
423 bool LoadGlobsHelper(const DictionaryValue* content_script,
424 int content_script_index,
[email protected]e2194742010-08-12 05:54:34425 const char* globs_property_name,
[email protected]6657afa62009-11-04 02:15:20426 std::string* error,
[email protected]11f4857282009-11-13 19:56:17427 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20428 UserScript *instance);
429
[email protected]867a73e12010-03-19 20:45:46430 // Helpers to load various chunks of the manifest.
[email protected]3ba0fd32010-06-19 05:39:10431 bool LoadIsApp(const DictionaryValue* manifest, std::string* error);
[email protected]e2194742010-08-12 05:54:34432 bool LoadExtent(const DictionaryValue* manifest, const char* key,
[email protected]4fdbc1492010-07-01 01:20:59433 ExtensionExtent* extent, const char* list_error,
434 const char* value_error, std::string* error);
[email protected]867a73e12010-03-19 20:45:46435 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46436 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error);
[email protected]cbf4d1912010-08-12 18:24:57437 bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46438
[email protected]5d246db22009-10-27 06:17:57439 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08440 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57441 ExtensionAction* LoadExtensionActionHelper(
[email protected]92c6f9b92009-10-24 04:35:08442 const DictionaryValue* extension_action, std::string* error);
443
[email protected]e2eb43112009-05-29 21:19:54444 // Figures out if a source contains keys not associated with themes - we
445 // don't want to allow scripts and such to be bundled with themes.
446 bool ContainsNonThemeKeys(const DictionaryValue& source);
447
[email protected]1952c7d2010-03-04 23:48:34448 // Returns true if the string is one of the known api permissions (see
449 // kPermissionNames).
450 bool IsAPIPermission(const std::string& permission);
451
[email protected]5351dbc2010-08-27 15:22:11452 // Utility functions to get the icon relative path used to create an
453 // ExtensionResource or URL.
454 std::string GetIconPath(Icons icon);
455 Icons GetIconPathAllowLargerSize(std::string* path, Icons icon);
456
[email protected]4a8d3272009-03-10 19:15:08457 // The absolute path to the directory the extension is stored in.
458 FilePath path_;
459
460 // The base extension url for the extension.
461 GURL extension_url_;
[email protected]eab9b452009-01-23 20:48:59462
[email protected]631cf822009-05-15 07:01:25463 // The location the extension was loaded from.
464 Location location_;
465
[email protected]7713d632008-12-02 07:52:33466 // A human-readable ID for the extension. The convention is to use something
467 // like 'com.example.myextension', but this is not currently enforced. An
468 // extension's ID is used in things like directory structures and URLs, and
469 // is expected to not change across versions. In the case of conflicts,
470 // updates will only be allowed if the extension can be validated using the
471 // previous version's update key.
[email protected]e1cec06c2008-12-18 01:22:23472 std::string id_;
[email protected]82891262008-12-24 00:21:26473
[email protected]64a02b802009-01-12 19:36:42474 // The extension's version.
[email protected]cc655912009-01-29 23:19:19475 scoped_ptr<Version> version_;
[email protected]64a02b802009-01-12 19:36:42476
[email protected]49a7c772010-05-21 18:32:35477 // The extension's human-readable name. Name is used for display purpose. It
478 // might be wrapped with unicode bidi control characters so that it is
479 // displayed correctly in RTL context.
480 // NOTE: Name is UTF-8 and may contain non-ascii characters.
[email protected]e1cec06c2008-12-18 01:22:23481 std::string name_;
[email protected]82891262008-12-24 00:21:26482
[email protected]4a8d3272009-03-10 19:15:08483 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:23484 std::string description_;
[email protected]82891262008-12-24 00:21:26485
[email protected]6657afa62009-11-04 02:15:20486 // True if the extension was generated from a user script. (We show slightly
487 // different UI if so).
488 bool converted_from_user_script_;
489
[email protected]82891262008-12-24 00:21:26490 // Paths to the content scripts the extension contains.
[email protected]34aa8dc2009-02-19 07:03:05491 UserScriptList content_scripts_;
[email protected]7713d632008-12-02 07:52:33492
[email protected]37e960e2009-10-13 23:17:50493 // The extension's page action, if any.
[email protected]5d246db22009-10-27 06:17:57494 scoped_ptr<ExtensionAction> page_action_;
[email protected]671e6c1ce2009-09-26 03:18:46495
496 // The extension's browser action, if any.
[email protected]5d246db22009-10-27 06:17:57497 scoped_ptr<ExtensionAction> browser_action_;
[email protected]ec9ac0df2009-10-01 18:06:47498
[email protected]c533bb22009-06-03 19:06:11499 // Optional list of NPAPI plugins and associated properties.
500 std::vector<PluginInfo> plugins_;
[email protected]367230c52009-02-21 01:44:30501
[email protected]c64631652009-04-29 22:24:31502 // Optional URL to a master page of which a single instance should be always
503 // loaded in the background.
504 GURL background_url_;
505
[email protected]43919ac92009-10-16 18:34:28506 // Optional URL to a page for setting options/preferences.
507 GURL options_url_;
508
[email protected]c0821052010-08-06 11:44:57509 // Optional URL to a devtools extension page.
510 GURL devtools_url_;
511
[email protected]bbc945542009-07-26 00:11:42512 // Optional list of toolstrips_ and associated properties.
[email protected]6d7a6042010-08-12 20:12:42513 std::vector<GURL> toolstrips_;
[email protected]4a8d3272009-03-10 19:15:08514
[email protected]fbcc40302009-06-12 20:45:45515 // The public key ('key' in the manifest) used to sign the contents of the
516 // crx package ('signature' in the manifest)
517 std::string public_key_;
[email protected]cc655912009-01-29 23:19:19518
[email protected]07c00d992009-03-04 20:27:04519 // A map of resource id's to relative file paths.
[email protected]bbb436f2009-05-09 16:51:07520 scoped_ptr<DictionaryValue> theme_images_;
[email protected]4a190632009-05-09 01:07:42521
522 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07523 scoped_ptr<DictionaryValue> theme_colors_;
[email protected]4a190632009-05-09 01:07:42524
525 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07526 scoped_ptr<DictionaryValue> theme_tints_;
[email protected]4a190632009-05-09 01:07:42527
[email protected]7895ea22009-06-02 20:53:50528 // A map of display properties.
529 scoped_ptr<DictionaryValue> theme_display_properties_;
530
[email protected]4a190632009-05-09 01:07:42531 // Whether the extension is a theme - if it is, certain things are disabled.
532 bool is_theme_;
[email protected]07c00d992009-03-04 20:27:04533
[email protected]35506352009-08-07 18:58:19534 // The set of module-level APIs this extension can use.
535 std::vector<std::string> api_permissions_;
536
[email protected]c64631652009-04-29 22:24:31537 // The sites this extension has permission to talk to (using XHR, etc).
[email protected]b30e0dd2010-01-29 23:33:21538 URLPatternList host_permissions_;
[email protected]7197f4992009-03-23 05:05:49539
[email protected]c3e3def742009-07-17 07:51:06540 // The paths to the icons the extension contains mapped by their width.
541 std::map<int, std::string> icons_;
542
[email protected]b29682ba22009-06-18 19:53:56543 // URL for fetching an update manifest
544 GURL update_url_;
[email protected]d6336a92009-08-13 17:25:12545
[email protected]b6ab96d2009-08-20 18:58:19546 // A copy of the manifest that this extension was created from.
547 scoped_ptr<DictionaryValue> manifest_value_;
548
[email protected]9428edc2009-11-18 18:02:47549 // Default locale for fall back. Can be empty if extension is not localized.
550 std::string default_locale_;
551
[email protected]86c008e82009-08-28 20:26:05552 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
553 // which override the handling of those URLs.
[email protected]d3cfa482009-10-17 13:54:57554 URLOverrideMap chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05555
[email protected]867a73e12010-03-19 20:45:46556 // Whether apps-related features can be parsed during InitFromValue().
557 // Defaults to the value from --enable-extension-apps.
558 bool apps_enabled_;
[email protected]581b0ad2010-01-12 21:54:38559
[email protected]3ba0fd32010-06-19 05:39:10560 // Whether this extension uses app features.
561 bool is_app_;
[email protected]3b355642010-02-05 16:01:49562
[email protected]867a73e12010-03-19 20:45:46563 // Defines the set of URLs in the extension's web content.
564 ExtensionExtent web_extent_;
[email protected]3b355642010-02-05 16:01:49565
[email protected]867a73e12010-03-19 20:45:46566 // The local path inside the extension to use with the launcher.
567 std::string launch_local_path_;
568
569 // A web url to use with the launcher. Note that this might be relative or
570 // absolute. If relative, it is relative to web_origin_.
571 std::string launch_web_url_;
572
573 // The type of container to launch into.
574 LaunchContainer launch_container_;
575
[email protected]605cfad2010-06-22 20:49:35576 // The default size of the container when launching. Only respected for
577 // containers like panels and windows.
578 int launch_width_;
579 int launch_height_;
580
[email protected]052c92702010-06-25 07:25:52581 // Cached images for this extension.
[email protected]d9ad80f2010-03-30 20:40:18582 ImageCache image_cache_;
[email protected]ceefd3d2010-03-12 09:10:29583
[email protected]56ad3792010-05-28 17:45:33584 // The omnibox keyword for this extension, or empty if there is none.
585 std::string omnibox_keyword_;
586
[email protected]bc535ee52010-08-31 18:40:32587 // If true, a separate process will be used for the extension in incognito
588 // mode.
589 bool incognito_split_mode_;
590
[email protected]e95ad332009-08-03 19:44:25591 // Runtime data:
592
593 // True if the background page is ready.
594 bool background_page_ready_;
[email protected]b29682ba22009-06-18 19:53:56595
[email protected]1e8c93f2010-02-08 22:58:31596 // True while the extension is being upgraded.
597 bool being_upgraded_;
598
[email protected]19118d52010-07-26 22:13:42599 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
600 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58601
[email protected]894bb502009-05-21 22:39:57602 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33603};
604
[email protected]b1748b1d82009-11-30 20:32:56605typedef std::vector<Extension*> ExtensionList;
606
[email protected]c6d474f82009-12-16 21:11:06607// Handy struct to pass core extension info around.
608struct ExtensionInfo {
609 ExtensionInfo(const DictionaryValue* manifest,
610 const std::string& id,
611 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:46612 Extension::Location location);
613 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06614
615 scoped_ptr<DictionaryValue> extension_manifest;
616 std::string extension_id;
617 FilePath extension_path;
618 Extension::Location extension_location;
619
620 private:
621 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
622};
623
[email protected]5b1a0e22009-05-26 19:00:58624#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_