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

Unified Diff: chrome/browser/ui/views/profiles/user_manager_view.cc

Issue 1220843003: Perform online reauth when password is changed for a locked profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use DialogDelegateView Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/user_manager.h ('k') | chrome/browser/ui/webui/signin/inline_login_handler_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/profiles/user_manager_view.cc
diff --git a/chrome/browser/ui/views/profiles/user_manager_view.cc b/chrome/browser/ui/views/profiles/user_manager_view.cc
index 6435d04a6e2de2dfe136edbf9e767c8a662d9a32..3b79459d1cd917300d32a3835e1eee1bda5b65ac 100644
--- a/chrome/browser/ui/views/profiles/user_manager_view.cc
+++ b/chrome/browser/ui/views/profiles/user_manager_view.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/profiles/user_manager_view.h"
+#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h"
@@ -12,15 +13,21 @@
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
+#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/user_manager.h"
#include "chrome/browser/ui/views/auto_keep_alive.h"
+#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/guest_view/browser/guest_view_manager.h"
+#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
+#include "google_apis/gaia/gaia_urls.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/webview/webview.h"
@@ -28,6 +35,7 @@
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h"
+#include "ui/views/window/dialog_delegate.h"
#if defined(OS_WIN)
#include "chrome/browser/shell_integration.h"
@@ -48,10 +56,136 @@ namespace {
UserManagerView* instance_ = NULL;
bool instance_under_construction_ = false;
+class ReauthDelegate : public views::DialogDelegateView,
+ public content::WebContentsObserver {
+ public:
+ ReauthDelegate(content::BrowserContext* browser_context,
+ const std::string& email_address);
+ ~ReauthDelegate() override {}
+
+ private:
+ // views::DialogDelegate:
+ gfx::Size GetPreferredSize() const override;
+ bool CanResize() const override;
+ bool CanMaximize() const override;
+ bool CanMinimize() const override;
+ bool UseNewStyleForThisDialog() const override;
+ ui::ModalType GetModalType() const override;
+ void DeleteDelegate() override;
+ base::string16 GetWindowTitle() const override;
+ int GetDialogButtons() const override;
+
+ // content::WebContentsObserver:
+ void DidStopLoading() override;
+
+ content::BrowserContext* browser_context_;
+ views::WebView* web_view_;
+ const std::string email_address_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReauthDelegate);
+};
+
+ReauthDelegate::ReauthDelegate(content::BrowserContext* browser_context,
+ const std::string& email_address)
+ : browser_context_(browser_context),
+ email_address_(email_address) {
+ web_view_ = new views::WebView(browser_context_);
+ AddChildView(web_view_);
+ SetLayoutManager(new views::FillLayout());
+
+ // Observe navigations of the web contents so that the dialog can close itself
+ // when the sign in process is done.
+ Observe(web_view_->GetWebContents());
+
+ // Load the re-auth URL, prepopulated with the user's email address.
+ // Add the index of the profile to the URL so that the inline login page
+ // knows which profile to load and update the credentials.
+ GURL url = signin::GetReauthURLWithEmail(email_address_);
+ web_view_->LoadInitialURL(url);
+}
+
+gfx::Size ReauthDelegate::GetPreferredSize() const {
+ return gfx::Size(UserManager::kReauthDialogWidth,
+ UserManager::kReauthDialogHeight);
+}
+
+bool ReauthDelegate::CanResize() const {
+ return true;
+}
+
+bool ReauthDelegate::CanMaximize() const {
+ return true;
+}
+
+bool ReauthDelegate::CanMinimize() const {
+ return true;
+}
+
+bool ReauthDelegate::UseNewStyleForThisDialog() const {
+ return false;
+}
+
+ui::ModalType ReauthDelegate::GetModalType() const {
+ return ui::MODAL_TYPE_WINDOW;
+}
+
+void ReauthDelegate::DeleteDelegate() {
+ delete this;
+}
+
+base::string16 ReauthDelegate::GetWindowTitle() const {
+ return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE);
+}
+
+int ReauthDelegate::GetDialogButtons() const {
+ return ui::DIALOG_BUTTON_NONE;
+}
+
+bool AddToSet(std::set<content::WebContents*>* content_set,
+ content::WebContents* web_contents) {
+ content_set->insert(web_contents);
+ return false;
+}
+
+void ReauthDelegate::DidStopLoading() {
+ // If the sign in process reaches the termination URL, close the dialog.
+ // Make sure to remove any parts of the URL that gaia might append during
+ // signin.
+ GURL url = web_contents()->GetURL();
+ url::Replacements<char> replacements;
+ replacements.ClearQuery();
+ replacements.ClearRef();
+ if (url.ReplaceComponents(replacements) ==
+ GaiaUrls::GetInstance()->signin_completed_continue_url()) {
+ GetWidget()->Close();
+ return;
+ }
+
+ // If still observing the top level web contents, try to find the embedded
+ // webview and observe it instead. The webview may not be found in the
+ // initial page load since it loads asynchronously.
+ if (url.GetOrigin() !=
+ signin::GetReauthURLWithEmail(email_address_).GetOrigin()) {
+ return;
+ }
+
+ std::set<content::WebContents*> content_set;
+ content::WebContents* web_contents = web_view_->GetWebContents();
+ guest_view::GuestViewManager* manager =
+ guest_view::GuestViewManager::FromBrowserContext(
+ web_contents->GetBrowserContext());
+ if (manager)
+ manager->ForEachGuest(web_contents, base::Bind(&AddToSet, &content_set));
+ DCHECK_LE(content_set.size(), 1U);
+ if (!content_set.empty())
+ Observe(*content_set.begin());
+}
+
} // namespace
// UserManager -----------------------------------------------------------------
+// static
void UserManager::Show(
const base::FilePath& profile_path_to_focus,
profiles::UserManagerTutorialMode tutorial_mode,
@@ -93,20 +227,38 @@ void UserManager::Show(
&instance_under_construction_, true))));
}
+// static
void UserManager::Hide() {
if (instance_)
instance_->GetWidget()->Close();
}
+// static
bool UserManager::IsShowing() {
return instance_ ? instance_->GetWidget()->IsActive() : false;
}
+// static
void UserManager::OnUserManagerShown() {
if (instance_)
instance_->LogTimeToOpen();
}
+// static
+void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
+ const std::string& email) {
+ // This method should only be called if the user manager is already showing.
+ if (!IsShowing())
+ return;
+
+ // The dialog delegate will be deleted when the dialog closes.
+ views::DialogDelegate* delegate =
+ new ReauthDelegate(browser_context, email);
+ gfx::NativeView parent = instance_->GetWidget()->GetNativeView();
+ views::DialogDelegate::CreateDialogWidget(delegate, nullptr, parent);
+ delegate->GetWidget()->Show();
+}
+
// UserManagerView -------------------------------------------------------------
UserManagerView::UserManagerView()
« no previous file with comments | « chrome/browser/ui/user_manager.h ('k') | chrome/browser/ui/webui/signin/inline_login_handler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698