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

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

Issue 7096016: Remove JS dialog dependency from content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: one more DEPS item removal Created 9 years, 6 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/utf_string_conversions.h"
12 #include "build/build_config.h" 11 #include "build/build_config.h"
13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 12 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
13 #include "content/browser/javascript_dialog_delegate.h"
14 #include "content/common/notification_observer.h" 14 #include "content/common/notification_observer.h"
15 #include "content/common/notification_registrar.h" 15 #include "content/common/notification_registrar.h"
16 #include "ui/gfx/native_widget_types.h"
17 16
18 class ExtensionHost; 17 class ExtensionHost;
19 class NativeAppModalDialog; 18 class NativeAppModalDialog;
20 class TabContents; 19 class TabContents;
21 20
22 namespace IPC { 21 namespace IPC {
23 class Message; 22 class Message;
24 } 23 }
25 24
26 class JavaScriptAppModalDialogDelegate { 25 // The callback interface for JavaScript dialogs. Extends the content/ version
26 // to add Chrome-only features.
27 class ChromeJavaScriptDialogDelegate
28 : public content::JavaScriptDialogDelegate {
27 public: 29 public:
28 // AppModalDialog calls this when the dialog is closed. 30 // Indicates whether additional dialogs should be suppressed.
29 virtual void OnMessageBoxClosed(IPC::Message* reply_msg, 31 virtual void SetSuppressDialogs(bool suppress_dialogs) = 0;
30 bool success,
31 const std::wstring& prompt) = 0;
32
33 // Indicates whether additional message boxes should be suppressed.
34 virtual void SetSuppressMessageBoxes(bool suppress_message_boxes) = 0;
35
36 // Returns the root native window with which the message box is associated.
37 virtual gfx::NativeWindow GetMessageBoxRootWindow() = 0;
38
39 // Returns the TabContents or ExtensionHost associated with this message
40 // box -- in practice, the object implementing this interface. Exactly one
41 // of these must be non-NULL; behavior is undefined (read: it'll probably
42 // crash) if that is not the case.
43 virtual TabContents* AsTabContents() = 0;
44 virtual ExtensionHost* AsExtensionHost() = 0;
45
46 protected:
47 virtual ~JavaScriptAppModalDialogDelegate() {}
48 }; 32 };
49 33
50 // A controller + model class for JavaScript alert, confirm, prompt, and 34 // A controller + model class for JavaScript alert, confirm, prompt, and
51 // onbeforeunload dialog boxes. 35 // onbeforeunload dialog boxes.
52 class JavaScriptAppModalDialog : public AppModalDialog, 36 class JavaScriptAppModalDialog : public AppModalDialog,
53 public NotificationObserver { 37 public NotificationObserver {
54 public: 38 public:
55 JavaScriptAppModalDialog(JavaScriptAppModalDialogDelegate* delegate, 39 JavaScriptAppModalDialog(ChromeJavaScriptDialogDelegate* delegate,
56 const std::wstring& title, 40 const string16& title,
57 int dialog_flags, 41 int dialog_flags,
58 const std::wstring& message_text, 42 const string16& message_text,
59 const std::wstring& default_prompt_text, 43 const string16& default_prompt_text,
60 bool display_suppress_checkbox, 44 bool display_suppress_checkbox,
61 bool is_before_unload_dialog, 45 bool is_before_unload_dialog,
62 IPC::Message* reply_msg); 46 IPC::Message* reply_msg);
63 virtual ~JavaScriptAppModalDialog(); 47 virtual ~JavaScriptAppModalDialog();
64 48
65 // Overridden from AppModalDialog: 49 // Overridden from AppModalDialog:
66 virtual NativeAppModalDialog* CreateNativeDialog(); 50 virtual NativeAppModalDialog* CreateNativeDialog();
67 virtual bool IsJavaScriptModalDialog(); 51 virtual bool IsJavaScriptModalDialog();
68 52
69 JavaScriptAppModalDialogDelegate* delegate() const { return delegate_; } 53 ChromeJavaScriptDialogDelegate* delegate() const { return delegate_; }
70 54
71 // Callbacks from NativeDialog when the user accepts or cancels the dialog. 55 // Callbacks from NativeDialog when the user accepts or cancels the dialog.
72 void OnCancel(bool suppress_js_messages); 56 void OnCancel(bool suppress_js_messages);
73 void OnAccept(const std::wstring& prompt_text, bool suppress_js_messages); 57 void OnAccept(const string16& prompt_text, bool suppress_js_messages);
74 58
75 // NOTE: This is only called under Views, and should be removed. Any critical 59 // NOTE: This is only called under Views, and should be removed. Any critical
76 // work should be done in OnCancel or OnAccept. See crbug.com/63732 for more. 60 // work should be done in OnCancel or OnAccept. See crbug.com/63732 for more.
77 void OnClose(); 61 void OnClose();
78 62
79 // Used only for testing. The dialog will use the given text when notifying 63 // Used only for testing. The dialog will use the given text when notifying
80 // its delegate instead of whatever the UI reports. 64 // its delegate instead of whatever the UI reports.
81 void SetOverridePromptText(const string16& prompt_text); 65 void SetOverridePromptText(const string16& prompt_text);
82 66
83 // Accessors 67 // Accessors
84 int dialog_flags() const { return dialog_flags_; } 68 int dialog_flags() const { return dialog_flags_; }
85 std::wstring message_text() const { return message_text_; } 69 string16 message_text() const { return message_text_; }
86 std::wstring default_prompt_text() const { 70 string16 default_prompt_text() const { return default_prompt_text_; }
87 return UTF16ToWideHack(default_prompt_text_);
88 }
89 bool display_suppress_checkbox() const { return display_suppress_checkbox_; } 71 bool display_suppress_checkbox() const { return display_suppress_checkbox_; }
90 bool is_before_unload_dialog() const { return is_before_unload_dialog_; } 72 bool is_before_unload_dialog() const { return is_before_unload_dialog_; }
91 73
92 private: 74 private:
93 // Overridden from NotificationObserver: 75 // Overridden from NotificationObserver:
94 virtual void Observe(NotificationType type, 76 virtual void Observe(NotificationType type,
95 const NotificationSource& source, 77 const NotificationSource& source,
96 const NotificationDetails& details); 78 const NotificationDetails& details);
97 79
98 // Initializes for notifications to listen. 80 // Initializes for notifications to listen.
99 void InitNotifications(); 81 void InitNotifications();
100 82
101 // Notifies the delegate with the result of the dialog. 83 // Notifies the delegate with the result of the dialog.
102 void NotifyDelegate(bool success, const std::wstring& prompt_text, 84 void NotifyDelegate(bool success, const string16& prompt_text,
103 bool suppress_js_messages); 85 bool suppress_js_messages);
104 86
105 NotificationRegistrar registrar_; 87 NotificationRegistrar registrar_;
106 88
107 // An implementation of the client interface to provide supporting methods 89 // An implementation of the client interface to provide supporting methods
108 // and receive results. 90 // and receive results.
109 JavaScriptAppModalDialogDelegate* delegate_; 91 ChromeJavaScriptDialogDelegate* delegate_;
110 92
111 // The client_ as an ExtensionHost, cached for use during notifications that 93 // The client_ as an ExtensionHost, cached for use during notifications that
112 // may arrive after the client has entered its destructor (and is thus 94 // may arrive after the client has entered its destructor (and is thus
113 // treated as a base Delegate). This will be NULL if the |delegate_| is not an 95 // treated as a base Delegate). This will be NULL if the |delegate_| is not an
114 // ExtensionHost. 96 // ExtensionHost.
115 ExtensionHost* extension_host_; 97 ExtensionHost* extension_host_;
116 98
117 // Information about the message box is held in the following variables. 99 // Information about the message box is held in the following variables.
118 int dialog_flags_; 100 int dialog_flags_;
119 std::wstring message_text_; 101 string16 message_text_;
120 string16 default_prompt_text_; 102 string16 default_prompt_text_;
121 bool display_suppress_checkbox_; 103 bool display_suppress_checkbox_;
122 bool is_before_unload_dialog_; 104 bool is_before_unload_dialog_;
123 IPC::Message* reply_msg_; 105 IPC::Message* reply_msg_;
124 106
125 // Used only for testing. Specifies alternative prompt text that should be 107 // Used only for testing. Specifies alternative prompt text that should be
126 // used when notifying the delegate, if |use_override_prompt_text_| is true. 108 // used when notifying the delegate, if |use_override_prompt_text_| is true.
127 string16 override_prompt_text_; 109 string16 override_prompt_text_;
128 bool use_override_prompt_text_; 110 bool use_override_prompt_text_;
129 111
130 DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog); 112 DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog);
131 }; 113 };
132 114
133 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_ 115 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698