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

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

Issue 298003005: Revert of Support "Pin to taskbar" for hosted app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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/web_applications/web_app_win.h ('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_win.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/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/md5.h" 13 #include "base/md5.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/win/shortcut.h" 18 #include "base/win/shortcut.h"
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "chrome/browser/web_applications/update_shortcut_worker_win.h" 20 #include "chrome/browser/web_applications/update_shortcut_worker_win.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/installer/util/browser_distribution.h" 22 #include "chrome/installer/util/browser_distribution.h"
23 #include "chrome/installer/util/shell_util.h" 23 #include "chrome/installer/util/shell_util.h"
24 #include "chrome/installer/util/util_constants.h" 24 #include "chrome/installer/util/util_constants.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "ui/base/win/shell.h"
27 #include "ui/gfx/icon_util.h" 26 #include "ui/gfx/icon_util.h"
28 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/image/image_family.h" 28 #include "ui/gfx/image/image_family.h"
30 29
31 namespace { 30 namespace {
32 31
33 const base::FilePath::CharType kIconChecksumFileExt[] = 32 const base::FilePath::CharType kIconChecksumFileExt[] =
34 FILE_PATH_LITERAL(".ico.md5"); 33 FILE_PATH_LITERAL(".ico.md5");
35 34
36 // Calculates checksum of an icon family using MD5. 35 // Calculates checksum of an icon family using MD5.
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); 316 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin();
318 j != shortcut_files.end(); ++j) { 317 j != shortcut_files.end(); ++j) {
319 // Any shortcut could have been pinned, either by chrome or the user, so 318 // Any shortcut could have been pinned, either by chrome or the user, so
320 // they are all unpinned. 319 // they are all unpinned.
321 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); 320 base::win::TaskbarUnpinShortcutLink(j->value().c_str());
322 base::DeleteFile(*j, false); 321 base::DeleteFile(*j, false);
323 } 322 }
324 } 323 }
325 } 324 }
326 325
327 void CreateIconAndSetRelaunchDetails(const base::FilePath& web_app_path,
328 const base::FilePath& icon_file,
329 const web_app::ShortcutInfo& shortcut_info,
330 HWND hwnd) {
331 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
332
333 CommandLine command_line =
334 ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url,
335 shortcut_info.extension_id,
336 shortcut_info.profile_path);
337
338 base::FilePath chrome_exe;
339 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
340 NOTREACHED();
341 return;
342 }
343 command_line.SetProgram(chrome_exe);
344 ui::win::SetRelaunchDetailsForWindow(
345 command_line.GetCommandLineString(), shortcut_info.title, hwnd);
346
347 if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path))
348 return;
349
350 ui::win::SetAppIconForWindow(icon_file.value(), hwnd);
351 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon);
352 }
353
354 void OnShortcutInfoLoadedForSetRelaunchDetails(
355 HWND hwnd,
356 const web_app::ShortcutInfo& shortcut_info) {
357 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
358
359 // Set window's icon to the one we're about to create/update in the web app
360 // path. The icon cache will refresh on icon creation.
361 base::FilePath web_app_path =
362 web_app::GetWebAppDataDirectory(shortcut_info.profile_path,
363 shortcut_info.extension_id,
364 shortcut_info.url);
365 base::FilePath icon_file =
366 web_app_path.Append(web_app::internals::GetSanitizedFileName(
367 shortcut_info.title))
368 .ReplaceExtension(FILE_PATH_LITERAL(".ico"));
369
370 content::BrowserThread::PostBlockingPoolTask(
371 FROM_HERE,
372 base::Bind(&CreateIconAndSetRelaunchDetails,
373 web_app_path,
374 icon_file,
375 shortcut_info,
376 hwnd));
377 }
378
379 } // namespace 326 } // namespace
380 327
381 namespace web_app { 328 namespace web_app {
382 329
383 base::FilePath CreateShortcutInWebAppDir(const base::FilePath& web_app_dir, 330 base::FilePath CreateShortcutInWebAppDir(const base::FilePath& web_app_dir,
384 const ShortcutInfo& shortcut_info) { 331 const ShortcutInfo& shortcut_info) {
385 std::vector<base::FilePath> paths; 332 std::vector<base::FilePath> paths;
386 paths.push_back(web_app_dir); 333 paths.push_back(web_app_dir);
387 std::vector<base::FilePath> out_filenames; 334 std::vector<base::FilePath> out_filenames;
388 base::FilePath web_app_dir_shortcut = 335 base::FilePath web_app_dir_shortcut =
389 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title)) 336 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title))
390 .AddExtension(installer::kLnkExt); 337 .AddExtension(installer::kLnkExt);
391 if (!PathExists(web_app_dir_shortcut)) { 338 if (!PathExists(web_app_dir_shortcut)) {
392 CreateShortcutsInPaths(web_app_dir, 339 CreateShortcutsInPaths(web_app_dir,
393 shortcut_info, 340 shortcut_info,
394 paths, 341 paths,
395 SHORTCUT_CREATION_BY_USER, 342 SHORTCUT_CREATION_BY_USER,
396 &out_filenames); 343 &out_filenames);
397 DCHECK_EQ(out_filenames.size(), 1u); 344 DCHECK_EQ(out_filenames.size(), 1u);
398 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); 345 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value());
399 } else { 346 } else {
400 internals::CheckAndSaveIcon( 347 internals::CheckAndSaveIcon(
401 internals::GetIconFilePath(web_app_dir, shortcut_info.title), 348 internals::GetIconFilePath(web_app_dir, shortcut_info.title),
402 shortcut_info.favicon); 349 shortcut_info.favicon);
403 } 350 }
404 return web_app_dir_shortcut; 351 return web_app_dir_shortcut;
405 } 352 }
406 353
407 void UpdateRelaunchDetailsForApp(Profile* profile,
408 const extensions::Extension* extension,
409 HWND hwnd) {
410 web_app::UpdateShortcutInfoAndIconForApp(
411 extension,
412 profile,
413 base::Bind(&OnShortcutInfoLoadedForSetRelaunchDetails, hwnd));
414 }
415
416 namespace internals { 354 namespace internals {
417 355
418 // Saves |image| to |icon_file| if the file is outdated and refresh shell's 356 // Saves |image| to |icon_file| if the file is outdated and refresh shell's
419 // icon cache to ensure correct icon is displayed. Returns true if icon_file 357 // icon cache to ensure correct icon is displayed. Returns true if icon_file
420 // is up to date or successfully updated. 358 // is up to date or successfully updated.
421 bool CheckAndSaveIcon(const base::FilePath& icon_file, 359 bool CheckAndSaveIcon(const base::FilePath& icon_file,
422 const gfx::ImageFamily& image) { 360 const gfx::ImageFamily& image) {
423 if (ShouldUpdateIcon(icon_file, image)) { 361 if (ShouldUpdateIcon(icon_file, image)) {
424 if (SaveIconWithCheckSum(icon_file, image)) { 362 if (SaveIconWithCheckSum(icon_file, image)) {
425 // Refresh shell's icon cache. This call is quite disruptive as user would 363 // Refresh shell's icon cache. This call is quite disruptive as user would
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 548
611 } // namespace internals 549 } // namespace internals
612 550
613 void UpdateShortcutForTabContents(content::WebContents* web_contents) { 551 void UpdateShortcutForTabContents(content::WebContents* web_contents) {
614 // UpdateShortcutWorker will delete itself when it's done. 552 // UpdateShortcutWorker will delete itself when it's done.
615 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); 553 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents);
616 worker->Run(); 554 worker->Run();
617 } 555 }
618 556
619 } // namespace web_app 557 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698