blob: 7559162fb292771e149f365d4ef8238a5ef1b661 [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]ba69a7d2009-09-28 21:09:5617#include "chrome/common/extensions/extension_action.h"
[email protected]867a73e12010-03-19 20:45:4618#include "chrome/common/extensions/extension_extent.h"
[email protected]ecabe6ee2009-10-07 22:49:1019#include "chrome/common/extensions/extension_resource.h"
[email protected]42b6f0f82009-09-18 21:07:3920#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4921#include "chrome/common/extensions/url_pattern.h"
[email protected]eab9b452009-01-23 20:48:5922#include "googleurl/src/gurl.h"
[email protected]8cb5d5b2010-02-09 11:36:1623#include "testing/gtest/include/gtest/gtest_prod.h"
[email protected]d9ad80f2010-03-30 20:40:1824#include "third_party/skia/include/core/SkBitmap.h"
[email protected]eab9b452009-01-23 20:48:5925
[email protected]c533bb22009-06-03 19:06:1126// Represents a Chrome extension.
[email protected]7713d632008-12-02 07:52:3327class Extension {
28 public:
[email protected]b30e0dd2010-01-29 23:33:2129 typedef std::vector<URLPattern> URLPatternList;
[email protected]d3cfa482009-10-17 13:54:5730 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]b24d8312009-08-27 06:47:4631
[email protected]631cf822009-05-15 07:01:2532 // What an extension was loaded from.
[email protected]1952c7d2010-03-04 23:48:3433 // NOTE: These values are stored as integers in the preferences, so you
34 // really don't want to change any existing ones.
[email protected]631cf822009-05-15 07:01:2535 enum Location {
36 INVALID,
[email protected]25b34332009-06-05 21:53:1937 INTERNAL, // A crx file from the internal Extensions directory.
38 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
39 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
40 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3441 LOAD, // --load-extension.
42 COMPONENT // An integral component of Chrome itself, which happens
43 // to be implemented as an extension. We don't show
44 // these in the management UI.
[email protected]25b34332009-06-05 21:53:1945 };
46
47 enum State {
[email protected]0c6da502009-08-14 22:32:3948 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1949 ENABLED,
50 KILLBIT, // Don't install/upgrade (applies to external extensions only).
[email protected]0c6da502009-08-14 22:32:3951
52 NUM_STATES
[email protected]631cf822009-05-15 07:01:2553 };
[email protected]7713d632008-12-02 07:52:3354
[email protected]fbcc40302009-06-12 20:45:4555 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3756 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4557 DOWNGRADE,
58 REINSTALL,
59 UPGRADE,
60 NEW_INSTALL
61 };
62
[email protected]d2817012009-08-04 06:46:2163 // NOTE: If you change this list, you should also change kIconSizes in the cc
64 // file.
65 enum Icons {
66 EXTENSION_ICON_LARGE = 128,
67 EXTENSION_ICON_MEDIUM = 48,
68 EXTENSION_ICON_SMALL = 32,
[email protected]39382942010-03-23 15:57:0969 EXTENSION_ICON_SMALLISH = 24,
[email protected]d2817012009-08-04 06:46:2170 EXTENSION_ICON_BITTY = 16,
71 };
72
[email protected]867a73e12010-03-19 20:45:4673 enum LaunchContainer {
[email protected]c28071ad2010-03-12 17:28:5674 LAUNCH_WINDOW,
75 LAUNCH_PANEL,
76 LAUNCH_TAB
[email protected]28375ae2010-02-05 04:45:5077 };
78
[email protected]867a73e12010-03-19 20:45:4679 bool apps_enabled() const { return apps_enabled_; }
80 void set_apps_enabled(bool val) { apps_enabled_ = val; }
81
[email protected]c3e3def742009-07-17 07:51:0682 // Icon sizes used by the extension system.
[email protected]d2817012009-08-04 06:46:2183 static const int kIconSizes[];
[email protected]c3e3def742009-07-17 07:51:0684
[email protected]4c4f8192009-10-17 01:03:2685 // Max size (both dimensions) for browser and page actions.
86 static const int kPageActionIconMaxSize;
87 static const int kBrowserActionIconMaxSize;
88
[email protected]35506352009-08-07 18:58:1989 // Each permission is a module that the extension is permitted to use.
[email protected]aeb53b32009-10-29 07:34:4590 static const char* kTabPermission;
91 static const char* kBookmarkPermission;
[email protected]0faf2aa82009-11-24 22:10:4992 static const char* kNotificationPermission;
[email protected]ea99c3a2010-01-07 00:40:1993 static const char* kExperimentalPermission;
[email protected]24b538a2010-02-27 01:22:4494 static const char* kUnlimitedStoragePermission;
[email protected]bb0a6a02010-04-01 21:17:0095 static const char* kHistoryPermission;
[email protected]aeb53b32009-10-29 07:34:4596
[email protected]35506352009-08-07 18:58:1997 static const char* kPermissionNames[];
98 static const size_t kNumPermissions;
99
[email protected]c533bb22009-06-03 19:06:11100 // An NPAPI plugin included in the extension.
101 struct PluginInfo {
102 FilePath path; // Path to the plugin.
103 bool is_public; // False if only this extension can load this plugin.
104 };
105
[email protected]bbc945542009-07-26 00:11:42106 // A toolstrip and its associated mole.
107 struct ToolstripInfo {
108 ToolstripInfo() : mole_height(0) {}
109
110 GURL toolstrip;
111 GURL mole;
112 int mole_height;
113 };
114
[email protected]6014d672008-12-05 00:38:25115 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16116 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25117
[email protected]300cc58db2009-08-19 20:45:14118 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16119 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14120
121 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16122 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14123
[email protected]25b34332009-06-05 21:53:19124#if defined(OS_WIN)
125 static const char* kExtensionRegistryPath;
126#endif
127
[email protected]37eeb5a2009-02-26 23:36:17128 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48129 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17130
[email protected]e435d6b72009-07-25 03:15:58131 // The mimetype used for extensions.
132 static const char kMimeType[];
133
[email protected]631cf822009-05-15 07:01:25134 explicit Extension(const FilePath& path);
[email protected]631cf822009-05-15 07:01:25135 virtual ~Extension();
136
[email protected]25b34332009-06-05 21:53:19137 // Checks to see if the extension has a valid ID.
138 static bool IdIsValid(const std::string& id);
139
[email protected]e435d6b72009-07-25 03:15:58140 // Returns true if the specified file is an extension.
141 static bool IsExtension(const FilePath& file_name);
142
[email protected]25b34332009-06-05 21:53:19143 // Whether the |location| is external or not.
144 static inline bool IsExternalLocation(Location location) {
145 return location == Extension::EXTERNAL_PREF ||
146 location == Extension::EXTERNAL_REGISTRY;
147 }
148
[email protected]07c00d992009-03-04 20:27:04149 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59150 // |extension_url| argument should be the url() from an Extension object. The
151 // |relative_path| can be untrusted user input. The returned URL will either
152 // be invalid() or a child of |extension_url|.
153 // NOTE: Static so that it can be used from multiple threads.
154 static GURL GetResourceURL(const GURL& extension_url,
155 const std::string& relative_path);
[email protected]3cfbd0e2009-03-18 21:26:24156 GURL GetResourceURL(const std::string& relative_path) {
157 return GetResourceURL(url(), relative_path);
158 }
[email protected]eab9b452009-01-23 20:48:59159
[email protected]99efb7b12009-12-18 02:39:16160 // Returns an extension resource object. |relative_path| should be UTF8
161 // encoded.
162 ExtensionResource GetResource(const std::string& relative_path);
163
164 // As above, but with |relative_path| following the file system's encoding.
165 ExtensionResource GetResource(const FilePath& relative_path);
[email protected]eab9b452009-01-23 20:48:59166
[email protected]a17f9462009-06-09 02:56:41167 // |input| is expected to be the text of an rsa public or private key. It
168 // tolerates the presence or absence of bracking header/footer like this:
169 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
170 // and may contain newlines.
171 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
172
173 // Does a simple base64 encoding of |input| into |output|.
174 static bool ProducePEM(const std::string& input, std::string* output);
175
[email protected]84ac7f32009-10-06 06:17:54176 // Generates an extension ID from arbitrary input. The same input string will
177 // always generate the same output ID.
178 static bool GenerateId(const std::string& input, std::string* output);
[email protected]fbcc40302009-06-12 20:45:45179
[email protected]a17f9462009-06-09 02:56:41180 // Expects base64 encoded |input| and formats into |output| including
181 // the appropriate header & footer.
182 static bool FormatPEMForFileOutput(const std::string input,
183 std::string* output, bool is_public);
184
[email protected]2a409532009-08-28 19:39:44185 // Determine whether |new_extension| has increased privileges compared to
186 // |old_extension|.
187 static bool IsPrivilegeIncrease(Extension* old_extension,
188 Extension* new_extension);
[email protected]b24d8312009-08-27 06:47:46189
[email protected]699e1cd2010-03-24 16:00:34190 // *** HITS THE FILESYSTEM. Do not call on UI thread! ***
[email protected]c690a9812009-12-17 05:55:32191 // Given an extension and icon size, read it if present and decode it into
192 // result.
[email protected]699e1cd2010-03-24 16:00:34193 // NOTE: If you need the icon on the UI thread, please use the
194 // ImageLoadingTracker, which uses the File thread internally to decode.
[email protected]c690a9812009-12-17 05:55:32195 static void DecodeIcon(Extension* extension,
196 Icons icon_size,
197 scoped_ptr<SkBitmap>* result);
198
[email protected]699e1cd2010-03-24 16:00:34199 // *** HITS THE FILESYSTEM. Do not call on UI thread! ***
[email protected]c690a9812009-12-17 05:55:32200 // Given an icon_path and icon size, read it if present and decode it into
201 // result.
[email protected]699e1cd2010-03-24 16:00:34202 // NOTE: If you need the icon on the UI thread, please use the
203 // ImageLoadingTracker, which uses the File thread internally to decode.
[email protected]c690a9812009-12-17 05:55:32204 static void DecodeIconFromPath(const FilePath& icon_path,
205 Icons icon_size,
206 scoped_ptr<SkBitmap>* result);
207
[email protected]4a8d3272009-03-10 19:15:08208 // Initialize the extension from a parsed manifest.
[email protected]1952c7d2010-03-04 23:48:34209 // Usually, the id of an extension is generated by the "key" property of
210 // its manifest, but if |require_key| is |false|, a temporary ID will be
211 // generated based on the path.
212 bool InitFromValue(const DictionaryValue& value, bool require_key,
[email protected]5bfb1eb0a2009-04-08 18:33:30213 std::string* error);
[email protected]4a8d3272009-03-10 19:15:08214
[email protected]82891262008-12-24 00:21:26215 const FilePath& path() const { return path_; }
[email protected]af1277b2009-07-28 00:47:53216 void set_path(const FilePath& path) { path_ = path; }
[email protected]5bfb1eb0a2009-04-08 18:33:30217 const GURL& url() const { return extension_url_; }
[email protected]225c8f52010-02-05 22:23:20218 Location location() const { return location_; }
[email protected]631cf822009-05-15 07:01:25219 void set_location(Location location) { location_ = location; }
[email protected]4a8d3272009-03-10 19:15:08220 const std::string& id() const { return id_; }
221 const Version* version() const { return version_.get(); }
222 // String representation of the version number.
223 const std::string VersionString() const;
224 const std::string& name() const { return name_; }
[email protected]fbcc40302009-06-12 20:45:45225 const std::string& public_key() const { return public_key_; }
[email protected]4a8d3272009-03-10 19:15:08226 const std::string& description() const { return description_; }
[email protected]6657afa62009-11-04 02:15:20227 bool converted_from_user_script() const {
228 return converted_from_user_script_;
229 }
[email protected]4a8d3272009-03-10 19:15:08230 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]5d246db22009-10-27 06:17:57231 ExtensionAction* page_action() const { return page_action_.get(); }
232 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]c533bb22009-06-03 19:06:11233 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]c64631652009-04-29 22:24:31234 const GURL& background_url() const { return background_url_; }
[email protected]43919ac92009-10-16 18:34:28235 const GURL& options_url() const { return options_url_; }
[email protected]bbc945542009-07-26 00:11:42236 const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; }
[email protected]35506352009-08-07 18:58:19237 const std::vector<std::string>& api_permissions() const {
238 return api_permissions_;
239 }
[email protected]b30e0dd2010-01-29 23:33:21240 const URLPatternList& host_permissions() const {
[email protected]c7ad50f2009-09-11 06:28:15241 return host_permissions_;
242 }
243
[email protected]e9303b942010-02-20 08:21:19244 // Returns true if the extension has permission to execute script on a
245 // particular host.
246 // TODO(aa): Also use this in the renderer, for normal content script
247 // injection. Currently, that has its own copy of this code.
248 bool CanExecuteScriptOnHost(const GURL& url, std::string* error) const;
[email protected]b24d8312009-08-27 06:47:46249
[email protected]aeb53b32009-10-29 07:34:45250 // Returns true if the extension has the specified API permission.
251 bool HasApiPermission(const std::string& permission) const {
252 return std::find(api_permissions_.begin(), api_permissions_.end(),
253 permission) != api_permissions_.end();
254 }
255
[email protected]b24d8312009-08-27 06:47:46256 // Returns the set of hosts that the extension effectively has access to. This
257 // is used in the permissions UI and is a combination of the hosts accessible
258 // through content scripts and the hosts accessible through XHR.
259 const std::set<std::string> GetEffectiveHostPermissions() const;
260
[email protected]215160af2010-04-03 06:02:34261 // Returns true if the extension effectively has access to the user's browsing
262 // history. There are several permissions that we group together into this
263 // bucket. For example: tabs, bookmarks, and history.
264 bool HasEffectiveBrowsingHistoryPermission() const;
265
[email protected]b24d8312009-08-27 06:47:46266 // Whether the extension has access to all hosts. This is true if there is
267 // a content script that matches all hosts, or if there is a host permission
268 // for all hosts.
269 bool HasAccessToAllHosts() const;
270
[email protected]b29682ba22009-06-18 19:53:56271 const GURL& update_url() const { return update_url_; }
[email protected]0cb5f502009-10-21 21:35:47272 const std::map<int, std::string>& icons() const { return icons_; }
[email protected]4a8d3272009-03-10 19:15:08273
[email protected]25b34332009-06-05 21:53:19274 // Theme-related.
[email protected]631cf822009-05-15 07:01:25275 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
276 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
277 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
[email protected]7895ea22009-06-02 20:53:50278 DictionaryValue* GetThemeDisplayProperties() const {
279 return theme_display_properties_.get();
280 }
[email protected]66da08b2009-10-19 22:27:00281 bool IsTheme() const { return is_theme_; }
[email protected]631cf822009-05-15 07:01:25282
[email protected]facd7a7652009-06-05 23:15:02283 // Returns a list of paths (relative to the extension dir) for images that
284 // the browser might load (like themes and page action icons).
285 std::set<FilePath> GetBrowserImages();
286
[email protected]866930682009-08-18 22:53:47287 // Returns an absolute path to the given icon inside of the extension. Returns
288 // an empty FilePath if the extension does not have that icon.
[email protected]ecabe6ee2009-10-07 22:49:10289 ExtensionResource GetIconPath(Icons icon);
[email protected]866930682009-08-18 22:53:47290
[email protected]f34e79632010-03-17 02:34:08291 // Looks for an extension icon of dimension |icon|. If not found, checks if
292 // the next larger size exists (until one is found or the end is reached). If
293 // an icon is found, the path is returned in |resource| and the dimension
294 // found is returned to the caller (as function return value).
295 // NOTE: |resource| is not guaranteed to be non-empty.
296 Icons GetIconPathAllowLargerSize(ExtensionResource* resource, Icons icon);
297
[email protected]b6ab96d2009-08-20 18:58:19298 const DictionaryValue* manifest_value() const {
299 return manifest_value_.get();
300 }
301
[email protected]9428edc2009-11-18 18:02:47302 const std::string default_locale() const { return default_locale_; }
303
[email protected]86c008e82009-08-28 20:26:05304 // Chrome URL overrides (see ExtensionOverrideUI).
[email protected]d3cfa482009-10-17 13:54:57305 const URLOverrideMap& GetChromeURLOverrides() const {
306 return chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05307 }
308
[email protected]867a73e12010-03-19 20:45:46309 bool web_content_enabled() const { return web_content_enabled_; }
310 const ExtensionExtent& web_extent() const { return web_extent_; }
311
312 const std::string& launch_local_path() const { return launch_local_path_; }
313 const std::string& launch_web_url() const { return launch_web_url_; }
[email protected]98254d22010-03-26 00:03:50314 LaunchContainer launch_container() const { return launch_container_; }
[email protected]867a73e12010-03-19 20:45:46315
316 // Gets the fully resolved absolute launch URL.
317 GURL GetFullLaunchURL() const;
[email protected]ceefd3d2010-03-12 09:10:29318
[email protected]e95ad332009-08-03 19:44:25319 // Runtime data:
320 // Put dynamic data about the state of a running extension below.
321
322 // Whether the background page, if any, is ready. We don't load other
323 // components until then. If there is no background page, we consider it to
324 // be ready.
325 bool GetBackgroundPageReady();
326 void SetBackgroundPageReady();
327
[email protected]1e8c93f2010-02-08 22:58:31328 // Getter and setter for the flag that specifies whether the extension is
329 // being upgraded.
330 bool being_upgraded() const { return being_upgraded_; }
331 void set_being_upgraded(bool value) { being_upgraded_ = value; }
332
[email protected]d9ad80f2010-03-30 20:40:18333 // Image cache related methods. These are only valid on the UI thread and
334 // not maintained by this class. See ImageLoadingTracker for usage.
335 void SetCachedImage(const ExtensionResource& source,
336 const SkBitmap& image);
337 bool HasCachedImage(const ExtensionResource& source);
338 SkBitmap GetCachedImage(const ExtensionResource& source);
339
[email protected]4a8d3272009-03-10 19:15:08340 private:
[email protected]d9ad80f2010-03-30 20:40:18341 typedef std::map<FilePath, SkBitmap> ImageCache;
342
[email protected]3cfbd0e2009-03-18 21:26:24343 // Helper method that loads a UserScript object from a
344 // dictionary in the content_script list of the manifest.
345 bool LoadUserScriptHelper(const DictionaryValue* content_script,
346 int definition_index,
347 std::string* error,
348 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34349
[email protected]6657afa62009-11-04 02:15:20350 // Helper method that loads either the include_globs or exclude_globs list
351 // from an entry in the content_script lists of the manifest.
352 bool LoadGlobsHelper(const DictionaryValue* content_script,
353 int content_script_index,
354 const wchar_t* globs_property_name,
355 std::string* error,
[email protected]11f4857282009-11-13 19:56:17356 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20357 UserScript *instance);
358
[email protected]867a73e12010-03-19 20:45:46359 // Checks that apps features are enabled if the manifest tries to use any of
360 // them.
361 bool CheckAppsAreEnabled(const DictionaryValue* manifest, std::string* error);
362
363 // Helpers to load various chunks of the manifest.
364 bool LoadWebContentEnabled(const DictionaryValue* manifest,
365 std::string* error);
366 bool LoadWebOrigin(const DictionaryValue* manifest, std::string* error);
367 bool LoadWebPaths(const DictionaryValue* manifest, std::string* error);
368 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
369 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error);
370
[email protected]5d246db22009-10-27 06:17:57371 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08372 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57373 ExtensionAction* LoadExtensionActionHelper(
[email protected]92c6f9b92009-10-24 04:35:08374 const DictionaryValue* extension_action, std::string* error);
375
[email protected]e2eb43112009-05-29 21:19:54376 // Figures out if a source contains keys not associated with themes - we
377 // don't want to allow scripts and such to be bundled with themes.
378 bool ContainsNonThemeKeys(const DictionaryValue& source);
379
[email protected]1952c7d2010-03-04 23:48:34380 // Returns true if the string is one of the known api permissions (see
381 // kPermissionNames).
382 bool IsAPIPermission(const std::string& permission);
383
[email protected]4a8d3272009-03-10 19:15:08384 // The absolute path to the directory the extension is stored in.
385 FilePath path_;
386
387 // The base extension url for the extension.
388 GURL extension_url_;
[email protected]eab9b452009-01-23 20:48:59389
[email protected]631cf822009-05-15 07:01:25390 // The location the extension was loaded from.
391 Location location_;
392
[email protected]7713d632008-12-02 07:52:33393 // A human-readable ID for the extension. The convention is to use something
394 // like 'com.example.myextension', but this is not currently enforced. An
395 // extension's ID is used in things like directory structures and URLs, and
396 // is expected to not change across versions. In the case of conflicts,
397 // updates will only be allowed if the extension can be validated using the
398 // previous version's update key.
[email protected]e1cec06c2008-12-18 01:22:23399 std::string id_;
[email protected]82891262008-12-24 00:21:26400
[email protected]64a02b802009-01-12 19:36:42401 // The extension's version.
[email protected]cc655912009-01-29 23:19:19402 scoped_ptr<Version> version_;
[email protected]64a02b802009-01-12 19:36:42403
[email protected]82891262008-12-24 00:21:26404 // The extension's human-readable name.
[email protected]e1cec06c2008-12-18 01:22:23405 std::string name_;
[email protected]82891262008-12-24 00:21:26406
[email protected]4a8d3272009-03-10 19:15:08407 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:23408 std::string description_;
[email protected]82891262008-12-24 00:21:26409
[email protected]6657afa62009-11-04 02:15:20410 // True if the extension was generated from a user script. (We show slightly
411 // different UI if so).
412 bool converted_from_user_script_;
413
[email protected]82891262008-12-24 00:21:26414 // Paths to the content scripts the extension contains.
[email protected]34aa8dc2009-02-19 07:03:05415 UserScriptList content_scripts_;
[email protected]7713d632008-12-02 07:52:33416
[email protected]37e960e2009-10-13 23:17:50417 // The extension's page action, if any.
[email protected]5d246db22009-10-27 06:17:57418 scoped_ptr<ExtensionAction> page_action_;
[email protected]671e6c1ce2009-09-26 03:18:46419
420 // The extension's browser action, if any.
[email protected]5d246db22009-10-27 06:17:57421 scoped_ptr<ExtensionAction> browser_action_;
[email protected]ec9ac0df2009-10-01 18:06:47422
[email protected]c533bb22009-06-03 19:06:11423 // Optional list of NPAPI plugins and associated properties.
424 std::vector<PluginInfo> plugins_;
[email protected]367230c52009-02-21 01:44:30425
[email protected]c64631652009-04-29 22:24:31426 // Optional URL to a master page of which a single instance should be always
427 // loaded in the background.
428 GURL background_url_;
429
[email protected]43919ac92009-10-16 18:34:28430 // Optional URL to a page for setting options/preferences.
431 GURL options_url_;
432
[email protected]bbc945542009-07-26 00:11:42433 // Optional list of toolstrips_ and associated properties.
434 std::vector<ToolstripInfo> toolstrips_;
[email protected]4a8d3272009-03-10 19:15:08435
[email protected]fbcc40302009-06-12 20:45:45436 // The public key ('key' in the manifest) used to sign the contents of the
437 // crx package ('signature' in the manifest)
438 std::string public_key_;
[email protected]cc655912009-01-29 23:19:19439
[email protected]07c00d992009-03-04 20:27:04440 // A map of resource id's to relative file paths.
[email protected]bbb436f2009-05-09 16:51:07441 scoped_ptr<DictionaryValue> theme_images_;
[email protected]4a190632009-05-09 01:07:42442
443 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07444 scoped_ptr<DictionaryValue> theme_colors_;
[email protected]4a190632009-05-09 01:07:42445
446 // A map of color names to colors.
[email protected]bbb436f2009-05-09 16:51:07447 scoped_ptr<DictionaryValue> theme_tints_;
[email protected]4a190632009-05-09 01:07:42448
[email protected]7895ea22009-06-02 20:53:50449 // A map of display properties.
450 scoped_ptr<DictionaryValue> theme_display_properties_;
451
[email protected]4a190632009-05-09 01:07:42452 // Whether the extension is a theme - if it is, certain things are disabled.
453 bool is_theme_;
[email protected]07c00d992009-03-04 20:27:04454
[email protected]35506352009-08-07 18:58:19455 // The set of module-level APIs this extension can use.
456 std::vector<std::string> api_permissions_;
457
[email protected]c64631652009-04-29 22:24:31458 // The sites this extension has permission to talk to (using XHR, etc).
[email protected]b30e0dd2010-01-29 23:33:21459 URLPatternList host_permissions_;
[email protected]7197f4992009-03-23 05:05:49460
[email protected]c3e3def742009-07-17 07:51:06461 // The paths to the icons the extension contains mapped by their width.
462 std::map<int, std::string> icons_;
463
[email protected]b29682ba22009-06-18 19:53:56464 // URL for fetching an update manifest
465 GURL update_url_;
[email protected]d6336a92009-08-13 17:25:12466
[email protected]b6ab96d2009-08-20 18:58:19467 // A copy of the manifest that this extension was created from.
468 scoped_ptr<DictionaryValue> manifest_value_;
469
[email protected]9428edc2009-11-18 18:02:47470 // Default locale for fall back. Can be empty if extension is not localized.
471 std::string default_locale_;
472
[email protected]86c008e82009-08-28 20:26:05473 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
474 // which override the handling of those URLs.
[email protected]d3cfa482009-10-17 13:54:57475 URLOverrideMap chrome_url_overrides_;
[email protected]86c008e82009-08-28 20:26:05476
[email protected]867a73e12010-03-19 20:45:46477 // Whether apps-related features can be parsed during InitFromValue().
478 // Defaults to the value from --enable-extension-apps.
479 bool apps_enabled_;
[email protected]581b0ad2010-01-12 21:54:38480
[email protected]867a73e12010-03-19 20:45:46481 // Whether the extension can contain live web content. Defaults to false.
482 bool web_content_enabled_;
[email protected]3b355642010-02-05 16:01:49483
[email protected]867a73e12010-03-19 20:45:46484 // Defines the set of URLs in the extension's web content.
485 ExtensionExtent web_extent_;
[email protected]3b355642010-02-05 16:01:49486
[email protected]867a73e12010-03-19 20:45:46487 // The local path inside the extension to use with the launcher.
488 std::string launch_local_path_;
489
490 // A web url to use with the launcher. Note that this might be relative or
491 // absolute. If relative, it is relative to web_origin_.
492 std::string launch_web_url_;
493
494 // The type of container to launch into.
495 LaunchContainer launch_container_;
496
[email protected]d9ad80f2010-03-30 20:40:18497 // Cached images for this extension. This maps from the relative_path of the
498 // resource to the cached image.
499 ImageCache image_cache_;
[email protected]ceefd3d2010-03-12 09:10:29500
[email protected]e95ad332009-08-03 19:44:25501 // Runtime data:
502
503 // True if the background page is ready.
504 bool background_page_ready_;
[email protected]b29682ba22009-06-18 19:53:56505
[email protected]1e8c93f2010-02-08 22:58:31506 // True while the extension is being upgraded.
507 bool being_upgraded_;
508
[email protected]ae7fe712009-07-02 20:33:58509 FRIEND_TEST(ExtensionTest, LoadPageActionHelper);
[email protected]3b355642010-02-05 16:01:49510 FRIEND_TEST(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58511
[email protected]894bb502009-05-21 22:39:57512 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33513};
514
[email protected]b1748b1d82009-11-30 20:32:56515typedef std::vector<Extension*> ExtensionList;
516
[email protected]c6d474f82009-12-16 21:11:06517// Handy struct to pass core extension info around.
518struct ExtensionInfo {
519 ExtensionInfo(const DictionaryValue* manifest,
520 const std::string& id,
521 const FilePath& path,
522 Extension::Location location)
523 : extension_id(id),
524 extension_path(path),
525 extension_location(location) {
526 if (manifest)
527 extension_manifest.reset(
528 static_cast<DictionaryValue*>(manifest->DeepCopy()));
529 }
530
531 scoped_ptr<DictionaryValue> extension_manifest;
532 std::string extension_id;
533 FilePath extension_path;
534 Extension::Location extension_location;
535
536 private:
537 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
538};
539
[email protected]5b1a0e22009-05-26 19:00:58540#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_