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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h"
6
7 #include "base/json/json_writer.h"
8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_dialogs.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/web_contents_modal_dialog.h"
15 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/web_ui.h"
18 #include "content/public/browser/web_ui_message_handler.h"
19 #include "grit/browser_resources.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 namespace {
25 const int kMinimumDialogWidth = 480;
26 const int kMinimumDialogHeight = 300;
27 } // namespace
28
29 // ============================================================================
30 // WebUIMessageHandler
31
32 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.
33 public:
34 ProfileSigninConfirmationHandler(
35 ProfileSigninConfirmationDialog* dialog,
36 const base::Closure& cancel_signin,
37 const base::Closure& signin_with_new_profile,
38 const base::Closure& continue_signin);
39 virtual ~ProfileSigninConfirmationHandler();
40 virtual void RegisterMessages() OVERRIDE;
41
42 private:
43 void OnCancelButtonClicked(const base::ListValue* args);
44 void OnCreateProfileClicked(const base::ListValue* args);
45 void OnContinueButtonClicked(const base::ListValue* args);
46
47 // Weak ptr to parent dialog.
48 ProfileSigninConfirmationDialog* dialog_;
49
50 base::Closure cancel_signin_;
51 base::Closure signin_with_new_profile_;
52 base::Closure continue_signin_;
53 };
54
55 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler(
56 ProfileSigninConfirmationDialog* dialog,
57 const base::Closure& cancel_signin,
58 const base::Closure& signin_with_new_profile,
59 const base::Closure& continue_signin)
60 : dialog_(dialog),
61 cancel_signin_(cancel_signin),
62 signin_with_new_profile_(signin_with_new_profile),
63 continue_signin_(continue_signin) {
64 }
65
66 ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() {
67 }
68
69 void ProfileSigninConfirmationHandler::RegisterMessages() {
70 web_ui()->RegisterMessageCallback("cancel",
71 base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked,
72 base::Unretained(this)));
73 web_ui()->RegisterMessageCallback("createNewProfile",
74 base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked,
75 base::Unretained(this)));
76 web_ui()->RegisterMessageCallback("continue",
77 base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked,
78 base::Unretained(this)));
79 }
80
81 void ProfileSigninConfirmationHandler::OnCancelButtonClicked(
82 const base::ListValue* args) {
83 // TODO(dconnelly): redirect back to NTP?
84 cancel_signin_.Run();
85 dialog_->Close();
86 }
87
88 void ProfileSigninConfirmationHandler::OnCreateProfileClicked(
89 const base::ListValue* args) {
90 signin_with_new_profile_.Run();
91 dialog_->Close();
92 }
93
94 void ProfileSigninConfirmationHandler::OnContinueButtonClicked(
95 const base::ListValue* args) {
96 continue_signin_.Run();
97 dialog_->Close();
98 }
99
100 // ============================================================================
101 // WebDialogDelegate
102
103 void ProfileSigninConfirmationDialog::ShowDialog(
104 Profile* profile,
105 const std::string& username,
106 const base::Closure& cancel_signin,
107 const base::Closure& signin_with_new_profile,
108 const base::Closure& continue_signin) {
109 new ProfileSigninConfirmationDialog(profile,
110 username,
111 cancel_signin,
112 signin_with_new_profile,
113 continue_signin);
114 }
115
116 ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog(
117 Profile* profile,
118 const std::string& username,
119 const base::Closure& cancel_signin,
120 const base::Closure& signin_with_new_profile,
121 const base::Closure& continue_signin)
122 : username_(username) {
123 handler_.reset(new ProfileSigninConfirmationHandler(this,
124 cancel_signin,
125 signin_with_new_profile,
126 continue_signin));
127
128 Browser* browser = FindBrowserWithProfile(profile,
129 chrome::HOST_DESKTOP_TYPE_FIRST);
130 DCHECK(browser);
131 delegate_ = CreateConstrainedWebDialog(
132 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
133 }
134
135 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() {
136 }
137
138 void ProfileSigninConfirmationDialog::Close() {
139 delegate_->GetWindow()->CloseWebContentsModalDialog();
140 }
141
142 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const {
143 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
144 }
145
146 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const {
147 return l10n_util::GetStringUTF16(
148 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE);
149 }
150
151 GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const {
152 return GURL(chrome::kChromeUIProfileSigninConfirmationURL);
153 }
154
155 void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers(
156 std::vector<content::WebUIMessageHandler*>* handlers) const {
157 handlers->push_back(handler_.release());
158 }
159
160 void ProfileSigninConfirmationDialog::GetDialogSize(gfx::Size* size) const {
161 size->SetSize(kMinimumDialogWidth, kMinimumDialogHeight);
162 }
163
164 std::string ProfileSigninConfirmationDialog::GetDialogArgs() const {
165 std::string data;
166 DictionaryValue dict;
167 dict.SetString("username", username_);
168 base::JSONWriter::Write(&dict, &data);
169 return data;
170 }
171
172 void ProfileSigninConfirmationDialog::OnDialogClosed(
173 const std::string& json_retval) {
174 // TODO(dconnelly): if the user closed the tab we should cancel
175 }
176
177 void ProfileSigninConfirmationDialog::OnCloseContents(
178 content::WebContents* source,
179 bool* out_close_dialog) {
180 if (out_close_dialog)
181 *out_close_dialog = true;
182 }
183
184 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const {
185 return true;
186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698