diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 02:09:22 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 02:09:22 +0000 |
commit | d96efb858c168820c8d9f04d7405ea1f879e4719 (patch) | |
tree | 125c31e3e9bef3064f809fd1a43cafb024f0adc4 | |
parent | d5ee38316359bf6379b1de7269a724ad3d904cb5 (diff) | |
download | chromium_src-d96efb858c168820c8d9f04d7405ea1f879e4719.zip chromium_src-d96efb858c168820c8d9f04d7405ea1f879e4719.tar.gz chromium_src-d96efb858c168820c8d9f04d7405ea1f879e4719.tar.bz2 |
Refactored shortcut creation in AppListControllerDelegate.
Moved DoCreateShortcutsFlow from AppListControllerDelegate subclasses to
the base class. Previously, Win and Mac had separate implementations,
and Ash had no implementation.
BUG=307837
Review URL: https://codereview.chromium.org/27545003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230009 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 33 insertions, 59 deletions
diff --git a/chrome/browser/ui/app_list/app_context_menu.cc b/chrome/browser/ui/app_list/app_context_menu.cc index e70e3fc..ac5ce9e 100644 --- a/chrome/browser/ui/app_list/app_context_menu.cc +++ b/chrome/browser/ui/app_list/app_context_menu.cc @@ -189,7 +189,7 @@ ui::MenuModel* AppContextMenu::GetMenuModel() { IDS_APP_LIST_CONTEXT_MENU_PIN); } - if (controller_->CanDoCreateShortcutsFlow(is_platform_app_)) { + if (controller_->CanDoCreateShortcutsFlow()) { menu_model_->AddItemWithStringId(CREATE_SHORTCUTS, IDS_NEW_TAB_APP_CREATE_SHORTCUT); } diff --git a/chrome/browser/ui/app_list/app_list_controller_delegate.cc b/chrome/browser/ui/app_list/app_list_controller_delegate.cc index ec1332d..9daf2f8 100644 --- a/chrome/browser/ui/app_list/app_list_controller_delegate.cc +++ b/chrome/browser/ui/app_list/app_list_controller_delegate.cc @@ -6,7 +6,10 @@ #include "base/logging.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/common/extensions/extension_constants.h" #include "ui/gfx/image/image_skia.h" @@ -26,9 +29,30 @@ void AppListControllerDelegate::PinApp(const std::string& extension_id) {} void AppListControllerDelegate::UnpinApp(const std::string& extension_id) {} +bool AppListControllerDelegate::CanDoCreateShortcutsFlow() { + return false; +} + void AppListControllerDelegate::DoCreateShortcutsFlow( Profile* profile, - const std::string& extension_id) {} + const std::string& extension_id) { + DCHECK(CanDoCreateShortcutsFlow()); + ExtensionService* service = + extensions::ExtensionSystem::Get(profile)->extension_service(); + DCHECK(service); + const extensions::Extension* extension = service->GetInstalledExtension( + extension_id); + DCHECK(extension); + + gfx::NativeWindow parent_window = GetAppListWindow(); + if (!parent_window) + return; + OnShowExtensionPrompt(); + chrome::ShowCreateChromeAppShortcutsDialog( + parent_window, profile, extension, + base::Bind(&AppListControllerDelegate::OnCloseExtensionPrompt, + base::Unretained(this))); +} void AppListControllerDelegate::CreateNewWindow(Profile* profile, bool incognito) { diff --git a/chrome/browser/ui/app_list/app_list_controller_delegate.h b/chrome/browser/ui/app_list/app_list_controller_delegate.h index 4b8ed1d..04d04a8 100644 --- a/chrome/browser/ui/app_list/app_list_controller_delegate.h +++ b/chrome/browser/ui/app_list/app_list_controller_delegate.h @@ -67,9 +67,11 @@ class AppListControllerDelegate { virtual void OnCloseExtensionPrompt() {} // Whether the controller supports a Create Shortcuts flow. - virtual bool CanDoCreateShortcutsFlow(bool is_platform_app) = 0; - virtual void DoCreateShortcutsFlow(Profile* profile, - const std::string& extension_id); + virtual bool CanDoCreateShortcutsFlow(); + + // Show the dialog to create shortcuts. Call only if + // CanDoCreateShortcutsFlow() returns true. + void DoCreateShortcutsFlow(Profile* profile, const std::string& extension_id); // Handle the "create window" context menu items of Chrome App. // |incognito| is true to create an incognito window. diff --git a/chrome/browser/ui/app_list/app_list_service_mac.mm b/chrome/browser/ui/app_list/app_list_service_mac.mm index faeefa4..193a93d 100644 --- a/chrome/browser/ui/app_list/app_list_service_mac.mm +++ b/chrome/browser/ui/app_list/app_list_service_mac.mm @@ -89,10 +89,7 @@ class AppListControllerDelegateCocoa : public AppListControllerDelegate { virtual void DismissView() OVERRIDE; virtual gfx::NativeWindow GetAppListWindow() OVERRIDE; virtual Pinnable GetPinnable() OVERRIDE; - virtual bool CanDoCreateShortcutsFlow(bool is_platform_app) OVERRIDE; virtual void CreateNewWindow(Profile* profile, bool incognito) OVERRIDE; - virtual void DoCreateShortcutsFlow(Profile* profile, - const std::string& extension_id) OVERRIDE; virtual void ActivateApp(Profile* profile, const extensions::Extension* extension, AppListSource source, @@ -216,24 +213,6 @@ AppListControllerDelegate::Pinnable return NO_PIN; } -bool AppListControllerDelegateCocoa::CanDoCreateShortcutsFlow( - bool is_platform_app) { - return false; -} - -void AppListControllerDelegateCocoa::DoCreateShortcutsFlow( - Profile* profile, const std::string& extension_id) { - ExtensionService* service = - extensions::ExtensionSystem::Get(profile)->extension_service(); - DCHECK(service); - const extensions::Extension* extension = - service->GetInstalledExtension(extension_id); - DCHECK(extension); - - web_app::UpdateShortcutInfoAndIconForApp( - *extension, profile, base::Bind(&CreateShortcutsInDefaultLocation)); -} - void AppListControllerDelegateCocoa::CreateNewWindow( Profile* profile, bool incognito) { Profile* window_profile = incognito ? diff --git a/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc b/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc index fdf01dd..54b4a51 100644 --- a/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc +++ b/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc @@ -41,11 +41,6 @@ AppListControllerDelegate::Pinnable PIN_FIXED; } -bool AppListControllerDelegateAsh::CanDoCreateShortcutsFlow( - bool is_platform_app) { - return false; -} - void AppListControllerDelegateAsh::CreateNewWindow(Profile* profile, bool incognito) { if (incognito) diff --git a/chrome/browser/ui/ash/app_list/app_list_controller_ash.h b/chrome/browser/ui/ash/app_list/app_list_controller_ash.h index 60005f5..bf4c295 100644 --- a/chrome/browser/ui/ash/app_list/app_list_controller_ash.h +++ b/chrome/browser/ui/ash/app_list/app_list_controller_ash.h @@ -23,7 +23,6 @@ class AppListControllerDelegateAsh : public AppListControllerDelegate { virtual void PinApp(const std::string& extension_id) OVERRIDE; virtual void UnpinApp(const std::string& extension_id) OVERRIDE; virtual Pinnable GetPinnable() OVERRIDE; - virtual bool CanDoCreateShortcutsFlow(bool is_platform_app) OVERRIDE; virtual void CreateNewWindow(Profile* profile, bool incognito) OVERRIDE; virtual void ActivateApp(Profile* profile, const extensions::Extension* extension, diff --git a/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.cc b/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.cc index 7ee95ad..ca4458e 100644 --- a/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.cc +++ b/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.cc @@ -4,8 +4,6 @@ #include "chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/ui/app_list/app_list_icon_win.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_dialogs.h" @@ -60,31 +58,10 @@ void AppListControllerDelegateWin::OnCloseExtensionPrompt() { service_->set_can_close(true); } -bool AppListControllerDelegateWin::CanDoCreateShortcutsFlow( - bool is_platform_app) { +bool AppListControllerDelegateWin::CanDoCreateShortcutsFlow() { return true; } -void AppListControllerDelegateWin::DoCreateShortcutsFlow( - Profile* profile, - const std::string& extension_id) { - ExtensionService* service = - extensions::ExtensionSystem::Get(profile)->extension_service(); - DCHECK(service); - const extensions::Extension* extension = service->GetInstalledExtension( - extension_id); - DCHECK(extension); - - gfx::NativeWindow parent_hwnd = GetAppListWindow(); - if (!parent_hwnd) - return; - OnShowExtensionPrompt(); - chrome::ShowCreateChromeAppShortcutsDialog( - parent_hwnd, profile, extension, - base::Bind(&AppListControllerDelegateWin::OnCloseExtensionPrompt, - base::Unretained(this))); -} - void AppListControllerDelegateWin::CreateNewWindow(Profile* profile, bool incognito) { Profile* window_profile = incognito ? diff --git a/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.h b/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.h index 869ca28..9e3ffcc 100644 --- a/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.h +++ b/chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.h @@ -31,9 +31,7 @@ class AppListControllerDelegateWin : public AppListControllerDelegate { virtual Pinnable GetPinnable() OVERRIDE; virtual void OnShowExtensionPrompt() OVERRIDE; virtual void OnCloseExtensionPrompt() OVERRIDE; - virtual bool CanDoCreateShortcutsFlow(bool is_platform_app) OVERRIDE; - virtual void DoCreateShortcutsFlow(Profile* profile, - const std::string& extension_id) OVERRIDE; + virtual bool CanDoCreateShortcutsFlow() OVERRIDE; virtual void CreateNewWindow(Profile* profile, bool incognito) OVERRIDE; virtual void ActivateApp(Profile* profile, const extensions::Extension* extension, |