OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_APP_MODAL_DIALOG_H_ | 5 #ifndef CHROME_BROWSER_APP_MODAL_DIALOG_H_ |
6 #define CHROME_BROWSER_APP_MODAL_DIALOG_H_ | 6 #define CHROME_BROWSER_APP_MODAL_DIALOG_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/common/notification_observer.h" | 11 #include "chrome/common/notification_observer.h" |
12 #include "chrome/common/notification_registrar.h" | 12 #include "chrome/common/notification_registrar.h" |
13 | 13 |
| 14 // Define NativeDialog type as platform specific dialog view. |
14 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
15 class JavascriptMessageBoxDialog; | 16 class ModalDialogDelegate; |
16 typedef JavascriptMessageBoxDialog* NativeDialog; | 17 typedef ModalDialogDelegate* NativeDialog; |
17 #elif defined(OS_MACOSX) | 18 #elif defined(OS_MACOSX) |
18 #if __OBJC__ | 19 #if __OBJC__ |
19 @class NSAlert; | 20 @class NSAlert; |
20 #else | 21 #else |
21 class NSAlert; | 22 class NSAlert; |
22 #endif | 23 #endif |
23 typedef NSAlert* NativeDialog; | 24 typedef NSAlert* NativeDialog; |
24 #elif defined(OS_POSIX) | 25 #elif defined(OS_POSIX) |
| 26 typedef struct _GtkDialog GtkDialog; |
25 typedef struct _GtkWidget GtkWidget; | 27 typedef struct _GtkWidget GtkWidget; |
| 28 typedef int gint; |
26 typedef GtkWidget* NativeDialog; | 29 typedef GtkWidget* NativeDialog; |
27 #endif | 30 #endif |
28 | 31 |
29 class ExtensionHost; | |
30 class JavaScriptMessageBoxClient; | |
31 class TabContents; | 32 class TabContents; |
32 namespace IPC { | 33 namespace IPC { |
33 class Message; | 34 class Message; |
34 } | 35 } |
35 | 36 |
36 // A controller+model class for javascript alert, confirm, prompt, and | 37 // A controller+model base class for modal dialogs. |
37 // onbeforeunload dialog boxes. |NativeDialog| is a platform specific | 38 class AppModalDialog { |
38 // view. | |
39 class AppModalDialog : public NotificationObserver { | |
40 public: | 39 public: |
41 // A union of data necessary to determine the type of message box to | 40 // A union of data necessary to determine the type of message box to |
42 // show. |dialog_flags| is a MessageBox flag. | 41 // show. |tab_contents| parameter is optional, if provided that tab will be |
43 AppModalDialog(JavaScriptMessageBoxClient* client, | 42 // activated before the modal dialog is displayed. |
44 const std::wstring& title, | 43 AppModalDialog(TabContents* tab_contents, const std::wstring& title); |
45 int dialog_flags, | 44 virtual ~AppModalDialog(); |
46 const std::wstring& message_text, | |
47 const std::wstring& default_prompt_text, | |
48 bool display_suppress_checkbox, | |
49 bool is_before_unload_dialog, | |
50 IPC::Message* reply_msg); | |
51 ~AppModalDialog(); | |
52 | 45 |
53 // Called by the app modal window queue when it is time to show this window. | 46 // Called by the app modal window queue when it is time to show this window. |
54 void ShowModalDialog(); | 47 void ShowModalDialog(); |
55 | 48 |
56 ///////////////////////////////////////////////////////////////////////////// | 49 ///////////////////////////////////////////////////////////////////////////// |
57 // The following methods are platform specific and should be implemented in | 50 // The following methods are platform specific and should be implemented in |
58 // the platform specific .cc files. | 51 // the platform specific .cc files. |
59 // Create the platform specific NativeDialog and display it. When the | 52 // Create the platform specific NativeDialog and display it. When the |
60 // NativeDialog is closed, it should call OnAccept or OnCancel to notify the | 53 // NativeDialog is closed, it should call OnAccept or OnCancel to notify the |
61 // renderer of the user's action. The NativeDialog is also expected to | 54 // renderer of the user's action. The NativeDialog is also expected to |
62 // delete the AppModalDialog associated with it. | 55 // delete the AppModalDialog associated with it. |
63 void CreateAndShowDialog(); | 56 virtual void CreateAndShowDialog(); |
| 57 |
| 58 #if defined(OS_LINUX) |
| 59 virtual void HandleDialogResponse(GtkDialog* dialog, gint response_id) = 0; |
| 60 // Callback for dialog response calls, passes results to specialized |
| 61 // HandleDialogResponse() implementation. |
| 62 static void OnDialogResponse(GtkDialog* dialog, gint response_id, |
| 63 AppModalDialog* app_modal_dialog); |
| 64 #endif |
64 | 65 |
65 // Close the dialog if it is showing. | 66 // Close the dialog if it is showing. |
66 void CloseModalDialog(); | 67 void CloseModalDialog(); |
67 | 68 |
68 // Called by the app modal window queue to activate the window. | 69 // Called by the app modal window queue to activate the window. |
69 void ActivateModalDialog(); | 70 void ActivateModalDialog(); |
70 | 71 |
71 ///////////////////////////////////////////////////////////////////////////// | 72 // Completes dialog handling, shows next modal dialog from the queue. |
72 // Getters so NativeDialog can get information about the message box. | 73 void CompleteDialog(); |
73 JavaScriptMessageBoxClient* client() { | 74 |
74 return client_; | 75 // Dialog window title. |
75 } | |
76 int dialog_flags() { | |
77 return dialog_flags_; | |
78 } | |
79 std::wstring title() { | 76 std::wstring title() { |
80 return title_; | 77 return title_; |
81 } | 78 } |
82 bool is_before_unload_dialog() { | |
83 return is_before_unload_dialog_; | |
84 } | |
85 | |
86 // Callbacks from NativeDialog when the user accepts or cancels the dialog. | |
87 void OnCancel(); | |
88 void OnAccept(const std::wstring& prompt_text, bool suppress_js_messages); | |
89 void OnClose(); | |
90 | 79 |
91 // Helper methods used to query or control the dialog. This is used by | 80 // Helper methods used to query or control the dialog. This is used by |
92 // automation. | 81 // automation. |
93 int GetDialogButtons(); | 82 virtual int GetDialogButtons() = 0; |
94 void AcceptWindow(); | 83 virtual void AcceptWindow() = 0; |
95 void CancelWindow(); | 84 virtual void CancelWindow() = 0; |
96 | 85 |
97 private: | 86 protected: |
98 void InitNotifications(); | 87 // Cleans up the dialog class. |
99 | 88 virtual void Cleanup(); |
100 // NotificationObserver implementation. | 89 // Creates the actual platform specific dialog view class. |
101 virtual void Observe(NotificationType type, | 90 virtual NativeDialog CreateNativeDialog() = 0; |
102 const NotificationSource& source, | |
103 const NotificationDetails& details); | |
104 | |
105 // Cleans up after the dialog closes for any reason: sends close | |
106 // notification and re-enables input events. | |
107 void Cleanup(); | |
108 | |
109 NotificationRegistrar registrar_; | |
110 | 91 |
111 // A reference to the platform native dialog box. | 92 // A reference to the platform native dialog box. |
112 NativeDialog dialog_; | 93 NativeDialog dialog_; |
113 | 94 |
114 // An implementation of the client interface to provide supporting methods | 95 // Parent tab contents. |
115 // and receive results. | 96 TabContents* tab_contents_; |
116 JavaScriptMessageBoxClient* client_; | |
117 | 97 |
118 // The client_ as an ExtensionHost, cached for use during notifications that | 98 // Information about the message box is held in the following variables. |
119 // may arrive after the client has entered its destructor (and is thus | 99 std::wstring title_; |
120 // treated as a base JavaScriptMessageBoxClient). This will be NULL if the | |
121 // client is not an ExtensionHost. | |
122 TabContents* tab_contents_; | |
123 ExtensionHost* extension_host_; | |
124 | 100 |
125 // True if the dialog should no longer be shown, e.g. because the underlying | 101 // True if the dialog should no longer be shown, e.g. because the underlying |
126 // tab navigated away while the dialog was queued. | 102 // tab navigated away while the dialog was queued. |
127 bool skip_this_dialog_; | 103 bool skip_this_dialog_; |
128 | |
129 // Information about the message box is held in the following variables. | |
130 std::wstring title_; | |
131 int dialog_flags_; | |
132 std::wstring message_text_; | |
133 std::wstring default_prompt_text_; | |
134 bool display_suppress_checkbox_; | |
135 bool is_before_unload_dialog_; | |
136 IPC::Message* reply_msg_; | |
137 }; | 104 }; |
138 | 105 |
139 #endif // CHROME_BROWSER_APP_MODAL_DIALOG_H_ | 106 #endif // CHROME_BROWSER_APP_MODAL_DIALOG_H_ |
OLD | NEW |