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

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: Created 8 years, 6 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 96 }
95 97
96 ExtensionInstallPrompt::Prompt::~Prompt() { 98 ExtensionInstallPrompt::Prompt::~Prompt() {
97 } 99 }
98 100
99 void ExtensionInstallPrompt::Prompt::SetPermissions( 101 void ExtensionInstallPrompt::Prompt::SetPermissions(
100 const std::vector<string16>& permissions) { 102 const std::vector<string16>& permissions) {
101 permissions_ = permissions; 103 permissions_ = permissions;
102 } 104 }
103 105
106 void ExtensionInstallPrompt::Prompt::SetOAuthIssues(
107 const IssueAdviceInfo& issues) {
108 oauth_issues_ = issues;
109 }
110
104 void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData( 111 void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData(
105 const std::string& localized_user_count, 112 const std::string& localized_user_count,
106 double average_rating, 113 double average_rating,
107 int rating_count) { 114 int rating_count) {
108 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); 115 CHECK_EQ(INLINE_INSTALL_PROMPT, type_);
109 localized_user_count_ = localized_user_count; 116 localized_user_count_ = localized_user_count;
110 average_rating_ = average_rating; 117 average_rating_ = average_rating;
111 rating_count_ = rating_count; 118 rating_count_ = rating_count;
112 } 119 }
113 120
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { 208 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const {
202 return permissions_.size(); 209 return permissions_.size();
203 } 210 }
204 211
205 string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) const { 212 string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) const {
206 CHECK_LT(index, permissions_.size()); 213 CHECK_LT(index, permissions_.size());
207 return l10n_util::GetStringFUTF16( 214 return l10n_util::GetStringFUTF16(
208 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]); 215 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]);
209 } 216 }
210 217
218 size_t ExtensionInstallPrompt::Prompt::GetOAuthIssueCount() const {
219 return oauth_issues_.size();
220 }
221
222 const IssueAdviceInfoEntry& ExtensionInstallPrompt::Prompt::GetOAuthIssue(
223 size_t index) const {
224 CHECK_LT(index, oauth_issues_.size());
225 return oauth_issues_[index];
226 }
227
211 // static 228 // static
212 scoped_refptr<Extension> 229 scoped_refptr<Extension>
213 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( 230 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay(
214 const DictionaryValue* manifest, 231 const DictionaryValue* manifest,
215 const std::string& id, 232 const std::string& id,
216 const std::string& localized_name, 233 const std::string& localized_name,
217 const std::string& localized_description, 234 const std::string& localized_description,
218 std::string* error) { 235 std::string* error) {
219 scoped_ptr<DictionaryValue> localized_manifest; 236 scoped_ptr<DictionaryValue> localized_manifest;
220 if (!localized_name.empty() || !localized_description.empty()) { 237 if (!localized_name.empty() || !localized_description.empty()) {
(...skipping 18 matching lines...) Expand all
239 } 256 }
240 257
241 ExtensionInstallPrompt::ExtensionInstallPrompt(Browser* browser) 258 ExtensionInstallPrompt::ExtensionInstallPrompt(Browser* browser)
242 : browser_(browser), 259 : browser_(browser),
243 ui_loop_(MessageLoop::current()), 260 ui_loop_(MessageLoop::current()),
244 extension_(NULL), 261 extension_(NULL),
245 install_ui_(ExtensionInstallUI::Create(browser)), 262 install_ui_(ExtensionInstallUI::Create(browser)),
246 delegate_(NULL), 263 delegate_(NULL),
247 prompt_(UNSET_PROMPT_TYPE), 264 prompt_(UNSET_PROMPT_TYPE),
248 prompt_type_(UNSET_PROMPT_TYPE), 265 prompt_type_(UNSET_PROMPT_TYPE),
266 record_oauth2_grant_(false),
249 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { 267 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
250 } 268 }
251 269
252 ExtensionInstallPrompt::~ExtensionInstallPrompt() { 270 ExtensionInstallPrompt::~ExtensionInstallPrompt() {
253 } 271 }
254 272
255 void ExtensionInstallPrompt::ConfirmBundleInstall( 273 void ExtensionInstallPrompt::ConfirmBundleInstall(
256 extensions::BundleInstaller* bundle, 274 extensions::BundleInstaller* bundle,
257 const ExtensionPermissionSet* permissions) { 275 const ExtensionPermissionSet* permissions) {
258 DCHECK(ui_loop_ == MessageLoop::current()); 276 DCHECK(ui_loop_ == MessageLoop::current());
259 bundle_ = bundle; 277 bundle_ = bundle;
260 permissions_ = permissions; 278 permissions_ = permissions;
261 delegate_ = bundle; 279 delegate_ = bundle;
262 prompt_type_ = BUNDLE_INSTALL_PROMPT; 280 prompt_type_ = BUNDLE_INSTALL_PROMPT;
263 281
264 ShowConfirmation(); 282 FetchOAuthIssuesIfNeeded();
265 } 283 }
266 284
267 void ExtensionInstallPrompt::ConfirmInlineInstall( 285 void ExtensionInstallPrompt::ConfirmInlineInstall(
268 Delegate* delegate, 286 Delegate* delegate,
269 const Extension* extension, 287 const Extension* extension,
270 SkBitmap* icon, 288 SkBitmap* icon,
271 const ExtensionInstallPrompt::Prompt& prompt) { 289 const ExtensionInstallPrompt::Prompt& prompt) {
272 DCHECK(ui_loop_ == MessageLoop::current()); 290 DCHECK(ui_loop_ == MessageLoop::current());
273 extension_ = extension; 291 extension_ = extension;
274 permissions_ = extension->GetActivePermissions(); 292 permissions_ = extension->GetActivePermissions();
275 delegate_ = delegate; 293 delegate_ = delegate;
276 prompt_ = prompt; 294 prompt_ = prompt;
277 prompt_type_ = INLINE_INSTALL_PROMPT; 295 prompt_type_ = INLINE_INSTALL_PROMPT;
278 296
279 SetIcon(icon); 297 SetIcon(icon);
280 ShowConfirmation(); 298 FetchOAuthIssuesIfNeeded();
281 } 299 }
282 300
283 void ExtensionInstallPrompt::ConfirmWebstoreInstall(Delegate* delegate, 301 void ExtensionInstallPrompt::ConfirmWebstoreInstall(Delegate* delegate,
284 const Extension* extension, 302 const Extension* extension,
285 const SkBitmap* icon) { 303 const SkBitmap* icon) {
286 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the 304 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
287 // remaining fields. 305 // remaining fields.
288 extension_ = extension; 306 extension_ = extension;
289 SetIcon(icon); 307 SetIcon(icon);
290 ConfirmInstall(delegate, extension); 308 ConfirmInstall(delegate, extension);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 else 376 else
359 icon_ = SkBitmap(); 377 icon_ = SkBitmap();
360 if (icon_.empty()) 378 if (icon_.empty())
361 icon_ = Extension::GetDefaultIcon(extension_->is_app()); 379 icon_ = Extension::GetDefaultIcon(extension_->is_app());
362 } 380 }
363 381
364 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, 382 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image,
365 const std::string& extension_id, 383 const std::string& extension_id,
366 int index) { 384 int index) {
367 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); 385 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap());
368 ShowConfirmation(); 386 FetchOAuthIssuesIfNeeded();
369 } 387 }
370 388
371 void ExtensionInstallPrompt::LoadImageIfNeeded() { 389 void ExtensionInstallPrompt::LoadImageIfNeeded() {
372 // Bundle install prompts do not have an icon. 390 // Bundle install prompts do not have an icon.
373 if (!icon_.empty()) { 391 if (!icon_.empty()) {
374 ShowConfirmation(); 392 FetchOAuthIssuesIfNeeded();
375 return; 393 return;
376 } 394 }
377 395
378 // Load the image asynchronously. For the response, check OnImageLoaded. 396 // Load the image asynchronously. For the response, check OnImageLoaded.
379 ExtensionResource image = 397 ExtensionResource image =
380 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, 398 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE,
381 ExtensionIconSet::MATCH_BIGGER); 399 ExtensionIconSet::MATCH_BIGGER);
382 tracker_.LoadImage(extension_, image, 400 tracker_.LoadImage(extension_, image,
383 gfx::Size(kIconSize, kIconSize), 401 gfx::Size(kIconSize, kIconSize),
384 ImageLoadingTracker::DONT_CACHE); 402 ImageLoadingTracker::DONT_CACHE);
385 } 403 }
386 404
405 void ExtensionInstallPrompt::FetchOAuthIssuesIfNeeded() {
406 #if !defined(TOOLKIT_GTK)
407 // TODO(estade): Displaying the OAuth issues is not yet implemented except
408 // on desktop linux.
409 ShowConfirmation();
410 return;
411 #else
412 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info();
413 if (oauth2_info.client_id.empty() ||
414 permissions_->scopes().empty() ||
415 prompt_type_ == BUNDLE_INSTALL_PROMPT) {
416 ShowConfirmation();
417 return;
418 }
419
420 Profile* profile = install_ui_->browser()->profile();
421 TokenService* token_service = TokenServiceFactory::GetForProfile(profile);
422 std::vector<std::string> scopes;
423 scopes.assign(permissions_->scopes().begin(), permissions_->scopes().end());
424
425 token_flow_ = new OAuth2MintTokenFlow(
426 profile->GetRequestContext(),
427 this,
428 OAuth2MintTokenFlow::Parameters(
429 token_service->GetOAuth2LoginRefreshToken(),
430 extension_->id(),
431 oauth2_info.client_id,
432 scopes,
433 OAuth2MintTokenFlow::MODE_ISSUE_ADVICE));
434 token_flow_->Start();
435 #endif
436 }
437
438 void ExtensionInstallPrompt::OnIssueAdviceSuccess(
439 const IssueAdviceInfo& advice_info) {
440 prompt_.SetOAuthIssues(advice_info);
441 record_oauth2_grant_ = true;
442 ShowConfirmation();
443 }
444
445 void ExtensionInstallPrompt::OnMintTokenFailure(
446 const GoogleServiceAuthError& error) {
447 ShowConfirmation();
448 }
449
387 void ExtensionInstallPrompt::ShowConfirmation() { 450 void ExtensionInstallPrompt::ShowConfirmation() {
451 prompt_.SetPermissions(permissions_->GetWarningMessages());
388 prompt_.set_type(prompt_type_); 452 prompt_.set_type(prompt_type_);
389 prompt_.SetPermissions(permissions_->GetWarningMessages());
390 453
391 switch (prompt_type_) { 454 switch (prompt_type_) {
392 case PERMISSIONS_PROMPT: 455 case PERMISSIONS_PROMPT:
393 case RE_ENABLE_PROMPT: 456 case RE_ENABLE_PROMPT:
394 case INLINE_INSTALL_PROMPT: 457 case INLINE_INSTALL_PROMPT:
395 case INSTALL_PROMPT: { 458 case INSTALL_PROMPT: {
396 prompt_.set_extension(extension_); 459 prompt_.set_extension(extension_);
397 prompt_.set_icon(gfx::Image(icon_)); 460 prompt_.set_icon(gfx::Image(icon_));
398 ShowExtensionInstallDialog(browser_, delegate_, prompt_); 461 ShowExtensionInstallDialog(browser_, delegate_, prompt_);
399 break; 462 break;
400 } 463 }
401 case BUNDLE_INSTALL_PROMPT: { 464 case BUNDLE_INSTALL_PROMPT: {
402 prompt_.set_bundle(bundle_); 465 prompt_.set_bundle(bundle_);
403 ShowExtensionInstallDialog(browser_, delegate_, prompt_); 466 ShowExtensionInstallDialog(browser_, delegate_, prompt_);
404 break; 467 break;
405 } 468 }
406 default: 469 default:
407 NOTREACHED() << "Unknown message"; 470 NOTREACHED() << "Unknown message";
408 break; 471 break;
409 } 472 }
410 } 473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698