Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | 18 #include "ui/display/display.h" |
|
dominickn
2016/12/19 06:23:32
Nit: remove display.h and screen.h includes.
| |
| 19 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
| 20 | 20 |
| 21 // DevToolsConsoleHelper is a class that holds a WebContents in order to be able | 21 // 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 | 22 // to send a message to the WebContents' main frame. It is used so |
| 23 // ManifestIconDownloader and the callers do not have to worry about | 23 // ManifestIconDownloader and the callers do not have to worry about |
| 24 // |web_contents| lifetime. If the |web_contents| is invalidated before the | 24 // |web_contents| lifetime. If the |web_contents| is invalidated before the |
| 25 // message can be sent, the message will simply be ignored. | 25 // message can be sent, the message will simply be ignored. |
| 26 class ManifestIconDownloader::DevToolsConsoleHelper | 26 class ManifestIconDownloader::DevToolsConsoleHelper |
| 27 : public content::WebContentsObserver { | 27 : public content::WebContentsObserver { |
| 28 public: | 28 public: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 42 content::ConsoleMessageLevel level, | 42 content::ConsoleMessageLevel level, |
| 43 const std::string& message) { | 43 const std::string& message) { |
| 44 if (!web_contents()) | 44 if (!web_contents()) |
| 45 return; | 45 return; |
| 46 web_contents()->GetMainFrame()->AddMessageToConsole(level, message); | 46 web_contents()->GetMainFrame()->AddMessageToConsole(level, message); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool ManifestIconDownloader::Download( | 49 bool ManifestIconDownloader::Download( |
| 50 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
| 51 const GURL& icon_url, | 51 const GURL& icon_url, |
| 52 int ideal_icon_size_in_dp, | 52 int ideal_icon_size_in_px, |
| 53 int minimum_icon_size_in_dp, | 53 int minimum_icon_size_in_px, |
| 54 const ManifestIconDownloader::IconFetchCallback& callback) { | 54 const ManifestIconDownloader::IconFetchCallback& callback) { |
| 55 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); | 55 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); |
| 56 if (!web_contents || !icon_url.is_valid()) | 56 if (!web_contents || !icon_url.is_valid()) |
| 57 return false; | 57 return false; |
| 58 | 58 |
| 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( | 59 web_contents->DownloadImage( |
| 67 icon_url, | 60 icon_url, |
| 68 false, // is_favicon | 61 false, // is_favicon |
| 69 0, // max_bitmap_size - 0 means no maximum size. | 62 0, // max_bitmap_size - 0 means no maximum size. |
| 70 false, // bypass_cache | 63 false, // bypass_cache |
| 71 base::Bind(&ManifestIconDownloader::OnIconFetched, | 64 base::Bind(&ManifestIconDownloader::OnIconFetched, |
| 72 ideal_icon_size_in_px, | 65 ideal_icon_size_in_px, |
| 73 minimum_icon_size_in_px, | 66 minimum_icon_size_in_px, |
| 74 base::Owned(new DevToolsConsoleHelper(web_contents)), | 67 base::Owned(new DevToolsConsoleHelper(web_contents)), |
| 75 callback)); | 68 callback)); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 float ratio = height / width; | 187 float ratio = height / width; |
| 195 float ratio_difference = fabs(ratio - 1); | 188 float ratio_difference = fabs(ratio - 1); |
| 196 if (ratio_difference < best_ratio_difference) { | 189 if (ratio_difference < best_ratio_difference) { |
| 197 best_index = i; | 190 best_index = i; |
| 198 best_ratio_difference = ratio_difference; | 191 best_ratio_difference = ratio_difference; |
| 199 } | 192 } |
| 200 } | 193 } |
| 201 | 194 |
| 202 return best_index; | 195 return best_index; |
| 203 } | 196 } |
| OLD | NEW |