Index: chrome/common/extensions/extension.cc |
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc |
index dc11856b2e10223da756c659f14447620a7e5215..6faa1d0c0296293084b4413660ddd9dc15497c66 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); |
} |
} |