OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/shell_integration_win.h" | 5 #include "chrome/browser/shell_integration_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shlwapi.h> | 8 #include <shlwapi.h> |
9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
10 #include <propkey.h> // Needs to come after shobjidl.h. | 10 #include <propkey.h> // Needs to come after shobjidl.h. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 #include "chrome/installer/util/work_item_list.h" | 52 #include "chrome/installer/util/work_item_list.h" |
53 #include "components/variations/variations_associated_data.h" | 53 #include "components/variations/variations_associated_data.h" |
54 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
55 | 55 |
56 using content::BrowserThread; | 56 using content::BrowserThread; |
57 | 57 |
58 namespace shell_integration { | 58 namespace shell_integration { |
59 | 59 |
60 namespace { | 60 namespace { |
61 | 61 |
62 const wchar_t kAppListAppNameSuffix[] = L"AppList"; | |
63 | |
64 // Helper function for GetAppId to generates profile id | 62 // Helper function for GetAppId to generates profile id |
65 // from profile path. "profile_id" is composed of sanitized basenames of | 63 // from profile path. "profile_id" is composed of sanitized basenames of |
66 // user data dir and profile dir joined by a ".". | 64 // user data dir and profile dir joined by a ".". |
67 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { | 65 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { |
68 // Return empty string if profile_path is empty | 66 // Return empty string if profile_path is empty |
69 if (profile_path.empty()) | 67 if (profile_path.empty()) |
70 return base::string16(); | 68 return base::string16(); |
71 | 69 |
72 base::FilePath default_user_data_dir; | 70 base::FilePath default_user_data_dir; |
73 // Return empty string if profile_path is in default user data | 71 // Return empty string if profile_path is in default user data |
(...skipping 16 matching lines...) Expand all Loading... | |
90 for (size_t i = 0; i < basenames.length(); ++i) { | 88 for (size_t i = 0; i < basenames.length(); ++i) { |
91 if (base::IsAsciiAlpha(basenames[i]) || | 89 if (base::IsAsciiAlpha(basenames[i]) || |
92 base::IsAsciiDigit(basenames[i]) || | 90 base::IsAsciiDigit(basenames[i]) || |
93 basenames[i] == L'.') | 91 basenames[i] == L'.') |
94 profile_id += basenames[i]; | 92 profile_id += basenames[i]; |
95 } | 93 } |
96 | 94 |
97 return profile_id; | 95 return profile_id; |
98 } | 96 } |
99 | 97 |
100 base::string16 GetAppListAppName() { | |
101 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
102 base::string16 app_name(dist->GetBaseAppId()); | |
103 app_name.append(kAppListAppNameSuffix); | |
104 return app_name; | |
105 } | |
106 | |
107 // Gets expected app id for given Chrome (based on |command_line| and | 98 // Gets expected app id for given Chrome (based on |command_line| and |
108 // |is_per_user_install|). | 99 // |is_per_user_install|). |
109 base::string16 GetExpectedAppId(const base::CommandLine& command_line, | 100 base::string16 GetExpectedAppId(const base::CommandLine& command_line, |
110 bool is_per_user_install) { | 101 bool is_per_user_install) { |
111 base::FilePath user_data_dir; | 102 base::FilePath user_data_dir; |
112 if (command_line.HasSwitch(switches::kUserDataDir)) | 103 if (command_line.HasSwitch(switches::kUserDataDir)) |
113 user_data_dir = command_line.GetSwitchValuePath(switches::kUserDataDir); | 104 user_data_dir = command_line.GetSwitchValuePath(switches::kUserDataDir); |
114 else | 105 else |
115 chrome::GetDefaultUserDataDirectory(&user_data_dir); | 106 chrome::GetDefaultUserDataDirectory(&user_data_dir); |
116 // Adjust with any policy that overrides any other way to set the path. | 107 // Adjust with any policy that overrides any other way to set the path. |
(...skipping 11 matching lines...) Expand all Loading... | |
128 DCHECK(!profile_subdir.empty()); | 119 DCHECK(!profile_subdir.empty()); |
129 | 120 |
130 base::FilePath profile_path = user_data_dir.Append(profile_subdir); | 121 base::FilePath profile_path = user_data_dir.Append(profile_subdir); |
131 base::string16 app_name; | 122 base::string16 app_name; |
132 if (command_line.HasSwitch(switches::kApp)) { | 123 if (command_line.HasSwitch(switches::kApp)) { |
133 app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( | 124 app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( |
134 GURL(command_line.GetSwitchValueASCII(switches::kApp)))); | 125 GURL(command_line.GetSwitchValueASCII(switches::kApp)))); |
135 } else if (command_line.HasSwitch(switches::kAppId)) { | 126 } else if (command_line.HasSwitch(switches::kAppId)) { |
136 app_name = base::UTF8ToUTF16( | 127 app_name = base::UTF8ToUTF16( |
137 web_app::GenerateApplicationNameFromExtensionId( | 128 web_app::GenerateApplicationNameFromExtensionId( |
138 command_line.GetSwitchValueASCII(switches::kAppId))); | 129 command_line.GetSwitchValueASCII(switches::kAppId))); |
huangs
2016/05/04 15:54:07
Delete other instances of kShowAppList? Or perhap
tapted
2016/05/05 07:14:18
There's a bit about this on the bug at http://crbu
| |
139 } else if (command_line.HasSwitch(switches::kShowAppList)) { | |
140 app_name = GetAppListAppName(); | |
141 } else { | 130 } else { |
142 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 131 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
143 app_name = ShellUtil::GetBrowserModelId(dist, is_per_user_install); | 132 app_name = ShellUtil::GetBrowserModelId(dist, is_per_user_install); |
144 } | 133 } |
145 DCHECK(!app_name.empty()); | 134 DCHECK(!app_name.empty()); |
146 | 135 |
147 return win::GetAppModelIdForProfile(app_name, profile_path); | 136 return win::GetAppModelIdForProfile(app_name, profile_path); |
148 } | 137 } |
149 | 138 |
150 void MigrateTaskbarPinsCallback() { | 139 void MigrateTaskbarPinsCallback() { |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 545 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
557 NOTREACHED(); | 546 NOTREACHED(); |
558 return dist->GetBaseAppId(); | 547 return dist->GetBaseAppId(); |
559 } | 548 } |
560 return GetAppModelIdForProfile( | 549 return GetAppModelIdForProfile( |
561 ShellUtil::GetBrowserModelId(dist, | 550 ShellUtil::GetBrowserModelId(dist, |
562 InstallUtil::IsPerUserInstall(chrome_exe)), | 551 InstallUtil::IsPerUserInstall(chrome_exe)), |
563 profile_path); | 552 profile_path); |
564 } | 553 } |
565 | 554 |
566 base::string16 GetAppListAppModelIdForProfile( | |
567 const base::FilePath& profile_path) { | |
568 return GetAppModelIdForProfile(GetAppListAppName(), profile_path); | |
569 } | |
570 | |
571 void MigrateTaskbarPins() { | 555 void MigrateTaskbarPins() { |
572 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 556 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
573 return; | 557 return; |
574 | 558 |
575 // This needs to happen eventually (e.g. so that the appid is fixed and the | 559 // This needs to happen eventually (e.g. so that the appid is fixed and the |
576 // run-time Chrome icon is merged with the taskbar shortcut), but this is not | 560 // run-time Chrome icon is merged with the taskbar shortcut), but this is not |
577 // urgent and shouldn't delay Chrome startup. | 561 // urgent and shouldn't delay Chrome startup. |
578 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; | 562 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; |
579 BrowserThread::PostDelayedTask( | 563 BrowserThread::PostDelayedTask( |
580 BrowserThread::FILE, FROM_HERE, | 564 BrowserThread::FILE, FROM_HERE, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 } | 673 } |
690 return shortcuts_migrated; | 674 return shortcuts_migrated; |
691 } | 675 } |
692 | 676 |
693 base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe) { | 677 base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe) { |
694 static const int kFolderIds[] = { | 678 static const int kFolderIds[] = { |
695 base::DIR_COMMON_START_MENU, | 679 base::DIR_COMMON_START_MENU, |
696 base::DIR_START_MENU, | 680 base::DIR_START_MENU, |
697 }; | 681 }; |
698 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 682 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
699 const base::string16 shortcut_name( | 683 const base::string16 shortcut_name(dist->GetShortcutName() + |
700 dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | 684 installer::kLnkExt); |
701 installer::kLnkExt); | |
702 base::FilePath programs_folder; | 685 base::FilePath programs_folder; |
703 base::FilePath shortcut; | 686 base::FilePath shortcut; |
704 | 687 |
705 // Check both the common and the per-user Start Menu folders for system-level | 688 // Check both the common and the per-user Start Menu folders for system-level |
706 // installs. | 689 // installs. |
707 size_t folder = InstallUtil::IsPerUserInstall(chrome_exe) ? 1 : 0; | 690 size_t folder = InstallUtil::IsPerUserInstall(chrome_exe) ? 1 : 0; |
708 for (; folder < arraysize(kFolderIds); ++folder) { | 691 for (; folder < arraysize(kFolderIds); ++folder) { |
709 if (!PathService::Get(kFolderIds[folder], &programs_folder)) { | 692 if (!PathService::Get(kFolderIds[folder], &programs_folder)) { |
710 NOTREACHED(); | 693 NOTREACHED(); |
711 continue; | 694 continue; |
712 } | 695 } |
713 | 696 |
714 shortcut = programs_folder.Append(shortcut_name); | 697 shortcut = programs_folder.Append(shortcut_name); |
715 if (base::PathExists(shortcut)) | 698 if (base::PathExists(shortcut)) |
716 return shortcut; | 699 return shortcut; |
717 } | 700 } |
718 | 701 |
719 return base::FilePath(); | 702 return base::FilePath(); |
720 } | 703 } |
721 | 704 |
722 } // namespace win | 705 } // namespace win |
723 | 706 |
724 } // namespace shell_integration | 707 } // namespace shell_integration |
OLD | NEW |