diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-03 23:00:30 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-03 23:00:30 +0000 |
commit | 3cf4f0999332e4406b29ec19401fdde45a377049 (patch) | |
tree | 1ae1929813a73f6b221ae9e53d09af173cd1d7b9 | |
parent | f6a9e5f191be83a7d0a867eed5e5754d378101bb (diff) | |
download | chromium_src-3cf4f0999332e4406b29ec19401fdde45a377049.zip chromium_src-3cf4f0999332e4406b29ec19401fdde45a377049.tar.gz chromium_src-3cf4f0999332e4406b29ec19401fdde45a377049.tar.bz2 |
Add a command line flag to load a single extension from an arbitrary (non-versioned) directory. This is designed for developers to iterate on extension development without having to go through the install process.
Review URL: http://codereview.chromium.org/20020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9107 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_init.cc | 11 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 35 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 14 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 33 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 3 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
7 files changed, 78 insertions, 23 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 443f0be..4aecb2c 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -422,12 +422,15 @@ bool BrowserInit::ProcessCommandLine( CreateAutomationProvider<AutomationProvider>(automation_channel_id, profile, expected_tabs); } - - // Start up the extensions service http://crbug.com/7265 - profile->InitExtensions(); - // TODO(port): figure out why this call crashes. #endif + if (command_line.HasSwitch(switches::kLoadExtension)) { + std::wstring path_string = + command_line.GetSwitchValue(switches::kLoadExtension); + FilePath path = FilePath::FromWStringHack(path_string); + profile->GetExtensionsService()->LoadExtension(path); + } + if (command_line.HasSwitch(switches::kInstallExtension)) { std::wstring path_string = command_line.GetSwitchValue(switches::kInstallExtension); diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index e3064a0..375e06f 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -543,6 +543,10 @@ int BrowserMain(const MainFunctionParams& parameters) { RecordBreakpadStatusUMA(metrics); + // Start up the extensions service. + // This should happen before ProcessCommandLine. + profile->InitExtensions(); + int result_code = ResultCodes::NORMAL_EXIT; if (parameters.ui_task) { MessageLoopForUI::current()->PostTask(FROM_HERE, parameters.ui_task); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 60f9880..d749fd57 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -70,6 +70,29 @@ MessageLoop* ExtensionsService::GetMessageLoop() { return message_loop_; } +void ExtensionsService::InstallExtension(const FilePath& extension_path) { + // TODO(aa): This message loop should probably come from a backend + // interface, similar to how the message loop for the frontend comes + // from the frontend interface. + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(backend_.get(), + &ExtensionsServiceBackend::InstallExtension, + extension_path, + install_directory_, + scoped_refptr<ExtensionsServiceFrontendInterface>(this))); +} + +void ExtensionsService::LoadExtension(const FilePath& extension_path) { + // TODO(aa): This message loop should probably come from a backend + // interface, similar to how the message loop for the frontend comes + // from the frontend interface. + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(backend_.get(), + &ExtensionsServiceBackend::LoadSingleExtension, + extension_path, + scoped_refptr<ExtensionsServiceFrontendInterface>(this))); +} + void ExtensionsService::OnExtensionsLoadedFromDirectory( ExtensionList* new_extensions) { extensions_.insert(extensions_.end(), new_extensions->begin(), @@ -107,18 +130,6 @@ void ExtensionsService::OnExtensionLoadError(const std::string& error) { LOG(WARNING) << error; } -void ExtensionsService::InstallExtension(const FilePath& extension_path) { - // TODO(aa): This message loop should probably come from a backend - // interface, similar to how the message loop for the frontend comes - // from the frontend interface. - g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(backend_.get(), - &ExtensionsServiceBackend::InstallExtension, - extension_path, - install_directory_, - scoped_refptr<ExtensionsServiceFrontendInterface>(this))); -} - void ExtensionsService::OnExtensionInstallError(const std::string& error) { // TODO(erikkay): Print the error message out somewhere better. LOG(WARNING) << error; diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 3988a5e..0421f4b 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -27,6 +27,12 @@ class ExtensionsServiceFrontendInterface // The message loop to invoke the frontend's methods on. virtual MessageLoop* GetMessageLoop() = 0; + // Install the extension file at |extension_path|. + virtual void InstallExtension(const FilePath& extension_path) = 0; + + // Load the extension from the directory |extension_path|. + virtual void LoadExtension(const FilePath& extension_path) = 0; + // Called when loading an extension fails. virtual void OnExtensionLoadError(const std::string& message) = 0; @@ -34,9 +40,6 @@ class ExtensionsServiceFrontendInterface // takes ownership of the list. virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions) = 0; - // Install the extension file at extension_path. - virtual void InstallExtension(const FilePath& extension_path) = 0; - // Called when installing an extension fails. virtual void OnExtensionInstallError(const std::string& message) = 0; @@ -62,9 +65,10 @@ class ExtensionsService : public ExtensionsServiceFrontendInterface { // ExtensionsServiceFrontendInterface virtual MessageLoop* GetMessageLoop(); + virtual void InstallExtension(const FilePath& extension_path); + virtual void LoadExtension(const FilePath& extension_path); virtual void OnExtensionLoadError(const std::string& message); virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions); - virtual void InstallExtension(const FilePath& extension_path); virtual void OnExtensionInstallError(const std::string& message); virtual void OnExtensionInstalled(FilePath path); @@ -116,6 +120,8 @@ class ExtensionsServiceBackend // Errors are reported through OnExtensionLoadError(). On completion, // OnExtensionsLoadedFromDirectory() is called with any successfully loaded // extensions. + // TODO(erikkay): It might be useful to be able to load a packed extension + // (presumably into memory) without installing it. bool LoadSingleExtension( const FilePath &path, scoped_refptr<ExtensionsServiceFrontendInterface> frontend); diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index c6af8ff..ed86b6b 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -66,6 +66,12 @@ class ExtensionsServiceTestFrontend return &message_loop_; } + virtual void InstallExtension(const FilePath& extension_path) { + } + + virtual void LoadExtension(const FilePath& extension_path) { + } + virtual void OnExtensionLoadError(const std::string& message) { errors_.push_back(message); } @@ -79,9 +85,6 @@ class ExtensionsServiceTestFrontend std::stable_sort(extensions_.begin(), extensions_.end(), ExtensionsOrder()); } - virtual void InstallExtension(const FilePath& extension_path) { - } - virtual void OnExtensionInstallError(const std::string& message) { errors_.push_back(message); } @@ -217,3 +220,27 @@ TEST_F(ExtensionsServiceTest, InstallExtension) { // TODO(erikkay): add tests for upgrade cases. } +TEST_F(ExtensionsServiceTest, LoadExtension) { + FilePath extensions_path; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); + extensions_path = extensions_path.AppendASCII("extensions"); + + scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); + scoped_refptr<ExtensionsServiceTestFrontend> frontend( + new ExtensionsServiceTestFrontend); + + FilePath ext1 = extensions_path.AppendASCII("extension1"); + EXPECT_TRUE(backend->LoadSingleExtension(ext1, + scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); + frontend->GetMessageLoop()->RunAllPending(); + EXPECT_EQ(frontend->errors()->size(), 0u); + ASSERT_EQ(1u, frontend->extensions()->size()); + + FilePath no_manifest = extensions_path.AppendASCII("no_manifest"); + EXPECT_FALSE(backend->LoadSingleExtension(no_manifest, + scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); + frontend->GetMessageLoop()->RunAllPending(); + EXPECT_EQ(frontend->errors()->size(), 1u); + ASSERT_EQ(1u, frontend->extensions()->size()); +} + diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index f2e0c68..e694366 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -344,6 +344,9 @@ const wchar_t kEnableExtensions[] = L"enable-extensions"; // handling so that users can double-click on an extension. const wchar_t kInstallExtension[] = L"install-extension"; +// Load an extension from the specified directory. +const wchar_t kLoadExtension[] = L"load-extension"; + // Causes the browser to launch directly in incognito mode. const wchar_t kIncognito[] = L"incognito"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 046c690..1a2c36c 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -131,6 +131,7 @@ extern const wchar_t kSdchFilter[]; extern const wchar_t kEnableUserScripts[]; extern const wchar_t kEnableExtensions[]; extern const wchar_t kInstallExtension[]; +extern const wchar_t kLoadExtension[]; extern const wchar_t kIncognito[]; extern const wchar_t kUseOldSafeBrowsing[]; |