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

Side by Side Diff: chrome/browser/manifest/manifest_icon_downloader.cc

Issue 2589503002: Use exact pixel sizes instead of dip in webapp/WebAPK installability code (Closed)
Patch Set: Merge branch 'master' into dp_px Created 4 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/manifest/manifest_icon_downloader.h" 5 #include "chrome/browser/manifest/manifest_icon_downloader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
11 #include "chrome/browser/manifest/manifest_icon_selector.h" 11 #include "chrome/browser/manifest/manifest_icon_selector.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/console_message_level.h" 16 #include "content/public/common/console_message_level.h"
17 #include "skia/ext/image_operations.h" 17 #include "skia/ext/image_operations.h"
18 #include "ui/display/display.h"
19 #include "ui/display/screen.h"
20 18
21 // DevToolsConsoleHelper is a class that holds a WebContents in order to be able 19 // DevToolsConsoleHelper is a class that holds a WebContents in order to be able
22 // to send a message to the WebContents' main frame. It is used so 20 // to send a message to the WebContents' main frame. It is used so
23 // ManifestIconDownloader and the callers do not have to worry about 21 // ManifestIconDownloader and the callers do not have to worry about
24 // |web_contents| lifetime. If the |web_contents| is invalidated before the 22 // |web_contents| lifetime. If the |web_contents| is invalidated before the
25 // message can be sent, the message will simply be ignored. 23 // message can be sent, the message will simply be ignored.
26 class ManifestIconDownloader::DevToolsConsoleHelper 24 class ManifestIconDownloader::DevToolsConsoleHelper
27 : public content::WebContentsObserver { 25 : public content::WebContentsObserver {
28 public: 26 public:
29 explicit DevToolsConsoleHelper(content::WebContents* web_contents); 27 explicit DevToolsConsoleHelper(content::WebContents* web_contents);
(...skipping 12 matching lines...) Expand all
42 content::ConsoleMessageLevel level, 40 content::ConsoleMessageLevel level,
43 const std::string& message) { 41 const std::string& message) {
44 if (!web_contents()) 42 if (!web_contents())
45 return; 43 return;
46 web_contents()->GetMainFrame()->AddMessageToConsole(level, message); 44 web_contents()->GetMainFrame()->AddMessageToConsole(level, message);
47 } 45 }
48 46
49 bool ManifestIconDownloader::Download( 47 bool ManifestIconDownloader::Download(
50 content::WebContents* web_contents, 48 content::WebContents* web_contents,
51 const GURL& icon_url, 49 const GURL& icon_url,
52 int ideal_icon_size_in_dp, 50 int ideal_icon_size_in_px,
53 int minimum_icon_size_in_dp, 51 int minimum_icon_size_in_px,
54 const ManifestIconDownloader::IconFetchCallback& callback) { 52 const ManifestIconDownloader::IconFetchCallback& callback) {
55 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); 53 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px);
56 if (!web_contents || !icon_url.is_valid()) 54 if (!web_contents || !icon_url.is_valid())
57 return false; 55 return false;
58 56
59 const float device_scale_factor =
60 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
61 const int ideal_icon_size_in_px =
62 static_cast<int>(round(ideal_icon_size_in_dp * device_scale_factor));
63 const int minimum_icon_size_in_px =
64 static_cast<int>(round(minimum_icon_size_in_dp * device_scale_factor));
65
66 web_contents->DownloadImage( 57 web_contents->DownloadImage(
67 icon_url, 58 icon_url,
68 false, // is_favicon 59 false, // is_favicon
69 0, // max_bitmap_size - 0 means no maximum size. 60 0, // max_bitmap_size - 0 means no maximum size.
70 false, // bypass_cache 61 false, // bypass_cache
71 base::Bind(&ManifestIconDownloader::OnIconFetched, 62 base::Bind(&ManifestIconDownloader::OnIconFetched,
72 ideal_icon_size_in_px, 63 ideal_icon_size_in_px,
73 minimum_icon_size_in_px, 64 minimum_icon_size_in_px,
74 base::Owned(new DevToolsConsoleHelper(web_contents)), 65 base::Owned(new DevToolsConsoleHelper(web_contents)),
75 callback)); 66 callback));
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 float ratio = height / width; 185 float ratio = height / width;
195 float ratio_difference = fabs(ratio - 1); 186 float ratio_difference = fabs(ratio - 1);
196 if (ratio_difference < best_ratio_difference) { 187 if (ratio_difference < best_ratio_difference) {
197 best_index = i; 188 best_index = i;
198 best_ratio_difference = ratio_difference; 189 best_ratio_difference = ratio_difference;
199 } 190 }
200 } 191 }
201 192
202 return best_index; 193 return best_index;
203 } 194 }
OLDNEW
« no previous file with comments | « chrome/browser/manifest/manifest_icon_downloader.h ('k') | chrome/browser/manifest/manifest_icon_selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698