Use Persistent::Reset.
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_webkitplatformsupport_impl.cc
blobd885814e7268c40e8b65757658f103821d37f017
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"
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 "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"
18 #if defined(OS_WIN)
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"
25 #endif
26 #include "third_party/WebKit/Source/Platform/chromium/public/linux/WebFontFamily.h"
27 #include "third_party/WebKit/Source/Platform/chromium/public/linux/WebSandboxSupport.h"
29 #endif
31 using WebKit::WebSandboxSupport;
32 using WebKit::WebString;
33 using WebKit::WebUChar;
35 typedef struct CGFont* CGFontRef;
37 namespace content {
39 class PpapiWebKitPlatformSupportImpl::SandboxSupport
40 : public WebSandboxSupport {
41 public:
42 virtual ~SandboxSupport() {}
44 #if defined(OS_WIN)
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,
52 size_t numCharacters,
53 const char* preferred_locale,
54 WebKit::WebFontFamily* family);
55 virtual void getRenderStyleForStrike(
56 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out);
58 private:
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_;
65 #endif
68 #if defined(OS_WIN)
70 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
71 HFONT font) {
72 LOGFONT logfont;
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(
84 NSFont* src_font,
85 CGFontRef* out,
86 uint32_t* font_id) {
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.
90 NOTIMPLEMENTED();
91 return false;
94 #elif defined(OS_ANDROID)
96 // TODO(jrg): resolve (and implement?) PPAPI SandboxSupport for Android.
98 void
99 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
100 const WebUChar* characters,
101 size_t num_characters,
102 const char* preferred_locale,
103 WebKit::WebFontFamily* family) {
104 NOTIMPLEMENTED();
107 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
108 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) {
109 NOTIMPLEMENTED();
112 #elif defined(OS_POSIX)
114 void
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;
128 return;
131 GetFontFamilyForCharacters(
132 characters,
133 num_characters,
134 preferred_locale,
135 family);
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);
144 #endif
146 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
147 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
150 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
153 WebKit::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() {
154 NOTREACHED();
155 return NULL;
158 WebKit::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
159 NOTREACHED();
160 return NULL;
163 WebKit::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() {
164 NOTREACHED();
165 return NULL;
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,
178 size_t length) {
179 NOTREACHED();
180 return 0;
183 bool PpapiWebKitPlatformSupportImpl::isLinkVisited(
184 unsigned long long link_hash) {
185 NOTREACHED();
186 return false;
189 WebKit::WebMessagePortChannel*
190 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() {
191 NOTREACHED();
192 return NULL;
195 void PpapiWebKitPlatformSupportImpl::setCookies(
196 const WebKit::WebURL& url,
197 const WebKit::WebURL& first_party_for_cookies,
198 const WebKit::WebString& value) {
199 NOTREACHED();
202 WebKit::WebString PpapiWebKitPlatformSupportImpl::cookies(
203 const WebKit::WebURL& url,
204 const WebKit::WebURL& first_party_for_cookies) {
205 NOTREACHED();
206 return WebKit::WebString();
209 void PpapiWebKitPlatformSupportImpl::prefetchHostName(
210 const WebKit::WebString&) {
211 NOTREACHED();
214 WebKit::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() {
215 NOTREACHED();
216 return WebKit::WebString();
219 WebKit::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() {
220 NOTREACHED();
221 return NULL;
224 WebKit::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() {
225 NOTREACHED();
226 return NULL;
229 WebKit::WebSocketStreamHandle*
230 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
231 NOTREACHED();
232 return NULL;
235 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh,
236 WebKit::WebPluginListBuilder* builder) {
237 NOTREACHED();
240 WebKit::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) {
241 NOTREACHED();
242 return WebKit::WebData();
245 WebKit::WebStorageNamespace*
246 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace(
247 const WebKit::WebString& path, unsigned quota) {
248 NOTREACHED();
249 return 0;
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) {
256 NOTREACHED();
259 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
260 const WebKit::WebString& vfs_file_name, bool sync_dir) {
261 NOTREACHED();
262 return 0;
265 } // namespace content