OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_ | 5 #ifndef CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_ |
6 #define CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_ | 6 #define CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "ui/gfx/native_widget_types.h" | 10 #include "ui/gfx/native_widget_types.h" |
11 | 11 |
12 class ExtensionHost; | 12 class ExtensionHost; |
13 class GURL; | 13 class GURL; |
14 class Profile; | 14 class Profile; |
15 class TabContents; | 15 class TabContents; |
16 | 16 |
17 namespace IPC { | 17 namespace IPC { |
18 class Message; | 18 class Message; |
19 } | 19 } |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
| 23 class DialogDelegate { |
| 24 public: |
| 25 // Returns the root native window with which to associate the dialog. |
| 26 virtual gfx::NativeWindow GetDialogRootWindow() = 0; |
| 27 |
| 28 // Called right before the dialog is shown. |
| 29 virtual void OnDialogShown() {} |
| 30 |
| 31 protected: |
| 32 virtual ~DialogDelegate() {} |
| 33 }; |
| 34 |
23 // A class that invokes a JavaScript dialog must implement this interface to | 35 // A class that invokes a JavaScript dialog must implement this interface to |
24 // allow the dialog implementation to get needed information and return results. | 36 // allow the dialog implementation to get needed information and return results. |
25 class JavaScriptDialogDelegate { | 37 class JavaScriptDialogDelegate : public DialogDelegate { |
26 public: | 38 public: |
27 // This callback is invoked when the dialog is closed. | 39 // This callback is invoked when the dialog is closed. |
28 virtual void OnDialogClosed(IPC::Message* reply_msg, | 40 virtual void OnDialogClosed(IPC::Message* reply_msg, |
29 bool success, | 41 bool success, |
30 const string16& user_input) = 0; | 42 const string16& user_input) = 0; |
31 | 43 |
32 // Returns the root native window with which to associate the dialog. | |
33 virtual gfx::NativeWindow GetDialogRootWindow() = 0; | |
34 | |
35 // Returns the TabContents implementing this delegate, or NULL if there is | |
36 // none. TODO(avi): This breaks encapsulation and in general sucks; figure out | |
37 // a better way of doing this. | |
38 virtual TabContents* AsTabContents() = 0; | |
39 | |
40 // Returns the ExtensionHost implementing this delegate, or NULL if there is | |
41 // none. TODO(avi): This is even suckier than AsTabContents above as it breaks | |
42 // layering; figure out a better way of doing this. http://crbug.com/84604 | |
43 virtual ExtensionHost* AsExtensionHost() = 0; | |
44 | |
45 protected: | 44 protected: |
46 virtual ~JavaScriptDialogDelegate() {} | 45 virtual ~JavaScriptDialogDelegate() {} |
47 }; | 46 }; |
48 | 47 |
49 | |
50 // An interface consisting of methods that can be called to produce JavaScript | 48 // An interface consisting of methods that can be called to produce JavaScript |
51 // dialogs. | 49 // dialogs. |
52 class JavaScriptDialogCreator { | 50 class JavaScriptDialogCreator { |
53 public: | 51 public: |
54 enum TitleType { | 52 enum TitleType { |
55 DIALOG_TITLE_NONE, | 53 DIALOG_TITLE_NONE, |
56 DIALOG_TITLE_PLAIN_STRING, | 54 DIALOG_TITLE_PLAIN_STRING, |
57 DIALOG_TITLE_FORMATTED_URL | 55 DIALOG_TITLE_FORMATTED_URL |
58 }; | 56 }; |
59 | 57 |
60 // Displays a JavaScript dialog. |did_suppress_message| will not be nil; if | 58 // Displays a JavaScript dialog. |did_suppress_message| will not be nil; if |
61 // |true| is returned in it, the caller will handle faking the reply. | 59 // |true| is returned in it, the caller will handle faking the reply. |
62 virtual void RunJavaScriptDialog(JavaScriptDialogDelegate* delegate, | 60 virtual void RunJavaScriptDialog(JavaScriptDialogDelegate* delegate, |
63 TitleType title_type, | 61 TitleType title_type, |
64 const string16& title, | 62 const string16& title, |
65 int dialog_flags, | 63 int dialog_flags, |
66 const string16& message_text, | 64 const string16& message_text, |
67 const string16& default_prompt_text, | 65 const string16& default_prompt_text, |
68 IPC::Message* reply_message, | 66 IPC::Message* reply_message, |
69 bool* did_suppress_message) = 0; | 67 bool* did_suppress_message) = 0; |
70 | 68 |
71 // Displays a dialog asking the user if they want to leave a page. | 69 // Displays a dialog asking the user if they want to leave a page. |
72 virtual void RunBeforeUnloadDialog(JavaScriptDialogDelegate* delegate, | 70 virtual void RunBeforeUnloadDialog(JavaScriptDialogDelegate* delegate, |
73 const string16& message_text, | 71 const string16& message_text, |
74 IPC::Message* reply_message) = 0; | 72 IPC::Message* reply_message) = 0; |
75 | 73 |
76 // Resets any saved JavaScript dialog state for the delegate. | 74 // Cancels all pending dialogs and resets any saved JavaScript dialog state |
| 75 // for the delegate. |
77 virtual void ResetJavaScriptState(JavaScriptDialogDelegate* delegate) = 0; | 76 virtual void ResetJavaScriptState(JavaScriptDialogDelegate* delegate) = 0; |
78 | 77 |
79 protected: | 78 protected: |
80 virtual ~JavaScriptDialogCreator() {} | 79 virtual ~JavaScriptDialogCreator() {} |
81 }; | 80 }; |
82 | 81 |
83 } // namespace content | 82 } // namespace content |
84 | 83 |
85 #endif // CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_ | 84 #endif // CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_ |
OLD | NEW |