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..b98aa2f5df3f84e1cb30750d69e65fd17dea37a3 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,145 @@ namespace { |
UserManagerView* instance_ = NULL; |
bool instance_under_construction_ = false; |
+class ReauthDelegate : public views::DialogDelegate, |
+ public content::WebContentsObserver { |
+ public: |
+ ReauthDelegate(content::BrowserContext* browser_context, |
+ const std::string& email_address); |
+ ~ReauthDelegate() override {} |
+ |
+ private: |
+ // Overridden from views::DialogDelegate: |
Alexei Svitkine (slow)
2015/07/24 16:36:42
Nit: I think new convention is just to have the co
Roger Tawa OOO till Jul 10th
2015/07/24 17:01:29
Done.
|
+ bool CanResize() const override; |
+ bool CanMaximize() const override; |
+ bool CanMinimize() const override; |
+ bool UseNewStyleForThisDialog() const override; |
+ ui::ModalType GetModalType() const override; |
+ void DeleteDelegate() override; |
+ views::Widget* GetWidget() override; |
+ const views::Widget* GetWidget() const override; |
+ views::View* GetContentsView() override; |
+ base::string16 GetWindowTitle() const override; |
+ int GetDialogButtons() const override; |
+ |
+ // Overridden from content::WebContentsObserver: |
+ void DidStopLoading() override; |
+ |
+ content::BrowserContext* browser_context_; |
+ scoped_ptr<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) {} |
+ |
+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; |
+} |
+ |
+views::Widget* ReauthDelegate::GetWidget() { |
+ return web_view_->GetWidget(); |
+} |
+ |
+void ReauthDelegate::DeleteDelegate() { |
+ delete this; |
+} |
+ |
+const views::Widget* ReauthDelegate::GetWidget() const { |
+ return web_view_->GetWidget(); |
+} |
+ |
+views::View* ReauthDelegate::GetContentsView() { |
+ DCHECK(!web_view_); |
+ web_view_.reset(new views::WebView(browser_context_)); |
+ web_view_->set_owned_by_client(); |
+ |
+ // 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); |
+ web_view_->SetPreferredSize(gfx::Size(360, 440)); |
+ return web_view_.get(); |
+} |
+ |
+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 +236,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() |