[content shell] hook up testRunner.dumpEditingCallbacks
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_webkitplatformsupport_impl.cc
blob106a69fc59127bdeafdde1c020edb3448bf694ee
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/WebKit/chromium/public/platform/WebString.h"
18 #if defined(OS_WIN)
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"
25 #endif
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"
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 : public WebSandboxSupport {
40 public:
41 virtual ~SandboxSupport() {}
43 #if defined(OS_WIN)
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,
51 size_t numCharacters,
52 const char* preferred_locale,
53 WebKit::WebFontFamily* family);
54 virtual void getRenderStyleForStrike(
55 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out);
57 private:
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_;
64 #endif
67 #if defined(OS_WIN)
69 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
70 HFONT font) {
71 LOGFONT logfont;
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(
83 NSFont* src_font,
84 CGFontRef* out,
85 uint32_t* font_id) {
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.
89 NOTIMPLEMENTED();
90 return false;
93 #elif defined(OS_ANDROID)
95 // TODO(jrg): resolve (and implement?) PPAPI SandboxSupport for Android.
97 void
98 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
99 const WebUChar* characters,
100 size_t num_characters,
101 const char* preferred_locale,
102 WebKit::WebFontFamily* family) {
103 NOTIMPLEMENTED();
106 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
107 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) {
108 NOTIMPLEMENTED();
111 #elif defined(OS_POSIX)
113 void
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;
127 return;
130 GetFontFamilyForCharacters(
131 characters,
132 num_characters,
133 preferred_locale,
134 family);
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);
143 #endif
145 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
146 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
149 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
152 WebKit::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() {
153 NOTREACHED();
154 return NULL;
157 WebKit::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
158 NOTREACHED();
159 return NULL;
162 WebKit::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() {
163 NOTREACHED();
164 return NULL;
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,
177 size_t length) {
178 NOTREACHED();
179 return 0;
182 bool PpapiWebKitPlatformSupportImpl::isLinkVisited(unsigned long long link_hash) {
183 NOTREACHED();
184 return false;
187 WebKit::WebMessagePortChannel*
188 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() {
189 NOTREACHED();
190 return NULL;
193 void PpapiWebKitPlatformSupportImpl::setCookies(
194 const WebKit::WebURL& url,
195 const WebKit::WebURL& first_party_for_cookies,
196 const WebKit::WebString& value) {
197 NOTREACHED();
200 WebKit::WebString PpapiWebKitPlatformSupportImpl::cookies(
201 const WebKit::WebURL& url,
202 const WebKit::WebURL& first_party_for_cookies) {
203 NOTREACHED();
204 return WebKit::WebString();
207 void PpapiWebKitPlatformSupportImpl::prefetchHostName(const WebKit::WebString&) {
208 NOTREACHED();
211 WebKit::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() {
212 NOTREACHED();
213 return WebKit::WebString();
216 WebKit::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() {
217 NOTREACHED();
218 return NULL;
221 WebKit::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() {
222 NOTREACHED();
223 return NULL;
226 WebKit::WebSocketStreamHandle*
227 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
228 NOTREACHED();
229 return NULL;
232 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh,
233 WebKit::WebPluginListBuilder* builder) {
234 NOTREACHED();
237 WebKit::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) {
238 NOTREACHED();
239 return WebKit::WebData();
242 WebKit::WebStorageNamespace*
243 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace(
244 const WebKit::WebString& path, unsigned quota) {
245 NOTREACHED();
246 return 0;
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) {
253 NOTREACHED();
256 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
257 const WebKit::WebString& vfs_file_name, bool sync_dir) {
258 NOTREACHED();
259 return 0;
262 } // namespace content