IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_webkitplatformsupport_impl.cc
blob948b02581ec01fcc10f11089111bd037bfdf3409
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/logging.h"
10 #include "base/strings/string16.h"
11 #include "base/threading/platform_thread.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 "ppapi/shared_impl/proxy_lock.h"
17 #include "third_party/WebKit/public/platform/WebString.h"
19 #if defined(OS_WIN)
20 #include "third_party/WebKit/public/platform/win/WebSandboxSupport.h"
21 #elif defined(OS_MACOSX)
22 #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h"
23 #elif defined(OS_ANDROID)
24 #include "third_party/WebKit/public/platform/android/WebSandboxSupport.h"
25 #elif defined(OS_POSIX)
26 #include "content/common/child_process_sandbox_support_impl_linux.h"
27 #include "third_party/WebKit/public/platform/linux/WebFontFamily.h"
28 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h"
29 #include "third_party/icu/source/common/unicode/utf16.h"
30 #endif
32 using blink::WebSandboxSupport;
33 using blink::WebString;
34 using blink::WebUChar;
35 using blink::WebUChar32;
37 typedef struct CGFont* CGFontRef;
39 namespace content {
41 class PpapiWebKitPlatformSupportImpl::SandboxSupport
42 : public WebSandboxSupport {
43 public:
44 virtual ~SandboxSupport() {}
46 #if defined(OS_WIN)
47 virtual bool ensureFontLoaded(HFONT);
48 #elif defined(OS_MACOSX)
49 virtual bool loadFont(
50 NSFont* srcFont, CGFontRef* out, uint32_t* fontID);
51 #elif defined(OS_ANDROID)
52 // Empty class.
53 #elif defined(OS_POSIX)
54 SandboxSupport();
55 virtual void getFontFamilyForCharacter(
56 WebUChar32 character,
57 const char* preferred_locale,
58 blink::WebFontFamily* family);
59 virtual void getRenderStyleForStrike(
60 const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out);
62 private:
63 // WebKit likes to ask us for the correct font family to use for a set of
64 // unicode code points. It needs this information frequently so we cache it
65 // here.
66 std::map<int32_t, blink::WebFontFamily> unicode_font_families_;
67 // For debugging crbug.com/312965
68 base::PlatformThreadId creation_thread_;
69 #endif
72 #if defined(OS_WIN)
74 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
75 HFONT font) {
76 LOGFONT logfont;
77 GetObject(font, sizeof(LOGFONT), &logfont);
79 // Use the proxy sender rather than going directly to the ChildThread since
80 // the proxy browser sender will properly unlock during sync messages.
81 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send(
82 new ChildProcessHostMsg_PreCacheFont(logfont));
85 #elif defined(OS_MACOSX)
87 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
88 NSFont* src_font,
89 CGFontRef* out,
90 uint32_t* font_id) {
91 // TODO(brettw) this should do the something similar to what
92 // RendererWebKitClientImpl does and request that the browser load the font.
93 // Note: need to unlock the proxy lock like ensureFontLoaded does.
94 NOTIMPLEMENTED();
95 return false;
98 #elif defined(OS_ANDROID)
100 // Empty class.
102 #elif defined(OS_POSIX)
104 PpapiWebKitPlatformSupportImpl::SandboxSupport::SandboxSupport()
105 : creation_thread_(base::PlatformThread::CurrentId()) {
108 void
109 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacter(
110 WebUChar32 character,
111 const char* preferred_locale,
112 blink::WebFontFamily* family) {
113 ppapi::ProxyLock::AssertAcquired();
114 // For debugging crbug.com/312965
115 CHECK_EQ(creation_thread_, base::PlatformThread::CurrentId());
116 const std::map<int32_t, blink::WebFontFamily>::const_iterator iter =
117 unicode_font_families_.find(character);
118 if (iter != unicode_font_families_.end()) {
119 family->name = iter->second.name;
120 family->isBold = iter->second.isBold;
121 family->isItalic = iter->second.isItalic;
122 return;
125 GetFontFamilyForCharacter(character, preferred_locale, family);
126 unicode_font_families_.insert(std::make_pair(character, *family));
129 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
130 const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out) {
131 GetRenderStyleForStrike(family, sizeAndStyle, out);
134 #endif
136 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
137 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
140 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
143 void PpapiWebKitPlatformSupportImpl::Shutdown() {
144 // SandboxSupport contains a map of WebFontFamily objects, which hold
145 // WebCStrings, which become invalidated when blink is shut down. Hence, we
146 // need to clear that map now, just before blink::shutdown() is called.
147 sandbox_support_.reset();
150 blink::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() {
151 NOTREACHED();
152 return NULL;
155 blink::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
156 NOTREACHED();
157 return NULL;
160 blink::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() {
161 NOTREACHED();
162 return NULL;
165 blink::WebSandboxSupport* PpapiWebKitPlatformSupportImpl::sandboxSupport() {
166 return sandbox_support_.get();
169 bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() {
170 return true; // Assume PPAPI is always sandboxed.
173 unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash(
174 const char* canonical_url,
175 size_t length) {
176 NOTREACHED();
177 return 0;
180 bool PpapiWebKitPlatformSupportImpl::isLinkVisited(
181 unsigned long long link_hash) {
182 NOTREACHED();
183 return false;
186 blink::WebMessagePortChannel*
187 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() {
188 NOTREACHED();
189 return NULL;
192 void PpapiWebKitPlatformSupportImpl::setCookies(
193 const blink::WebURL& url,
194 const blink::WebURL& first_party_for_cookies,
195 const blink::WebString& value) {
196 NOTREACHED();
199 blink::WebString PpapiWebKitPlatformSupportImpl::cookies(
200 const blink::WebURL& url,
201 const blink::WebURL& first_party_for_cookies) {
202 NOTREACHED();
203 return blink::WebString();
206 blink::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() {
207 NOTREACHED();
208 return blink::WebString();
211 blink::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() {
212 NOTREACHED();
213 return NULL;
216 blink::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() {
217 NOTREACHED();
218 return NULL;
221 blink::WebSocketStreamHandle*
222 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
223 NOTREACHED();
224 return NULL;
227 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh,
228 blink::WebPluginListBuilder* builder) {
229 NOTREACHED();
232 blink::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) {
233 NOTREACHED();
234 return blink::WebData();
237 blink::WebStorageNamespace*
238 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace() {
239 NOTREACHED();
240 return 0;
243 void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent(
244 const blink::WebString& key, const blink::WebString& old_value,
245 const blink::WebString& new_value, const blink::WebString& origin,
246 const blink::WebURL& url, bool is_local_storage) {
247 NOTREACHED();
250 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
251 const blink::WebString& vfs_file_name, bool sync_dir) {
252 NOTREACHED();
253 return 0;
256 } // namespace content