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