Chromium Code Reviews| Index: chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| diff --git a/chrome/browser/ui/views/app_list/app_list_controller_win.cc b/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| index 982a0171829e228301c6a8df6edfc271e8579393..bde2e7725a7de1c5c1cd6980ad0fe8975348b8a2 100644 |
| --- a/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| +++ b/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| @@ -5,11 +5,13 @@ |
| #include <sstream> |
| #include "base/command_line.h" |
| +#include "base/file_util.h" |
| #include "base/lazy_instance.h" |
| #include "base/path_service.h" |
| #include "base/time.h" |
| #include "base/timer.h" |
| #include "base/utf_string_conversions.h" |
| +#include "base/win/shortcut.h" |
| #include "chrome/app/chrome_dll_resource.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| @@ -23,6 +25,7 @@ |
| #include "chrome/browser/ui/views/browser_dialogs.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "grit/generated_resources.h" |
| #include "ui/app_list/app_list_view.h" |
| #include "ui/app_list/pagination_model.h" |
| @@ -40,6 +43,34 @@ namespace { |
| // amount. |
| static const int kAnchorOffset = 25; |
| +CommandLine GetAppListCommandLine() { |
| + CommandLine* current = CommandLine::ForCurrentProcess(); |
| + CommandLine command_line(current->GetProgram()); |
| + |
| + if (current->HasSwitch(switches::kUserDataDir)) { |
| + FilePath user_data_dir = current->GetSwitchValuePath( |
| + switches::kUserDataDir); |
| + command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| + } |
| + |
| + command_line.AppendSwitch(switches::kShowAppList); |
| + return command_line; |
| +} |
| + |
| +string16 GetAppModelId() { |
| + // The AppModelId should be the same for all profiles in a user data directory |
| + // but different for different user data directories, so base it on the |
| + // initial profile in the current user data directory. |
| + FilePath initial_profile_path; |
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kUserDataDir)) { |
| + initial_profile_path = |
| + command_line->GetSwitchValuePath(switches::kUserDataDir).AppendASCII( |
| + chrome::kInitialProfile); |
| + } |
| + return ShellIntegration::GetAppListAppModelIdForProfile(initial_profile_path); |
| +} |
| + |
| class AppListControllerDelegateWin : public AppListControllerDelegate { |
| public: |
| AppListControllerDelegateWin(); |
| @@ -86,9 +117,7 @@ class AppListController { |
| views::BubbleBorder::ArrowLocation* arrow, |
| gfx::Point* anchor); |
| void UpdateArrowPositionAndAnchorPoint(app_list::AppListView* view); |
| - CommandLine GetAppListCommandLine(); |
| string16 GetAppListIconPath(); |
| - string16 GetAppModelId(); |
| // Check if the app list or the taskbar has focus. The app list is kept |
| // visible whenever either of these have focus, which allows it to be |
| @@ -264,8 +293,8 @@ void AppListController::GetArrowLocationAndUpdateAnchor( |
| void AppListController::UpdateArrowPositionAndAnchorPoint( |
| app_list::AppListView* view) { |
| - static const int kArrowSize = 10; |
| - static const int kPadding = 20; |
| + const int kArrowSize = 10; |
| + const int kPadding = 20; |
| gfx::Size preferred = view->GetPreferredSize(); |
| // Add the size of the arrow to the space needed, as the preferred size is |
| @@ -287,20 +316,6 @@ void AppListController::UpdateArrowPositionAndAnchorPoint( |
| view->SetAnchorPoint(anchor); |
| } |
| -CommandLine AppListController::GetAppListCommandLine() { |
| - CommandLine* current = CommandLine::ForCurrentProcess(); |
| - CommandLine command_line(current->GetProgram()); |
| - |
| - if (current->HasSwitch(switches::kUserDataDir)) { |
| - FilePath user_data_dir = current->GetSwitchValuePath( |
| - switches::kUserDataDir); |
| - command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| - } |
| - |
| - command_line.AppendSwitch(switches::kShowAppList); |
| - return command_line; |
| -} |
| - |
| string16 AppListController::GetAppListIconPath() { |
| FilePath icon_path; |
| if (!PathService::Get(base::DIR_MODULE, &icon_path)) |
| @@ -314,17 +329,6 @@ string16 AppListController::GetAppListIconPath() { |
| return result; |
| } |
| -string16 AppListController::GetAppModelId() { |
| - static const wchar_t kAppListId[] = L"ChromeAppList"; |
| - // The AppModelId should be the same for all profiles in a user data directory |
| - // but different for different user data directories, so base it on the |
| - // initial profile in the current user data directory. |
| - FilePath initial_profile_path = |
| - g_browser_process->profile_manager()->GetInitialProfileDir(); |
| - return ShellIntegration::GetAppModelIdForProfile(kAppListId, |
| - initial_profile_path); |
| -} |
| - |
| void AppListController::CheckTaskbarOrViewHasFocus() { |
| #if !defined(USE_AURA) |
| // Don't bother checking if the view has been closed. |
| @@ -357,6 +361,62 @@ void AppListController::CheckTaskbarOrViewHasFocus() { |
| #endif |
| } |
| +void DoCheckAppListTaskbarShortcut(const FilePath user_data_dir, |
|
sky
2012/10/31 14:20:52
Add a description.
benwells
2012/11/01 05:31:05
Done.
|
| + const string16& app_model_id) { |
| + const wchar_t kAppListShortcutFileName[] = L"Chrome Apps Launcher.lnk"; |
|
sky
2012/10/31 14:20:52
DCHECK file thread.
benwells
2012/11/01 05:31:05
It was down, it's now at the top.
|
| + const wchar_t kAppListDescription[] = L"Chrome Apps Launcher"; |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| + FilePath shortcut_path(user_data_dir.Append(kAppListShortcutFileName)); |
| + bool should_show = CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kShowAppListShortcut); |
| + |
| + // This will not reshow a shortcut if it has been unpinned manually by the |
| + // user, as that will not delete the shortcut file. |
| + if (should_show && !file_util::PathExists(shortcut_path)) { |
| + FilePath chrome_exe; |
| + if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
| + return; |
| + |
| + base::win::ShortcutProperties shortcut_properties; |
| + shortcut_properties.set_target(chrome_exe); |
| + shortcut_properties.set_working_dir(chrome_exe.DirName()); |
| + |
| + string16 wide_switches(GetAppListCommandLine().GetArgumentsString()); |
| + shortcut_properties.set_arguments(wide_switches); |
| + shortcut_properties.set_description(kAppListDescription); |
| + |
| + FilePath icon_path; |
| + if (!PathService::Get(base::DIR_MODULE, &icon_path)) |
| + return; |
| + |
| + icon_path = icon_path.Append(chrome::kBrowserResourcesDll); |
| + |
| + // Icons are added to the resources of the DLL using icon indexes. The |
| + // icon index for the app list icon is in IDI_APP_LIST. Creating shortcuts |
| + // needs to specify a resource index, which are different to icon indexes. |
| + // They are 0 based and contiguous. As Google Chrome builds have an extra |
| + // icon (SXS) the icon for Google Chrome builds need to be one higher. |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + const int kIconIndex = 26; |
| +#else |
| + const int kIconIndex = 25; |
| +#endif |
| + shortcut_properties.set_icon(icon_path, 25); |
| + shortcut_properties.set_app_id(app_model_id); |
| + shortcut_properties.set_dual_mode(false); |
| + |
| + base::win::CreateOrUpdateShortcutLink(shortcut_path, shortcut_properties, |
| + base::win::SHORTCUT_CREATE_ALWAYS); |
| + base::win::TaskbarPinShortcutLink(shortcut_path.value().c_str()); |
| + return; |
| + } |
| + |
| + if (!should_show && file_util::PathExists(shortcut_path)) { |
| + base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str()); |
| + file_util::Delete(shortcut_path, false); |
| + } |
| +} |
| + |
| } // namespace |
| namespace app_list_controller { |
| @@ -365,4 +425,13 @@ void ShowAppList() { |
| g_app_list_controller.Get().ShowAppList(); |
| } |
| +void CheckAppListTaskbarShortcut() { |
| + FilePath user_data_dir(g_browser_process->profile_manager()->user_data_dir()); |
| + string16 app_model_id = GetAppModelId(); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&DoCheckAppListTaskbarShortcut, user_data_dir, app_model_id)); |
| +} |
| + |
| } // namespace app_list_controller |