102f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba/* 202f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * Copyright 2009, The Android Open Source Project 302f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * 402f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * Redistribution and use in source and binary forms, with or without 502f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * modification, are permitted provided that the following conditions 602f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * are met: 702f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * * Redistributions of source code must retain the above copyright 802f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * notice, this list of conditions and the following disclaimer. 902f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * * Redistributions in binary form must reproduce the above copyright 1002f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * notice, this list of conditions and the following disclaimer in the 1102f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * documentation and/or other materials provided with the distribution. 1202f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * 1302f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 1402f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1502f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16e03118fd5d9b776df29de3f96232ed6b5395c845Steve Block * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1702f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1802f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1902f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2002f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 2102f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2202f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2302f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2402f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba */ 2502f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba 261890130f485b2a3365409653a1b83396a02eed94Andrei Popescu#include "config.h" 2740a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu#include <PlatformBridge.h> 2840a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu 2940a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu#include "CookieClient.h" 30918f81255bd5490e0536420428111e71d31ae209Elliott Slaughter#include "Document.h" 317b52283c1a7f90ff5441d7bc30677c91af016b22Ben Murdoch#include "FileSystemClient.h" 32f116b073399a3c3f644d6e6aeb2521ef9d2c9e9bLeon Scroggins III#include "FrameView.h" 333e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch#include "JNIUtility.h" 341890130f485b2a3365409653a1b83396a02eed94Andrei Popescu#include "JavaSharedClient.h" 351890130f485b2a3365409653a1b83396a02eed94Andrei Popescu#include "KeyGeneratorClient.h" 36e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch#include "MemoryUsage.h" 37b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu#include "PluginView.h" 38a3d6f6aedc8ed044682d65258bb964c64fc7511bNicolas Roard#include "RenderLayer.h" 39a3d6f6aedc8ed044682d65258bb964c64fc7511bNicolas Roard#include "RenderView.h" 40918f81255bd5490e0536420428111e71d31ae209Elliott Slaughter#include "Settings.h" 418a5f8b64a112f92833cd718f9b401c996918081bKristian Monsen#include "WebCookieJar.h" 423e1fb9526199fc05fdb2266189e71728299745c0Kristian Monsen#include "WebRequestContext.h" 43797e4f1087e408060f2812c79bddcd2b73a3830dNicolas Roard#include "WebViewCore.h" 44b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu#include "npruntime.h" 45a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block 465b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown#include <gui/ISurfaceComposer.h> 479f6ce052a4112e9ffe56da94153c89e841219be4Mathias Agopian#include <gui/SurfaceComposerClient.h> 48a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block#include <ui/DisplayInfo.h> 49a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block#include <ui/PixelFormat.h> 505df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block#include <wtf/android/AndroidThreading.h> 515df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block#include <wtf/MainThread.h> 5202f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba 53a30818b6d22801f8f2f4d6f29dd83d3eddb67b6fVictoria Lease#include <algorithm> 54a30818b6d22801f8f2f4d6f29dd83d3eddb67b6fVictoria Lease 551890130f485b2a3365409653a1b83396a02eed94Andrei Popescuusing namespace android; 567576971da15c4fb3eac2800cc74d635beac50e07Andrei Popescu 571890130f485b2a3365409653a1b83396a02eed94Andrei Popescunamespace WebCore { 5802f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba 591890130f485b2a3365409653a1b83396a02eed94Andrei PopescuWTF::Vector<String> PlatformBridge::getSupportedKeyStrengthList() 601890130f485b2a3365409653a1b83396a02eed94Andrei Popescu{ 611890130f485b2a3365409653a1b83396a02eed94Andrei Popescu KeyGeneratorClient* client = JavaSharedClient::GetKeyGeneratorClient(); 621890130f485b2a3365409653a1b83396a02eed94Andrei Popescu if (!client) 63a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block return WTF::Vector<String>(); 6402f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba 651890130f485b2a3365409653a1b83396a02eed94Andrei Popescu return client->getSupportedKeyStrengthList(); 6602f5cda5965b8aba67f5bdb5d308002920b9a05aGrace Kloba} 671890130f485b2a3365409653a1b83396a02eed94Andrei Popescu 681890130f485b2a3365409653a1b83396a02eed94Andrei PopescuString PlatformBridge::getSignedPublicKeyAndChallengeString(unsigned index, const String& challenge, const KURL& url) 691890130f485b2a3365409653a1b83396a02eed94Andrei Popescu{ 701890130f485b2a3365409653a1b83396a02eed94Andrei Popescu KeyGeneratorClient* client = JavaSharedClient::GetKeyGeneratorClient(); 711890130f485b2a3365409653a1b83396a02eed94Andrei Popescu if (!client) 721890130f485b2a3365409653a1b83396a02eed94Andrei Popescu return String(); 731890130f485b2a3365409653a1b83396a02eed94Andrei Popescu 741890130f485b2a3365409653a1b83396a02eed94Andrei Popescu return client->getSignedPublicKeyAndChallengeString(index, challenge, url); 751890130f485b2a3365409653a1b83396a02eed94Andrei Popescu} 761890130f485b2a3365409653a1b83396a02eed94Andrei Popescu 77918f81255bd5490e0536420428111e71d31ae209Elliott Slaughtervoid PlatformBridge::setCookies(const Document* document, const KURL& url, const String& value) 7840a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu{ 793e1fb9526199fc05fdb2266189e71728299745c0Kristian Monsen std::string cookieValue(value.utf8().data()); 803e1fb9526199fc05fdb2266189e71728299745c0Kristian Monsen GURL cookieGurl(url.string().utf8().data()); 81f6c40294adb5fce93668a0e92e8731e21752a1dfSteve Block bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled(); 82dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount WebCookieJar* cookieJar = WebCookieJar::get(isPrivateBrowsing); 83dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount if (cookieJar->allowCookies()) 84dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount cookieJar->cookieStore()->SetCookie(cookieGurl, cookieValue); 8540a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu} 8640a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu 87918f81255bd5490e0536420428111e71d31ae209Elliott SlaughterString PlatformBridge::cookies(const Document* document, const KURL& url) 8840a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu{ 893e1fb9526199fc05fdb2266189e71728299745c0Kristian Monsen GURL cookieGurl(url.string().utf8().data()); 90f6c40294adb5fce93668a0e92e8731e21752a1dfSteve Block bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled(); 91dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount WebCookieJar* cookieJar = WebCookieJar::get(isPrivateBrowsing); 92dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount String cookieString; 93dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount if (cookieJar->allowCookies()) { 94dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount std::string cookies = cookieJar->cookieStore()->GetCookies(cookieGurl); 95dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount cookieString = cookies.c_str(); 96dea81519c4952136ae22d26e3d7395535d39691cGeorge Mount } 973e1fb9526199fc05fdb2266189e71728299745c0Kristian Monsen return cookieString; 9840a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu} 9940a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu 100918f81255bd5490e0536420428111e71d31ae209Elliott Slaughterbool PlatformBridge::cookiesEnabled(const Document* document) 10140a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu{ 102965d128a2f803da81a8a6d04c3d79382ff827bb9Steve Block bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled(); 1038a5f8b64a112f92833cd718f9b401c996918081bKristian Monsen return WebCookieJar::get(isPrivateBrowsing)->allowCookies(); 10440a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu} 10540a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu 106b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei PopescuNPObject* PlatformBridge::pluginScriptableObject(Widget* widget) 107b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu{ 108b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu if (!widget->isPluginView()) 109b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu return 0; 110b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu 111b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu PluginView* pluginView = static_cast<PluginView*>(widget); 112b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu return pluginView->getNPObject(); 113b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu} 114b9ca2665dcffd57d63df89bca0444f1cee8d0feeAndrei Popescu 115dcb9f821994a3c585bc51d6f1a6a356a6034de5bAndrei Popescubool PlatformBridge::popupsAllowed(NPP) 116dcb9f821994a3c585bc51d6f1a6a356a6034de5bAndrei Popescu{ 117dcb9f821994a3c585bc51d6f1a6a356a6034de5bAndrei Popescu return false; 118dcb9f821994a3c585bc51d6f1a6a356a6034de5bAndrei Popescu} 119dcb9f821994a3c585bc51d6f1a6a356a6034de5bAndrei Popescu 12010bcdb2eab81b5b9c893faf90f5bd9f396edeb4aBen MurdochString PlatformBridge::resolveFilePathForContentUri(const String& contentUri) 1217b52283c1a7f90ff5441d7bc30677c91af016b22Ben Murdoch{ 1227b52283c1a7f90ff5441d7bc30677c91af016b22Ben Murdoch FileSystemClient* client = JavaSharedClient::GetFileSystemClient(); 12310bcdb2eab81b5b9c893faf90f5bd9f396edeb4aBen Murdoch return client->resolveFilePathForContentUri(contentUri); 1247b52283c1a7f90ff5441d7bc30677c91af016b22Ben Murdoch} 1257b52283c1a7f90ff5441d7bc30677c91af016b22Ben Murdoch 126a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Blockint PlatformBridge::PlatformBridge::screenDepth() 127a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block{ 1285b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::sp<android::IBinder> display( 1295b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::SurfaceComposerClient::getBuiltInDisplay( 1305b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::ISurfaceComposer::eDisplayIdMain)); 131a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block android::DisplayInfo info; 1325b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::SurfaceComposerClient::getDisplayInfo(display, &info); 133a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block return info.pixelFormatInfo.bitsPerPixel; 134a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block} 135a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block 136a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve BlockFloatRect PlatformBridge::screenRect() 137a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block{ 1385b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::sp<android::IBinder> display( 1395b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::SurfaceComposerClient::getBuiltInDisplay( 1405b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::ISurfaceComposer::eDisplayIdMain)); 141a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block android::DisplayInfo info; 1425b30c69cf29e28981f69c96296aebaf745b08e47Jeff Brown android::SurfaceComposerClient::getDisplayInfo(display, &info); 143a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block return FloatRect(0.0, 0.0, info.w, info.h); 144a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block} 145a670d9b37b9afce0ec7e53d72e375b6ac9ca04dfSteve Block 1460026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu// The visible size on screen in document coordinate 1473a7568b5aa8ee4ef6ba961eae690b498f5ba8e9eTeng-Hui Zhuint PlatformBridge::screenWidthInDocCoord(const WebCore::FrameView* frameView) 1480026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu{ 1490026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView); 1503a7568b5aa8ee4ef6ba961eae690b498f5ba8e9eTeng-Hui Zhu return webViewCore->screenWidth(); 1510026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu} 1520026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu 1533a7568b5aa8ee4ef6ba961eae690b498f5ba8e9eTeng-Hui Zhuint PlatformBridge::screenHeightInDocCoord(const WebCore::FrameView* frameView) 1540026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu{ 1550026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView); 1563a7568b5aa8ee4ef6ba961eae690b498f5ba8e9eTeng-Hui Zhu return webViewCore->screenHeight(); 1570026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu} 1580026842c0dc9cc472966e6ef44b707683ca5317bTeng-Hui Zhu 159e8e7e7f47930d953f99108f9a82214f2f2a5a7bcTeng-Hui ZhuString PlatformBridge::computeDefaultLanguage() 160e8e7e7f47930d953f99108f9a82214f2f2a5a7bcTeng-Hui Zhu{ 16163ebc0f62b5ab9255998d79dfa25ed607118938fSteve Block String acceptLanguages = WebRequestContext::acceptLanguage(); 162e8e7e7f47930d953f99108f9a82214f2f2a5a7bcTeng-Hui Zhu size_t length = acceptLanguages.find(','); 163e8e7e7f47930d953f99108f9a82214f2f2a5a7bcTeng-Hui Zhu if (length == std::string::npos) 164e8e7e7f47930d953f99108f9a82214f2f2a5a7bcTeng-Hui Zhu length = acceptLanguages.length(); 16563ebc0f62b5ab9255998d79dfa25ed607118938fSteve Block return acceptLanguages.substring(0, length); 166e8e7e7f47930d953f99108f9a82214f2f2a5a7bcTeng-Hui Zhu} 167e8e7e7f47930d953f99108f9a82214f2f2a5a7bcTeng-Hui Zhu 168f4220bb8c200137e401bfce313ec01c6dc1e59e0Ben Murdochvoid PlatformBridge::updateViewport(FrameView* frameView) 169f4220bb8c200137e401bfce313ec01c6dc1e59e0Ben Murdoch{ 170f4220bb8c200137e401bfce313ec01c6dc1e59e0Ben Murdoch android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView); 171f4220bb8c200137e401bfce313ec01c6dc1e59e0Ben Murdoch webViewCore->updateViewport(); 172f4220bb8c200137e401bfce313ec01c6dc1e59e0Ben Murdoch} 173f4220bb8c200137e401bfce313ec01c6dc1e59e0Ben Murdoch 174bc17d11c07d97392bb41b9d707726bec5c8cb64dGeorge Mountvoid PlatformBridge::updateTextfield(FrameView* frameView, Node* nodePtr, const WTF::String& text) 1759dd59112365c6368f9d510822009c59f1981d670Ben Murdoch{ 1769dd59112365c6368f9d510822009c59f1981d670Ben Murdoch android::WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frameView); 177bc17d11c07d97392bb41b9d707726bec5c8cb64dGeorge Mount webViewCore->updateTextfield(nodePtr, text); 1789dd59112365c6368f9d510822009c59f1981d670Ben Murdoch} 1799dd59112365c6368f9d510822009c59f1981d670Ben Murdoch 180d15092ffa5957f6f3a2f4709db4e6a49130eab0eShimeng (Simon) Wangvoid PlatformBridge::setScrollPosition(ScrollView* scrollView, int x, int y) { 181a30818b6d22801f8f2f4d6f29dd83d3eddb67b6fVictoria Lease FrameView* frameView = scrollView->frameView(); 182a30818b6d22801f8f2f4d6f29dd83d3eddb67b6fVictoria Lease if (!frameView) return; 183d15092ffa5957f6f3a2f4709db4e6a49130eab0eShimeng (Simon) Wang // Check to make sure the view is the main FrameView. 184d15092ffa5957f6f3a2f4709db4e6a49130eab0eShimeng (Simon) Wang android::WebViewCore *webViewCore = android::WebViewCore::getWebViewCore(scrollView); 185a30818b6d22801f8f2f4d6f29dd83d3eddb67b6fVictoria Lease if (webViewCore->mainFrame()->view() == scrollView) { 186a30818b6d22801f8f2f4d6f29dd83d3eddb67b6fVictoria Lease x = std::max(0, std::min(frameView->contentsWidth(), x)); 187a30818b6d22801f8f2f4d6f29dd83d3eddb67b6fVictoria Lease y = std::max(0, std::min(frameView->contentsHeight(), y)); 18823a9c23ab28314661206716c0846f6a10f34c5a7Victoria Lease webViewCore->scrollTo(x, y); 189a3d6f6aedc8ed044682d65258bb964c64fc7511bNicolas Roard } 190d15092ffa5957f6f3a2f4709db4e6a49130eab0eShimeng (Simon) Wang} 191d15092ffa5957f6f3a2f4709db4e6a49130eab0eShimeng (Simon) Wang 192e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdochint PlatformBridge::lowMemoryUsageMB() 193e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch{ 194e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch return MemoryUsage::lowMemoryUsageMb(); 195e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch} 196e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch 197e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdochint PlatformBridge::highMemoryUsageMB() 198e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch{ 199e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch return MemoryUsage::highMemoryUsageMb(); 200e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch} 201e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch 2026e8da6e69536dd9fd167ad0f7a429c43cea6e6d2Shimeng (Simon) Wangint PlatformBridge::highUsageDeltaMB() 2036e8da6e69536dd9fd167ad0f7a429c43cea6e6d2Shimeng (Simon) Wang{ 2046e8da6e69536dd9fd167ad0f7a429c43cea6e6d2Shimeng (Simon) Wang return MemoryUsage::highUsageDeltaMb(); 2056e8da6e69536dd9fd167ad0f7a429c43cea6e6d2Shimeng (Simon) Wang} 2066e8da6e69536dd9fd167ad0f7a429c43cea6e6d2Shimeng (Simon) Wang 207e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdochint PlatformBridge::memoryUsageMB() 208e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch{ 209e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch return MemoryUsage::memoryUsageMb(false); 210e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch} 211e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch 212e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdochint PlatformBridge::actualMemoryUsageMB() 213e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch{ 214e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch return MemoryUsage::memoryUsageMb(true); 215e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch} 216e02b67f8cfa87b8e952bcae834e4f3d3937fcc98Ben Murdoch 2173e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdochbool PlatformBridge::canSatisfyMemoryAllocation(long bytes) 2183e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch{ 2193e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch JNIEnv* env = JSC::Bindings::getJNIEnv(); 2203e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch jclass bridgeClass = env->FindClass("android/webkit/JniUtil"); 2213e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch jmethodID method = env->GetStaticMethodID(bridgeClass, "canSatisfyMemoryAllocation", "(J)Z"); 2223e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch jboolean canAllocate = env->CallStaticBooleanMethod(bridgeClass, method, static_cast<jlong>(bytes)); 2233e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch env->DeleteLocalRef(bridgeClass); 2243e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch 2253e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch return canAllocate == JNI_TRUE; 2263e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch} 2273e556736c899f74f2ccc010a8bc7401c36e9a1a0Ben Murdoch 2285df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block} // namespace WebCore 2295df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block 2305df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block 2315df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// This is the implementation of AndroidThreading, which is declared in 2325df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// JavaScriptCore/wtf/android/AndroidThreading.h. It is provided here, rather 2335df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// than in its own source file, to avoid linker problems. 2345df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// 2355df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// By default, when building a shared library, the linker strips from static 2365df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// libraries any compilation units which do not contain any code referenced from 2375df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// that static library. Since 2385df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// AndroidThreading::scheduleDispatchFunctionsOnMainThread is not referenced 2395df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// from libwebcore.a, implementing it in its own compilation unit results in it 2405df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// being stripped. This stripping can be avoided by using the linker option 2415df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// --whole-archive for libwebcore.a, but this adds considerably to the size of 2425df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// libwebcore.so. 2435df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block 2445df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Blocknamespace WTF { 2455df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block 2465df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block// Callback in the main thread. 2475df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Blockstatic void timeoutFired(void*) 2485df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block{ 2495df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block dispatchFunctionsFromMainThread(); 2505df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block} 2515df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block 2525df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Blockvoid AndroidThreading::scheduleDispatchFunctionsOnMainThread() 2535df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block{ 2545df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block JavaSharedClient::EnqueueFunctionPtr(timeoutFired, 0); 2555df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block} 25640a90188cf739cbcc2a44669c05ca526aaf0b0d8Andrei Popescu 2575df9fcdb69c1d4f2009e1f7bad0d969f164dffc0Steve Block} // namespace WTF 258