| 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) { |
| 20 if (!web_contents || !icon_url.is_valid()) | 21 if (!web_contents || !icon_url.is_valid()) |
| 21 return false; | 22 return false; |
| 22 | 23 |
| 23 const gfx::Screen* screen = | 24 const gfx::Screen* screen = |
| 24 gfx::Screen::GetScreenFor(web_contents->GetNativeView()); | 25 gfx::Screen::GetScreenFor(web_contents->GetNativeView()); |
| 25 | 26 |
| 26 const float device_scale_factor = | 27 const float device_scale_factor = |
| 27 screen->GetPrimaryDisplay().device_scale_factor(); | 28 screen->GetPrimaryDisplay().device_scale_factor(); |
| 28 const float ideal_icon_size_in_px = | 29 const float ideal_icon_size_in_px = |
| 29 ideal_icon_size_in_dp * device_scale_factor; | 30 ideal_icon_size_in_dp * device_scale_factor; |
| 30 | |
| 31 const int minimum_scale_factor = std::max( | |
| 32 static_cast<int>(floor(device_scale_factor - 1)), 1); | |
| 33 const float minimum_icon_size_in_px = | 31 const float minimum_icon_size_in_px = |
| 34 ideal_icon_size_in_dp * minimum_scale_factor; | 32 minimum_icon_size_in_dp * device_scale_factor; |
| 35 | 33 |
| 36 web_contents->DownloadImage( | 34 web_contents->DownloadImage( |
| 37 icon_url, | 35 icon_url, |
| 38 false, // is_favicon | 36 false, // is_favicon |
| 39 0, // max_bitmap_size - 0 means no maximum size. | 37 0, // max_bitmap_size - 0 means no maximum size. |
| 40 false, // bypass_cache | 38 false, // bypass_cache |
| 41 base::Bind(&ManifestIconDownloader::OnIconFetched, | 39 base::Bind(&ManifestIconDownloader::OnIconFetched, |
| 42 ideal_icon_size_in_px, | 40 ideal_icon_size_in_px, |
| 43 minimum_icon_size_in_px, | 41 minimum_icon_size_in_px, |
| 44 callback)); | 42 callback)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 continue; | 120 continue; |
| 123 | 121 |
| 124 if ((best_delta > 0 && delta < best_delta) || | 122 if ((best_delta > 0 && delta < best_delta) || |
| 125 (best_delta < 0 && delta > best_delta && delta >= max_negative_delta)) { | 123 (best_delta < 0 && delta > best_delta && delta >= max_negative_delta)) { |
| 126 best_index = i; | 124 best_index = i; |
| 127 best_delta = delta; | 125 best_delta = delta; |
| 128 } | 126 } |
| 129 } | 127 } |
| 130 return best_index; | 128 return best_index; |
| 131 } | 129 } |
| OLD | NEW |