1/*
2 * Copyright 2009, The Android Open Source Project
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *  * Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 *  * Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include <PlatformBridge.h>
28
29#include "CookieClient.h"
30#include "JavaSharedClient.h"
31#include "KeyGeneratorClient.h"
32#include "PluginView.h"
33#include "WebViewCore.h"
34#include "npruntime.h"
35#include <wtf/android/AndroidThreading.h>
36#include <wtf/MainThread.h>
37
38#if USE(ACCELERATED_COMPOSITING)
39#include "LayerAndroid.h"
40#endif
41
42using namespace android;
43
44namespace WebCore {
45
46#if USE(ACCELERATED_COMPOSITING)
47
48void PlatformBridge::setUIRootLayer(const WebCore::FrameView* view, const LayerAndroid* layer)
49{
50    android::WebViewCore* core = android::WebViewCore::getWebViewCore(view);
51    core->setUIRootLayer(layer);
52}
53
54void PlatformBridge::immediateRepaint(const WebCore::FrameView* view)
55{
56    android::WebViewCore* core = android::WebViewCore::getWebViewCore(view);
57    core->immediateRepaint();
58}
59
60#endif // USE(ACCELERATED_COMPOSITING)
61
62int PlatformBridge::screenWidth(const WebCore::FrameView* view)
63{
64    android::WebViewCore* core = android::WebViewCore::getWebViewCore(view);
65    return static_cast<int>((core->screenWidthScale() * core->screenWidth()) / core->scale());
66}
67
68int PlatformBridge::screenHeight(const WebCore::FrameView* view)
69{
70    android::WebViewCore* core = android::WebViewCore::getWebViewCore(view);
71    return core->screenHeight();
72}
73
74WTF::Vector<String> PlatformBridge::getSupportedKeyStrengthList()
75{
76    KeyGeneratorClient* client = JavaSharedClient::GetKeyGeneratorClient();
77    if (!client)
78        return Vector<String>();
79
80    return client->getSupportedKeyStrengthList();
81}
82
83String PlatformBridge::getSignedPublicKeyAndChallengeString(unsigned index, const String& challenge, const KURL& url)
84{
85    KeyGeneratorClient* client = JavaSharedClient::GetKeyGeneratorClient();
86    if (!client)
87        return String();
88
89    return client->getSignedPublicKeyAndChallengeString(index, challenge, url);
90}
91
92void PlatformBridge::setCookies(const KURL& url, const String& value)
93{
94    CookieClient* client = JavaSharedClient::GetCookieClient();
95    if (!client)
96        return;
97
98    client->setCookies(url, value);
99}
100
101String PlatformBridge::cookies(const KURL& url)
102{
103    CookieClient* client = JavaSharedClient::GetCookieClient();
104    if (!client)
105        return String();
106
107    return client->cookies(url);
108}
109
110bool PlatformBridge::cookiesEnabled()
111{
112    CookieClient* client = JavaSharedClient::GetCookieClient();
113    if (!client)
114        return false;
115
116    return client->cookiesEnabled();
117}
118
119NPObject* PlatformBridge::pluginScriptableObject(Widget* widget)
120{
121#if USE(V8)
122    if (!widget->isPluginView())
123        return 0;
124
125    PluginView* pluginView = static_cast<PluginView*>(widget);
126    return pluginView->getNPObject();
127#else
128    return 0;
129#endif
130}
131
132bool PlatformBridge::isWebViewPaused(const WebCore::FrameView* frameView)
133{
134    android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView);
135    return webViewCore->isPaused();
136}
137
138bool PlatformBridge::popupsAllowed(NPP)
139{
140    return false;
141}
142
143}  // namespace WebCore
144
145
146// This is the implementation of AndroidThreading, which is declared in
147// JavaScriptCore/wtf/android/AndroidThreading.h. It is provided here, rather
148// than in its own source file, to avoid linker problems.
149//
150// By default, when building a shared library, the linker strips from static
151// libraries any compilation units which do not contain any code referenced from
152// that static library. Since
153// AndroidThreading::scheduleDispatchFunctionsOnMainThread is not referenced
154// from libwebcore.a, implementing it in its own compilation unit results in it
155// being stripped. This stripping can be avoided by using the linker option
156// --whole-archive for libwebcore.a, but this adds considerably to the size of
157// libwebcore.so.
158
159namespace WTF {
160
161// Callback in the main thread.
162static void timeoutFired(void*)
163{
164    dispatchFunctionsFromMainThread();
165}
166
167void AndroidThreading::scheduleDispatchFunctionsOnMainThread()
168{
169    JavaSharedClient::EnqueueFunctionPtr(timeoutFired, 0);
170}
171
172}  // namespace WTF
173