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_finder.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" | 16 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
| 21 #include "content/public/browser/web_ui_message_handler.h" | 21 #include "content/public/browser/web_ui_message_handler.h" |
| 22 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
| 23 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 50 const ProfileSigninConfirmationDialog* dialog_; | 50 const ProfileSigninConfirmationDialog* dialog_; |
| 51 | 51 |
| 52 // Dialog button callbacks. | 52 // Dialog button callbacks. |
| 53 base::Closure cancel_signin_; | 53 base::Closure cancel_signin_; |
| 54 base::Closure signin_with_new_profile_; | 54 base::Closure signin_with_new_profile_; |
| 55 base::Closure continue_signin_; | 55 base::Closure continue_signin_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 #if !defined(TOOLKIT_VIEWS) | |
| 61 namespace chrome { | |
| 62 // static | |
| 63 // Declared in browser_dialogs.h | |
| 64 void ShowProfileSigninConfirmationDialog( | |
| 65 Profile* profile, | |
| 66 const std::string& username, | |
| 67 const base::Closure& cancel_signin, | |
| 68 const base::Closure& signin_with_new_profile, | |
| 69 const base::Closure& continue_signin) { | |
| 70 ProfileSigninConfirmationDialog* dialog = | |
| 71 new ProfileSigninConfirmationDialog(profile, | |
| 72 username, | |
| 73 cancel_signin, | |
| 74 signin_with_new_profile, | |
| 75 continue_signin); | |
| 76 ui::CheckShouldPromptForNewProfile( | |
| 77 profile, | |
| 78 // This callback is guaranteed to be invoked, and once it is, the dialog | |
| 79 // owns itself. | |
| 80 base::Bind(&ProfileSigninConfirmationDialog::Show, | |
| 81 base::Unretained(dialog))); | |
| 82 } | |
| 83 } // namespace chrome | |
| 84 #endif | |
| 85 | |
| 60 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( | 86 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( |
| 61 const ProfileSigninConfirmationDialog* dialog, | 87 const ProfileSigninConfirmationDialog* dialog, |
| 62 const base::Closure& cancel_signin, | 88 const base::Closure& cancel_signin, |
| 63 const base::Closure& signin_with_new_profile, | 89 const base::Closure& signin_with_new_profile, |
| 64 const base::Closure& continue_signin) | 90 const base::Closure& continue_signin) |
| 65 : dialog_(dialog), | 91 : dialog_(dialog), |
| 66 cancel_signin_(cancel_signin), | 92 cancel_signin_(cancel_signin), |
| 67 signin_with_new_profile_(signin_with_new_profile), | 93 signin_with_new_profile_(signin_with_new_profile), |
| 68 continue_signin_(continue_signin) { | 94 continue_signin_(continue_signin) { |
| 69 } | 95 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 95 signin_with_new_profile_.Run(); | 121 signin_with_new_profile_.Run(); |
| 96 dialog_->Close(); | 122 dialog_->Close(); |
| 97 } | 123 } |
| 98 | 124 |
| 99 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( | 125 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( |
| 100 const base::ListValue* args) { | 126 const base::ListValue* args) { |
| 101 continue_signin_.Run(); | 127 continue_signin_.Run(); |
| 102 dialog_->Close(); | 128 dialog_->Close(); |
| 103 } | 129 } |
| 104 | 130 |
| 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( | 131 ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog( |
| 124 Profile* profile, | 132 Profile* profile, |
| 125 const std::string& username, | 133 const std::string& username, |
| 126 const base::Closure& cancel_signin, | 134 const base::Closure& cancel_signin, |
| 127 const base::Closure& signin_with_new_profile, | 135 const base::Closure& signin_with_new_profile, |
| 128 const base::Closure& continue_signin) | 136 const base::Closure& continue_signin) |
| 129 : username_(username), | 137 : delegate_(NULL), |
| 138 username_(username), | |
| 130 prompt_for_new_profile_(true), | 139 prompt_for_new_profile_(true), |
| 131 cancel_signin_(cancel_signin), | 140 cancel_signin_(cancel_signin), |
| 132 signin_with_new_profile_(signin_with_new_profile), | 141 signin_with_new_profile_(signin_with_new_profile), |
| 133 continue_signin_(continue_signin), | 142 continue_signin_(continue_signin), |
| 134 profile_(profile), | 143 profile_(profile) { |
| 135 weak_pointer_factory_(this) { | |
| 136 } | 144 } |
| 137 | 145 |
| 138 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { | 146 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { |
| 139 } | 147 } |
| 140 | 148 |
| 141 void ProfileSigninConfirmationDialog::Close() const { | 149 void ProfileSigninConfirmationDialog::Close() const { |
| 142 closed_by_handler_ = true; | 150 closed_by_handler_ = true; |
| 143 delegate_->OnDialogCloseFromWebUI(); | 151 delegate_->OnDialogCloseFromWebUI(); |
| 144 } | 152 } |
| 145 | 153 |
| 146 void ProfileSigninConfirmationDialog::Show(bool prompt) { | 154 void ProfileSigninConfirmationDialog::Show(bool prompt) { |
| 147 prompt_for_new_profile_ = prompt; | |
| 148 | |
| 149 Browser* browser = FindBrowserWithProfile(profile_, | 155 Browser* browser = FindBrowserWithProfile(profile_, |
| 150 chrome::GetActiveDesktop()); | 156 chrome::GetActiveDesktop()); |
| 151 if (!browser) { | 157 if (!browser) { |
| 152 DLOG(WARNING) << "No browser found to display the confirmation dialog"; | 158 DLOG(WARNING) << "No browser found to display the confirmation dialog"; |
| 153 cancel_signin_.Run(); | 159 cancel_signin_.Run(); |
| 160 delete this; | |
|
James Hawkins
2013/05/07 17:22:44
This is really fragile. Don't we have a ScopedDel
dconnelly
2013/05/07 17:31:30
I don't know anything about that, but it sounds go
dconnelly
2013/05/13 14:45:21
No longer needed
| |
| 154 return; | 161 return; |
| 155 } | 162 } |
| 156 | |
| 157 content::WebContents* web_contents = | 163 content::WebContents* web_contents = |
| 158 browser->tab_strip_model()->GetActiveWebContents(); | 164 browser->tab_strip_model()->GetActiveWebContents(); |
| 159 if (!web_contents) { | 165 if (!web_contents) { |
| 160 DLOG(WARNING) << "No web contents found to display the confirmation dialog"; | 166 DLOG(WARNING) << "No web contents found to display the confirmation dialog"; |
| 161 cancel_signin_.Run(); | 167 cancel_signin_.Run(); |
| 168 delete this; | |
| 162 return; | 169 return; |
| 163 } | 170 } |
| 164 | 171 prompt_for_new_profile_ = prompt; |
| 165 delegate_ = CreateConstrainedWebDialog(profile_, this, NULL, web_contents); | 172 delegate_ = CreateConstrainedWebDialog(profile_, this, NULL, web_contents); |
| 166 } | 173 } |
| 167 | 174 |
| 168 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { | 175 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { |
| 169 return ui::MODAL_TYPE_WINDOW; | 176 return ui::MODAL_TYPE_WINDOW; |
| 170 } | 177 } |
| 171 | 178 |
| 172 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { | 179 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { |
| 173 return l10n_util::GetStringUTF16( | 180 return l10n_util::GetStringUTF16( |
| 174 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE); | 181 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 void ProfileSigninConfirmationDialog::OnCloseContents( | 227 void ProfileSigninConfirmationDialog::OnCloseContents( |
| 221 content::WebContents* source, | 228 content::WebContents* source, |
| 222 bool* out_close_dialog) { | 229 bool* out_close_dialog) { |
| 223 if (out_close_dialog) | 230 if (out_close_dialog) |
| 224 *out_close_dialog = true; | 231 *out_close_dialog = true; |
| 225 } | 232 } |
| 226 | 233 |
| 227 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { | 234 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { |
| 228 return true; | 235 return true; |
| 229 } | 236 } |
| OLD | NEW |