web_app_win.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/web_applications/web_app_win.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <shlobj.h> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_util.h" 11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/files/file_enumerator.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/md5.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/strings/string_piece.h" 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h" 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/shortcut.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/windows_version.h" 20c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/web_applications/update_shortcut_worker_win.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/installer/util/browser_distribution.h" 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/installer/util/shell_util.h" 24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/installer/util/util_constants.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_thread.h" 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/base/win/shell.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/icon_util.h" 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/gfx/image/image.h" 29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/gfx/image/image_family.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const base::FilePath::CharType kIconChecksumFileExt[] = 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FILE_PATH_LITERAL(".ico.md5"); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Calculates checksum of an icon family using MD5. 37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// The checksum is derived from all of the icons in the family. 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void GetImageCheckSum(const gfx::ImageFamily& image, base::MD5Digest* digest) { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(digest); 40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MD5Context md5_context; 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MD5Init(&md5_context); 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (gfx::ImageFamily::const_iterator it = image.begin(); it != image.end(); 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ++it) { 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SkBitmap bitmap = it->AsBitmap(); 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SkAutoLockPixels image_lock(bitmap); 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::StringPiece image_data( 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) reinterpret_cast<const char*>(bitmap.getPixels()), bitmap.getSize()); 50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MD5Update(&md5_context, image_data); 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MD5Final(digest, &md5_context); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Saves |image| as an |icon_file| with the checksum. 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool SaveIconWithCheckSum(const base::FilePath& icon_file, 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::ImageFamily& image) { 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!IconUtil::CreateIconFileFromImageFamily(image, icon_file)) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::MD5Digest digest; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetImageCheckSum(image, &digest); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath cheksum_file(icon_file.ReplaceExtension(kIconChecksumFileExt)); 66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return base::WriteFile(cheksum_file, 67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) reinterpret_cast<const char*>(&digest), 68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) sizeof(digest)) == sizeof(digest); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true if |icon_file| is missing or different from |image|. 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool ShouldUpdateIcon(const base::FilePath& icon_file, 73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::ImageFamily& image) { 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath checksum_file( 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) icon_file.ReplaceExtension(kIconChecksumFileExt)); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if icon_file or checksum file is missing. 787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!base::PathExists(icon_file) || 797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch !base::PathExists(checksum_file)) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::MD5Digest persisted_image_checksum; 83a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (sizeof(persisted_image_checksum) != base::ReadFile(checksum_file, 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reinterpret_cast<char*>(&persisted_image_checksum), 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sizeof(persisted_image_checksum))) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::MD5Digest downloaded_image_checksum; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetImageCheckSum(image, &downloaded_image_checksum); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update icon if checksums are not equal. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return memcmp(&persisted_image_checksum, &downloaded_image_checksum, 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sizeof(base::MD5Digest)) != 0; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Returns true if |shortcut_file_name| matches profile |profile_path|, and has 97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// an --app-id flag. 98eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool IsAppShortcutForProfile(const base::FilePath& shortcut_file_name, 99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath& profile_path) { 100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 cmd_line_string; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::ResolveShortcut(shortcut_file_name, NULL, &cmd_line_string)) { 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cmd_line_string = L"program " + cmd_line_string; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandLine shortcut_cmd_line = CommandLine::FromString(cmd_line_string); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return shortcut_cmd_line.HasSwitch(switches::kProfileDirectory) && 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_cmd_line.GetSwitchValuePath(switches::kProfileDirectory) == 106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profile_path.BaseName() && 107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch shortcut_cmd_line.HasSwitch(switches::kAppId); 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Finds shortcuts in |shortcut_path| that match profile for |profile_path| and 114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// extension with title |shortcut_name|. 115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// If |shortcut_name| is empty, finds all shortcuts matching |profile_path|. 116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochstd::vector<base::FilePath> FindAppShortcutsByProfileAndTitle( 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& shortcut_path, 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path, 119a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& shortcut_name) { 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<base::FilePath> shortcut_paths; 121eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (shortcut_name.empty()) { 123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Find all shortcuts for this profile. 124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FileEnumerator files(shortcut_path, false, 125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FileEnumerator::FILES, 126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FILE_PATH_LITERAL("*.lnk")); 127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath shortcut_file = files.Next(); 128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch while (!shortcut_file.empty()) { 129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (IsAppShortcutForProfile(shortcut_file, profile_path)) 130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch shortcut_paths.push_back(shortcut_file); 131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch shortcut_file = files.Next(); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } else { 134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Find all shortcuts matching |shortcut_name|. 135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath base_path = shortcut_path. 136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Append(web_app::internals::GetSanitizedFileName(shortcut_name)). 137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AddExtension(FILE_PATH_LITERAL(".lnk")); 138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const int fileNamesToCheck = 10; 140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch for (int i = 0; i < fileNamesToCheck; ++i) { 141eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath shortcut_file = base_path; 142eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (i > 0) { 143eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch shortcut_file = shortcut_file.InsertBeforeExtensionASCII( 144eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::StringPrintf(" (%d)", i)); 145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 1467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (base::PathExists(shortcut_file) && 147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch IsAppShortcutForProfile(shortcut_file, profile_path)) { 148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch shortcut_paths.push_back(shortcut_file); 149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return shortcut_paths; 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Creates application shortcuts in a given set of paths. 15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// |shortcut_paths| is a list of directories in which shortcuts should be 158558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// created. If |creation_reason| is SHORTCUT_CREATION_AUTOMATED and there is an 159558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// existing shortcut to this app for this profile, does nothing (succeeding). 16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Returns true on success, false on failure. 16190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Must be called on the FILE thread. 16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool CreateShortcutsInPaths( 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& web_app_path, 164a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const web_app::ShortcutInfo& shortcut_info, 165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::vector<base::FilePath>& shortcut_paths, 166558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch web_app::ShortcutCreationReason creation_reason, 167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<base::FilePath>* out_filenames) { 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Ensure web_app_path exists. 1697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!base::PathExists(web_app_path) && 170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) !base::CreateDirectory(web_app_path)) { 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Generates file name to use with persisted ico and shortcut file. 175effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath icon_file = 176effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch web_app::internals::GetIconFilePath(web_app_path, shortcut_info.title); 177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon)) { 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::FilePath chrome_exe; 182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NOTREACHED(); 184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return false; 185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Working directory. 188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::FilePath working_dir(chrome_exe.DirName()); 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandLine cmd_line(CommandLine::NO_PROGRAM); 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cmd_line = ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_info.extension_id, shortcut_info.profile_path); 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(evan): we rely on the fact that command_line_string() is 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // properly quoted for a Windows command line. The method on 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // CommandLine should probably be renamed to better reflect that 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // fact. 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 wide_switches(cmd_line.GetCommandLineString()); 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sanitize description 201a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 description = shortcut_info.description; 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (description.length() >= MAX_PATH) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) description.resize(MAX_PATH - 1); 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Generates app id from web app url and profile path. 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); 207a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 app_id(ShellIntegration::GetAppModelIdForProfile( 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::UTF8ToUTF16(app_name), shortcut_info.profile_path)); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool success = true; 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < shortcut_paths.size(); ++i) { 212effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath shortcut_file = 213effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch shortcut_paths[i] 214effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch .Append( 215effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch web_app::internals::GetSanitizedFileName(shortcut_info.title)) 216effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch .AddExtension(installer::kLnkExt); 217558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch if (creation_reason == web_app::SHORTCUT_CREATION_AUTOMATED) { 218eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Check whether there is an existing shortcut to this app. 219eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<base::FilePath> shortcut_files = 220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FindAppShortcutsByProfileAndTitle(shortcut_paths[i], 221eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch shortcut_info.profile_path, 222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch shortcut_info.title); 223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!shortcut_files.empty()) 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch continue; 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (shortcut_paths[i] != web_app_path) { 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int unique_number = 228a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::GetUniquePathNumber(shortcut_file, 229a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::FilePath::StringType()); 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (unique_number == -1) { 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) success = false; 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) continue; 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (unique_number > 0) { 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shortcut_file = shortcut_file.InsertBeforeExtensionASCII( 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::StringPrintf(" (%d)", unique_number)); 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::ShortcutProperties shortcut_properties; 239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) shortcut_properties.set_target(chrome_exe); 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_properties.set_working_dir(working_dir); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_properties.set_arguments(wide_switches); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_properties.set_description(description); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_properties.set_icon(icon_file, 0); 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_properties.set_app_id(app_id); 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_properties.set_dual_mode(false); 2467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!base::PathExists(shortcut_file.DirName()) && 247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) !base::CreateDirectory(shortcut_file.DirName())) { 248c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NOTREACHED(); 249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return false; 250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) success = base::win::CreateOrUpdateShortcutLink( 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut_file, shortcut_properties, 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::SHORTCUT_CREATE_ALWAYS) && success; 254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (out_filenames) 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch out_filenames->push_back(shortcut_file); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 25890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return success; 25990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 26090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 26190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Gets the directories with shortcuts for an app, and deletes the shortcuts. 26290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// This will search the standard locations for shortcuts named |title| that open 26390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// in the profile with |profile_path|. 26490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// |was_pinned_to_taskbar| will be set to true if there was previously a 26590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shortcut pinned to the taskbar for this app; false otherwise. 266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// If |web_app_path| is empty, this will not delete shortcuts from the web app 267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// directory. If |title| is empty, all shortcuts for this profile will be 268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// deleted. 26990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// |shortcut_paths| will be populated with a list of directories where shortcuts 27090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// for this app were found (and deleted). This will delete duplicate shortcuts, 27190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// but only return each path once, even if it contained multiple deleted 27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shortcuts. Both of these may be NULL. 27390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void GetShortcutLocationsAndDeleteShortcuts( 27490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const base::FilePath& web_app_path, 27590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const base::FilePath& profile_path, 276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& title, 27790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool* was_pinned_to_taskbar, 27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<base::FilePath>* shortcut_paths) { 27990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 28190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Get all possible locations for shortcuts. 282a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch web_app::ShortcutLocations all_shortcut_locations; 28390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) all_shortcut_locations.in_quick_launch_bar = true; 28490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) all_shortcut_locations.on_desktop = true; 28590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Delete shortcuts from the Chrome Apps subdirectory. 28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // This matches the subdir name set by CreateApplicationShortcutView::Accept 28790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // for Chrome apps (not URL apps, but this function does not apply for them). 288a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) all_shortcut_locations.applications_menu_location = 289a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; 29090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<base::FilePath> all_paths = web_app::internals::GetShortcutPaths( 29190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) all_shortcut_locations); 292eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (base::win::GetVersion() >= base::win::VERSION_WIN7 && 293eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch !web_app_path.empty()) { 29490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) all_paths.push_back(web_app_path); 295eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 29690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 29790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (was_pinned_to_taskbar) { 29890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Determine if there is a link to this app in the TaskBar pin directory. 29990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::FilePath taskbar_pin_path; 30090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_pin_path)) { 30190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<base::FilePath> taskbar_pin_files = 302eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FindAppShortcutsByProfileAndTitle(taskbar_pin_path, profile_path, 303eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch title); 30490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) *was_pinned_to_taskbar = !taskbar_pin_files.empty(); 30590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else { 30690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) *was_pinned_to_taskbar = false; 30790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 30890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 30990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 31090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) for (std::vector<base::FilePath>::const_iterator i = all_paths.begin(); 31190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) i != all_paths.end(); ++i) { 31290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<base::FilePath> shortcut_files = 313eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FindAppShortcutsByProfileAndTitle(*i, profile_path, title); 31490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (shortcut_paths && !shortcut_files.empty()) { 31590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shortcut_paths->push_back(*i); 31690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 31790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); 31890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) j != shortcut_files.end(); ++j) { 31990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Any shortcut could have been pinned, either by chrome or the user, so 32090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // they are all unpinned. 32190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::win::TaskbarUnpinShortcutLink(j->value().c_str()); 3227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::DeleteFile(*j, false); 32390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 32490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 32590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 32690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 327cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void CreateIconAndSetRelaunchDetails(const base::FilePath& web_app_path, 328cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const base::FilePath& icon_file, 329cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const web_app::ShortcutInfo& shortcut_info, 330cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) HWND hwnd) { 331cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 332cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 333cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CommandLine command_line = 334cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, 335cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) shortcut_info.extension_id, 336cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) shortcut_info.profile_path); 337cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 338cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FilePath chrome_exe; 339cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 340cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) NOTREACHED(); 341cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 342cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 343cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) command_line.SetProgram(chrome_exe); 344cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::win::SetRelaunchDetailsForWindow( 345cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) command_line.GetCommandLineString(), shortcut_info.title, hwnd); 346cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 347cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) 348cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 349cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 350cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::win::SetAppIconForWindow(icon_file.value(), hwnd); 351cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); 352cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 353cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 354cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void OnShortcutInfoLoadedForSetRelaunchDetails( 355cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) HWND hwnd, 356cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const web_app::ShortcutInfo& shortcut_info) { 357cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 358cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 359cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Set window's icon to the one we're about to create/update in the web app 360cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // path. The icon cache will refresh on icon creation. 361cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FilePath web_app_path = 362cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) web_app::GetWebAppDataDirectory(shortcut_info.profile_path, 363cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) shortcut_info.extension_id, 364cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) shortcut_info.url); 365cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FilePath icon_file = 366cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) web_app_path.Append(web_app::internals::GetSanitizedFileName( 367cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) shortcut_info.title)) 368cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) .ReplaceExtension(FILE_PATH_LITERAL(".ico")); 369cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 370cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) content::BrowserThread::PostBlockingPoolTask( 371cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) FROM_HERE, 372cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::Bind(&CreateIconAndSetRelaunchDetails, 373cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) web_app_path, 374cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) icon_file, 375cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) shortcut_info, 376cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) hwnd)); 377cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 378cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 37990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace 38090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 38190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace web_app { 38290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 383cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)base::FilePath CreateShortcutInWebAppDir(const base::FilePath& web_app_dir, 384cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const ShortcutInfo& shortcut_info) { 385eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<base::FilePath> paths; 386eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch paths.push_back(web_app_dir); 387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<base::FilePath> out_filenames; 388effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath web_app_dir_shortcut = 389effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title)) 390effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch .AddExtension(installer::kLnkExt); 391effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!PathExists(web_app_dir_shortcut)) { 392effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch CreateShortcutsInPaths(web_app_dir, 393effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch shortcut_info, 394effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch paths, 395effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SHORTCUT_CREATION_BY_USER, 396effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch &out_filenames); 397effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DCHECK_EQ(out_filenames.size(), 1u); 398effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); 399effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } else { 400effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch internals::CheckAndSaveIcon( 401effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch internals::GetIconFilePath(web_app_dir, shortcut_info.title), 402effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch shortcut_info.favicon); 403effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 404effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return web_app_dir_shortcut; 405eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 406eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 407cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void UpdateRelaunchDetailsForApp(Profile* profile, 408cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const extensions::Extension* extension, 409cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) HWND hwnd) { 410cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) web_app::UpdateShortcutInfoAndIconForApp( 411cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) extension, 412cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profile, 413cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::Bind(&OnShortcutInfoLoadedForSetRelaunchDetails, hwnd)); 414cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 415cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 41646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void UpdateShortcutsForAllApps(Profile* profile, 41746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const base::Closure& callback) { 41846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) callback.Run(); 41946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)} 42046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 42190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace internals { 42290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 42390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Saves |image| to |icon_file| if the file is outdated and refresh shell's 42490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// icon cache to ensure correct icon is displayed. Returns true if icon_file 42590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// is up to date or successfully updated. 42690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool CheckAndSaveIcon(const base::FilePath& icon_file, 42790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const gfx::ImageFamily& image) { 42890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (ShouldUpdateIcon(icon_file, image)) { 42990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (SaveIconWithCheckSum(icon_file, image)) { 43090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Refresh shell's icon cache. This call is quite disruptive as user would 43190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // see explorer rebuilding the icon cache. It would be great that we find 43290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // a better way to achieve this. 43390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, 43490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NULL, NULL); 43590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else { 43690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 43790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 43890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 43990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 44090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return true; 44190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 44290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 44390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool CreatePlatformShortcuts( 44490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const base::FilePath& web_app_path, 445cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const ShortcutInfo& shortcut_info, 446a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const extensions::FileHandlersInfo& file_handlers_info, 447cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const ShortcutLocations& creation_locations, 448558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch ShortcutCreationReason creation_reason) { 44990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 45090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 45190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Shortcut paths under which to create shortcuts. 45290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<base::FilePath> shortcut_paths = 45390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) GetShortcutPaths(creation_locations); 45490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 45590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool pin_to_taskbar = creation_locations.in_quick_launch_bar && 45690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) (base::win::GetVersion() >= base::win::VERSION_WIN7); 45790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 45890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Create/update the shortcut in the web app path for the "Pin To Taskbar" 45990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // option in Win7. We use the web app path shortcut because we will overwrite 46090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // it rather than appending unique numbers if the shortcut already exists. 46190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // This prevents pinned apps from having unique numbers in their names. 46290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (pin_to_taskbar) 46390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shortcut_paths.push_back(web_app_path); 46490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 46590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (shortcut_paths.empty()) 46690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 46790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 468eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths, 469558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch creation_reason, NULL)) 47090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 47190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 47290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (pin_to_taskbar) { 473effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath file_name = GetSanitizedFileName(shortcut_info.title); 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Use the web app path shortcut for pinning to avoid having unique numbers 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in the application name. 4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath shortcut_to_pin = web_app_path.Append(file_name). 477c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddExtension(installer::kLnkExt); 47890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (!base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str())) 47990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 48290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return true; 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void UpdatePlatformShortcuts( 4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& web_app_path, 487a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& old_app_title, 488cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const ShortcutInfo& shortcut_info, 489a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const extensions::FileHandlersInfo& file_handlers_info) { 490c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 491c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Generates file name to use with persisted ico and shortcut file. 4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath file_name = 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_app::internals::GetSanitizedFileName(shortcut_info.title); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 49690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (old_app_title != shortcut_info.title) { 49790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The app's title has changed. Delete all existing app shortcuts and 49890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // recreate them in any locations they already existed (but do not add them 49990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // to locations where they do not currently exist). 50090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool was_pinned_to_taskbar; 50190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<base::FilePath> shortcut_paths; 50290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) GetShortcutLocationsAndDeleteShortcuts( 50390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_app_path, shortcut_info.profile_path, old_app_title, 50490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) &was_pinned_to_taskbar, &shortcut_paths); 505eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths, 506558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch SHORTCUT_CREATION_BY_USER, NULL); 50790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // If the shortcut was pinned to the taskbar, 50890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // GetShortcutLocationsAndDeleteShortcuts will have deleted it. In that 50990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // case, re-pin it. 51090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (was_pinned_to_taskbar) { 511effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath file_name = GetSanitizedFileName(shortcut_info.title); 51290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Use the web app path shortcut for pinning to avoid having unique 51390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // numbers in the application name. 51490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::FilePath shortcut_to_pin = web_app_path.Append(file_name). 51590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AddExtension(installer::kLnkExt); 51690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); 51790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 51890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 51990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 52023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Update the icon if necessary. 521effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title); 522effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch CheckAndSaveIcon(icon_file, shortcut_info.favicon); 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void DeletePlatformShortcuts(const base::FilePath& web_app_path, 526cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const ShortcutInfo& shortcut_info) { 52790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) GetShortcutLocationsAndDeleteShortcuts( 52890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, 52990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NULL); 530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 531c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::FilePath chrome_apps_dir; 533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (ShellUtil::GetShortcutPath( 534a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 535a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BrowserDistribution::GetDistribution(), 536a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::CURRENT_USER, 537a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) &chrome_apps_dir)) { 538a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (base::IsDirectoryEmpty(chrome_apps_dir)) 5397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::DeleteFile(chrome_apps_dir, false); 540eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 541eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 542eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 543eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { 544eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetShortcutLocationsAndDeleteShortcuts(base::FilePath(), profile_path, L"", 545eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch NULL, NULL); 546eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 547eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 548eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath chrome_apps_dir; 549a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (ShellUtil::GetShortcutPath( 550a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 551a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BrowserDistribution::GetDistribution(), 552a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::CURRENT_USER, 553a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) &chrome_apps_dir)) { 554a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (base::IsDirectoryEmpty(chrome_apps_dir)) 5557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::DeleteFile(chrome_apps_dir, false); 556c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 557c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)std::vector<base::FilePath> GetShortcutPaths( 560cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const ShortcutLocations& creation_locations) { 561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Shortcut paths under which to create shortcuts. 562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::vector<base::FilePath> shortcut_paths; 563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Locations to add to shortcut_paths. 564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) struct { 565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool use_this_location; 566a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::ShortcutLocation location_id; 567c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } locations[] = { 568c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) { 569c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) creation_locations.on_desktop, 570a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_DESKTOP 571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }, { 572a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) creation_locations.applications_menu_location == 573cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) APP_MENU_LOCATION_ROOT, 574a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT 575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }, { 576a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) creation_locations.applications_menu_location == 577cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) APP_MENU_LOCATION_SUBDIR_CHROME, 578a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR 579a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }, { 580a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) creation_locations.applications_menu_location == 581cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 582a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR 583a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }, { 584a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // For Win7+, |in_quick_launch_bar| indicates that we are pinning to 585a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // taskbar. This needs to be handled by callers. 586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) creation_locations.in_quick_launch_bar && 587a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::win::GetVersion() < base::win::VERSION_WIN7, 588a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH 589c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }; 591a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 592a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Populate shortcut_paths. 594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (int i = 0; i < arraysize(locations); ++i) { 595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (locations[i].use_this_location) { 596c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::FilePath path; 597a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!ShellUtil::GetShortcutPath(locations[i].location_id, 598a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) dist, 599a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::CURRENT_USER, 600a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) &path)) { 601a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NOTREACHED(); 602c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) continue; 603c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 604c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) shortcut_paths.push_back(path); 605c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 606c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 607c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return shortcut_paths; 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 610effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochbase::FilePath GetIconFilePath(const base::FilePath& web_app_path, 611effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const base::string16& title) { 612effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return web_app_path.Append(GetSanitizedFileName(title)) 613effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch .AddExtension(FILE_PATH_LITERAL(".ico")); 614effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 615effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace internals 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 618c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid UpdateShortcutForTabContents(content::WebContents* web_contents) { 619c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // UpdateShortcutWorker will delete itself when it's done. 620c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); 621c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch worker->Run(); 622c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch} 623c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace web_app 625