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/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app_win.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/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/win/shortcut.h" | 17 #include "base/win/shortcut.h" |
18 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
| 19 #include "chrome/browser/web_applications/web_app.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 21 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
21 #include "chrome/installer/util/util_constants.h" | 22 #include "chrome/installer/util/util_constants.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "ui/gfx/icon_util.h" | 24 #include "ui/gfx/icon_util.h" |
24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
25 #include "ui/gfx/image/image_family.h" | 26 #include "ui/gfx/image/image_family.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 131 } |
131 | 132 |
132 // Creates application shortcuts in a given set of paths. | 133 // Creates application shortcuts in a given set of paths. |
133 // |shortcut_paths| is a list of directories in which shortcuts should be | 134 // |shortcut_paths| is a list of directories in which shortcuts should be |
134 // created. | 135 // created. |
135 // Returns true on success, false on failure. | 136 // Returns true on success, false on failure. |
136 // Must be called on the FILE thread. | 137 // Must be called on the FILE thread. |
137 bool CreateShortcutsInPaths( | 138 bool CreateShortcutsInPaths( |
138 const base::FilePath& web_app_path, | 139 const base::FilePath& web_app_path, |
139 const ShellIntegration::ShortcutInfo& shortcut_info, | 140 const ShellIntegration::ShortcutInfo& shortcut_info, |
140 const std::vector<base::FilePath>& shortcut_paths) { | 141 const std::vector<base::FilePath>& shortcut_paths, |
| 142 std::vector<base::FilePath>* out_filenames) { |
141 // Ensure web_app_path exists. | 143 // Ensure web_app_path exists. |
142 if (!file_util::PathExists(web_app_path) && | 144 if (!file_util::PathExists(web_app_path) && |
143 !file_util::CreateDirectory(web_app_path)) { | 145 !file_util::CreateDirectory(web_app_path)) { |
144 return false; | 146 return false; |
145 } | 147 } |
146 | 148 |
147 // Generates file name to use with persisted ico and shortcut file. | 149 // Generates file name to use with persisted ico and shortcut file. |
148 base::FilePath file_name = | 150 base::FilePath file_name = |
149 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 151 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
150 | 152 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 shortcut_properties.set_app_id(app_id); | 210 shortcut_properties.set_app_id(app_id); |
209 shortcut_properties.set_dual_mode(false); | 211 shortcut_properties.set_dual_mode(false); |
210 if (!file_util::PathExists(shortcut_file.DirName()) && | 212 if (!file_util::PathExists(shortcut_file.DirName()) && |
211 !file_util::CreateDirectory(shortcut_file.DirName())) { | 213 !file_util::CreateDirectory(shortcut_file.DirName())) { |
212 NOTREACHED(); | 214 NOTREACHED(); |
213 return false; | 215 return false; |
214 } | 216 } |
215 success = base::win::CreateOrUpdateShortcutLink( | 217 success = base::win::CreateOrUpdateShortcutLink( |
216 shortcut_file, shortcut_properties, | 218 shortcut_file, shortcut_properties, |
217 base::win::SHORTCUT_CREATE_ALWAYS) && success; | 219 base::win::SHORTCUT_CREATE_ALWAYS) && success; |
| 220 if (out_filenames) |
| 221 out_filenames->push_back(shortcut_file); |
218 } | 222 } |
219 | 223 |
220 return success; | 224 return success; |
221 } | 225 } |
222 | 226 |
223 // Gets the directories with shortcuts for an app, and deletes the shortcuts. | 227 // Gets the directories with shortcuts for an app, and deletes the shortcuts. |
224 // This will search the standard locations for shortcuts named |title| that open | 228 // This will search the standard locations for shortcuts named |title| that open |
225 // in the profile with |profile_path|. | 229 // in the profile with |profile_path|. |
226 // |was_pinned_to_taskbar| will be set to true if there was previously a | 230 // |was_pinned_to_taskbar| will be set to true if there was previously a |
227 // shortcut pinned to the taskbar for this app; false otherwise. | 231 // shortcut pinned to the taskbar for this app; false otherwise. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 283 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
280 file_util::Delete(*j, false); | 284 file_util::Delete(*j, false); |
281 } | 285 } |
282 } | 286 } |
283 } | 287 } |
284 | 288 |
285 } // namespace | 289 } // namespace |
286 | 290 |
287 namespace web_app { | 291 namespace web_app { |
288 | 292 |
| 293 base::FilePath CreateShortcutInWebAppDir( |
| 294 const base::FilePath& web_app_dir, |
| 295 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 296 std::vector<base::FilePath> paths; |
| 297 paths.push_back(web_app_dir); |
| 298 std::vector<base::FilePath> out_filenames; |
| 299 CreateShortcutsInPaths(web_app_dir, shortcut_info, paths, &out_filenames); |
| 300 DCHECK_EQ(out_filenames.size(), 1u); |
| 301 return out_filenames[0]; |
| 302 } |
| 303 |
289 namespace internals { | 304 namespace internals { |
290 | 305 |
291 // Saves |image| to |icon_file| if the file is outdated and refresh shell's | 306 // Saves |image| to |icon_file| if the file is outdated and refresh shell's |
292 // icon cache to ensure correct icon is displayed. Returns true if icon_file | 307 // icon cache to ensure correct icon is displayed. Returns true if icon_file |
293 // is up to date or successfully updated. | 308 // is up to date or successfully updated. |
294 bool CheckAndSaveIcon(const base::FilePath& icon_file, | 309 bool CheckAndSaveIcon(const base::FilePath& icon_file, |
295 const gfx::ImageFamily& image) { | 310 const gfx::ImageFamily& image) { |
296 if (ShouldUpdateIcon(icon_file, image)) { | 311 if (ShouldUpdateIcon(icon_file, image)) { |
297 if (SaveIconWithCheckSum(icon_file, image)) { | 312 if (SaveIconWithCheckSum(icon_file, image)) { |
298 // Refresh shell's icon cache. This call is quite disruptive as user would | 313 // Refresh shell's icon cache. This call is quite disruptive as user would |
(...skipping 25 matching lines...) Expand all Loading... |
324 // Create/update the shortcut in the web app path for the "Pin To Taskbar" | 339 // Create/update the shortcut in the web app path for the "Pin To Taskbar" |
325 // option in Win7. We use the web app path shortcut because we will overwrite | 340 // option in Win7. We use the web app path shortcut because we will overwrite |
326 // it rather than appending unique numbers if the shortcut already exists. | 341 // it rather than appending unique numbers if the shortcut already exists. |
327 // This prevents pinned apps from having unique numbers in their names. | 342 // This prevents pinned apps from having unique numbers in their names. |
328 if (pin_to_taskbar) | 343 if (pin_to_taskbar) |
329 shortcut_paths.push_back(web_app_path); | 344 shortcut_paths.push_back(web_app_path); |
330 | 345 |
331 if (shortcut_paths.empty()) | 346 if (shortcut_paths.empty()) |
332 return false; | 347 return false; |
333 | 348 |
334 if (!CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths)) | 349 if (!CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths, |
| 350 NULL)) |
335 return false; | 351 return false; |
336 | 352 |
337 if (pin_to_taskbar) { | 353 if (pin_to_taskbar) { |
338 base::FilePath file_name = | 354 base::FilePath file_name = |
339 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 355 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
340 // Use the web app path shortcut for pinning to avoid having unique numbers | 356 // Use the web app path shortcut for pinning to avoid having unique numbers |
341 // in the application name. | 357 // in the application name. |
342 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). | 358 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). |
343 AddExtension(installer::kLnkExt); | 359 AddExtension(installer::kLnkExt); |
344 if (!base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str())) | 360 if (!base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str())) |
(...skipping 15 matching lines...) Expand all Loading... |
360 | 376 |
361 if (old_app_title != shortcut_info.title) { | 377 if (old_app_title != shortcut_info.title) { |
362 // The app's title has changed. Delete all existing app shortcuts and | 378 // The app's title has changed. Delete all existing app shortcuts and |
363 // recreate them in any locations they already existed (but do not add them | 379 // recreate them in any locations they already existed (but do not add them |
364 // to locations where they do not currently exist). | 380 // to locations where they do not currently exist). |
365 bool was_pinned_to_taskbar; | 381 bool was_pinned_to_taskbar; |
366 std::vector<base::FilePath> shortcut_paths; | 382 std::vector<base::FilePath> shortcut_paths; |
367 GetShortcutLocationsAndDeleteShortcuts( | 383 GetShortcutLocationsAndDeleteShortcuts( |
368 web_app_path, shortcut_info.profile_path, old_app_title, | 384 web_app_path, shortcut_info.profile_path, old_app_title, |
369 &was_pinned_to_taskbar, &shortcut_paths); | 385 &was_pinned_to_taskbar, &shortcut_paths); |
370 CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths); | 386 CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths, NULL); |
371 // If the shortcut was pinned to the taskbar, | 387 // If the shortcut was pinned to the taskbar, |
372 // GetShortcutLocationsAndDeleteShortcuts will have deleted it. In that | 388 // GetShortcutLocationsAndDeleteShortcuts will have deleted it. In that |
373 // case, re-pin it. | 389 // case, re-pin it. |
374 if (was_pinned_to_taskbar) { | 390 if (was_pinned_to_taskbar) { |
375 base::FilePath file_name = | 391 base::FilePath file_name = |
376 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 392 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
377 // Use the web app path shortcut for pinning to avoid having unique | 393 // Use the web app path shortcut for pinning to avoid having unique |
378 // numbers in the application name. | 394 // numbers in the application name. |
379 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). | 395 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). |
380 AddExtension(installer::kLnkExt); | 396 AddExtension(installer::kLnkExt); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 path = path.Append(locations[i].subdir); | 469 path = path.Append(locations[i].subdir); |
454 shortcut_paths.push_back(path); | 470 shortcut_paths.push_back(path); |
455 } | 471 } |
456 } | 472 } |
457 return shortcut_paths; | 473 return shortcut_paths; |
458 } | 474 } |
459 | 475 |
460 } // namespace internals | 476 } // namespace internals |
461 | 477 |
462 } // namespace web_app | 478 } // namespace web_app |
OLD | NEW |