OLD | NEW |
(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 |
| 26 class ProfileSigninConfirmationHandler : public content::WebUIMessageHandler { |
| 27 public: |
| 28 ProfileSigninConfirmationHandler( |
| 29 const ProfileSigninConfirmationDialog* dialog, |
| 30 const base::Closure& cancel_signin, |
| 31 const base::Closure& signin_with_new_profile, |
| 32 const base::Closure& continue_signin); |
| 33 virtual ~ProfileSigninConfirmationHandler(); |
| 34 virtual void RegisterMessages() OVERRIDE; |
| 35 |
| 36 private: |
| 37 // content::WebUIMessageHandler implementation. |
| 38 void OnCancelButtonClicked(const base::ListValue* args); |
| 39 void OnCreateProfileClicked(const base::ListValue* args); |
| 40 void OnContinueButtonClicked(const base::ListValue* args); |
| 41 |
| 42 // Weak ptr to parent dialog. |
| 43 const ProfileSigninConfirmationDialog* dialog_; |
| 44 |
| 45 // Dialog button callbacks. |
| 46 base::Closure cancel_signin_; |
| 47 base::Closure signin_with_new_profile_; |
| 48 base::Closure continue_signin_; |
| 49 }; |
| 50 |
| 51 } // namespace |
| 52 |
| 53 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( |
| 54 const ProfileSigninConfirmationDialog* dialog, |
| 55 const base::Closure& cancel_signin, |
| 56 const base::Closure& signin_with_new_profile, |
| 57 const base::Closure& continue_signin) |
| 58 : dialog_(dialog), |
| 59 cancel_signin_(cancel_signin), |
| 60 signin_with_new_profile_(signin_with_new_profile), |
| 61 continue_signin_(continue_signin) { |
| 62 } |
| 63 |
| 64 ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() { |
| 65 } |
| 66 |
| 67 void ProfileSigninConfirmationHandler::RegisterMessages() { |
| 68 web_ui()->RegisterMessageCallback("cancel", |
| 69 base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked, |
| 70 base::Unretained(this))); |
| 71 web_ui()->RegisterMessageCallback("createNewProfile", |
| 72 base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked, |
| 73 base::Unretained(this))); |
| 74 web_ui()->RegisterMessageCallback("continue", |
| 75 base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked, |
| 76 base::Unretained(this))); |
| 77 } |
| 78 |
| 79 void ProfileSigninConfirmationHandler::OnCancelButtonClicked( |
| 80 const base::ListValue* args) { |
| 81 // TODO(dconnelly): redirect back to NTP? |
| 82 cancel_signin_.Run(); |
| 83 dialog_->Close(); |
| 84 } |
| 85 |
| 86 void ProfileSigninConfirmationHandler::OnCreateProfileClicked( |
| 87 const base::ListValue* args) { |
| 88 signin_with_new_profile_.Run(); |
| 89 dialog_->Close(); |
| 90 } |
| 91 |
| 92 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( |
| 93 const base::ListValue* args) { |
| 94 continue_signin_.Run(); |
| 95 dialog_->Close(); |
| 96 } |
| 97 |
| 98 void ProfileSigninConfirmationDialog::ShowDialog( |
| 99 Profile* profile, |
| 100 const std::string& username, |
| 101 const base::Closure& cancel_signin, |
| 102 const base::Closure& signin_with_new_profile, |
| 103 const base::Closure& continue_signin) { |
| 104 new ProfileSigninConfirmationDialog(profile, |
| 105 username, |
| 106 cancel_signin, |
| 107 signin_with_new_profile, |
| 108 continue_signin); |
| 109 } |
| 110 |
| 111 ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog( |
| 112 Profile* profile, |
| 113 const std::string& username, |
| 114 const base::Closure& cancel_signin, |
| 115 const base::Closure& signin_with_new_profile, |
| 116 const base::Closure& continue_signin) |
| 117 : username_(username), |
| 118 cancel_signin_(cancel_signin), |
| 119 signin_with_new_profile_(signin_with_new_profile), |
| 120 continue_signin_(continue_signin) { |
| 121 Browser* browser = FindBrowserWithProfile(profile, |
| 122 chrome::HOST_DESKTOP_TYPE_FIRST); |
| 123 DCHECK(browser); |
| 124 delegate_ = CreateConstrainedWebDialog( |
| 125 profile, this, NULL, browser->tab_strip_model()->GetActiveWebContents()); |
| 126 } |
| 127 |
| 128 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { |
| 129 } |
| 130 |
| 131 void ProfileSigninConfirmationDialog::Close() const { |
| 132 closed_by_handler_ = true; |
| 133 delegate_->GetWindow()->CloseWebContentsModalDialog(); |
| 134 } |
| 135 |
| 136 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { |
| 137 return ui::MODAL_TYPE_WINDOW; |
| 138 } |
| 139 |
| 140 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { |
| 141 return l10n_util::GetStringUTF16( |
| 142 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE); |
| 143 } |
| 144 |
| 145 GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const { |
| 146 return GURL(chrome::kChromeUIProfileSigninConfirmationURL); |
| 147 } |
| 148 |
| 149 void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers( |
| 150 std::vector<content::WebUIMessageHandler*>* handlers) const { |
| 151 handlers->push_back( |
| 152 new ProfileSigninConfirmationHandler(this, |
| 153 cancel_signin_, |
| 154 signin_with_new_profile_, |
| 155 continue_signin_)); |
| 156 } |
| 157 |
| 158 void ProfileSigninConfirmationDialog::GetDialogSize(gfx::Size* size) const { |
| 159 const int kMinimumDialogWidth = 480; |
| 160 const int kMinimumDialogHeight = 300; |
| 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 if (!closed_by_handler_) |
| 175 cancel_signin_.Run(); |
| 176 } |
| 177 |
| 178 void ProfileSigninConfirmationDialog::OnCloseContents( |
| 179 content::WebContents* source, |
| 180 bool* out_close_dialog) { |
| 181 if (out_close_dialog) |
| 182 *out_close_dialog = true; |
| 183 } |
| 184 |
| 185 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { |
| 186 return true; |
| 187 } |
OLD | NEW |