• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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.
4 
5 #ifndef WEBKIT_GLUE_WEBKIT_GLUE_H_
6 #define WEBKIT_GLUE_WEBKIT_GLUE_H_
7 
8 #include "base/basictypes.h"
9 
10 #if defined(OS_WIN)
11 #include <windows.h>
12 #endif
13 
14 #include <string>
15 #include <vector>
16 
17 #include "base/file_path.h"
18 #include "base/platform_file.h"
19 #include "base/string16.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h"
22 #include "ui/base/clipboard/clipboard.h"
23 
24 class GURL;
25 class SkBitmap;
26 
27 namespace base {
28 class StringPiece;
29 }
30 
31 namespace skia {
32 class PlatformCanvas;
33 }
34 
35 namespace WebKit {
36 class WebFrame;
37 class WebString;
38 class WebView;
39 }
40 
41 namespace webkit {
42 namespace npapi {
43 struct WebPluginInfo;
44 }
45 }
46 
47 namespace webkit_glue {
48 
49 
50 //---- BEGIN FUNCTIONS IMPLEMENTED BY WEBKIT/GLUE -----------------------------
51 
52 void SetJavaScriptFlags(const std::string& flags);
53 
54 // Turn on logging for flags in the provided comma delimited list.
55 void EnableWebCoreLogChannels(const std::string& channels);
56 
57 // Returns the text of the document element.
58 string16 DumpDocumentText(WebKit::WebFrame* web_frame);
59 
60 // Returns the text of the document element and optionally its child frames.
61 // If recursive is false, this is equivalent to DumpDocumentText followed by
62 // a newline.  If recursive is true, it recursively dumps all frames as text.
63 string16 DumpFramesAsText(WebKit::WebFrame* web_frame, bool recursive);
64 
65 // Returns the renderer's description of its tree (its externalRepresentation).
66 string16 DumpRenderer(WebKit::WebFrame* web_frame);
67 
68 // Fill the value of counter in the element specified by the id into
69 // counter_value.  Return false when the specified id doesn't exist.
70 bool CounterValueForElementById(WebKit::WebFrame* web_frame,
71                                 const std::string& id,
72                                 string16* counter_value);
73 
74 // Returns the number of page where the specified element will be put.
75 int PageNumberForElementById(WebKit::WebFrame* web_frame,
76                              const std::string& id,
77                              float page_width_in_pixels,
78                              float page_height_in_pixels);
79 
80 // Returns the number of pages to be printed.
81 int NumberOfPages(WebKit::WebFrame* web_frame,
82                   float page_width_in_pixels,
83                   float page_height_in_pixels);
84 
85 // Returns a dump of the scroll position of the webframe.
86 string16 DumpFrameScrollPosition(WebKit::WebFrame* web_frame, bool recursive);
87 
88 // Returns a dump of the given history state suitable for implementing the
89 // dumpBackForwardList command of the layoutTestController.
90 string16 DumpHistoryState(const std::string& history_state, int indent,
91                           bool is_current);
92 
93 // Returns the WebKit version (major.minor).
94 std::string GetWebKitVersion();
95 
96 // Called to override the default user agent with a custom one.  Call this
97 // before anyone actually asks for the user agent in order to prevent
98 // inconsistent behavior.
99 void SetUserAgent(const std::string& new_user_agent);
100 
101 // Returns the user agent to use for the given URL, which is usually the
102 // default user agent but may be overriden by a call to SetUserAgent() (which
103 // should be done at startup).
104 const std::string& GetUserAgent(const GURL& url);
105 
106 // Creates serialized state for the specified URL. This is a variant of
107 // HistoryItemToString (in glue_serialize) that is used during session restore
108 // if the saved state is empty.
109 std::string CreateHistoryStateForURL(const GURL& url);
110 
111 // Removes any form data state from the history state string |content_state|.
112 std::string RemoveFormDataFromHistoryState(const std::string& content_state);
113 
114 // Removes scroll offset from the history state string |content_state|.
115 std::string RemoveScrollOffsetFromHistoryState(
116     const std::string& content_state);
117 
118 #ifndef NDEBUG
119 // Checks various important objects to see if there are any in memory, and
120 // calls AppendToLog with any leaked objects. Designed to be called on shutdown
121 void CheckForLeaks();
122 #endif
123 
124 // Decodes the image from the data in |image_data| into |image|.
125 // Returns false if the image could not be decoded.
126 bool DecodeImage(const std::string& image_data, SkBitmap* image);
127 
128 // Tells the plugin thread to terminate the process forcefully instead of
129 // exiting cleanly.
130 void SetForcefullyTerminatePluginProcess(bool value);
131 
132 // Returns true if the plugin thread should terminate the process forcefully
133 // instead of exiting cleanly.
134 bool ShouldForcefullyTerminatePluginProcess();
135 
136 // File path string conversions.
137 FilePath::StringType WebStringToFilePathString(const WebKit::WebString& str);
138 WebKit::WebString FilePathStringToWebString(const FilePath::StringType& str);
139 FilePath WebStringToFilePath(const WebKit::WebString& str);
140 WebKit::WebString FilePathToWebString(const FilePath& file_path);
141 
142 // File error conversion
143 WebKit::WebFileError PlatformFileErrorToWebFileError(
144     base::PlatformFileError error_code);
145 
146 // Returns a WebCanvas pointer associated with the given Skia canvas.
147 WebKit::WebCanvas* ToWebCanvas(skia::PlatformCanvas*);
148 
149 // Returns the number of currently-active glyph pages this process is using.
150 // There can be many such pages (maps of 256 character -> glyph) so this is
151 // used to get memory usage statistics.
152 int GetGlyphPageCount();
153 
154 //---- END FUNCTIONS IMPLEMENTED BY WEBKIT/GLUE -------------------------------
155 
156 
157 //---- BEGIN FUNCTIONS IMPLEMENTED BY EMBEDDER --------------------------------
158 
159 // This function is called to add a line to the application's log file.
160 void AppendToLog(const char* filename, int line, const char* message);
161 
162 // Glue to get resources from the embedder.
163 
164 // Gets a localized string given a message id.  Returns an empty string if the
165 // message id is not found.
166 string16 GetLocalizedString(int message_id);
167 
168 // Returns the raw data for a resource.  This resource must have been
169 // specified as BINDATA in the relevant .rc file.
170 base::StringPiece GetDataResource(int resource_id);
171 
172 #if defined(OS_WIN)
173 // Loads and returns a cursor.
174 HCURSOR LoadCursor(int cursor_id);
175 #endif
176 
177 // Glue to access the clipboard.
178 
179 // Get a clipboard that can be used to construct a ScopedClipboardWriterGlue.
180 ui::Clipboard* ClipboardGetClipboard();
181 
182 // Tests whether the clipboard contains a certain format
183 bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format,
184                                 ui::Clipboard::Buffer buffer);
185 
186 // Reads the available types from the clipboard, if available.
187 void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer,
188                                  std::vector<string16>* types,
189                                  bool* contains_filenames);
190 
191 // Reads UNICODE text from the clipboard, if available.
192 void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result);
193 
194 // Reads ASCII text from the clipboard, if available.
195 void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result);
196 
197 // Reads HTML from the clipboard, if available.
198 void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
199                        GURL* url);
200 
201 void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data);
202 
203 // Reads one type of data from the clipboard, if available.
204 bool ClipboardReadData(ui::Clipboard::Buffer buffer, const string16& type,
205                        string16* data, string16* metadata);
206 
207 // Reads filenames from the clipboard, if available.
208 bool ClipboardReadFilenames(ui::Clipboard::Buffer buffer,
209                             std::vector<string16>* filenames);
210 
211 // Gets the directory where the application data and libraries exist.  This
212 // may be a versioned subdirectory, or it may be the same directory as the
213 // GetExeDirectory(), depending on the embedder's implementation.
214 // Path is an output parameter to receive the path.
215 // Returns true if successful, false otherwise.
216 bool GetApplicationDirectory(FilePath* path);
217 
218 // Gets the directory where the launching executable resides on disk.
219 // Path is an output parameter to receive the path.
220 // Returns true if successful, false otherwise.
221 bool GetExeDirectory(FilePath* path);
222 
223 // Embedders implement this function to return the list of plugins to Webkit.
224 void GetPlugins(bool refresh,
225                 std::vector<webkit::npapi::WebPluginInfo>* plugins);
226 
227 // Returns true if the plugins run in the same process as the renderer, and
228 // false otherwise.
229 bool IsPluginRunningInRendererProcess();
230 
231 // Returns a bool indicating if the Null plugin should be enabled or not.
232 bool IsDefaultPluginEnabled();
233 
234 // Returns true if the protocol implemented to serve |url| supports features
235 // required by the media engine.
236 bool IsProtocolSupportedForMedia(const GURL& url);
237 
238 #if defined(OS_WIN)
239 // Downloads the file specified by the URL. On sucess a WM_COPYDATA message
240 // will be sent to the caller_window.
241 bool DownloadUrl(const std::string& url, HWND caller_window);
242 #endif
243 
244 // Returns the plugin finder URL.
245 bool GetPluginFinderURL(std::string* plugin_finder_url);
246 
247 // Resolves the proxies for the url, returns true on success.
248 bool FindProxyForUrl(const GURL& url, std::string* proxy_list);
249 
250 // Returns the locale that this instance of webkit is running as.  This is of
251 // the form language-country (e.g., en-US or pt-BR).
252 std::string GetWebKitLocale();
253 
254 // Close current connections.  Used for debugging.
255 void CloseCurrentConnections();
256 
257 // Enable or disable the disk cache.  Used for debugging.
258 void SetCacheMode(bool enabled);
259 
260 // Clear the disk cache.  Used for debugging.
261 // |preserve_ssl_host_info| indicates whether disk cache entries related to
262 // SSL information should be purged.
263 void ClearCache(bool preserve_ssl_host_info);
264 
265 // Clear the host resolver cache.  Used for debugging.
266 void ClearHostResolverCache();
267 
268 // Clear the predictor cache (for DNS prefetch and preconnect).  Used for
269 // debugging.
270 void ClearPredictorCache();
271 
272 // Returns the product version.  E.g., Chrome/4.1.333.0
273 std::string GetProductVersion();
274 
275 // Returns true if the embedder is running in single process mode.
276 bool IsSingleProcess();
277 
278 // Enables/Disables Spdy for requests afterwards. Used for benchmarking.
279 void EnableSpdy(bool enable);
280 
281 // Notifies the browser that the given action has been performed.
282 void UserMetricsRecordAction(const std::string& action);
283 
284 #if !defined(DISABLE_NACL)
285 // Launch NaCl's sel_ldr process.
286 bool LaunchSelLdr(const char* alleged_url, int socket_count, void* imc_handles,
287                   void* nacl_process_handle, int* nacl_process_id);
288 #endif
289 
290 #if defined(OS_LINUX)
291 // Return a read-only file descriptor to the font which best matches the given
292 // properties or -1 on failure.
293 //   charset: specifies the language(s) that the font must cover. See
294 // render_sandbox_host_linux.cc for more information.
295 int MatchFontWithFallback(const std::string& face, bool bold,
296                           bool italic, int charset);
297 
298 // GetFontTable loads a specified font table from an open SFNT file.
299 //   fd: a file descriptor to the SFNT file. The position doesn't matter.
300 //   table: the table in *big-endian* format, or 0 for the whole font file.
301 //   output: a buffer of size output_length that gets the data.  can be 0, in
302 //     which case output_length will be set to the required size in bytes.
303 //   output_length: size of output, if it's not 0.
304 //
305 //   returns: true on success.
306 bool GetFontTable(int fd, uint32_t table, uint8_t* output,
307                   size_t* output_length);
308 #endif
309 
310 // ---- END FUNCTIONS IMPLEMENTED BY EMBEDDER ---------------------------------
311 
312 
313 } // namespace webkit_glue
314 
315 #endif  // WEBKIT_GLUE_WEBKIT_GLUE_H_
316