Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h

Issue 7283022: Make a clean interface for dialog callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_ 5 #ifndef CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_
6 #define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_ 6 #define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/compiler_specific.h"
11 #include "base/time.h" 12 #include "base/time.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 14 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
14 #include "content/browser/javascript_dialogs.h" 15 #include "content/browser/javascript_dialogs.h"
15 #include "content/common/notification_observer.h"
16 #include "content/common/notification_registrar.h"
17 16
18 class ExtensionHost; 17 namespace content {
19 class NativeAppModalDialog; 18 class JavaScriptDialogDelegate;
20 class TabContents; 19 }
21 20
22 namespace IPC { 21 namespace IPC {
23 class Message; 22 class Message;
24 } 23 }
25 24
26 // Extra data for JavaScript dialogs to add Chrome-only features. 25 // Extra data for JavaScript dialogs to add Chrome-only features.
27 class ChromeJavaScriptDialogExtraData { 26 class ChromeJavaScriptDialogExtraData {
28 public: 27 public:
29 ChromeJavaScriptDialogExtraData(); 28 ChromeJavaScriptDialogExtraData();
30 29
31 // The time that the last JavaScript dialog was dismissed. 30 // The time that the last JavaScript dialog was dismissed.
32 base::TimeTicks last_javascript_message_dismissal_; 31 base::TimeTicks last_javascript_message_dismissal_;
33 32
34 // True if the user has decided to block future JavaScript dialogs. 33 // True if the user has decided to block future JavaScript dialogs.
35 bool suppress_javascript_messages_; 34 bool suppress_javascript_messages_;
36 }; 35 };
37 36
38 // A controller + model class for JavaScript alert, confirm, prompt, and 37 // A controller + model class for JavaScript alert, confirm, prompt, and
39 // onbeforeunload dialog boxes. 38 // onbeforeunload dialog boxes.
40 class JavaScriptAppModalDialog : public AppModalDialog, 39 class JavaScriptAppModalDialog : public AppModalDialog {
41 public NotificationObserver {
42 public: 40 public:
43 JavaScriptAppModalDialog(content::JavaScriptDialogDelegate* delegate, 41 JavaScriptAppModalDialog(content::JavaScriptDialogDelegate* delegate,
44 ChromeJavaScriptDialogExtraData* extra_data, 42 ChromeJavaScriptDialogExtraData* extra_data,
45 const string16& title, 43 const string16& title,
46 int dialog_flags, 44 int dialog_flags,
47 const string16& message_text, 45 const string16& message_text,
48 const string16& default_prompt_text, 46 const string16& default_prompt_text,
49 bool display_suppress_checkbox, 47 bool display_suppress_checkbox,
50 bool is_before_unload_dialog, 48 bool is_before_unload_dialog,
51 IPC::Message* reply_msg); 49 IPC::Message* reply_msg);
52 virtual ~JavaScriptAppModalDialog(); 50 virtual ~JavaScriptAppModalDialog();
53 51
54 // Overridden from AppModalDialog: 52 // Overridden from AppModalDialog:
55 virtual NativeAppModalDialog* CreateNativeDialog(); 53 virtual NativeAppModalDialog* CreateNativeDialog() OVERRIDE;
56 virtual bool IsJavaScriptModalDialog(); 54 virtual bool IsJavaScriptModalDialog() OVERRIDE;
57 55 virtual void Invalidate() OVERRIDE;
58 content::JavaScriptDialogDelegate* delegate() const { return delegate_; } 56 virtual content::JavaScriptDialogDelegate* delegate() const OVERRIDE;
59 57
60 // Callbacks from NativeDialog when the user accepts or cancels the dialog. 58 // Callbacks from NativeDialog when the user accepts or cancels the dialog.
61 void OnCancel(bool suppress_js_messages); 59 void OnCancel(bool suppress_js_messages);
62 void OnAccept(const string16& prompt_text, bool suppress_js_messages); 60 void OnAccept(const string16& prompt_text, bool suppress_js_messages);
63 61
64 // NOTE: This is only called under Views, and should be removed. Any critical 62 // NOTE: This is only called under Views, and should be removed. Any critical
65 // work should be done in OnCancel or OnAccept. See crbug.com/63732 for more. 63 // work should be done in OnCancel or OnAccept. See crbug.com/63732 for more.
66 void OnClose(); 64 void OnClose();
67 65
68 // Used only for testing. The dialog will use the given text when notifying 66 // Used only for testing. The dialog will use the given text when notifying
69 // its delegate instead of whatever the UI reports. 67 // its delegate instead of whatever the UI reports.
70 void SetOverridePromptText(const string16& prompt_text); 68 void SetOverridePromptText(const string16& prompt_text);
71 69
72 // Accessors 70 // Accessors
73 int dialog_flags() const { return dialog_flags_; } 71 int dialog_flags() const { return dialog_flags_; }
74 string16 message_text() const { return message_text_; } 72 string16 message_text() const { return message_text_; }
75 string16 default_prompt_text() const { return default_prompt_text_; } 73 string16 default_prompt_text() const { return default_prompt_text_; }
76 bool display_suppress_checkbox() const { return display_suppress_checkbox_; } 74 bool display_suppress_checkbox() const { return display_suppress_checkbox_; }
77 bool is_before_unload_dialog() const { return is_before_unload_dialog_; } 75 bool is_before_unload_dialog() const { return is_before_unload_dialog_; }
78 76
79 private: 77 private:
80 // Overridden from NotificationObserver:
81 virtual void Observe(NotificationType type,
82 const NotificationSource& source,
83 const NotificationDetails& details);
84
85 // Initializes for notifications to listen.
86 void InitNotifications();
87
88 // Notifies the delegate with the result of the dialog. 78 // Notifies the delegate with the result of the dialog.
89 void NotifyDelegate(bool success, const string16& prompt_text, 79 void NotifyDelegate(bool success, const string16& prompt_text,
90 bool suppress_js_messages); 80 bool suppress_js_messages);
91 81
92 NotificationRegistrar registrar_;
93
94 // An implementation of the client interface to provide supporting methods
95 // and receive results.
96 content::JavaScriptDialogDelegate* delegate_;
97
98 // The extra Chrome-only data associated with the delegate_. 82 // The extra Chrome-only data associated with the delegate_.
99 ChromeJavaScriptDialogExtraData* extra_data_; 83 ChromeJavaScriptDialogExtraData* extra_data_;
100 84
101 // The client_ as an ExtensionHost, cached for use during notifications that 85 // The client_ as an ExtensionHost, cached for use during notifications that
102 // may arrive after the client has entered its destructor (and is thus 86 // may arrive after the client has entered its destructor (and is thus
103 // treated as a base Delegate). This will be NULL if the |delegate_| is not an 87 // treated as a base Delegate). This will be NULL if the |delegate_| is not an
104 // ExtensionHost. 88 // ExtensionHost.
105 ExtensionHost* extension_host_; 89 ExtensionHost* extension_host_;
106 90
107 // Information about the message box is held in the following variables. 91 // Information about the message box is held in the following variables.
108 int dialog_flags_; 92 int dialog_flags_;
109 string16 message_text_; 93 string16 message_text_;
110 string16 default_prompt_text_; 94 string16 default_prompt_text_;
111 bool display_suppress_checkbox_; 95 bool display_suppress_checkbox_;
112 bool is_before_unload_dialog_; 96 bool is_before_unload_dialog_;
113 IPC::Message* reply_msg_; 97 IPC::Message* reply_msg_;
114 98
115 // Used only for testing. Specifies alternative prompt text that should be 99 // Used only for testing. Specifies alternative prompt text that should be
116 // used when notifying the delegate, if |use_override_prompt_text_| is true. 100 // used when notifying the delegate, if |use_override_prompt_text_| is true.
117 string16 override_prompt_text_; 101 string16 override_prompt_text_;
118 bool use_override_prompt_text_; 102 bool use_override_prompt_text_;
119 103
120 DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog); 104 DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog);
121 }; 105 };
122 106
123 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_ 107 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.cc ('k') | chrome/browser/ui/app_modal_dialogs/js_modal_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698