| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/ui/views/create_application_shortcut_view.h" | 5 #include "chrome/browser/ui/views/create_application_shortcut_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
| 14 #include "chrome/browser/extensions/tab_helper.h" | 15 #include "chrome/browser/extensions/tab_helper.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 const GURL& image_url, | 491 const GURL& image_url, |
| 491 const std::vector<SkBitmap>& bitmaps, | 492 const std::vector<SkBitmap>& bitmaps, |
| 492 const std::vector<gfx::Size>& original_bitmap_sizes) { | 493 const std::vector<gfx::Size>& original_bitmap_sizes) { |
| 493 if (id != pending_download_id_) | 494 if (id != pending_download_id_) |
| 494 return; | 495 return; |
| 495 pending_download_id_ = -1; | 496 pending_download_id_ = -1; |
| 496 | 497 |
| 497 SkBitmap image; | 498 SkBitmap image; |
| 498 | 499 |
| 499 if (!bitmaps.empty()) { | 500 if (!bitmaps.empty()) { |
| 500 std::vector<ui::ScaleFactor> scale_factors; | 501 std::vector<int> requested_sizes_in_pixel; |
| 501 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor( | 502 float scale = ui::GetScaleFactorForNativeView( |
| 502 ui::GetScaleFactorForNativeView( | 503 web_contents_->GetRenderViewHost()->GetView()->GetNativeView()); |
| 503 web_contents_->GetRenderViewHost()->GetView()->GetNativeView())); | 504 requested_sizes_in_pixel.push_back(ceil(requested_size * scale)); |
| 504 scale_factors.push_back(scale_factor); | |
| 505 std::vector<size_t> closest_indices; | 505 std::vector<size_t> closest_indices; |
| 506 SelectFaviconFrameIndices(original_bitmap_sizes, | 506 SelectFaviconFrameIndices(original_bitmap_sizes, |
| 507 scale_factors, | 507 requested_sizes_in_pixel, |
| 508 requested_size, | |
| 509 &closest_indices, | 508 &closest_indices, |
| 510 NULL); | 509 NULL); |
| 511 size_t closest_index = closest_indices[0]; | 510 size_t closest_index = closest_indices[0]; |
| 512 image = bitmaps[closest_index]; | 511 image = bitmaps[closest_index]; |
| 513 } | 512 } |
| 514 | 513 |
| 515 if (!image.isNull()) { | 514 if (!image.isNull()) { |
| 516 shortcut_info_.favicon.Add(gfx::ImageSkia::CreateFrom1xBitmap(image)); | 515 shortcut_info_.favicon.Add(gfx::ImageSkia::CreateFrom1xBitmap(image)); |
| 517 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 516 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
| 518 } else { | 517 } else { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 if (!close_callback_.is_null()) | 552 if (!close_callback_.is_null()) |
| 554 close_callback_.Run(false); | 553 close_callback_.Run(false); |
| 555 return CreateApplicationShortcutView::Cancel(); | 554 return CreateApplicationShortcutView::Cancel(); |
| 556 } | 555 } |
| 557 | 556 |
| 558 // Called when the app's ShortcutInfo (with icon) is loaded. | 557 // Called when the app's ShortcutInfo (with icon) is loaded. |
| 559 void CreateChromeApplicationShortcutView::OnShortcutInfoLoaded( | 558 void CreateChromeApplicationShortcutView::OnShortcutInfoLoaded( |
| 560 const web_app::ShortcutInfo& shortcut_info) { | 559 const web_app::ShortcutInfo& shortcut_info) { |
| 561 shortcut_info_ = shortcut_info; | 560 shortcut_info_ = shortcut_info; |
| 562 } | 561 } |
| OLD | NEW |