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/strings/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_ANDROID) 23 #include "third_party/WebKit/public/platform/android/WebSandboxSupport.h" 24 #elif defined(OS_POSIX) 25 #include "content/common/child_process_sandbox_support_impl_linux.h" 26 #include "third_party/WebKit/public/platform/linux/WebFontFamily.h" 27 #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h" 28 #include "third_party/icu/source/common/unicode/utf16.h" 29 #endif 30 31 using WebKit::WebSandboxSupport; 32 using WebKit::WebString; 33 using WebKit::WebUChar; 34 using WebKit::WebUChar32; 35 36 typedef struct CGFont* CGFontRef; 37 38 namespace content { 39 40 class PpapiWebKitPlatformSupportImpl::SandboxSupport 41 : public WebSandboxSupport { 42 public: 43 virtual ~SandboxSupport() {} 44 45 #if defined(OS_WIN) 46 virtual bool ensureFontLoaded(HFONT); 47 #elif defined(OS_MACOSX) 48 virtual bool loadFont( 49 NSFont* srcFont, CGFontRef* out, uint32_t* fontID); 50 #elif defined(OS_ANDROID) 51 // Empty class. 52 #elif defined(OS_POSIX) 53 virtual void getFontFamilyForCharacter( 54 WebUChar32 character, 55 const char* preferred_locale, 56 WebKit::WebFontFamily* family); 57 virtual void getRenderStyleForStrike( 58 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out); 59 60 private: 61 // WebKit likes to ask us for the correct font family to use for a set of 62 // unicode code points. It needs this information frequently so we cache it 63 // here. 64 base::Lock unicode_font_families_mutex_; 65 std::map<int32_t, WebKit::WebFontFamily> unicode_font_families_; 66 #endif 67 }; 68 69 #if defined(OS_WIN) 70 71 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( 72 HFONT font) { 73 LOGFONT logfont; 74 GetObject(font, sizeof(LOGFONT), &logfont); 75 76 // Use the proxy sender rather than going directly to the ChildThread since 77 // the proxy browser sender will properly unlock during sync messages. 78 return ppapi::proxy::PluginGlobals::Get()->GetBrowserSender()->Send( 79 new ChildProcessHostMsg_PreCacheFont(logfont)); 80 } 81 82 #elif defined(OS_MACOSX) 83 84 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont( 85 NSFont* src_font, 86 CGFontRef* out, 87 uint32_t* font_id) { 88 // TODO(brettw) this should do the something similar to what 89 // RendererWebKitClientImpl 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; 93 } 94 95 #elif defined(OS_ANDROID) 96 97 // Empty class. 98 99 #elif defined(OS_POSIX) 100 101 void 102 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacter( 103 WebUChar32 character, 104 const char* preferred_locale, 105 WebKit::WebFontFamily* family) { 106 base::AutoLock lock(unicode_font_families_mutex_); 107 const std::map<int32_t, WebKit::WebFontFamily>::const_iterator iter = 108 unicode_font_families_.find(character); 109 if (iter != unicode_font_families_.end()) { 110 family->name = iter->second.name; 111 family->isBold = iter->second.isBold; 112 family->isItalic = iter->second.isItalic; 113 return; 114 } 115 116 GetFontFamilyForCharacter(character, preferred_locale, family); 117 unicode_font_families_.insert(std::make_pair(character, *family)); 118 } 119 120 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( 121 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) { 122 GetRenderStyleForStrike(family, sizeAndStyle, out); 123 } 124 125 #endif 126 127 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl() 128 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) { 129 } 130 131 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() { 132 } 133 134 WebKit::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() { 135 NOTREACHED(); 136 return NULL; 137 } 138 139 WebKit::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() { 140 NOTREACHED(); 141 return NULL; 142 } 143 144 WebKit::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() { 145 NOTREACHED(); 146 return NULL; 147 } 148 149 WebKit::WebSandboxSupport* PpapiWebKitPlatformSupportImpl::sandboxSupport() { 150 return sandbox_support_.get(); 151 } 152 153 bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() { 154 return true; // Assume PPAPI is always sandboxed. 155 } 156 157 unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash( 158 const char* canonical_url, 159 size_t length) { 160 NOTREACHED(); 161 return 0; 162 } 163 164 bool PpapiWebKitPlatformSupportImpl::isLinkVisited( 165 unsigned long long link_hash) { 166 NOTREACHED(); 167 return false; 168 } 169 170 WebKit::WebMessagePortChannel* 171 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() { 172 NOTREACHED(); 173 return NULL; 174 } 175 176 void PpapiWebKitPlatformSupportImpl::setCookies( 177 const WebKit::WebURL& url, 178 const WebKit::WebURL& first_party_for_cookies, 179 const WebKit::WebString& value) { 180 NOTREACHED(); 181 } 182 183 WebKit::WebString PpapiWebKitPlatformSupportImpl::cookies( 184 const WebKit::WebURL& url, 185 const WebKit::WebURL& first_party_for_cookies) { 186 NOTREACHED(); 187 return WebKit::WebString(); 188 } 189 190 WebKit::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() { 191 NOTREACHED(); 192 return WebKit::WebString(); 193 } 194 195 WebKit::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() { 196 NOTREACHED(); 197 return NULL; 198 } 199 200 WebKit::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() { 201 NOTREACHED(); 202 return NULL; 203 } 204 205 WebKit::WebSocketStreamHandle* 206 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() { 207 NOTREACHED(); 208 return NULL; 209 } 210 211 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh, 212 WebKit::WebPluginListBuilder* builder) { 213 NOTREACHED(); 214 } 215 216 WebKit::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) { 217 NOTREACHED(); 218 return WebKit::WebData(); 219 } 220 221 WebKit::WebStorageNamespace* 222 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace() { 223 NOTREACHED(); 224 return 0; 225 } 226 227 void PpapiWebKitPlatformSupportImpl::dispatchStorageEvent( 228 const WebKit::WebString& key, const WebKit::WebString& old_value, 229 const WebKit::WebString& new_value, const WebKit::WebString& origin, 230 const WebKit::WebURL& url, bool is_local_storage) { 231 NOTREACHED(); 232 } 233 234 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile( 235 const WebKit::WebString& vfs_file_name, bool sync_dir) { 236 NOTREACHED(); 237 return 0; 238 } 239 240 } // namespace content 241