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_blink_platform_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_impl.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 PpapiBlinkPlatformImpl::SandboxSupport
: public WebSandboxSupport
{
43 virtual ~SandboxSupport() {}
46 virtual bool ensureFontLoaded(HFONT
);
47 #elif defined(OS_MACOSX)
48 virtual bool loadFont(NSFont
* srcFont
, CGFontRef
* out
, uint32_t* fontID
);
49 #elif defined(OS_ANDROID)
51 #elif defined(OS_POSIX)
53 virtual void getFallbackFontForCharacter(
55 const char* preferred_locale
,
56 blink::WebFallbackFont
* fallbackFont
);
57 virtual void getRenderStyleForStrike(const char* family
,
59 blink::WebFontRenderStyle
* out
);
62 // WebKit likes to ask us for the correct font family to use for a set of
63 // unicode code points. It needs this information frequently so we cache it
65 std::map
<int32_t, blink::WebFallbackFont
> unicode_font_families_
;
66 // For debugging crbug.com/312965
67 base::PlatformThreadId creation_thread_
;
73 bool PpapiBlinkPlatformImpl::SandboxSupport::ensureFontLoaded(HFONT font
) {
75 GetObject(font
, sizeof(LOGFONT
), &logfont
);
77 // Use the proxy sender rather than going directly to the ChildThread since
78 // the proxy browser sender will properly unlock during sync messages.
79 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send(
80 new ChildProcessHostMsg_PreCacheFont(logfont
));
83 #elif defined(OS_MACOSX)
85 bool PpapiBlinkPlatformImpl::SandboxSupport::loadFont(NSFont
* src_font
,
88 // TODO(brettw) this should do the something similar to what
89 // RendererBlinkPlatformImpl does and request that the browser load the font.
90 // Note: need to unlock the proxy lock like ensureFontLoaded does.
95 #elif defined(OS_ANDROID)
99 #elif defined(OS_POSIX)
101 PpapiBlinkPlatformImpl::SandboxSupport::SandboxSupport()
102 : creation_thread_(base::PlatformThread::CurrentId()) {
105 void PpapiBlinkPlatformImpl::SandboxSupport::getFallbackFontForCharacter(
106 WebUChar32 character
,
107 const char* preferred_locale
,
108 blink::WebFallbackFont
* fallbackFont
) {
109 ppapi::ProxyLock::AssertAcquired();
110 // For debugging crbug.com/312965
111 CHECK_EQ(creation_thread_
, base::PlatformThread::CurrentId());
112 const std::map
<int32_t, blink::WebFallbackFont
>::const_iterator iter
=
113 unicode_font_families_
.find(character
);
114 if (iter
!= unicode_font_families_
.end()) {
115 fallbackFont
->name
= iter
->second
.name
;
116 fallbackFont
->filename
= iter
->second
.filename
;
117 fallbackFont
->fontconfigInterfaceId
= iter
->second
.fontconfigInterfaceId
;
118 fallbackFont
->ttcIndex
= iter
->second
.ttcIndex
;
119 fallbackFont
->isBold
= iter
->second
.isBold
;
120 fallbackFont
->isItalic
= iter
->second
.isItalic
;
124 GetFallbackFontForCharacter(character
, preferred_locale
, fallbackFont
);
125 unicode_font_families_
.insert(std::make_pair(character
, *fallbackFont
));
128 void PpapiBlinkPlatformImpl::SandboxSupport::getRenderStyleForStrike(
131 blink::WebFontRenderStyle
* out
) {
132 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
137 PpapiBlinkPlatformImpl::PpapiBlinkPlatformImpl()
138 : sandbox_support_(new PpapiBlinkPlatformImpl::SandboxSupport()) {
141 PpapiBlinkPlatformImpl::~PpapiBlinkPlatformImpl() {
144 void PpapiBlinkPlatformImpl::Shutdown() {
145 // SandboxSupport contains a map of WebFontFamily objects, which hold
146 // WebCStrings, which become invalidated when blink is shut down. Hence, we
147 // need to clear that map now, just before blink::shutdown() is called.
148 sandbox_support_
.reset();
151 blink::WebClipboard
* PpapiBlinkPlatformImpl::clipboard() {
156 blink::WebMimeRegistry
* PpapiBlinkPlatformImpl::mimeRegistry() {
161 blink::WebFileUtilities
* PpapiBlinkPlatformImpl::fileUtilities() {
166 blink::WebSandboxSupport
* PpapiBlinkPlatformImpl::sandboxSupport() {
167 return sandbox_support_
.get();
170 bool PpapiBlinkPlatformImpl::sandboxEnabled() {
171 return true; // Assume PPAPI is always sandboxed.
174 unsigned long long PpapiBlinkPlatformImpl::visitedLinkHash(
175 const char* canonical_url
,
181 bool PpapiBlinkPlatformImpl::isLinkVisited(unsigned long long link_hash
) {
186 void PpapiBlinkPlatformImpl::createMessageChannel(
187 blink::WebMessagePortChannel
** channel1
,
188 blink::WebMessagePortChannel
** channel2
) {
194 void PpapiBlinkPlatformImpl::setCookies(
195 const blink::WebURL
& url
,
196 const blink::WebURL
& first_party_for_cookies
,
197 const blink::WebString
& value
) {
201 blink::WebString
PpapiBlinkPlatformImpl::cookies(
202 const blink::WebURL
& url
,
203 const blink::WebURL
& first_party_for_cookies
) {
205 return blink::WebString();
208 blink::WebString
PpapiBlinkPlatformImpl::defaultLocale() {
210 return blink::WebString();
213 blink::WebThemeEngine
* PpapiBlinkPlatformImpl::themeEngine() {
218 blink::WebURLLoader
* PpapiBlinkPlatformImpl::createURLLoader() {
223 void PpapiBlinkPlatformImpl::getPluginList(
225 blink::WebPluginListBuilder
* builder
) {
229 blink::WebData
PpapiBlinkPlatformImpl::loadResource(const char* name
) {
231 return blink::WebData();
234 blink::WebStorageNamespace
*
235 PpapiBlinkPlatformImpl::createLocalStorageNamespace() {
240 void PpapiBlinkPlatformImpl::dispatchStorageEvent(
241 const blink::WebString
& key
,
242 const blink::WebString
& old_value
,
243 const blink::WebString
& new_value
,
244 const blink::WebString
& origin
,
245 const blink::WebURL
& url
,
246 bool is_local_storage
) {
250 int PpapiBlinkPlatformImpl::databaseDeleteFile(
251 const blink::WebString
& vfs_file_name
,
257 } // namespace content