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

Unified Diff: chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.cc

Issue 12221111: Add a modal confirmation dialog to the enterprise profile sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move WebUI handler into WebDialogDelegate implementation Created 7 years, 10 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
Index: chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.cc
diff --git a/chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.cc b/chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e1e625cd70fd9898e47ab1e2ebbbf70749dc4bf
--- /dev/null
+++ b/chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.cc
@@ -0,0 +1,186 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h"
+
+#include "base/json/json_writer.h"
+#include "chrome/browser/profiles/profile_manager.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_list.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/web_contents_modal_dialog.h"
+#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
+#include "chrome/common/url_constants.h"
+#include "content/public/browser/web_ui.h"
+#include "content/public/browser/web_ui_message_handler.h"
+#include "grit/browser_resources.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace {
+const int kMinimumDialogWidth = 480;
+const int kMinimumDialogHeight = 300;
+} // namespace
+
+// ============================================================================
+// WebUIMessageHandler
+
+class ProfileSigninConfirmationHandler : public content::WebUIMessageHandler {
Roger Tawa OOO till Jul 10th 2013/02/11 16:24:39 put class in anon namespace too?
dconnelly 2013/02/12 10:04:36 Done.
+ public:
+ ProfileSigninConfirmationHandler(
+ ProfileSigninConfirmationDialog* dialog,
+ const base::Closure& cancel_signin,
+ const base::Closure& signin_with_new_profile,
+ const base::Closure& continue_signin);
+ virtual ~ProfileSigninConfirmationHandler();
+ virtual void RegisterMessages() OVERRIDE;
+
+ private:
+ void OnCancelButtonClicked(const base::ListValue* args);
+ void OnCreateProfileClicked(const base::ListValue* args);
+ void OnContinueButtonClicked(const base::ListValue* args);
+
+ // Weak ptr to parent dialog.
+ ProfileSigninConfirmationDialog* dialog_;
+
+ base::Closure cancel_signin_;
+ base::Closure signin_with_new_profile_;
+ base::Closure continue_signin_;
+};
+
+ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler(
+ ProfileSigninConfirmationDialog* dialog,
+ const base::Closure& cancel_signin,
+ const base::Closure& signin_with_new_profile,
+ const base::Closure& continue_signin)
+ : dialog_(dialog),
+ cancel_signin_(cancel_signin),
+ signin_with_new_profile_(signin_with_new_profile),
+ continue_signin_(continue_signin) {
+}
+
+ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() {
+}
+
+void ProfileSigninConfirmationHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("cancel",
+ base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("createNewProfile",
+ base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("continue",
+ base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked,
+ base::Unretained(this)));
+}
+
+void ProfileSigninConfirmationHandler::OnCancelButtonClicked(
+ const base::ListValue* args) {
+ // TODO(dconnelly): redirect back to NTP?
+ cancel_signin_.Run();
+ dialog_->Close();
+}
+
+void ProfileSigninConfirmationHandler::OnCreateProfileClicked(
+ const base::ListValue* args) {
+ signin_with_new_profile_.Run();
+ dialog_->Close();
+}
+
+void ProfileSigninConfirmationHandler::OnContinueButtonClicked(
+ const base::ListValue* args) {
+ continue_signin_.Run();
+ dialog_->Close();
+}
+
+// ============================================================================
+// WebDialogDelegate
+
+void ProfileSigninConfirmationDialog::ShowDialog(
+ Profile* profile,
+ const std::string& username,
+ const base::Closure& cancel_signin,
+ const base::Closure& signin_with_new_profile,
+ const base::Closure& continue_signin) {
+ new ProfileSigninConfirmationDialog(profile,
+ username,
+ cancel_signin,
+ signin_with_new_profile,
+ continue_signin);
+}
+
+ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog(
+ Profile* profile,
+ const std::string& username,
+ const base::Closure& cancel_signin,
+ const base::Closure& signin_with_new_profile,
+ const base::Closure& continue_signin)
+ : username_(username) {
+ handler_.reset(new ProfileSigninConfirmationHandler(this,
+ cancel_signin,
+ signin_with_new_profile,
+ continue_signin));
+
+ Browser* browser = FindBrowserWithProfile(profile,
+ chrome::HOST_DESKTOP_TYPE_FIRST);
+ DCHECK(browser);
+ delegate_ = CreateConstrainedWebDialog(
+ profile, this, NULL, browser->tab_strip_model()->GetActiveWebContents());
Roger Tawa OOO till Jul 10th 2013/02/11 16:24:39 Ideally you would want to pass the web_contents di
Andrew T Wilson (Slow) 2013/02/12 10:46:41 Yeah, currently SigninManager doesn't know anythin
Roger Tawa OOO till Jul 10th 2013/02/12 14:57:29 Yes, sounds like something for M27. For M26, does
+}
+
+ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() {
+}
+
+void ProfileSigninConfirmationDialog::Close() {
+ delegate_->GetWindow()->CloseWebContentsModalDialog();
+}
+
+ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const {
+ return ui::MODAL_TYPE_WINDOW;
Roger Tawa OOO till Jul 10th 2013/02/11 16:24:39 is this modal app-wide? If not, should it be?
dconnelly 2013/02/12 10:04:36 It's local to the tab. Good question. I don't kn
Andrew T Wilson (Slow) 2013/02/12 10:46:41 Let's leave as-is until the UX guys get back to us
+}
+
+string16 ProfileSigninConfirmationDialog::GetDialogTitle() const {
+ return l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE);
+}
+
+GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const {
+ return GURL(chrome::kChromeUIProfileSigninConfirmationURL);
+}
+
+void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers(
+ std::vector<content::WebUIMessageHandler*>* handlers) const {
+ handlers->push_back(handler_.release());
+}
+
+void ProfileSigninConfirmationDialog::GetDialogSize(gfx::Size* size) const {
+ size->SetSize(kMinimumDialogWidth, kMinimumDialogHeight);
+}
+
+std::string ProfileSigninConfirmationDialog::GetDialogArgs() const {
+ std::string data;
+ DictionaryValue dict;
+ dict.SetString("username", username_);
+ base::JSONWriter::Write(&dict, &data);
+ return data;
+}
+
+void ProfileSigninConfirmationDialog::OnDialogClosed(
+ const std::string& json_retval) {
+ // TODO(dconnelly): if the user closed the tab we should cancel
+}
+
+void ProfileSigninConfirmationDialog::OnCloseContents(
+ content::WebContents* source,
+ bool* out_close_dialog) {
+ if (out_close_dialog)
+ *out_close_dialog = true;
+}
+
+bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const {
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698