Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1683)

Unified Diff: chrome/browser/extensions/extension.cc

Issue 60112: Implement chromium.self in content scripts, fix bugs (Closed)
Patch Set: fixedy fixedy Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension.cc
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc
index d8ab40379d0c0fde26f59ff8b724fc6bde4ea053..1aeaeaab67229608fc479c79caf011ac1a3cb298 100644
--- a/chrome/browser/extensions/extension.cc
+++ b/chrome/browser/extensions/extension.cc
@@ -103,21 +103,6 @@ Extension::Extension(const Extension& rhs)
theme_paths_(rhs.theme_paths_) {
}
-const GURL& Extension::url() {
- if (!extension_url_.is_valid())
- extension_url_ = GURL(std::string(chrome::kExtensionScheme) +
- chrome::kStandardSchemeSeparator + id_ + "/");
-
- return extension_url_;
-}
-
-void Extension::set_id(const std::string& id) {
- id_ = id;
-
- // Reset url_ so that it gets reinitialized next time.
- extension_url_ = GURL();
-}
-
const std::string Extension::VersionString() const {
return version_->GetString();
}
@@ -335,10 +320,9 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script,
return true;
}
-bool Extension::InitFromValue(const DictionaryValue& source,
+bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
std::string* error) {
- // Initialize id. The ID is not required here because we don't require IDs for
- // extensions used with --load-extension.
+ // Initialize id.
if (source.HasKey(kIdKey)) {
if (!source.GetString(kIdKey, &id_)) {
*error = kInvalidIdError;
@@ -356,8 +340,23 @@ bool Extension::InitFromValue(const DictionaryValue& source,
*error = kInvalidIdError;
return false;
}
+ } else if (require_id) {
+ *error = kInvalidIdError;
+ return false;
+ } else {
+ // Generate a random ID
+ static int counter = 0;
+ id_ = StringPrintf("%x", counter);
+ ++counter;
+
+ // pad the string out to 40 chars with zeroes.
+ id_.insert(0, 40 - id_.length(), '0');
}
+ // Initialize the URL.
+ extension_url_ = GURL(std::string(chrome::kExtensionScheme) +
+ chrome::kStandardSchemeSeparator + id_ + "/");
+
// Initialize version.
std::string version_str;
if (!source.GetString(kVersionKey, &version_str)) {
@@ -457,6 +456,7 @@ bool Extension::InitFromValue(const DictionaryValue& source,
UserScript script;
if (!LoadUserScriptHelper(content_script, i, error, &script))
return false; // Failed to parse script context definition
+ script.set_extension_id(id());
content_scripts_.push_back(script);
}
}
« no previous file with comments | « chrome/browser/extensions/extension.h ('k') | chrome/browser/extensions/extension_content_script_inject_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698