1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h"
9 #include "base/logging.h"
10 #include "base/strings/string16.h"
11 #include "base/threading/platform_thread.h"
12 #include "build/build_config.h"
13 #include "content/child/child_thread.h"
14 #include "content/common/child_process_messages.h"
15 #include "ppapi/proxy/plugin_globals.h"
16 #include "ppapi/shared_impl/proxy_lock.h"
17 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/win/WebSandboxSupport.h"
21 #elif defined(OS_MACOSX)
22 #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h"
23 #elif defined(OS_ANDROID)
24 #include "third_party/WebKit/public/platform/android/WebSandboxSupport.h"
25 #elif defined(OS_POSIX)
26 #include "content/common/child_process_sandbox_support_impl_linux.h"
27 #include "third_party/WebKit/public/platform/linux/WebFallbackFont.h"
28 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h"
29 #include "third_party/icu/source/common/unicode/utf16.h"
32 using blink::WebSandboxSupport
;
33 using blink::WebString
;
34 using blink::WebUChar
;
35 using blink::WebUChar32
;
37 typedef struct CGFont
* CGFontRef
;
41 class PpapiWebKitPlatformSupportImpl::SandboxSupport
42 : public WebSandboxSupport
{
44 virtual ~SandboxSupport() {}
47 virtual bool ensureFontLoaded(HFONT
);
48 #elif defined(OS_MACOSX)
49 virtual bool loadFont(
50 NSFont
* srcFont
, CGFontRef
* out
, uint32_t* fontID
);
51 #elif defined(OS_ANDROID)
53 #elif defined(OS_POSIX)
55 virtual void getFallbackFontForCharacter(
57 const char* preferred_locale
,
58 blink::WebFallbackFont
* fallbackFont
);
59 virtual void getRenderStyleForStrike(
60 const char* family
, int sizeAndStyle
, blink::WebFontRenderStyle
* out
);
63 // WebKit likes to ask us for the correct font family to use for a set of
64 // unicode code points. It needs this information frequently so we cache it
66 std::map
<int32_t, blink::WebFallbackFont
> unicode_font_families_
;
67 // For debugging crbug.com/312965
68 base::PlatformThreadId creation_thread_
;
74 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
77 GetObject(font
, sizeof(LOGFONT
), &logfont
);
79 // Use the proxy sender rather than going directly to the ChildThread since
80 // the proxy browser sender will properly unlock during sync messages.
81 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send(
82 new ChildProcessHostMsg_PreCacheFont(logfont
));
85 #elif defined(OS_MACOSX)
87 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
91 // TODO(brettw) this should do the something similar to what
92 // RendererWebKitClientImpl does and request that the browser load the font.
93 // Note: need to unlock the proxy lock like ensureFontLoaded does.
98 #elif defined(OS_ANDROID)
102 #elif defined(OS_POSIX)
104 PpapiWebKitPlatformSupportImpl::SandboxSupport::SandboxSupport()
105 : creation_thread_(base::PlatformThread::CurrentId()) {
109 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFallbackFontForCharacter(
110 WebUChar32 character
,
111 const char* preferred_locale
,
112 blink::WebFallbackFont
* fallbackFont
) {
113 ppapi::ProxyLock::AssertAcquired();
114 // For debugging crbug.com/312965
115 CHECK_EQ(creation_thread_
, base::PlatformThread::CurrentId());
116 const std::map
<int32_t, blink::WebFallbackFont
>::const_iterator iter
=
117 unicode_font_families_
.find(character
);
118 if (iter
!= unicode_font_families_
.end()) {
119 fallbackFont
->name
= iter
->second
.name
;
120 fallbackFont
->filename
= iter
->second
.filename
;
121 fallbackFont
->fontconfigInterfaceId
= iter
->second
.fontconfigInterfaceId
;
122 fallbackFont
->ttcIndex
= iter
->second
.ttcIndex
;
123 fallbackFont
->isBold
= iter
->second
.isBold
;
124 fallbackFont
->isItalic
= iter
->second
.isItalic
;
128 GetFallbackFontForCharacter(character
, preferred_locale
, fallbackFont
);
129 unicode_font_families_
.insert(std::make_pair(character
, *fallbackFont
));
132 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
133 const char* family
, int sizeAndStyle
, blink::WebFontRenderStyle
* out
) {
134 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
139 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
140 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
143 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
146 void PpapiWebKitPlatformSupportImpl::Shutdown() {
147 // SandboxSupport contains a map of WebFontFamily objects, which hold
148 // WebCStrings, which become invalidated when blink is shut down. Hence, we
149 // need to clear that map now, just before blink::shutdown() is called.
150 sandbox_support_
.reset();
153 blink::WebClipboard
* PpapiWebKitPlatformSupportImpl::clipboard() {
158 blink::WebMimeRegistry
* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
163 blink::WebFileUtilities
* PpapiWebKitPlatformSupportImpl::fileUtilities() {
168 blink::WebSandboxSupport
* PpapiWebKitPlatformSupportImpl::sandboxSupport() {
169 return sandbox_support_
.get();
172 bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() {
173 return true; // Assume PPAPI is always sandboxed.
176 unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash(
177 const char* canonical_url
,
183 bool PpapiWebKitPlatformSupportImpl::isLinkVisited(
184 unsigned long long link_hash
) {
189 void PpapiWebKitPlatformSupportImpl::createMessageChannel(
190 blink::WebMessagePortChannel
** channel1
,
191 blink::WebMessagePortChannel
** channel2
) {
197 void PpapiWebKitPlatformSupportImpl::setCookies(
198 const blink::WebURL
& url
,
199 const blink::WebURL
& first_party_for_cookies
,
200 const blink::WebString
& value
) {
204 blink::WebString
PpapiWebKitPlatformSupportImpl::cookies(
205 const blink::WebURL
& url
,
206 const blink::WebURL
& first_party_for_cookies
) {
208 return blink::WebString();
211 blink::WebString
PpapiWebKitPlatformSupportImpl::defaultLocale() {
213 return blink::WebString();
216 blink::WebThemeEngine
* PpapiWebKitPlatformSupportImpl::themeEngine() {
221 blink::WebURLLoader
* PpapiWebKitPlatformSupportImpl::createURLLoader() {
226 blink::WebSocketStreamHandle
*
227 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
232 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh
,
233 blink::WebPluginListBuilder
* builder
) {
237 blink::WebData
PpapiWebKitPlatformSupportImpl::loadResource(const char* name
) {
239 return blink::WebData();
242 blink::WebStorageNamespace
*
243 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace() {
248 void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent(
249 const blink::WebString
& key
, const blink::WebString
& old_value
,
250 const blink::WebString
& new_value
, const blink::WebString
& origin
,
251 const blink::WebURL
& url
, bool is_local_storage
) {
255 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
256 const blink::WebString
& vfs_file_name
, bool sync_dir
) {
261 } // namespace content