| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
| 14 #include "chrome/browser/extensions/image_loader.h" | 14 #include "chrome/browser/extensions/image_loader.h" |
| 15 #include "chrome/browser/extensions/tab_helper.h" | 15 #include "chrome/browser/extensions/tab_helper.h" |
| 16 #include "chrome/browser/favicon/favicon_util.h" | 16 #include "chrome/browser/favicon/favicon_util.h" |
| 17 #include "chrome/browser/history/select_favicon_frames.h" | 17 #include "chrome/browser/history/select_favicon_frames.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 22 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 23 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 23 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/extensions/api/icons/icons_handler.h" |
| 25 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/extensions/extension_resource.h" | 27 #include "chrome/common/extensions/extension_resource.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
| 29 #include "content/public/browser/render_widget_host_view.h" | 30 #include "content/public/browser/render_widget_host_view.h" |
| 30 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 31 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
| 32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 33 #include "grit/locale_settings.h" | 34 #include "grit/locale_settings.h" |
| 34 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 app_(app), | 489 app_(app), |
| 489 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 490 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 490 web_app::UpdateShortcutInfoForApp(*app, profile, &shortcut_info_); | 491 web_app::UpdateShortcutInfoForApp(*app, profile, &shortcut_info_); |
| 491 // The icon will be resized to |max_size|. | 492 // The icon will be resized to |max_size|. |
| 492 const gfx::Size max_size(kAppIconSize, kAppIconSize); | 493 const gfx::Size max_size(kAppIconSize, kAppIconSize); |
| 493 | 494 |
| 494 // Look for an icon. If there is no icon at the ideal size, | 495 // Look for an icon. If there is no icon at the ideal size, |
| 495 // we will resize whatever we can get. Making a large icon smaller | 496 // we will resize whatever we can get. Making a large icon smaller |
| 496 // is prefered to making a small icon larger, so look for a larger | 497 // is prefered to making a small icon larger, so look for a larger |
| 497 // icon first: | 498 // icon first: |
| 498 ExtensionResource icon_resource = app_->GetIconResource( | 499 ExtensionResource icon_resource = extensions::IconsInfo::GetIconResource( |
| 500 app_, |
| 499 kAppIconSize, | 501 kAppIconSize, |
| 500 ExtensionIconSet::MATCH_BIGGER); | 502 ExtensionIconSet::MATCH_BIGGER); |
| 501 | 503 |
| 502 // If no icon exists that is the desired size or larger, get the | 504 // If no icon exists that is the desired size or larger, get the |
| 503 // largest icon available: | 505 // largest icon available: |
| 504 if (icon_resource.empty()) { | 506 if (icon_resource.empty()) { |
| 505 icon_resource = app_->GetIconResource( | 507 icon_resource = extensions::IconsInfo::GetIconResource( |
| 508 app_, |
| 506 kAppIconSize, | 509 kAppIconSize, |
| 507 ExtensionIconSet::MATCH_SMALLER); | 510 ExtensionIconSet::MATCH_SMALLER); |
| 508 } | 511 } |
| 509 | 512 |
| 510 InitControls(); | 513 InitControls(); |
| 511 | 514 |
| 512 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile); | 515 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile); |
| 513 loader->LoadImageAsync(app_, icon_resource, max_size, | 516 loader->LoadImageAsync(app_, icon_resource, max_size, |
| 514 base::Bind(&CreateChromeApplicationShortcutView::OnImageLoaded, | 517 base::Bind(&CreateChromeApplicationShortcutView::OnImageLoaded, |
| 515 weak_ptr_factory_.GetWeakPtr())); | 518 weak_ptr_factory_.GetWeakPtr())); |
| 516 } | 519 } |
| 517 | 520 |
| 518 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} | 521 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} |
| 519 | 522 |
| 520 // Called by ImageLoader when the app's icon is loaded. | 523 // Called by ImageLoader when the app's icon is loaded. |
| 521 void CreateChromeApplicationShortcutView::OnImageLoaded( | 524 void CreateChromeApplicationShortcutView::OnImageLoaded( |
| 522 const gfx::Image& image) { | 525 const gfx::Image& image) { |
| 523 if (image.IsEmpty()) { | 526 if (image.IsEmpty()) { |
| 524 shortcut_info_.favicon = ui::ResourceBundle::GetSharedInstance(). | 527 shortcut_info_.favicon = ui::ResourceBundle::GetSharedInstance(). |
| 525 GetImageNamed(IDR_APP_DEFAULT_ICON); | 528 GetImageNamed(IDR_APP_DEFAULT_ICON); |
| 526 } else { | 529 } else { |
| 527 shortcut_info_.favicon = image; | 530 shortcut_info_.favicon = image; |
| 528 } | 531 } |
| 529 | 532 |
| 530 CHECK(app_info_); | 533 CHECK(app_info_); |
| 531 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 534 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
| 532 } | 535 } |
| OLD | NEW |