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

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

Issue 10630021: Modify experimental identity flow to display scope descriptions and details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 5 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 | Annotate | Revision Log
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/file_util.h" 10 #include "base/file_util.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/extensions/bundle_installer.h" 16 #include "chrome/browser/extensions/bundle_installer.h"
17 #include "chrome/browser/extensions/extension_install_dialog.h" 17 #include "chrome/browser/extensions/extension_install_dialog.h"
18 #include "chrome/browser/extensions/extension_install_ui.h" 18 #include "chrome/browser/extensions/extension_install_ui.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/signin/token_service.h"
21 #include "chrome/browser/signin/token_service_factory.h"
20 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_navigator.h" 23 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents.h"
23 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/extensions/extension.h" 26 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/extensions/extension_icon_set.h" 27 #include "chrome/common/extensions/extension_icon_set.h"
26 #include "chrome/common/extensions/extension_manifest_constants.h" 28 #include "chrome/common/extensions/extension_manifest_constants.h"
27 #include "chrome/common/extensions/extension_resource.h" 29 #include "chrome/common/extensions/extension_resource.h"
28 #include "chrome/common/extensions/extension_switch_utils.h" 30 #include "chrome/common/extensions/extension_switch_utils.h"
29 #include "chrome/common/extensions/url_pattern.h" 31 #include "chrome/common/extensions/url_pattern.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 97 }
96 98
97 ExtensionInstallPrompt::Prompt::~Prompt() { 99 ExtensionInstallPrompt::Prompt::~Prompt() {
98 } 100 }
99 101
100 void ExtensionInstallPrompt::Prompt::SetPermissions( 102 void ExtensionInstallPrompt::Prompt::SetPermissions(
101 const std::vector<string16>& permissions) { 103 const std::vector<string16>& permissions) {
102 permissions_ = permissions; 104 permissions_ = permissions;
103 } 105 }
104 106
107 void ExtensionInstallPrompt::Prompt::SetOAuthIssueAdvice(
108 const IssueAdviceInfo& issue_advice) {
109 oauth_issue_advice_ = issue_advice;
110 }
111
105 void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData( 112 void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData(
106 const std::string& localized_user_count, 113 const std::string& localized_user_count,
107 double average_rating, 114 double average_rating,
108 int rating_count) { 115 int rating_count) {
109 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); 116 CHECK_EQ(INLINE_INSTALL_PROMPT, type_);
110 localized_user_count_ = localized_user_count; 117 localized_user_count_ = localized_user_count;
111 average_rating_ = average_rating; 118 average_rating_ = average_rating;
112 rating_count_ = rating_count; 119 rating_count_ = rating_count;
113 } 120 }
114 121
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { 209 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const {
203 return permissions_.size(); 210 return permissions_.size();
204 } 211 }
205 212
206 string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) const { 213 string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) const {
207 CHECK_LT(index, permissions_.size()); 214 CHECK_LT(index, permissions_.size());
208 return l10n_util::GetStringFUTF16( 215 return l10n_util::GetStringFUTF16(
209 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]); 216 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]);
210 } 217 }
211 218
219 size_t ExtensionInstallPrompt::Prompt::GetOAuthIssueCount() const {
220 return oauth_issue_advice_.size();
221 }
222
223 const IssueAdviceInfoEntry& ExtensionInstallPrompt::Prompt::GetOAuthIssue(
224 size_t index) const {
225 CHECK_LT(index, oauth_issue_advice_.size());
226 return oauth_issue_advice_[index];
227 }
228
212 // static 229 // static
213 scoped_refptr<Extension> 230 scoped_refptr<Extension>
214 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( 231 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay(
215 const DictionaryValue* manifest, 232 const DictionaryValue* manifest,
216 const std::string& id, 233 const std::string& id,
217 const std::string& localized_name, 234 const std::string& localized_name,
218 const std::string& localized_description, 235 const std::string& localized_description,
219 std::string* error) { 236 std::string* error) {
220 scoped_ptr<DictionaryValue> localized_manifest; 237 scoped_ptr<DictionaryValue> localized_manifest;
221 if (!localized_name.empty() || !localized_description.empty()) { 238 if (!localized_name.empty() || !localized_description.empty()) {
(...skipping 11 matching lines...) Expand all
233 return Extension::Create( 250 return Extension::Create(
234 FilePath(), 251 FilePath(),
235 Extension::INTERNAL, 252 Extension::INTERNAL,
236 localized_manifest.get() ? *localized_manifest.get() : *manifest, 253 localized_manifest.get() ? *localized_manifest.get() : *manifest,
237 Extension::NO_FLAGS, 254 Extension::NO_FLAGS,
238 id, 255 id,
239 error); 256 error);
240 } 257 }
241 258
242 ExtensionInstallPrompt::ExtensionInstallPrompt(Browser* browser) 259 ExtensionInstallPrompt::ExtensionInstallPrompt(Browser* browser)
243 : browser_(browser), 260 : record_oauth2_grant_(ShouldAutomaticallyApproveScopes()),
261 browser_(browser),
244 ui_loop_(MessageLoop::current()), 262 ui_loop_(MessageLoop::current()),
245 extension_(NULL), 263 extension_(NULL),
246 install_ui_(ExtensionInstallUI::Create(browser)), 264 install_ui_(ExtensionInstallUI::Create(browser)),
247 delegate_(NULL), 265 delegate_(NULL),
248 prompt_(UNSET_PROMPT_TYPE), 266 prompt_(UNSET_PROMPT_TYPE),
249 prompt_type_(UNSET_PROMPT_TYPE), 267 prompt_type_(UNSET_PROMPT_TYPE),
250 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { 268 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
251 } 269 }
252 270
253 ExtensionInstallPrompt::~ExtensionInstallPrompt() { 271 ExtensionInstallPrompt::~ExtensionInstallPrompt() {
254 } 272 }
255 273
256 void ExtensionInstallPrompt::ConfirmBundleInstall( 274 void ExtensionInstallPrompt::ConfirmBundleInstall(
257 extensions::BundleInstaller* bundle, 275 extensions::BundleInstaller* bundle,
258 const PermissionSet* permissions) { 276 const PermissionSet* permissions) {
259 DCHECK(ui_loop_ == MessageLoop::current()); 277 DCHECK(ui_loop_ == MessageLoop::current());
260 bundle_ = bundle; 278 bundle_ = bundle;
261 permissions_ = permissions; 279 permissions_ = permissions;
262 delegate_ = bundle; 280 delegate_ = bundle;
263 prompt_type_ = BUNDLE_INSTALL_PROMPT; 281 prompt_type_ = BUNDLE_INSTALL_PROMPT;
264 282
265 ShowConfirmation(); 283 FetchOAuthIssueAdviceIfNeeded();
266 } 284 }
267 285
268 void ExtensionInstallPrompt::ConfirmInlineInstall( 286 void ExtensionInstallPrompt::ConfirmInlineInstall(
269 Delegate* delegate, 287 Delegate* delegate,
270 const Extension* extension, 288 const Extension* extension,
271 SkBitmap* icon, 289 SkBitmap* icon,
272 const ExtensionInstallPrompt::Prompt& prompt) { 290 const ExtensionInstallPrompt::Prompt& prompt) {
273 DCHECK(ui_loop_ == MessageLoop::current()); 291 DCHECK(ui_loop_ == MessageLoop::current());
274 extension_ = extension; 292 extension_ = extension;
275 permissions_ = extension->GetActivePermissions(); 293 permissions_ = extension->GetActivePermissions();
276 delegate_ = delegate; 294 delegate_ = delegate;
277 prompt_ = prompt; 295 prompt_ = prompt;
278 prompt_type_ = INLINE_INSTALL_PROMPT; 296 prompt_type_ = INLINE_INSTALL_PROMPT;
279 297
280 SetIcon(icon); 298 SetIcon(icon);
281 ShowConfirmation(); 299 FetchOAuthIssueAdviceIfNeeded();
282 } 300 }
283 301
284 void ExtensionInstallPrompt::ConfirmWebstoreInstall(Delegate* delegate, 302 void ExtensionInstallPrompt::ConfirmWebstoreInstall(Delegate* delegate,
285 const Extension* extension, 303 const Extension* extension,
286 const SkBitmap* icon) { 304 const SkBitmap* icon) {
287 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the 305 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
288 // remaining fields. 306 // remaining fields.
289 extension_ = extension; 307 extension_ = extension;
290 SetIcon(icon); 308 SetIcon(icon);
291 ConfirmInstall(delegate, extension); 309 ConfirmInstall(delegate, extension);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 else 377 else
360 icon_ = SkBitmap(); 378 icon_ = SkBitmap();
361 if (icon_.empty()) 379 if (icon_.empty())
362 icon_ = Extension::GetDefaultIcon(extension_->is_app()); 380 icon_ = Extension::GetDefaultIcon(extension_->is_app());
363 } 381 }
364 382
365 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, 383 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image,
366 const std::string& extension_id, 384 const std::string& extension_id,
367 int index) { 385 int index) {
368 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); 386 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap());
369 ShowConfirmation(); 387 FetchOAuthIssueAdviceIfNeeded();
370 } 388 }
371 389
372 void ExtensionInstallPrompt::LoadImageIfNeeded() { 390 void ExtensionInstallPrompt::LoadImageIfNeeded() {
373 // Bundle install prompts do not have an icon. 391 // Bundle install prompts do not have an icon.
374 if (!icon_.empty()) { 392 if (!icon_.empty()) {
375 ShowConfirmation(); 393 FetchOAuthIssueAdviceIfNeeded();
376 return; 394 return;
377 } 395 }
378 396
379 // Load the image asynchronously. For the response, check OnImageLoaded. 397 // Load the image asynchronously. For the response, check OnImageLoaded.
380 ExtensionResource image = 398 ExtensionResource image =
381 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, 399 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE,
382 ExtensionIconSet::MATCH_BIGGER); 400 ExtensionIconSet::MATCH_BIGGER);
383 tracker_.LoadImage(extension_, image, 401 tracker_.LoadImage(extension_, image,
384 gfx::Size(kIconSize, kIconSize), 402 gfx::Size(kIconSize, kIconSize),
385 ImageLoadingTracker::DONT_CACHE); 403 ImageLoadingTracker::DONT_CACHE);
386 } 404 }
387 405
406 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() {
407 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info();
408 if (ShouldAutomaticallyApproveScopes() ||
409 oauth2_info.client_id.empty() ||
410 permissions_->scopes().empty() ||
411 prompt_type_ == BUNDLE_INSTALL_PROMPT ||
412 prompt_type_ == INLINE_INSTALL_PROMPT) {
413 ShowConfirmation();
414 return;
415 }
416
417 Profile* profile = install_ui_->browser()->profile();
418 TokenService* token_service = TokenServiceFactory::GetForProfile(profile);
419 std::vector<std::string> scopes;
420 scopes.assign(permissions_->scopes().begin(), permissions_->scopes().end());
421
422 token_flow_.reset(new OAuth2MintTokenFlow(
423 profile->GetRequestContext(),
424 this,
425 OAuth2MintTokenFlow::Parameters(
426 token_service->GetOAuth2LoginRefreshToken(),
427 extension_->id(),
428 oauth2_info.client_id,
429 scopes,
430 OAuth2MintTokenFlow::MODE_ISSUE_ADVICE)));
431 token_flow_->Start();
432 }
433
434 void ExtensionInstallPrompt::OnIssueAdviceSuccess(
435 const IssueAdviceInfo& advice_info) {
436 prompt_.SetOAuthIssueAdvice(advice_info);
437 record_oauth2_grant_ = true;
438 ShowConfirmation();
439 }
440
441 void ExtensionInstallPrompt::OnMintTokenFailure(
442 const GoogleServiceAuthError& error) {
443 ShowConfirmation();
444 }
445
388 void ExtensionInstallPrompt::ShowConfirmation() { 446 void ExtensionInstallPrompt::ShowConfirmation() {
389 prompt_.set_type(prompt_type_); 447 prompt_.set_type(prompt_type_);
390 prompt_.SetPermissions(permissions_->GetWarningMessages()); 448 prompt_.SetPermissions(permissions_->GetWarningMessages());
391 449
392 switch (prompt_type_) { 450 switch (prompt_type_) {
393 case PERMISSIONS_PROMPT: 451 case PERMISSIONS_PROMPT:
394 case RE_ENABLE_PROMPT: 452 case RE_ENABLE_PROMPT:
395 case INLINE_INSTALL_PROMPT: 453 case INLINE_INSTALL_PROMPT:
396 case INSTALL_PROMPT: { 454 case INSTALL_PROMPT: {
397 prompt_.set_extension(extension_); 455 prompt_.set_extension(extension_);
398 prompt_.set_icon(gfx::Image(icon_)); 456 prompt_.set_icon(gfx::Image(icon_));
399 ShowExtensionInstallDialog(browser_, delegate_, prompt_); 457 ShowExtensionInstallDialog(browser_, delegate_, prompt_);
400 break; 458 break;
401 } 459 }
402 case BUNDLE_INSTALL_PROMPT: { 460 case BUNDLE_INSTALL_PROMPT: {
403 prompt_.set_bundle(bundle_); 461 prompt_.set_bundle(bundle_);
404 ShowExtensionInstallDialog(browser_, delegate_, prompt_); 462 ShowExtensionInstallDialog(browser_, delegate_, prompt_);
405 break; 463 break;
406 } 464 }
407 default: 465 default:
408 NOTREACHED() << "Unknown message"; 466 NOTREACHED() << "Unknown message";
409 break; 467 break;
410 } 468 }
411 } 469 }
470
471 // static
472 bool ExtensionInstallPrompt::ShouldAutomaticallyApproveScopes() {
473 return !CommandLine::ForCurrentProcess()->HasSwitch(
474 switches::kDemandUserScopeApproval);
475 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_prompt.h ('k') | chrome/browser/extensions/extension_install_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698