summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 08:01:50 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 08:01:50 +0000
commit4259f9cc708d8f67d7f935d267da9a7ffa852b65 (patch)
tree48992e2008df8ff57c600b65f71946774ab074e3 /chrome/browser/extensions/extension.cc
parent86fd92283a371973f175b34f39ba8dd6ef86d7bc (diff)
downloadchromium_src-4259f9cc708d8f67d7f935d267da9a7ffa852b65.zip
chromium_src-4259f9cc708d8f67d7f935d267da9a7ffa852b65.tar.gz
chromium_src-4259f9cc708d8f67d7f935d267da9a7ffa852b65.tar.bz2
Implement chromium.self in content scripts, so that developers don't
have to know and copy/paste their extension ID. This required moving the code that defaults the extension ID earlier in the load process. Also fixed some bugs: * fixed a bug that was causing all user scripts to get executed in the same context. * made the greasemonkey api only available in 'standalone' user scripts. * re-added the anonymous function wrapper that is supposed to wrap content scripts. Also added unit tests for the fixed bugs. Review URL: http://codereview.chromium.org/60112 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13238 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension.cc')
-rw-r--r--chrome/browser/extensions/extension.cc36
1 files changed, 18 insertions, 18 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc
index d8ab403..1aeaeaa 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);
}
}