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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE, |
61 IDS_EXTENSION_UPDATE_PROMPT_TITLE, | |
Matt Perry
2013/02/27 01:21:46
Let's not add a new prompt type. We should do what
Joe Thomas
2013/02/27 20:55:38
Done.
| |
61 }; | 62 }; |
62 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 63 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
63 IDS_EXTENSION_INSTALL_PROMPT_HEADING, | 64 IDS_EXTENSION_INSTALL_PROMPT_HEADING, |
64 0, // Inline installs use the extension name. | 65 0, // Inline installs use the extension name. |
65 0, // Heading for bundle installs depends on the bundle contents. | 66 0, // Heading for bundle installs depends on the bundle contents. |
66 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, | 67 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, |
67 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, | 68 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, |
68 0, // External installs use different strings for extensions/apps. | 69 0, // External installs use different strings for extensions/apps. |
69 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING, | 70 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING, |
71 IDS_EXTENSION_UPDATE_PROMPT_HEADING, | |
70 }; | 72 }; |
71 static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 73 static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
72 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 74 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
73 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 75 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
74 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 76 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
75 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 77 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
76 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 78 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
77 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 79 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
78 ui::DIALOG_BUTTON_CANCEL, | 80 ui::DIALOG_BUTTON_CANCEL, |
81 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | |
79 }; | 82 }; |
80 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 83 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
81 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 84 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
82 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 85 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
83 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 86 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
84 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, | 87 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, |
85 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, | 88 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, |
86 0, // External installs use different strings for extensions/apps. | 89 0, // External installs use different strings for extensions/apps. |
87 0, | 90 0, |
91 IDS_EXTENSION_PROMPT_UPDATE_BUTTON, | |
88 }; | 92 }; |
89 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 93 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
90 0, // These all use the platform's default cancel label. | 94 0, // These all use the platform's default cancel label. |
91 0, | 95 0, |
92 0, | 96 0, |
93 0, | 97 0, |
94 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, | 98 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, |
95 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, | 99 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, |
96 IDS_CLOSE, | 100 IDS_CLOSE, |
101 0, | |
97 }; | 102 }; |
98 static const int kPermissionsHeaderIds[ | 103 static const int kPermissionsHeaderIds[ |
99 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 104 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
100 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 105 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
101 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 106 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
102 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, | 107 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, |
103 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, | 108 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
104 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, | 109 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
105 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 110 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
106 IDS_EXTENSION_PROMPT_CAN_ACCESS, | 111 IDS_EXTENSION_PROMPT_CAN_ACCESS, |
112 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, | |
107 }; | 113 }; |
108 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 114 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
109 IDS_EXTENSION_PROMPT_OAUTH_HEADER, | 115 IDS_EXTENSION_PROMPT_OAUTH_HEADER, |
110 0, // Inline installs don't show OAuth permissions. | 116 0, // Inline installs don't show OAuth permissions. |
111 0, // Bundle installs don't show OAuth permissions. | 117 0, // Bundle installs don't show OAuth permissions. |
112 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, | 118 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, |
113 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, | 119 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, |
114 // TODO(mpcomplete): Do we need this for external install UI? If we do, | 120 // TODO(mpcomplete): Do we need this for external install UI? If we do, |
115 // we need to update FetchOAuthIssueAdviceIfNeeded. | 121 // we need to update FetchOAuthIssueAdviceIfNeeded. |
116 0, | 122 0, |
117 0, | 123 0, |
124 IDS_EXTENSION_PROMPT_OAUTH_UPDATE_HEADER, | |
118 }; | 125 }; |
119 | 126 |
120 // Size of extension icon in top left of dialog. | 127 // Size of extension icon in top left of dialog. |
121 const int kIconSize = 69; | 128 const int kIconSize = 69; |
122 | 129 |
123 // Returns pixel size under maximal scale factor for the icon whose device | 130 // Returns pixel size under maximal scale factor for the icon whose device |
124 // independent size is |size_in_dip| | 131 // independent size is |size_in_dip| |
125 int GetSizeForMaxScaleFactor(int size_in_dip) { | 132 int GetSizeForMaxScaleFactor(int size_in_dip) { |
126 float max_scale_factor_scale = | 133 float max_scale_factor_scale = |
127 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); | 134 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 const Extension* extension) { | 566 const Extension* extension) { |
560 DCHECK(ui_loop_ == MessageLoop::current()); | 567 DCHECK(ui_loop_ == MessageLoop::current()); |
561 extension_ = extension; | 568 extension_ = extension; |
562 permissions_ = extension->GetActivePermissions(); | 569 permissions_ = extension->GetActivePermissions(); |
563 delegate_ = delegate; | 570 delegate_ = delegate; |
564 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); | 571 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); |
565 | 572 |
566 LoadImageIfNeeded(); | 573 LoadImageIfNeeded(); |
567 } | 574 } |
568 | 575 |
576 void ExtensionInstallPrompt::ConfirmUpdate(Delegate* delegate, | |
577 const Extension* extension) { | |
578 DCHECK(ui_loop_ == MessageLoop::current()); | |
579 extension_ = extension; | |
580 permissions_ = extension->GetActivePermissions(); | |
581 delegate_ = delegate; | |
582 prompt_.set_type(UPDATE_PROMPT); | |
583 | |
584 LoadImageIfNeeded(); | |
585 } | |
586 | |
569 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, | 587 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
570 SkBitmap* icon) { | 588 SkBitmap* icon) { |
571 extension_ = extension; | 589 extension_ = extension; |
572 SetIcon(icon); | 590 SetIcon(icon); |
573 | 591 |
574 install_ui_->OnInstallSuccess(extension, &icon_); | 592 install_ui_->OnInstallSuccess(extension, &icon_); |
575 } | 593 } |
576 | 594 |
577 void ExtensionInstallPrompt::OnInstallFailure( | 595 void ExtensionInstallPrompt::OnInstallFailure( |
578 const extensions::CrxInstallerError& error) { | 596 const extensions::CrxInstallerError& error) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 extension_->GetType() : Manifest::TYPE_UNKNOWN; | 690 extension_->GetType() : Manifest::TYPE_UNKNOWN; |
673 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); | 691 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); |
674 } | 692 } |
675 | 693 |
676 switch (prompt_.type()) { | 694 switch (prompt_.type()) { |
677 case PERMISSIONS_PROMPT: | 695 case PERMISSIONS_PROMPT: |
678 case RE_ENABLE_PROMPT: | 696 case RE_ENABLE_PROMPT: |
679 case INLINE_INSTALL_PROMPT: | 697 case INLINE_INSTALL_PROMPT: |
680 case EXTERNAL_INSTALL_PROMPT: | 698 case EXTERNAL_INSTALL_PROMPT: |
681 case INSTALL_PROMPT: | 699 case INSTALL_PROMPT: |
682 case POST_INSTALL_PERMISSIONS_PROMPT: { | 700 case POST_INSTALL_PERMISSIONS_PROMPT: |
701 case UPDATE_PROMPT: { | |
683 prompt_.set_extension(extension_); | 702 prompt_.set_extension(extension_); |
684 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); | 703 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); |
685 break; | 704 break; |
686 } | 705 } |
687 case BUNDLE_INSTALL_PROMPT: { | 706 case BUNDLE_INSTALL_PROMPT: { |
688 prompt_.set_bundle(bundle_); | 707 prompt_.set_bundle(bundle_); |
689 break; | 708 break; |
690 } | 709 } |
691 default: | 710 default: |
692 NOTREACHED() << "Unknown message"; | 711 NOTREACHED() << "Unknown message"; |
693 return; | 712 return; |
694 } | 713 } |
695 | 714 |
696 if (AutoConfirmPrompt(delegate_)) | 715 if (AutoConfirmPrompt(delegate_)) |
697 return; | 716 return; |
698 | 717 |
699 if (show_dialog_callback_.is_null()) | 718 if (show_dialog_callback_.is_null()) |
700 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 719 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
701 else | 720 else |
702 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 721 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
703 } | 722 } |
OLD | NEW |