|
1 /* |
|
2 * Copyright (C) 2009 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
8 * * Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * * Redistributions in binary form must reproduce the above |
|
11 * copyright notice, this list of conditions and the following disclaimer |
|
12 * in the documentation and/or other materials provided with the |
|
13 * distribution. |
|
14 * * Neither the name of Google Inc. nor the names of its |
|
15 * contributors may be used to endorse or promote products derived from |
|
16 * this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 #include "config.h" |
|
32 #include "ChromiumBridge.h" |
|
33 |
|
34 #include <googleurl/src/url_util.h> |
|
35 |
|
36 #include "Chrome.h" |
|
37 #include "ChromeClientImpl.h" |
|
38 #include "WebClipboard.h" |
|
39 #include "WebCookie.h" |
|
40 #include "WebCookieJar.h" |
|
41 #include "WebCursorInfo.h" |
|
42 #include "WebData.h" |
|
43 #include "WebDragData.h" |
|
44 #include "WebFileSystem.h" |
|
45 #include "WebFrameClient.h" |
|
46 #include "WebFrameImpl.h" |
|
47 #include "WebImage.h" |
|
48 #include "WebKit.h" |
|
49 #include "WebKitClient.h" |
|
50 #include "WebMimeRegistry.h" |
|
51 #include "WebPluginContainerImpl.h" |
|
52 #include "WebPluginListBuilderImpl.h" |
|
53 #include "WebSandboxSupport.h" |
|
54 #include "WebScreenInfo.h" |
|
55 #include "WebString.h" |
|
56 #include "WebURL.h" |
|
57 #include "WebVector.h" |
|
58 #include "WebViewClient.h" |
|
59 #include "WebViewImpl.h" |
|
60 #include "WebWorkerClientImpl.h" |
|
61 |
|
62 #if OS(WINDOWS) |
|
63 #include "WebRect.h" |
|
64 #include "WebThemeEngine.h" |
|
65 #endif |
|
66 |
|
67 #if OS(LINUX) |
|
68 #include "WebFontInfo.h" |
|
69 #include "WebFontRenderStyle.h" |
|
70 #endif |
|
71 |
|
72 #if WEBKIT_USING_SKIA |
|
73 #include "NativeImageSkia.h" |
|
74 #endif |
|
75 |
|
76 #include "BitmapImage.h" |
|
77 #include "Cookie.h" |
|
78 #include "FrameView.h" |
|
79 #include "GraphicsContext.h" |
|
80 #include "IndexedDatabaseProxy.h" |
|
81 #include "KURL.h" |
|
82 #include "NotImplemented.h" |
|
83 #include "PlatformContextSkia.h" |
|
84 #include "PluginData.h" |
|
85 #include "SharedBuffer.h" |
|
86 #include "WebGeolocationServiceBridgeImpl.h" |
|
87 #include "Worker.h" |
|
88 #include "WorkerContextProxy.h" |
|
89 #include <wtf/Assertions.h> |
|
90 |
|
91 // We are part of the WebKit implementation. |
|
92 using namespace WebKit; |
|
93 |
|
94 namespace WebCore { |
|
95 |
|
96 static ChromeClientImpl* toChromeClientImpl(Widget* widget) |
|
97 { |
|
98 if (!widget) |
|
99 return 0; |
|
100 |
|
101 FrameView* view; |
|
102 if (widget->isFrameView()) |
|
103 view = static_cast<FrameView*>(widget); |
|
104 else if (widget->parent() && widget->parent()->isFrameView()) |
|
105 view = static_cast<FrameView*>(widget->parent()); |
|
106 else |
|
107 return 0; |
|
108 |
|
109 Page* page = view->frame() ? view->frame()->page() : 0; |
|
110 if (!page) |
|
111 return 0; |
|
112 |
|
113 return static_cast<ChromeClientImpl*>(page->chrome()->client()); |
|
114 } |
|
115 |
|
116 static WebWidgetClient* toWebWidgetClient(Widget* widget) |
|
117 { |
|
118 ChromeClientImpl* chromeClientImpl = toChromeClientImpl(widget); |
|
119 if (!chromeClientImpl || !chromeClientImpl->webView()) |
|
120 return 0; |
|
121 return chromeClientImpl->webView()->client(); |
|
122 } |
|
123 |
|
124 static WebCookieJar* getCookieJar(const Document* document) |
|
125 { |
|
126 WebFrameImpl* frameImpl = WebFrameImpl::fromFrame(document->frame()); |
|
127 if (!frameImpl || !frameImpl->client()) |
|
128 return 0; |
|
129 WebCookieJar* cookieJar = frameImpl->client()->cookieJar(); |
|
130 if (!cookieJar) |
|
131 cookieJar = webKitClient()->cookieJar(); |
|
132 return cookieJar; |
|
133 } |
|
134 |
|
135 // Cache ---------------------------------------------------------------------- |
|
136 |
|
137 void ChromiumBridge::cacheMetadata(const KURL& url, double responseTime, const Vector<char>& data) |
|
138 { |
|
139 webKitClient()->cacheMetadata(url, responseTime, data.data(), data.size()); |
|
140 } |
|
141 |
|
142 // Clipboard ------------------------------------------------------------------ |
|
143 |
|
144 bool ChromiumBridge::clipboardIsFormatAvailable( |
|
145 PasteboardPrivate::ClipboardFormat format, |
|
146 PasteboardPrivate::ClipboardBuffer buffer) |
|
147 { |
|
148 return webKitClient()->clipboard()->isFormatAvailable( |
|
149 static_cast<WebClipboard::Format>(format), |
|
150 static_cast<WebClipboard::Buffer>(buffer)); |
|
151 } |
|
152 |
|
153 String ChromiumBridge::clipboardReadPlainText( |
|
154 PasteboardPrivate::ClipboardBuffer buffer) |
|
155 { |
|
156 return webKitClient()->clipboard()->readPlainText( |
|
157 static_cast<WebClipboard::Buffer>(buffer)); |
|
158 } |
|
159 |
|
160 void ChromiumBridge::clipboardReadHTML( |
|
161 PasteboardPrivate::ClipboardBuffer buffer, |
|
162 String* htmlText, KURL* sourceURL) |
|
163 { |
|
164 WebURL url; |
|
165 *htmlText = webKitClient()->clipboard()->readHTML( |
|
166 static_cast<WebClipboard::Buffer>(buffer), &url); |
|
167 *sourceURL = url; |
|
168 } |
|
169 |
|
170 void ChromiumBridge::clipboardWriteSelection(const String& htmlText, |
|
171 const KURL& sourceURL, |
|
172 const String& plainText, |
|
173 bool writeSmartPaste) |
|
174 { |
|
175 webKitClient()->clipboard()->writeHTML( |
|
176 htmlText, sourceURL, plainText, writeSmartPaste); |
|
177 } |
|
178 |
|
179 void ChromiumBridge::clipboardWritePlainText(const String& plainText) |
|
180 { |
|
181 webKitClient()->clipboard()->writePlainText(plainText); |
|
182 } |
|
183 |
|
184 void ChromiumBridge::clipboardWriteURL(const KURL& url, const String& title) |
|
185 { |
|
186 webKitClient()->clipboard()->writeURL(url, title); |
|
187 } |
|
188 |
|
189 void ChromiumBridge::clipboardWriteImage(NativeImagePtr image, |
|
190 const KURL& sourceURL, |
|
191 const String& title) |
|
192 { |
|
193 #if WEBKIT_USING_SKIA |
|
194 WebImage webImage(*image); |
|
195 #else |
|
196 WebImage webImage(image); |
|
197 #endif |
|
198 webKitClient()->clipboard()->writeImage(webImage, sourceURL, title); |
|
199 } |
|
200 |
|
201 void ChromiumBridge::clipboardWriteData(ClipboardData* data) |
|
202 { |
|
203 notImplemented(); |
|
204 WebDragData dragData; // FIXME: Define the conversion from ClipboardData to WebDragData. |
|
205 webKitClient()->clipboard()->writeData(dragData); |
|
206 } |
|
207 |
|
208 HashSet<String> ChromiumBridge::clipboardReadAvailableTypes( |
|
209 PasteboardPrivate::ClipboardBuffer buffer, bool* containsFilenames) |
|
210 { |
|
211 WebVector<WebString> result = webKitClient()->clipboard()->readAvailableTypes( |
|
212 static_cast<WebClipboard::Buffer>(buffer), containsFilenames); |
|
213 HashSet<String> types; |
|
214 for (size_t i = 0; i < result.size(); ++i) |
|
215 types.add(result[i]); |
|
216 return types; |
|
217 } |
|
218 |
|
219 bool ChromiumBridge::clipboardReadData(PasteboardPrivate::ClipboardBuffer buffer, |
|
220 const String& type, String& data, String& metadata) |
|
221 { |
|
222 WebString resultData; |
|
223 WebString resultMetadata; |
|
224 bool succeeded = webKitClient()->clipboard()->readData( |
|
225 static_cast<WebClipboard::Buffer>(buffer), type, &resultData, &resultMetadata); |
|
226 if (succeeded) { |
|
227 data = resultData; |
|
228 metadata = resultMetadata; |
|
229 } |
|
230 return succeeded; |
|
231 } |
|
232 |
|
233 Vector<String> ChromiumBridge::clipboardReadFilenames(PasteboardPrivate::ClipboardBuffer buffer) |
|
234 { |
|
235 WebVector<WebString> result = webKitClient()->clipboard()->readFilenames( |
|
236 static_cast<WebClipboard::Buffer>(buffer)); |
|
237 Vector<String> convertedResult; |
|
238 for (size_t i = 0; i < result.size(); ++i) |
|
239 convertedResult.append(result[i]); |
|
240 return convertedResult; |
|
241 } |
|
242 |
|
243 // Cookies -------------------------------------------------------------------- |
|
244 |
|
245 void ChromiumBridge::setCookies(const Document* document, const KURL& url, |
|
246 const String& value) |
|
247 { |
|
248 WebCookieJar* cookieJar = getCookieJar(document); |
|
249 if (cookieJar) |
|
250 cookieJar->setCookie(url, document->firstPartyForCookies(), value); |
|
251 } |
|
252 |
|
253 String ChromiumBridge::cookies(const Document* document, const KURL& url) |
|
254 { |
|
255 String result; |
|
256 WebCookieJar* cookieJar = getCookieJar(document); |
|
257 if (cookieJar) |
|
258 result = cookieJar->cookies(url, document->firstPartyForCookies()); |
|
259 return result; |
|
260 } |
|
261 |
|
262 String ChromiumBridge::cookieRequestHeaderFieldValue(const Document* document, |
|
263 const KURL& url) |
|
264 { |
|
265 String result; |
|
266 WebCookieJar* cookieJar = getCookieJar(document); |
|
267 if (cookieJar) |
|
268 result = cookieJar->cookieRequestHeaderFieldValue(url, document->firstPartyForCookies()); |
|
269 return result; |
|
270 } |
|
271 |
|
272 bool ChromiumBridge::rawCookies(const Document* document, const KURL& url, Vector<Cookie>& rawCookies) |
|
273 { |
|
274 rawCookies.clear(); |
|
275 WebVector<WebCookie> webCookies; |
|
276 |
|
277 WebCookieJar* cookieJar = getCookieJar(document); |
|
278 if (cookieJar) |
|
279 cookieJar->rawCookies(url, document->firstPartyForCookies(), webCookies); |
|
280 |
|
281 for (unsigned i = 0; i < webCookies.size(); ++i) { |
|
282 const WebCookie& webCookie = webCookies[i]; |
|
283 Cookie cookie(webCookie.name, |
|
284 webCookie.value, |
|
285 webCookie.domain, |
|
286 webCookie.path, |
|
287 webCookie.expires, |
|
288 webCookie.httpOnly, |
|
289 webCookie.secure, |
|
290 webCookie.session); |
|
291 rawCookies.append(cookie); |
|
292 } |
|
293 return true; |
|
294 } |
|
295 |
|
296 void ChromiumBridge::deleteCookie(const Document* document, const KURL& url, const String& cookieName) |
|
297 { |
|
298 WebCookieJar* cookieJar = getCookieJar(document); |
|
299 if (cookieJar) |
|
300 cookieJar->deleteCookie(url, cookieName); |
|
301 } |
|
302 |
|
303 bool ChromiumBridge::cookiesEnabled(const Document* document) |
|
304 { |
|
305 bool result = false; |
|
306 WebCookieJar* cookieJar = getCookieJar(document); |
|
307 if (cookieJar) |
|
308 result = cookieJar->cookiesEnabled(document->cookieURL(), document->firstPartyForCookies()); |
|
309 return result; |
|
310 } |
|
311 |
|
312 // DNS ------------------------------------------------------------------------ |
|
313 |
|
314 void ChromiumBridge::prefetchDNS(const String& hostname) |
|
315 { |
|
316 webKitClient()->prefetchHostName(hostname); |
|
317 } |
|
318 |
|
319 // File ------------------------------------------------------------------------ |
|
320 |
|
321 bool ChromiumBridge::fileExists(const String& path) |
|
322 { |
|
323 return webKitClient()->fileSystem()->fileExists(path); |
|
324 } |
|
325 |
|
326 bool ChromiumBridge::deleteFile(const String& path) |
|
327 { |
|
328 return webKitClient()->fileSystem()->deleteFile(path); |
|
329 } |
|
330 |
|
331 bool ChromiumBridge::deleteEmptyDirectory(const String& path) |
|
332 { |
|
333 return webKitClient()->fileSystem()->deleteEmptyDirectory(path); |
|
334 } |
|
335 |
|
336 bool ChromiumBridge::getFileSize(const String& path, long long& result) |
|
337 { |
|
338 return webKitClient()->fileSystem()->getFileSize(path, result); |
|
339 } |
|
340 |
|
341 bool ChromiumBridge::getFileModificationTime(const String& path, time_t& result) |
|
342 { |
|
343 double modificationTime; |
|
344 if (!webKitClient()->fileSystem()->getFileModificationTime(path, modificationTime)) |
|
345 return false; |
|
346 result = static_cast<time_t>(modificationTime); |
|
347 return true; |
|
348 } |
|
349 |
|
350 String ChromiumBridge::directoryName(const String& path) |
|
351 { |
|
352 return webKitClient()->fileSystem()->directoryName(path); |
|
353 } |
|
354 |
|
355 String ChromiumBridge::pathByAppendingComponent(const String& path, const String& component) |
|
356 { |
|
357 return webKitClient()->fileSystem()->pathByAppendingComponent(path, component); |
|
358 } |
|
359 |
|
360 bool ChromiumBridge::makeAllDirectories(const String& path) |
|
361 { |
|
362 return webKitClient()->fileSystem()->makeAllDirectories(path); |
|
363 } |
|
364 |
|
365 String ChromiumBridge::getAbsolutePath(const String& path) |
|
366 { |
|
367 return webKitClient()->fileSystem()->getAbsolutePath(path); |
|
368 } |
|
369 |
|
370 bool ChromiumBridge::isDirectory(const String& path) |
|
371 { |
|
372 return webKitClient()->fileSystem()->isDirectory(path); |
|
373 } |
|
374 |
|
375 KURL ChromiumBridge::filePathToURL(const String& path) |
|
376 { |
|
377 return webKitClient()->fileSystem()->filePathToURL(path); |
|
378 } |
|
379 |
|
380 PlatformFileHandle ChromiumBridge::openFile(const String& path, FileOpenMode mode) |
|
381 { |
|
382 return webKitClient()->fileSystem()->openFile(path, mode); |
|
383 } |
|
384 |
|
385 void ChromiumBridge::closeFile(PlatformFileHandle& handle) |
|
386 { |
|
387 webKitClient()->fileSystem()->closeFile(handle); |
|
388 } |
|
389 |
|
390 long long ChromiumBridge::seekFile(PlatformFileHandle handle, long long offset, FileSeekOrigin origin) |
|
391 { |
|
392 return webKitClient()->fileSystem()->seekFile(handle, offset, origin); |
|
393 } |
|
394 |
|
395 bool ChromiumBridge::truncateFile(PlatformFileHandle handle, long long offset) |
|
396 { |
|
397 return webKitClient()->fileSystem()->truncateFile(handle, offset); |
|
398 } |
|
399 |
|
400 int ChromiumBridge::readFromFile(PlatformFileHandle handle, char* data, int length) |
|
401 { |
|
402 return webKitClient()->fileSystem()->readFromFile(handle, data, length); |
|
403 } |
|
404 |
|
405 int ChromiumBridge::writeToFile(PlatformFileHandle handle, const char* data, int length) |
|
406 { |
|
407 return webKitClient()->fileSystem()->writeToFile(handle, data, length); |
|
408 } |
|
409 |
|
410 // Font ----------------------------------------------------------------------- |
|
411 |
|
412 #if OS(WINDOWS) |
|
413 bool ChromiumBridge::ensureFontLoaded(HFONT font) |
|
414 { |
|
415 WebSandboxSupport* ss = webKitClient()->sandboxSupport(); |
|
416 |
|
417 // if there is no sandbox, then we can assume the font |
|
418 // was able to be loaded successfully already |
|
419 return ss ? ss->ensureFontLoaded(font) : true; |
|
420 } |
|
421 #endif |
|
422 |
|
423 #if OS(LINUX) |
|
424 String ChromiumBridge::getFontFamilyForCharacters(const UChar* characters, size_t numCharacters) |
|
425 { |
|
426 if (webKitClient()->sandboxSupport()) |
|
427 return webKitClient()->sandboxSupport()->getFontFamilyForCharacters(characters, numCharacters); |
|
428 |
|
429 WebCString family = WebFontInfo::familyForChars(characters, numCharacters); |
|
430 if (family.data()) |
|
431 return WebString::fromUTF8(family.data()); |
|
432 |
|
433 return WebString(); |
|
434 } |
|
435 |
|
436 void ChromiumBridge::getRenderStyleForStrike(const char* font, int sizeAndStyle, FontRenderStyle* result) |
|
437 { |
|
438 WebFontRenderStyle style; |
|
439 |
|
440 if (webKitClient()->sandboxSupport()) |
|
441 webKitClient()->sandboxSupport()->getRenderStyleForStrike(font, sizeAndStyle, &style); |
|
442 else |
|
443 WebFontInfo::renderStyleForStrike(font, sizeAndStyle, &style); |
|
444 |
|
445 style.toFontRenderStyle(result); |
|
446 } |
|
447 #endif |
|
448 |
|
449 #if OS(DARWIN) |
|
450 bool ChromiumBridge::loadFont(NSFont* srcFont, ATSFontContainerRef* out) |
|
451 { |
|
452 WebSandboxSupport* ss = webKitClient()->sandboxSupport(); |
|
453 if (ss) |
|
454 return ss->loadFont(srcFont, out); |
|
455 |
|
456 // This function should only be called in response to an error loading a |
|
457 // font due to being blocked by the sandbox. |
|
458 // This by definition shouldn't happen if there is no sandbox support. |
|
459 ASSERT_NOT_REACHED(); |
|
460 *out = 0; |
|
461 return false; |
|
462 } |
|
463 #endif |
|
464 |
|
465 // Geolocation ---------------------------------------------------------------- |
|
466 |
|
467 GeolocationServiceBridge* ChromiumBridge::createGeolocationServiceBridge(GeolocationServiceChromium* geolocationServiceChromium) |
|
468 { |
|
469 return createGeolocationServiceBridgeImpl(geolocationServiceChromium); |
|
470 } |
|
471 |
|
472 // HTML5 DB ------------------------------------------------------------------- |
|
473 |
|
474 #if ENABLE(DATABASE) |
|
475 PlatformFileHandle ChromiumBridge::databaseOpenFile(const String& vfsFileName, int desiredFlags) |
|
476 { |
|
477 return webKitClient()->databaseOpenFile(WebString(vfsFileName), desiredFlags); |
|
478 } |
|
479 |
|
480 int ChromiumBridge::databaseDeleteFile(const String& vfsFileName, bool syncDir) |
|
481 { |
|
482 return webKitClient()->databaseDeleteFile(WebString(vfsFileName), syncDir); |
|
483 } |
|
484 |
|
485 long ChromiumBridge::databaseGetFileAttributes(const String& vfsFileName) |
|
486 { |
|
487 return webKitClient()->databaseGetFileAttributes(WebString(vfsFileName)); |
|
488 } |
|
489 |
|
490 long long ChromiumBridge::databaseGetFileSize(const String& vfsFileName) |
|
491 { |
|
492 return webKitClient()->databaseGetFileSize(WebString(vfsFileName)); |
|
493 } |
|
494 #endif |
|
495 |
|
496 // Indexed Database ----------------------------------------------------------- |
|
497 |
|
498 PassRefPtr<IndexedDatabase> ChromiumBridge::indexedDatabase() |
|
499 { |
|
500 // There's no reason why we need to allocate a new proxy each time, but |
|
501 // there's also no strong reason not to. |
|
502 return IndexedDatabaseProxy::create(); |
|
503 } |
|
504 |
|
505 // Keygen --------------------------------------------------------------------- |
|
506 |
|
507 String ChromiumBridge::signedPublicKeyAndChallengeString( |
|
508 unsigned keySizeIndex, const String& challenge, const KURL& url) |
|
509 { |
|
510 return webKitClient()->signedPublicKeyAndChallengeString(keySizeIndex, |
|
511 WebString(challenge), |
|
512 WebURL(url)); |
|
513 } |
|
514 |
|
515 // Language ------------------------------------------------------------------- |
|
516 |
|
517 String ChromiumBridge::computedDefaultLanguage() |
|
518 { |
|
519 return webKitClient()->defaultLocale(); |
|
520 } |
|
521 |
|
522 // LayoutTestMode ------------------------------------------------------------- |
|
523 |
|
524 bool ChromiumBridge::layoutTestMode() |
|
525 { |
|
526 return WebKit::layoutTestMode(); |
|
527 } |
|
528 |
|
529 // MimeType ------------------------------------------------------------------- |
|
530 |
|
531 bool ChromiumBridge::isSupportedImageMIMEType(const String& mimeType) |
|
532 { |
|
533 return webKitClient()->mimeRegistry()->supportsImageMIMEType(mimeType) |
|
534 != WebMimeRegistry::IsNotSupported; |
|
535 } |
|
536 |
|
537 bool ChromiumBridge::isSupportedJavaScriptMIMEType(const String& mimeType) |
|
538 { |
|
539 return webKitClient()->mimeRegistry()->supportsJavaScriptMIMEType(mimeType) |
|
540 != WebMimeRegistry::IsNotSupported; |
|
541 } |
|
542 |
|
543 bool ChromiumBridge::isSupportedNonImageMIMEType(const String& mimeType) |
|
544 { |
|
545 return webKitClient()->mimeRegistry()->supportsNonImageMIMEType(mimeType) |
|
546 != WebMimeRegistry::IsNotSupported; |
|
547 } |
|
548 |
|
549 String ChromiumBridge::mimeTypeForExtension(const String& extension) |
|
550 { |
|
551 return webKitClient()->mimeRegistry()->mimeTypeForExtension(extension); |
|
552 } |
|
553 |
|
554 String ChromiumBridge::mimeTypeFromFile(const String& path) |
|
555 { |
|
556 return webKitClient()->mimeRegistry()->mimeTypeFromFile(path); |
|
557 } |
|
558 |
|
559 String ChromiumBridge::preferredExtensionForMIMEType(const String& mimeType) |
|
560 { |
|
561 return webKitClient()->mimeRegistry()->preferredExtensionForMIMEType(mimeType); |
|
562 } |
|
563 |
|
564 // Plugin --------------------------------------------------------------------- |
|
565 |
|
566 bool ChromiumBridge::plugins(bool refresh, Vector<PluginInfo>* results) |
|
567 { |
|
568 WebPluginListBuilderImpl builder(results); |
|
569 webKitClient()->getPluginList(refresh, &builder); |
|
570 return true; // FIXME: There is no need for this function to return a value. |
|
571 } |
|
572 |
|
573 NPObject* ChromiumBridge::pluginScriptableObject(Widget* widget) |
|
574 { |
|
575 if (!widget) |
|
576 return 0; |
|
577 |
|
578 ASSERT(!widget->isFrameView()); |
|
579 |
|
580 // NOTE: We have to trust that the widget passed to us here is a |
|
581 // WebPluginContainerImpl. There isn't a way to dynamically verify it, |
|
582 // since the derived class (Widget) has no identifier. |
|
583 return static_cast<WebPluginContainerImpl*>(widget)->scriptableObject(); |
|
584 } |
|
585 |
|
586 // Resources ------------------------------------------------------------------ |
|
587 |
|
588 PassRefPtr<Image> ChromiumBridge::loadPlatformImageResource(const char* name) |
|
589 { |
|
590 const WebData& resource = webKitClient()->loadResource(name); |
|
591 if (resource.isEmpty()) |
|
592 return Image::nullImage(); |
|
593 |
|
594 RefPtr<Image> image = BitmapImage::create(); |
|
595 image->setData(resource, true); |
|
596 return image; |
|
597 } |
|
598 |
|
599 // Sandbox -------------------------------------------------------------------- |
|
600 |
|
601 bool ChromiumBridge::sandboxEnabled() |
|
602 { |
|
603 return webKitClient()->sandboxEnabled(); |
|
604 } |
|
605 |
|
606 // SharedTimers --------------------------------------------------------------- |
|
607 |
|
608 void ChromiumBridge::setSharedTimerFiredFunction(void (*func)()) |
|
609 { |
|
610 webKitClient()->setSharedTimerFiredFunction(func); |
|
611 } |
|
612 |
|
613 void ChromiumBridge::setSharedTimerFireTime(double fireTime) |
|
614 { |
|
615 webKitClient()->setSharedTimerFireTime(fireTime); |
|
616 } |
|
617 |
|
618 void ChromiumBridge::stopSharedTimer() |
|
619 { |
|
620 webKitClient()->stopSharedTimer(); |
|
621 } |
|
622 |
|
623 // StatsCounters -------------------------------------------------------------- |
|
624 |
|
625 void ChromiumBridge::decrementStatsCounter(const char* name) |
|
626 { |
|
627 webKitClient()->decrementStatsCounter(name); |
|
628 } |
|
629 |
|
630 void ChromiumBridge::incrementStatsCounter(const char* name) |
|
631 { |
|
632 webKitClient()->incrementStatsCounter(name); |
|
633 } |
|
634 |
|
635 // Sudden Termination --------------------------------------------------------- |
|
636 |
|
637 void ChromiumBridge::suddenTerminationChanged(bool enabled) |
|
638 { |
|
639 webKitClient()->suddenTerminationChanged(enabled); |
|
640 } |
|
641 |
|
642 // SystemTime ----------------------------------------------------------------- |
|
643 |
|
644 double ChromiumBridge::currentTime() |
|
645 { |
|
646 return webKitClient()->currentTime(); |
|
647 } |
|
648 |
|
649 // Theming -------------------------------------------------------------------- |
|
650 |
|
651 #if OS(WINDOWS) |
|
652 |
|
653 void ChromiumBridge::paintButton( |
|
654 GraphicsContext* gc, int part, int state, int classicState, |
|
655 const IntRect& rect) |
|
656 { |
|
657 webKitClient()->themeEngine()->paintButton( |
|
658 gc->platformContext()->canvas(), part, state, classicState, rect); |
|
659 } |
|
660 |
|
661 void ChromiumBridge::paintMenuList( |
|
662 GraphicsContext* gc, int part, int state, int classicState, |
|
663 const IntRect& rect) |
|
664 { |
|
665 webKitClient()->themeEngine()->paintMenuList( |
|
666 gc->platformContext()->canvas(), part, state, classicState, rect); |
|
667 } |
|
668 |
|
669 void ChromiumBridge::paintScrollbarArrow( |
|
670 GraphicsContext* gc, int state, int classicState, |
|
671 const IntRect& rect) |
|
672 { |
|
673 webKitClient()->themeEngine()->paintScrollbarArrow( |
|
674 gc->platformContext()->canvas(), state, classicState, rect); |
|
675 } |
|
676 |
|
677 void ChromiumBridge::paintScrollbarThumb( |
|
678 GraphicsContext* gc, int part, int state, int classicState, |
|
679 const IntRect& rect) |
|
680 { |
|
681 webKitClient()->themeEngine()->paintScrollbarThumb( |
|
682 gc->platformContext()->canvas(), part, state, classicState, rect); |
|
683 } |
|
684 |
|
685 void ChromiumBridge::paintScrollbarTrack( |
|
686 GraphicsContext* gc, int part, int state, int classicState, |
|
687 const IntRect& rect, const IntRect& alignRect) |
|
688 { |
|
689 webKitClient()->themeEngine()->paintScrollbarTrack( |
|
690 gc->platformContext()->canvas(), part, state, classicState, rect, |
|
691 alignRect); |
|
692 } |
|
693 |
|
694 void ChromiumBridge::paintSpinButton( |
|
695 GraphicsContext* gc, int part, int state, int classicState, |
|
696 const IntRect& rect) |
|
697 { |
|
698 webKitClient()->themeEngine()->paintSpinButton( |
|
699 gc->platformContext()->canvas(), part, state, classicState, rect); |
|
700 } |
|
701 |
|
702 void ChromiumBridge::paintTextField( |
|
703 GraphicsContext* gc, int part, int state, int classicState, |
|
704 const IntRect& rect, const Color& color, bool fillContentArea, |
|
705 bool drawEdges) |
|
706 { |
|
707 // Fallback to white when |color| is invalid. |
|
708 RGBA32 backgroundColor = color.isValid() ? color.rgb() : Color::white; |
|
709 |
|
710 webKitClient()->themeEngine()->paintTextField( |
|
711 gc->platformContext()->canvas(), part, state, classicState, rect, |
|
712 backgroundColor, fillContentArea, drawEdges); |
|
713 } |
|
714 |
|
715 void ChromiumBridge::paintTrackbar( |
|
716 GraphicsContext* gc, int part, int state, int classicState, |
|
717 const IntRect& rect) |
|
718 { |
|
719 webKitClient()->themeEngine()->paintTrackbar( |
|
720 gc->platformContext()->canvas(), part, state, classicState, rect); |
|
721 } |
|
722 |
|
723 void ChromiumBridge::paintProgressBar( |
|
724 GraphicsContext* gc, const IntRect& barRect, const IntRect& valueRect, bool determinate, double animatedSeconds) |
|
725 { |
|
726 webKitClient()->themeEngine()->paintProgressBar( |
|
727 gc->platformContext()->canvas(), barRect, valueRect, determinate, animatedSeconds); |
|
728 } |
|
729 |
|
730 #endif |
|
731 |
|
732 // Trace Event ---------------------------------------------------------------- |
|
733 |
|
734 void ChromiumBridge::traceEventBegin(const char* name, void* id, const char* extra) |
|
735 { |
|
736 webKitClient()->traceEventBegin(name, id, extra); |
|
737 } |
|
738 |
|
739 void ChromiumBridge::traceEventEnd(const char* name, void* id, const char* extra) |
|
740 { |
|
741 webKitClient()->traceEventEnd(name, id, extra); |
|
742 } |
|
743 |
|
744 // Visited Links -------------------------------------------------------------- |
|
745 |
|
746 LinkHash ChromiumBridge::visitedLinkHash(const UChar* url, unsigned length) |
|
747 { |
|
748 url_canon::RawCanonOutput<2048> buffer; |
|
749 url_parse::Parsed parsed; |
|
750 if (!url_util::Canonicalize(url, length, 0, &buffer, &parsed)) |
|
751 return 0; // Invalid URLs are unvisited. |
|
752 return webKitClient()->visitedLinkHash(buffer.data(), buffer.length()); |
|
753 } |
|
754 |
|
755 LinkHash ChromiumBridge::visitedLinkHash(const KURL& base, |
|
756 const AtomicString& attributeURL) |
|
757 { |
|
758 // Resolve the relative URL using googleurl and pass the absolute URL up to |
|
759 // the embedder. We could create a GURL object from the base and resolve |
|
760 // the relative URL that way, but calling the lower-level functions |
|
761 // directly saves us the string allocation in most cases. |
|
762 url_canon::RawCanonOutput<2048> buffer; |
|
763 url_parse::Parsed parsed; |
|
764 |
|
765 #if USE(GOOGLEURL) |
|
766 const CString& cstr = base.utf8String(); |
|
767 const char* data = cstr.data(); |
|
768 int length = cstr.length(); |
|
769 const url_parse::Parsed& srcParsed = base.parsed(); |
|
770 #else |
|
771 // When we're not using GoogleURL, first canonicalize it so we can resolve it |
|
772 // below. |
|
773 url_canon::RawCanonOutput<2048> srcCanon; |
|
774 url_parse::Parsed srcParsed; |
|
775 String str = base.string(); |
|
776 if (!url_util::Canonicalize(str.characters(), str.length(), 0, &srcCanon, &srcParsed)) |
|
777 return 0; |
|
778 const char* data = srcCanon.data(); |
|
779 int length = srcCanon.length(); |
|
780 #endif |
|
781 |
|
782 if (!url_util::ResolveRelative(data, length, srcParsed, attributeURL.characters(), |
|
783 attributeURL.length(), 0, &buffer, &parsed)) |
|
784 return 0; // Invalid resolved URL. |
|
785 |
|
786 return webKitClient()->visitedLinkHash(buffer.data(), buffer.length()); |
|
787 } |
|
788 |
|
789 bool ChromiumBridge::isLinkVisited(LinkHash visitedLinkHash) |
|
790 { |
|
791 return webKitClient()->isLinkVisited(visitedLinkHash); |
|
792 } |
|
793 |
|
794 // These are temporary methods that the WebKit layer can use to call to the |
|
795 // Glue layer. Once the Glue layer moves entirely into the WebKit layer, these |
|
796 // methods will be deleted. |
|
797 |
|
798 void ChromiumBridge::notifyJSOutOfMemory(Frame* frame) |
|
799 { |
|
800 if (!frame) |
|
801 return; |
|
802 |
|
803 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame); |
|
804 if (!webFrame->client()) |
|
805 return; |
|
806 webFrame->client()->didExhaustMemoryAvailableForScript(webFrame); |
|
807 } |
|
808 |
|
809 int ChromiumBridge::memoryUsageMB() |
|
810 { |
|
811 return static_cast<int>(webKitClient()->memoryUsageMB()); |
|
812 } |
|
813 |
|
814 int ChromiumBridge::screenDepth(Widget* widget) |
|
815 { |
|
816 WebWidgetClient* client = toWebWidgetClient(widget); |
|
817 if (!client) |
|
818 return 0; |
|
819 return client->screenInfo().depth; |
|
820 } |
|
821 |
|
822 int ChromiumBridge::screenDepthPerComponent(Widget* widget) |
|
823 { |
|
824 WebWidgetClient* client = toWebWidgetClient(widget); |
|
825 if (!client) |
|
826 return 0; |
|
827 return client->screenInfo().depthPerComponent; |
|
828 } |
|
829 |
|
830 bool ChromiumBridge::screenIsMonochrome(Widget* widget) |
|
831 { |
|
832 WebWidgetClient* client = toWebWidgetClient(widget); |
|
833 if (!client) |
|
834 return 0; |
|
835 return client->screenInfo().isMonochrome; |
|
836 } |
|
837 |
|
838 IntRect ChromiumBridge::screenRect(Widget* widget) |
|
839 { |
|
840 WebWidgetClient* client = toWebWidgetClient(widget); |
|
841 if (!client) |
|
842 return IntRect(); |
|
843 return client->screenInfo().rect; |
|
844 } |
|
845 |
|
846 IntRect ChromiumBridge::screenAvailableRect(Widget* widget) |
|
847 { |
|
848 WebWidgetClient* client = toWebWidgetClient(widget); |
|
849 if (!client) |
|
850 return IntRect(); |
|
851 return client->screenInfo().availableRect; |
|
852 } |
|
853 |
|
854 bool ChromiumBridge::popupsAllowed(NPP npp) |
|
855 { |
|
856 // FIXME: Give the embedder a way to control this. |
|
857 return false; |
|
858 } |
|
859 |
|
860 void ChromiumBridge::widgetSetCursor(Widget* widget, const Cursor& cursor) |
|
861 { |
|
862 ChromeClientImpl* client = toChromeClientImpl(widget); |
|
863 if (client) |
|
864 client->setCursor(WebCursorInfo(cursor)); |
|
865 } |
|
866 |
|
867 void ChromiumBridge::widgetSetFocus(Widget* widget) |
|
868 { |
|
869 ChromeClientImpl* client = toChromeClientImpl(widget); |
|
870 if (client) |
|
871 client->focus(); |
|
872 } |
|
873 |
|
874 WorkerContextProxy* WorkerContextProxy::create(Worker* worker) |
|
875 { |
|
876 return WebWorkerClientImpl::createWorkerContextProxy(worker); |
|
877 } |
|
878 |
|
879 } // namespace WebCore |