1 // Copyright (c) 2011 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_webkitclient_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 "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptValue.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebSandboxSupport.h"
18 #elif defined(OS_MACOSX)
19 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebSandboxSupport.h"
20 #elif defined(OS_POSIX)
21 #include "content/common/child_process_sandbox_support_linux.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebSandboxSupport.h"
25 using WebKit::WebSandboxSupport
;
26 using WebKit::WebString
;
27 using WebKit::WebUChar
;
29 class PpapiWebKitClientImpl::SandboxSupport
: public WebSandboxSupport
{
31 virtual ~SandboxSupport() {}
34 virtual bool ensureFontLoaded(HFONT
);
35 #elif defined(OS_MACOSX)
36 virtual bool loadFont(NSFont
* srcFont
, ATSFontContainerRef
* out
);
37 #elif defined(OS_POSIX)
38 virtual WebString
getFontFamilyForCharacters(
39 const WebUChar
* characters
,
41 const char* preferred_locale
);
42 virtual void getRenderStyleForStrike(
43 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
);
46 // WebKit likes to ask us for the correct font family to use for a set of
47 // unicode code points. It needs this information frequently so we cache it
48 // here. The key in this map is an array of 16-bit UTF16 values from WebKit.
49 // The value is a string containing the correct font family.
50 base::Lock unicode_font_families_mutex_
;
51 std::map
<string16
, std::string
> unicode_font_families_
;
57 bool PpapiWebKitClientImpl::SandboxSupport::ensureFontLoaded(HFONT font
) {
58 // TODO(brettw) this should do the something similar to what
59 // RendererWebKitClientImpl does and request that the browser load the font.
64 #elif defined(OS_MACOSX)
66 bool PpapiWebKitClientImpl::SandboxSupport::loadFont(NSFont
* srcFont
,
67 ATSFontContainerRef
* out
) {
68 // TODO(brettw) this should do the something similar to what
69 // RendererWebKitClientImpl does and request that the browser load the font.
74 #elif defined(OS_POSIX)
76 WebString
PpapiWebKitClientImpl::SandboxSupport::getFontFamilyForCharacters(
77 const WebUChar
* characters
,
78 size_t num_characters
,
79 const char* preferred_locale
) {
80 base::AutoLock
lock(unicode_font_families_mutex_
);
81 const string16
key(characters
, num_characters
);
82 const std::map
<string16
, std::string
>::const_iterator iter
=
83 unicode_font_families_
.find(key
);
84 if (iter
!= unicode_font_families_
.end())
85 return WebString::fromUTF8(iter
->second
);
87 const std::string family_name
=
88 child_process_sandbox_support::getFontFamilyForCharacters(
92 unicode_font_families_
.insert(make_pair(key
, family_name
));
93 return WebString::fromUTF8(family_name
);
96 void PpapiWebKitClientImpl::SandboxSupport::getRenderStyleForStrike(
97 const char* family
, int sizeAndStyle
, WebKit::WebFontRenderStyle
* out
) {
98 child_process_sandbox_support::getRenderStyleForStrike(family
, sizeAndStyle
,
104 PpapiWebKitClientImpl::PpapiWebKitClientImpl()
105 : sandbox_support_(new PpapiWebKitClientImpl::SandboxSupport()) {
108 PpapiWebKitClientImpl::~PpapiWebKitClientImpl() {
111 WebKit::WebClipboard
* PpapiWebKitClientImpl::clipboard() {
116 WebKit::WebMimeRegistry
* PpapiWebKitClientImpl::mimeRegistry() {
121 WebKit::WebFileUtilities
* PpapiWebKitClientImpl::fileUtilities() {
126 WebKit::WebSandboxSupport
* PpapiWebKitClientImpl::sandboxSupport() {
127 return sandbox_support_
.get();
130 bool PpapiWebKitClientImpl::sandboxEnabled() {
131 return true; // Assume PPAPI is always sandboxed.
134 unsigned long long PpapiWebKitClientImpl::visitedLinkHash(
135 const char* canonical_url
,
141 bool PpapiWebKitClientImpl::isLinkVisited(unsigned long long link_hash
) {
146 WebKit::WebMessagePortChannel
*
147 PpapiWebKitClientImpl::createMessagePortChannel() {
152 void PpapiWebKitClientImpl::setCookies(
153 const WebKit::WebURL
& url
,
154 const WebKit::WebURL
& first_party_for_cookies
,
155 const WebKit::WebString
& value
) {
159 WebKit::WebString
PpapiWebKitClientImpl::cookies(
160 const WebKit::WebURL
& url
,
161 const WebKit::WebURL
& first_party_for_cookies
) {
163 return WebKit::WebString();
166 void PpapiWebKitClientImpl::prefetchHostName(const WebKit::WebString
&) {
170 WebKit::WebString
PpapiWebKitClientImpl::defaultLocale() {
172 return WebKit::WebString();
175 WebKit::WebThemeEngine
* PpapiWebKitClientImpl::themeEngine() {
180 WebKit::WebURLLoader
* PpapiWebKitClientImpl::createURLLoader() {
185 WebKit::WebSocketStreamHandle
*
186 PpapiWebKitClientImpl::createSocketStreamHandle() {
191 void PpapiWebKitClientImpl::getPluginList(bool refresh
,
192 WebKit::WebPluginListBuilder
* builder
) {
196 WebKit::WebData
PpapiWebKitClientImpl::loadResource(const char* name
) {
198 return WebKit::WebData();
201 WebKit::WebStorageNamespace
*
202 PpapiWebKitClientImpl::createLocalStorageNamespace(
203 const WebKit::WebString
& path
, unsigned quota
) {
208 void PpapiWebKitClientImpl::dispatchStorageEvent(
209 const WebKit::WebString
& key
, const WebKit::WebString
& old_value
,
210 const WebKit::WebString
& new_value
, const WebKit::WebString
& origin
,
211 const WebKit::WebURL
& url
, bool is_local_storage
) {
215 WebKit::WebSharedWorkerRepository
*
216 PpapiWebKitClientImpl::sharedWorkerRepository() {
221 int PpapiWebKitClientImpl::databaseDeleteFile(
222 const WebKit::WebString
& vfs_file_name
, bool sync_dir
) {
227 void PpapiWebKitClientImpl::createIDBKeysFromSerializedValuesAndKeyPath(
228 const WebKit::WebVector
<WebKit::WebSerializedScriptValue
>& values
,
229 const WebKit::WebString
& keyPath
,
230 WebKit::WebVector
<WebKit::WebIDBKey
>& keys
) {
234 WebKit::WebSerializedScriptValue
235 PpapiWebKitClientImpl::injectIDBKeyIntoSerializedValue(
236 const WebKit::WebIDBKey
& key
,
237 const WebKit::WebSerializedScriptValue
& value
,
238 const WebKit::WebString
& keyPath
) {
240 return WebKit::WebSerializedScriptValue();