Chromium Code Reviews| 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 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 | 82 // An implementation of the client interface to provide supporting methods |
| 95 // and receive results. | 83 // and receive results. |
| 96 content::JavaScriptDialogDelegate* delegate_; | 84 content::JavaScriptDialogDelegate* delegate_; |
|
Evan Martin
2011/06/29 22:01:52
This is confusing; AppModalDialog already has a pr
Avi (use Gerrit)
2011/06/29 22:09:29
Right, but this as a subclass requires the expande
Evan Martin
2011/06/29 22:53:09
I polled my office and they came up with:
content
Avi (use Gerrit)
2011/06/29 23:19:48
You were objecting to the storage rather than the
| |
| 97 | 85 |
| 98 // The extra Chrome-only data associated with the delegate_. | 86 // The extra Chrome-only data associated with the delegate_. |
| 99 ChromeJavaScriptDialogExtraData* extra_data_; | 87 ChromeJavaScriptDialogExtraData* extra_data_; |
| 100 | 88 |
| 101 // The client_ as an ExtensionHost, cached for use during notifications that | 89 // The client_ as an ExtensionHost, cached for use during notifications that |
| 102 // may arrive after the client has entered its destructor (and is thus | 90 // 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 | 91 // treated as a base Delegate). This will be NULL if the |delegate_| is not an |
| 104 // ExtensionHost. | 92 // ExtensionHost. |
| 105 ExtensionHost* extension_host_; | 93 ExtensionHost* extension_host_; |
| 106 | 94 |
| 107 // Information about the message box is held in the following variables. | 95 // Information about the message box is held in the following variables. |
| 108 int dialog_flags_; | 96 int dialog_flags_; |
| 109 string16 message_text_; | 97 string16 message_text_; |
| 110 string16 default_prompt_text_; | 98 string16 default_prompt_text_; |
| 111 bool display_suppress_checkbox_; | 99 bool display_suppress_checkbox_; |
| 112 bool is_before_unload_dialog_; | 100 bool is_before_unload_dialog_; |
| 113 IPC::Message* reply_msg_; | 101 IPC::Message* reply_msg_; |
| 114 | 102 |
| 115 // Used only for testing. Specifies alternative prompt text that should be | 103 // Used only for testing. Specifies alternative prompt text that should be |
| 116 // used when notifying the delegate, if |use_override_prompt_text_| is true. | 104 // used when notifying the delegate, if |use_override_prompt_text_| is true. |
| 117 string16 override_prompt_text_; | 105 string16 override_prompt_text_; |
| 118 bool use_override_prompt_text_; | 106 bool use_override_prompt_text_; |
| 119 | 107 |
| 120 DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog); | 108 DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog); |
| 121 }; | 109 }; |
| 122 | 110 |
| 123 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_ | 111 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_JS_MODAL_DIALOG_H_ |
| OLD | NEW |