ppapi_webkitplatformsupport_impl.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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. 4 5#include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" 6 7#include <map> 8 9#include "base/logging.h" 10#include "base/string16.h" 11#include "base/synchronization/lock.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 "third_party/WebKit/public/platform/WebString.h" 17 18#if defined(OS_WIN) 19#include "third_party/WebKit/public/platform/win/WebSandboxSupport.h" 20#elif defined(OS_MACOSX) 21#include "third_party/WebKit/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/public/platform/linux/WebFontFamily.h" 27#include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h" 28 29#endif 30 31using WebKit::WebSandboxSupport; 32using WebKit::WebString; 33using WebKit::WebUChar; 34 35typedef struct CGFont* CGFontRef; 36 37namespace content { 38 39class PpapiWebKitPlatformSupportImpl::SandboxSupport 40 : public WebSandboxSupport { 41 public: 42 virtual ~SandboxSupport() {} 43 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); 57 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 66}; 67 68#if defined(OS_WIN) 69 70bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( 71 HFONT font) { 72 LOGFONT logfont; 73 GetObject(font, sizeof(LOGFONT), &logfont); 74 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)); 79} 80 81#elif defined(OS_MACOSX) 82 83bool 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; 92} 93 94#elif defined(OS_ANDROID) 95 96// TODO(jrg): resolve (and implement?) PPAPI SandboxSupport for Android. 97 98void 99PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters( 100 const WebUChar* characters, 101 size_t num_characters, 102 const char* preferred_locale, 103 WebKit::WebFontFamily* family) { 104 NOTIMPLEMENTED(); 105} 106 107void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( 108 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) { 109 NOTIMPLEMENTED(); 110} 111 112#elif defined(OS_POSIX) 113 114void 115PpapiWebKitPlatformSupportImpl::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; 129 } 130 131 GetFontFamilyForCharacters( 132 characters, 133 num_characters, 134 preferred_locale, 135 family); 136 unicode_font_families_.insert(make_pair(key, *family)); 137} 138 139void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( 140 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) { 141 GetRenderStyleForStrike(family, sizeAndStyle, out); 142} 143 144#endif 145 146PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl() 147 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) { 148} 149 150PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() { 151} 152 153WebKit::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() { 154 NOTREACHED(); 155 return NULL; 156} 157 158WebKit::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() { 159 NOTREACHED(); 160 return NULL; 161} 162 163WebKit::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() { 164 NOTREACHED(); 165 return NULL; 166} 167 168WebKit::WebSandboxSupport* PpapiWebKitPlatformSupportImpl::sandboxSupport() { 169 return sandbox_support_.get(); 170} 171 172bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() { 173 return true; // Assume PPAPI is always sandboxed. 174} 175 176unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash( 177 const char* canonical_url, 178 size_t length) { 179 NOTREACHED(); 180 return 0; 181} 182 183bool PpapiWebKitPlatformSupportImpl::isLinkVisited( 184 unsigned long long link_hash) { 185 NOTREACHED(); 186 return false; 187} 188 189WebKit::WebMessagePortChannel* 190PpapiWebKitPlatformSupportImpl::createMessagePortChannel() { 191 NOTREACHED(); 192 return NULL; 193} 194 195void PpapiWebKitPlatformSupportImpl::setCookies( 196 const WebKit::WebURL& url, 197 const WebKit::WebURL& first_party_for_cookies, 198 const WebKit::WebString& value) { 199 NOTREACHED(); 200} 201 202WebKit::WebString PpapiWebKitPlatformSupportImpl::cookies( 203 const WebKit::WebURL& url, 204 const WebKit::WebURL& first_party_for_cookies) { 205 NOTREACHED(); 206 return WebKit::WebString(); 207} 208 209void PpapiWebKitPlatformSupportImpl::prefetchHostName( 210 const WebKit::WebString&) { 211 NOTREACHED(); 212} 213 214WebKit::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() { 215 NOTREACHED(); 216 return WebKit::WebString(); 217} 218 219WebKit::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() { 220 NOTREACHED(); 221 return NULL; 222} 223 224WebKit::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() { 225 NOTREACHED(); 226 return NULL; 227} 228 229WebKit::WebSocketStreamHandle* 230 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() { 231 NOTREACHED(); 232 return NULL; 233} 234 235void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh, 236 WebKit::WebPluginListBuilder* builder) { 237 NOTREACHED(); 238} 239 240WebKit::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) { 241 NOTREACHED(); 242 return WebKit::WebData(); 243} 244 245WebKit::WebStorageNamespace* 246PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace( 247 const WebKit::WebString& path, unsigned quota) { 248 NOTREACHED(); 249 return 0; 250} 251 252void 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(); 257} 258 259int PpapiWebKitPlatformSupportImpl::databaseDeleteFile( 260 const WebKit::WebString& vfs_file_name, bool sync_dir) { 261 NOTREACHED(); 262 return 0; 263} 264 265} // namespace content 266