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

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: Write all bitmaps needed to the disk. 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
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::Image& image,
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.IsEmpty()) {
93 const gfx::ImageSkia* imageskia = image.ToImageSkia();
sky 2017/02/08 03:14:54 image_skia.
chengx 2017/02/08 07:42:26 Done.
94 DCHECK(imageskia);
95 std::vector<float> supportedScales = imageskia->GetSupportedScales();
sky 2017/02/08 03:14:54 supported_scales (or use directly in for statement
chengx 2017/02/08 07:42:26 Done.
96 for (auto& scale : supportedScales) {
97 gfx::ImageSkiaRep imageSkiaRep = imageskia->GetRepresentation(scale);
sky 2017/02/08 03:14:54 image_skia_rep.
chengx 2017/02/08 07:42:26 Done.
98 if (!imageSkiaRep.is_null())
99 image_family.Add(
100 gfx::Image::CreateFrom1xBitmap(imageSkiaRep.sk_bitmap()));
101 }
102 }
103
90 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path, 104 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path,
91 IconUtil::NORMAL_WRITE)) 105 IconUtil::NORMAL_WRITE))
92 return false; 106 return false;
93 107
94 // Add this icon file to the list and return its absolute path. 108 // Add this icon file to the list and return its absolute path.
95 // The IShellLink::SetIcon() function needs the absolute path to an icon. 109 // The IShellLink::SetIcon() function needs the absolute path to an icon.
96 *icon_path = path; 110 *icon_path = path;
97 return true; 111 return true;
98 } 112 }
99 113
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 548
535 // If there is currently a favicon request in progress, it is now outdated, 549 // 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. 550 // as we have received another, so nullify the handle from the old request.
537 task_id_ = base::CancelableTaskTracker::kBadTaskId; 551 task_id_ = base::CancelableTaskTracker::kBadTaskId;
538 // Lock the list to set icon data and pop the url. 552 // Lock the list to set icon data and pop the url.
539 { 553 {
540 JumpListData* data = &jumplist_data_->data; 554 JumpListData* data = &jumplist_data_->data;
541 base::AutoLock auto_lock(data->list_lock_); 555 base::AutoLock auto_lock(data->list_lock_);
542 // Attach the received data to the ShellLinkItem object. 556 // Attach the received data to the ShellLinkItem object.
543 // This data will be decoded by the RunUpdateOnFileThread method. 557 // This data will be decoded by the RunUpdateOnFileThread method.
544 if (!image_result.image.IsEmpty()) { 558 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() &&
545 if (!data->icon_urls_.empty() && data->icon_urls_.front().second.get()) 559 data->icon_urls_.front().second.get()) {
546 data->icon_urls_.front().second->set_icon_data( 560 data->icon_urls_.front().second->set_icon_data(image_result.image);
sky 2017/02/08 03:14:54 I'm worried about using the image from multiple th
chengx 2017/02/08 07:42:26 Agreed. I switched to ImageSkia.
547 image_result.image.AsBitmap());
548 } 561 }
549 562
550 if (!data->icon_urls_.empty()) 563 if (!data->icon_urls_.empty())
551 data->icon_urls_.pop_front(); 564 data->icon_urls_.pop_front();
552 } 565 }
553 // Check whether we need to load more favicons. 566 // Check whether we need to load more favicons.
554 StartLoadingFavicon(); 567 StartLoadingFavicon();
555 } 568 }
556 569
557 void JumpList::OnIncognitoAvailabilityChanged() { 570 void JumpList::OnIncognitoAvailabilityChanged() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { 621 void JumpList::TopSitesLoaded(history::TopSites* top_sites) {
609 } 622 }
610 623
611 void JumpList::TopSitesChanged(history::TopSites* top_sites, 624 void JumpList::TopSitesChanged(history::TopSites* top_sites,
612 ChangeReason change_reason) { 625 ChangeReason change_reason) {
613 top_sites->GetMostVisitedURLs( 626 top_sites->GetMostVisitedURLs(
614 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 627 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
615 weak_ptr_factory_.GetWeakPtr()), 628 weak_ptr_factory_.GetWeakPtr()),
616 false); 629 false);
617 } 630 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/win/jumplist_updater.h » ('j') | chrome/browser/win/jumplist_updater.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698