SimpleCache: add an histogram to record the age of entry on open
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_webkitplatformsupport_impl.cc
blob049fe20d1027ae374da666e94720965544b39c4b
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/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"
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
31 using WebKit::WebSandboxSupport;
32 using WebKit::WebString;
33 using WebKit::WebUChar;
34 using WebKit::WebUChar32;
36 typedef struct CGFont* CGFontRef;
38 namespace content {
40 class PpapiWebKitPlatformSupportImpl::SandboxSupport
41 : 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(
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);
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
69 #if defined(OS_WIN)
71 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
72 HFONT font) {
73 LOGFONT logfont;
74 GetObject(font, sizeof(LOGFONT), &logfont);
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));
82 #elif defined(OS_MACOSX)
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;
95 #elif defined(OS_ANDROID)
97 // Empty class.
99 #elif defined(OS_POSIX)
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;
116 GetFontFamilyForCharacter(character, preferred_locale, family);
117 unicode_font_families_.insert(std::make_pair(character, *family));
120 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
121 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) {
122 GetRenderStyleForStrike(family, sizeAndStyle, out);
125 #endif
127 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
128 : sandbox_support_(new PpapiWebKitPlatformSupportImpl::SandboxSupport()) {
131 PpapiWebKitPlatformSupportImpl::~PpapiWebKitPlatformSupportImpl() {
134 WebKit::WebClipboard* PpapiWebKitPlatformSupportImpl::clipboard() {
135 NOTREACHED();
136 return NULL;
139 WebKit::WebMimeRegistry* PpapiWebKitPlatformSupportImpl::mimeRegistry() {
140 NOTREACHED();
141 return NULL;
144 WebKit::WebFileUtilities* PpapiWebKitPlatformSupportImpl::fileUtilities() {
145 NOTREACHED();
146 return NULL;
149 WebKit::WebSandboxSupport* PpapiWebKitPlatformSupportImpl::sandboxSupport() {
150 return sandbox_support_.get();
153 bool PpapiWebKitPlatformSupportImpl::sandboxEnabled() {
154 return true; // Assume PPAPI is always sandboxed.
157 unsigned long long PpapiWebKitPlatformSupportImpl::visitedLinkHash(
158 const char* canonical_url,
159 size_t length) {
160 NOTREACHED();
161 return 0;
164 bool PpapiWebKitPlatformSupportImpl::isLinkVisited(
165 unsigned long long link_hash) {
166 NOTREACHED();
167 return false;
170 WebKit::WebMessagePortChannel*
171 PpapiWebKitPlatformSupportImpl::createMessagePortChannel() {
172 NOTREACHED();
173 return NULL;
176 void PpapiWebKitPlatformSupportImpl::setCookies(
177 const WebKit::WebURL& url,
178 const WebKit::WebURL& first_party_for_cookies,
179 const WebKit::WebString& value) {
180 NOTREACHED();
183 WebKit::WebString PpapiWebKitPlatformSupportImpl::cookies(
184 const WebKit::WebURL& url,
185 const WebKit::WebURL& first_party_for_cookies) {
186 NOTREACHED();
187 return WebKit::WebString();
190 WebKit::WebString PpapiWebKitPlatformSupportImpl::defaultLocale() {
191 NOTREACHED();
192 return WebKit::WebString();
195 WebKit::WebThemeEngine* PpapiWebKitPlatformSupportImpl::themeEngine() {
196 NOTREACHED();
197 return NULL;
200 WebKit::WebURLLoader* PpapiWebKitPlatformSupportImpl::createURLLoader() {
201 NOTREACHED();
202 return NULL;
205 WebKit::WebSocketStreamHandle*
206 PpapiWebKitPlatformSupportImpl::createSocketStreamHandle() {
207 NOTREACHED();
208 return NULL;
211 void PpapiWebKitPlatformSupportImpl::getPluginList(bool refresh,
212 WebKit::WebPluginListBuilder* builder) {
213 NOTREACHED();
216 WebKit::WebData PpapiWebKitPlatformSupportImpl::loadResource(const char* name) {
217 NOTREACHED();
218 return WebKit::WebData();
221 WebKit::WebStorageNamespace*
222 PpapiWebKitPlatformSupportImpl::createLocalStorageNamespace() {
223 NOTREACHED();
224 return 0;
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();
234 int PpapiWebKitPlatformSupportImpl::databaseDeleteFile(
235 const WebKit::WebString& vfs_file_name, bool sync_dir) {
236 NOTREACHED();
237 return 0;
240 } // namespace content