[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_webkitplatformsupport_impl.cc
blobc4a1153926957e88bd342db0d132308688f507ef
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/WebFallbackFont.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 getFallbackFontForCharacter(
56 WebUChar32 character,
57 const char* preferred_locale,
58 blink::WebFallbackFont* fallbackFont);
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::WebFallbackFont> 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::getFallbackFontForCharacter(
110 WebUChar32 character,
111 const char* preferred_locale,
112 blink::WebFallbackFont* fallbackFont) {
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::WebFallbackFont>::const_iterator iter =
117 unicode_font_families_.find(character);
118 if (iter != unicode_font_families_.end()) {
119 fallbackFont->name = iter->second.name;
120 fallbackFont->filename = iter->second.filename;
121 fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId;
122 fallbackFont->ttcIndex = iter->second.ttcIndex;
123 fallbackFont->isBold = iter->second.isBold;
124 fallbackFont->isItalic = iter->second.isItalic;
125 return;
128 GetFallbackFontForCharacter(character, preferred_locale, fallbackFont);
129 unicode_font_families_.insert(std::make_pair(character, *fallbackFont));
132 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
133 const char* family, int sizeAndStyle, blink::WebFontRenderStyle* out) {
134 GetRenderStyleForStrike(family, sizeAndStyle, out);
137 #endif
139 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
140 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
143 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
146 void PpapiWebKitPlatformSupportImpl::Shutdown() {
147 // SandboxSupport contains a map of WebFontFamily objects, which hold
148 // WebCStrings, which become invalidated when blink is shut down. Hence, we
149 // need to clear that map now, just before blink::shutdown() is called.
150 sandbox_support_.reset();
153 blink::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() {
154 NOTREACHED();
155 return NULL;
158 blink::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
159 NOTREACHED();
160 return NULL;
163 blink::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() {
164 NOTREACHED();
165 return NULL;
168 blink::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 void PpapiWebKitPlatformSupportImpl::createMessageChannel(
190 blink::WebMessagePortChannel** channel1,
191 blink::WebMessagePortChannel** channel2) {
192 NOTREACHED();
193 *channel1 = NULL;
194 *channel2 = NULL;
197 void PpapiWebKitPlatformSupportImpl::setCookies(
198 const blink::WebURL& url,
199 const blink::WebURL& first_party_for_cookies,
200 const blink::WebString& value) {
201 NOTREACHED();
204 blink::WebString PpapiWebKitPlatformSupportImpl::cookies(
205 const blink::WebURL& url,
206 const blink::WebURL& first_party_for_cookies) {
207 NOTREACHED();
208 return blink::WebString();
211 blink::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() {
212 NOTREACHED();
213 return blink::WebString();
216 blink::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() {
217 NOTREACHED();
218 return NULL;
221 blink::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() {
222 NOTREACHED();
223 return NULL;
226 blink::WebSocketStreamHandle*
227 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
228 NOTREACHED();
229 return NULL;
232 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh,
233 blink::WebPluginListBuilder* builder) {
234 NOTREACHED();
237 blink::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) {
238 NOTREACHED();
239 return blink::WebData();
242 blink::WebStorageNamespace*
243 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace() {
244 NOTREACHED();
245 return 0;
248 void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent(
249 const blink::WebString& key, const blink::WebString& old_value,
250 const blink::WebString& new_value, const blink::WebString& origin,
251 const blink::WebURL& url, bool is_local_storage) {
252 NOTREACHED();
255 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
256 const blink::WebString& vfs_file_name, bool sync_dir) {
257 NOTREACHED();
258 return 0;
261 } // namespace content