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..80208e703bb0c2715d58779e604533d30b6bea20 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,7 +25,10 @@ |
#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/chromium_strings.h" |
#include "grit/generated_resources.h" |
+#include "grit/google_chrome_strings.h" |
#include "ui/app_list/app_list_view.h" |
#include "ui/app_list/pagination_model.h" |
#include "ui/base/l10n/l10n_util.h" |
@@ -40,6 +45,30 @@ namespace { |
// amount. |
static const int kAnchorOffset = 25; |
+CommandLine GetAppListCommandLine() { |
+ const char* kSwitchesToCopy[] = {switches::kUserDataDir}; |
grt (UTC plus 2)
2012/11/02 04:00:36
"const char* const " so the whole thing is truly c
benwells
2012/11/02 04:54:43
Done.
|
+ CommandLine* current = CommandLine::ForCurrentProcess(); |
+ CommandLine command_line(current->GetProgram()); |
+ command_line.CopySwitchesFrom(*current, kSwitchesToCopy, |
+ arraysize(kSwitchesToCopy)); |
+ command_line.AppendSwitch(switches::kShowAppList); |
+ return command_line; |
+} |
+ |
+string16 GetAppModelId() { |
+ // The AppModelId should be the same for all profiles in a user data directory |
gab
2012/11/02 04:36:28
Are you sure this is what you want? i.e. you will
benwells
2012/11/02 04:54:43
Yes that's correct. It will get profile switching
|
+ // 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 +115,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 +291,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 +314,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 +327,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 +359,69 @@ void AppListController::CheckTaskbarOrViewHasFocus() { |
#endif |
} |
+// Check that a taskbar shortcut exists if it should, or does not exist if |
+// it should not. A taskbar shortcut should exist if the switch |
+// kShowAppListShortcut is set. The shortcut will be created or deleted in |
+// |user_data_dir| and will use a Windows Application Model Id of |
+// |app_model_id|. |
+void CheckAppListTaskbarShortcutOnFileThread(const FilePath user_data_dir, |
gab
2012/11/02 04:36:28
nit: Should this be const FilePath&?
gab
2012/11/02 12:37:28
Ping.
|
+ const string16& app_model_id) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
+ |
+ const string16 shortcut_name = l10n_util::GetStringUTF16( |
+ IDS_APP_LIST_SHORTCUT_NAME); |
+ const FilePath shortcut_path(user_data_dir.Append(shortcut_name). |
+ AddExtension(L"lnk")); |
gab
2012/11/02 04:36:28
nit: put '.' on this line to make it more obvious
benwells
2012/11/02 04:54:43
Done.
|
+ const 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; |
gab
2012/11/02 04:36:28
It will probably be easier to use the ShellUtil AP
benwells
2012/11/02 04:54:43
Yes this is temporary, and will be removed when th
|
+ 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(shortcut_name); |
+ |
+ 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, kIconIndex); |
+ shortcut_properties.set_app_id(app_model_id); |
+ shortcut_properties.set_dual_mode(false); |
gab
2012/11/02 03:47:15
You don't need to explicitly set dual_mode to fals
benwells
2012/11/02 04:54:43
Done.
|
+ |
+ 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 +430,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(); |
gab
2012/11/02 03:47:15
nit: Also use () initialization here instead of '=
benwells
2012/11/02 04:54:43
Done.
|
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&CheckAppListTaskbarShortcutOnFileThread, user_data_dir, |
+ app_model_id)); |
+} |
+ |
} // namespace app_list_controller |