diff options
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/extension.h | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 17 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 2 |
4 files changed, 41 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index b886d85..d75ed5e 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -25,6 +25,7 @@ const wchar_t* Extension::kNameKey = L"name"; const wchar_t* Extension::kRunAtKey = L"run_at"; const wchar_t* Extension::kVersionKey = L"version"; const wchar_t* Extension::kZipHashKey = L"zip_hash"; +const wchar_t* Extension::kPluginsDirKey = L"plugins_dir"; const char* Extension::kRunAtDocumentStartValue = "document_start"; const char* Extension::kRunAtDocumentEndValue = "document_end"; @@ -67,6 +68,8 @@ const char* Extension::kInvalidVersionError = "Required value 'version' is missing or invalid."; const char* Extension::kInvalidZipHashError = "Required key 'zip_hash' is missing or invalid."; +const char* Extension::kInvalidPluginsDirError = + "Invalid value for 'plugins_dir'."; const std::string Extension::VersionString() const { return version_->GetString(); @@ -230,6 +233,16 @@ bool Extension::InitFromValue(const DictionaryValue& source, } } + // Initialize plugins dir (optional). + if (source.HasKey(kPluginsDirKey)) { + std::string plugins_dir; + if (!source.GetString(kPluginsDirKey, &plugins_dir)) { + *error = kInvalidPluginsDirError; + return false; + } + plugins_dir_ = path_.AppendASCII(plugins_dir); + } + // Initialize content scripts (optional). if (source.HasKey(kContentScriptsKey)) { ListValue* list_value; diff --git a/chrome/browser/extensions/extension.h b/chrome/browser/extensions/extension.h index eae110c..cc44cd5 100644 --- a/chrome/browser/extensions/extension.h +++ b/chrome/browser/extensions/extension.h @@ -47,6 +47,7 @@ class Extension { static const wchar_t* kRunAtKey; static const wchar_t* kVersionKey; static const wchar_t* kZipHashKey; + static const wchar_t* kPluginsDirKey; // Some values expected in manifests. static const char* kRunAtDocumentStartValue; @@ -69,6 +70,7 @@ class Extension { static const char* kInvalidRunAtError; static const char* kInvalidVersionError; static const char* kInvalidZipHashError; + static const char* kInvalidPluginsDirError; // Creates an absolute url to a resource inside an extension. The // |extension_url| argument should be the url() from an Extension object. The @@ -117,6 +119,11 @@ class Extension { return content_scripts_; } + // Path to the directory of NPAPI plugins that the extension contains. + const FilePath& plugins_dir() const { + return plugins_dir_; + } + // Initialize the extension from a parsed manifest. bool InitFromValue(const DictionaryValue& value, std::string* error); @@ -142,6 +149,9 @@ class Extension { // Paths to the content scripts the extension contains. UserScriptList content_scripts_; + // Path to the directory of NPAPI plugins that the extension contains. + FilePath plugins_dir_; + // A SHA1 hash of the contents of the zip file. Note that this key is only // present in the manifest that's prepended to the zip. The inner manifest // will not have this key. diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 13d43a5..2f10da0 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -15,6 +15,7 @@ #include "net/base/file_stream.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/user_script_master.h" +#include "chrome/browser/plugin_service.h" #include "chrome/common/json_value_serializer.h" #include "chrome/common/notification_service.h" #include "chrome/common/unzip.h" @@ -101,9 +102,23 @@ void ExtensionsService::OnExtensionsLoadedFromDirectory( extensions_.insert(extensions_.end(), new_extensions->begin(), new_extensions->end()); - // Tell UserScriptMaster about any scripts in the loaded extensions. + bool found_plugin = false; + + // TODO: Fix race here. A page could need a user script on startup, before + // the user script is loaded. We need to freeze the renderer in that case. + // TODO(mpcomplete): We also need to force a renderer to refresh its cache of + // the plugin list when we inject user scripts, since it could have a stale + // version by the time extensions are loaded. + for (ExtensionList::iterator extension = extensions_.begin(); extension != extensions_.end(); ++extension) { + // Tell NPAPI about any plugins in the loaded extensions. + if (!(*extension)->plugins_dir().empty()) { + PluginService::GetInstance()->AddExtraPluginDir( + (*extension)->plugins_dir()); + } + + // Tell UserScriptMaster about any scripts in the loaded extensions. const UserScriptList& scripts = (*extension)->content_scripts(); for (UserScriptList::const_iterator script = scripts.begin(); script != scripts.end(); ++script) { diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 4c38801..6040823 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -177,6 +177,8 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { frontend->extensions()->at(1)->name()); EXPECT_EQ(std::string(""), frontend->extensions()->at(1)->description()); + EXPECT_EQ(frontend->extensions()->at(1)->path().AppendASCII("npapi").value(), + frontend->extensions()->at(1)->plugins_dir().value()); ASSERT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); EXPECT_EQ(std::string("com.google.myextension3"), |