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