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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
53 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 53 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
54 0, // The regular install prompt depends on what's being installed. | 54 0, // The regular install prompt depends on what's being installed. |
55 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, | 55 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, |
56 IDS_EXTENSION_INSTALL_PROMPT_TITLE, | 56 IDS_EXTENSION_INSTALL_PROMPT_TITLE, |
57 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, | 57 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, |
58 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE, | 58 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE, |
59 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE, | 59 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE, |
| 60 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE, |
60 }; | 61 }; |
61 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 62 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
62 IDS_EXTENSION_INSTALL_PROMPT_HEADING, | 63 IDS_EXTENSION_INSTALL_PROMPT_HEADING, |
63 0, // Inline installs use the extension name. | 64 0, // Inline installs use the extension name. |
64 0, // Heading for bundle installs depends on the bundle contents. | 65 0, // Heading for bundle installs depends on the bundle contents. |
65 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, | 66 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, |
66 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, | 67 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, |
67 0, // External installs use different strings for extensions/apps. | 68 0, // External installs use different strings for extensions/apps. |
| 69 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING, |
| 70 }; |
| 71 static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 72 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 73 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 74 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 75 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 76 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 77 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 78 ui::DIALOG_BUTTON_CANCEL, |
68 }; | 79 }; |
69 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 80 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
70 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 81 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
71 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 82 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
72 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 83 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
73 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, | 84 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, |
74 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, | 85 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, |
75 0, // External installs use different strings for extensions/apps. | 86 0, // External installs use different strings for extensions/apps. |
| 87 0, |
76 }; | 88 }; |
77 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 89 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
78 0, // These all use the platform's default cancel label. | 90 0, // These all use the platform's default cancel label. |
79 0, | 91 0, |
80 0, | 92 0, |
81 0, | 93 0, |
82 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, | 94 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, |
83 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, | 95 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, |
| 96 IDS_CLOSE, |
84 }; | 97 }; |
85 static const int kPermissionsHeaderIds[ | 98 static const int kPermissionsHeaderIds[ |
86 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 99 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
87 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 100 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
88 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 101 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
89 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, | 102 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, |
90 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, | 103 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
91 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, | 104 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
92 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 105 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 106 IDS_EXTENSION_PROMPT_CAN_ACCESS, |
93 }; | 107 }; |
94 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 108 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
95 IDS_EXTENSION_PROMPT_OAUTH_HEADER, | 109 IDS_EXTENSION_PROMPT_OAUTH_HEADER, |
96 0, // Inline installs don't show OAuth permissions. | 110 0, // Inline installs don't show OAuth permissions. |
97 0, // Bundle installs don't show OAuth permissions. | 111 0, // Bundle installs don't show OAuth permissions. |
98 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, | 112 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, |
99 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, | 113 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, |
100 // TODO(mpcomplete): Do we need this for external install UI? If we do, | 114 // TODO(mpcomplete): Do we need this for external install UI? If we do, |
101 // we need to update FetchOAuthIssueAdviceIfNeeded. | 115 // we need to update FetchOAuthIssueAdviceIfNeeded. |
102 0, | 116 0, |
| 117 0, |
103 }; | 118 }; |
104 | 119 |
105 // Size of extension icon in top left of dialog. | 120 // Size of extension icon in top left of dialog. |
106 const int kIconSize = 69; | 121 const int kIconSize = 69; |
107 | 122 |
108 // Returns pixel size under maximal scale factor for the icon whose device | 123 // Returns pixel size under maximal scale factor for the icon whose device |
109 // independent size is |size_in_dip| | 124 // independent size is |size_in_dip| |
110 int GetSizeForMaxScaleFactor(int size_in_dip) { | 125 int GetSizeForMaxScaleFactor(int size_in_dip) { |
111 float max_scale_factor_scale = | 126 float max_scale_factor_scale = |
112 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); | 127 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_THEME; | 255 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_THEME; |
241 else | 256 else |
242 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; | 257 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; |
243 return l10n_util::GetStringUTF16(resource_id); | 258 return l10n_util::GetStringUTF16(resource_id); |
244 } else { | 259 } else { |
245 return l10n_util::GetStringFUTF16( | 260 return l10n_util::GetStringFUTF16( |
246 kHeadingIds[type_], UTF8ToUTF16(extension_->name())); | 261 kHeadingIds[type_], UTF8ToUTF16(extension_->name())); |
247 } | 262 } |
248 } | 263 } |
249 | 264 |
| 265 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { |
| 266 return kButtons[type_]; |
| 267 } |
| 268 |
| 269 bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { |
| 270 return kAcceptButtonIds[type_] > 0; |
| 271 } |
| 272 |
250 string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { | 273 string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { |
251 if (type_ == EXTERNAL_INSTALL_PROMPT) { | 274 if (type_ == EXTERNAL_INSTALL_PROMPT) { |
252 int id = -1; | 275 int id = -1; |
253 if (extension_->is_app()) | 276 if (extension_->is_app()) |
254 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; | 277 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; |
255 else if (extension_->is_theme()) | 278 else if (extension_->is_theme()) |
256 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; | 279 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; |
257 else | 280 else |
258 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; | 281 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; |
259 return l10n_util::GetStringUTF16(id); | 282 return l10n_util::GetStringUTF16(id); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 extension_ = extension; | 548 extension_ = extension; |
526 delegate_ = delegate; | 549 delegate_ = delegate; |
527 prompt_.set_type(PERMISSIONS_PROMPT); | 550 prompt_.set_type(PERMISSIONS_PROMPT); |
528 | 551 |
529 record_oauth2_grant_ = true; | 552 record_oauth2_grant_ = true; |
530 prompt_.SetOAuthIssueAdvice(issue_advice); | 553 prompt_.SetOAuthIssueAdvice(issue_advice); |
531 | 554 |
532 LoadImageIfNeeded(); | 555 LoadImageIfNeeded(); |
533 } | 556 } |
534 | 557 |
| 558 void ExtensionInstallPrompt::ReviewPermissions(Delegate* delegate, |
| 559 const Extension* extension) { |
| 560 DCHECK(ui_loop_ == MessageLoop::current()); |
| 561 extension_ = extension; |
| 562 permissions_ = extension->GetActivePermissions(); |
| 563 delegate_ = delegate; |
| 564 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); |
| 565 |
| 566 LoadImageIfNeeded(); |
| 567 } |
| 568 |
535 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, | 569 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
536 SkBitmap* icon) { | 570 SkBitmap* icon) { |
537 extension_ = extension; | 571 extension_ = extension; |
538 SetIcon(icon); | 572 SetIcon(icon); |
539 | 573 |
540 install_ui_->OnInstallSuccess(extension, &icon_); | 574 install_ui_->OnInstallSuccess(extension, &icon_); |
541 } | 575 } |
542 | 576 |
543 void ExtensionInstallPrompt::OnInstallFailure( | 577 void ExtensionInstallPrompt::OnInstallFailure( |
544 const extensions::CrxInstallerError& error) { | 578 const extensions::CrxInstallerError& error) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 Manifest::Type extension_type = extension_ ? | 671 Manifest::Type extension_type = extension_ ? |
638 extension_->GetType() : Manifest::TYPE_UNKNOWN; | 672 extension_->GetType() : Manifest::TYPE_UNKNOWN; |
639 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); | 673 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); |
640 } | 674 } |
641 | 675 |
642 switch (prompt_.type()) { | 676 switch (prompt_.type()) { |
643 case PERMISSIONS_PROMPT: | 677 case PERMISSIONS_PROMPT: |
644 case RE_ENABLE_PROMPT: | 678 case RE_ENABLE_PROMPT: |
645 case INLINE_INSTALL_PROMPT: | 679 case INLINE_INSTALL_PROMPT: |
646 case EXTERNAL_INSTALL_PROMPT: | 680 case EXTERNAL_INSTALL_PROMPT: |
647 case INSTALL_PROMPT: { | 681 case INSTALL_PROMPT: |
| 682 case POST_INSTALL_PERMISSIONS_PROMPT: { |
648 prompt_.set_extension(extension_); | 683 prompt_.set_extension(extension_); |
649 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); | 684 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); |
650 break; | 685 break; |
651 } | 686 } |
652 case BUNDLE_INSTALL_PROMPT: { | 687 case BUNDLE_INSTALL_PROMPT: { |
653 prompt_.set_bundle(bundle_); | 688 prompt_.set_bundle(bundle_); |
654 break; | 689 break; |
655 } | 690 } |
656 default: | 691 default: |
657 NOTREACHED() << "Unknown message"; | 692 NOTREACHED() << "Unknown message"; |
658 return; | 693 return; |
659 } | 694 } |
660 | 695 |
661 if (AutoConfirmPrompt(delegate_)) | 696 if (AutoConfirmPrompt(delegate_)) |
662 return; | 697 return; |
663 | 698 |
664 if (show_dialog_callback_.is_null()) | 699 if (show_dialog_callback_.is_null()) |
665 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 700 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
666 else | 701 else |
667 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 702 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
668 } | 703 } |
OLD | NEW |