Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 { | |
| 28 class WebContents; | |
| 29 } | |
| 30 | |
| 31 namespace { | 24 namespace { |
| 32 | 25 |
| 33 class ProfileSigninConfirmationHandler : public content::WebUIMessageHandler { | 26 class ProfileSigninConfirmationHandler : public content::WebUIMessageHandler { |
| 34 public: | 27 public: |
| 35 ProfileSigninConfirmationHandler( | 28 ProfileSigninConfirmationHandler( |
| 36 const ProfileSigninConfirmationDialog* dialog, | 29 const ProfileSigninConfirmationDialog* dialog, |
| 37 const base::Closure& cancel_signin, | 30 const base::Closure& cancel_signin, |
| 38 const base::Closure& signin_with_new_profile, | 31 const base::Closure& signin_with_new_profile, |
| 39 const base::Closure& continue_signin); | 32 const base::Closure& continue_signin); |
| 40 virtual ~ProfileSigninConfirmationHandler(); | 33 virtual ~ProfileSigninConfirmationHandler(); |
| 41 virtual void RegisterMessages() OVERRIDE; | 34 virtual void RegisterMessages() OVERRIDE; |
| 42 | 35 |
| 43 private: | 36 private: |
| 44 // content::WebUIMessageHandler implementation. | 37 // content::WebUIMessageHandler implementation. |
| 45 void OnCancelButtonClicked(const base::ListValue* args); | 38 void OnCancelButtonClicked(const base::ListValue* args); |
| 46 void OnCreateProfileClicked(const base::ListValue* args); | 39 void OnCreateProfileClicked(const base::ListValue* args); |
| 47 void OnContinueButtonClicked(const base::ListValue* args); | 40 void OnContinueButtonClicked(const base::ListValue* args); |
| 48 | 41 |
| 49 // Weak ptr to parent dialog. | 42 // Weak ptr to parent dialog. |
| 50 const ProfileSigninConfirmationDialog* dialog_; | 43 const ProfileSigninConfirmationDialog* dialog_; |
| 51 | 44 |
| 52 // Dialog button callbacks. | 45 // Dialog button callbacks. |
| 53 base::Closure cancel_signin_; | 46 base::Closure cancel_signin_; |
| 54 base::Closure signin_with_new_profile_; | 47 base::Closure signin_with_new_profile_; |
| 55 base::Closure continue_signin_; | 48 base::Closure continue_signin_; |
| 56 }; | 49 }; |
| 57 | 50 |
| 58 } // namespace | 51 } // namespace |
| 59 | 52 |
| 53 #if !defined(TOOLKIT_VIEWS) | |
| 54 namespace chrome { | |
| 55 // static | |
| 56 // Declared in browser_dialogs.h | |
| 57 void ShowProfileSigninConfirmationDialog( | |
| 58 Browser* browser, | |
| 59 content::WebContents* web_contents, | |
| 60 Profile* profile, | |
| 61 const std::string& username, | |
| 62 const base::Closure& cancel_signin, | |
| 63 const base::Closure& signin_with_new_profile, | |
| 64 const base::Closure& continue_signin) { | |
| 65 ProfileSigninConfirmationDialog* dialog = | |
| 66 new ProfileSigninConfirmationDialog(web_contents, | |
| 67 profile, | |
| 68 username, | |
| 69 cancel_signin, | |
| 70 signin_with_new_profile, | |
| 71 continue_signin); | |
| 72 ui::CheckShouldPromptForNewProfile( | |
| 73 profile, | |
| 74 // This callback is guaranteed to be invoked, and once it is, the dialog | |
| 75 // owns itself. | |
| 76 base::Bind(&ProfileSigninConfirmationDialog::Show, | |
| 77 base::Unretained(dialog))); | |
| 78 } | |
| 79 } // namespace chrome | |
| 80 #endif | |
| 81 | |
| 60 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( | 82 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( |
| 61 const ProfileSigninConfirmationDialog* dialog, | 83 const ProfileSigninConfirmationDialog* dialog, |
| 62 const base::Closure& cancel_signin, | 84 const base::Closure& cancel_signin, |
| 63 const base::Closure& signin_with_new_profile, | 85 const base::Closure& signin_with_new_profile, |
| 64 const base::Closure& continue_signin) | 86 const base::Closure& continue_signin) |
| 65 : dialog_(dialog), | 87 : dialog_(dialog), |
| 66 cancel_signin_(cancel_signin), | 88 cancel_signin_(cancel_signin), |
| 67 signin_with_new_profile_(signin_with_new_profile), | 89 signin_with_new_profile_(signin_with_new_profile), |
| 68 continue_signin_(continue_signin) { | 90 continue_signin_(continue_signin) { |
| 69 } | 91 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 95 signin_with_new_profile_.Run(); | 117 signin_with_new_profile_.Run(); |
| 96 dialog_->Close(); | 118 dialog_->Close(); |
| 97 } | 119 } |
| 98 | 120 |
| 99 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( | 121 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( |
| 100 const base::ListValue* args) { | 122 const base::ListValue* args) { |
| 101 continue_signin_.Run(); | 123 continue_signin_.Run(); |
| 102 dialog_->Close(); | 124 dialog_->Close(); |
| 103 } | 125 } |
| 104 | 126 |
| 105 void ProfileSigninConfirmationDialog::ShowDialog( | |
| 106 Profile* profile, | |
| 107 const std::string& username, | |
| 108 const base::Closure& cancel_signin, | |
| 109 const base::Closure& signin_with_new_profile, | |
| 110 const base::Closure& continue_signin) { | |
| 111 ProfileSigninConfirmationDialog *dialog = | |
| 112 new ProfileSigninConfirmationDialog(profile, | |
| 113 username, | |
| 114 cancel_signin, | |
| 115 signin_with_new_profile, | |
| 116 continue_signin); | |
| 117 ui::CheckShouldPromptForNewProfile( | |
| 118 profile, | |
| 119 base::Bind(&ProfileSigninConfirmationDialog::Show, | |
| 120 dialog->weak_pointer_factory_.GetWeakPtr())); | |
| 121 } | |
| 122 | |
| 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), |
|
Peter Kasting
2013/05/15 00:11:03
Tiny nit: It would be nice if this function's arg
dconnelly
2013/05/17 13:01:55
Done.
| |
| 130 prompt_for_new_profile_(true), | 135 delegate_(NULL), |
| 136 username_(username), | |
| 137 prompt_for_new_profile_(ui::PROMPT_TO_CREATE_PROFILE), | |
| 131 cancel_signin_(cancel_signin), | 138 cancel_signin_(cancel_signin), |
| 132 signin_with_new_profile_(signin_with_new_profile), | 139 signin_with_new_profile_(signin_with_new_profile), |
| 133 continue_signin_(continue_signin), | 140 continue_signin_(continue_signin), |
| 134 profile_(profile), | 141 profile_(profile) { |
| 135 weak_pointer_factory_(this) { | |
| 136 } | 142 } |
| 137 | 143 |
| 138 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { | 144 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { |
| 139 } | 145 } |
| 140 | 146 |
| 141 void ProfileSigninConfirmationDialog::Close() const { | 147 void ProfileSigninConfirmationDialog::Close() const { |
| 142 closed_by_handler_ = true; | 148 closed_by_handler_ = true; |
| 143 delegate_->OnDialogCloseFromWebUI(); | 149 delegate_->OnDialogCloseFromWebUI(); |
| 144 } | 150 } |
| 145 | 151 |
| 146 void ProfileSigninConfirmationDialog::Show(bool prompt) { | 152 void ProfileSigninConfirmationDialog::Show( |
| 153 ui::DisplayCreateProfilePrompt prompt) { | |
| 147 prompt_for_new_profile_ = prompt; | 154 prompt_for_new_profile_ = prompt; |
| 148 | 155 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 } | 156 } |
| 167 | 157 |
| 168 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { | 158 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { |
| 169 return ui::MODAL_TYPE_WINDOW; | 159 return ui::MODAL_TYPE_WINDOW; |
| 170 } | 160 } |
| 171 | 161 |
| 172 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { | 162 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { |
| 173 return l10n_util::GetStringUTF16( | 163 return l10n_util::GetStringUTF16( |
| 174 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE); | 164 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE); |
| 175 } | 165 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 187 continue_signin_)); | 177 continue_signin_)); |
| 188 } | 178 } |
| 189 | 179 |
| 190 void ProfileSigninConfirmationDialog::GetDialogSize(gfx::Size* size) const { | 180 void ProfileSigninConfirmationDialog::GetDialogSize(gfx::Size* size) const { |
| 191 const int kMinimumDialogWidth = 480; | 181 const int kMinimumDialogWidth = 480; |
| 192 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
| 193 const int kMinimumDialogHeight = 180; | 183 const int kMinimumDialogHeight = 180; |
| 194 #else | 184 #else |
| 195 const int kMinimumDialogHeight = 210; | 185 const int kMinimumDialogHeight = 210; |
| 196 #endif | 186 #endif |
| 197 const int kProfileCreationMessageHeight = prompt_for_new_profile_ ? 50 : 0; | 187 const int kProfileCreationMessageHeight = |
| 188 prompt_for_new_profile_ == ui::PROMPT_TO_CREATE_PROFILE ? 50 : 0; | |
| 198 size->SetSize(kMinimumDialogWidth, | 189 size->SetSize(kMinimumDialogWidth, |
| 199 kMinimumDialogHeight + kProfileCreationMessageHeight); | 190 kMinimumDialogHeight + kProfileCreationMessageHeight); |
| 200 } | 191 } |
| 201 | 192 |
| 202 std::string ProfileSigninConfirmationDialog::GetDialogArgs() const { | 193 std::string ProfileSigninConfirmationDialog::GetDialogArgs() const { |
| 203 std::string data; | 194 std::string data; |
| 204 base::DictionaryValue dict; | 195 base::DictionaryValue dict; |
| 205 dict.SetString("username", username_); | 196 dict.SetString("username", username_); |
| 206 dict.SetBoolean("promptForNewProfile", prompt_for_new_profile_); | 197 dict.SetBoolean("promptForNewProfile", |
| 198 prompt_for_new_profile_ == ui::PROMPT_TO_CREATE_PROFILE); | |
| 207 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
| 208 dict.SetBoolean("hideTitle", true); | 200 dict.SetBoolean("hideTitle", true); |
| 209 #endif | 201 #endif |
| 210 base::JSONWriter::Write(&dict, &data); | 202 base::JSONWriter::Write(&dict, &data); |
| 211 return data; | 203 return data; |
| 212 } | 204 } |
| 213 | 205 |
| 214 void ProfileSigninConfirmationDialog::OnDialogClosed( | 206 void ProfileSigninConfirmationDialog::OnDialogClosed( |
| 215 const std::string& json_retval) { | 207 const std::string& json_retval) { |
| 216 if (!closed_by_handler_) | 208 if (!closed_by_handler_) |
| 217 cancel_signin_.Run(); | 209 cancel_signin_.Run(); |
| 218 } | 210 } |
| 219 | 211 |
| 220 void ProfileSigninConfirmationDialog::OnCloseContents( | 212 void ProfileSigninConfirmationDialog::OnCloseContents( |
| 221 content::WebContents* source, | 213 content::WebContents* source, |
| 222 bool* out_close_dialog) { | 214 bool* out_close_dialog) { |
| 223 if (out_close_dialog) | 215 if (out_close_dialog) |
| 224 *out_close_dialog = true; | 216 *out_close_dialog = true; |
| 225 } | 217 } |
| 226 | 218 |
| 227 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { | 219 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { |
| 228 return true; | 220 return true; |
| 229 } | 221 } |
| OLD | NEW |