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

Side by Side Diff: chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.cc

Issue 14846020: Add Views implementation of ProfileSigninConfirmationDialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more nits Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/ui/webui/signin/profile_signin_confirmation_dialog.h" 5 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_dialogs.h" 13 #include "chrome/browser/ui/browser_dialogs.h"
14 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 15 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
19 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
21 #include "content/public/browser/web_ui_message_handler.h" 18 #include "content/public/browser/web_ui_message_handler.h"
22 #include "grit/browser_resources.h" 19 #include "grit/browser_resources.h"
23 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
25 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
26 23
27 namespace content { 24 // ProfileSigninConfirmationHandler --------------------------------------------
28 class WebContents;
29 }
30 25
31 namespace { 26 namespace {
32 27
33 class ProfileSigninConfirmationHandler : public content::WebUIMessageHandler { 28 class ProfileSigninConfirmationHandler : public content::WebUIMessageHandler {
34 public: 29 public:
35 ProfileSigninConfirmationHandler( 30 ProfileSigninConfirmationHandler(
36 const ProfileSigninConfirmationDialog* dialog, 31 const ProfileSigninConfirmationDialog* dialog,
37 const base::Closure& cancel_signin, 32 const base::Closure& cancel_signin,
38 const base::Closure& signin_with_new_profile, 33 const base::Closure& signin_with_new_profile,
39 const base::Closure& continue_signin); 34 const base::Closure& continue_signin);
40 virtual ~ProfileSigninConfirmationHandler(); 35 virtual ~ProfileSigninConfirmationHandler();
41 virtual void RegisterMessages() OVERRIDE; 36 virtual void RegisterMessages() OVERRIDE;
42 37
43 private: 38 private:
44 // content::WebUIMessageHandler implementation. 39 // content::WebUIMessageHandler implementation.
45 void OnCancelButtonClicked(const base::ListValue* args); 40 void OnCancelButtonClicked(const base::ListValue* args);
46 void OnCreateProfileClicked(const base::ListValue* args); 41 void OnCreateProfileClicked(const base::ListValue* args);
47 void OnContinueButtonClicked(const base::ListValue* args); 42 void OnContinueButtonClicked(const base::ListValue* args);
48 43
49 // Weak ptr to parent dialog. 44 // Weak ptr to parent dialog.
50 const ProfileSigninConfirmationDialog* dialog_; 45 const ProfileSigninConfirmationDialog* dialog_;
51 46
52 // Dialog button callbacks. 47 // Dialog button callbacks.
53 base::Closure cancel_signin_; 48 base::Closure cancel_signin_;
54 base::Closure signin_with_new_profile_; 49 base::Closure signin_with_new_profile_;
55 base::Closure continue_signin_; 50 base::Closure continue_signin_;
56 }; 51 };
57 52
58 } // namespace
59
60 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( 53 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler(
61 const ProfileSigninConfirmationDialog* dialog, 54 const ProfileSigninConfirmationDialog* dialog,
62 const base::Closure& cancel_signin, 55 const base::Closure& cancel_signin,
63 const base::Closure& signin_with_new_profile, 56 const base::Closure& signin_with_new_profile,
64 const base::Closure& continue_signin) 57 const base::Closure& continue_signin)
65 : dialog_(dialog), 58 : dialog_(dialog),
66 cancel_signin_(cancel_signin), 59 cancel_signin_(cancel_signin),
67 signin_with_new_profile_(signin_with_new_profile), 60 signin_with_new_profile_(signin_with_new_profile),
68 continue_signin_(continue_signin) { 61 continue_signin_(continue_signin) {
69 } 62 }
70 63
71 ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() { 64 ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() {
72 } 65 }
73 66
74 void ProfileSigninConfirmationHandler::RegisterMessages() { 67 void ProfileSigninConfirmationHandler::RegisterMessages() {
75 web_ui()->RegisterMessageCallback("cancel", 68 web_ui()->RegisterMessageCallback(
69 "cancel",
76 base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked, 70 base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked,
77 base::Unretained(this))); 71 base::Unretained(this)));
78 web_ui()->RegisterMessageCallback("createNewProfile", 72 web_ui()->RegisterMessageCallback(
73 "createNewProfile",
79 base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked, 74 base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked,
80 base::Unretained(this))); 75 base::Unretained(this)));
81 web_ui()->RegisterMessageCallback("continue", 76 web_ui()->RegisterMessageCallback(
77 "continue",
82 base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked, 78 base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked,
83 base::Unretained(this))); 79 base::Unretained(this)));
84 } 80 }
85 81
86 void ProfileSigninConfirmationHandler::OnCancelButtonClicked( 82 void ProfileSigninConfirmationHandler::OnCancelButtonClicked(
87 const base::ListValue* args) { 83 const base::ListValue* args) {
88 // TODO(dconnelly): redirect back to NTP? 84 // TODO(dconnelly): redirect back to NTP?
89 cancel_signin_.Run(); 85 cancel_signin_.Run();
90 dialog_->Close(); 86 dialog_->Close();
91 } 87 }
92 88
93 void ProfileSigninConfirmationHandler::OnCreateProfileClicked( 89 void ProfileSigninConfirmationHandler::OnCreateProfileClicked(
94 const base::ListValue* args) { 90 const base::ListValue* args) {
95 signin_with_new_profile_.Run(); 91 signin_with_new_profile_.Run();
96 dialog_->Close(); 92 dialog_->Close();
97 } 93 }
98 94
99 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( 95 void ProfileSigninConfirmationHandler::OnContinueButtonClicked(
100 const base::ListValue* args) { 96 const base::ListValue* args) {
101 continue_signin_.Run(); 97 continue_signin_.Run();
102 dialog_->Close(); 98 dialog_->Close();
103 } 99 }
104 100
105 void ProfileSigninConfirmationDialog::ShowDialog( 101 } // namespace
102
103 #if !defined(TOOLKIT_VIEWS)
104 namespace chrome {
105 // static
106 // Declared in browser_dialogs.h
107 void ShowProfileSigninConfirmationDialog(
108 Browser* browser,
109 content::WebContents* web_contents,
106 Profile* profile, 110 Profile* profile,
107 const std::string& username, 111 const std::string& username,
108 const base::Closure& cancel_signin, 112 const base::Closure& cancel_signin,
109 const base::Closure& signin_with_new_profile, 113 const base::Closure& signin_with_new_profile,
110 const base::Closure& continue_signin) { 114 const base::Closure& continue_signin) {
111 ProfileSigninConfirmationDialog *dialog = 115 ProfileSigninConfirmationDialog::ShowDialog(web_contents,
112 new ProfileSigninConfirmationDialog(profile, 116 profile,
113 username, 117 username,
114 cancel_signin, 118 cancel_signin,
115 signin_with_new_profile, 119 signin_with_new_profile,
116 continue_signin); 120 continue_signin);
117 ui::CheckShouldPromptForNewProfile(
118 profile,
119 base::Bind(&ProfileSigninConfirmationDialog::Show,
120 dialog->weak_pointer_factory_.GetWeakPtr()));
121 } 121 }
122 } // namespace chrome
123 #endif
124
125 // ProfileSigninConfirmationDialog ---------------------------------------------
122 126
123 ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog( 127 ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog(
128 content::WebContents* web_contents,
124 Profile* profile, 129 Profile* profile,
125 const std::string& username, 130 const std::string& username,
126 const base::Closure& cancel_signin, 131 const base::Closure& cancel_signin,
127 const base::Closure& signin_with_new_profile, 132 const base::Closure& signin_with_new_profile,
128 const base::Closure& continue_signin) 133 const base::Closure& continue_signin)
129 : username_(username), 134 : web_contents_(web_contents),
130 prompt_for_new_profile_(true), 135 profile_(profile),
136 username_(username),
131 cancel_signin_(cancel_signin), 137 cancel_signin_(cancel_signin),
132 signin_with_new_profile_(signin_with_new_profile), 138 signin_with_new_profile_(signin_with_new_profile),
133 continue_signin_(continue_signin), 139 continue_signin_(continue_signin),
134 profile_(profile), 140 delegate_(NULL),
135 weak_pointer_factory_(this) { 141 prompt_for_new_profile_(true) {
136 } 142 }
137 143
138 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { 144 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() {
139 } 145 }
140 146
147 // static
148 void ProfileSigninConfirmationDialog::ShowDialog(
149 content::WebContents* web_contents,
150 Profile* profile,
151 const std::string& username,
152 const base::Closure& cancel_signin,
153 const base::Closure& signin_with_new_profile,
154 const base::Closure& continue_signin) {
155 ProfileSigninConfirmationDialog* dialog =
156 new ProfileSigninConfirmationDialog(web_contents,
157 profile,
158 username,
159 cancel_signin,
160 signin_with_new_profile,
161 continue_signin);
162 ui::CheckShouldPromptForNewProfile(
163 profile,
164 // This callback is guaranteed to be invoked, and once it is, the dialog
165 // owns itself.
166 base::Bind(&ProfileSigninConfirmationDialog::Show,
167 base::Unretained(dialog)));
168 }
169
141 void ProfileSigninConfirmationDialog::Close() const { 170 void ProfileSigninConfirmationDialog::Close() const {
142 closed_by_handler_ = true; 171 closed_by_handler_ = true;
143 delegate_->OnDialogCloseFromWebUI(); 172 delegate_->OnDialogCloseFromWebUI();
144 } 173 }
145 174
146 void ProfileSigninConfirmationDialog::Show(bool prompt) { 175 void ProfileSigninConfirmationDialog::Show(bool prompt) {
147 prompt_for_new_profile_ = prompt; 176 prompt_for_new_profile_ = prompt;
148 177 delegate_ = CreateConstrainedWebDialog(profile_, this, NULL, web_contents_);
149 Browser* browser = FindBrowserWithProfile(profile_,
150 chrome::GetActiveDesktop());
151 if (!browser) {
152 DLOG(WARNING) << "No browser found to display the confirmation dialog";
153 cancel_signin_.Run();
154 return;
155 }
156
157 content::WebContents* web_contents =
158 browser->tab_strip_model()->GetActiveWebContents();
159 if (!web_contents) {
160 DLOG(WARNING) << "No web contents found to display the confirmation dialog";
161 cancel_signin_.Run();
162 return;
163 }
164
165 delegate_ = CreateConstrainedWebDialog(profile_, this, NULL, web_contents);
166 } 178 }
167 179
168 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { 180 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const {
169 return ui::MODAL_TYPE_WINDOW; 181 return ui::MODAL_TYPE_WINDOW;
170 } 182 }
171 183
172 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { 184 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const {
173 return l10n_util::GetStringUTF16( 185 return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_TITLE);
174 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE);
175 } 186 }
176 187
177 GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const { 188 GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const {
178 return GURL(chrome::kChromeUIProfileSigninConfirmationURL); 189 return GURL(chrome::kChromeUIProfileSigninConfirmationURL);
179 } 190 }
180 191
181 void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers( 192 void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers(
182 std::vector<content::WebUIMessageHandler*>* handlers) const { 193 std::vector<content::WebUIMessageHandler*>* handlers) const {
183 handlers->push_back( 194 handlers->push_back(
184 new ProfileSigninConfirmationHandler(this, 195 new ProfileSigninConfirmationHandler(this,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void ProfileSigninConfirmationDialog::OnCloseContents( 231 void ProfileSigninConfirmationDialog::OnCloseContents(
221 content::WebContents* source, 232 content::WebContents* source,
222 bool* out_close_dialog) { 233 bool* out_close_dialog) {
223 if (out_close_dialog) 234 if (out_close_dialog)
224 *out_close_dialog = true; 235 *out_close_dialog = true;
225 } 236 }
226 237
227 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { 238 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const {
228 return true; 239 return true;
229 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698