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"
19 #if defined(OS_MACOSX)
20 #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h"
21 #elif defined(OS_POSIX) && !defined(OS_ANDROID)
22 #include "content/common/child_process_sandbox_support_impl_linux.h"
23 #include "third_party/WebKit/public/platform/linux/WebFallbackFont.h"
24 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h"
25 #include "third_party/icu/source/common/unicode/utf16.h"
28 using blink::WebSandboxSupport
;
29 using blink::WebString
;
30 using blink::WebUChar
;
31 using blink::WebUChar32
;
33 typedef struct CGFont
* CGFontRef
;
37 #if !defined(OS_ANDROID) && !defined(OS_WIN)
39 class PpapiBlinkPlatformImpl::SandboxSupport
: public WebSandboxSupport
{
41 virtual ~SandboxSupport() {}
43 #if defined(OS_MACOSX)
44 virtual bool loadFont(NSFont
* srcFont
, CGFontRef
* out
, uint32_t* fontID
);
45 #elif defined(OS_POSIX)
47 virtual void getFallbackFontForCharacter(
49 const char* preferred_locale
,
50 blink::WebFallbackFont
* fallbackFont
);
51 virtual void getRenderStyleForStrike(const char* family
,
53 blink::WebFontRenderStyle
* out
);
56 // WebKit likes to ask us for the correct font family to use for a set of
57 // unicode code points. It needs this information frequently so we cache it
59 std::map
<int32_t, blink::WebFallbackFont
> unicode_font_families_
;
60 // For debugging crbug.com/312965
61 base::PlatformThreadId creation_thread_
;
65 #if defined(OS_MACOSX)
67 bool PpapiBlinkPlatformImpl::SandboxSupport::loadFont(NSFont
* src_font
,
70 // TODO(brettw) this should do the something similar to what
71 // RendererBlinkPlatformImpl does and request that the browser load the font.
72 // Note: need to unlock the proxy lock like ensureFontLoaded does.
77 #elif defined(OS_POSIX)
79 PpapiBlinkPlatformImpl::SandboxSupport::SandboxSupport()
80 : creation_thread_(base::PlatformThread::CurrentId()) {
83 void PpapiBlinkPlatformImpl::SandboxSupport::getFallbackFontForCharacter(
85 const char* preferred_locale
,
86 blink::WebFallbackFont
* fallbackFont
) {
87 ppapi::ProxyLock::AssertAcquired();
88 // For debugging crbug.com/312965
89 CHECK_EQ(creation_thread_
, base::PlatformThread::CurrentId());
90 const std::map
<int32_t, blink::WebFallbackFont
>::const_iterator iter
=
91 unicode_font_families_
.find(character
);
92 if (iter
!= unicode_font_families_
.end()) {
93 fallbackFont
->name
= iter
->second
.name
;
94 fallbackFont
->filename
= iter
->second
.filename
;
95 fallbackFont
->fontconfigInterfaceId
= iter
->second
.fontconfigInterfaceId
;
96 fallbackFont
->ttcIndex
= iter
->second
.ttcIndex
;
97 fallbackFont
->isBold
= iter
->second
.isBold
;
98 fallbackFont
->isItalic
= iter
->second
.isItalic
;
102 GetFallbackFontForCharacter(character
, preferred_locale
, fallbackFont
);
103 unicode_font_families_
.insert(std::make_pair(character
, *fallbackFont
));
106 void PpapiBlinkPlatformImpl::SandboxSupport::getRenderStyleForStrike(
109 blink::WebFontRenderStyle
* out
) {
110 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
115 #endif // !defined(OS_ANDROID) && !defined(OS_WIN)
117 PpapiBlinkPlatformImpl::PpapiBlinkPlatformImpl() {
118 #if !defined(OS_ANDROID) && !defined(OS_WIN)
119 sandbox_support_
.reset(new PpapiBlinkPlatformImpl::SandboxSupport
);
123 PpapiBlinkPlatformImpl::~PpapiBlinkPlatformImpl() {
126 void PpapiBlinkPlatformImpl::Shutdown() {
127 #if !defined(OS_ANDROID) && !defined(OS_WIN)
128 // SandboxSupport contains a map of WebFontFamily objects, which hold
129 // WebCStrings, which become invalidated when blink is shut down. Hence, we
130 // need to clear that map now, just before blink::shutdown() is called.
131 sandbox_support_
.reset();
135 blink::WebClipboard
* PpapiBlinkPlatformImpl::clipboard() {
140 blink::WebMimeRegistry
* PpapiBlinkPlatformImpl::mimeRegistry() {
145 blink::WebFileUtilities
* PpapiBlinkPlatformImpl::fileUtilities() {
150 blink::WebSandboxSupport
* PpapiBlinkPlatformImpl::sandboxSupport() {
151 #if !defined(OS_ANDROID) && !defined(OS_WIN)
152 return sandbox_support_
.get();
158 bool PpapiBlinkPlatformImpl::sandboxEnabled() {
159 return true; // Assume PPAPI is always sandboxed.
162 unsigned long long PpapiBlinkPlatformImpl::visitedLinkHash(
163 const char* canonical_url
,
169 bool PpapiBlinkPlatformImpl::isLinkVisited(unsigned long long link_hash
) {
174 void PpapiBlinkPlatformImpl::createMessageChannel(
175 blink::WebMessagePortChannel
** channel1
,
176 blink::WebMessagePortChannel
** channel2
) {
182 void PpapiBlinkPlatformImpl::setCookies(
183 const blink::WebURL
& url
,
184 const blink::WebURL
& first_party_for_cookies
,
185 const blink::WebString
& value
) {
189 blink::WebString
PpapiBlinkPlatformImpl::cookies(
190 const blink::WebURL
& url
,
191 const blink::WebURL
& first_party_for_cookies
) {
193 return blink::WebString();
196 blink::WebString
PpapiBlinkPlatformImpl::defaultLocale() {
198 return blink::WebString();
201 blink::WebThemeEngine
* PpapiBlinkPlatformImpl::themeEngine() {
206 blink::WebURLLoader
* PpapiBlinkPlatformImpl::createURLLoader() {
211 void PpapiBlinkPlatformImpl::getPluginList(
213 blink::WebPluginListBuilder
* builder
) {
217 blink::WebData
PpapiBlinkPlatformImpl::loadResource(const char* name
) {
219 return blink::WebData();
222 blink::WebStorageNamespace
*
223 PpapiBlinkPlatformImpl::createLocalStorageNamespace() {
228 void PpapiBlinkPlatformImpl::dispatchStorageEvent(
229 const blink::WebString
& key
,
230 const blink::WebString
& old_value
,
231 const blink::WebString
& new_value
,
232 const blink::WebString
& origin
,
233 const blink::WebURL
& url
,
234 bool is_local_storage
) {
238 int PpapiBlinkPlatformImpl::databaseDeleteFile(
239 const blink::WebString
& vfs_file_name
,
245 } // namespace content