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
|
/*
* Copyright 2009, The Android Open Source Project
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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.
*/
#include "config.h"
#include <PlatformBridge.h>
#include "CookieClient.h"
#include "Document.h"
#include "FileSystemClient.h"
#include "FrameView.h"
#include "JNIUtility.h"
#include "JavaSharedClient.h"
#include "KeyGeneratorClient.h"
#include "MemoryUsage.h"
#include "PluginView.h"
#include "RenderLayer.h"
#include "RenderView.h"
#include "Settings.h"
#include "WebCookieJar.h"
#include "WebRequestContext.h"
#include "WebViewCore.h"
#include "npruntime.h"
#include <gui/SurfaceComposerClient.h>
#include <ui/DisplayInfo.h>
#include <ui/PixelFormat.h>
#include <wtf/android/AndroidThreading.h>
#include <wtf/MainThread.h>
#include <algorithm>
using namespace android;
namespace WebCore {
WTF::Vector<String> PlatformBridge::getSupportedKeyStrengthList()
{
KeyGeneratorClient* client = JavaSharedClient::GetKeyGeneratorClient();
if (!client)
return WTF::Vector<String>();
return client->getSupportedKeyStrengthList();
}
String PlatformBridge::getSignedPublicKeyAndChallengeString(unsigned index, const String& challenge, const KURL& url)
{
KeyGeneratorClient* client = JavaSharedClient::GetKeyGeneratorClient();
if (!client)
return String();
return client->getSignedPublicKeyAndChallengeString(index, challenge, url);
}
void PlatformBridge::setCookies(const Document* document, const KURL& url, const String& value)
{
std::string cookieValue(value.utf8().data());
GURL cookieGurl(url.string().utf8().data());
bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
WebCookieJar::get(isPrivateBrowsing)->cookieStore()->SetCookie(cookieGurl, cookieValue);
}
String PlatformBridge::cookies(const Document* document, const KURL& url)
{
GURL cookieGurl(url.string().utf8().data());
bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
std::string cookies = WebCookieJar::get(isPrivateBrowsing)->cookieStore()->GetCookies(cookieGurl);
String cookieString(cookies.c_str());
return cookieString;
}
bool PlatformBridge::cookiesEnabled(const Document* document)
{
bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
return WebCookieJar::get(isPrivateBrowsing)->allowCookies();
}
NPObject* PlatformBridge::pluginScriptableObject(Widget* widget)
{
if (!widget->isPluginView())
return 0;
PluginView* pluginView = static_cast<PluginView*>(widget);
return pluginView->getNPObject();
}
bool PlatformBridge::isWebViewPaused(const WebCore::FrameView* frameView)
{
android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView);
return webViewCore->isPaused();
}
bool PlatformBridge::popupsAllowed(NPP)
{
return false;
}
String PlatformBridge::resolveFilePathForContentUri(const String& contentUri)
{
FileSystemClient* client = JavaSharedClient::GetFileSystemClient();
return client->resolveFilePathForContentUri(contentUri);
}
int PlatformBridge::PlatformBridge::screenDepth()
{
android::DisplayInfo info;
android::SurfaceComposerClient::getDisplayInfo(android::DisplayID(0), &info);
return info.pixelFormatInfo.bitsPerPixel;
}
FloatRect PlatformBridge::screenRect()
{
android::DisplayInfo info;
android::SurfaceComposerClient::getDisplayInfo(android::DisplayID(0), &info);
return FloatRect(0.0, 0.0, info.w, info.h);
}
// The visible size on screen in document coordinate
int PlatformBridge::screenWidthInDocCoord(const WebCore::FrameView* frameView)
{
android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView);
return webViewCore->screenWidth();
}
int PlatformBridge::screenHeightInDocCoord(const WebCore::FrameView* frameView)
{
android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView);
return webViewCore->screenHeight();
}
String PlatformBridge::computeDefaultLanguage()
{
String acceptLanguages = WebRequestContext::acceptLanguage();
size_t length = acceptLanguages.find(',');
if (length == std::string::npos)
length = acceptLanguages.length();
return acceptLanguages.substring(0, length);
}
void PlatformBridge::updateViewport(FrameView* frameView)
{
android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView);
webViewCore->updateViewport();
}
void PlatformBridge::updateTextfield(FrameView* frameView, Node* nodePtr, bool changeToPassword, const WTF::String& text)
{
android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView);
webViewCore->updateTextfield(nodePtr, changeToPassword, text);
}
void PlatformBridge::setScrollPosition(ScrollView* scrollView, int x, int y) {
FrameView* frameView = scrollView->frameView();
if (!frameView) return;
// Check to make sure the view is the main FrameView.
android::WebViewCore *webViewCore = android::WebViewCore::getWebViewCore(scrollView);
if (webViewCore->mainFrame()->view() == scrollView) {
const IntRect& visibleContentRect = frameView->visibleContentRect();
x = std::max(0, std::min(frameView->contentsWidth(), x));
y = std::max(0, std::min(frameView->contentsHeight(), y));
if ((x != visibleContentRect.x()) || (y != visibleContentRect.y()))
webViewCore->scrollTo(x, y);
} else {
RenderView* renderer = frameView->frame()->contentRenderer();
if (renderer) {
RenderLayer* layer = renderer->layer();
layer->scrollToOffset(x, y);
}
}
}
int PlatformBridge::lowMemoryUsageMB()
{
return MemoryUsage::lowMemoryUsageMb();
}
int PlatformBridge::highMemoryUsageMB()
{
return MemoryUsage::highMemoryUsageMb();
}
int PlatformBridge::highUsageDeltaMB()
{
return MemoryUsage::highUsageDeltaMb();
}
int PlatformBridge::memoryUsageMB()
{
return MemoryUsage::memoryUsageMb(false);
}
int PlatformBridge::actualMemoryUsageMB()
{
return MemoryUsage::memoryUsageMb(true);
}
bool PlatformBridge::canSatisfyMemoryAllocation(long bytes)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
jclass bridgeClass = env->FindClass("android/webkit/JniUtil");
jmethodID method = env->GetStaticMethodID(bridgeClass, "canSatisfyMemoryAllocation", "(J)Z");
jboolean canAllocate = env->CallStaticBooleanMethod(bridgeClass, method, static_cast<jlong>(bytes));
env->DeleteLocalRef(bridgeClass);
return canAllocate == JNI_TRUE;
}
} // namespace WebCore
// This is the implementation of AndroidThreading, which is declared in
// JavaScriptCore/wtf/android/AndroidThreading.h. It is provided here, rather
// than in its own source file, to avoid linker problems.
//
// By default, when building a shared library, the linker strips from static
// libraries any compilation units which do not contain any code referenced from
// that static library. Since
// AndroidThreading::scheduleDispatchFunctionsOnMainThread is not referenced
// from libwebcore.a, implementing it in its own compilation unit results in it
// being stripped. This stripping can be avoided by using the linker option
// --whole-archive for libwebcore.a, but this adds considerably to the size of
// libwebcore.so.
namespace WTF {
// Callback in the main thread.
static void timeoutFired(void*)
{
dispatchFunctionsFromMainThread();
}
void AndroidThreading::scheduleDispatchFunctionsOnMainThread()
{
JavaSharedClient::EnqueueFunctionPtr(timeoutFired, 0);
}
} // namespace WTF
|