Index: remoting/host/chromeos/message_box.h |
diff --git a/remoting/host/chromeos/message_box.h b/remoting/host/chromeos/message_box.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cd326ebe2c362a30aa10982990b7972436b75c66 |
--- /dev/null |
+++ b/remoting/host/chromeos/message_box.h |
@@ -0,0 +1,70 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_HOST_CHROMEOS_MESSAGE_BOX_H_ |
+#define REMOTING_HOST_CHROMEOS_MESSAGE_BOX_H_ |
+ |
+#include "base/memory/ref_counted.h" |
+#include "ui/views/window/dialog_delegate.h" |
+ |
+namespace remoting { |
+ |
+// Overview: |
+// Shows a system modal message box with ok and cancel buttons. This class |
+// is not thread-safe. |
dcaiafa
2014/10/31 18:05:49
Does it have to run in a specific thread?
kelvinp
2014/10/31 21:12:53
Comments added.
|
+// |
+// Implementation details: |
+// The MessageBox creates the dialog using the views::DialogWidget. The |
+// DialogWidget is created by the caller but its lifetime is managed by the |
+// NativeWidget. The DialogWidget communicates with the MessageBox using the |
+// DialogDelegateView interface. DialogDelegateView must remain valid until |
+// DeleteDelegate() is called, at which the DialogDelegateView deletes itself. |
+// To abstract this awkward ownership model, the MessageBox object is |
+// RefCounted. It calls AddRef() on itself when the widget is created and calls |
+// Release() when DeleteDelegate() is called. |
+class MessageBox : public views::DialogDelegateView, |
+ public base::RefCounted<MessageBox> { |
+ public: |
+ enum Result { |
+ OK, |
+ CANCEL |
+ }; |
+ |
+ // ResultCallback will be invoked with Result::Cancel if the user closes the |
+ // MessageBox without clicking on any buttons. |
+ typedef base::Callback<void(Result)> ResultCallback; |
+ |
+ MessageBox(const base::string16& message_label, |
+ const base::string16& ok_label, |
+ const base::string16& cancel_label, |
+ ResultCallback result_callback); |
+ |
+ // Shows the message box. |
+ void Show(); |
+ // Hides the message box. |
+ void Hide(); |
+ |
+ // views::DialogDelegateView interface. |
+ bool Accept() override; |
+ bool Cancel() override; |
+ ui::ModalType GetModalType() const override; |
+ base::string16 GetWindowTitle() const override; |
+ base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
+ void DeleteDelegate() override; |
+ |
+ private: |
+ friend class base::RefCounted<MessageBox>; |
+ ~MessageBox(); |
dcaiafa
2014/10/31 18:05:49
~MessageBox() override;
kelvinp
2014/10/31 21:12:53
Done.
|
+ |
+ const base::string16 message_label_; |
+ const base::string16 ok_label_; |
+ const base::string16 cancel_label_; |
+ ResultCallback result_callback_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MessageBox); |
+}; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_HOST_CHROMEOS_MESSAGE_BOX_H_ |