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 26 matching lines...) Expand all Loading... | |
| 37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 38 #include "grit/theme_resources.h" | 38 #include "grit/theme_resources.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/image/image.h" | 41 #include "ui/gfx/image/image.h" |
| 42 | 42 |
| 43 using extensions::BundleInstaller; | 43 using extensions::BundleInstaller; |
| 44 using extensions::Extension; | 44 using extensions::Extension; |
| 45 using extensions::PermissionSet; | 45 using extensions::PermissionSet; |
| 46 | 46 |
| 47 namespace { | |
| 48 | |
| 47 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 49 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 48 0, // The regular install prompt depends on what's being installed. | 50 0, // The regular install prompt depends on what's being installed. |
| 49 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, | 51 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, |
| 50 IDS_EXTENSION_INSTALL_PROMPT_TITLE, | 52 IDS_EXTENSION_INSTALL_PROMPT_TITLE, |
| 51 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, | 53 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, |
| 52 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE | 54 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE, |
| 55 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE, | |
| 53 }; | 56 }; |
| 54 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 57 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 55 IDS_EXTENSION_INSTALL_PROMPT_HEADING, | 58 IDS_EXTENSION_INSTALL_PROMPT_HEADING, |
| 56 0, // Inline installs use the extension name. | 59 0, // Inline installs use the extension name. |
| 57 0, // Heading for bundle installs depends on the bundle contents. | 60 0, // Heading for bundle installs depends on the bundle contents. |
| 58 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, | 61 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, |
| 59 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING | 62 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, |
| 63 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING, | |
| 60 }; | 64 }; |
| 61 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 65 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 62 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 66 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 63 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 67 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 64 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 68 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 65 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, | 69 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, |
| 66 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON | 70 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, |
| 71 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON, | |
| 67 }; | 72 }; |
| 68 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 73 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 69 0, // These all use the platform's default cancel label. | 74 0, // These all use the platform's default cancel label. |
| 70 0, | 75 0, |
| 71 0, | 76 0, |
| 72 0, | 77 0, |
| 73 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON | 78 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, |
| 79 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, | |
| 74 }; | 80 }; |
| 75 static const int kPermissionsHeaderIds[ | 81 static const int kPermissionsHeaderIds[ |
| 76 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 82 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 77 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 83 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 78 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 84 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 79 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, | 85 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, |
| 80 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, | 86 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
| 81 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, | 87 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
| 88 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | |
| 82 }; | 89 }; |
| 83 static const int kOAuthHeaderIds[ | 90 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 84 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | |
| 85 IDS_EXTENSION_PROMPT_OAUTH_HEADER, | 91 IDS_EXTENSION_PROMPT_OAUTH_HEADER, |
| 86 0, // Inline installs don't show OAuth permissions. | 92 0, // Inline installs don't show OAuth permissions. |
| 87 0, // Bundle installs don't show OAuth permissions. | 93 0, // Bundle installs don't show OAuth permissions. |
| 88 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, | 94 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, |
| 89 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, | 95 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, |
| 96 0, // TODO(mpcomplete): Do we need this for external install UI? | |
|
Jeffrey Yasskin
2012/10/13 21:17:35
I'd assume external extensions can ask for oauth p
| |
| 90 }; | 97 }; |
| 91 | 98 |
| 92 namespace { | |
| 93 | |
| 94 // Size of extension icon in top left of dialog. | 99 // Size of extension icon in top left of dialog. |
| 95 const int kIconSize = 69; | 100 const int kIconSize = 69; |
| 96 | 101 |
| 97 // Returns pixel size under maximal scale factor for the icon whose device | 102 // Returns pixel size under maximal scale factor for the icon whose device |
| 98 // independent size is |size_in_dip| | 103 // independent size is |size_in_dip| |
| 99 int GetSizeForMaxScaleFactor(int size_in_dip) { | 104 int GetSizeForMaxScaleFactor(int size_in_dip) { |
| 100 std::vector<ui::ScaleFactor> supported_scale_factors = | 105 std::vector<ui::ScaleFactor> supported_scale_factors = |
| 101 ui::GetSupportedScaleFactors(); | 106 ui::GetSupportedScaleFactors(); |
| 102 // Scale factors are in ascending order, so the last one is the one we need. | 107 // Scale factors are in ascending order, so the last one is the one we need. |
| 103 ui::ScaleFactor max_scale_factor = supported_scale_factors.back(); | 108 ui::ScaleFactor max_scale_factor = supported_scale_factors.back(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { | 194 string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { |
| 190 int resource_id = kTitleIds[type_]; | 195 int resource_id = kTitleIds[type_]; |
| 191 | 196 |
| 192 if (type_ == INSTALL_PROMPT) { | 197 if (type_ == INSTALL_PROMPT) { |
| 193 if (extension_->is_app()) | 198 if (extension_->is_app()) |
| 194 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; | 199 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; |
| 195 else if (extension_->is_theme()) | 200 else if (extension_->is_theme()) |
| 196 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; | 201 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; |
| 197 else | 202 else |
| 198 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; | 203 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; |
| 204 } else if (type_ == EXTERNAL_INSTALL_PROMPT) { | |
| 205 return l10n_util::GetStringFUTF16( | |
| 206 resource_id, UTF8ToUTF16(extension_->name())); | |
| 199 } | 207 } |
| 200 | 208 |
| 201 return l10n_util::GetStringUTF16(resource_id); | 209 return l10n_util::GetStringUTF16(resource_id); |
| 202 } | 210 } |
| 203 | 211 |
| 204 string16 ExtensionInstallPrompt::Prompt::GetHeading() const { | 212 string16 ExtensionInstallPrompt::Prompt::GetHeading() const { |
| 205 if (type_ == INLINE_INSTALL_PROMPT) { | 213 if (type_ == INLINE_INSTALL_PROMPT) { |
| 206 return UTF8ToUTF16(extension_->name()); | 214 return UTF8ToUTF16(extension_->name()); |
| 207 } else if (type_ == BUNDLE_INSTALL_PROMPT) { | 215 } else if (type_ == BUNDLE_INSTALL_PROMPT) { |
| 208 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING); | 216 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING); |
| 217 } else if (type_ == EXTERNAL_INSTALL_PROMPT) { | |
| 218 return l10n_util::GetStringUTF16(kHeadingIds[type_]); | |
| 209 } else { | 219 } else { |
| 210 return l10n_util::GetStringFUTF16( | 220 return l10n_util::GetStringFUTF16( |
| 211 kHeadingIds[type_], UTF8ToUTF16(extension_->name())); | 221 kHeadingIds[type_], UTF8ToUTF16(extension_->name())); |
| 212 } | 222 } |
| 213 } | 223 } |
| 214 | 224 |
| 215 string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { | 225 string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { |
| 216 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); | 226 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); |
| 217 } | 227 } |
| 218 | 228 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 const Extension* extension) { | 436 const Extension* extension) { |
| 427 DCHECK(ui_loop_ == MessageLoop::current()); | 437 DCHECK(ui_loop_ == MessageLoop::current()); |
| 428 extension_ = extension; | 438 extension_ = extension; |
| 429 permissions_ = extension->GetActivePermissions(); | 439 permissions_ = extension->GetActivePermissions(); |
| 430 delegate_ = delegate; | 440 delegate_ = delegate; |
| 431 prompt_type_ = RE_ENABLE_PROMPT; | 441 prompt_type_ = RE_ENABLE_PROMPT; |
| 432 | 442 |
| 433 LoadImageIfNeeded(); | 443 LoadImageIfNeeded(); |
| 434 } | 444 } |
| 435 | 445 |
| 446 void ExtensionInstallPrompt::ConfirmExternalInstall( | |
| 447 Delegate* delegate, const Extension* extension) { | |
| 448 DCHECK(ui_loop_ == MessageLoop::current()); | |
| 449 extension_ = extension; | |
| 450 permissions_ = extension->GetActivePermissions(); | |
| 451 delegate_ = delegate; | |
| 452 prompt_type_ = EXTERNAL_INSTALL_PROMPT; | |
| 453 show_dialog_callback_ = // @@@MP | |
|
Matt Perry
2012/10/13 00:33:18
I'll remove this once http://codereview.chromium.o
| |
| 454 ExtensionInstallPrompt::GetDefaultShowDialogCallback(); | |
| 455 | |
| 456 LoadImageIfNeeded(); | |
|
Jeffrey Yasskin
2012/10/13 21:17:35
Wow, that's a subtle name for the "go show the dia
| |
| 457 } | |
| 458 | |
| 436 void ExtensionInstallPrompt::ConfirmPermissions( | 459 void ExtensionInstallPrompt::ConfirmPermissions( |
| 437 Delegate* delegate, | 460 Delegate* delegate, |
| 438 const Extension* extension, | 461 const Extension* extension, |
| 439 const PermissionSet* permissions) { | 462 const PermissionSet* permissions) { |
| 440 DCHECK(ui_loop_ == MessageLoop::current()); | 463 DCHECK(ui_loop_ == MessageLoop::current()); |
| 441 extension_ = extension; | 464 extension_ = extension; |
| 442 permissions_ = permissions; | 465 permissions_ = permissions; |
| 443 delegate_ = delegate; | 466 delegate_ = delegate; |
| 444 prompt_type_ = PERMISSIONS_PROMPT; | 467 prompt_type_ = PERMISSIONS_PROMPT; |
| 445 | 468 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 | 512 |
| 490 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, | 513 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, |
| 491 const std::string& extension_id, | 514 const std::string& extension_id, |
| 492 int index) { | 515 int index) { |
| 493 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); | 516 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
| 494 FetchOAuthIssueAdviceIfNeeded(); | 517 FetchOAuthIssueAdviceIfNeeded(); |
| 495 } | 518 } |
| 496 | 519 |
| 497 void ExtensionInstallPrompt::LoadImageIfNeeded() { | 520 void ExtensionInstallPrompt::LoadImageIfNeeded() { |
| 498 // Bundle install prompts do not have an icon. | 521 // Bundle install prompts do not have an icon. |
| 499 if (!icon_.empty()) { | 522 if (!icon_.empty()) { |
|
Jeffrey Yasskin
2012/10/13 21:17:35
Not related to this CL, but !icon_.empty() seems t
| |
| 500 FetchOAuthIssueAdviceIfNeeded(); | 523 FetchOAuthIssueAdviceIfNeeded(); |
| 501 return; | 524 return; |
| 502 } | 525 } |
| 503 | 526 |
| 504 // Load the image asynchronously. For the response, check OnImageLoaded. | 527 // Load the image asynchronously. For the response, check OnImageLoaded. |
| 505 ExtensionResource image = | 528 ExtensionResource image = |
| 506 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, | 529 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, |
| 507 ExtensionIconSet::MATCH_BIGGER); | 530 ExtensionIconSet::MATCH_BIGGER); |
| 508 // Load the icon whose pixel size is large enough to be displayed under | 531 // Load the icon whose pixel size is large enough to be displayed under |
| 509 // maximal supported scale factor. UI code will scale the icon down if needed. | 532 // maximal supported scale factor. UI code will scale the icon down if needed. |
| 510 // TODO(tbarzic): We should use IconImage here and load the required bitmap | 533 // TODO(tbarzic): We should use IconImage here and load the required bitmap |
| 511 // lazily. | 534 // lazily. |
| 512 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); | 535 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); |
| 513 tracker_.LoadImage(extension_, image, | 536 tracker_.LoadImage(extension_, image, |
| 514 gfx::Size(pixel_size, pixel_size), | 537 gfx::Size(pixel_size, pixel_size), |
| 515 ImageLoadingTracker::DONT_CACHE); | 538 ImageLoadingTracker::DONT_CACHE); |
| 516 } | 539 } |
| 517 | 540 |
| 518 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { | 541 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { |
| 519 // |extension_| may be NULL, e.g. in the bundle install case. | 542 // |extension_| may be NULL, e.g. in the bundle install case. |
| 520 if (!extension_ || | 543 if (!extension_ || |
| 521 prompt_type_ == BUNDLE_INSTALL_PROMPT || | 544 prompt_type_ == BUNDLE_INSTALL_PROMPT || |
| 522 prompt_type_ == INLINE_INSTALL_PROMPT || | 545 prompt_type_ == INLINE_INSTALL_PROMPT || |
|
Jeffrey Yasskin
2012/10/13 21:17:35
Do you need to include EXTERNAL_INSTALL_PROMPT in
Matt Perry
2012/10/15 19:13:38
Good catch. Done.
| |
| 523 prompt_.GetOAuthIssueCount() != 0U) { | 546 prompt_.GetOAuthIssueCount() != 0U) { |
| 524 ShowConfirmation(); | 547 ShowConfirmation(); |
| 525 return; | 548 return; |
| 526 } | 549 } |
| 527 | 550 |
| 528 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info(); | 551 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info(); |
| 529 if (oauth2_info.client_id.empty() || | 552 if (oauth2_info.client_id.empty() || |
| 530 oauth2_info.scopes.empty()) { | 553 oauth2_info.scopes.empty()) { |
| 531 ShowConfirmation(); | 554 ShowConfirmation(); |
| 532 return; | 555 return; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 if (permissions_) { | 588 if (permissions_) { |
| 566 Extension::Type extension_type = prompt_type_ == BUNDLE_INSTALL_PROMPT ? | 589 Extension::Type extension_type = prompt_type_ == BUNDLE_INSTALL_PROMPT ? |
| 567 Extension::TYPE_UNKNOWN : extension_->GetType(); | 590 Extension::TYPE_UNKNOWN : extension_->GetType(); |
| 568 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); | 591 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); |
| 569 } | 592 } |
| 570 | 593 |
| 571 switch (prompt_type_) { | 594 switch (prompt_type_) { |
| 572 case PERMISSIONS_PROMPT: | 595 case PERMISSIONS_PROMPT: |
| 573 case RE_ENABLE_PROMPT: | 596 case RE_ENABLE_PROMPT: |
| 574 case INLINE_INSTALL_PROMPT: | 597 case INLINE_INSTALL_PROMPT: |
| 598 case EXTERNAL_INSTALL_PROMPT: | |
| 575 case INSTALL_PROMPT: { | 599 case INSTALL_PROMPT: { |
| 576 prompt_.set_extension(extension_); | 600 prompt_.set_extension(extension_); |
| 577 prompt_.set_icon(gfx::Image(icon_)); | 601 prompt_.set_icon(gfx::Image(icon_)); |
| 578 break; | 602 break; |
| 579 } | 603 } |
| 580 case BUNDLE_INSTALL_PROMPT: { | 604 case BUNDLE_INSTALL_PROMPT: { |
| 581 prompt_.set_bundle(bundle_); | 605 prompt_.set_bundle(bundle_); |
| 582 break; | 606 break; |
| 583 } | 607 } |
| 584 default: | 608 default: |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 599 Browser* browser) { | 623 Browser* browser) { |
| 600 // |browser| can be NULL in unit tests. | 624 // |browser| can be NULL in unit tests. |
| 601 if (!browser) | 625 if (!browser) |
| 602 return new ExtensionInstallPrompt(NULL, NULL, NULL); | 626 return new ExtensionInstallPrompt(NULL, NULL, NULL); |
| 603 gfx::NativeWindow parent = | 627 gfx::NativeWindow parent = |
| 604 browser->window() ? browser->window()->GetNativeWindow() : NULL; | 628 browser->window() ? browser->window()->GetNativeWindow() : NULL; |
| 605 return new ExtensionInstallPrompt(parent, browser, browser->profile()); | 629 return new ExtensionInstallPrompt(parent, browser, browser->profile()); |
| 606 } | 630 } |
| 607 | 631 |
| 608 } // namespace chrome | 632 } // namespace chrome |
| OLD | NEW |