diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2014-10-02 11:32:52 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-02 18:33:55 +0000 |
commit | 462b2fbc2e486d47ab682770418fa6deacfe67be (patch) | |
tree | 78511821a2112550d53c60417d3ca3c4748668a2 | |
parent | 67d86f63228f12ecd59762ef44c190c51a37823d (diff) | |
download | chromium_src-462b2fbc2e486d47ab682770418fa6deacfe67be.zip chromium_src-462b2fbc2e486d47ab682770418fa6deacfe67be.tar.gz chromium_src-462b2fbc2e486d47ab682770418fa6deacfe67be.tar.bz2 |
Remove --install-from-webstore and --limited-install-from-webstore
Both these switches should be removed, as they allow malware
to potentially install extensions on a user's computer.
Since the --install-from-webstore switch is also being used
to install ephemeral apps, rename it to
--install-ephemeral-app-from-webstore, and ensure that this
only works on installed ephemeral apps on Windows. (This
has sufficient checks in place, such as an extension of
the same ID already being installed, that this is safe.)
BUG=410833
Review URL: https://codereview.chromium.org/617833003
Cr-Commit-Position: refs/heads/master@{#297868}
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/startup_helper.cc | 78 | ||||
-rw-r--r-- | chrome/browser/extensions/startup_helper.h | 22 | ||||
-rw-r--r-- | chrome/browser/extensions/webstore_startup_installer_browsertest.cc | 47 | ||||
-rw-r--r-- | chrome/browser/ui/startup/startup_browser_creator.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc | 4 | ||||
-rw-r--r-- | chrome/common/chrome_result_codes.h | 4 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 8 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 3 |
9 files changed, 39 insertions, 140 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index ec96a31..443f5ee 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -391,8 +391,7 @@ void ExtensionService::Init() { DCHECK_EQ(registry_->enabled_extensions().size(), 0u); const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); - if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || - cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) { + if (cmd_line->HasSwitch(switches::kInstallEphemeralAppFromWebstore)) { // The sole purpose of this launch is to install a new extension from CWS // and immediately terminate: loading already installed extensions is // unnecessary and may interfere with the inline install dialog (e.g. if an diff --git a/chrome/browser/extensions/startup_helper.cc b/chrome/browser/extensions/startup_helper.cc index 25cd85e..36f427c 100644 --- a/chrome/browser/extensions/startup_helper.cc +++ b/chrome/browser/extensions/startup_helper.cc @@ -34,6 +34,8 @@ using content::BrowserThread; +namespace extensions { + namespace { void PrintPackExtensionMessage(const std::string& message) { @@ -41,32 +43,30 @@ void PrintPackExtensionMessage(const std::string& message) { } // On Windows, the jumplist action for installing an ephemeral app has to use -// the --install-from-webstore command line arg to initiate an install. -scoped_refptr<extensions::WebstoreStandaloneInstaller> -CreateEphemeralAppInstaller( +// the --install-ephemeral-app-from-webstore command line arg to initiate an +// install. +scoped_refptr<WebstoreStandaloneInstaller> CreateEphemeralAppInstaller( Profile* profile, const std::string& app_id, - extensions::WebstoreStandaloneInstaller::Callback callback) { - scoped_refptr<extensions::WebstoreStandaloneInstaller> installer; + WebstoreStandaloneInstaller::Callback callback) { + scoped_refptr<WebstoreStandaloneInstaller> installer; #if defined(OS_WIN) - using extensions::ExtensionRegistry; ExtensionRegistry* registry = ExtensionRegistry::Get(profile); DCHECK(registry); if (!registry->GetExtensionById(app_id, ExtensionRegistry::EVERYTHING) || - !extensions::util::IsEphemeralApp(app_id, profile)) { + !util::IsEphemeralApp(app_id, profile)) { return installer; } - extensions::AppWindowRegistry* app_window_registry = - extensions::AppWindowRegistry::Get(profile); + AppWindowRegistry* app_window_registry = AppWindowRegistry::Get(profile); DCHECK(app_window_registry); - extensions::AppWindow* app_window = + AppWindow* app_window = app_window_registry->GetCurrentAppWindowForApp(app_id); if (!app_window) return installer; - installer = new extensions::WebstoreInstallWithPrompt( + installer = new WebstoreInstallWithPrompt( app_id, profile, app_window->GetNativeWindow(), callback); #endif @@ -75,8 +75,6 @@ CreateEphemeralAppInstaller( } // namespace -namespace extensions { - StartupHelper::StartupHelper() : pack_job_succeeded_(false) { ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); } @@ -288,11 +286,12 @@ void AppInstallHelper::BeginInstall( base::Unretained(this)); installer_ = CreateEphemeralAppInstaller(profile, id, callback); - if (!installer_.get()) { - installer_ = - new WebstoreStartupInstaller(id, profile, show_prompt, callback); + if (installer_.get()) { + installer_->BeginInstall(); + } else { + error_ = "Not a supported ephemeral app installation."; + done_callback_.Run(); } - installer_->BeginInstall(); } void AppInstallHelper::OnAppInstallComplete(bool success, @@ -303,20 +302,15 @@ void AppInstallHelper::OnAppInstallComplete(bool success, done_callback_.Run(); } -void DeleteHelperAndRunCallback(AppInstallHelper* helper, - base::Callback<void()> callback) { - delete helper; - callback.Run(); -} - } // namespace -bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, +bool StartupHelper::InstallEphemeralApp(const CommandLine& cmd_line, Profile* profile) { - std::string id = cmd_line.GetSwitchValueASCII(switches::kInstallFromWebstore); + std::string id = + cmd_line.GetSwitchValueASCII(switches::kInstallEphemeralAppFromWebstore); if (!crx_file::id_util::IdIsValid(id)) { - LOG(ERROR) << "Invalid id for " << switches::kInstallFromWebstore - << " : '" << id << "'"; + LOG(ERROR) << "Invalid id for " + << switches::kInstallEphemeralAppFromWebstore << " : '" << id << "'"; return false; } @@ -330,36 +324,6 @@ bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, return helper.success(); } -void StartupHelper::LimitedInstallFromWebstore( - const CommandLine& cmd_line, - Profile* profile, - base::Callback<void()> done_callback) { - std::string id = WebStoreIdFromLimitedInstallCmdLine(cmd_line); - if (!crx_file::id_util::IdIsValid(id)) { - LOG(ERROR) << "Invalid index for " << switches::kLimitedInstallFromWebstore; - done_callback.Run(); - return; - } - - AppInstallHelper* helper = new AppInstallHelper(); - helper->BeginInstall(profile, id, false /*show_prompt*/, - base::Bind(&DeleteHelperAndRunCallback, - helper, done_callback)); -} - -std::string StartupHelper::WebStoreIdFromLimitedInstallCmdLine( - const CommandLine& cmd_line) { - std::string index = cmd_line.GetSwitchValueASCII( - switches::kLimitedInstallFromWebstore); - std::string id; - if (index == "1") { - id = "nckgahadagoaajjgafhacjanaoiihapd"; - } else if (index == "2") { - id = "ecglahbcnmdpdciemllbhojghbkagdje"; - } - return id; -} - StartupHelper::~StartupHelper() { if (pack_job_.get()) pack_job_->ClearClient(); diff --git a/chrome/browser/extensions/startup_helper.h b/chrome/browser/extensions/startup_helper.h index e782906..3bb2fd8 100644 --- a/chrome/browser/extensions/startup_helper.h +++ b/chrome/browser/extensions/startup_helper.h @@ -38,25 +38,11 @@ class StartupHelper : public PackExtensionJob::Client { // into |error|. bool ValidateCrx(const base::CommandLine& cmd_line, std::string* error); - // Handle --install-from-webstore flag from |cmd_line| by downloading - // metadata from the webstore for the given id, prompting the user to - // confirm, and then downloading the crx and installing it. - bool InstallFromWebstore(const base::CommandLine& cmd_line, Profile* profile); + // Handle --install-ephemeral-app-from-webstore flag from |cmd_line| by + // downloading metadata from the webstore for the given id, prompting the + // user to confirm, and then downloading the crx and installing it. + bool InstallEphemeralApp(const base::CommandLine& cmd_line, Profile* profile); - // Handle --limited-install-from-webstore flag from |cmd_line| by downloading - // metadata from the webstore for the given id, prompting the user to - // confirm, and then downloading the crx and installing it. - // This whole process is only kicked off by this function and completed - // asynchronously unlike InstallFromWebstore which finishes everything before - // returning. - void LimitedInstallFromWebstore(const base::CommandLine& cmd_line, - Profile* profile, - base::Callback<void()> done_callback); - - // Maps the command line argument to the extension id. Returns an empty string - // in the case when there is no mapping. - std::string WebStoreIdFromLimitedInstallCmdLine( - const base::CommandLine& cmd_line); private: scoped_refptr<PackExtensionJob> pack_job_; bool pack_job_succeeded_; diff --git a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc b/chrome/browser/extensions/webstore_startup_installer_browsertest.cc index 82d3b96..ea9d965 100644 --- a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc +++ b/chrome/browser/extensions/webstore_startup_installer_browsertest.cc @@ -290,55 +290,14 @@ class CommandLineWebstoreInstall int browser_open_count_; }; -IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) { +IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, CannotInstallNonEphemeral) { base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); command_line->AppendSwitchASCII( - switches::kInstallFromWebstore, kTestExtensionId); + switches::kInstallEphemeralAppFromWebstore, kTestExtensionId); ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::ACCEPT; extensions::StartupHelper helper; - EXPECT_TRUE(helper.InstallFromWebstore(*command_line, browser()->profile())); - EXPECT_TRUE(saw_install()); - EXPECT_EQ(0, browser_open_count()); -} - -IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Cancel) { - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - command_line->AppendSwitchASCII( - switches::kInstallFromWebstore, kTestExtensionId); - ExtensionInstallPrompt::g_auto_confirm_for_tests = - ExtensionInstallPrompt::CANCEL; - extensions::StartupHelper helper; - EXPECT_FALSE(helper.InstallFromWebstore(*command_line, browser()->profile())); + EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile())); EXPECT_FALSE(saw_install()); EXPECT_EQ(0, browser_open_count()); } - -IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedAccept) { - extensions::StartupHelper helper; - - // Small test of "WebStoreIdFromLimitedInstallCmdLine" which made more - // sense together with the rest of the test for "LimitedInstallFromWebstore". - base::CommandLine command_line_test1(base::CommandLine::NO_PROGRAM); - command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore, - "1"); - EXPECT_EQ("nckgahadagoaajjgafhacjanaoiihapd", - helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1)); - - base::CommandLine command_line_test2(base::CommandLine::NO_PROGRAM); - command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore, - "2"); - EXPECT_EQ(kTestExtensionId, - helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1)); - - // Now, on to the real test for LimitedInstallFromWebstore. - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - command_line->AppendSwitchASCII( - switches::kLimitedInstallFromWebstore, "2"); - helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), - base::MessageLoop::QuitWhenIdleClosure()); - base::MessageLoop::current()->Run(); - - EXPECT_TRUE(saw_install()); - EXPECT_EQ(0, browser_open_count()); -} diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc index 6b3f827..4d5cdce 100644 --- a/chrome/browser/ui/startup/startup_browser_creator.cc +++ b/chrome/browser/ui/startup/startup_browser_creator.cc @@ -501,9 +501,9 @@ bool StartupBrowserCreator::ProcessCmdLineImpl( net::SetExplicitlyAllowedPorts(allowed_ports); } - if (command_line.HasSwitch(switches::kInstallFromWebstore)) { + if (command_line.HasSwitch(switches::kInstallEphemeralAppFromWebstore)) { extensions::StartupHelper helper; - helper.InstallFromWebstore(command_line, last_used_profile); + helper.InstallEphemeralApp(command_line, last_used_profile); // Nothing more needs to be done, so return false to stop launching and // quit. return false; @@ -527,12 +527,6 @@ bool StartupBrowserCreator::ProcessCmdLineImpl( return false; } - if (command_line.HasSwitch(switches::kLimitedInstallFromWebstore)) { - extensions::StartupHelper helper; - helper.LimitedInstallFromWebstore(command_line, last_used_profile, - base::Bind(&base::DoNothing)); - } - #if defined(OS_CHROMEOS) #if defined(USE_ATHENA) diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc b/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc index 497ac36..54197d3 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc @@ -189,8 +189,8 @@ void ChromeNativeAppWindowViewsWin::UpdateShelfMenu() { icon_resources::kInstallPackagedAppIndex); ShellIntegration::AppendProfileArgs( app_window()->browser_context()->GetPath(), link->GetCommandLine()); - link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, - extension->id()); + link->GetCommandLine()->AppendSwitchASCII( + switches::kInstallEphemeralAppFromWebstore, extension->id()); ShellLinkItemList items; items.push_back(link); diff --git a/chrome/common/chrome_result_codes.h b/chrome/common/chrome_result_codes.h index 5e1106c..c047b46 100644 --- a/chrome/common/chrome_result_codes.h +++ b/chrome/common/chrome_result_codes.h @@ -75,8 +75,8 @@ enum ResultCode { // A dummy value we should not use. See crbug.com/152285. RESULT_CODE_NOTUSED_1, - // Failed to install an item from the webstore when the kInstallFromWebstore - // command line flag was present. + // Failed to install an item from the webstore when the + // kInstallEphemeralAppFromWebstore command line flag was present. RESULT_CODE_INSTALL_FROM_WEBSTORE_ERROR_2, // A dummy value we should not use. See crbug.com/152285. diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 9d35d23..b1c245a 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -745,7 +745,9 @@ const char kInstallChromeApp[] = "install-chrome-app"; // Causes Chrome to attempt to get metadata from the webstore for the // app/extension ID given, and then prompt the user to download and install it. -const char kInstallFromWebstore[] = "install-from-webstore"; +// This is allowed *only* for ephemeral apps. All other ids will be ignored. +const char kInstallEphemeralAppFromWebstore[] = + "install-ephemeral-app-from-webstore"; // Marks a renderer as an Instant process. const char kInstantProcess[] = "instant-process"; @@ -770,10 +772,6 @@ const char kKioskMode[] = "kiosk"; // See http://crbug.com/31395. const char kKioskModePrinting[] = "kiosk-printing"; -// Causes Chrome to attempt to get metadata from the webstore for the -// given item, and then prompt the user to download and install it. -const char kLimitedInstallFromWebstore[] = "limited-install-from-webstore"; - // Comma-separated list of directories with component extensions to load. const char kLoadComponentExtension[] = "load-component-extension"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 9bde5f5..df61546 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -210,7 +210,7 @@ extern const char kHostResolverRetryAttempts[]; extern const char kIgnoreUrlFetcherCertRequests[]; extern const char kIncognito[]; extern const char kInstallChromeApp[]; -extern const char kInstallFromWebstore[]; +extern const char kInstallEphemeralAppFromWebstore[]; extern const char kInstantProcess[]; extern const char kInvalidationUseGCMChannel[]; extern const char kIpcFuzzerTestcase[]; @@ -218,7 +218,6 @@ extern const char kJavaScriptHarmony[]; extern const char kKeepAliveForTest[]; extern const char kKioskMode[]; extern const char kKioskModePrinting[]; -extern const char kLimitedInstallFromWebstore[]; extern const char kLoadComponentExtension[]; extern const char kLoadExtension[]; extern const char kMakeDefaultBrowser[]; |