Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(762)

Side by Side Diff: chrome/browser/web_applications/web_app_win.cc

Issue 14533004: Start menu shortcuts for apps on Windows are now inside a "Chrome Apps" submenu. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor nit. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/create_application_shortcut_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/web_applications/web_app.h" 5 #include "chrome/browser/web_applications/web_app.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/md5.h" 12 #include "base/md5.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/win/shortcut.h" 16 #include "base/win/shortcut.h"
17 #include "base/win/windows_version.h" 17 #include "base/win/windows_version.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/installer/launcher_support/chrome_launcher_support.h" 19 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
20 #include "chrome/installer/util/util_constants.h" 20 #include "chrome/installer/util/util_constants.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "grit/chromium_strings.h"
23 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/gfx/icon_util.h" 24 #include "ui/gfx/icon_util.h"
23 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
24 #include "ui/gfx/image/image_family.h" 26 #include "ui/gfx/image/image_family.h"
25 27
26 namespace { 28 namespace {
27 29
28 const base::FilePath::CharType kIconChecksumFileExt[] = 30 const base::FilePath::CharType kIconChecksumFileExt[] =
29 FILE_PATH_LITERAL(".ico.md5"); 31 FILE_PATH_LITERAL(".ico.md5");
30 32
31 // Width and height of icons exported to .ico files. 33 // Width and height of icons exported to .ico files.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 235 }
234 } 236 }
235 base::win::ShortcutProperties shortcut_properties; 237 base::win::ShortcutProperties shortcut_properties;
236 shortcut_properties.set_target(chrome_exe); 238 shortcut_properties.set_target(chrome_exe);
237 shortcut_properties.set_working_dir(working_dir); 239 shortcut_properties.set_working_dir(working_dir);
238 shortcut_properties.set_arguments(wide_switches); 240 shortcut_properties.set_arguments(wide_switches);
239 shortcut_properties.set_description(description); 241 shortcut_properties.set_description(description);
240 shortcut_properties.set_icon(icon_file, 0); 242 shortcut_properties.set_icon(icon_file, 0);
241 shortcut_properties.set_app_id(app_id); 243 shortcut_properties.set_app_id(app_id);
242 shortcut_properties.set_dual_mode(false); 244 shortcut_properties.set_dual_mode(false);
245 if (!file_util::PathExists(shortcut_file.DirName()) &&
246 !file_util::CreateDirectory(shortcut_file.DirName())) {
247 NOTREACHED();
248 return false;
249 }
243 success = base::win::CreateOrUpdateShortcutLink( 250 success = base::win::CreateOrUpdateShortcutLink(
244 shortcut_file, shortcut_properties, 251 shortcut_file, shortcut_properties,
245 base::win::SHORTCUT_CREATE_ALWAYS) && success; 252 base::win::SHORTCUT_CREATE_ALWAYS) && success;
246 } 253 }
247 254
248 if (success && pin_to_taskbar) { 255 if (success && pin_to_taskbar) {
249 // Use the web app path shortcut for pinning to avoid having unique numbers 256 // Use the web app path shortcut for pinning to avoid having unique numbers
250 // in the application name. 257 // in the application name.
251 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). 258 base::FilePath shortcut_to_pin = web_app_path.Append(file_name).
252 AddExtension(installer::kLnkExt); 259 AddExtension(installer::kLnkExt);
(...skipping 23 matching lines...) Expand all
276 void DeletePlatformShortcuts( 283 void DeletePlatformShortcuts(
277 const base::FilePath& web_app_path, 284 const base::FilePath& web_app_path,
278 const ShellIntegration::ShortcutInfo& shortcut_info) { 285 const ShellIntegration::ShortcutInfo& shortcut_info) {
279 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 286 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
280 287
281 // Get all possible locations for shortcuts. 288 // Get all possible locations for shortcuts.
282 ShellIntegration::ShortcutLocations all_shortcut_locations; 289 ShellIntegration::ShortcutLocations all_shortcut_locations;
283 all_shortcut_locations.in_applications_menu = true; 290 all_shortcut_locations.in_applications_menu = true;
284 all_shortcut_locations.in_quick_launch_bar = true; 291 all_shortcut_locations.in_quick_launch_bar = true;
285 all_shortcut_locations.on_desktop = true; 292 all_shortcut_locations.on_desktop = true;
293 // Delete shortcuts from the Chrome Apps subdirectory.
294 // This matches the subdir name set by CreateApplicationShortcutView::Accept
295 // for Chrome apps (not URL apps, but this function does not apply for them).
296 string16 start_menu_subdir =
297 l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME);
298 all_shortcut_locations.applications_menu_subdir = start_menu_subdir;
286 std::vector<base::FilePath> shortcut_paths = GetShortcutPaths( 299 std::vector<base::FilePath> shortcut_paths = GetShortcutPaths(
287 all_shortcut_locations); 300 all_shortcut_locations);
288 if (base::win::GetVersion() >= base::win::VERSION_WIN7) 301 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
289 shortcut_paths.push_back(web_app_path); 302 shortcut_paths.push_back(web_app_path);
290 303
291 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin(); 304 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin();
292 i != shortcut_paths.end(); ++i) { 305 i != shortcut_paths.end(); ++i) {
293 std::vector<base::FilePath> shortcut_files = 306 std::vector<base::FilePath> shortcut_files =
294 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path, 307 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path,
295 shortcut_info.title); 308 shortcut_info.title);
296 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); 309 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin();
297 j != shortcut_files.end(); ++j) { 310 j != shortcut_files.end(); ++j) {
298 // Any shortcut could have been pinned, either by chrome or the user, so 311 // Any shortcut could have been pinned, either by chrome or the user, so
299 // they are all unpinned. 312 // they are all unpinned.
300 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); 313 base::win::TaskbarUnpinShortcutLink(j->value().c_str());
301 file_util::Delete(*j, false); 314 file_util::Delete(*j, false);
302 } 315 }
303 } 316 }
317
318 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
319 base::FilePath chrome_apps_dir;
320 if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) {
321 chrome_apps_dir = chrome_apps_dir.Append(start_menu_subdir);
322 if (file_util::IsDirectoryEmpty(chrome_apps_dir))
323 file_util::Delete(chrome_apps_dir, false);
324 }
304 } 325 }
305 326
306 std::vector<base::FilePath> GetShortcutPaths( 327 std::vector<base::FilePath> GetShortcutPaths(
307 const ShellIntegration::ShortcutLocations& creation_locations) { 328 const ShellIntegration::ShortcutLocations& creation_locations) {
308 // Shortcut paths under which to create shortcuts. 329 // Shortcut paths under which to create shortcuts.
309 std::vector<base::FilePath> shortcut_paths; 330 std::vector<base::FilePath> shortcut_paths;
310 // Locations to add to shortcut_paths. 331 // Locations to add to shortcut_paths.
311 struct { 332 struct {
312 bool use_this_location; 333 bool use_this_location;
313 int location_id; 334 int location_id;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 path = path.Append(locations[i].subdir); 370 path = path.Append(locations[i].subdir);
350 shortcut_paths.push_back(path); 371 shortcut_paths.push_back(path);
351 } 372 }
352 } 373 }
353 return shortcut_paths; 374 return shortcut_paths;
354 } 375 }
355 376
356 } // namespace internals 377 } // namespace internals
357 378
358 } // namespace web_app 379 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/create_application_shortcut_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698