dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 1 | // Copyright 2014 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 | |
joedow | b1b8dca | 2016-09-12 17:03:24 | [diff] [blame] | 5 | #include <memory> |
| 6 | #include <string> |
| 7 | |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 8 | #include "base/bind.h" |
joedow | b1b8dca | 2016-09-12 17:03:24 | [diff] [blame] | 9 | #include "base/callback.h" |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 10 | #include "base/callback_helpers.h" |
joedow | b1b8dca | 2016-09-12 17:03:24 | [diff] [blame] | 11 | #include "base/i18n/message_formatter.h" |
avi | c5960f3 | 2015-12-22 22:49:48 | [diff] [blame] | 12 | #include "base/macros.h" |
joedow | 7cc2c86 | 2016-09-13 16:05:57 | [diff] [blame] | 13 | #include "base/memory/ptr_util.h" |
joedow | b1b8dca | 2016-09-12 17:03:24 | [diff] [blame] | 14 | #include "base/strings/utf_string_conversions.h" |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 15 | #include "remoting/base/string_resources.h" |
| 16 | #include "remoting/host/chromeos/message_box.h" |
| 17 | #include "remoting/host/it2me/it2me_confirmation_dialog.h" |
| 18 | #include "ui/base/l10n/l10n_util.h" |
| 19 | |
| 20 | namespace remoting { |
| 21 | |
| 22 | class It2MeConfirmationDialogChromeOS : public It2MeConfirmationDialog { |
| 23 | public: |
| 24 | It2MeConfirmationDialogChromeOS(); |
| 25 | ~It2MeConfirmationDialogChromeOS() override; |
| 26 | |
| 27 | // It2MeConfirmationDialog implementation. |
joedow | b1b8dca | 2016-09-12 17:03:24 | [diff] [blame] | 28 | void Show(const std::string& remote_user_email, |
| 29 | const ResultCallback& callback) override; |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 30 | |
| 31 | private: |
| 32 | // Handles result from |message_box_|. |
| 33 | void OnMessageBoxResult(MessageBox::Result result); |
| 34 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 35 | std::unique_ptr<MessageBox> message_box_; |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 36 | ResultCallback callback_; |
| 37 | |
| 38 | DISALLOW_COPY_AND_ASSIGN(It2MeConfirmationDialogChromeOS); |
| 39 | }; |
| 40 | |
Chris Watkins | 6fe52aa | 2017-11-28 03:24:05 | [diff] [blame^] | 41 | It2MeConfirmationDialogChromeOS::It2MeConfirmationDialogChromeOS() = default; |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 42 | |
Chris Watkins | 6fe52aa | 2017-11-28 03:24:05 | [diff] [blame^] | 43 | It2MeConfirmationDialogChromeOS::~It2MeConfirmationDialogChromeOS() = default; |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 44 | |
joedow | b1b8dca | 2016-09-12 17:03:24 | [diff] [blame] | 45 | void It2MeConfirmationDialogChromeOS::Show(const std::string& remote_user_email, |
| 46 | const ResultCallback& callback) { |
| 47 | DCHECK(!remote_user_email.empty()); |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 48 | callback_ = callback; |
| 49 | |
kelvinp | 8607d9d | 2017-01-27 03:33:52 | [diff] [blame] | 50 | message_box_ = base::MakeUnique<MessageBox>( |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 51 | l10n_util::GetStringUTF16(IDS_MODE_IT2ME), |
joedow | b1b8dca | 2016-09-12 17:03:24 | [diff] [blame] | 52 | base::i18n::MessageFormatter::FormatWithNumberedArgs( |
| 53 | l10n_util::GetStringUTF16( |
| 54 | IDS_SHARE_CONFIRM_DIALOG_MESSAGE_WITH_USERNAME), |
| 55 | base::UTF8ToUTF16(remote_user_email)), |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 56 | l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_CONFIRM), |
| 57 | l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_DECLINE), |
| 58 | base::Bind(&It2MeConfirmationDialogChromeOS::OnMessageBoxResult, |
kelvinp | 8607d9d | 2017-01-27 03:33:52 | [diff] [blame] | 59 | base::Unretained(this))); |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void It2MeConfirmationDialogChromeOS::OnMessageBoxResult( |
| 63 | MessageBox::Result result) { |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 64 | base::ResetAndReturn(&callback_).Run(result == MessageBox::OK ? |
| 65 | Result::OK : Result::CANCEL); |
| 66 | } |
| 67 | |
joedow | d15dc6a | 2017-03-20 16:52:26 | [diff] [blame] | 68 | std::unique_ptr<It2MeConfirmationDialog> |
| 69 | It2MeConfirmationDialogFactory::Create() { |
joedow | 7cc2c86 | 2016-09-13 16:05:57 | [diff] [blame] | 70 | return base::MakeUnique<It2MeConfirmationDialogChromeOS>(); |
dcaiafa | 3a5e728 | 2015-01-06 21:21:19 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } // namespace remoting |