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

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

Issue 13620002: Fix shortcut name slicing for v2 apps on windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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 | « no previous file | 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"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return false; 140 return false;
141 } 141 }
142 142
143 std::vector<base::FilePath> MatchingShortcutsForProfileAndExtension( 143 std::vector<base::FilePath> MatchingShortcutsForProfileAndExtension(
144 const base::FilePath& shortcut_path, 144 const base::FilePath& shortcut_path,
145 const base::FilePath& profile_path, 145 const base::FilePath& profile_path,
146 const string16& shortcut_name) { 146 const string16& shortcut_name) {
147 std::vector<base::FilePath> shortcut_paths; 147 std::vector<base::FilePath> shortcut_paths;
148 base::FilePath base_path = shortcut_path. 148 base::FilePath base_path = shortcut_path.
149 Append(web_app::internals::GetSanitizedFileName(shortcut_name)). 149 Append(web_app::internals::GetSanitizedFileName(shortcut_name)).
150 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); 150 AddExtension(FILE_PATH_LITERAL(".lnk"));
151 151
152 const int fileNamesToCheck = 10; 152 const int fileNamesToCheck = 10;
153 for (int i = 0; i < fileNamesToCheck; ++i) { 153 for (int i = 0; i < fileNamesToCheck; ++i) {
154 base::FilePath shortcut_file = base_path; 154 base::FilePath shortcut_file = base_path;
155 if (i) { 155 if (i) {
156 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( 156 shortcut_file = shortcut_file.InsertBeforeExtensionASCII(
157 base::StringPrintf(" (%d)", i)); 157 base::StringPrintf(" (%d)", i));
158 } 158 }
159 if (file_util::PathExists(shortcut_file) && 159 if (file_util::PathExists(shortcut_file) &&
160 ShortcutIsForProfile(shortcut_file, profile_path)) { 160 ShortcutIsForProfile(shortcut_file, profile_path)) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (!file_util::PathExists(web_app_path) && 227 if (!file_util::PathExists(web_app_path) &&
228 !file_util::CreateDirectory(web_app_path)) { 228 !file_util::CreateDirectory(web_app_path)) {
229 return false; 229 return false;
230 } 230 }
231 231
232 // Generates file name to use with persisted ico and shortcut file. 232 // Generates file name to use with persisted ico and shortcut file.
233 base::FilePath file_name = 233 base::FilePath file_name =
234 web_app::internals::GetSanitizedFileName(shortcut_info.title); 234 web_app::internals::GetSanitizedFileName(shortcut_info.title);
235 235
236 // Creates an ico file to use with shortcut. 236 // Creates an ico file to use with shortcut.
237 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( 237 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension(
238 FILE_PATH_LITERAL(".ico")); 238 FILE_PATH_LITERAL(".ico"));
239 if (!web_app::internals::CheckAndSaveIcon(icon_file, 239 if (!web_app::internals::CheckAndSaveIcon(icon_file,
240 *shortcut_info.favicon.ToSkBitmap())) { 240 *shortcut_info.favicon.ToSkBitmap())) {
241 return false; 241 return false;
242 } 242 }
243 243
244 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info); 244 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info);
245 DCHECK(!target_exe.empty()); 245 DCHECK(!target_exe.empty());
246 246
247 // Working directory. 247 // Working directory.
(...skipping 15 matching lines...) Expand all
263 description.resize(MAX_PATH - 1); 263 description.resize(MAX_PATH - 1);
264 264
265 // Generates app id from web app url and profile path. 265 // Generates app id from web app url and profile path.
266 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); 266 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info));
267 string16 app_id(ShellIntegration::GetAppModelIdForProfile( 267 string16 app_id(ShellIntegration::GetAppModelIdForProfile(
268 UTF8ToUTF16(app_name), shortcut_info.profile_path)); 268 UTF8ToUTF16(app_name), shortcut_info.profile_path));
269 269
270 bool success = true; 270 bool success = true;
271 for (size_t i = 0; i < shortcut_paths.size(); ++i) { 271 for (size_t i = 0; i < shortcut_paths.size(); ++i) {
272 base::FilePath shortcut_file = shortcut_paths[i].Append(file_name). 272 base::FilePath shortcut_file = shortcut_paths[i].Append(file_name).
273 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); 273 AddExtension(FILE_PATH_LITERAL(".lnk"));
274 if (shortcut_paths[i] != web_app_path) { 274 if (shortcut_paths[i] != web_app_path) {
275 int unique_number = 275 int unique_number =
276 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); 276 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL(""));
277 if (unique_number == -1) { 277 if (unique_number == -1) {
278 success = false; 278 success = false;
279 continue; 279 continue;
280 } else if (unique_number > 0) { 280 } else if (unique_number > 0) {
281 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( 281 shortcut_file = shortcut_file.InsertBeforeExtensionASCII(
282 base::StringPrintf(" (%d)", unique_number)); 282 base::StringPrintf(" (%d)", unique_number));
283 } 283 }
284 } 284 }
285 base::win::ShortcutProperties shortcut_properties; 285 base::win::ShortcutProperties shortcut_properties;
286 shortcut_properties.set_target(target_exe); 286 shortcut_properties.set_target(target_exe);
287 shortcut_properties.set_working_dir(working_dir); 287 shortcut_properties.set_working_dir(working_dir);
288 shortcut_properties.set_arguments(wide_switches); 288 shortcut_properties.set_arguments(wide_switches);
289 shortcut_properties.set_description(description); 289 shortcut_properties.set_description(description);
290 shortcut_properties.set_icon(icon_file, 0); 290 shortcut_properties.set_icon(icon_file, 0);
291 shortcut_properties.set_app_id(app_id); 291 shortcut_properties.set_app_id(app_id);
292 shortcut_properties.set_dual_mode(false); 292 shortcut_properties.set_dual_mode(false);
293 success = base::win::CreateOrUpdateShortcutLink( 293 success = base::win::CreateOrUpdateShortcutLink(
294 shortcut_file, shortcut_properties, 294 shortcut_file, shortcut_properties,
295 base::win::SHORTCUT_CREATE_ALWAYS) && success; 295 base::win::SHORTCUT_CREATE_ALWAYS) && success;
296 } 296 }
297 297
298 if (success && pin_to_taskbar) { 298 if (success && pin_to_taskbar) {
299 // Use the web app path shortcut for pinning to avoid having unique numbers 299 // Use the web app path shortcut for pinning to avoid having unique numbers
300 // in the application name. 300 // in the application name.
301 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). 301 base::FilePath shortcut_to_pin = web_app_path.Append(file_name).
302 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); 302 AddExtension(FILE_PATH_LITERAL(".lnk"));
303 success = base::win::TaskbarPinShortcutLink( 303 success = base::win::TaskbarPinShortcutLink(
304 shortcut_to_pin.value().c_str()) && success; 304 shortcut_to_pin.value().c_str()) && success;
305 } 305 }
306 306
307 return success; 307 return success;
308 } 308 }
309 309
310 void UpdatePlatformShortcuts( 310 void UpdatePlatformShortcuts(
311 const base::FilePath& web_app_path, 311 const base::FilePath& web_app_path,
312 const ShellIntegration::ShortcutInfo& shortcut_info) { 312 const ShellIntegration::ShortcutInfo& shortcut_info) {
313 // Generates file name to use with persisted ico and shortcut file. 313 // Generates file name to use with persisted ico and shortcut file.
314 base::FilePath file_name = 314 base::FilePath file_name =
315 web_app::internals::GetSanitizedFileName(shortcut_info.title); 315 web_app::internals::GetSanitizedFileName(shortcut_info.title);
316 316
317 // If an icon file exists, and is out of date, replace it with the new icon 317 // If an icon file exists, and is out of date, replace it with the new icon
318 // and let the shell know the icon has been modified. 318 // and let the shell know the icon has been modified.
319 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( 319 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension(
320 FILE_PATH_LITERAL(".ico")); 320 FILE_PATH_LITERAL(".ico"));
321 if (file_util::PathExists(icon_file)) { 321 if (file_util::PathExists(icon_file)) {
322 web_app::internals::CheckAndSaveIcon(icon_file, 322 web_app::internals::CheckAndSaveIcon(icon_file,
323 *shortcut_info.favicon.ToSkBitmap()); 323 *shortcut_info.favicon.ToSkBitmap());
324 } 324 }
325 } 325 }
326 326
327 void DeletePlatformShortcuts( 327 void DeletePlatformShortcuts(
328 const base::FilePath& web_app_path, 328 const base::FilePath& web_app_path,
329 const ShellIntegration::ShortcutInfo& shortcut_info) { 329 const ShellIntegration::ShortcutInfo& shortcut_info) {
(...skipping 20 matching lines...) Expand all
350 // they are all unpinned. 350 // they are all unpinned.
351 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); 351 base::win::TaskbarUnpinShortcutLink(j->value().c_str());
352 file_util::Delete(*j, false); 352 file_util::Delete(*j, false);
353 } 353 }
354 } 354 }
355 } 355 }
356 356
357 } // namespace internals 357 } // namespace internals
358 358
359 } // namespace web_app 359 } // namespace web_app
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698