Fix Pepper plugin sandbox interface for out-of-process plugin.
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_webkitclient_impl.cc
blob366b49f5158e96e69c4cfb49a98cbc3f94492ffa
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"
7 #include <map>
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"
16 #if defined(OS_WIN)
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"
23 #endif
25 using WebKit::WebSandboxSupport;
26 using WebKit::WebString;
27 using WebKit::WebUChar;
29 class PpapiWebKitClientImpl::SandboxSupport : public WebSandboxSupport {
30 public:
31 virtual ~SandboxSupport() {}
33 #if defined(OS_WIN)
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,
40 size_t numCharacters,
41 const char* preferred_locale);
42 virtual void getRenderStyleForStrike(
43 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out);
45 private:
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_;
52 #endif
55 #if defined(OS_WIN)
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.
60 NOTIMPLEMENTED();
61 return false;
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.
70 NOTIMPLEMENTED();
71 return false;
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(
89 characters,
90 num_characters,
91 preferred_locale);
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,
99 out);
102 #endif
104 PpapiWebKitClientImpl::PpapiWebKitClientImpl()
105 : sandbox_support_(new PpapiWebKitClientImpl::SandboxSupport()) {
108 PpapiWebKitClientImpl::~PpapiWebKitClientImpl() {
111 WebKit::WebClipboard* PpapiWebKitClientImpl::clipboard() {
112 NOTREACHED();
113 return NULL;
116 WebKit::WebMimeRegistry* PpapiWebKitClientImpl::mimeRegistry() {
117 NOTREACHED();
118 return NULL;
121 WebKit::WebFileUtilities* PpapiWebKitClientImpl::fileUtilities() {
122 NOTREACHED();
123 return NULL;
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,
136 size_t length) {
137 NOTREACHED();
138 return 0;
141 bool PpapiWebKitClientImpl::isLinkVisited(unsigned long long link_hash) {
142 NOTREACHED();
143 return false;
146 WebKit::WebMessagePortChannel*
147 PpapiWebKitClientImpl::createMessagePortChannel() {
148 NOTREACHED();
149 return NULL;
152 void PpapiWebKitClientImpl::setCookies(
153 const WebKit::WebURL& url,
154 const WebKit::WebURL& first_party_for_cookies,
155 const WebKit::WebString& value) {
156 NOTREACHED();
159 WebKit::WebString PpapiWebKitClientImpl::cookies(
160 const WebKit::WebURL& url,
161 const WebKit::WebURL& first_party_for_cookies) {
162 NOTREACHED();
163 return WebKit::WebString();
166 void PpapiWebKitClientImpl::prefetchHostName(const WebKit::WebString&) {
167 NOTREACHED();
170 WebKit::WebString PpapiWebKitClientImpl::defaultLocale() {
171 NOTREACHED();
172 return WebKit::WebString();
175 WebKit::WebThemeEngine* PpapiWebKitClientImpl::themeEngine() {
176 NOTREACHED();
177 return NULL;
180 WebKit::WebURLLoader* PpapiWebKitClientImpl::createURLLoader() {
181 NOTREACHED();
182 return NULL;
185 WebKit::WebSocketStreamHandle*
186 PpapiWebKitClientImpl::createSocketStreamHandle() {
187 NOTREACHED();
188 return NULL;
191 void PpapiWebKitClientImpl::getPluginList(bool refresh,
192 WebKit::WebPluginListBuilder* builder) {
193 NOTREACHED();
196 WebKit::WebData PpapiWebKitClientImpl::loadResource(const char* name) {
197 NOTREACHED();
198 return WebKit::WebData();
201 WebKit::WebStorageNamespace*
202 PpapiWebKitClientImpl::createLocalStorageNamespace(
203 const WebKit::WebString& path, unsigned quota) {
204 NOTREACHED();
205 return 0;
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) {
212 NOTREACHED();
215 WebKit::WebSharedWorkerRepository*
216 PpapiWebKitClientImpl::sharedWorkerRepository() {
217 NOTREACHED();
218 return NULL;
221 int PpapiWebKitClientImpl::databaseDeleteFile(
222 const WebKit::WebString& vfs_file_name, bool sync_dir) {
223 NOTREACHED();
224 return 0;
227 void PpapiWebKitClientImpl::createIDBKeysFromSerializedValuesAndKeyPath(
228 const WebKit::WebVector<WebKit::WebSerializedScriptValue>& values,
229 const WebKit::WebString& keyPath,
230 WebKit::WebVector<WebKit::WebIDBKey>& keys) {
231 NOTREACHED();
234 WebKit::WebSerializedScriptValue
235 PpapiWebKitClientImpl::injectIDBKeyIntoSerializedValue(
236 const WebKit::WebIDBKey& key,
237 const WebKit::WebSerializedScriptValue& value,
238 const WebKit::WebString& keyPath) {
239 NOTREACHED();
240 return WebKit::WebSerializedScriptValue();