Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 10915251: Fix for pixelated icons in extension install ui on 2x scale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: .. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_uninstall_dialog.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/extensions/extension_install_prompt.h" 5 #include "chrome/browser/extensions/extension_install_prompt.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 0, // Bundle installs don't show OAuth permissions. 88 0, // Bundle installs don't show OAuth permissions.
89 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, 89 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER,
90 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, 90 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER,
91 }; 91 };
92 92
93 namespace { 93 namespace {
94 94
95 // Size of extension icon in top left of dialog. 95 // Size of extension icon in top left of dialog.
96 const int kIconSize = 69; 96 const int kIconSize = 69;
97 97
98 // Returns pixel size under maximal scale factor for the icon whose device
99 // independent size is |size_in_dip|
100 int GetSizeForMaxScaleFactor(int size_in_dip) {
101 std::vector<ui::ScaleFactor> supported_scale_factors =
102 ui::GetSupportedScaleFactors();
103 // Scale factors are in ascending order, so the last one is the one we need.
104 ui::ScaleFactor max_scale_factor = supported_scale_factors.back();
105 float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor);
106
107 return static_cast<int>(size_in_dip * max_scale_factor_scale);
108 }
109
110 // Returns bitmap for the default icon with size equal to the default icon's
111 // pixel size under maximal supported scale factor.
112 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
113 std::vector<ui::ScaleFactor> supported_scale_factors =
114 ui::GetSupportedScaleFactors();
115 // Scale factors are in ascending order, so the last one is the one we need.
116 ui::ScaleFactor max_scale_factor =
117 supported_scale_factors[supported_scale_factors.size() - 1];
118
119 return Extension::GetDefaultIcon(is_app).
120 GetRepresentation(max_scale_factor).sk_bitmap();
121 }
122
98 } // namespace 123 } // namespace
99 124
100 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) 125 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type)
101 : type_(type), 126 : type_(type),
102 extension_(NULL), 127 extension_(NULL),
103 bundle_(NULL), 128 bundle_(NULL),
104 average_rating_(0.0), 129 average_rating_(0.0),
105 rating_count_(0), 130 rating_count_(0),
106 profile_(profile) { 131 profile_(profile) {
107 } 132 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 void ExtensionInstallPrompt::OnInstallFailure( 434 void ExtensionInstallPrompt::OnInstallFailure(
410 const extensions::CrxInstallerError& error) { 435 const extensions::CrxInstallerError& error) {
411 install_ui_->OnInstallFailure(error); 436 install_ui_->OnInstallFailure(error);
412 } 437 }
413 438
414 void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) { 439 void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) {
415 if (image) 440 if (image)
416 icon_ = *image; 441 icon_ = *image;
417 else 442 else
418 icon_ = SkBitmap(); 443 icon_ = SkBitmap();
419 if (icon_.empty()) 444 if (icon_.empty()) {
420 icon_ = Extension::GetDefaultIcon(extension_->is_app()); 445 // Let's set default icon bitmap whose size is equal to the default icon's
446 // pixel size under maximal supported scale factor. If the bitmap is larger
447 // than the one we need, it will be scaled down by the ui code.
448 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
449 }
421 } 450 }
422 451
423 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, 452 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image,
424 const std::string& extension_id, 453 const std::string& extension_id,
425 int index) { 454 int index) {
426 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); 455 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap());
427 FetchOAuthIssueAdviceIfNeeded(); 456 FetchOAuthIssueAdviceIfNeeded();
428 } 457 }
429 458
430 void ExtensionInstallPrompt::LoadImageIfNeeded() { 459 void ExtensionInstallPrompt::LoadImageIfNeeded() {
431 // Bundle install prompts do not have an icon. 460 // Bundle install prompts do not have an icon.
432 if (!icon_.empty()) { 461 if (!icon_.empty()) {
433 FetchOAuthIssueAdviceIfNeeded(); 462 FetchOAuthIssueAdviceIfNeeded();
434 return; 463 return;
435 } 464 }
436 465
437 // Load the image asynchronously. For the response, check OnImageLoaded. 466 // Load the image asynchronously. For the response, check OnImageLoaded.
438 ExtensionResource image = 467 ExtensionResource image =
439 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, 468 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE,
440 ExtensionIconSet::MATCH_BIGGER); 469 ExtensionIconSet::MATCH_BIGGER);
470 // Load the icon whose pixel size is large enough to be displayed under
471 // maximal supported scale factor. UI code will scale the icon down if needed.
472 // TODO(tbarzic): We should use IconImage here and load the required bitmap
473 // lazily.
474 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
441 tracker_.LoadImage(extension_, image, 475 tracker_.LoadImage(extension_, image,
442 gfx::Size(kIconSize, kIconSize), 476 gfx::Size(pixel_size, pixel_size),
443 ImageLoadingTracker::DONT_CACHE); 477 ImageLoadingTracker::DONT_CACHE);
444 } 478 }
445 479
446 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { 480 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() {
447 // |extension_| may be NULL, e.g. in the bundle install case. 481 // |extension_| may be NULL, e.g. in the bundle install case.
448 if (!extension_ || 482 if (!extension_ ||
449 prompt_type_ == BUNDLE_INSTALL_PROMPT || 483 prompt_type_ == BUNDLE_INSTALL_PROMPT ||
450 prompt_type_ == INLINE_INSTALL_PROMPT || 484 prompt_type_ == INLINE_INSTALL_PROMPT ||
451 prompt_.GetOAuthIssueCount() != 0U) { 485 prompt_.GetOAuthIssueCount() != 0U) {
452 ShowConfirmation(); 486 ShowConfirmation();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 Browser* browser) { 557 Browser* browser) {
524 // |browser| can be NULL in unit tests. 558 // |browser| can be NULL in unit tests.
525 if (!browser) 559 if (!browser)
526 return new ExtensionInstallPrompt(NULL, NULL, NULL); 560 return new ExtensionInstallPrompt(NULL, NULL, NULL);
527 gfx::NativeWindow parent = 561 gfx::NativeWindow parent =
528 browser->window() ? browser->window()->GetNativeWindow() : NULL; 562 browser->window() ? browser->window()->GetNativeWindow() : NULL;
529 return new ExtensionInstallPrompt(parent, browser, browser->profile()); 563 return new ExtensionInstallPrompt(parent, browser, browser->profile());
530 } 564 }
531 565
532 } // namespace chrome 566 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_uninstall_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698