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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// Copyright (c) 2009 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_APP_MODAL_DIALOG_H_
#define CHROME_BROWSER_APP_MODAL_DIALOG_H_
#include <string>
#include "build/build_config.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#if defined(OS_WIN)
class JavascriptMessageBoxDialog;
typedef JavascriptMessageBoxDialog* NativeDialog;
#elif defined(OS_MACOSX)
#if __OBJC__
@class NSAlert;
#else
class NSAlert;
#endif
typedef NSAlert* NativeDialog;
#elif defined(OS_POSIX)
typedef struct _GtkWidget GtkWidget;
typedef GtkWidget* NativeDialog;
#endif
class ExtensionHost;
class JavaScriptMessageBoxClient;
class TabContents;
namespace IPC {
class Message;
}
// A controller+model class for javascript alert, confirm, prompt, and
// onbeforeunload dialog boxes. |NativeDialog| is a platform specific
// view.
class AppModalDialog : public NotificationObserver {
public:
// A union of data necessary to determine the type of message box to
// show. |dialog_flags| is a MessageBox flag.
AppModalDialog(JavaScriptMessageBoxClient* client,
const std::wstring& title,
int dialog_flags,
const std::wstring& message_text,
const std::wstring& default_prompt_text,
bool display_suppress_checkbox,
bool is_before_unload_dialog,
IPC::Message* reply_msg);
~AppModalDialog();
// Called by the app modal window queue when it is time to show this window.
void ShowModalDialog();
/////////////////////////////////////////////////////////////////////////////
// The following methods are platform specific and should be implemented in
// the platform specific .cc files.
// Create the platform specific NativeDialog and display it. When the
// NativeDialog is closed, it should call OnAccept or OnCancel to notify the
// renderer of the user's action. The NativeDialog is also expected to
// delete the AppModalDialog associated with it.
void CreateAndShowDialog();
// Close the dialog if it is showing.
void CloseModalDialog();
// Called by the app modal window queue to activate the window.
void ActivateModalDialog();
/////////////////////////////////////////////////////////////////////////////
// Getters so NativeDialog can get information about the message box.
JavaScriptMessageBoxClient* client() {
return client_;
}
int dialog_flags() {
return dialog_flags_;
}
std::wstring title() {
return title_;
}
bool is_before_unload_dialog() {
return is_before_unload_dialog_;
}
// Callbacks from NativeDialog when the user accepts or cancels the dialog.
void OnCancel();
void OnAccept(const std::wstring& prompt_text, bool suppress_js_messages);
void OnClose();
// Helper methods used to query or control the dialog. This is used by
// automation.
int GetDialogButtons();
void AcceptWindow();
void CancelWindow();
private:
void InitNotifications();
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
// Cleans up after the dialog closes for any reason: sends close
// notification and re-enables input events.
void Cleanup();
NotificationRegistrar registrar_;
// A reference to the platform native dialog box.
NativeDialog dialog_;
// An implementation of the client interface to provide supporting methods
// and receive results.
JavaScriptMessageBoxClient* client_;
// 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 JavaScriptMessageBoxClient). This will be NULL if the
// client is not an ExtensionHost.
TabContents* tab_contents_;
ExtensionHost* extension_host_;
// True if the dialog should no longer be shown, e.g. because the underlying
// tab navigated away while the dialog was queued.
bool skip_this_dialog_;
// Information about the message box is held in the following variables.
std::wstring title_;
int dialog_flags_;
std::wstring message_text_;
std::wstring default_prompt_text_;
bool display_suppress_checkbox_;
bool is_before_unload_dialog_;
IPC::Message* reply_msg_;
};
#endif // CHROME_BROWSER_APP_MODAL_DIALOG_H_
|