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

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

Issue 23978007: Identity API: prevent install time OAuth prompts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
« no previous file with comments | « chrome/browser/extensions/extension_install_prompt.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, 105 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO,
106 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 106 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
107 IDS_EXTENSION_PROMPT_CAN_ACCESS, 107 IDS_EXTENSION_PROMPT_CAN_ACCESS,
108 }; 108 };
109 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 109 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
110 IDS_EXTENSION_PROMPT_OAUTH_HEADER, 110 IDS_EXTENSION_PROMPT_OAUTH_HEADER,
111 0, // Inline installs don't show OAuth permissions. 111 0, // Inline installs don't show OAuth permissions.
112 0, // Bundle installs don't show OAuth permissions. 112 0, // Bundle installs don't show OAuth permissions.
113 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, 113 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER,
114 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, 114 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER,
115 // TODO(mpcomplete): Do we need this for external install UI? If we do,
116 // we need to update FetchOAuthIssueAdviceIfNeeded.
117 0, 115 0,
118 0, 116 0,
119 }; 117 };
120 118
121 // Size of extension icon in top left of dialog. 119 // Size of extension icon in top left of dialog.
122 const int kIconSize = 69; 120 const int kIconSize = 69;
123 121
124 // Returns pixel size under maximal scale factor for the icon whose device 122 // Returns pixel size under maximal scale factor for the icon whose device
125 // independent size is |size_in_dip| 123 // independent size is |size_in_dip|
126 int GetSizeForMaxScaleFactor(int size_in_dip) { 124 int GetSizeForMaxScaleFactor(int size_in_dip) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 544
547 void ExtensionInstallPrompt::ConfirmBundleInstall( 545 void ExtensionInstallPrompt::ConfirmBundleInstall(
548 extensions::BundleInstaller* bundle, 546 extensions::BundleInstaller* bundle,
549 const PermissionSet* permissions) { 547 const PermissionSet* permissions) {
550 DCHECK(ui_loop_ == base::MessageLoop::current()); 548 DCHECK(ui_loop_ == base::MessageLoop::current());
551 bundle_ = bundle; 549 bundle_ = bundle;
552 permissions_ = permissions; 550 permissions_ = permissions;
553 delegate_ = bundle; 551 delegate_ = bundle;
554 prompt_.set_type(BUNDLE_INSTALL_PROMPT); 552 prompt_.set_type(BUNDLE_INSTALL_PROMPT);
555 553
556 FetchOAuthIssueAdviceIfNeeded(); 554 ShowConfirmation();
557 } 555 }
558 556
559 void ExtensionInstallPrompt::ConfirmStandaloneInstall( 557 void ExtensionInstallPrompt::ConfirmStandaloneInstall(
560 Delegate* delegate, 558 Delegate* delegate,
561 const Extension* extension, 559 const Extension* extension,
562 SkBitmap* icon, 560 SkBitmap* icon,
563 const ExtensionInstallPrompt::Prompt& prompt) { 561 const ExtensionInstallPrompt::Prompt& prompt) {
564 DCHECK(ui_loop_ == base::MessageLoop::current()); 562 DCHECK(ui_loop_ == base::MessageLoop::current());
565 extension_ = extension; 563 extension_ = extension;
566 permissions_ = extension->GetActivePermissions(); 564 permissions_ = extension->GetActivePermissions();
567 delegate_ = delegate; 565 delegate_ = delegate;
568 prompt_ = prompt; 566 prompt_ = prompt;
569 567
570 SetIcon(icon); 568 SetIcon(icon);
571 FetchOAuthIssueAdviceIfNeeded(); 569 ShowConfirmation();
572 } 570 }
573 571
574 void ExtensionInstallPrompt::ConfirmWebstoreInstall( 572 void ExtensionInstallPrompt::ConfirmWebstoreInstall(
575 Delegate* delegate, 573 Delegate* delegate,
576 const Extension* extension, 574 const Extension* extension,
577 const SkBitmap* icon, 575 const SkBitmap* icon,
578 const ShowDialogCallback& show_dialog_callback) { 576 const ShowDialogCallback& show_dialog_callback) {
579 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the 577 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
580 // remaining fields. 578 // remaining fields.
581 extension_ = extension; 579 extension_ = extension;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 if (icon_.empty()) { 698 if (icon_.empty()) {
701 // Let's set default icon bitmap whose size is equal to the default icon's 699 // Let's set default icon bitmap whose size is equal to the default icon's
702 // pixel size under maximal supported scale factor. If the bitmap is larger 700 // pixel size under maximal supported scale factor. If the bitmap is larger
703 // than the one we need, it will be scaled down by the ui code. 701 // than the one we need, it will be scaled down by the ui code.
704 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); 702 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
705 } 703 }
706 } 704 }
707 705
708 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { 706 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) {
709 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); 707 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap());
710 FetchOAuthIssueAdviceIfNeeded(); 708 ShowConfirmation();
711 } 709 }
712 710
713 void ExtensionInstallPrompt::LoadImageIfNeeded() { 711 void ExtensionInstallPrompt::LoadImageIfNeeded() {
714 // Bundle install prompts do not have an icon. 712 // Bundle install prompts do not have an icon.
715 // Also |install_ui_.profile()| can be NULL in unit tests. 713 // Also |install_ui_.profile()| can be NULL in unit tests.
716 if (!icon_.empty() || !install_ui_->profile()) { 714 if (!icon_.empty() || !install_ui_->profile()) {
717 FetchOAuthIssueAdviceIfNeeded(); 715 ShowConfirmation();
718 return; 716 return;
719 } 717 }
720 718
721 // Load the image asynchronously. For the response, check OnImageLoaded. 719 // Load the image asynchronously. For the response, check OnImageLoaded.
722 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( 720 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource(
723 extension_, 721 extension_,
724 extension_misc::EXTENSION_ICON_LARGE, 722 extension_misc::EXTENSION_ICON_LARGE,
725 ExtensionIconSet::MATCH_BIGGER); 723 ExtensionIconSet::MATCH_BIGGER);
726 // Load the icon whose pixel size is large enough to be displayed under 724 // Load the icon whose pixel size is large enough to be displayed under
727 // maximal supported scale factor. UI code will scale the icon down if needed. 725 // maximal supported scale factor. UI code will scale the icon down if needed.
728 // TODO(tbarzic): We should use IconImage here and load the required bitmap 726 // TODO(tbarzic): We should use IconImage here and load the required bitmap
729 // lazily. 727 // lazily.
730 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); 728 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
731 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync( 729 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync(
732 extension_, image, gfx::Size(pixel_size, pixel_size), 730 extension_, image, gfx::Size(pixel_size, pixel_size),
733 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); 731 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr()));
734 } 732 }
735 733
736 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() {
737 // |extension_| may be NULL, e.g. in the bundle install case.
738 if (!extension_ ||
739 prompt_.type() == BUNDLE_INSTALL_PROMPT ||
740 prompt_.type() == INLINE_INSTALL_PROMPT ||
741 prompt_.type() == EXTERNAL_INSTALL_PROMPT ||
742 prompt_.GetOAuthIssueCount() != 0U) {
743 ShowConfirmation();
744 return;
745 }
746
747 const extensions::OAuth2Info& oauth2_info =
748 extensions::OAuth2Info::GetOAuth2Info(extension_);
749 if (oauth2_info.client_id.empty() ||
750 oauth2_info.scopes.empty()) {
751 ShowConfirmation();
752 return;
753 }
754
755 ProfileOAuth2TokenService* token_service =
756 ProfileOAuth2TokenServiceFactory::GetForProfile(install_ui_->profile());
757 if (!token_service || !token_service->RefreshTokenIsAvailable()) {
758 ShowConfirmation();
759 return;
760 }
761
762 // Get an access token from the token service.
763 login_token_request_ = token_service->StartRequest(
764 OAuth2TokenService::ScopeSet(), this);
765 }
766
767 void ExtensionInstallPrompt::OnGetTokenSuccess( 734 void ExtensionInstallPrompt::OnGetTokenSuccess(
768 const OAuth2TokenService::Request* request, 735 const OAuth2TokenService::Request* request,
769 const std::string& access_token, 736 const std::string& access_token,
770 const base::Time& expiration_time) { 737 const base::Time& expiration_time) {
771 DCHECK_EQ(login_token_request_.get(), request); 738 DCHECK_EQ(login_token_request_.get(), request);
772 login_token_request_.reset(); 739 login_token_request_.reset();
773 740
774 const extensions::OAuth2Info& oauth2_info = 741 const extensions::OAuth2Info& oauth2_info =
775 extensions::OAuth2Info::GetOAuth2Info(extension_); 742 extensions::OAuth2Info::GetOAuth2Info(extension_);
776 743
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 } 807 }
841 808
842 if (AutoConfirmPrompt(delegate_)) 809 if (AutoConfirmPrompt(delegate_))
843 return; 810 return;
844 811
845 if (show_dialog_callback_.is_null()) 812 if (show_dialog_callback_.is_null())
846 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 813 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
847 else 814 else
848 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 815 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
849 } 816 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_prompt.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698