summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-03 16:34:06 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-03 16:34:06 +0000
commit0877fd9d0ad95ca621d338485918cd347242591e (patch)
tree6f2d6cdaf11f8909256853e7c4b28f5bbe4ed49a /chrome/browser/extensions
parent0c829f6d4c5d04faac2e7fa7d73e6713e0a9d297 (diff)
downloadchromium_src-0877fd9d0ad95ca621d338485918cd347242591e.zip
chromium_src-0877fd9d0ad95ca621d338485918cd347242591e.tar.gz
chromium_src-0877fd9d0ad95ca621d338485918cd347242591e.tar.bz2
Extension loading improvements.
Add a method that allows loading a single specific extension. Load extensions upon successful install. Review is for which ever one of you gets in first, or both if you care. ;-) Review URL: http://codereview.chromium.org/19759 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extensions_service.cc89
-rw-r--r--chrome/browser/extensions/extensions_service.h15
2 files changed, 74 insertions, 30 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 3038cab..60f9880 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -130,7 +130,12 @@ void ExtensionsService::OnExtensionInstalled(FilePath path) {
NotificationService::AllSources(),
Details<FilePath>(&path));
- // TODO(erikkay): now what?
+ // Immediately try to load the extension.
+ g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(backend_.get(),
+ &ExtensionsServiceBackend::LoadSingleExtension,
+ path,
+ scoped_refptr<ExtensionsServiceFrontendInterface>(this)));
}
@@ -160,41 +165,65 @@ bool ExtensionsServiceBackend::LoadExtensionsFromDirectory(
// from local directories that developers are just hacking in place.
// TODO(erikkay): perhaps we should use a different code path for this.
}
- FilePath manifest_path =
- child_path.AppendASCII(Extension::kManifestFilename);
- if (!file_util::PathExists(manifest_path)) {
- ReportExtensionLoadError(frontend.get(), child_path,
- Extension::kInvalidManifestError);
- continue;
- }
- JSONFileValueSerializer serializer(manifest_path.ToWStringHack());
- std::string error;
- scoped_ptr<Value> root(serializer.Deserialize(&error));
- if (!root.get()) {
- ReportExtensionLoadError(frontend.get(), child_path,
- error);
- continue;
- }
+ Extension* extension = LoadExtension(child_path, frontend);
+ if (extension)
+ extensions->push_back(extension);
+ }
- if (!root->IsType(Value::TYPE_DICTIONARY)) {
- ReportExtensionLoadError(frontend.get(), child_path,
- Extension::kInvalidManifestError);
- continue;
- }
+ ReportExtensionsLoaded(frontend.get(), extensions.release());
+ return true;
+}
- scoped_ptr<Extension> extension(new Extension(child_path));
- if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root.get()),
- &error)) {
- ReportExtensionLoadError(frontend.get(), child_path, error);
- continue;
- }
+bool ExtensionsServiceBackend::LoadSingleExtension(
+ const FilePath& path_in,
+ scoped_refptr<ExtensionsServiceFrontendInterface> frontend) {
+ FilePath path = path_in;
+ if (!file_util::AbsolutePath(&path))
+ NOTREACHED();
+ Extension* extension = LoadExtension(path, frontend);
+ if (extension) {
+ ExtensionList* extensions = new ExtensionList;
+ extensions->push_back(extension);
+ ReportExtensionsLoaded(frontend.get(), extensions);
+ return true;
+ }
+ return false;
+}
- extensions->push_back(extension.release());
+Extension* ExtensionsServiceBackend::LoadExtension(
+ const FilePath& path,
+ scoped_refptr<ExtensionsServiceFrontendInterface> frontend) {
+ FilePath manifest_path =
+ path.AppendASCII(Extension::kManifestFilename);
+ if (!file_util::PathExists(manifest_path)) {
+ ReportExtensionLoadError(frontend.get(), path,
+ Extension::kInvalidManifestError);
+ return NULL;
}
- ReportExtensionsLoaded(frontend.get(), extensions.release());
- return true;
+ JSONFileValueSerializer serializer(manifest_path.ToWStringHack());
+ std::string error;
+ scoped_ptr<Value> root(serializer.Deserialize(&error));
+ if (!root.get()) {
+ ReportExtensionLoadError(frontend.get(), path,
+ error);
+ return NULL;
+ }
+
+ if (!root->IsType(Value::TYPE_DICTIONARY)) {
+ ReportExtensionLoadError(frontend.get(), path,
+ Extension::kInvalidManifestError);
+ return NULL;
+ }
+
+ scoped_ptr<Extension> extension(new Extension(path));
+ if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root.get()),
+ &error)) {
+ ReportExtensionLoadError(frontend.get(), path, error);
+ return NULL;
+ }
+ return extension.release();
}
void ExtensionsServiceBackend::ReportExtensionLoadError(
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index 48d9778..3988a5e 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -111,6 +111,15 @@ class ExtensionsServiceBackend
const FilePath &path,
scoped_refptr<ExtensionsServiceFrontendInterface> frontend);
+ // Loads a single extension from |path| where |path| is the top directory of
+ // a specific extension where its manifest file lives.
+ // Errors are reported through OnExtensionLoadError(). On completion,
+ // OnExtensionsLoadedFromDirectory() is called with any successfully loaded
+ // extensions.
+ bool LoadSingleExtension(
+ const FilePath &path,
+ scoped_refptr<ExtensionsServiceFrontendInterface> frontend);
+
// Install the extension file at extension_path to install_dir.
// ReportExtensionInstallError is called on error.
// ReportExtensionInstalled is called on success.
@@ -120,6 +129,12 @@ class ExtensionsServiceBackend
scoped_refptr<ExtensionsServiceFrontendInterface> frontend);
private:
+ // Load a single extension from |path| where |path| is the top directory of
+ // a specific extension where its manifest file lives.
+ Extension* LoadExtension(
+ const FilePath &path,
+ scoped_refptr<ExtensionsServiceFrontendInterface> frontend);
+
// Notify a frontend that there was an error loading an extension.
void ReportExtensionLoadError(ExtensionsServiceFrontendInterface* frontend,
const FilePath& path,