diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 03:40:44 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 03:40:44 +0000 |
commit | e49002ab6fab8693dda975ee8bd0ffaae8bbc5cb (patch) | |
tree | b8e5c895ef14cd139634c158519df84f28dd2677 | |
parent | d70c2dee0cc76dc86d8ffd8bbd129ac204fa03f5 (diff) | |
download | chromium_src-e49002ab6fab8693dda975ee8bd0ffaae8bbc5cb.zip chromium_src-e49002ab6fab8693dda975ee8bd0ffaae8bbc5cb.tar.gz chromium_src-e49002ab6fab8693dda975ee8bd0ffaae8bbc5cb.tar.bz2 |
Don't show a prompt when loading an extension with NPAPI plugins via
--load-extension.
BUG=89075
TEST=load an extension with an NPAPI plugin via --load-extension and via the extension managment page. Only the latter should prompt with an install dialog.
Review URL: http://codereview.chromium.org/7349020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92310 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 100 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.h | 6 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/panels/panel_browser_view_browsertest.cc | 2 |
4 files changed, 58 insertions, 52 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index a786653..09711b5 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -229,12 +229,14 @@ class ExtensionServiceBackend const FilePath& install_directory); // Loads a single extension from |path| where |path| is the top directory of - // a specific extension where its manifest file lives. + // a specific extension where its manifest file lives. If |prompt_for_plugins| + // is true and the extension contains plugins, we prompt the user before + // loading. // Errors are reported through ExtensionErrorReporter. On success, // AddExtension() is called. // TODO(erikkay): It might be useful to be able to load a packed extension // (presumably into memory) without installing it. - void LoadSingleExtension(const FilePath &path); + void LoadSingleExtension(const FilePath &path, bool prompt_for_plugins); private: friend class base::RefCountedThreadSafe<ExtensionServiceBackend>; @@ -245,16 +247,18 @@ class ExtensionServiceBackend // to happen back on the UI thread, so it posts CheckExtensionFileAccess on // the UI thread. In turn, once that gets the pref, it goes back to the // file thread with LoadSingleExtensionWithFileAccess. - void CheckExtensionFileAccess(const FilePath& extension_path); + void CheckExtensionFileAccess(const FilePath& extension_path, + bool prompt_for_plugins); void LoadSingleExtensionWithFileAccess( - const FilePath &path, bool allow_file_access); + const FilePath &path, bool allow_file_access, bool prompt_for_plugins); // Notify the frontend that there was an error loading an extension. void ReportExtensionLoadError(const FilePath& extension_path, const std::string& error); // Notify the frontend that an extension was installed. - void OnLoadSingleExtension(const scoped_refptr<const Extension>& extension); + void OnLoadSingleExtension(const scoped_refptr<const Extension>& extension, + bool prompt_for_plugins); base::WeakPtr<ExtensionService> frontend_; @@ -277,23 +281,21 @@ ExtensionServiceBackend::~ExtensionServiceBackend() { BrowserThread::CurrentlyOn(BrowserThread::FILE)); } -void ExtensionServiceBackend::LoadSingleExtension(const FilePath& path_in) { +void ExtensionServiceBackend::LoadSingleExtension(const FilePath& path_in, + bool prompt_for_plugins) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); FilePath extension_path = path_in; file_util::AbsolutePath(&extension_path); - if (!BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, - &ExtensionServiceBackend::CheckExtensionFileAccess, - extension_path))) - NOTREACHED(); + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, + &ExtensionServiceBackend::CheckExtensionFileAccess, + extension_path, prompt_for_plugins)); } void ExtensionServiceBackend::CheckExtensionFileAccess( - const FilePath& extension_path) { + const FilePath& extension_path, bool prompt_for_plugins) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); std::string id = Extension::GenerateIdForPath(extension_path); // Unpacked extensions default to allowing file access, but if that has been @@ -302,19 +304,17 @@ void ExtensionServiceBackend::CheckExtensionFileAccess( Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) && !frontend_->extension_prefs()->HasAllowFileAccessSetting(id); - if (!BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - this, - &ExtensionServiceBackend::LoadSingleExtensionWithFileAccess, - extension_path, - allow_file_access))) - NOTREACHED(); + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + NewRunnableMethod( + this, + &ExtensionServiceBackend::LoadSingleExtensionWithFileAccess, + extension_path, allow_file_access, prompt_for_plugins)); } - void ExtensionServiceBackend::LoadSingleExtensionWithFileAccess( - const FilePath& extension_path, bool allow_file_access) { + const FilePath& extension_path, + bool allow_file_access, + bool prompt_for_plugins) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); int flags = allow_file_access ? Extension::ALLOW_FILE_ACCESS : Extension::NO_FLAGS; @@ -328,25 +328,21 @@ void ExtensionServiceBackend::LoadSingleExtensionWithFileAccess( &error)); if (!extension) { - if (!BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, - &ExtensionServiceBackend::ReportExtensionLoadError, - extension_path, error))) - NOTREACHED() << error; + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod( + this, + &ExtensionServiceBackend::ReportExtensionLoadError, + extension_path, error)); return; } // Report this as an installed extension so that it gets remembered in the // prefs. - if (!BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, - &ExtensionServiceBackend::OnLoadSingleExtension, - extension))) - NOTREACHED(); + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod( + this, + &ExtensionServiceBackend::OnLoadSingleExtension, + extension, prompt_for_plugins)); } void ExtensionServiceBackend::ReportExtensionLoadError( @@ -359,10 +355,10 @@ void ExtensionServiceBackend::ReportExtensionLoadError( } void ExtensionServiceBackend::OnLoadSingleExtension( - const scoped_refptr<const Extension>& extension) { + const scoped_refptr<const Extension>& extension, bool prompt_for_plugins) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (frontend_.get()) - frontend_->OnLoadSingleExtension(extension); + frontend_->OnLoadSingleExtension(extension, prompt_for_plugins); } void ExtensionService::CheckExternalUninstall(const std::string& id) { @@ -999,13 +995,18 @@ void ExtensionService::GrantPermissionsAndEnableExtension( } void ExtensionService::LoadExtension(const FilePath& extension_path) { - if (!BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - backend_.get(), - &ExtensionServiceBackend::LoadSingleExtension, - extension_path))) - NOTREACHED(); + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + NewRunnableMethod(backend_.get(), + &ExtensionServiceBackend::LoadSingleExtension, + extension_path, true)); +} + +void ExtensionService::LoadExtensionFromCommandLine( + const FilePath& extension_path) { + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + NewRunnableMethod(backend_.get(), + &ExtensionServiceBackend::LoadSingleExtension, + extension_path, false)); } void ExtensionService::LoadComponentExtensions() { @@ -2014,10 +2015,11 @@ void ExtensionService::UpdateActiveExtensionsInCrashReporter() { child_process_logging::SetActiveExtensions(extension_ids); } -void ExtensionService::OnLoadSingleExtension(const Extension* extension) { +void ExtensionService::OnLoadSingleExtension(const Extension* extension, + bool prompt_for_plugins) { // If this is a new install of an extension with plugins, prompt the user // first. - if (show_extensions_prompts_ && + if (show_extensions_prompts_ && prompt_for_plugins && !extension->plugins().empty() && disabled_extension_paths_.find(extension->id()) == disabled_extension_paths_.end()) { diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index 99c576e..611056a 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -325,6 +325,9 @@ class ExtensionService // Loads the extension from the directory |extension_path|. void LoadExtension(const FilePath& extension_path); + // Same as above, but for use with command line switch --load-extension=path. + void LoadExtensionFromCommandLine(const FilePath& extension_path); + // Loads any component extensions. void LoadComponentExtensions(); @@ -397,7 +400,8 @@ class ExtensionService void AddExtension(const Extension* extension); // Called by the backend when an unpacked extension has been loaded. - void OnLoadSingleExtension(const Extension* extension); + void OnLoadSingleExtension(const Extension* extension, + bool prompt_for_plugins); // Called by the backend when an extension has been installed. void OnExtensionInstalled( diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 619ff13..b28484f 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -470,7 +470,7 @@ void ProfileImpl::InitExtensions(bool extensions_enabled) { if (command_line->HasSwitch(switches::kLoadExtension)) { FilePath path = command_line->GetSwitchValuePath( switches::kLoadExtension); - extension_service_->LoadExtension(path); + extension_service_->LoadExtensionFromCommandLine(path); } } diff --git a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc index c55f483..f98ca06 100644 --- a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc @@ -223,7 +223,7 @@ class PanelBrowserViewTest : public InProcessBrowserTest { ASSERT_TRUE(extension.get()); EXPECT_STREQ("", error.c_str()); browser()->GetProfile()->GetExtensionService()->OnLoadSingleExtension( - extension.get()); + extension.get(), false); // Creates a panel with the app name that comes from the extension ID. PanelBrowserView* browser_view = CreatePanelBrowserView( |