blob: 15aca067b1625c54478646e3ecbf8efbc5ff6063 [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]7713d632008-12-02 07:52:337
[email protected]300cc58db2009-08-19 20:45:148#include <map>
[email protected]facd7a7652009-06-05 23:15:029#include <set>
[email protected]7713d632008-12-02 07:52:3310#include <string>
11#include <vector>
12
[email protected]6014d672008-12-05 00:38:2513#include "base/file_path.h"
[email protected]cc655912009-01-29 23:19:1914#include "base/scoped_ptr.h"
[email protected]7713d632008-12-02 07:52:3315#include "base/values.h"
[email protected]cc655912009-01-29 23:19:1916#include "base/version.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"
[email protected]8cb5d5b2010-02-09 11:36:1622#include "testing/gtest/include/gtest/gtest_prod.h"
[email protected]d9ad80f2010-03-30 20:40:1823#include "third_party/skia/include/core/SkBitmap.h"
[email protected]eab9b452009-01-23 20:48:5924
[email protected]942690b132010-05-11 06:42:1425class ExtensionAction;
26class ExtensionResource;
27
[email protected]f0755532010-06-22 07:27:2528// Represents a Chrome extension.
[email protected]7713d632008-12-02 07:52:3329class Extension {
30 public:
[email protected]b30e0dd2010-01-29 23:33:2131 typedef std::vector<URLPattern> URLPatternList;
[email protected]d3cfa482009-10-17 13:54:5732 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]b24d8312009-08-27 06:47:4633
[email protected]631cf822009-05-15 07:01:2534 // What an extension was loaded from.
[email protected]1952c7d2010-03-04 23:48:3435 // NOTE: These values are stored as integers in the preferences, so you
36 // really don't want to change any existing ones.
[email protected]631cf822009-05-15 07:01:2537 enum Location {
38 INVALID,
[email protected]25b34332009-06-05 21:53:1939 INTERNAL, // A crx file from the internal Extensions directory.
40 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
41 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
42 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3443 LOAD, // --load-extension.
44 COMPONENT // An integral component of Chrome itself, which happens
45 // to be implemented as an extension. We don't show
46 // these in the management UI.
[email protected]25b34332009-06-05 21:53:1947 };
48
49 enum State {
[email protected]0c6da502009-08-14 22:32:3950 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1951 ENABLED,
52 KILLBIT, // Don't install/upgrade (applies to external extensions only).
[email protected]0c6da502009-08-14 22:32:3953
54 NUM_STATES
[email protected]631cf822009-05-15 07:01:2555 };
[email protected]7713d632008-12-02 07:52:3356
[email protected]fbcc40302009-06-12 20:45:4557 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3758 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4559 DOWNGRADE,
60 REINSTALL,
61 UPGRADE,
62 NEW_INSTALL
63 };
64
[email protected]d2817012009-08-04 06:46:2165 // NOTE: If you change this list, you should also change kIconSizes in the cc
66 // file.
67 enum Icons {
68 EXTENSION_ICON_LARGE = 128,
69 EXTENSION_ICON_MEDIUM = 48,
70 EXTENSION_ICON_SMALL = 32,
[email protected]39382942010-03-23 15:57:0971 EXTENSION_ICON_SMALLISH = 24,
[email protected]d2817012009-08-04 06:46:2172 EXTENSION_ICON_BITTY = 16,
73 };
74
[email protected]867a73e12010-03-19 20:45:4675 enum LaunchContainer {
[email protected]c28071ad2010-03-12 17:28:5676 LAUNCH_WINDOW,
77 LAUNCH_PANEL,
78 LAUNCH_TAB
[email protected]28375ae2010-02-05 04:45:5079 };
80
[email protected]867a73e12010-03-19 20:45:4681 bool apps_enabled() const { return apps_enabled_; }
82 void set_apps_enabled(bool val) { apps_enabled_ = val; }
83
[email protected]c3e3def742009-07-17 07:51:0684 // Icon sizes used by the extension system.
[email protected]d2817012009-08-04 06:46:2185 static const int kIconSizes[];
[email protected]c3e3def742009-07-17 07:51:0686
[email protected]4c4f8192009-10-17 01:03:2687 // Max size (both dimensions) for browser and page actions.
88 static const int kPageActionIconMaxSize;
89 static const int kBrowserActionIconMaxSize;
90
[email protected]35506352009-08-07 18:58:1991 // Each permission is a module that the extension is permitted to use.
[email protected]218990c2010-06-26 01:21:0792 //
93 // NOTE: If you add a permission, consider also changing:
94 // - Extension::GetSimplePermissions()
95 // - Extension::IsPrivilegeIncrease()
96 // - ExtensionInstallUI::GetV2Warnings()
[email protected]e8345242010-05-06 03:00:4097 static const char* kBackgroundPermission;
[email protected]aeb53b32009-10-29 07:34:4598 static const char* kBookmarkPermission;
[email protected]ea99c3a2010-01-07 00:40:1999 static const char* kExperimentalPermission;
[email protected]5ab79b02010-04-26 16:47:11100 static const char* kGeolocationPermission;
[email protected]bb0a6a02010-04-01 21:17:00101 static const char* kHistoryPermission;
[email protected]5ab79b02010-04-26 16:47:11102 static const char* kNotificationPermission;
103 static const char* kTabPermission;
104 static const char* kUnlimitedStoragePermission;
[email protected]aeb53b32009-10-29 07:34:45105
[email protected]35506352009-08-07 18:58:19106 static const char* kPermissionNames[];
107 static const size_t kNumPermissions;
108
[email protected]218990c2010-06-26 01:21:07109 // A "simple permission" is one that has a one-to-one mapping with a message
110 // that is displayed in the install UI. This is in contrast to more complex
111 // permissions like http access, where the exact message displayed depends on
112 // several factors.
113 typedef std::map<std::string, string16> SimplePermissions;
114 static const SimplePermissions& GetSimplePermissions();
115
[email protected]c533bb22009-06-03 19:06:11116 // An NPAPI plugin included in the extension.
117 struct PluginInfo {
118 FilePath path; // Path to the plugin.
119 bool is_public; // False if only this extension can load this plugin.
120 };
121
[email protected]bbc945542009-07-26 00:11:42122 // A toolstrip and its associated mole.
123 struct ToolstripInfo {
124 ToolstripInfo() : mole_height(0) {}
125
126 GURL toolstrip;
127 GURL mole;
128 int mole_height;
129 };
130
[email protected]6014d672008-12-05 00:38:25131 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16132 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25133
[email protected]300cc58db2009-08-19 20:45:14134 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16135 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14136
137 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16138 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14139
[email protected]25b34332009-06-05 21:53:19140#if defined(OS_WIN)
141 static const char* kExtensionRegistryPath;
142#endif
143
[email protected]37eeb5a2009-02-26 23:36:17144 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48145 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17146
[email protected]e435d6b72009-07-25 03:15:58147 // The mimetype used for extensions.
148 static const char kMimeType[];
149
[email protected]631cf822009-05-15 07:01:25150 explicit Extension(const FilePath& path);
[email protected]631cf822009-05-15 07:01:25151 virtual ~Extension();
152
[email protected]25b34332009-06-05 21:53:19153 // Checks to see if the extension has a valid ID.
154 static bool IdIsValid(const std::string& id);
155
[email protected]e435d6b72009-07-25 03:15:58156 // Returns true if the specified file is an extension.
157 static bool IsExtension(const FilePath& file_name);
158
[email protected]25b34332009-06-05 21:53:19159 // Whether the |location| is external or not.
160 static inline bool IsExternalLocation(Location location) {
161 return location == Extension::EXTERNAL_PREF ||
162 location == Extension::EXTERNAL_REGISTRY;
163 }
164
[email protected]07c00d992009-03-04 20:27:04165 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59166 // |extension_url| argument should be the url() from an Extension object. The
167 // |relative_path| can be untrusted user input. The returned URL will either
168 // be invalid() or a child of |extension_url|.
169 // NOTE: Static so that it can be used from multiple threads.
170 static GURL GetResourceURL(const GURL& extension_url,
171 const std::string& relative_path);
[email protected]3cfbd0e2009-03-18 21:26:24172 GURL GetResourceURL(const std::string& relative_path) {
173 return GetResourceURL(url(), relative_path);
174 }
[email protected]eab9b452009-01-23 20:48:59175
[email protected]99efb7b12009-12-18 02:39:16176 // Returns an extension resource object. |relative_path| should be UTF8
177 // encoded.
178 ExtensionResource GetResource(const std::string& relative_path);
179
180 // As above, but with |relative_path| following the file system's encoding.
181 ExtensionResource GetResource(const FilePath& relative_path);
[email protected]eab9b452009-01-23 20:48:59182
[email protected]a17f9462009-06-09 02:56:41183 // |input| is expected to be the text of an rsa public or private key. It
184 // tolerates the presence or absence of bracking header/footer like this:
185 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
186 // and may contain newlines.
187 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
188
189 // Does a simple base64 encoding of |input| into |output|.
190 static bool ProducePEM(const std::string& input, std::string* output);
191
[email protected]84ac7f32009-10-06 06:17:54192 // Generates an extension ID from arbitrary input. The same input string will
193 // always generate the same output ID.
194 static bool GenerateId(const std::string& input, std::string* output);
[email protected]fbcc40302009-06-12 20:45:45195
[email protected]a17f9462009-06-09 02:56:41196 // Expects base64 encoded |input| and formats into |output| including
197 // the appropriate header & footer.
198 static bool FormatPEMForFileOutput(const std::string input,
199 std::string* output, bool is_public);
200
[email protected]2a409532009-08-28 19:39:44201 // Determine whether |new_extension| has increased privileges compared to
202 // |old_extension|.
203 static bool IsPrivilegeIncrease(Extension* old_extension,
204 Extension* new_extension);
[email protected]b24d8312009-08-27 06:47:46205
[email protected]c690a9812009-12-17 05:55:32206 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23207 // result. In the browser process, this will DCHECK if not called on the
208 // file thread. To easily load extension images on the UI thread, see
209 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32210 static void DecodeIcon(Extension* extension,
211 Icons icon_size,
212 scoped_ptr<SkBitmap>* result);
213
214 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23215 // result. In the browser process, this will DCHECK if not called on the
216 // file thread. To easily load extension images on the UI thread, see
217 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32218 static void DecodeIconFromPath(const FilePath& icon_path,
219 Icons icon_size,
220 scoped_ptr<SkBitmap>* result);
221
[email protected]a807bbe2010-04-14 10:51:19222 // Returns the base extension url for a given |extension_id|.
223 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
224
[email protected]596c6aa2010-05-25 15:56:26225 // Returns whether the browser has apps enabled (either as the default or if
226 // it was explictly turned on via a command line switch).
227 static bool AppsAreEnabled();
228
[email protected]a0cf04a2010-06-23 03:29:55229 // Returns the url prefix for the extension/apps gallery. Can be set via the
230 // --apps-gallery-url switch.
231 static std::string ChromeStoreURL();
232
[email protected]4a8d3272009-03-10 19:15:08233 // Initialize the extension from a parsed manifest.
[email protected]1952c7d2010-03-04 23:48:34234 // Usually, the id of an extension is generated by the "key" property of
235 // its manifest, but if |require_key| is |false|, a temporary ID will be
236 // generated based on the path.
237 bool InitFromValue(const DictionaryValue& value, bool require_key,
[email protected]5bfb1eb0a2009-04-08 18:33:30238 std::string* error);
[email protected]4a8d3272009-03-10 19:15:08239
[email protected]82891262008-12-24 00:21:26240 const FilePath& path() const { return path_; }
[email protected]af1277b2009-07-28 00:47:53241 void set_path(const FilePath& path) { path_ = path; }
[email protected]5bfb1eb0a2009-04-08 18:33:30242 const GURL& url() const { return extension_url_; }
[email protected]225c8f52010-02-05 22:23:20243 Location location() const { return location_; }
[email protected]631cf822009-05-15 07:01:25244 void set_location(Location location) { location_ = location; }
[email protected]4a8d3272009-03-10 19:15:08245 const std::string& id() const { return id_; }
246 const Version* version() const { return version_.get(); }
247 // String representation of the version number.
248 const std::string VersionString() const;
249 const std::string& name() const { return name_; }
[email protected]fbcc40302009-06-12 20:45:45250 const std::string& public_key() const { return public_key_; }
[email protected]4a8d3272009-03-10 19:15:08251 const std::string& description() const { return description_; }
[email protected]6657afa62009-11-04 02:15:20252 bool converted_from_user_script() const {
253 return converted_from_user_script_;
254 }
[email protected]4a8d3272009-03-10 19:15:08255 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]5d246db22009-10-27 06:17:57256 ExtensionAction* page_action() const { return page_action_.get(); }
257 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]c533bb22009-06-03 19:06:11258 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]c64631652009-04-29 22:24:31259 const GURL& background_url() const { return background_url_; }
[email protected]43919ac92009-10-16 18:34:28260 const GURL& options_url() const { return options_url_; }
[email protected]bbc945542009-07-26 00:11:42261 const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; }
[email protected]35506352009-08-07 18:58:19262 const std::vector<std::string>& api_permissions() const {
263 return api_permissions_;
264 }
[email protected]b30e0dd2010-01-29 23:33:21265 const URLPatternList& host_permissions() const {
[email protected]c7ad50f2009-09-11 06:28:15266 return host_permissions_;
267 }
268
[email protected]aeb53b32009-10-29 07:34:45269 // Returns true if the extension has the specified API permission.
270 bool HasApiPermission(const std::string& permission) const {
271 return std::find(api_permissions_.begin(), api_permissions_.end(),
272 permission) != api_permissions_.end();
273 }
274
[email protected]b24d8312009-08-27 06:47:46275 // Returns the set of hosts that the extension effectively has access to. This
276 // is used in the permissions UI and is a combination of the hosts accessible
277 // through content scripts and the hosts accessible through XHR.
278 const std::set<std::string> GetEffectiveHostPermissions() const;
279
[email protected]fbd17cf2010-04-28 23:52:56280 // Whether or not the extension is allowed permission for a URL pattern from
281 // the manifest. http, https, and chrome://favicon/ is allowed for all
282 // extensions, while component extensions are allowed access to
283 // chrome://resources.
284 bool CanAccessURL(const URLPattern pattern) const;
285
[email protected]584b8e3f2010-04-10 00:23:37286 // Whether the extension has access to the given URL.
287 bool HasHostPermission(const GURL& url) const;
288
[email protected]215160af2010-04-03 06:02:34289 // Returns true if the extension effectively has access to the user's browsing
290 // history. There are several permissions that we group together into this
291 // bucket. For example: tabs, bookmarks, and history.
292 bool HasEffectiveBrowsingHistoryPermission() const;
293
[email protected]b24d8312009-08-27 06:47:46294 // Whether the extension has access to all hosts. This is true if there is
295 // a content script that matches all hosts, or if there is a host permission
296 // for all hosts.
297 bool HasAccessToAllHosts() const;
298
[email protected]b29682ba22009-06-18 19:53:56299 const GURL& update_url() const { return update_url_; }
[email protected]0cb5f502009-10-21 21:35:47300 const std::map<int, std::string>& icons() const { return icons_; }
[email protected]4a8d3272009-03-10 19:15:08301
[email protected]bfa90a3a2010-04-28 15:43:23302 // Returns the Google Gallery URL for this extension, if one exists. For
303 // third-party extensions, this returns a blank GURL.
304 GURL GalleryUrl() const;
305
[email protected]25b34332009-06-05 21:53:19306 // Theme-related.
[email protected]631cf822009-05-15 07:01:25307 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
308 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
309 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
[email protected]7895ea22009-06-02 20:53:50310 DictionaryValue* GetThemeDisplayProperties() const {
311 return theme_display_properties_.get();
312 }
[email protected]3ba0fd32010-06-19 05:39:10313 bool is_theme() const { return is_theme_; }
[email protected]631cf822009-05-15 07:01:25314
[email protected]facd7a7652009-06-05 23:15:02315 // Returns a list of paths (relative to the extension dir) for images that
316 // the browser might load (like themes and page action icons).
317 std::set<FilePath> GetBrowserImages();
318
[email protected]866930682009-08-18 22:53:47319 // Returns an absolute path to the given icon inside of the extension. Returns
320 // an empty FilePath if the extension does not have that icon.
[email protected]ecabe6ee2009-10-07 22:49:10321 ExtensionResource GetIconPath(Icons icon);
[email protected]866930682009-08-18 22:53:47322
[email protected]f34e79632010-03-17 02:34:08323 // Looks for an extension icon of dimension |icon|. If not found, checks if
324 // the next larger size exists (until one is found or the end is reached). If
325 // an icon is found, the path is returned in |resource| and the dimension
326 // found is returned to the caller (as function return value).
327 // NOTE: |resource| is not guaranteed to be non-empty.
328 Icons GetIconPathAllowLargerSize(ExtensionResource* resource, Icons icon);
329
[email protected]b6ab96d2009-08-20 18:58:19330 const DictionaryValue* manifest_value() const {
331 return manifest_value_.get();
332 }
333
[email protected]9428edc2009-11-18 18:02:47334 const std::string default_locale() const { return default_locale_; }
335
[email protected]86c008e82009-08-28 20:26:05336 // Chrome URL overrides (see ExtensionOverrideUI).
[email protected]d3cfa482009-10-17 13:54:57337 const URLOverrideMap& GetChromeURLOverrides() const {
338 return chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05339 }
340
[email protected]56ad3792010-05-28 17:45:33341 const std::string omnibox_keyword() const { return omnibox_keyword_; }
342
[email protected]3ba0fd32010-06-19 05:39:10343 bool is_app() const { return is_app_; }
[email protected]867a73e12010-03-19 20:45:46344 const ExtensionExtent& web_extent() const { return web_extent_; }
[email protected]867a73e12010-03-19 20:45:46345 const std::string& launch_local_path() const { return launch_local_path_; }
346 const std::string& launch_web_url() const { return launch_web_url_; }
[email protected]98254d22010-03-26 00:03:50347 LaunchContainer launch_container() const { return launch_container_; }
[email protected]bbadaa782010-04-28 21:21:53348 bool launch_fullscreen() const { return launch_fullscreen_; }
[email protected]605cfad2010-06-22 20:49:35349 int launch_width() const { return launch_width_; }
350 int launch_height() const { return launch_height_; }
[email protected]867a73e12010-03-19 20:45:46351
352 // Gets the fully resolved absolute launch URL.
353 GURL GetFullLaunchURL() const;
[email protected]ceefd3d2010-03-12 09:10:29354
[email protected]e95ad332009-08-03 19:44:25355 // Runtime data:
356 // Put dynamic data about the state of a running extension below.
357
358 // Whether the background page, if any, is ready. We don't load other
359 // components until then. If there is no background page, we consider it to
360 // be ready.
361 bool GetBackgroundPageReady();
362 void SetBackgroundPageReady();
363
[email protected]1e8c93f2010-02-08 22:58:31364 // Getter and setter for the flag that specifies whether the extension is
365 // being upgraded.
366 bool being_upgraded() const { return being_upgraded_; }
367 void set_being_upgraded(bool value) { being_upgraded_ = value; }
368
[email protected]d9ad80f2010-03-30 20:40:18369 // Image cache related methods. These are only valid on the UI thread and
[email protected]052c92702010-06-25 07:25:52370 // not maintained by this class. See ImageLoadingTracker for usage. The
371 // |original_size| parameter should be the size of the image at |source|
372 // before any scaling may have been done to produce the pixels in |image|.
[email protected]d9ad80f2010-03-30 20:40:18373 void SetCachedImage(const ExtensionResource& source,
[email protected]052c92702010-06-25 07:25:52374 const SkBitmap& image,
375 const gfx::Size& original_size);
376 bool HasCachedImage(const ExtensionResource& source,
377 const gfx::Size& max_size);
378 SkBitmap GetCachedImage(const ExtensionResource& source,
379 const gfx::Size& max_size);
[email protected]d9ad80f2010-03-30 20:40:18380
[email protected]4a8d3272009-03-10 19:15:08381 private:
[email protected]052c92702010-06-25 07:25:52382 // We keep a cache of images loaded from extension resources based on their
383 // path and a string representation of a size that may have been used to
384 // scale it (or the empty string if the image is at its original size).
385 typedef std::pair<FilePath, std::string> ImageCacheKey;
386 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
387
388 // Helper function for implementing HasCachedImage/GetCachedImage. A return
389 // value of NULL means there is no matching image cached (we allow caching an
390 // empty SkBitmap).
391 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
392 const gfx::Size& max_size);
[email protected]d9ad80f2010-03-30 20:40:18393
[email protected]3cfbd0e2009-03-18 21:26:24394 // Helper method that loads a UserScript object from a
395 // dictionary in the content_script list of the manifest.
396 bool LoadUserScriptHelper(const DictionaryValue* content_script,
397 int definition_index,
398 std::string* error,
399 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34400
[email protected]6657afa62009-11-04 02:15:20401 // Helper method that loads either the include_globs or exclude_globs list
402 // from an entry in the content_script lists of the manifest.
403 bool LoadGlobsHelper(const DictionaryValue* content_script,
404 int content_script_index,
405 const wchar_t* globs_property_name,
406 std::string* error,
[email protected]11f4857282009-11-13 19:56:17407 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20408 UserScript *instance);
409
[email protected]867a73e12010-03-19 20:45:46410 // Helpers to load various chunks of the manifest.
[email protected]3ba0fd32010-06-19 05:39:10411 bool LoadIsApp(const DictionaryValue* manifest, std::string* error);
[email protected]9f72aa02010-06-25 10:01:05412 bool LoadWebURLs(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46413 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
[email protected]bbadaa782010-04-28 21:21:53414 bool LoadLaunchFullscreen(const DictionaryValue* manifest,
415 std::string* error);
[email protected]867a73e12010-03-19 20:45:46416 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error);
417
[email protected]5d246db22009-10-27 06:17:57418 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08419 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57420 ExtensionAction* LoadExtensionActionHelper(
[email protected]92c6f9b92009-10-24 04:35:08421 const DictionaryValue* extension_action, std::string* error);
422
[email protected]e2eb43112009-05-29 21:19:54423 // Figures out if a source contains keys not associated with themes - we
424 // don't want to allow scripts and such to be bundled with themes.
425 bool ContainsNonThemeKeys(const DictionaryValue& source);
426
[email protected]1952c7d2010-03-04 23:48:34427 // Returns true if the string is one of the known api permissions (see
428 // kPermissionNames).
429 bool IsAPIPermission(const std::string& permission);
430
[email protected]4a8d3272009-03-10 19:15:08431 // The absolute path to the directory the extension is stored in.
432 FilePath path_;
433
434 // The base extension url for the extension.
435 GURL extension_url_;
[email protected]eab9b452009-01-23 20:48:59436
[email protected]631cf822009-05-15 07:01:25437 // The location the extension was loaded from.
438 Location location_;
439
[email protected]7713d632008-12-02 07:52:33440 // A human-readable ID for the extension. The convention is to use something
441 // like 'com.example.myextension', but this is not currently enforced. An
442 // extension's ID is used in things like directory structures and URLs, and
443 // is expected to not change across versions. In the case of conflicts,
444 // updates will only be allowed if the extension can be validated using the
445 // previous version's update key.
[email protected]e1cec06c2008-12-18 01:22:23446 std::string id_;
[email protected]82891262008-12-24 00:21:26447
[email protected]64a02b802009-01-12 19:36:42448 // The extension's version.
[email protected]cc655912009-01-29 23:19:19449 scoped_ptr<Version> version_;
[email protected]64a02b802009-01-12 19:36:42450
[email protected]49a7c772010-05-21 18:32:35451 // The extension's human-readable name. Name is used for display purpose. It
452 // might be wrapped with unicode bidi control characters so that it is
453 // displayed correctly in RTL context.
454 // NOTE: Name is UTF-8 and may contain non-ascii characters.
[email protected]e1cec06c2008-12-18 01:22:23455 std::string name_;
[email protected]82891262008-12-24 00:21:26456
[email protected]4a8d3272009-03-10 19:15:08457 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:23458 std::string description_;
[email protected]82891262008-12-24 00:21:26459
[email protected]6657afa62009-11-04 02:15:20460 // True if the extension was generated from a user script. (We show slightly
461 // different UI if so).
462 bool converted_from_user_script_;
463
[email protected]82891262008-12-24 00:21:26464 // Paths to the content scripts the extension contains.
[email protected]34aa8dc2009-02-19 07:03:05465 UserScriptList content_scripts_;
[email protected]7713d632008-12-02 07:52:33466
[email protected]37e960e2009-10-13 23:17:50467 // The extension's page action, if any.
[email protected]5d246db22009-10-27 06:17:57468 scoped_ptr<ExtensionAction> page_action_;
[email protected]671e6c1ce2009-09-26 03:18:46469
470 // The extension's browser action, if any.
[email protected]5d246db22009-10-27 06:17:57471 scoped_ptr<ExtensionAction> browser_action_;
[email protected]ec9ac0df2009-10-01 18:06:47472
[email protected]c533bb22009-06-03 19:06:11473 // Optional list of NPAPI plugins and associated properties.
474 std::vector<PluginInfo> plugins_;
[email protected]367230c52009-02-21 01:44:30475
[email protected]c64631652009-04-29 22:24:31476 // Optional URL to a master page of which a single instance should be always
477 // loaded in the background.
478 GURL background_url_;
479
[email protected]43919ac92009-10-16 18:34:28480 // Optional URL to a page for setting options/preferences.
481 GURL options_url_;
482
[email protected]bbc945542009-07-26 00:11:42483 // Optional list of toolstrips_ and associated properties.
484 std::vector<ToolstripInfo> toolstrips_;
[email protected]4a8d3272009-03-10 19:15:08485
[email protected]fbcc40302009-06-12 20:45:45486 // The public key ('key' in the manifest) used to sign the contents of the
487 // crx package ('signature' in the manifest)
488 std::string public_key_;
[email protected]cc655912009-01-29 23:19:19489
[email protected]07c00d992009-03-04 20:27:04490 // A map of resource id's to relative file paths.
[email protected]bbb436f2009-05-09 16:51:07491 scoped_ptr<DictionaryValue> theme_images_;
[email protected]4a190632009-05-09 01:07:42492
493 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07494 scoped_ptr<DictionaryValue> theme_colors_;
[email protected]4a190632009-05-09 01:07:42495
496 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07497 scoped_ptr<DictionaryValue> theme_tints_;
[email protected]4a190632009-05-09 01:07:42498
[email protected]7895ea22009-06-02 20:53:50499 // A map of display properties.
500 scoped_ptr<DictionaryValue> theme_display_properties_;
501
[email protected]4a190632009-05-09 01:07:42502 // Whether the extension is a theme - if it is, certain things are disabled.
503 bool is_theme_;
[email protected]07c00d992009-03-04 20:27:04504
[email protected]35506352009-08-07 18:58:19505 // The set of module-level APIs this extension can use.
506 std::vector<std::string> api_permissions_;
507
[email protected]c64631652009-04-29 22:24:31508 // The sites this extension has permission to talk to (using XHR, etc).
[email protected]b30e0dd2010-01-29 23:33:21509 URLPatternList host_permissions_;
[email protected]7197f4992009-03-23 05:05:49510
[email protected]c3e3def742009-07-17 07:51:06511 // The paths to the icons the extension contains mapped by their width.
512 std::map<int, std::string> icons_;
513
[email protected]b29682ba22009-06-18 19:53:56514 // URL for fetching an update manifest
515 GURL update_url_;
[email protected]d6336a92009-08-13 17:25:12516
[email protected]b6ab96d2009-08-20 18:58:19517 // A copy of the manifest that this extension was created from.
518 scoped_ptr<DictionaryValue> manifest_value_;
519
[email protected]9428edc2009-11-18 18:02:47520 // Default locale for fall back. Can be empty if extension is not localized.
521 std::string default_locale_;
522
[email protected]86c008e82009-08-28 20:26:05523 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
524 // which override the handling of those URLs.
[email protected]d3cfa482009-10-17 13:54:57525 URLOverrideMap chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05526
[email protected]867a73e12010-03-19 20:45:46527 // Whether apps-related features can be parsed during InitFromValue().
528 // Defaults to the value from --enable-extension-apps.
529 bool apps_enabled_;
[email protected]581b0ad2010-01-12 21:54:38530
[email protected]3ba0fd32010-06-19 05:39:10531 // Whether this extension uses app features.
532 bool is_app_;
[email protected]3b355642010-02-05 16:01:49533
[email protected]867a73e12010-03-19 20:45:46534 // Defines the set of URLs in the extension's web content.
535 ExtensionExtent web_extent_;
[email protected]3b355642010-02-05 16:01:49536
[email protected]867a73e12010-03-19 20:45:46537 // The local path inside the extension to use with the launcher.
538 std::string launch_local_path_;
539
540 // A web url to use with the launcher. Note that this might be relative or
541 // absolute. If relative, it is relative to web_origin_.
542 std::string launch_web_url_;
543
544 // The type of container to launch into.
545 LaunchContainer launch_container_;
546
[email protected]bbadaa782010-04-28 21:21:53547 // Launch full screen by default.
548 bool launch_fullscreen_;
549
[email protected]605cfad2010-06-22 20:49:35550 // The default size of the container when launching. Only respected for
551 // containers like panels and windows.
552 int launch_width_;
553 int launch_height_;
554
[email protected]052c92702010-06-25 07:25:52555 // Cached images for this extension.
[email protected]d9ad80f2010-03-30 20:40:18556 ImageCache image_cache_;
[email protected]ceefd3d2010-03-12 09:10:29557
[email protected]56ad3792010-05-28 17:45:33558 // The omnibox keyword for this extension, or empty if there is none.
559 std::string omnibox_keyword_;
560
[email protected]e95ad332009-08-03 19:44:25561 // Runtime data:
562
563 // True if the background page is ready.
564 bool background_page_ready_;
[email protected]b29682ba22009-06-18 19:53:56565
[email protected]1e8c93f2010-02-08 22:58:31566 // True while the extension is being upgraded.
567 bool being_upgraded_;
568
[email protected]ae7fe712009-07-02 20:33:58569 FRIEND_TEST(ExtensionTest, LoadPageActionHelper);
[email protected]3b355642010-02-05 16:01:49570 FRIEND_TEST(TabStripModelTest, Apps);
[email protected]4488e65f2010-06-06 04:49:53571 FRIEND_TEST(TabStripModelTest, ToolbarVisibility);
[email protected]ae7fe712009-07-02 20:33:58572
[email protected]894bb502009-05-21 22:39:57573 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33574};
575
[email protected]b1748b1d82009-11-30 20:32:56576typedef std::vector<Extension*> ExtensionList;
577
[email protected]c6d474f82009-12-16 21:11:06578// Handy struct to pass core extension info around.
579struct ExtensionInfo {
580 ExtensionInfo(const DictionaryValue* manifest,
581 const std::string& id,
582 const FilePath& path,
583 Extension::Location location)
584 : extension_id(id),
585 extension_path(path),
586 extension_location(location) {
587 if (manifest)
588 extension_manifest.reset(
589 static_cast<DictionaryValue*>(manifest->DeepCopy()));
590 }
591
592 scoped_ptr<DictionaryValue> extension_manifest;
593 std::string extension_id;
594 FilePath extension_path;
595 Extension::Location extension_location;
596
597 private:
598 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
599};
600
[email protected]5b1a0e22009-05-26 19:00:58601#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_