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

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

Issue 850283003: Add a new webstorePrivate API to show a permission prompt for delegated installs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_permission_prompt
Patch Set: rebase Created 5 years, 10 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
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/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 0, // The regular install prompt depends on what's being installed. 63 0, // The regular install prompt depends on what's being installed.
64 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, 64 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE,
65 IDS_EXTENSION_INSTALL_PROMPT_TITLE, 65 IDS_EXTENSION_INSTALL_PROMPT_TITLE,
66 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, 66 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE,
67 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE, 67 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE,
68 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE, 68 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE,
69 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE, 69 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE,
70 IDS_EXTENSION_LAUNCH_APP_PROMPT_TITLE, 70 IDS_EXTENSION_LAUNCH_APP_PROMPT_TITLE,
71 0, // The remote install prompt depends on what's being installed. 71 0, // The remote install prompt depends on what's being installed.
72 0, // The repair install prompt depends on what's being installed. 72 0, // The repair install prompt depends on what's being installed.
73 0, // The delegated install prompt depends on what's being installed.
73 }; 74 };
74 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 75 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
75 IDS_EXTENSION_INSTALL_PROMPT_HEADING, 76 IDS_EXTENSION_INSTALL_PROMPT_HEADING,
76 0, // Inline installs use the extension name. 77 0, // Inline installs use the extension name.
77 0, // Heading for bundle installs depends on the bundle contents. 78 0, // Heading for bundle installs depends on the bundle contents.
78 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, 79 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING,
79 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, 80 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING,
80 0, // External installs use different strings for extensions/apps. 81 0, // External installs use different strings for extensions/apps.
81 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING, 82 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING,
82 IDS_EXTENSION_LAUNCH_APP_PROMPT_HEADING, 83 IDS_EXTENSION_LAUNCH_APP_PROMPT_HEADING,
83 IDS_EXTENSION_REMOTE_INSTALL_PROMPT_HEADING, 84 IDS_EXTENSION_REMOTE_INSTALL_PROMPT_HEADING,
84 IDS_EXTENSION_REPAIR_PROMPT_HEADING 85 IDS_EXTENSION_REPAIR_PROMPT_HEADING,
86 IDS_EXTENSION_INSTALL_PROMPT_HEADING,
85 }; 87 };
86 static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 88 static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
87 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 89 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
88 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 90 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
89 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 91 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
90 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 92 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
91 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 93 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
92 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 94 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
93 ui::DIALOG_BUTTON_CANCEL, 95 ui::DIALOG_BUTTON_CANCEL,
94 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 96 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
95 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 97 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
96 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 98 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
99 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
97 }; 100 };
98 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 101 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
99 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 102 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
100 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 103 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
101 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 104 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
102 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, 105 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON,
103 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, 106 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON,
104 0, // External installs use different strings for extensions/apps. 107 0, // External installs use different strings for extensions/apps.
105 0, // Different strings depending on the files and devices retained. 108 0, // Different strings depending on the files and devices retained.
106 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, 109 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON,
107 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON, 110 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON,
108 IDS_EXTENSION_PROMPT_REPAIR_BUTTON, 111 IDS_EXTENSION_PROMPT_REPAIR_BUTTON,
112 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON,
109 }; 113 };
110 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 114 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
111 0, // These all use the platform's default cancel label. 115 0, // These all use the platform's default cancel label.
112 0, 116 0,
113 0, 117 0,
114 0, 118 0,
115 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, 119 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON,
116 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, 120 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON,
117 IDS_CLOSE, 121 IDS_CLOSE,
118 0, // Platform dependent cancel button. 122 0, // Platform dependent cancel button.
119 0, 123 0,
120 0, 124 0,
125 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON,
121 }; 126 };
122 static const int 127 static const int
123 kPermissionsHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 128 kPermissionsHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
124 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 129 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
125 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 130 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
126 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, 131 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO,
127 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, 132 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO,
128 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, 133 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO,
129 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 134 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
130 IDS_EXTENSION_PROMPT_CAN_ACCESS, 135 IDS_EXTENSION_PROMPT_CAN_ACCESS,
131 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 136 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
132 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 137 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
133 IDS_EXTENSION_PROMPT_CAN_ACCESS, 138 IDS_EXTENSION_PROMPT_CAN_ACCESS,
139 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
134 }; 140 };
135 141
136 // Returns bitmap for the default icon with size equal to the default icon's 142 // Returns bitmap for the default icon with size equal to the default icon's
137 // pixel size under maximal supported scale factor. 143 // pixel size under maximal supported scale factor.
138 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { 144 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
139 const gfx::ImageSkia& image = is_app ? 145 const gfx::ImageSkia& image = is_app ?
140 extensions::util::GetDefaultAppIcon() : 146 extensions::util::GetDefaultAppIcon() :
141 extensions::util::GetDefaultExtensionIcon(); 147 extensions::util::GetDefaultExtensionIcon();
142 return image.GetRepresentation( 148 return image.GetRepresentation(
143 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); 149 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 case ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT: 216 case ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT:
211 return "EXTERNAL_INSTALL_PROMPT"; 217 return "EXTERNAL_INSTALL_PROMPT";
212 case ExtensionInstallPrompt::POST_INSTALL_PERMISSIONS_PROMPT: 218 case ExtensionInstallPrompt::POST_INSTALL_PERMISSIONS_PROMPT:
213 return "POST_INSTALL_PERMISSIONS_PROMPT"; 219 return "POST_INSTALL_PERMISSIONS_PROMPT";
214 case ExtensionInstallPrompt::LAUNCH_PROMPT: 220 case ExtensionInstallPrompt::LAUNCH_PROMPT:
215 return "LAUNCH_PROMPT"; 221 return "LAUNCH_PROMPT";
216 case ExtensionInstallPrompt::REMOTE_INSTALL_PROMPT: 222 case ExtensionInstallPrompt::REMOTE_INSTALL_PROMPT:
217 return "REMOTE_INSTALL_PROMPT"; 223 return "REMOTE_INSTALL_PROMPT";
218 case ExtensionInstallPrompt::REPAIR_PROMPT: 224 case ExtensionInstallPrompt::REPAIR_PROMPT:
219 return "REPAIR_PROMPT"; 225 return "REPAIR_PROMPT";
226 case ExtensionInstallPrompt::DELEGATED_PERMISSIONS_PROMPT:
227 return "DELEGATED_PERMISSIONS_PROMPT";
220 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE: 228 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE:
221 case ExtensionInstallPrompt::NUM_PROMPT_TYPES: 229 case ExtensionInstallPrompt::NUM_PROMPT_TYPES:
222 break; 230 break;
223 } 231 }
224 return "OTHER"; 232 return "OTHER";
225 } 233 }
226 234
227 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) 235 ExtensionInstallPrompt::Prompt::Prompt(PromptType type)
228 : type_(type), 236 : type_(type),
229 is_showing_details_for_retained_files_(false), 237 is_showing_details_for_retained_files_(false),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } else if (type_ == REMOTE_INSTALL_PROMPT) { 332 } else if (type_ == REMOTE_INSTALL_PROMPT) {
325 if (extension_->is_app()) 333 if (extension_->is_app())
326 resource_id = IDS_EXTENSION_REMOTE_INSTALL_APP_PROMPT_TITLE; 334 resource_id = IDS_EXTENSION_REMOTE_INSTALL_APP_PROMPT_TITLE;
327 else 335 else
328 resource_id = IDS_EXTENSION_REMOTE_INSTALL_EXTENSION_PROMPT_TITLE; 336 resource_id = IDS_EXTENSION_REMOTE_INSTALL_EXTENSION_PROMPT_TITLE;
329 } else if (type_ == REPAIR_PROMPT) { 337 } else if (type_ == REPAIR_PROMPT) {
330 if (extension_->is_app()) 338 if (extension_->is_app())
331 resource_id = IDS_EXTENSION_REPAIR_APP_PROMPT_TITLE; 339 resource_id = IDS_EXTENSION_REPAIR_APP_PROMPT_TITLE;
332 else 340 else
333 resource_id = IDS_EXTENSION_REPAIR_EXTENSION_PROMPT_TITLE; 341 resource_id = IDS_EXTENSION_REPAIR_EXTENSION_PROMPT_TITLE;
342 } else if (type_ == DELEGATED_PERMISSIONS_PROMPT) {
343 DCHECK(!delegated_username_.empty());
344 if (extension_->is_app())
345 resource_id = IDS_EXTENSION_DELEGATED_INSTALL_APP_PROMPT_TITLE;
346 else
347 resource_id = IDS_EXTENSION_DELEGATED_INSTALL_EXTENSION_PROMPT_TITLE;
348 return l10n_util::GetStringFUTF16(
349 resource_id, base::UTF8ToUTF16(delegated_username_));
334 } 350 }
335 351
336 return l10n_util::GetStringUTF16(resource_id); 352 return l10n_util::GetStringUTF16(resource_id);
337 } 353 }
338 354
339 base::string16 ExtensionInstallPrompt::Prompt::GetHeading() const { 355 base::string16 ExtensionInstallPrompt::Prompt::GetHeading() const {
340 if (type_ == INLINE_INSTALL_PROMPT) { 356 if (type_ == INLINE_INSTALL_PROMPT) {
341 return base::UTF8ToUTF16(extension_->name()); 357 return base::UTF8ToUTF16(extension_->name());
342 } else if (type_ == BUNDLE_INSTALL_PROMPT) { 358 } else if (type_ == BUNDLE_INSTALL_PROMPT) {
343 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING); 359 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING);
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 if (extension->from_webstore() || 761 if (extension->from_webstore() ||
746 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { 762 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) {
747 delegate->InstallUIProceed(); 763 delegate->InstallUIProceed();
748 return; 764 return;
749 } 765 }
750 } 766 }
751 767
752 LoadImageIfNeeded(); 768 LoadImageIfNeeded();
753 } 769 }
754 770
771 void ExtensionInstallPrompt::ConfirmPermissionsForDelegatedInstall(
772 Delegate* delegate,
773 const Extension* extension,
774 const std::string& delegated_username,
775 const SkBitmap* icon) {
776 DCHECK(ui_loop_ == base::MessageLoop::current());
777 delegate_ = delegate;
778 extension_ = extension;
779 delegated_username_ = delegated_username;
780 SetIcon(icon);
781 prompt_ = new Prompt(DELEGATED_PERMISSIONS_PROMPT);
782 ShowConfirmation();
783 }
784
755 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, 785 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate,
756 const Extension* extension) { 786 const Extension* extension) {
757 DCHECK(ui_loop_ == base::MessageLoop::current()); 787 DCHECK(ui_loop_ == base::MessageLoop::current());
758 extension_ = extension; 788 extension_ = extension;
759 delegate_ = delegate; 789 delegate_ = delegate;
760 bool is_remote_install = 790 bool is_remote_install =
761 profile_ && 791 profile_ &&
762 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason( 792 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason(
763 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); 793 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL);
764 bool is_ephemeral = 794 bool is_ephemeral =
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 955
926 switch (prompt_->type()) { 956 switch (prompt_->type()) {
927 case PERMISSIONS_PROMPT: 957 case PERMISSIONS_PROMPT:
928 case RE_ENABLE_PROMPT: 958 case RE_ENABLE_PROMPT:
929 case INLINE_INSTALL_PROMPT: 959 case INLINE_INSTALL_PROMPT:
930 case EXTERNAL_INSTALL_PROMPT: 960 case EXTERNAL_INSTALL_PROMPT:
931 case INSTALL_PROMPT: 961 case INSTALL_PROMPT:
932 case LAUNCH_PROMPT: 962 case LAUNCH_PROMPT:
933 case POST_INSTALL_PERMISSIONS_PROMPT: 963 case POST_INSTALL_PERMISSIONS_PROMPT:
934 case REMOTE_INSTALL_PROMPT: 964 case REMOTE_INSTALL_PROMPT:
935 case REPAIR_PROMPT: { 965 case REPAIR_PROMPT:
966 case DELEGATED_PERMISSIONS_PROMPT: {
936 prompt_->set_extension(extension_); 967 prompt_->set_extension(extension_);
937 prompt_->set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); 968 prompt_->set_icon(gfx::Image::CreateFrom1xBitmap(icon_));
969 prompt_->set_delegated_username(delegated_username_);
938 break; 970 break;
939 } 971 }
940 case BUNDLE_INSTALL_PROMPT: { 972 case BUNDLE_INSTALL_PROMPT: {
941 prompt_->set_bundle(bundle_); 973 prompt_->set_bundle(bundle_);
942 break; 974 break;
943 } 975 }
944 default: 976 default:
945 NOTREACHED() << "Unknown message"; 977 NOTREACHED() << "Unknown message";
946 return; 978 return;
947 } 979 }
948 980
949 g_last_prompt_type_for_tests = prompt_->type(); 981 g_last_prompt_type_for_tests = prompt_->type();
950 982
951 if (AutoConfirmPrompt(delegate_)) 983 if (AutoConfirmPrompt(delegate_))
952 return; 984 return;
953 985
954 if (show_params_->WasParentDestroyed()) { 986 if (show_params_->WasParentDestroyed()) {
955 delegate_->InstallUIAbort(false); 987 delegate_->InstallUIAbort(false);
956 return; 988 return;
957 } 989 }
958 990
959 if (show_dialog_callback_.is_null()) 991 if (show_dialog_callback_.is_null())
960 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); 992 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_);
961 else 993 else
962 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); 994 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_);
963 } 995 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698