Chromium Code Reviews| Index: chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
| diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
| index 51d77993763aad6e7a0348352d76a920a70f2682..b61e212cf94ab5d6bfc896fd1f9315e46650401c 100644 |
| --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
| +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
| @@ -4,7 +4,6 @@ |
| #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| -#include <string> |
| #include <vector> |
| #include "base/auto_reset.h" |
| @@ -31,6 +30,7 @@ |
| #include "chrome/browser/ui/browser_tabstrip.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/extensions/application_launch.h" |
| +#include "chrome/browser/ui/extensions/extension_enable_flow.h" |
| #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| #include "chrome/browser/ui/webui/web_ui_util.h" |
| @@ -824,37 +824,13 @@ void AppLauncherHandler::RecordAppLaunchByUrl( |
| } |
| void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) { |
| - const Extension* extension = |
| - extension_service_->GetExtensionById(extension_id, true); |
| - if (!extension) { |
| - extension = extension_service_->GetTerminatedExtension(extension_id); |
| - // It's possible (though unlikely) the app could have been uninstalled since |
| - // the user clicked on it. |
| - if (!extension) |
| - return; |
| - // If the app was terminated, reload it first. (This reallocates the |
| - // Extension object.) |
| - extension_service_->ReloadExtension(extension_id); |
| - extension = extension_service_->GetExtensionById(extension_id, true); |
| - } |
| - |
| - ExtensionPrefs* extension_prefs = extension_service_->extension_prefs(); |
| - if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) { |
| - // Enable the extension immediately if its privileges weren't escalated. |
| - // This is a no-op if the extension was previously terminated. |
| - extension_service_->EnableExtension(extension_id); |
| - |
| - // Launch app asynchronously so the image will update. |
| - StringValue app_id(extension_id); |
| - web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id); |
| - return; |
| - } |
| - |
| if (!extension_id_prompting_.empty()) |
| return; // Only one prompt at a time. |
| extension_id_prompting_ = extension_id; |
|
Evan Stade
2012/12/21 22:45:26
can you get rid of extension_id_prompting_ and jus
xiyuan
2012/12/22 00:35:43
extension_id_prompting_ used to guard both uninsta
Evan Stade
2013/01/02 21:55:38
that's a reasonable explanation. Can you add "(eit
xiyuan
2013/01/07 18:13:12
Done.
|
| - GetExtensionInstallPrompt()->ConfirmReEnable(this, extension); |
| + extension_enable_flow_.reset(new ExtensionEnableFlow( |
| + Profile::FromWebUI(web_ui()), extension_id, this)); |
| + extension_enable_flow_->Start(); |
| } |
| void AppLauncherHandler::ExtensionUninstallAccepted() { |
| @@ -877,31 +853,31 @@ void AppLauncherHandler::ExtensionUninstallCanceled() { |
| CleanupAfterUninstall(); |
| } |
| -void AppLauncherHandler::InstallUIProceed() { |
| - // Do the re-enable work here. |
| - DCHECK(!extension_id_prompting_.empty()); |
| - |
| - // The extension can be uninstalled in another window while the UI was |
| - // showing. Do nothing in that case. |
| - const Extension* extension = |
| - extension_service_->GetExtensionById(extension_id_prompting_, true); |
| - if (!extension) |
| - return; |
| +ExtensionInstallPrompt* AppLauncherHandler::CreateExtensionInstallPrompt() { |
| + return new ExtensionInstallPrompt(web_ui()->GetWebContents()); |
| +} |
| - extension_service_->GrantPermissionsAndEnableExtension( |
| - extension, extension_install_ui_->record_oauth2_grant()); |
| +void AppLauncherHandler::ExtensionEnableFlowFinished( |
| + ExtensionEnableFlow* flow) { |
| + DCHECK_EQ(extension_enable_flow_.get(), flow); |
| + DCHECK_EQ(extension_id_prompting_, flow->extension_id()); |
| // We bounce this off the NTP so the browser can update the apps icon. |
| // If we don't launch the app asynchronously, then the app's disabled |
| // icon disappears but isn't replaced by the enabled icon, making a poor |
| // visual experience. |
| - StringValue app_id(extension->id()); |
| + StringValue app_id(flow->extension_id()); |
| web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id); |
| + extension_enable_flow_.reset(); |
| extension_id_prompting_ = ""; |
| } |
| -void AppLauncherHandler::InstallUIAbort(bool user_initiated) { |
| +void AppLauncherHandler::ExtensionEnableFlowAborted(ExtensionEnableFlow* flow, |
| + bool user_initiated) { |
| + DCHECK_EQ(extension_enable_flow_.get(), flow); |
| + DCHECK_EQ(extension_id_prompting_, flow->extension_id()); |
| + |
| // We record the histograms here because ExtensionUninstallCanceled is also |
| // called when the extension uninstall dialog is canceled. |
| const Extension* extension = |
| @@ -912,6 +888,7 @@ void AppLauncherHandler::InstallUIAbort(bool user_initiated) { |
| ExtensionService::RecordPermissionMessagesHistogram( |
| extension, histogram_name.c_str()); |
| + extension_enable_flow_.reset(); |
| CleanupAfterUninstall(); |
| } |
| @@ -924,11 +901,3 @@ ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
| } |
| return extension_uninstall_dialog_.get(); |
| } |
| - |
| -ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() { |
| - if (!extension_install_ui_.get()) { |
| - extension_install_ui_.reset( |
| - new ExtensionInstallPrompt(web_ui()->GetWebContents())); |
| - } |
| - return extension_install_ui_.get(); |
| -} |