blob: 40e3a9b38d7bb03161a1a62a093b7b00a9288349 (
plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
// Copyright (c) 2006-2008 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 Navigator_h
#define Navigator_h
#include "Language.h"
#include "CookieJar.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "Document.h"
#include "Settings.h"
#include "PluginInfoStore.h"
#include <wtf/RefCounted.h>
// Navigator strings copied from KJS, must be updated whenever
// Apple updated theirs.
#ifndef WEBCORE_NAVIGATOR_PLATFORM
#if PLATFORM(MAC) && PLATFORM(PPC)
#define WEBCORE_NAVIGATOR_PLATFORM "MacPPC"
#elif PLATFORM(MAC) && PLATFORM(X86)
#define WEBCORE_NAVIGATOR_PLATFORM "MacIntel"
#elif PLATFORM(WIN_OS)
#define WEBCORE_NAVIGATOR_PLATFORM "Win32"
#else
#define WEBCORE_NAVIGATOR_PLATFORM ""
#endif
#endif // ifndef WEBCORE_NAVIGATOR_PLATFORM
#ifndef WEBCORE_NAVIGATOR_PRODUCT
#define WEBCORE_NAVIGATOR_PRODUCT "Gecko"
#endif // ifndef WEBCORE_NAVIGATOR_PRODUCT
#ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
#define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
#endif // ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
#ifndef WEBCORE_NAVIGATOR_VENDOR
#define WEBCORE_NAVIGATOR_VENDOR "Apple Computer, Inc."
#endif // ifndef WEBCORE_NAVIGATOR_VENDOR
#ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
#define WEBCORE_NAVIGATOR_VENDOR_SUB ""
#endif // ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
namespace WebCore {
class Plugin;
class Navigator;
// The following two classes (MimeType and Plugin) are wrappers around
// MimeClassInfo and PluginInfo structs defined by WebKit. These are created
// by PluginInfoStore::createPluginInfoForPluginAtIndex and are responsible
// for cleaning up *info objects on deletion. The cleanup for MimeClassInfo
// as well as PluginInfo is done by Plugin wrapper because each Plugin has its
// own list of supported mime_types that should not be needed once the plugin
// is gone.
class MimeType : public RefCounted<MimeType> {
public:
explicit MimeType(MimeClassInfo* info, Plugin* plugin)
: m_info(info), m_plugin(plugin) { }
String description() const { return m_info->desc; }
Plugin* enabledPlugin() const { return m_plugin; }
String suffixes() const { return m_info->suffixes; }
String type() const { return m_info->type; }
private:
MimeClassInfo* m_info;
Plugin* m_plugin;
};
class Plugin : public RefCounted<Plugin> {
public:
explicit Plugin(PluginInfo* info) : m_info(info) {
}
~Plugin() {
if (m_info) {
for (size_t i = 0; i < m_info->mimes.size(); i++) {
if (m_info->mimes[i]) {
delete m_info->mimes[i];
m_info->mimes[i] = NULL;
}
}
delete m_info;
m_info = NULL;
}
}
String description() const { return m_info->desc; }
String filename() const { return m_info->file; }
String name() const { return m_info->name; }
int length() const { return m_info->mimes.size(); }
MimeType* item(int index) {
if (index >= 0 && index < length())
return new MimeType(m_info->mimes[index], this);
return NULL;
}
MimeType* namedItem(const String& name) {
for (int i = 0; i < length(); ++i) {
MimeClassInfo* m = m_info->mimes[i];
if (m->type == name)
return new MimeType(m, this);
}
return NULL;
}
private:
PluginInfo* m_info;
};
template<class T>
class ArrayOf {
public:
~ArrayOf() {
// release contents
Clear();
}
int length() const {
return m_contents.size();
}
T* item(int index) {
if (index >= 0 && index < length())
return m_contents[index];
return NULL;
}
protected:
Vector<T*> m_contents;
private:
void Add(T* el) {
el->ref();
m_contents.append(el);
}
void Clear() {
while (m_contents.size() > 0) {
m_contents[0]->deref();
m_contents.remove(0);
}
}
friend class Navigator;
};
class MimeTypeArray : public ArrayOf<MimeType>,
public RefCounted<MimeTypeArray> {
public:
MimeType* namedItem(const String& name) {
for (int i = 0; i < length(); ++i) {
if (m_contents[i]->type() == name)
return m_contents[i];
}
return NULL;
}
};
class PluginArray : public ArrayOf<Plugin>, public RefCounted<PluginArray> {
public:
explicit PluginArray(Navigator* nav) : m_navigator(nav) { }
Plugin* namedItem(const String& name) {
for (int i = 0; i < length(); ++i) {
if (m_contents[i]->name() == name)
return m_contents[i];
}
return NULL;
}
void refresh(bool reloadDocuments);
private:
Navigator* m_navigator;
};
class Navigator : public RefCounted<Navigator> {
public:
static PassRefPtr<Navigator> create(Frame* frame)
{
return adoptRef(new Navigator(frame));
}
~Navigator();
String appCodeName() const { return "Mozilla"; }
String appName() const { return "Netscape"; }
String appVersion() const {
if (!m_frame)
return String();
KURL url;
if (m_frame->document()) {
url = m_frame->document()->url();
}
const String user_agent = m_frame->loader()->userAgent(url);
return user_agent.substring(user_agent.find('/') + 1);
}
String language() { return defaultLanguage(); }
MimeTypeArray* mimeTypes() {
if (!m_frame)
return NULL;
if (!m_mimetypes)
Initialize(false);
return m_mimetypes.get();
}
String platform() const { return WEBCORE_NAVIGATOR_PLATFORM; }
String vendor() const { return WEBCORE_NAVIGATOR_VENDOR; }
String vendorSub() const { return WEBCORE_NAVIGATOR_VENDOR_SUB; }
String product() const { return WEBCORE_NAVIGATOR_PRODUCT; }
String productSub() const { return WEBCORE_NAVIGATOR_PRODUCT_SUB; }
PluginArray* plugins() {
if (!m_frame)
return NULL;
if (!m_plugins)
Initialize(false);
return m_plugins.get();
}
String userAgent() const {
if (!m_frame)
return String();
KURL url;
if (m_frame->document()) {
url = m_frame->document()->url();
}
return m_frame->loader()->userAgent(url);
}
bool cookieEnabled() {
if (!m_frame)
return false;
return cookiesEnabled(m_frame->document());
}
bool javaEnabled() {
if (!m_frame)
return false;
return m_frame->settings()->isJavaEnabled();
}
Frame* frame() { return m_frame; }
void disconnectFrame() { m_frame = NULL; }
private:
Navigator(Frame* frame);
Frame* m_frame;
RefPtr<MimeTypeArray> m_mimetypes;
RefPtr<PluginArray> m_plugins;
void Initialize(bool refresh);
friend class PluginArray; // need to call Refresh
void Refresh(bool reload);
};
} // namespace WebCore
#endif
|