Chromium Code Reviews| 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/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 Loading... | |
| 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 = | |
| 105 supported_scale_factors[supported_scale_factors.size() - 1]; | |
| 106 float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor); | |
| 107 | |
| 108 return static_cast<int>(size_in_dip * max_scale_factor_scale); | |
| 109 } | |
| 110 | |
| 111 // Returns bitmap for the default icon with size equal to the default icon's | |
| 112 // pixel size under maximal supported scale factor. | |
| 113 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { | |
| 114 std::vector<ui::ScaleFactor> supported_scale_factors = | |
| 115 ui::GetSupportedScaleFactors(); | |
| 116 // Scale factors are in ascending order, so the last one is the one we need. | |
| 117 ui::ScaleFactor max_scale_factor = | |
| 118 supported_scale_factors[supported_scale_factors.size() - 1]; | |
| 119 | |
| 120 return Extension::GetDefaultIcon(is_app). | |
| 121 GetRepresentation(max_scale_factor).sk_bitmap(); | |
| 122 } | |
| 123 | |
| 98 } // namespace | 124 } // namespace |
| 99 | 125 |
| 100 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) | 126 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) |
| 101 : type_(type), | 127 : type_(type), |
| 102 extension_(NULL), | 128 extension_(NULL), |
| 103 bundle_(NULL), | 129 bundle_(NULL), |
| 104 average_rating_(0.0), | 130 average_rating_(0.0), |
| 105 rating_count_(0), | 131 rating_count_(0), |
| 106 profile_(profile) { | 132 profile_(profile) { |
| 107 } | 133 } |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 void ExtensionInstallPrompt::OnInstallFailure( | 435 void ExtensionInstallPrompt::OnInstallFailure( |
| 410 const extensions::CrxInstallerError& error) { | 436 const extensions::CrxInstallerError& error) { |
| 411 install_ui_->OnInstallFailure(error); | 437 install_ui_->OnInstallFailure(error); |
| 412 } | 438 } |
| 413 | 439 |
| 414 void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) { | 440 void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) { |
| 415 if (image) | 441 if (image) |
| 416 icon_ = *image; | 442 icon_ = *image; |
| 417 else | 443 else |
| 418 icon_ = SkBitmap(); | 444 icon_ = SkBitmap(); |
| 419 if (icon_.empty()) | 445 if (icon_.empty()) { |
| 420 icon_ = Extension::GetDefaultIcon(extension_->is_app()); | 446 // Let's set default icon bitmap whose size is equal to the default icon's |
| 447 // pixel size under maximal supported scale factor. If the bitmap is larger | |
| 448 // than the one we need, it will be scaled down by the ui code. | |
| 449 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); | |
| 450 } | |
| 421 } | 451 } |
| 422 | 452 |
| 423 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, | 453 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, |
| 424 const std::string& extension_id, | 454 const std::string& extension_id, |
| 425 int index) { | 455 int index) { |
| 426 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); | 456 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
| 427 FetchOAuthIssueAdviceIfNeeded(); | 457 FetchOAuthIssueAdviceIfNeeded(); |
| 428 } | 458 } |
| 429 | 459 |
| 430 void ExtensionInstallPrompt::LoadImageIfNeeded() { | 460 void ExtensionInstallPrompt::LoadImageIfNeeded() { |
| 431 // Bundle install prompts do not have an icon. | 461 // Bundle install prompts do not have an icon. |
| 432 if (!icon_.empty()) { | 462 if (!icon_.empty()) { |
| 433 FetchOAuthIssueAdviceIfNeeded(); | 463 FetchOAuthIssueAdviceIfNeeded(); |
| 434 return; | 464 return; |
| 435 } | 465 } |
| 436 | 466 |
| 437 // Load the image asynchronously. For the response, check OnImageLoaded. | 467 // Load the image asynchronously. For the response, check OnImageLoaded. |
| 438 ExtensionResource image = | 468 ExtensionResource image = |
| 439 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, | 469 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, |
| 440 ExtensionIconSet::MATCH_BIGGER); | 470 ExtensionIconSet::MATCH_BIGGER); |
| 471 // Load the icon whose pixel size is large enough to be displayed under | |
|
Jeffrey Yasskin
2012/09/14 19:34:01
Please add TODOs to load the precisely correct siz
tbarzic
2012/09/14 22:34:31
Done.
| |
| 472 // maximal supported scale factor. UI code will scale the icon down if needed. | |
| 473 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); | |
| 441 tracker_.LoadImage(extension_, image, | 474 tracker_.LoadImage(extension_, image, |
| 442 gfx::Size(kIconSize, kIconSize), | 475 gfx::Size(pixel_size, pixel_size), |
| 443 ImageLoadingTracker::DONT_CACHE); | 476 ImageLoadingTracker::DONT_CACHE); |
| 444 } | 477 } |
| 445 | 478 |
| 446 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { | 479 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { |
| 447 // |extension_| may be NULL, e.g. in the bundle install case. | 480 // |extension_| may be NULL, e.g. in the bundle install case. |
| 448 if (!extension_ || | 481 if (!extension_ || |
| 449 prompt_type_ == BUNDLE_INSTALL_PROMPT || | 482 prompt_type_ == BUNDLE_INSTALL_PROMPT || |
| 450 prompt_type_ == INLINE_INSTALL_PROMPT || | 483 prompt_type_ == INLINE_INSTALL_PROMPT || |
| 451 prompt_.GetOAuthIssueCount() != 0U) { | 484 prompt_.GetOAuthIssueCount() != 0U) { |
| 452 ShowConfirmation(); | 485 ShowConfirmation(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 Browser* browser) { | 556 Browser* browser) { |
| 524 // |browser| can be NULL in unit tests. | 557 // |browser| can be NULL in unit tests. |
| 525 if (!browser) | 558 if (!browser) |
| 526 return new ExtensionInstallPrompt(NULL, NULL, NULL); | 559 return new ExtensionInstallPrompt(NULL, NULL, NULL); |
| 527 gfx::NativeWindow parent = | 560 gfx::NativeWindow parent = |
| 528 browser->window() ? browser->window()->GetNativeWindow() : NULL; | 561 browser->window() ? browser->window()->GetNativeWindow() : NULL; |
| 529 return new ExtensionInstallPrompt(parent, browser, browser->profile()); | 562 return new ExtensionInstallPrompt(parent, browser, browser->profile()); |
| 530 } | 563 } |
| 531 | 564 |
| 532 } // namespace chrome | 565 } // namespace chrome |
| OLD | NEW |