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 { |
|
Peter Kasting
2013/05/28 23:25:11
Nit: Since you have multiple classes in this file,
dconnelly
2013/05/29 16:46:14
Done.
| |
| 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::ShowDialog(web_contents, | |
| 66 profile, | |
| 67 username, | |
| 68 cancel_signin, | |
| 69 signin_with_new_profile, | |
| 70 continue_signin); | |
| 71 } | |
| 72 } // namespace chrome | |
| 73 #endif | |
| 74 | |
| 60 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( | 75 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( |
|
Peter Kasting
2013/05/28 23:25:11
Nit: Put these function definitions next to the cl
dconnelly
2013/05/29 16:46:14
Done.
| |
| 61 const ProfileSigninConfirmationDialog* dialog, | 76 const ProfileSigninConfirmationDialog* dialog, |
| 62 const base::Closure& cancel_signin, | 77 const base::Closure& cancel_signin, |
| 63 const base::Closure& signin_with_new_profile, | 78 const base::Closure& signin_with_new_profile, |
| 64 const base::Closure& continue_signin) | 79 const base::Closure& continue_signin) |
| 65 : dialog_(dialog), | 80 : dialog_(dialog), |
| 66 cancel_signin_(cancel_signin), | 81 cancel_signin_(cancel_signin), |
| 67 signin_with_new_profile_(signin_with_new_profile), | 82 signin_with_new_profile_(signin_with_new_profile), |
| 68 continue_signin_(continue_signin) { | 83 continue_signin_(continue_signin) { |
| 69 } | 84 } |
| 70 | 85 |
| 71 ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() { | 86 ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() { |
| 72 } | 87 } |
| 73 | 88 |
| 74 void ProfileSigninConfirmationHandler::RegisterMessages() { | 89 void ProfileSigninConfirmationHandler::RegisterMessages() { |
| 75 web_ui()->RegisterMessageCallback("cancel", | 90 web_ui()->RegisterMessageCallback("cancel", |
|
Peter Kasting
2013/05/28 23:25:11
Nit: Per c-style, all lines of arguments should st
dconnelly
2013/05/29 16:46:14
Done.
| |
| 76 base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked, | 91 base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked, |
| 77 base::Unretained(this))); | 92 base::Unretained(this))); |
| 78 web_ui()->RegisterMessageCallback("createNewProfile", | 93 web_ui()->RegisterMessageCallback("createNewProfile", |
| 79 base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked, | 94 base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked, |
| 80 base::Unretained(this))); | 95 base::Unretained(this))); |
| 81 web_ui()->RegisterMessageCallback("continue", | 96 web_ui()->RegisterMessageCallback("continue", |
| 82 base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked, | 97 base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked, |
| 83 base::Unretained(this))); | 98 base::Unretained(this))); |
| 84 } | 99 } |
| 85 | 100 |
| 86 void ProfileSigninConfirmationHandler::OnCancelButtonClicked( | 101 void ProfileSigninConfirmationHandler::OnCancelButtonClicked( |
| 87 const base::ListValue* args) { | 102 const base::ListValue* args) { |
| 88 // TODO(dconnelly): redirect back to NTP? | 103 // TODO(dconnelly): redirect back to NTP? |
| 89 cancel_signin_.Run(); | 104 cancel_signin_.Run(); |
| 90 dialog_->Close(); | 105 dialog_->Close(); |
| 91 } | 106 } |
| 92 | 107 |
| 93 void ProfileSigninConfirmationHandler::OnCreateProfileClicked( | 108 void ProfileSigninConfirmationHandler::OnCreateProfileClicked( |
| 94 const base::ListValue* args) { | 109 const base::ListValue* args) { |
| 95 signin_with_new_profile_.Run(); | 110 signin_with_new_profile_.Run(); |
| 96 dialog_->Close(); | 111 dialog_->Close(); |
| 97 } | 112 } |
| 98 | 113 |
| 99 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( | 114 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( |
| 100 const base::ListValue* args) { | 115 const base::ListValue* args) { |
| 101 continue_signin_.Run(); | 116 continue_signin_.Run(); |
| 102 dialog_->Close(); | 117 dialog_->Close(); |
| 103 } | 118 } |
| 104 | 119 |
| 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( | 120 ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog( |
| 121 content::WebContents* web_contents, | |
| 124 Profile* profile, | 122 Profile* profile, |
| 125 const std::string& username, | 123 const std::string& username, |
| 126 const base::Closure& cancel_signin, | 124 const base::Closure& cancel_signin, |
| 127 const base::Closure& signin_with_new_profile, | 125 const base::Closure& signin_with_new_profile, |
| 128 const base::Closure& continue_signin) | 126 const base::Closure& continue_signin) |
| 129 : username_(username), | 127 : web_contents_(web_contents), |
| 130 prompt_for_new_profile_(true), | 128 profile_(profile), |
| 129 username_(username), | |
| 131 cancel_signin_(cancel_signin), | 130 cancel_signin_(cancel_signin), |
| 132 signin_with_new_profile_(signin_with_new_profile), | 131 signin_with_new_profile_(signin_with_new_profile), |
| 133 continue_signin_(continue_signin), | 132 continue_signin_(continue_signin), |
| 134 profile_(profile), | 133 delegate_(NULL), |
| 135 weak_pointer_factory_(this) { | 134 prompt_for_new_profile_(true) { |
| 136 } | 135 } |
| 137 | 136 |
| 138 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { | 137 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { |
| 139 } | 138 } |
| 140 | 139 |
| 140 // static | |
| 141 void ProfileSigninConfirmationDialog::ShowDialog( | |
| 142 content::WebContents* web_contents, | |
| 143 Profile* profile, | |
| 144 const std::string& username, | |
| 145 const base::Closure& cancel_signin, | |
| 146 const base::Closure& signin_with_new_profile, | |
| 147 const base::Closure& continue_signin) { | |
| 148 ProfileSigninConfirmationDialog* dialog = | |
| 149 new ProfileSigninConfirmationDialog(web_contents, | |
| 150 profile, | |
| 151 username, | |
| 152 cancel_signin, | |
| 153 signin_with_new_profile, | |
| 154 continue_signin); | |
| 155 ui::CheckShouldPromptForNewProfile( | |
| 156 profile, | |
| 157 // This callback is guaranteed to be invoked, and once it is, the dialog | |
| 158 // owns itself. | |
| 159 base::Bind(&ProfileSigninConfirmationDialog::Show, | |
| 160 base::Unretained(dialog))); | |
| 161 } | |
| 162 | |
| 141 void ProfileSigninConfirmationDialog::Close() const { | 163 void ProfileSigninConfirmationDialog::Close() const { |
| 142 closed_by_handler_ = true; | 164 closed_by_handler_ = true; |
| 143 delegate_->OnDialogCloseFromWebUI(); | 165 delegate_->OnDialogCloseFromWebUI(); |
| 144 } | 166 } |
| 145 | 167 |
| 146 void ProfileSigninConfirmationDialog::Show(bool prompt) { | 168 void ProfileSigninConfirmationDialog::Show(bool prompt) { |
| 147 prompt_for_new_profile_ = prompt; | 169 prompt_for_new_profile_ = prompt; |
| 148 | 170 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 } | 171 } |
| 167 | 172 |
| 168 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { | 173 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { |
| 169 return ui::MODAL_TYPE_WINDOW; | 174 return ui::MODAL_TYPE_WINDOW; |
| 170 } | 175 } |
| 171 | 176 |
| 172 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { | 177 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { |
| 173 return l10n_util::GetStringUTF16( | 178 return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_TITLE); |
| 174 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE); | |
| 175 } | 179 } |
| 176 | 180 |
| 177 GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const { | 181 GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const { |
| 178 return GURL(chrome::kChromeUIProfileSigninConfirmationURL); | 182 return GURL(chrome::kChromeUIProfileSigninConfirmationURL); |
| 179 } | 183 } |
| 180 | 184 |
| 181 void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers( | 185 void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers( |
| 182 std::vector<content::WebUIMessageHandler*>* handlers) const { | 186 std::vector<content::WebUIMessageHandler*>* handlers) const { |
| 183 handlers->push_back( | 187 handlers->push_back( |
| 184 new ProfileSigninConfirmationHandler(this, | 188 new ProfileSigninConfirmationHandler(this, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 void ProfileSigninConfirmationDialog::OnCloseContents( | 224 void ProfileSigninConfirmationDialog::OnCloseContents( |
| 221 content::WebContents* source, | 225 content::WebContents* source, |
| 222 bool* out_close_dialog) { | 226 bool* out_close_dialog) { |
| 223 if (out_close_dialog) | 227 if (out_close_dialog) |
| 224 *out_close_dialog = true; | 228 *out_close_dialog = true; |
| 225 } | 229 } |
| 226 | 230 |
| 227 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { | 231 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { |
| 228 return true; | 232 return true; |
| 229 } | 233 } |
| OLD | NEW |