2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "PlatformBridge.h"
34 #include <googleurl/src/url_util.h>
37 #include "ChromeClientImpl.h"
38 #include "WebAudioBus.h"
39 #include "WebClipboard.h"
40 #include "WebCookie.h"
41 #include "WebCookieJar.h"
43 #include "WebDragData.h"
44 #include "WebFileUtilities.h"
45 #include "WebFrameClient.h"
46 #include "WebFrameImpl.h"
47 #include "WebIDBKey.h"
50 #include "WebKitClient.h"
51 #include "WebMimeRegistry.h"
52 #include "WebPluginContainerImpl.h"
53 #include "WebPluginListBuilderImpl.h"
54 #include "WebSandboxSupport.h"
55 #include "WebSerializedScriptValue.h"
56 #include "WebScreenInfo.h"
57 #include "WebString.h"
59 #include "WebVector.h"
60 #include "WebViewClient.h"
61 #include "WebViewImpl.h"
62 #include "WebWorkerClientImpl.h"
65 #include <CoreGraphics/CGContext.h>
70 #include "win/WebThemeEngine.h"
73 #if OS(LINUX) || OS(FREEBSD)
74 #include "linux/WebThemeEngine.h"
75 #include "WebFontInfo.h"
76 #include "WebFontRenderStyle.h"
80 #include "mac/WebThemeEngine.h"
84 #include "NativeImageSkia.h"
87 #include "BitmapImage.h"
89 #include "FrameView.h"
90 #include "GraphicsContext.h"
91 #include "IDBFactoryBackendProxy.h"
93 #include "NotImplemented.h"
94 #include "PlatformContextSkia.h"
95 #include "PluginData.h"
96 #include "SharedBuffer.h"
99 #include "WorkerContextProxy.h"
100 #include <wtf/Assertions.h>
102 // We are part of the WebKit implementation.
103 using namespace WebKit;
107 static ChromeClientImpl* toChromeClientImpl(Widget* widget)
113 if (widget->isFrameView())
114 view = static_cast<FrameView*>(widget);
115 else if (widget->parent() && widget->parent()->isFrameView())
116 view = static_cast<FrameView*>(widget->parent());
120 Page* page = view->frame() ? view->frame()->page() : 0;
124 return static_cast<ChromeClientImpl*>(page->chrome()->client());
127 static WebWidgetClient* toWebWidgetClient(Widget* widget)
129 ChromeClientImpl* chromeClientImpl = toChromeClientImpl(widget);
130 if (!chromeClientImpl || !chromeClientImpl->webView())
132 return chromeClientImpl->webView()->client();
135 static WebCookieJar* getCookieJar(const Document* document)
137 WebFrameImpl* frameImpl = WebFrameImpl::fromFrame(document->frame());
138 if (!frameImpl || !frameImpl->client())
140 WebCookieJar* cookieJar = frameImpl->client()->cookieJar(frameImpl);
142 cookieJar = webKitClient()->cookieJar();
146 // Cache ----------------------------------------------------------------------
148 void PlatformBridge::cacheMetadata(const KURL& url, double responseTime, const Vector<char>& data)
150 webKitClient()->cacheMetadata(url, responseTime, data.data(), data.size());
153 // Clipboard ------------------------------------------------------------------
155 bool PlatformBridge::clipboardIsFormatAvailable(
156 PasteboardPrivate::ClipboardFormat format,
157 PasteboardPrivate::ClipboardBuffer buffer)
159 return webKitClient()->clipboard()->isFormatAvailable(
160 static_cast<WebClipboard::Format>(format),
161 static_cast<WebClipboard::Buffer>(buffer));
164 String PlatformBridge::clipboardReadPlainText(
165 PasteboardPrivate::ClipboardBuffer buffer)
167 return webKitClient()->clipboard()->readPlainText(
168 static_cast<WebClipboard::Buffer>(buffer));
171 void PlatformBridge::clipboardReadHTML(
172 PasteboardPrivate::ClipboardBuffer buffer,
173 String* htmlText, KURL* sourceURL)
176 *htmlText = webKitClient()->clipboard()->readHTML(
177 static_cast<WebClipboard::Buffer>(buffer), &url);
181 void PlatformBridge::clipboardWriteSelection(const String& htmlText,
182 const KURL& sourceURL,
183 const String& plainText,
184 bool writeSmartPaste)
186 webKitClient()->clipboard()->writeHTML(
187 htmlText, sourceURL, plainText, writeSmartPaste);
190 void PlatformBridge::clipboardWritePlainText(const String& plainText)
192 webKitClient()->clipboard()->writePlainText(plainText);
195 void PlatformBridge::clipboardWriteURL(const KURL& url, const String& title)
197 webKitClient()->clipboard()->writeURL(url, title);
200 void PlatformBridge::clipboardWriteImage(NativeImagePtr image,
201 const KURL& sourceURL,
204 #if WEBKIT_USING_SKIA
205 WebImage webImage(*image);
207 WebImage webImage(image);
209 webKitClient()->clipboard()->writeImage(webImage, sourceURL, title);
212 void PlatformBridge::clipboardWriteData(const String& type,
214 const String& metadata)
216 webKitClient()->clipboard()->writeData(type, data, metadata);
219 HashSet<String> PlatformBridge::clipboardReadAvailableTypes(
220 PasteboardPrivate::ClipboardBuffer buffer, bool* containsFilenames)
222 WebVector<WebString> result = webKitClient()->clipboard()->readAvailableTypes(
223 static_cast<WebClipboard::Buffer>(buffer), containsFilenames);
224 HashSet<String> types;
225 for (size_t i = 0; i < result.size(); ++i)
226 types.add(result[i]);
230 bool PlatformBridge::clipboardReadData(PasteboardPrivate::ClipboardBuffer buffer,
231 const String& type, String& data, String& metadata)
233 WebString resultData;
234 WebString resultMetadata;
235 bool succeeded = webKitClient()->clipboard()->readData(
236 static_cast<WebClipboard::Buffer>(buffer), type, &resultData, &resultMetadata);
239 metadata = resultMetadata;
244 Vector<String> PlatformBridge::clipboardReadFilenames(PasteboardPrivate::ClipboardBuffer buffer)
246 WebVector<WebString> result = webKitClient()->clipboard()->readFilenames(
247 static_cast<WebClipboard::Buffer>(buffer));
248 Vector<String> convertedResult;
249 for (size_t i = 0; i < result.size(); ++i)
250 convertedResult.append(result[i]);
251 return convertedResult;
254 // Cookies --------------------------------------------------------------------
256 void PlatformBridge::setCookies(const Document* document, const KURL& url,
259 WebCookieJar* cookieJar = getCookieJar(document);
261 cookieJar->setCookie(url, document->firstPartyForCookies(), value);
264 String PlatformBridge::cookies(const Document* document, const KURL& url)
267 WebCookieJar* cookieJar = getCookieJar(document);
269 result = cookieJar->cookies(url, document->firstPartyForCookies());
273 String PlatformBridge::cookieRequestHeaderFieldValue(const Document* document,
277 WebCookieJar* cookieJar = getCookieJar(document);
279 result = cookieJar->cookieRequestHeaderFieldValue(url, document->firstPartyForCookies());
283 bool PlatformBridge::rawCookies(const Document* document, const KURL& url, Vector<Cookie>& rawCookies)
286 WebVector<WebCookie> webCookies;
288 WebCookieJar* cookieJar = getCookieJar(document);
290 cookieJar->rawCookies(url, document->firstPartyForCookies(), webCookies);
292 for (unsigned i = 0; i < webCookies.size(); ++i) {
293 const WebCookie& webCookie = webCookies[i];
294 Cookie cookie(webCookie.name,
302 rawCookies.append(cookie);
307 void PlatformBridge::deleteCookie(const Document* document, const KURL& url, const String& cookieName)
309 WebCookieJar* cookieJar = getCookieJar(document);
311 cookieJar->deleteCookie(url, cookieName);
314 bool PlatformBridge::cookiesEnabled(const Document* document)
317 WebCookieJar* cookieJar = getCookieJar(document);
319 result = cookieJar->cookiesEnabled(document->cookieURL(), document->firstPartyForCookies());
323 // DNS ------------------------------------------------------------------------
325 void PlatformBridge::prefetchDNS(const String& hostname)
327 webKitClient()->prefetchHostName(hostname);
330 // File ------------------------------------------------------------------------
332 bool PlatformBridge::fileExists(const String& path)
334 return webKitClient()->fileUtilities()->fileExists(path);
337 bool PlatformBridge::deleteFile(const String& path)
339 return webKitClient()->fileUtilities()->deleteFile(path);
342 bool PlatformBridge::deleteEmptyDirectory(const String& path)
344 return webKitClient()->fileUtilities()->deleteEmptyDirectory(path);
347 bool PlatformBridge::getFileSize(const String& path, long long& result)
349 return webKitClient()->fileUtilities()->getFileSize(path, result);
352 void PlatformBridge::revealFolderInOS(const String& path)
354 webKitClient()->fileUtilities()->revealFolderInOS(path);
357 bool PlatformBridge::getFileModificationTime(const String& path, time_t& result)
359 double modificationTime;
360 if (!webKitClient()->fileUtilities()->getFileModificationTime(path, modificationTime))
362 result = static_cast<time_t>(modificationTime);
366 String PlatformBridge::directoryName(const String& path)
368 return webKitClient()->fileUtilities()->directoryName(path);
371 String PlatformBridge::pathByAppendingComponent(const String& path, const String& component)
373 return webKitClient()->fileUtilities()->pathByAppendingComponent(path, component);
376 bool PlatformBridge::makeAllDirectories(const String& path)
378 return webKitClient()->fileUtilities()->makeAllDirectories(path);
381 String PlatformBridge::getAbsolutePath(const String& path)
383 return webKitClient()->fileUtilities()->getAbsolutePath(path);
386 bool PlatformBridge::isDirectory(const String& path)
388 return webKitClient()->fileUtilities()->isDirectory(path);
391 KURL PlatformBridge::filePathToURL(const String& path)
393 return webKitClient()->fileUtilities()->filePathToURL(path);
396 PlatformFileHandle PlatformBridge::openFile(const String& path, FileOpenMode mode)
398 return webKitClient()->fileUtilities()->openFile(path, mode);
401 void PlatformBridge::closeFile(PlatformFileHandle& handle)
403 webKitClient()->fileUtilities()->closeFile(handle);
406 long long PlatformBridge::seekFile(PlatformFileHandle handle, long long offset, FileSeekOrigin origin)
408 return webKitClient()->fileUtilities()->seekFile(handle, offset, origin);
411 bool PlatformBridge::truncateFile(PlatformFileHandle handle, long long offset)
413 return webKitClient()->fileUtilities()->truncateFile(handle, offset);
416 int PlatformBridge::readFromFile(PlatformFileHandle handle, char* data, int length)
418 return webKitClient()->fileUtilities()->readFromFile(handle, data, length);
421 int PlatformBridge::writeToFile(PlatformFileHandle handle, const char* data, int length)
423 return webKitClient()->fileUtilities()->writeToFile(handle, data, length);
426 // Font -----------------------------------------------------------------------
429 bool PlatformBridge::ensureFontLoaded(HFONT font)
431 WebSandboxSupport* ss = webKitClient()->sandboxSupport();
433 // if there is no sandbox, then we can assume the font
434 // was able to be loaded successfully already
435 return ss ? ss->ensureFontLoaded(font) : true;
439 #if OS(LINUX) || OS(FREEBSD)
440 String PlatformBridge::getFontFamilyForCharacters(const UChar* characters, size_t numCharacters)
442 if (webKitClient()->sandboxSupport())
443 return webKitClient()->sandboxSupport()->getFontFamilyForCharacters(characters, numCharacters);
445 WebCString family = WebFontInfo::familyForChars(characters, numCharacters);
447 return WebString::fromUTF8(family.data());
452 void PlatformBridge::getRenderStyleForStrike(const char* font, int sizeAndStyle, FontRenderStyle* result)
454 WebFontRenderStyle style;
456 if (webKitClient()->sandboxSupport())
457 webKitClient()->sandboxSupport()->getRenderStyleForStrike(font, sizeAndStyle, &style);
459 WebFontInfo::renderStyleForStrike(font, sizeAndStyle, &style);
461 style.toFontRenderStyle(result);
466 bool PlatformBridge::loadFont(NSFont* srcFont, ATSFontContainerRef* out)
468 WebSandboxSupport* ss = webKitClient()->sandboxSupport();
470 return ss->loadFont(srcFont, out);
472 // This function should only be called in response to an error loading a
473 // font due to being blocked by the sandbox.
474 // This by definition shouldn't happen if there is no sandbox support.
475 ASSERT_NOT_REACHED();
481 // Databases ------------------------------------------------------------------
483 PlatformFileHandle PlatformBridge::databaseOpenFile(const String& vfsFileName, int desiredFlags)
485 return webKitClient()->databaseOpenFile(WebString(vfsFileName), desiredFlags);
488 int PlatformBridge::databaseDeleteFile(const String& vfsFileName, bool syncDir)
490 return webKitClient()->databaseDeleteFile(WebString(vfsFileName), syncDir);
493 long PlatformBridge::databaseGetFileAttributes(const String& vfsFileName)
495 return webKitClient()->databaseGetFileAttributes(WebString(vfsFileName));
498 long long PlatformBridge::databaseGetFileSize(const String& vfsFileName)
500 return webKitClient()->databaseGetFileSize(WebString(vfsFileName));
503 // Indexed Database -----------------------------------------------------------
505 PassRefPtr<IDBFactoryBackendInterface> PlatformBridge::idbFactory()
507 // There's no reason why we need to allocate a new proxy each time, but
508 // there's also no strong reason not to.
509 return IDBFactoryBackendProxy::create();
512 void PlatformBridge::idbShutdown()
514 // In the browser process, this shuts down the utility process. In the renderer process, it does nothing.
515 webKitClient()->idbShutdown();
518 void PlatformBridge::createIDBKeysFromSerializedValuesAndKeyPath(const Vector<RefPtr<SerializedScriptValue> >& values, const String& keyPath, Vector<RefPtr<IDBKey> >& keys)
520 WebVector<WebSerializedScriptValue> webValues = values;
521 WebVector<WebIDBKey> webKeys;
522 webKitClient()->createIDBKeysFromSerializedValuesAndKeyPath(webValues, WebString(keyPath), webKeys);
524 size_t webKeysSize = webKeys.size();
525 keys.reserveCapacity(webKeysSize);
526 for (size_t i = 0; i < webKeysSize; ++i)
527 keys.append(PassRefPtr<IDBKey>(webKeys[i]));
530 // Keygen ---------------------------------------------------------------------
532 String PlatformBridge::signedPublicKeyAndChallengeString(
533 unsigned keySizeIndex, const String& challenge, const KURL& url)
535 return webKitClient()->signedPublicKeyAndChallengeString(keySizeIndex,
536 WebString(challenge),
540 // Language -------------------------------------------------------------------
542 String PlatformBridge::computedDefaultLanguage()
544 return webKitClient()->defaultLocale();
547 // LayoutTestMode -------------------------------------------------------------
549 bool PlatformBridge::layoutTestMode()
551 return WebKit::layoutTestMode();
554 // MimeType -------------------------------------------------------------------
556 bool PlatformBridge::isSupportedImageMIMEType(const String& mimeType)
558 return webKitClient()->mimeRegistry()->supportsImageMIMEType(mimeType)
559 != WebMimeRegistry::IsNotSupported;
562 bool PlatformBridge::isSupportedJavaScriptMIMEType(const String& mimeType)
564 return webKitClient()->mimeRegistry()->supportsJavaScriptMIMEType(mimeType)
565 != WebMimeRegistry::IsNotSupported;
568 bool PlatformBridge::isSupportedNonImageMIMEType(const String& mimeType)
570 return webKitClient()->mimeRegistry()->supportsNonImageMIMEType(mimeType)
571 != WebMimeRegistry::IsNotSupported;
574 String PlatformBridge::mimeTypeForExtension(const String& extension)
576 return webKitClient()->mimeRegistry()->mimeTypeForExtension(extension);
579 String PlatformBridge::mimeTypeFromFile(const String& path)
581 return webKitClient()->mimeRegistry()->mimeTypeFromFile(path);
584 String PlatformBridge::preferredExtensionForMIMEType(const String& mimeType)
586 return webKitClient()->mimeRegistry()->preferredExtensionForMIMEType(mimeType);
589 // Plugin ---------------------------------------------------------------------
591 bool PlatformBridge::plugins(bool refresh, Vector<PluginInfo>* results)
593 WebPluginListBuilderImpl builder(results);
594 webKitClient()->getPluginList(refresh, &builder);
595 return true; // FIXME: There is no need for this function to return a value.
598 NPObject* PlatformBridge::pluginScriptableObject(Widget* widget)
600 if (!widget || !widget->isPluginContainer())
603 return static_cast<WebPluginContainerImpl*>(widget)->scriptableObject();
606 // Resources ------------------------------------------------------------------
608 PassRefPtr<Image> PlatformBridge::loadPlatformImageResource(const char* name)
610 const WebData& resource = webKitClient()->loadResource(name);
611 if (resource.isEmpty())
612 return Image::nullImage();
614 RefPtr<Image> image = BitmapImage::create();
615 image->setData(resource, true);
619 #if ENABLE(WEB_AUDIO)
621 PassOwnPtr<AudioBus> PlatformBridge::loadPlatformAudioResource(const char* name, double sampleRate)
623 const WebData& resource = webKitClient()->loadResource(name);
624 if (resource.isEmpty())
627 return decodeAudioFileData(resource.data(), resource.size(), sampleRate);
630 PassOwnPtr<AudioBus> PlatformBridge::decodeAudioFileData(const char* data, size_t size, double sampleRate)
632 WebAudioBus webAudioBus;
633 if (webKitClient()->loadAudioResource(&webAudioBus, data, size, sampleRate))
634 return webAudioBus.release();
638 #endif // ENABLE(WEB_AUDIO)
640 // Sandbox --------------------------------------------------------------------
642 bool PlatformBridge::sandboxEnabled()
644 return webKitClient()->sandboxEnabled();
647 // SharedTimers ---------------------------------------------------------------
649 void PlatformBridge::setSharedTimerFiredFunction(void (*func)())
651 webKitClient()->setSharedTimerFiredFunction(func);
654 void PlatformBridge::setSharedTimerFireTime(double fireTime)
656 webKitClient()->setSharedTimerFireTime(fireTime);
659 void PlatformBridge::stopSharedTimer()
661 webKitClient()->stopSharedTimer();
664 // StatsCounters --------------------------------------------------------------
666 void PlatformBridge::decrementStatsCounter(const char* name)
668 webKitClient()->decrementStatsCounter(name);
671 void PlatformBridge::incrementStatsCounter(const char* name)
673 webKitClient()->incrementStatsCounter(name);
676 void PlatformBridge::histogramCustomCounts(const char* name, int sample, int min, int max, int bucketCount)
678 webKitClient()->histogramCustomCounts(name, sample, min, max, bucketCount);
681 void PlatformBridge::histogramEnumeration(const char* name, int sample, int boundaryValue)
683 webKitClient()->histogramEnumeration(name, sample, boundaryValue);
686 // Sudden Termination ---------------------------------------------------------
688 void PlatformBridge::suddenTerminationChanged(bool enabled)
690 webKitClient()->suddenTerminationChanged(enabled);
693 // SystemTime -----------------------------------------------------------------
695 double PlatformBridge::currentTime()
697 return webKitClient()->currentTime();
700 // Theming --------------------------------------------------------------------
704 void PlatformBridge::paintButton(
705 GraphicsContext* gc, int part, int state, int classicState,
708 webKitClient()->themeEngine()->paintButton(
709 gc->platformContext()->canvas(), part, state, classicState, rect);
712 void PlatformBridge::paintMenuList(
713 GraphicsContext* gc, int part, int state, int classicState,
716 webKitClient()->themeEngine()->paintMenuList(
717 gc->platformContext()->canvas(), part, state, classicState, rect);
720 void PlatformBridge::paintScrollbarArrow(
721 GraphicsContext* gc, int state, int classicState,
724 webKitClient()->themeEngine()->paintScrollbarArrow(
725 gc->platformContext()->canvas(), state, classicState, rect);
728 void PlatformBridge::paintScrollbarThumb(
729 GraphicsContext* gc, int part, int state, int classicState,
732 webKitClient()->themeEngine()->paintScrollbarThumb(
733 gc->platformContext()->canvas(), part, state, classicState, rect);
736 void PlatformBridge::paintScrollbarTrack(
737 GraphicsContext* gc, int part, int state, int classicState,
738 const IntRect& rect, const IntRect& alignRect)
740 webKitClient()->themeEngine()->paintScrollbarTrack(
741 gc->platformContext()->canvas(), part, state, classicState, rect,
745 void PlatformBridge::paintSpinButton(
746 GraphicsContext* gc, int part, int state, int classicState,
749 webKitClient()->themeEngine()->paintSpinButton(
750 gc->platformContext()->canvas(), part, state, classicState, rect);
753 void PlatformBridge::paintTextField(
754 GraphicsContext* gc, int part, int state, int classicState,
755 const IntRect& rect, const Color& color, bool fillContentArea,
758 // Fallback to white when |color| is invalid.
759 RGBA32 backgroundColor = color.isValid() ? color.rgb() : Color::white;
761 webKitClient()->themeEngine()->paintTextField(
762 gc->platformContext()->canvas(), part, state, classicState, rect,
763 backgroundColor, fillContentArea, drawEdges);
766 void PlatformBridge::paintTrackbar(
767 GraphicsContext* gc, int part, int state, int classicState,
770 webKitClient()->themeEngine()->paintTrackbar(
771 gc->platformContext()->canvas(), part, state, classicState, rect);
774 void PlatformBridge::paintProgressBar(
775 GraphicsContext* gc, const IntRect& barRect, const IntRect& valueRect, bool determinate, double animatedSeconds)
777 webKitClient()->themeEngine()->paintProgressBar(
778 gc->platformContext()->canvas(), barRect, valueRect, determinate, animatedSeconds);
783 static WebThemeEngine::Part WebThemePart(PlatformBridge::ThemePart part)
786 case PlatformBridge::PartScrollbarDownArrow: return WebThemeEngine::PartScrollbarDownArrow;
787 case PlatformBridge::PartScrollbarLeftArrow: return WebThemeEngine::PartScrollbarLeftArrow;
788 case PlatformBridge::PartScrollbarRightArrow: return WebThemeEngine::PartScrollbarRightArrow;
789 case PlatformBridge::PartScrollbarUpArrow: return WebThemeEngine::PartScrollbarUpArrow;
790 case PlatformBridge::PartScrollbarHorizontalThumb: return WebThemeEngine::PartScrollbarHorizontalThumb;
791 case PlatformBridge::PartScrollbarVerticalThumb: return WebThemeEngine::PartScrollbarVerticalThumb;
792 case PlatformBridge::PartScrollbarHorizontalTrack: return WebThemeEngine::PartScrollbarHorizontalTrack;
793 case PlatformBridge::PartScrollbarVerticalTrack: return WebThemeEngine::PartScrollbarVerticalTrack;
795 ASSERT_NOT_REACHED();
796 return WebThemeEngine::PartScrollbarDownArrow;
799 static WebThemeEngine::State WebThemeState(PlatformBridge::ThemePaintState state)
802 case PlatformBridge::StateDisabled: return WebThemeEngine::StateDisabled;
803 case PlatformBridge::StateHover: return WebThemeEngine::StateHover;
804 case PlatformBridge::StateNormal: return WebThemeEngine::StateNormal;
805 case PlatformBridge::StatePressed: return WebThemeEngine::StatePressed;
807 ASSERT_NOT_REACHED();
808 return WebThemeEngine::StateDisabled;
811 static void GetWebThemeExtraParams(PlatformBridge::ThemePart part, PlatformBridge::ThemePaintState state, const PlatformBridge::ThemePaintExtraParams* extraParams, WebThemeEngine::ExtraParams* webThemeExtraParams)
813 if (part == PlatformBridge::PartScrollbarHorizontalTrack || part == PlatformBridge::PartScrollbarVerticalTrack) {
814 webThemeExtraParams->scrollbarTrack.trackX = extraParams->scrollbarTrack.trackX;
815 webThemeExtraParams->scrollbarTrack.trackY = extraParams->scrollbarTrack.trackY;
816 webThemeExtraParams->scrollbarTrack.trackWidth = extraParams->scrollbarTrack.trackWidth;
817 webThemeExtraParams->scrollbarTrack.trackHeight = extraParams->scrollbarTrack.trackHeight;
821 IntSize PlatformBridge::getThemePartSize(ThemePart part)
823 return webKitClient()->themeEngine()->getSize(WebThemePart(part));
826 void PlatformBridge::paintThemePart(
827 GraphicsContext* gc, ThemePart part, ThemePaintState state, const IntRect& rect, const ThemePaintExtraParams* extraParams)
829 WebThemeEngine::ExtraParams webThemeExtraParams;
830 GetWebThemeExtraParams(part, state, extraParams, &webThemeExtraParams);
831 webKitClient()->themeEngine()->paint(
832 gc->platformContext()->canvas(), WebThemePart(part), WebThemeState(state), rect, &webThemeExtraParams);
837 void PlatformBridge::paintScrollbarThumb(
838 GraphicsContext* gc, ThemePaintState state, ThemePaintSize size, const IntRect& rect, const ThemePaintScrollbarInfo& scrollbarInfo)
840 WebThemeEngine::ScrollbarInfo webThemeScrollbarInfo;
842 webThemeScrollbarInfo.orientation = static_cast<WebThemeEngine::ScrollbarOrientation>(scrollbarInfo.orientation);
843 webThemeScrollbarInfo.parent = static_cast<WebThemeEngine::ScrollbarParent>(scrollbarInfo.parent);
844 webThemeScrollbarInfo.maxValue = scrollbarInfo.maxValue;
845 webThemeScrollbarInfo.currentValue = scrollbarInfo.currentValue;
846 webThemeScrollbarInfo.visibleSize = scrollbarInfo.visibleSize;
847 webThemeScrollbarInfo.totalSize = scrollbarInfo.totalSize;
849 webKitClient()->themeEngine()->paintScrollbarThumb(
850 gc->platformContext(),
851 static_cast<WebThemeEngine::State>(state),
852 static_cast<WebThemeEngine::Size>(size),
854 webThemeScrollbarInfo);
859 // Trace Event ----------------------------------------------------------------
861 void PlatformBridge::traceEventBegin(const char* name, void* id, const char* extra)
863 webKitClient()->traceEventBegin(name, id, extra);
866 void PlatformBridge::traceEventEnd(const char* name, void* id, const char* extra)
868 webKitClient()->traceEventEnd(name, id, extra);
871 // Visited Links --------------------------------------------------------------
873 LinkHash PlatformBridge::visitedLinkHash(const UChar* url, unsigned length)
875 url_canon::RawCanonOutput<2048> buffer;
876 url_parse::Parsed parsed;
877 if (!url_util::Canonicalize(url, length, 0, &buffer, &parsed))
878 return 0; // Invalid URLs are unvisited.
879 return webKitClient()->visitedLinkHash(buffer.data(), buffer.length());
882 LinkHash PlatformBridge::visitedLinkHash(const KURL& base,
883 const AtomicString& attributeURL)
885 // Resolve the relative URL using googleurl and pass the absolute URL up to
886 // the embedder. We could create a GURL object from the base and resolve
887 // the relative URL that way, but calling the lower-level functions
888 // directly saves us the string allocation in most cases.
889 url_canon::RawCanonOutput<2048> buffer;
890 url_parse::Parsed parsed;
893 const CString& cstr = base.utf8String();
894 const char* data = cstr.data();
895 int length = cstr.length();
896 const url_parse::Parsed& srcParsed = base.parsed();
898 // When we're not using GoogleURL, first canonicalize it so we can resolve it
900 url_canon::RawCanonOutput<2048> srcCanon;
901 url_parse::Parsed srcParsed;
902 String str = base.string();
903 if (!url_util::Canonicalize(str.characters(), str.length(), 0, &srcCanon, &srcParsed))
905 const char* data = srcCanon.data();
906 int length = srcCanon.length();
909 if (!url_util::ResolveRelative(data, length, srcParsed, attributeURL.characters(),
910 attributeURL.length(), 0, &buffer, &parsed))
911 return 0; // Invalid resolved URL.
913 return webKitClient()->visitedLinkHash(buffer.data(), buffer.length());
916 bool PlatformBridge::isLinkVisited(LinkHash visitedLinkHash)
918 return webKitClient()->isLinkVisited(visitedLinkHash);
921 // These are temporary methods that the WebKit layer can use to call to the
922 // Glue layer. Once the Glue layer moves entirely into the WebKit layer, these
923 // methods will be deleted.
925 void PlatformBridge::notifyJSOutOfMemory(Frame* frame)
930 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame);
931 if (!webFrame->client())
933 webFrame->client()->didExhaustMemoryAvailableForScript(webFrame);
936 int PlatformBridge::memoryUsageMB()
938 return static_cast<int>(webKitClient()->memoryUsageMB());
941 int PlatformBridge::actualMemoryUsageMB()
943 return static_cast<int>(webKitClient()->actualMemoryUsageMB());
946 int PlatformBridge::screenDepth(Widget* widget)
948 WebWidgetClient* client = toWebWidgetClient(widget);
951 return client->screenInfo().depth;
954 int PlatformBridge::screenDepthPerComponent(Widget* widget)
956 WebWidgetClient* client = toWebWidgetClient(widget);
959 return client->screenInfo().depthPerComponent;
962 bool PlatformBridge::screenIsMonochrome(Widget* widget)
964 WebWidgetClient* client = toWebWidgetClient(widget);
967 return client->screenInfo().isMonochrome;
970 IntRect PlatformBridge::screenRect(Widget* widget)
972 WebWidgetClient* client = toWebWidgetClient(widget);
975 return client->screenInfo().rect;
978 IntRect PlatformBridge::screenAvailableRect(Widget* widget)
980 WebWidgetClient* client = toWebWidgetClient(widget);
983 return client->screenInfo().availableRect;
986 bool PlatformBridge::popupsAllowed(NPP npp)
988 // FIXME: Give the embedder a way to control this.
992 WorkerContextProxy* WorkerContextProxy::create(Worker* worker)
994 return WebWorkerClientImpl::createWorkerContextProxy(worker);
997 } // namespace WebCore