| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "chrome/browser/manifest/manifest_icon_selector.h" | 9 #include "chrome/browser/manifest/manifest_icon_selector.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
| 13 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
| 14 | 14 |
| 15 bool ManifestIconDownloader::Download( | 15 bool ManifestIconDownloader::Download( |
| 16 content::WebContents* web_contents, | 16 content::WebContents* web_contents, |
| 17 const GURL& icon_url, | 17 const GURL& icon_url, |
| 18 int ideal_icon_size_in_dp, | 18 int ideal_icon_size_in_dp, |
| 19 int minimum_icon_size_in_dp, |
| 19 const ManifestIconDownloader::IconFetchCallback& callback) { | 20 const ManifestIconDownloader::IconFetchCallback& callback) { |
| 21 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); |
| 20 if (!web_contents || !icon_url.is_valid()) | 22 if (!web_contents || !icon_url.is_valid()) |
| 21 return false; | 23 return false; |
| 22 | 24 |
| 23 const gfx::Screen* screen = | 25 const gfx::Screen* screen = |
| 24 gfx::Screen::GetScreenFor(web_contents->GetNativeView()); | 26 gfx::Screen::GetScreenFor(web_contents->GetNativeView()); |
| 25 | 27 |
| 26 const float device_scale_factor = | 28 const float device_scale_factor = |
| 27 screen->GetPrimaryDisplay().device_scale_factor(); | 29 screen->GetPrimaryDisplay().device_scale_factor(); |
| 28 const int ideal_icon_size_in_px = | 30 const int ideal_icon_size_in_px = |
| 29 static_cast<int>(round(ideal_icon_size_in_dp * device_scale_factor)); | 31 static_cast<int>(round(ideal_icon_size_in_dp * device_scale_factor)); |
| 30 | |
| 31 const float minimum_scale_factor = std::max(device_scale_factor - 1, 1.0f); | |
| 32 const int minimum_icon_size_in_px = | 32 const int minimum_icon_size_in_px = |
| 33 static_cast<int>(round(ideal_icon_size_in_dp * minimum_scale_factor)); | 33 static_cast<int>(round(minimum_icon_size_in_dp * device_scale_factor)); |
| 34 | 34 |
| 35 web_contents->DownloadImage( | 35 web_contents->DownloadImage( |
| 36 icon_url, | 36 icon_url, |
| 37 false, // is_favicon | 37 false, // is_favicon |
| 38 0, // max_bitmap_size - 0 means no maximum size. | 38 0, // max_bitmap_size - 0 means no maximum size. |
| 39 false, // bypass_cache | 39 false, // bypass_cache |
| 40 base::Bind(&ManifestIconDownloader::OnIconFetched, | 40 base::Bind(&ManifestIconDownloader::OnIconFetched, |
| 41 ideal_icon_size_in_px, | 41 ideal_icon_size_in_px, |
| 42 minimum_icon_size_in_px, | 42 minimum_icon_size_in_px, |
| 43 callback)); | 43 callback)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 continue; | 121 continue; |
| 122 | 122 |
| 123 if ((best_delta > 0 && delta < best_delta) || | 123 if ((best_delta > 0 && delta < best_delta) || |
| 124 (best_delta < 0 && delta > best_delta && delta >= max_negative_delta)) { | 124 (best_delta < 0 && delta > best_delta && delta >= max_negative_delta)) { |
| 125 best_index = i; | 125 best_index = i; |
| 126 best_delta = delta; | 126 best_delta = delta; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 return best_index; | 129 return best_index; |
| 130 } | 130 } |
| OLD | NEW |