diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 08:01:50 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 08:01:50 +0000 |
commit | 4259f9cc708d8f67d7f935d267da9a7ffa852b65 (patch) | |
tree | 48992e2008df8ff57c600b65f71946774ab074e3 /chrome/browser/extensions/extensions_service.cc | |
parent | 86fd92283a371973f175b34f39ba8dd6ef86d7bc (diff) | |
download | chromium_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/extensions_service.cc')
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 5c836d0..942d23c 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -258,18 +258,9 @@ void ExtensionsServiceBackend::LoadSingleExtension( LOG(INFO) << "Loading single extension from " << WideToASCII(extension_path.BaseName().ToWStringHack()); - Extension* extension = LoadExtension(extension_path); + Extension* extension = LoadExtension(extension_path, + false); // don't require ID if (extension) { - if (extension->id().empty()) { - // Generate an ID - static int counter = 0; - std::string id = StringPrintf("%x", counter); - ++counter; - - // pad the string out to 40 chars with zeroes. - id.insert(0, 40 - id.length(), '0'); - extension->set_id(id); - } ExtensionList* extensions = new ExtensionList; extensions->push_back(extension); ReportExtensionsLoaded(extensions); @@ -290,11 +281,12 @@ Extension* ExtensionsServiceBackend::LoadExtensionCurrentVersion( WideToASCII(extension_path.BaseName().ToWStringHack()) << " version: " << version_str; - return LoadExtension(extension_path.AppendASCII(version_str)); + return LoadExtension(extension_path.AppendASCII(version_str), + true); // require id } Extension* ExtensionsServiceBackend::LoadExtension( - const FilePath& extension_path) { + const FilePath& extension_path, bool require_id) { FilePath manifest_path = extension_path.AppendASCII(Extension::kManifestFilename); if (!file_util::PathExists(manifest_path)) { @@ -317,7 +309,7 @@ Extension* ExtensionsServiceBackend::LoadExtension( scoped_ptr<Extension> extension(new Extension(extension_path)); if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root.get()), - &error)) { + require_id, &error)) { ReportExtensionLoadError(extension_path, error); return NULL; } @@ -638,7 +630,9 @@ bool ExtensionsServiceBackend::InstallOrUpdateExtension( DictionaryValue* dict = manifest.get(); Extension extension; std::string error; - if (!extension.InitFromValue(*dict, &error)) { + if (!extension.InitFromValue(*dict, + true, // require ID + &error)) { ReportExtensionInstallError(source_file, "Invalid extension manifest."); return false; |