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/synchronization/lock.h"
10 #include "base/logging.h"
11 #include "base/string16.h"
12 #include "build/build_config.h"
13 #include "content/common/child_process_messages.h"
14 #include "content/common/child_thread.h"
15 #include "ppapi/proxy/plugin_globals.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/win/WebSandboxSupport.h"
20 #elif defined(OS_MACOSX)
21 #include "third_party/WebKit/Source/Platform/chromium/public/mac/WebSandboxSupport.h"
22 #elif defined(OS_POSIX)
23 #if !defined(OS_ANDROID)
24 #include "content/common/child_process_sandbox_support_impl_linux.h"
26 #include "third_party/WebKit/Source/Platform/chromium/public/linux/WebFontFamily.h"
27 #include "third_party/WebKit/Source/Platform/chromium/public/linux/WebSandboxSupport.h"
31 using WebKit::WebSandboxSupport
;
32 using WebKit::WebString
;
33 using WebKit::WebUChar
;
35 typedef struct CGFont
* CGFontRef
;
39 class PpapiWebKitPlatformSupportImpl::SandboxSupport
40 : public WebSandboxSupport
{
42 virtual ~SandboxSupport() {}
45 virtual bool ensureFontLoaded(HFONT
);
46 #elif defined(OS_MACOSX)
47 virtual bool loadFont(
48 NSFont
* srcFont
, CGFontRef
* out
, uint32_t* fontID
);
49 #elif defined(OS_POSIX)
50 virtual void getFontFamilyForCharacters(
51 const WebUChar
* characters
,
53 const char* preferred_locale
,
54 WebKit::WebFontFamily
* family
);
55 virtual void getRenderStyleForStrike(
56 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
);
59 // WebKit likes to ask us for the correct font family to use for a set of
60 // unicode code points. It needs this information frequently so we cache it
61 // here. The key in this map is an array of 16-bit UTF16 values from WebKit.
62 // The value is a string containing the correct font family.
63 base::Lock unicode_font_families_mutex_
;
64 std::map
<string16
, WebKit::WebFontFamily
> unicode_font_families_
;
70 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
73 GetObject(font
, sizeof(LOGFONT
), &logfont
);
75 // Use the proxy sender rather than going directly to the ChildThread since
76 // the proxy browser sender will properly unlock during sync messages.
77 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send(
78 new ChildProcessHostMsg_PreCacheFont(logfont
));
81 #elif defined(OS_MACOSX)
83 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
87 // TODO(brettw) this should do the something similar to what
88 // RendererWebKitClientImpl does and request that the browser load the font.
89 // Note: need to unlock the proxy lock like ensureFontLoaded does.
94 #elif defined(OS_ANDROID)
96 // TODO(jrg): resolve (and implement?) PPAPI SandboxSupport for Android.
99 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
100 const WebUChar
* characters
,
101 size_t num_characters
,
102 const char* preferred_locale
,
103 WebKit::WebFontFamily
* family
) {
107 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
108 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
112 #elif defined(OS_POSIX)
115 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
116 const WebUChar
* characters
,
117 size_t num_characters
,
118 const char* preferred_locale
,
119 WebKit::WebFontFamily
* family
) {
120 base::AutoLock
lock(unicode_font_families_mutex_
);
121 const string16
key(characters
, num_characters
);
122 const std::map
<string16
, WebKit::WebFontFamily
>::const_iterator iter
=
123 unicode_font_families_
.find(key
);
124 if (iter
!= unicode_font_families_
.end()) {
125 family
->name
= iter
->second
.name
;
126 family
->isBold
= iter
->second
.isBold
;
127 family
->isItalic
= iter
->second
.isItalic
;
131 GetFontFamilyForCharacters(
136 unicode_font_families_
.insert(make_pair(key
, *family
));
139 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
140 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
141 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
146 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
147 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
150 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
153 WebKit::WebClipboard
* PpapiWebKitPlatformSupportImpl::clipboard() {
158 WebKit::WebMimeRegistry
* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
163 WebKit::WebFileUtilities
* PpapiWebKitPlatformSupportImpl::fileUtilities() {
168 WebKit::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 WebKit::WebMessagePortChannel
*
190 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() {
195 void PpapiWebKitPlatformSupportImpl::setCookies(
196 const WebKit::WebURL
& url
,
197 const WebKit::WebURL
& first_party_for_cookies
,
198 const WebKit::WebString
& value
) {
202 WebKit::WebString
PpapiWebKitPlatformSupportImpl::cookies(
203 const WebKit::WebURL
& url
,
204 const WebKit::WebURL
& first_party_for_cookies
) {
206 return WebKit::WebString();
209 void PpapiWebKitPlatformSupportImpl::prefetchHostName(
210 const WebKit::WebString
&) {
214 WebKit::WebString
PpapiWebKitPlatformSupportImpl::defaultLocale() {
216 return WebKit::WebString();
219 WebKit::WebThemeEngine
* PpapiWebKitPlatformSupportImpl::themeEngine() {
224 WebKit::WebURLLoader
* PpapiWebKitPlatformSupportImpl::createURLLoader() {
229 WebKit::WebSocketStreamHandle
*
230 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
235 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh
,
236 WebKit::WebPluginListBuilder
* builder
) {
240 WebKit::WebData
PpapiWebKitPlatformSupportImpl::loadResource(const char* name
) {
242 return WebKit::WebData();
245 WebKit::WebStorageNamespace
*
246 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace(
247 const WebKit::WebString
& path
, unsigned quota
) {
252 void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent(
253 const WebKit::WebString
& key
, const WebKit::WebString
& old_value
,
254 const WebKit::WebString
& new_value
, const WebKit::WebString
& origin
,
255 const WebKit::WebURL
& url
, bool is_local_storage
) {
259 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
260 const WebKit::WebString
& vfs_file_name
, bool sync_dir
) {
265 } // namespace content