Fix the last lint warnings in chrome/
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_blink_platform_impl.cc
blob793f6d612bc48712f887282fd9f80d120ec63792
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_blink_platform_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_impl.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 PpapiBlinkPlatformImpl::SandboxSupport : public WebSandboxSupport {
42 public:
43 virtual ~SandboxSupport() {}
45 #if defined(OS_WIN)
46 virtual bool ensureFontLoaded(HFONT);
47 #elif defined(OS_MACOSX)
48 virtual bool loadFont(NSFont* srcFont, CGFontRef* out, uint32_t* fontID);
49 #elif defined(OS_ANDROID)
50 // Empty class.
51 #elif defined(OS_POSIX)
52 SandboxSupport();
53 virtual void getFallbackFontForCharacter(
54 WebUChar32 character,
55 const char* preferred_locale,
56 blink::WebFallbackFont* fallbackFont);
57 virtual void getRenderStyleForStrike(const char* family,
58 int sizeAndStyle,
59 blink::WebFontRenderStyle* out);
61 private:
62 // WebKit likes to ask us for the correct font family to use for a set of
63 // unicode code points. It needs this information frequently so we cache it
64 // here.
65 std::map<int32_t, blink::WebFallbackFont> unicode_font_families_;
66 // For debugging crbug.com/312965
67 base::PlatformThreadId creation_thread_;
68 #endif
71 #if defined(OS_WIN)
73 bool PpapiBlinkPlatformImpl::SandboxSupport::ensureFontLoaded(HFONT font) {
74 LOGFONT logfont;
75 GetObject(font, sizeof(LOGFONT), &logfont);
77 // Use the proxy sender rather than going directly to the ChildThread since
78 // the proxy browser sender will properly unlock during sync messages.
79 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send(
80 new ChildProcessHostMsg_PreCacheFont(logfont));
83 #elif defined(OS_MACOSX)
85 bool PpapiBlinkPlatformImpl::SandboxSupport::loadFont(NSFont* src_font,
86 CGFontRef* out,
87 uint32_t* font_id) {
88 // TODO(brettw) this should do the something similar to what
89 // RendererBlinkPlatformImpl does and request that the browser load the font.
90 // Note: need to unlock the proxy lock like ensureFontLoaded does.
91 NOTIMPLEMENTED();
92 return false;
95 #elif defined(OS_ANDROID)
97 // Empty class.
99 #elif defined(OS_POSIX)
101 PpapiBlinkPlatformImpl::SandboxSupport::SandboxSupport()
102 : creation_thread_(base::PlatformThread::CurrentId()) {
105 void PpapiBlinkPlatformImpl::SandboxSupport::getFallbackFontForCharacter(
106 WebUChar32 character,
107 const char* preferred_locale,
108 blink::WebFallbackFont* fallbackFont) {
109 ppapi::ProxyLock::AssertAcquired();
110 // For debugging crbug.com/312965
111 CHECK_EQ(creation_thread_, base::PlatformThread::CurrentId());
112 const std::map<int32_t, blink::WebFallbackFont>::const_iterator iter =
113 unicode_font_families_.find(character);
114 if (iter != unicode_font_families_.end()) {
115 fallbackFont->name = iter->second.name;
116 fallbackFont->filename = iter->second.filename;
117 fallbackFont->fontconfigInterfaceId = iter->second.fontconfigInterfaceId;
118 fallbackFont->ttcIndex = iter->second.ttcIndex;
119 fallbackFont->isBold = iter->second.isBold;
120 fallbackFont->isItalic = iter->second.isItalic;
121 return;
124 GetFallbackFontForCharacter(character, preferred_locale, fallbackFont);
125 unicode_font_families_.insert(std::make_pair(character, *fallbackFont));
128 void PpapiBlinkPlatformImpl::SandboxSupport::getRenderStyleForStrike(
129 const char* family,
130 int sizeAndStyle,
131 blink::WebFontRenderStyle* out) {
132 GetRenderStyleForStrike(family, sizeAndStyle, out);
135 #endif
137 PpapiBlinkPlatformImpl::PpapiBlinkPlatformImpl()
138 : sandbox_support_(new PpapiBlinkPlatformImpl::SandboxSupport()) {
141 PpapiBlinkPlatformImpl::~PpapiBlinkPlatformImpl() {
144 void PpapiBlinkPlatformImpl::Shutdown() {
145 // SandboxSupport contains a map of WebFontFamily objects, which hold
146 // WebCStrings, which become invalidated when blink is shut down. Hence, we
147 // need to clear that map now, just before blink::shutdown() is called.
148 sandbox_support_.reset();
151 blink::WebClipboard* PpapiBlinkPlatformImpl::clipboard() {
152 NOTREACHED();
153 return NULL;
156 blink::WebMimeRegistry* PpapiBlinkPlatformImpl::mimeRegistry() {
157 NOTREACHED();
158 return NULL;
161 blink::WebFileUtilities* PpapiBlinkPlatformImpl::fileUtilities() {
162 NOTREACHED();
163 return NULL;
166 blink::WebSandboxSupport* PpapiBlinkPlatformImpl::sandboxSupport() {
167 return sandbox_support_.get();
170 bool PpapiBlinkPlatformImpl::sandboxEnabled() {
171 return true; // Assume PPAPI is always sandboxed.
174 unsigned long long PpapiBlinkPlatformImpl::visitedLinkHash(
175 const char* canonical_url,
176 size_t length) {
177 NOTREACHED();
178 return 0;
181 bool PpapiBlinkPlatformImpl::isLinkVisited(unsigned long long link_hash) {
182 NOTREACHED();
183 return false;
186 void PpapiBlinkPlatformImpl::createMessageChannel(
187 blink::WebMessagePortChannel** channel1,
188 blink::WebMessagePortChannel** channel2) {
189 NOTREACHED();
190 *channel1 = NULL;
191 *channel2 = NULL;
194 void PpapiBlinkPlatformImpl::setCookies(
195 const blink::WebURL& url,
196 const blink::WebURL& first_party_for_cookies,
197 const blink::WebString& value) {
198 NOTREACHED();
201 blink::WebString PpapiBlinkPlatformImpl::cookies(
202 const blink::WebURL& url,
203 const blink::WebURL& first_party_for_cookies) {
204 NOTREACHED();
205 return blink::WebString();
208 blink::WebString PpapiBlinkPlatformImpl::defaultLocale() {
209 NOTREACHED();
210 return blink::WebString();
213 blink::WebThemeEngine* PpapiBlinkPlatformImpl::themeEngine() {
214 NOTREACHED();
215 return NULL;
218 blink::WebURLLoader* PpapiBlinkPlatformImpl::createURLLoader() {
219 NOTREACHED();
220 return NULL;
223 void PpapiBlinkPlatformImpl::getPluginList(
224 bool refresh,
225 blink::WebPluginListBuilder* builder) {
226 NOTREACHED();
229 blink::WebData PpapiBlinkPlatformImpl::loadResource(const char* name) {
230 NOTREACHED();
231 return blink::WebData();
234 blink::WebStorageNamespace*
235 PpapiBlinkPlatformImpl::createLocalStorageNamespace() {
236 NOTREACHED();
237 return 0;
240 void PpapiBlinkPlatformImpl::dispatchStorageEvent(
241 const blink::WebString& key,
242 const blink::WebString& old_value,
243 const blink::WebString& new_value,
244 const blink::WebString& origin,
245 const blink::WebURL& url,
246 bool is_local_storage) {
247 NOTREACHED();
250 int PpapiBlinkPlatformImpl::databaseDeleteFile(
251 const blink::WebString& vfs_file_name,
252 bool sync_dir) {
253 NOTREACHED();
254 return 0;
257 } // namespace content