OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 | |
5 #ifndef COMPONENTS_APP_MODAL_DIALOGS_JAVASCRIPT_APP_MODAL_DIALOG_H_ | |
6 #define COMPONENTS_APP_MODAL_DIALOGS_JAVASCRIPT_APP_MODAL_DIALOG_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/time/time.h" | |
13 #include "components/app_modal_dialogs/app_modal_dialog.h" | |
14 #include "content/public/browser/javascript_dialog_manager.h" | |
15 | |
16 // Extra data for JavaScript dialogs to add Chrome-only features. | |
17 class ChromeJavaScriptDialogExtraData { | |
18 public: | |
19 ChromeJavaScriptDialogExtraData(); | |
20 | |
21 // The time that the last JavaScript dialog was dismissed. | |
22 base::TimeTicks last_javascript_message_dismissal_; | |
23 | |
24 // True if the user has decided to block future JavaScript dialogs. | |
25 bool suppress_javascript_messages_; | |
26 }; | |
27 | |
28 // A controller + model class for JavaScript alert, confirm, prompt, and | |
29 // onbeforeunload dialog boxes. | |
30 class JavaScriptAppModalDialog : public AppModalDialog { | |
31 public: | |
32 typedef std::map<void*, ChromeJavaScriptDialogExtraData> ExtraDataMap; | |
33 | |
34 JavaScriptAppModalDialog( | |
35 content::WebContents* web_contents, | |
36 ExtraDataMap* extra_data_map, | |
37 const base::string16& title, | |
38 content::JavaScriptMessageType javascript_message_type, | |
39 const base::string16& message_text, | |
40 const base::string16& default_prompt_text, | |
41 bool display_suppress_checkbox, | |
42 bool is_before_unload_dialog, | |
43 bool is_reload, | |
44 const content::JavaScriptDialogManager::DialogClosedCallback& callback); | |
45 ~JavaScriptAppModalDialog() override; | |
46 | |
47 // Overridden from AppModalDialog: | |
48 NativeAppModalDialog* CreateNativeDialog() override; | |
49 bool IsJavaScriptModalDialog() override; | |
50 void Invalidate() override; | |
51 | |
52 // Callbacks from NativeDialog when the user accepts or cancels the dialog. | |
53 void OnCancel(bool suppress_js_messages); | |
54 void OnAccept(const base::string16& prompt_text, bool suppress_js_messages); | |
55 | |
56 // NOTE: This is only called under Views, and should be removed. Any critical | |
57 // work should be done in OnCancel or OnAccept. See crbug.com/63732 for more. | |
58 void OnClose(); | |
59 | |
60 // Used only for testing. The dialog will use the given text when notifying | |
61 // its delegate instead of whatever the UI reports. | |
62 void SetOverridePromptText(const base::string16& prompt_text); | |
63 | |
64 // Accessors | |
65 content::JavaScriptMessageType javascript_message_type() const { | |
66 return javascript_message_type_; | |
67 } | |
68 base::string16 message_text() const { return message_text_; } | |
69 base::string16 default_prompt_text() const { return default_prompt_text_; } | |
70 bool display_suppress_checkbox() const { return display_suppress_checkbox_; } | |
71 bool is_before_unload_dialog() const { return is_before_unload_dialog_; } | |
72 bool is_reload() const { return is_reload_; } | |
73 | |
74 private: | |
75 // Notifies the delegate with the result of the dialog. | |
76 void NotifyDelegate(bool success, const base::string16& prompt_text, | |
77 bool suppress_js_messages); | |
78 | |
79 // A map of extra Chrome-only data associated with the delegate_. | |
80 // Can be inspected via extra_data_map_[web_contents_]. | |
81 ExtraDataMap* extra_data_map_; | |
82 | |
83 // Information about the message box is held in the following variables. | |
84 const content::JavaScriptMessageType javascript_message_type_; | |
85 base::string16 message_text_; | |
86 base::string16 default_prompt_text_; | |
87 bool display_suppress_checkbox_; | |
88 bool is_before_unload_dialog_; | |
89 bool is_reload_; | |
90 | |
91 content::JavaScriptDialogManager::DialogClosedCallback callback_; | |
92 | |
93 // Used only for testing. Specifies alternative prompt text that should be | |
94 // used when notifying the delegate, if |use_override_prompt_text_| is true. | |
95 base::string16 override_prompt_text_; | |
96 bool use_override_prompt_text_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog); | |
99 }; | |
100 | |
101 #endif // COMPONENTS_APP_MODAL_DIALOGS_JAVASCRIPT_APP_MODAL_DIALOG_H_ | |
OLD | NEW |