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/WebKit/chromium/public/platform/WebString.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/win/WebSandboxSupport.h"
20 #elif defined(OS_MACOSX)
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/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/WebKit/chromium/public/platform/linux/WebFontFamily.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebSandboxSupport.h"
31 using WebKit::WebSandboxSupport
;
32 using WebKit::WebString
;
33 using WebKit::WebUChar
;
35 typedef struct CGFont
* CGFontRef
;
39 class PpapiWebKitPlatformSupportImpl::SandboxSupport
: public WebSandboxSupport
{
41 virtual ~SandboxSupport() {}
44 virtual bool ensureFontLoaded(HFONT
);
45 #elif defined(OS_MACOSX)
46 virtual bool loadFont(
47 NSFont
* srcFont
, CGFontRef
* out
, uint32_t* fontID
);
48 #elif defined(OS_POSIX)
49 virtual void getFontFamilyForCharacters(
50 const WebUChar
* characters
,
52 const char* preferred_locale
,
53 WebKit::WebFontFamily
* family
);
54 virtual void getRenderStyleForStrike(
55 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
);
58 // WebKit likes to ask us for the correct font family to use for a set of
59 // unicode code points. It needs this information frequently so we cache it
60 // here. The key in this map is an array of 16-bit UTF16 values from WebKit.
61 // The value is a string containing the correct font family.
62 base::Lock unicode_font_families_mutex_
;
63 std::map
<string16
, WebKit::WebFontFamily
> unicode_font_families_
;
69 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
72 GetObject(font
, sizeof(LOGFONT
), &logfont
);
74 // Use the proxy sender rather than going directly to the ChildThread since
75 // the proxy browser sender will properly unlock during sync messages.
76 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send(
77 new ChildProcessHostMsg_PreCacheFont(logfont
));
80 #elif defined(OS_MACOSX)
82 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
86 // TODO(brettw) this should do the something similar to what
87 // RendererWebKitClientImpl does and request that the browser load the font.
88 // Note: need to unlock the proxy lock like ensureFontLoaded does.
93 #elif defined(OS_ANDROID)
95 // TODO(jrg): resolve (and implement?) PPAPI SandboxSupport for Android.
98 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
99 const WebUChar
* characters
,
100 size_t num_characters
,
101 const char* preferred_locale
,
102 WebKit::WebFontFamily
* family
) {
106 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
107 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
111 #elif defined(OS_POSIX)
114 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
115 const WebUChar
* characters
,
116 size_t num_characters
,
117 const char* preferred_locale
,
118 WebKit::WebFontFamily
* family
) {
119 base::AutoLock
lock(unicode_font_families_mutex_
);
120 const string16
key(characters
, num_characters
);
121 const std::map
<string16
, WebKit::WebFontFamily
>::const_iterator iter
=
122 unicode_font_families_
.find(key
);
123 if (iter
!= unicode_font_families_
.end()) {
124 family
->name
= iter
->second
.name
;
125 family
->isBold
= iter
->second
.isBold
;
126 family
->isItalic
= iter
->second
.isItalic
;
130 GetFontFamilyForCharacters(
135 unicode_font_families_
.insert(make_pair(key
, *family
));
138 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
139 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
140 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
145 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
146 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
149 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
152 WebKit::WebClipboard
* PpapiWebKitPlatformSupportImpl::clipboard() {
157 WebKit::WebMimeRegistry
* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
162 WebKit::WebFileUtilities
* PpapiWebKitPlatformSupportImpl::fileUtilities() {
167 WebKit::WebSandboxSupport
* PpapiWebKitPlatformSupportImpl::sandboxSupport() {
168 return sandbox_support_
.get();
171 bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() {
172 return true; // Assume PPAPI is always sandboxed.
175 unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash(
176 const char* canonical_url
,
182 bool PpapiWebKitPlatformSupportImpl::isLinkVisited(unsigned long long link_hash
) {
187 WebKit::WebMessagePortChannel
*
188 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() {
193 void PpapiWebKitPlatformSupportImpl::setCookies(
194 const WebKit::WebURL
& url
,
195 const WebKit::WebURL
& first_party_for_cookies
,
196 const WebKit::WebString
& value
) {
200 WebKit::WebString
PpapiWebKitPlatformSupportImpl::cookies(
201 const WebKit::WebURL
& url
,
202 const WebKit::WebURL
& first_party_for_cookies
) {
204 return WebKit::WebString();
207 void PpapiWebKitPlatformSupportImpl::prefetchHostName(const WebKit::WebString
&) {
211 WebKit::WebString
PpapiWebKitPlatformSupportImpl::defaultLocale() {
213 return WebKit::WebString();
216 WebKit::WebThemeEngine
* PpapiWebKitPlatformSupportImpl::themeEngine() {
221 WebKit::WebURLLoader
* PpapiWebKitPlatformSupportImpl::createURLLoader() {
226 WebKit::WebSocketStreamHandle
*
227 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
232 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh
,
233 WebKit::WebPluginListBuilder
* builder
) {
237 WebKit::WebData
PpapiWebKitPlatformSupportImpl::loadResource(const char* name
) {
239 return WebKit::WebData();
242 WebKit::WebStorageNamespace
*
243 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace(
244 const WebKit::WebString
& path
, unsigned quota
) {
249 void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent(
250 const WebKit::WebString
& key
, const WebKit::WebString
& old_value
,
251 const WebKit::WebString
& new_value
, const WebKit::WebString
& origin
,
252 const WebKit::WebURL
& url
, bool is_local_storage
) {
256 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
257 const WebKit::WebString
& vfs_file_name
, bool sync_dir
) {
262 } // namespace content