diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 22:50:29 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 22:50:29 +0000 |
commit | c64eb4096d30f3018ccd75d076fb90304f0143b7 (patch) | |
tree | 8bd88bcdcb25fb4dabb31935ea38283c3b9f7b0d /chrome/common/extensions | |
parent | 829cb7a1163a73c410d0eb248f1d90116f390429 (diff) | |
download | chromium_src-c64eb4096d30f3018ccd75d076fb90304f0143b7.zip chromium_src-c64eb4096d30f3018ccd75d076fb90304f0143b7.tar.gz chromium_src-c64eb4096d30f3018ccd75d076fb90304f0143b7.tar.bz2 |
Part 4/4 of immutable Extension refactor: Kill Extension::StaticData and put
its guts into Extension.
BUG=56558
TEST=no functional change
Review URL: http://codereview.chromium.org/4200005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64676 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r-- | chrome/common/extensions/extension.cc | 194 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 464 | ||||
-rw-r--r-- | chrome/common/extensions/extension_unittest.cc | 2 |
3 files changed, 291 insertions, 369 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 5d87fd0..2ba995c 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -249,24 +249,6 @@ const size_t Extension::kNumHostedAppPermissions = const char Extension::kOldUnlimitedStoragePermission[] = "unlimited_storage"; // -// Extension::StaticData -// - -Extension::StaticData::StaticData() - : incognito_split_mode(false), - location(INVALID), - converted_from_user_script(false), - is_theme(false), - is_app(false), - launch_container(extension_misc::LAUNCH_TAB), - launch_width(0), - launch_height(0) { -} - -Extension::StaticData::~StaticData() { -} - -// // Extension::RuntimeData // @@ -794,7 +776,7 @@ bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) const { bool Extension::LoadIsApp(const DictionaryValue* manifest, std::string* error) { if (manifest->HasKey(keys::kApp)) - mutable_static_data_->is_app = true; + is_app_ = true; return true; } @@ -882,7 +864,7 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest, return false; } - mutable_static_data_->launch_local_path = launch_path; + launch_local_path_ = launch_path; } else if (manifest->Get(keys::kLaunchWebURL, &temp)) { std::string launch_url; if (!temp->GetAsString(&launch_url)) { @@ -896,7 +878,7 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest, return false; } - mutable_static_data_->launch_web_url = launch_url; + launch_web_url_ = launch_url; } else if (is_app()) { *error = errors::kLaunchURLRequired; return false; @@ -912,7 +894,7 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest, } pattern.set_host(launch_url.host()); pattern.set_path("/*"); - mutable_static_data_->extent.AddPattern(pattern); + extent_.AddPattern(pattern); } // In order for the --apps-gallery-url switch to work with the gallery @@ -922,12 +904,12 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest, GURL gallery_url(CommandLine::ForCurrentProcess()-> GetSwitchValueASCII(switches::kAppsGalleryURL)); if (gallery_url.is_valid()) { - mutable_static_data_->launch_web_url = gallery_url.spec(); + launch_web_url_ = gallery_url.spec(); URLPattern pattern(URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS); pattern.Parse(gallery_url.spec()); pattern.set_path(pattern.path() + '*'); - mutable_static_data_->extent.AddPattern(pattern); + extent_.AddPattern(pattern); } } @@ -947,9 +929,9 @@ bool Extension::LoadLaunchContainer(const DictionaryValue* manifest, } if (launch_container_string == values::kLaunchContainerPanel) { - mutable_static_data_->launch_container = extension_misc::LAUNCH_PANEL; + launch_container_ = extension_misc::LAUNCH_PANEL; } else if (launch_container_string == values::kLaunchContainerTab) { - mutable_static_data_->launch_container = extension_misc::LAUNCH_TAB; + launch_container_ = extension_misc::LAUNCH_TAB; } else { *error = errors::kInvalidLaunchContainer; return false; @@ -962,9 +944,9 @@ bool Extension::LoadLaunchContainer(const DictionaryValue* manifest, *error = errors::kInvalidLaunchWidthContainer; return false; } - if (!temp->GetAsInteger(&mutable_static_data_->launch_width) || - mutable_static_data_->launch_width < 0) { - mutable_static_data_->launch_width = 0; + if (!temp->GetAsInteger(&launch_width_) || + launch_width_ < 0) { + launch_width_ = 0; *error = errors::kInvalidLaunchWidth; return false; } @@ -977,9 +959,8 @@ bool Extension::LoadLaunchContainer(const DictionaryValue* manifest, *error = errors::kInvalidLaunchHeightContainer; return false; } - if (!temp->GetAsInteger(&mutable_static_data_->launch_height) || - mutable_static_data_->launch_height < 0) { - mutable_static_data_->launch_height = 0; + if (!temp->GetAsInteger(&launch_height_) || launch_height_ < 0) { + launch_height_ = 0; *error = errors::kInvalidLaunchHeight; return false; } @@ -1008,12 +989,16 @@ bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest, } Extension::Extension(const FilePath& path, Location location) - : mutable_static_data_(new StaticData) { + : incognito_split_mode_(false), + location_(location), + converted_from_user_script_(false), + is_theme_(false), + is_app_(false), + launch_container_(extension_misc::LAUNCH_TAB), + launch_width_(0), + launch_height_(0) { DCHECK(path.IsAbsolute()); - - static_data_ = mutable_static_data_; - mutable_static_data_->location = location; - mutable_static_data_->path = MaybeNormalizePath(path); + path_ = MaybeNormalizePath(path); } Extension::~Extension() { @@ -1211,17 +1196,13 @@ GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, std::string* error) { - // Unit tests reuse Extension objects, so we need to reset mutable_static_data - // when we re-initialize. - mutable_static_data_ = const_cast<StaticData*>(static_data_.get()); - if (source.HasKey(keys::kPublicKey)) { std::string public_key_bytes; if (!source.GetString(keys::kPublicKey, - &mutable_static_data_->public_key) || - !ParsePEMKeyBytes(mutable_static_data_->public_key, + &public_key_) || + !ParsePEMKeyBytes(public_key_, &public_key_bytes) || - !GenerateId(public_key_bytes, &mutable_static_data_->id)) { + !GenerateId(public_key_bytes, &id_)) { *error = errors::kInvalidKey; return false; } @@ -1232,19 +1213,19 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, // If there is a path, we generate the ID from it. This is useful for // development mode, because it keeps the ID stable across restarts and // reloading the extension. - mutable_static_data_->id = Extension::GenerateIdForPath(path()); - if (mutable_static_data_->id.empty()) { + id_ = Extension::GenerateIdForPath(path()); + if (id_.empty()) { NOTREACHED() << "Could not create ID from path."; return false; } } // Make a copy of the manifest so we can store it in prefs. - mutable_static_data_->manifest_value.reset( + manifest_value_.reset( static_cast<DictionaryValue*>(source.DeepCopy())); // Initialize the URL. - mutable_static_data_->extension_url = + extension_url_ = Extension::GetBaseURLFromExtensionId(id()); // Initialize version. @@ -1253,10 +1234,10 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, *error = errors::kInvalidVersion; return false; } - mutable_static_data_->version.reset( + version_.reset( Version::GetVersionFromString(version_str)); - if (!mutable_static_data_->version.get() || - mutable_static_data_->version->components().size() > 4) { + if (!version_.get() || + version_->components().size() > 4) { *error = errors::kInvalidVersion; return false; } @@ -1268,12 +1249,12 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } base::i18n::AdjustStringForLocaleDirection(localized_name, &localized_name); - mutable_static_data_->name = UTF16ToUTF8(localized_name); + name_ = UTF16ToUTF8(localized_name); // Initialize description (if present). if (source.HasKey(keys::kDescription)) { if (!source.GetString(keys::kDescription, - &mutable_static_data_->description)) { + &description_)) { *error = errors::kInvalidDescription; return false; } @@ -1287,8 +1268,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, errors::kInvalidHomepageURL, ""); return false; } - mutable_static_data_->homepage_url = GURL(tmp); - if (!mutable_static_data_->homepage_url.is_valid()) { + homepage_url_ = GURL(tmp); + if (!homepage_url_.is_valid()) { *error = ExtensionErrorUtils::FormatErrorMessage( errors::kInvalidHomepageURL, tmp); return false; @@ -1303,9 +1284,9 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, errors::kInvalidUpdateURL, ""); return false; } - mutable_static_data_->update_url = GURL(tmp); - if (!mutable_static_data_->update_url.is_valid() || - mutable_static_data_->update_url.has_ref()) { + update_url_ = GURL(tmp); + if (!update_url_.is_valid() || + update_url_.has_ref()) { *error = ExtensionErrorUtils::FormatErrorMessage( errors::kInvalidUpdateURL, tmp); return false; @@ -1353,7 +1334,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, // Initialize converted_from_user_script (if present) source.GetBoolean(keys::kConvertedFromUserScript, - &mutable_static_data_->converted_from_user_script); + &converted_from_user_script_); // Initialize icons (if present). if (source.HasKey(keys::kIcons)) { @@ -1382,13 +1363,13 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } - mutable_static_data_->icons.Add(kIconSizes[i], icon_path); + icons_.Add(kIconSizes[i], icon_path); } } } // Initialize themes (if present). - mutable_static_data_->is_theme = false; + is_theme_ = false; if (source.HasKey(keys::kTheme)) { // Themes cannot contain extension keys. if (ContainsNonThemeKeys(source)) { @@ -1401,7 +1382,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, *error = errors::kInvalidTheme; return false; } - mutable_static_data_->is_theme = true; + is_theme_ = true; DictionaryValue* images_value; if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { @@ -1414,7 +1395,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } } - mutable_static_data_->theme_images.reset( + theme_images_.reset( static_cast<DictionaryValue*>(images_value->DeepCopy())); } @@ -1443,7 +1424,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } } - mutable_static_data_->theme_colors.reset( + theme_colors_.reset( static_cast<DictionaryValue*>(colors_value->DeepCopy())); } @@ -1464,14 +1445,14 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } } - mutable_static_data_->theme_tints.reset( + theme_tints_.reset( static_cast<DictionaryValue*>(tints_value->DeepCopy())); } DictionaryValue* display_properties_value; if (theme_value->GetDictionary(keys::kThemeDisplayProperties, &display_properties_value)) { - mutable_static_data_->theme_display_properties.reset( + theme_display_properties_.reset( static_cast<DictionaryValue*>(display_properties_value->DeepCopy())); } @@ -1519,9 +1500,9 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, } } - mutable_static_data_->plugins.push_back(PluginInfo()); - mutable_static_data_->plugins.back().path = path().AppendASCII(path_str); - mutable_static_data_->plugins.back().is_public = is_public; + plugins_.push_back(PluginInfo()); + plugins_.back().path = path().AppendASCII(path_str); + plugins_.back().is_public = is_public; } } @@ -1532,7 +1513,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, *error = errors::kInvalidBackground; return false; } - mutable_static_data_->background_url = GetResourceURL(background_str); + background_url_ = GetResourceURL(background_str); } // Initialize toolstrips. This is deprecated for public use. @@ -1567,7 +1548,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, errors::kInvalidToolstrip, base::IntToString(i)); return false; } - mutable_static_data_->toolstrips.push_back(toolstrip); + toolstrips_.push_back(toolstrip); } } @@ -1591,11 +1572,11 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, if (!LoadUserScriptHelper(content_script, i, error, &script)) return false; // Failed to parse script context definition. script.set_extension_id(id()); - if (mutable_static_data_->converted_from_user_script) { + if (converted_from_user_script_) { script.set_emulate_greasemonkey(true); script.set_match_all_frames(true); // Greasemonkey matches all frames. } - mutable_static_data_->content_scripts.push_back(script); + content_scripts_.push_back(script); } } @@ -1632,9 +1613,9 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, // If page_action_value is not NULL, then there was a valid page action. if (page_action_value) { - mutable_static_data_->page_action.reset( + page_action_.reset( LoadExtensionActionHelper(page_action_value, error)); - if (!mutable_static_data_->page_action.get()) + if (!page_action_.get()) return false; // Failed to parse page action definition. } @@ -1646,25 +1627,25 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } - mutable_static_data_->browser_action.reset( + browser_action_.reset( LoadExtensionActionHelper(browser_action_value, error)); - if (!mutable_static_data_->browser_action.get()) + if (!browser_action_.get()) return false; // Failed to parse browser action definition. } // Load App settings. - if (!LoadIsApp(mutable_static_data_->manifest_value.get(), error) || - !LoadExtent(mutable_static_data_->manifest_value.get(), keys::kWebURLs, - &mutable_static_data_->extent, + if (!LoadIsApp(manifest_value_.get(), error) || + !LoadExtent(manifest_value_.get(), keys::kWebURLs, + &extent_, errors::kInvalidWebURLs, errors::kInvalidWebURL, error) || - !EnsureNotHybridApp(mutable_static_data_->manifest_value.get(), error) || - !LoadLaunchURL(mutable_static_data_->manifest_value.get(), error) || - !LoadLaunchContainer(mutable_static_data_->manifest_value.get(), error)) { + !EnsureNotHybridApp(manifest_value_.get(), error) || + !LoadLaunchURL(manifest_value_.get(), error) || + !LoadLaunchContainer(manifest_value_.get(), error)) { return false; } // Initialize options page url (optional). - // Funtion LoadIsApp() set mutable_static_data_->is_app above. + // Funtion LoadIsApp() set is_app_ above. if (source.HasKey(keys::kOptionsPage)) { std::string options_str; if (!source.GetString(keys::kOptionsPage, &options_str)) { @@ -1680,7 +1661,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, *error = errors::kInvalidOptionsPageInHostedApp; return false; } - mutable_static_data_->options_url = options_url; + options_url_ = options_url; } else { GURL absolute(options_str); @@ -1688,8 +1669,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, *error = errors::kInvalidOptionsPageExpectUrlInPackage; return false; } - mutable_static_data_->options_url = GetResourceURL(options_str); - if (!mutable_static_data_->options_url.is_valid()) { + options_url_ = GetResourceURL(options_str); + if (!options_url_.is_valid()) { *error = errors::kInvalidOptionsPage; return false; } @@ -1717,7 +1698,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, // TODO(asargent) - We want a more general purpose mechanism for this, // and better error messages. (http://crbug.com/54013) if (permission_str == kWebstorePrivatePermission && - mutable_static_data_->location != Extension::COMPONENT) { + location_ != Extension::COMPONENT) { continue; } @@ -1728,13 +1709,13 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, if (web_extent().is_empty() || location() == Extension::COMPONENT) { // Check if it's a module permission. If so, enable that permission. if (IsAPIPermission(permission_str)) { - mutable_static_data_->api_permissions.insert(permission_str); + api_permissions_.insert(permission_str); continue; } } else { // Hosted apps only get access to a subset of the valid permissions. if (IsHostedAppPermission(permission_str)) { - mutable_static_data_->api_permissions.insert(permission_str); + api_permissions_.insert(permission_str); continue; } } @@ -1761,14 +1742,14 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, // match all paths. pattern.set_path("/*"); - mutable_static_data_->host_permissions.push_back(pattern); + host_permissions_.push_back(pattern); } } if (source.HasKey(keys::kDefaultLocale)) { if (!source.GetString(keys::kDefaultLocale, - &mutable_static_data_->default_locale) || - mutable_static_data_->default_locale.empty()) { + &default_locale_) || + default_locale_.empty()) { *error = errors::kInvalidDefaultLocale; return false; } @@ -1799,7 +1780,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } // Replace the entry with a fully qualified chrome-extension:// URL. - mutable_static_data_->chrome_url_overrides[page] = GetResourceURL(val); + chrome_url_overrides_[page] = GetResourceURL(val); } // An extension may override at most one page. @@ -1811,8 +1792,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, if (source.HasKey(keys::kOmniboxKeyword)) { if (!source.GetString(keys::kOmniboxKeyword, - &mutable_static_data_->omnibox_keyword) || - mutable_static_data_->omnibox_keyword.empty()) { + &omnibox_keyword_) || + omnibox_keyword_.empty()) { *error = errors::kInvalidOmniboxKeyword; return false; } @@ -1833,12 +1814,12 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, *error = errors::kDevToolsExperimental; return false; } - mutable_static_data_->devtools_url = GetResourceURL(devtools_str); + devtools_url_ = GetResourceURL(devtools_str); } // Initialize incognito behavior. Apps default to split mode, extensions // default to spanning. - mutable_static_data_->incognito_split_mode = is_app(); + incognito_split_mode_ = is_app(); if (source.HasKey(keys::kIncognito)) { std::string value; if (!source.GetString(keys::kIncognito, &value)) { @@ -1846,9 +1827,9 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } if (value == values::kIncognitoSpanning) { - mutable_static_data_->incognito_split_mode = false; + incognito_split_mode_ = false; } else if (value == values::kIncognitoSplit) { - mutable_static_data_->incognito_split_mode = true; + incognito_split_mode_ = true; } else { *error = errors::kInvalidIncognitoBehavior; return false; @@ -1867,10 +1848,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, // it calls InitFromValue, passing it up to the browser process which calls // InitFromValue again. As a result, we need to make sure that nobody // accidentally modifies it. - DCHECK(source.Equals(mutable_static_data_->manifest_value.get())); - - // Ensure we can't modify our static data anymore. - mutable_static_data_ = NULL; + DCHECK(source.Equals(manifest_value_.get())); return true; } @@ -1887,8 +1865,8 @@ std::string Extension::ChromeStoreLaunchURL() { } GURL Extension::GetHomepageURL() const { - if (static_data_->homepage_url.is_valid()) - return static_data_->homepage_url; + if (homepage_url_.is_valid()) + return homepage_url_; if (update_url()!= GURL(extension_urls::kGalleryUpdateHttpsUrl) && update_url()!= GURL(extension_urls::kGalleryUpdateHttpUrl)) @@ -2113,7 +2091,7 @@ bool Extension::HasHostPermission(const GURL& url) const { void Extension::InitEffectiveHostPermissions() { for (URLPatternList::const_iterator host = host_permissions().begin(); host != host_permissions().end(); ++host) - mutable_static_data_->effective_host_permissions.AddPattern(*host); + effective_host_permissions_.AddPattern(*host); for (UserScriptList::const_iterator content_script = content_scripts().begin(); @@ -2121,7 +2099,7 @@ void Extension::InitEffectiveHostPermissions() { UserScript::PatternList::const_iterator pattern = content_script->url_patterns().begin(); for (; pattern != content_script->url_patterns().end(); ++pattern) - mutable_static_data_->effective_host_permissions.AddPattern(*pattern); + effective_host_permissions_.AddPattern(*pattern); } } diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 08e4bbb..b96eaec 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -100,151 +100,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> { bool is_public; // False if only this extension can load this plugin. }; - // Contains a subset of the extension's data that doesn't change once - // initialized, and therefore shareable across threads without locking. - struct StaticData : public base::RefCountedThreadSafe<StaticData> { - StaticData(); - - // A persistent, globally unique ID. An extension's ID is used in things - // like directory structures and URLs, and is expected to not change across - // versions. It is generated as a SHA-256 hash of the extension's public - // key, or as a hash of the path in the case of unpacked extensions. - std::string id; - - // The extension's human-readable name. Name is used for display purpose. It - // might be wrapped with unicode bidi control characters so that it is - // displayed correctly in RTL context. - // NOTE: Name is UTF-8 and may contain non-ascii characters. - std::string name; - - // The absolute path to the directory the extension is stored in. - FilePath path; - - // Default locale for fall back. Can be empty if extension is not localized. - std::string default_locale; - - // If true, a separate process will be used for the extension in incognito - // mode. - bool incognito_split_mode; - - // Defines the set of URLs in the extension's web content. - ExtensionExtent extent; - - // The set of host permissions that the extension effectively has access to, - // which is a merge of host_permissions_ and all of the match patterns in - // any content scripts the extension has. This is used to determine which - // URLs have the ability to load an extension's resources via embedded - // chrome-extension: URLs (see extension_protocols.cc). - ExtensionExtent effective_host_permissions; - - // The set of module-level APIs this extension can use. - std::set<std::string> api_permissions; - - // The icons for the extension. - ExtensionIconSet icons; - - // The base extension url for the extension. - GURL extension_url; - - // The location the extension was loaded from. - Location location; - - // The extension's version. - scoped_ptr<Version> version; - - // An optional longer description of the extension. - std::string description; - - // True if the extension was generated from a user script. (We show slightly - // different UI if so). - bool converted_from_user_script; - - // Paths to the content scripts the extension contains. - UserScriptList content_scripts; - - // The extension's page action, if any. - scoped_ptr<ExtensionAction> page_action; - - // The extension's browser action, if any. - scoped_ptr<ExtensionAction> browser_action; - - // Optional list of NPAPI plugins and associated properties. - std::vector<PluginInfo> plugins; - - // Optional URL to a master page of which a single instance should be always - // loaded in the background. - GURL background_url; - - // Optional URL to a page for setting options/preferences. - GURL options_url; - - // Optional URL to a devtools extension page. - GURL devtools_url; - - // Optional list of toolstrips and associated properties. - std::vector<GURL> toolstrips; - - // The public key used to sign the contents of the crx package. - std::string public_key; - - // A map of resource id's to relative file paths. - scoped_ptr<DictionaryValue> theme_images; - - // A map of color names to colors. - scoped_ptr<DictionaryValue> theme_colors; - - // A map of color names to colors. - scoped_ptr<DictionaryValue> theme_tints; - - // A map of display properties. - scoped_ptr<DictionaryValue> theme_display_properties; - - // Whether the extension is a theme. - bool is_theme; - - // The sites this extension has permission to talk to (using XHR, etc). - URLPatternList host_permissions; - - // The homepage for this extension. Useful if it is not hosted by Google and - // therefore does not have a Gallery URL. - GURL homepage_url; - - // URL for fetching an update manifest - GURL update_url; - - // A copy of the manifest that this extension was created from. - scoped_ptr<DictionaryValue> manifest_value; - - // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs - // which override the handling of those URLs. - URLOverrideMap chrome_url_overrides; - - // Whether this extension uses app features. - bool is_app; - - // The local path inside the extension to use with the launcher. - std::string launch_local_path; - - // A web url to use with the launcher. Note that this might be relative or - // absolute. If relative, it is relative to web_origin. - std::string launch_web_url; - - // The type of container to launch into. - extension_misc::LaunchContainer launch_container; - - // The default size of the container when launching. Only respected for - // containers like panels and windows. - int launch_width; - int launch_height; - - // The Omnibox keyword for this extension, or empty if there is none. - std::string omnibox_keyword; - - protected: - friend class base::RefCountedThreadSafe<StaticData>; - ~StaticData(); - }; - // Contains the subset of the extension's (private) data that can be modified // after initialization. This class should only be accessed on the UI thread. struct RuntimeData { @@ -464,46 +319,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // Adds an extension to the scripting whitelist. Used for testing only. static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); - const StaticData* static_data() const { return static_data_; } - - const FilePath& path() const { return static_data_->path; } - const GURL& url() const { return static_data_->extension_url; } - Location location() const { return static_data_->location; } - const std::string& id() const { return static_data_->id; } - const Version* version() const { return static_data_->version.get(); } - // String representation of the version number. - const std::string VersionString() const; - const std::string& name() const { return static_data_->name; } - const std::string& public_key() const { return static_data_->public_key; } - const std::string& description() const { return static_data_->description; } - bool converted_from_user_script() const { - return static_data_->converted_from_user_script; - } - const UserScriptList& content_scripts() const { - return static_data_->content_scripts; - } - ExtensionAction* page_action() const { - return static_data_->page_action.get(); - } - ExtensionAction* browser_action() const { - return static_data_->browser_action.get(); - } - const std::vector<PluginInfo>& plugins() const { - return static_data_->plugins; - } - const GURL& background_url() const { return static_data_->background_url; } - const GURL& options_url() const { return static_data_->options_url; } - const GURL& devtools_url() const { return static_data_->devtools_url; } - const std::vector<GURL>& toolstrips() const { - return static_data_->toolstrips; - } - const std::set<std::string>& api_permissions() const { - return static_data_->api_permissions; - } - const URLPatternList& host_permissions() const { - return static_data_->host_permissions; - } - // Returns true if the extension has the specified API permission. static bool HasApiPermission(const std::set<std::string>& api_permissions, const std::string& function_name); @@ -513,7 +328,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> { } const ExtensionExtent& GetEffectiveHostPermissions() const { - return static_data_->effective_host_permissions; + return effective_host_permissions_; } // Whether or not the extension is allowed permission for a URL pattern from @@ -532,32 +347,11 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // network, etc.) bool HasEffectiveAccessToAllHosts() const; - const GURL& update_url() const { return static_data_->update_url; } - - const ExtensionIconSet& icons() const { - return static_data_->icons; - } - // Returns the Homepage URL for this extension. If homepage_url was not // specified in the manifest, this returns the Google Gallery URL. For // third-party extensions, this returns a blank GURL. GURL GetHomepageURL() const; - // Theme-related. - DictionaryValue* GetThemeImages() const { - return static_data_->theme_images.get(); - } - DictionaryValue* GetThemeColors() const { - return static_data_->theme_colors.get(); - } - DictionaryValue* GetThemeTints() const { - return static_data_->theme_tints.get(); - } - DictionaryValue* GetThemeDisplayProperties() const { - return static_data_->theme_display_properties.get(); - } - bool is_theme() const { return static_data_->is_theme; } - // Returns a list of paths (relative to the extension dir) for images that // the browser might load (like themes and page action icons). std::set<FilePath> GetBrowserImages() const; @@ -567,44 +361,84 @@ class Extension : public base::RefCountedThreadSafe<Extension> { int size, ExtensionIconSet::MatchType match_type) const; GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; - const DictionaryValue* manifest_value() const { - return static_data_->manifest_value.get(); - } - const std::string default_locale() const { - return static_data_->default_locale; - } + // Gets the fully resolved absolute launch URL. + GURL GetFullLaunchURL() const; - // Chrome URL overrides (see ExtensionOverrideUI). - const URLOverrideMap& GetChromeURLOverrides() const { - return static_data_->chrome_url_overrides; - } + // Image cache related methods. These are only valid on the UI thread and + // not maintained by this class. See ImageLoadingTracker for usage. The + // |original_size| parameter should be the size of the image at |source| + // before any scaling may have been done to produce the pixels in |image|. + void SetCachedImage(const ExtensionResource& source, + const SkBitmap& image, + const gfx::Size& original_size) const; + bool HasCachedImage(const ExtensionResource& source, + const gfx::Size& max_size) const; + SkBitmap GetCachedImage(const ExtensionResource& source, + const gfx::Size& max_size) const; + // Returns true if this extension is a COMPONENT extension, or if it is + // on the whitelist of extensions that can script all pages. + bool CanExecuteScriptEverywhere() const; - const std::string omnibox_keyword() const { - return static_data_->omnibox_keyword; - } + // Accessors: - bool is_app() const { return static_data_->is_app; } - const ExtensionExtent& web_extent() const { - return static_data_->extent; + const FilePath& path() const { return path_; } + const GURL& url() const { return extension_url_; } + Location location() const { return location_; } + const std::string& id() const { return id_; } + const Version* version() const { return version_.get(); } + const std::string VersionString() const; + const std::string& name() const { return name_; } + const std::string& public_key() const { return public_key_; } + const std::string& description() const { return description_; } + bool converted_from_user_script() const { + return converted_from_user_script_; + } + const UserScriptList& content_scripts() const { return content_scripts_; } + ExtensionAction* page_action() const { return page_action_.get(); } + ExtensionAction* browser_action() const { return browser_action_.get(); } + const std::vector<PluginInfo>& plugins() const { return plugins_; } + const GURL& background_url() const { return background_url_; } + const GURL& options_url() const { return options_url_; } + const GURL& devtools_url() const { return devtools_url_; } + const std::vector<GURL>& toolstrips() const { return toolstrips_; } + const std::set<std::string>& api_permissions() const { + return api_permissions_; } - const std::string& launch_local_path() const { - return static_data_->launch_local_path; + const URLPatternList& host_permissions() const { return host_permissions_; } + const GURL& update_url() const { return update_url_; } + const ExtensionIconSet& icons() const { return icons_; } + const DictionaryValue* manifest_value() const { + return manifest_value_.get(); } - const std::string& launch_web_url() const { - return static_data_->launch_web_url; + const std::string default_locale() const { return default_locale_; } + const URLOverrideMap& GetChromeURLOverrides() const { + return chrome_url_overrides_; } + const std::string omnibox_keyword() const { return omnibox_keyword_; } + bool incognito_split_mode() const { return incognito_split_mode_; } + + // App-related. + bool is_app() const { return is_app_; } + bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } + bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } + const ExtensionExtent& web_extent() const { return extent_; } + const std::string& launch_local_path() const { return launch_local_path_; } + const std::string& launch_web_url() const { return launch_web_url_; } extension_misc::LaunchContainer launch_container() const { - return static_data_->launch_container; - } - int launch_width() const { return static_data_->launch_width; } - int launch_height() const { return static_data_->launch_height; } - bool incognito_split_mode() const { - return static_data_->incognito_split_mode; + return launch_container_; } + int launch_width() const { return launch_width_; } + int launch_height() const { return launch_height_; } - // Gets the fully resolved absolute launch URL. - GURL GetFullLaunchURL() const; + // Theme-related. + bool is_theme() const { return is_theme_; } + DictionaryValue* GetThemeImages() const { return theme_images_.get(); } + DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } + DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } + DictionaryValue* GetThemeDisplayProperties() const { + return theme_display_properties_.get(); + } // Whether the background page, if any, is ready. We don't load other // components until then. If there is no background page, we consider it to @@ -619,24 +453,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> { GetRuntimeData()->being_upgraded = value; } - // Image cache related methods. These are only valid on the UI thread and - // not maintained by this class. See ImageLoadingTracker for usage. The - // |original_size| parameter should be the size of the image at |source| - // before any scaling may have been done to produce the pixels in |image|. - void SetCachedImage(const ExtensionResource& source, - const SkBitmap& image, - const gfx::Size& original_size) const; - bool HasCachedImage(const ExtensionResource& source, - const gfx::Size& max_size) const; - SkBitmap GetCachedImage(const ExtensionResource& source, - const gfx::Size& max_size) const; - bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } - bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } - - // Returns true if this extension is a COMPONENT extension, or if it is - // on the whitelist of extensions that can script all pages. - bool CanExecuteScriptEverywhere() const; - private: friend class base::RefCountedThreadSafe<Extension>; @@ -720,16 +536,144 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // the UI thread. RuntimeData* GetRuntimeData() const; - // Collection of extension data that doesn't change doesn't change once an - // Extension object has been initialized. The mutable version is valid only - // until InitFromValue finishes, to ensure we don't accidentally modify it - // post-initialization. - StaticData* mutable_static_data_; - scoped_refptr<const StaticData> static_data_; - // Runtime data. const RuntimeData runtime_data_; + // A persistent, globally unique ID. An extension's ID is used in things + // like directory structures and URLs, and is expected to not change across + // versions. It is generated as a SHA-256 hash of the extension's public + // key, or as a hash of the path in the case of unpacked extensions. + std::string id_; + + // The extension's human-readable name. Name is used for display purpose. It + // might be wrapped with unicode bidi control characters so that it is + // displayed correctly in RTL context. + // NOTE: Name is UTF-8 and may contain non-ascii characters. + std::string name_; + + // The absolute path to the directory the extension is stored in. + FilePath path_; + + // Default locale for fall back. Can be empty if extension is not localized. + std::string default_locale_; + + // If true, a separate process will be used for the extension in incognito + // mode. + bool incognito_split_mode_; + + // Defines the set of URLs in the extension's web content. + ExtensionExtent extent_; + + // The set of host permissions that the extension effectively has access to, + // which is a merge of host_permissions_ and all of the match patterns in + // any content scripts the extension has. This is used to determine which + // URLs have the ability to load an extension's resources via embedded + // chrome-extension: URLs (see extension_protocols.cc). + ExtensionExtent effective_host_permissions_; + + // The set of module-level APIs this extension can use. + std::set<std::string> api_permissions_; + + // The icons for the extension. + ExtensionIconSet icons_; + + // The base extension url for the extension. + GURL extension_url_; + + // The location the extension was loaded from. + Location location_; + + // The extension's version. + scoped_ptr<Version> version_; + + // An optional longer description of the extension. + std::string description_; + + // True if the extension was generated from a user script. (We show slightly + // different UI if so). + bool converted_from_user_script_; + + // Paths to the content scripts the extension contains. + UserScriptList content_scripts_; + + // The extension's page action, if any. + scoped_ptr<ExtensionAction> page_action_; + + // The extension's browser action, if any. + scoped_ptr<ExtensionAction> browser_action_; + + // Optional list of NPAPI plugins and associated properties. + std::vector<PluginInfo> plugins_; + + // Optional URL to a master page of which a single instance should be always + // loaded in the background. + GURL background_url_; + + // Optional URL to a page for setting options/preferences. + GURL options_url_; + + // Optional URL to a devtools extension page. + GURL devtools_url_; + + // Optional list of toolstrips and associated properties. + std::vector<GURL> toolstrips_; + + // The public key used to sign the contents of the crx package. + std::string public_key_; + + // A map of resource id's to relative file paths. + scoped_ptr<DictionaryValue> theme_images_; + + // A map of color names to colors. + scoped_ptr<DictionaryValue> theme_colors_; + + // A map of color names to colors. + scoped_ptr<DictionaryValue> theme_tints_; + + // A map of display properties. + scoped_ptr<DictionaryValue> theme_display_properties_; + + // Whether the extension is a theme. + bool is_theme_; + + // The sites this extension has permission to talk to (using XHR, etc). + URLPatternList host_permissions_; + + // The homepage for this extension. Useful if it is not hosted by Google and + // therefore does not have a Gallery URL. + GURL homepage_url_; + + // URL for fetching an update manifest + GURL update_url_; + + // A copy of the manifest that this extension was created from. + scoped_ptr<DictionaryValue> manifest_value_; + + // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs + // which override the handling of those URLs. (see ExtensionOverrideUI). + URLOverrideMap chrome_url_overrides_; + + // Whether this extension uses app features. + bool is_app_; + + // The local path inside the extension to use with the launcher. + std::string launch_local_path_; + + // A web url to use with the launcher. Note that this might be relative or + // absolute. If relative, it is relative to web_origin. + std::string launch_web_url_; + + // The type of container to launch into. + extension_misc::LaunchContainer launch_container_; + + // The default size of the container when launching. Only respected for + // containers like panels and windows. + int launch_width_; + int launch_height_; + + // The Omnibox keyword for this extension, or empty if there is none. + std::string omnibox_keyword_; + FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid); FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid); diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc index 9aec5fe..3f86bbd 100644 --- a/chrome/common/extensions/extension_unittest.cc +++ b/chrome/common/extensions/extension_unittest.cc @@ -549,7 +549,7 @@ TEST(ExtensionTest, LoadPageActionHelper) { // LoadExtensionActionHelper expects the extension member |extension_url| // to be set. - extension.mutable_static_data_->extension_url = + extension.extension_url_ = GURL(std::string(chrome::kExtensionScheme) + chrome::kStandardSchemeSeparator + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/"); |