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/synchronization/lock.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 "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/win/WebSandboxSupport.h"
20 #elif defined(OS_MACOSX)
21 #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h"
22 #elif defined(OS_ANDROID)
23 #include "third_party/WebKit/public/platform/android/WebSandboxSupport.h"
24 #elif defined(OS_POSIX)
25 #include "content/common/child_process_sandbox_support_impl_linux.h"
26 #include "third_party/WebKit/public/platform/linux/WebFontFamily.h"
27 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h"
28 #include "third_party/icu/source/common/unicode/utf16.h"
31 using WebKit::WebSandboxSupport
;
32 using WebKit::WebString
;
33 using WebKit::WebUChar
;
34 using WebKit::WebUChar32
;
36 typedef struct CGFont
* CGFontRef
;
40 class PpapiWebKitPlatformSupportImpl::SandboxSupport
41 : public WebSandboxSupport
{
43 virtual ~SandboxSupport() {}
46 virtual bool ensureFontLoaded(HFONT
);
47 #elif defined(OS_MACOSX)
48 virtual bool loadFont(
49 NSFont
* srcFont
, CGFontRef
* out
, uint32_t* fontID
);
50 #elif defined(OS_ANDROID)
52 #elif defined(OS_POSIX)
53 virtual void getFontFamilyForCharacter(
55 const char* preferred_locale
,
56 WebKit::WebFontFamily
* family
);
57 virtual void getRenderStyleForStrike(
58 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
);
61 // WebKit likes to ask us for the correct font family to use for a set of
62 // unicode code points. It needs this information frequently so we cache it
64 base::Lock unicode_font_families_mutex_
;
65 std::map
<int32_t, WebKit::WebFontFamily
> unicode_font_families_
;
71 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
74 GetObject(font
, sizeof(LOGFONT
), &logfont
);
76 // Use the proxy sender rather than going directly to the ChildThread since
77 // the proxy browser sender will properly unlock during sync messages.
78 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send(
79 new ChildProcessHostMsg_PreCacheFont(logfont
));
82 #elif defined(OS_MACOSX)
84 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
88 // TODO(brettw) this should do the something similar to what
89 // RendererWebKitClientImpl 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)
102 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacter(
103 WebUChar32 character
,
104 const char* preferred_locale
,
105 WebKit::WebFontFamily
* family
) {
106 base::AutoLock
lock(unicode_font_families_mutex_
);
107 const std::map
<int32_t, WebKit::WebFontFamily
>::const_iterator iter
=
108 unicode_font_families_
.find(character
);
109 if (iter
!= unicode_font_families_
.end()) {
110 family
->name
= iter
->second
.name
;
111 family
->isBold
= iter
->second
.isBold
;
112 family
->isItalic
= iter
->second
.isItalic
;
116 GetFontFamilyForCharacter(character
, preferred_locale
, family
);
117 unicode_font_families_
.insert(std::make_pair(character
, *family
));
120 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
121 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
122 GetRenderStyleForStrike(family
, sizeAndStyle
, out
);
127 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
128 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
131 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
134 WebKit::WebClipboard
* PpapiWebKitPlatformSupportImpl::clipboard() {
139 WebKit::WebMimeRegistry
* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
144 WebKit::WebFileUtilities
* PpapiWebKitPlatformSupportImpl::fileUtilities() {
149 WebKit::WebSandboxSupport
* PpapiWebKitPlatformSupportImpl::sandboxSupport() {
150 return sandbox_support_
.get();
153 bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() {
154 return true; // Assume PPAPI is always sandboxed.
157 unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash(
158 const char* canonical_url
,
164 bool PpapiWebKitPlatformSupportImpl::isLinkVisited(
165 unsigned long long link_hash
) {
170 WebKit::WebMessagePortChannel
*
171 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() {
176 void PpapiWebKitPlatformSupportImpl::setCookies(
177 const WebKit::WebURL
& url
,
178 const WebKit::WebURL
& first_party_for_cookies
,
179 const WebKit::WebString
& value
) {
183 WebKit::WebString
PpapiWebKitPlatformSupportImpl::cookies(
184 const WebKit::WebURL
& url
,
185 const WebKit::WebURL
& first_party_for_cookies
) {
187 return WebKit::WebString();
190 WebKit::WebString
PpapiWebKitPlatformSupportImpl::defaultLocale() {
192 return WebKit::WebString();
195 WebKit::WebThemeEngine
* PpapiWebKitPlatformSupportImpl::themeEngine() {
200 WebKit::WebURLLoader
* PpapiWebKitPlatformSupportImpl::createURLLoader() {
205 WebKit::WebSocketStreamHandle
*
206 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
211 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh
,
212 WebKit::WebPluginListBuilder
* builder
) {
216 WebKit::WebData
PpapiWebKitPlatformSupportImpl::loadResource(const char* name
) {
218 return WebKit::WebData();
221 WebKit::WebStorageNamespace
*
222 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace() {
227 void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent(
228 const WebKit::WebString
& key
, const WebKit::WebString
& old_value
,
229 const WebKit::WebString
& new_value
, const WebKit::WebString
& origin
,
230 const WebKit::WebURL
& url
, bool is_local_storage
) {
234 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
235 const WebKit::WebString
& vfs_file_name
, bool sync_dir
) {
240 } // namespace content