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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef WEBKIT_GLUE_H__
#define WEBKIT_GLUE_H__
#include <string>
#include <vector>
#ifdef _WIN32
#include <windows.h>
#endif
#include "base/string16.h"
#include "webkit/glue/webplugin.h"
// We do not include the header files for these interfaces since this header
// file is included by code in webkit/port
class SharedCursor;
class WebView;
class WebViewDelegate;
class WebRequest;
class WebFrame;
class WebFrameImpl;
class GURL;
struct _NPNetscapeFuncs;
typedef _NPNetscapeFuncs NPNetscapeFuncs;
#ifdef _WIN32
struct IMLangFontLink2;
#endif
namespace WebCore {
class Document;
class Frame;
} // namespace WebCore
class SkBitmap;
namespace webkit_glue {
//-----------------------------------------------------------------------------
// Functions implemented by JS engines.
void SetJavaScriptFlags(const std::wstring& flags);
void SetRecordPlaybackMode(bool value);
//-----------------------------------------------------------------------------
// Functions implemented by WebKit, called by the embedder:
// Turns on "layout test" mode, which tries to mimic the font and widget sizing
// of the Mac DumpRenderTree.
void SetLayoutTestMode(bool enable);
bool IsLayoutTestMode();
#ifdef _WIN32
// Returns the com object pointer for the FontLink interface. This is the
// default way to do this operation. It can be called directly from
// GetLangFontLink.
IMLangFontLink2* GetLangFontLinkHelper();
// Returns the monitor information corresponding to the window.
// This is the default implementation.
MONITORINFOEX GetMonitorInfoForWindowHelper(HWND window);
#endif
// Returns the text of the document element.
std::wstring DumpDocumentText(WebFrame* web_frame);
// Returns the text of the document element and optionally its child frames.
// If recursive is false, this is equivalent to DumpDocumentText followed by
// a newline. If recursive is true, it recursively dumps all frames as text.
std::wstring DumpFramesAsText(WebFrame* web_frame, bool recursive);
// Returns the renderer's description of its tree (its externalRepresentation).
std::wstring DumpRenderer(WebFrame* web_frame);
// Returns a dump of the scroll position of the webframe.
std::wstring DumpFrameScrollPosition(WebFrame* web_frame, bool recursive);
// Returns a representation of the back/forward list.
void DumpBackForwardList(WebView* view, void* previous_history_item,
std::wstring* result);
// Cleans up state left over from the previous test run.
void ResetBeforeTestRun(WebView* view);
// Returns the WebKit version (major.minor).
std::string GetWebKitVersion();
// Returns the user agent.
const std::string& GetDefaultUserAgent();
// Creates serialized state for the specified URL. This is a variant of
// HistoryItemToString (in glue_serialize) that is used during session restore
// if the saved state is empty.
std::string CreateHistoryStateForURL(const GURL& url);
#ifndef NDEBUG
// Checks various important objects to see if there are any in memory, and
// calls AppendToLog with any leaked objects. Designed to be called on shutdown
void CheckForLeaks();
#endif
// Decodes the image from the data in |image_data| into |image|.
// Returns false if the image could not be decoded.
bool DecodeImage(const std::string& image_data, SkBitmap* image);
//-----------------------------------------------------------------------------
// Functions implemented by the embedder, called by WebKit:
// This function is called to check if the given URL string exists in the
// user's browsing history db. The given URL may NOT be in canonical form and
// it will NOT be null-terminated; use the length instead. This function also
// causes the hostnames' DNS record to be prefetched if is_dns_prefetch_enabled
// is true or document_host matches the URL being checked. The hostname will
// likewise not be null-terminated; use document_host_length instead.
bool HistoryContains(const char16* url, int url_length,
const char* document_host, int document_host_length,
bool is_dns_prefetch_enabled);
// This function is called to request a prefetch of the DNS resolution for the
// embedded URL's hostname. The given URL may NOT be in canonical form and
// it will NOT be null-terminated; use the length instead.
void DnsPrefetchUrl(const char16* url, int url_length);
// This function is called to request a prefetch of the entire URL, loading it
// into our cache for (expected) future needs. The given URL may NOT be in
// canonical form and it will NOT be null-terminated; use the length instead.
void PrecacheUrl(const char16* url, int url_length);
// This function is called to add a line to the application's log file.
void AppendToLog(const char* filename, int line, const char* message);
// Get the mime type (if any) that is associated with the given file extension.
// Returns true if a corresponding mime type exists.
bool GetMimeTypeFromExtension(std::wstring &ext, std::string *mime_type);
// Get the mime type (if any) that is associated with the given file.
// Returns true if a corresponding mime type exists.
bool GetMimeTypeFromFile(const std::wstring &file_path, std::string *mime_type);
// Get the preferred extension (if any) associated with the given mime type.
// Returns true if a corresponding file extension exists.
bool GetPreferredExtensionForMimeType(const std::string& mime_type,
std::wstring *ext);
#ifdef _WIN32
// Returns the com object pointer for the FontLink interface
IMLangFontLink2* GetLangFontLink();
#endif
// Sets a cookie string for the given URL. The policy_url argument indicates
// the URL of the topmost frame, which may be useful for determining whether or
// not to allow this cookie setting. NOTE: the cookie string is a standard
// cookie string of the form "name=value; option1=x; option2=y"
void SetCookie(const GURL& url, const GURL& policy_url,
const std::string& cookie);
// Returns all cookies in the form "a=1; b=2; c=3" for the given URL. NOTE:
// this string should not include any options that may have been specified when
// the cookie was set. Semicolons delimit individual cookies in this context.
std::string GetCookies(const GURL& url, const GURL& policy_url);
// Gather usage statistics from the in-memory cache and inform our host, if
// applicable.
void NotifyCacheStats();
// Glue to get resources from the embedder.
// Gets a localized string given a message id. Returns an empty string if the
// message id is not found.
std::wstring GetLocalizedString(int message_id);
// Returns the raw data for a resource. This resource must have been
// specified as BINDATA in the relevant .rc file.
std::string GetDataResource(int resource_id);
#ifdef _WIN32
// Loads and returns a cursor.
HCURSOR LoadCursor(int cursor_id);
#endif
// Glue to access the clipboard.
// Clear the clipboard. It is usually a good idea to clear the clipboard
// before writing content to the clipboard.
void ClipboardClear();
// Adds UNICODE and ASCII text to the clipboard.
void ClipboardWriteText(const std::wstring& text);
// Adds HTML to the clipboard. The url parameter is optional, but especially
// useful if the HTML fragment contains relative links
void ClipboardWriteHTML(const std::wstring& html, const GURL& url);
// Adds a bookmark to the clipboard
void ClipboardWriteBookmark(const std::wstring& title, const GURL& url);
// Adds a bitmap to the clipboard
void ClipboardWriteBitmap(const SkBitmap& bitmap);
// Used by WebKit to determine whether WebKit wrote the clipboard last
void ClipboardWriteWebSmartPaste();
// Tests whether the clipboard contains a certain format
bool ClipboardIsFormatAvailable(unsigned int format);
// Reads UNICODE text from the clipboard, if available.
void ClipboardReadText(std::wstring* result);
// Reads ASCII text from the clipboard, if available.
void ClipboardReadAsciiText(std::string* result);
// Reads HTML from the clipboard, if available.
void ClipboardReadHTML(std::wstring* markup, GURL* url);
// Gets the directory where the application data and libraries exist. This
// may be a versioned subdirectory, or it may be the same directory as the
// GetExeDirectory(), depending on the embedder's implementation.
// Path is an output parameter to receive the path.
// Returns true if successful, false otherwise.
bool GetApplicationDirectory(std::wstring *path);
// Gets the URL where the inspector's HTML file resides. It must use the
// protocol returned by GetUIResourceProtocol.
GURL GetInspectorURL();
// Gets the protocol that is used for all user interface resources, including
// the Inspector. It must end with "-resource".
std::string GetUIResourceProtocol();
// Gets the directory where the launching executable resides on disk.
// Path is an output parameter to receive the path.
// Returns true if successful, false otherwise.
bool GetExeDirectory(std::wstring *path);
// Embedders implement this function to return the list of plugins to Webkit.
bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins);
// Returns true if the plugins run in the same process as the renderer, and
// false otherwise.
bool IsPluginRunningInRendererProcess();
#ifdef _WIN32
// Asks the browser to load the font.
bool EnsureFontLoaded(HFONT font);
// Returns the monitor information corresponding to the window.
MONITORINFOEX GetMonitorInfoForWindow(HWND window);
#endif
// Functions implemented by webkit_glue for WebKit ----------------------------
// Notifies the embedder that a form element value has changed. The document
// pointer, which MAY BE NULL, indicates the document that owns the form
// element that changed, if any.
void NotifyFormStateChanged(const WebCore::Document* document);
// Returns a bool indicating if the Null plugin should be enabled or not.
bool IsDefaultPluginEnabled();
#ifdef _WIN32
// Downloads the file specified by the URL. On sucess a WM_COPYDATA message
// will be sent to the caller_window.
bool DownloadUrl(const std::string& url, HWND caller_window);
#endif
// Returns the plugin finder URL.
bool GetPluginFinderURL(std::string* plugin_finder_url);
// Returns the locale that this instance of webkit is running as. This is of
// the form language-country (e.g., en-US or pt-BR).
std::wstring GetWebKitLocale();
// Notifies the browser that the current page runs out of JS memory.
void NotifyJSOutOfMemory(WebCore::Frame* frame);
} // namespace webkit_glue
#endif // WEBKIT_GLUE_H__
|