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