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

Side by Side Diff: chrome/browser/win/jumplist.cc

Issue 2665623002: Fix Jumplist favicons to have high resolution in HDPI Windows displays (Closed)
Patch Set: Better function names and parameters. Created 3 years, 10 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 | chrome/browser/win/jumplist_updater.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/win/jumplist.h" 5 #include "chrome/browser/win/jumplist.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 26 matching lines...) Expand all
37 #include "components/sessions/core/session_types.h" 37 #include "components/sessions/core/session_types.h"
38 #include "components/sessions/core/tab_restore_service.h" 38 #include "components/sessions/core/tab_restore_service.h"
39 #include "components/strings/grit/components_strings.h" 39 #include "components/strings/grit/components_strings.h"
40 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/notification_registrar.h" 41 #include "content/public/browser/notification_registrar.h"
42 #include "content/public/browser/notification_source.h" 42 #include "content/public/browser/notification_source.h"
43 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/gfx/codec/png_codec.h" 44 #include "ui/gfx/codec/png_codec.h"
45 #include "ui/gfx/favicon_size.h" 45 #include "ui/gfx/favicon_size.h"
46 #include "ui/gfx/icon_util.h" 46 #include "ui/gfx/icon_util.h"
47 #include "ui/gfx/image/image.h"
47 #include "ui/gfx/image/image_family.h" 48 #include "ui/gfx/image/image_family.h"
49 #include "ui/gfx/image/image_skia.h"
50 #include "ui/gfx/image/image_skia_rep.h"
48 #include "url/gurl.h" 51 #include "url/gurl.h"
49 52
50 using content::BrowserThread; 53 using content::BrowserThread;
51 using JumpListData = JumpList::JumpListData; 54 using JumpListData = JumpList::JumpListData;
52 55
53 namespace { 56 namespace {
54 57
55 // Delay jumplist updates to allow collapsing of redundant update requests. 58 // Delay jumplist updates to allow collapsing of redundant update requests.
56 const int kDelayForJumplistUpdateInMS = 3500; 59 const int kDelayForJumplistUpdateInMS = 3500;
57 60
58 // Append the common switches to each shell link. 61 // Append the common switches to each shell link.
59 void AppendCommonSwitches(ShellLinkItem* shell_link) { 62 void AppendCommonSwitches(ShellLinkItem* shell_link) {
60 const char* kSwitchNames[] = { switches::kUserDataDir }; 63 const char* kSwitchNames[] = { switches::kUserDataDir };
61 const base::CommandLine& command_line = 64 const base::CommandLine& command_line =
62 *base::CommandLine::ForCurrentProcess(); 65 *base::CommandLine::ForCurrentProcess();
63 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, 66 shell_link->GetCommandLine()->CopySwitchesFrom(command_line,
64 kSwitchNames, 67 kSwitchNames,
65 arraysize(kSwitchNames)); 68 arraysize(kSwitchNames));
66 } 69 }
67 70
68 // Create a ShellLinkItem preloaded with common switches. 71 // Create a ShellLinkItem preloaded with common switches.
69 scoped_refptr<ShellLinkItem> CreateShellLink() { 72 scoped_refptr<ShellLinkItem> CreateShellLink() {
70 scoped_refptr<ShellLinkItem> link(new ShellLinkItem); 73 scoped_refptr<ShellLinkItem> link(new ShellLinkItem);
71 AppendCommonSwitches(link.get()); 74 AppendCommonSwitches(link.get());
72 return link; 75 return link;
73 } 76 }
74 77
75 // Creates a temporary icon file to be shown in JumpList. 78 // Creates a temporary icon file to be shown in JumpList.
76 bool CreateIconFile(const SkBitmap& bitmap, 79 bool CreateIconFile(const gfx::ImageSkia& image_skia,
77 const base::FilePath& icon_dir, 80 const base::FilePath& icon_dir,
78 base::FilePath* icon_path) { 81 base::FilePath* icon_path) {
79 // Retrieve the path to a temporary file. 82 // Retrieve the path to a temporary file.
80 // We don't have to care about the extension of this temporary file because 83 // We don't have to care about the extension of this temporary file because
81 // JumpList does not care about it. 84 // JumpList does not care about it.
82 base::FilePath path; 85 base::FilePath path;
83 if (!base::CreateTemporaryFileInDir(icon_dir, &path)) 86 if (!base::CreateTemporaryFileInDir(icon_dir, &path))
84 return false; 87 return false;
85 88
86 // Create an icon file from the favicon attached to the given |page|, and 89 // Create an icon file from the favicon attached to the given |page|, and
87 // save it as the temporary file. 90 // save it as the temporary file.
88 gfx::ImageFamily image_family; 91 gfx::ImageFamily image_family;
89 image_family.Add(gfx::Image::CreateFrom1xBitmap(bitmap)); 92 if (!image_skia.isNull()) {
93 std::vector<float> supported_scales = image_skia.GetSupportedScales();
94 for (auto& scale : supported_scales) {
95 gfx::ImageSkiaRep image_skia_rep = image_skia.GetRepresentation(scale);
96 if (!image_skia_rep.is_null())
97 image_family.Add(
98 gfx::Image::CreateFrom1xBitmap(image_skia_rep.sk_bitmap()));
99 }
100 }
101
90 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path, 102 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path,
91 IconUtil::NORMAL_WRITE)) 103 IconUtil::NORMAL_WRITE))
92 return false; 104 return false;
93 105
94 // Add this icon file to the list and return its absolute path. 106 // Add this icon file to the list and return its absolute path.
95 // The IShellLink::SetIcon() function needs the absolute path to an icon. 107 // The IShellLink::SetIcon() function needs the absolute path to an icon.
96 *icon_path = path; 108 *icon_path = path;
97 return true; 109 return true;
98 } 110 }
99 111
100 // Helper method for RunUpdate to create icon files for the asynchrounously 112 // Helper method for RunUpdate to create icon files for the asynchrounously
101 // loaded icons. 113 // loaded icons.
102 void CreateIconFiles(const base::FilePath& icon_dir, 114 void CreateIconFiles(const base::FilePath& icon_dir,
103 const ShellLinkItemList& item_list) { 115 const ShellLinkItemList& item_list) {
104 for (ShellLinkItemList::const_iterator item = item_list.begin(); 116 for (ShellLinkItemList::const_iterator item = item_list.begin();
105 item != item_list.end(); ++item) { 117 item != item_list.end(); ++item) {
106 base::FilePath icon_path; 118 base::FilePath icon_path;
107 if (CreateIconFile((*item)->icon_data(), icon_dir, &icon_path)) 119 if (CreateIconFile((*item)->icon_image(), icon_dir, &icon_path))
108 (*item)->set_icon(icon_path.value(), 0); 120 (*item)->set_icon(icon_path.value(), 0);
109 } 121 }
110 } 122 }
111 123
112 // Updates the "Tasks" category of the JumpList. 124 // Updates the "Tasks" category of the JumpList.
113 bool UpdateTaskCategory( 125 bool UpdateTaskCategory(
114 JumpListUpdater* jumplist_updater, 126 JumpListUpdater* jumplist_updater,
115 IncognitoModePrefs::Availability incognito_availability) { 127 IncognitoModePrefs::Availability incognito_availability) {
116 base::FilePath chrome_path; 128 base::FilePath chrome_path;
117 if (!PathService::Get(base::FILE_EXE, &chrome_path)) 129 if (!PathService::Get(base::FILE_EXE, &chrome_path))
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 546
535 // If there is currently a favicon request in progress, it is now outdated, 547 // If there is currently a favicon request in progress, it is now outdated,
536 // as we have received another, so nullify the handle from the old request. 548 // as we have received another, so nullify the handle from the old request.
537 task_id_ = base::CancelableTaskTracker::kBadTaskId; 549 task_id_ = base::CancelableTaskTracker::kBadTaskId;
538 // Lock the list to set icon data and pop the url. 550 // Lock the list to set icon data and pop the url.
539 { 551 {
540 JumpListData* data = &jumplist_data_->data; 552 JumpListData* data = &jumplist_data_->data;
541 base::AutoLock auto_lock(data->list_lock_); 553 base::AutoLock auto_lock(data->list_lock_);
542 // Attach the received data to the ShellLinkItem object. 554 // Attach the received data to the ShellLinkItem object.
543 // This data will be decoded by the RunUpdateOnFileThread method. 555 // This data will be decoded by the RunUpdateOnFileThread method.
544 if (!image_result.image.IsEmpty()) { 556 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() &&
545 if (!data->icon_urls_.empty() && data->icon_urls_.front().second.get()) 557 data->icon_urls_.front().second.get()) {
546 data->icon_urls_.front().second->set_icon_data( 558 gfx::ImageSkia image_skia = image_result.image.AsImageSkia();
547 image_result.image.AsBitmap()); 559 image_skia.EnsureRepsForSupportedScales();
560 std::unique_ptr<gfx::ImageSkia> deep_copy(image_skia.DeepCopy());
561 data->icon_urls_.front().second->set_icon_image(*deep_copy);
548 } 562 }
549 563
550 if (!data->icon_urls_.empty()) 564 if (!data->icon_urls_.empty())
551 data->icon_urls_.pop_front(); 565 data->icon_urls_.pop_front();
552 } 566 }
553 // Check whether we need to load more favicons. 567 // Check whether we need to load more favicons.
554 StartLoadingFavicon(); 568 StartLoadingFavicon();
555 } 569 }
556 570
557 void JumpList::OnIncognitoAvailabilityChanged() { 571 void JumpList::OnIncognitoAvailabilityChanged() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { 622 void JumpList::TopSitesLoaded(history::TopSites* top_sites) {
609 } 623 }
610 624
611 void JumpList::TopSitesChanged(history::TopSites* top_sites, 625 void JumpList::TopSitesChanged(history::TopSites* top_sites,
612 ChangeReason change_reason) { 626 ChangeReason change_reason) {
613 top_sites->GetMostVisitedURLs( 627 top_sites->GetMostVisitedURLs(
614 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 628 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
615 weak_ptr_factory_.GetWeakPtr()), 629 weak_ptr_factory_.GetWeakPtr()),
616 false); 630 false);
617 } 631 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/win/jumplist_updater.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698