Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc

Issue 8590028: Use new getFontFamilyForCharacters() API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" 5 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "content/common/child_process_messages.h" 13 #include "content/common/child_process_messages.h"
14 #include "content/common/child_thread.h" 14 #include "content/common/child_thread.h"
15 #include "ipc/ipc_sync_message_filter.h" 15 #include "ipc/ipc_sync_message_filter.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa lue.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa lue.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
18 18
19 #if defined(OS_WIN) 19 #if defined(OS_WIN)
20 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebSandboxSupport .h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebSandboxSupport .h"
21 #elif defined(OS_MACOSX) 21 #elif defined(OS_MACOSX)
22 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebSandboxSupport .h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebSandboxSupport .h"
23 #elif defined(OS_POSIX) 23 #elif defined(OS_POSIX)
24 #include "content/common/child_process_sandbox_support_impl_linux.h" 24 #include "content/common/child_process_sandbox_support_impl_linux.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebFontFamily.h "
25 #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebSandboxSuppo rt.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebSandboxSuppo rt.h"
26 #endif 27 #endif
27 28
28 using WebKit::WebSandboxSupport; 29 using WebKit::WebSandboxSupport;
29 using WebKit::WebString; 30 using WebKit::WebString;
30 using WebKit::WebUChar; 31 using WebKit::WebUChar;
31 32
32 typedef struct CGFont* CGFontRef; 33 typedef struct CGFont* CGFontRef;
33 34
34 class PpapiWebKitPlatformSupportImpl::SandboxSupport : public WebSandboxSupport { 35 class PpapiWebKitPlatformSupportImpl::SandboxSupport : public WebSandboxSupport {
35 public: 36 public:
36 virtual ~SandboxSupport() {} 37 virtual ~SandboxSupport() {}
37 38
38 #if defined(OS_WIN) 39 #if defined(OS_WIN)
39 virtual bool ensureFontLoaded(HFONT); 40 virtual bool ensureFontLoaded(HFONT);
40 #elif defined(OS_MACOSX) 41 #elif defined(OS_MACOSX)
41 virtual bool loadFont( 42 virtual bool loadFont(
42 NSFont* srcFont, CGFontRef* out, uint32_t* fontID); 43 NSFont* srcFont, CGFontRef* out, uint32_t* fontID);
43 #elif defined(OS_POSIX) 44 #elif defined(OS_POSIX)
44 virtual WebString getFontFamilyForCharacters( 45 virtual void getFontFamilyForCharacters(
45 const WebUChar* characters, 46 const WebUChar* characters,
46 size_t numCharacters, 47 size_t numCharacters,
47 const char* preferred_locale); 48 const char* preferred_locale,
49 WebKit::WebFontFamily* family);
48 virtual void getRenderStyleForStrike( 50 virtual void getRenderStyleForStrike(
49 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out); 51 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out);
50 52
51 private: 53 private:
52 // WebKit likes to ask us for the correct font family to use for a set of 54 // WebKit likes to ask us for the correct font family to use for a set of
53 // unicode code points. It needs this information frequently so we cache it 55 // unicode code points. It needs this information frequently so we cache it
54 // here. The key in this map is an array of 16-bit UTF16 values from WebKit. 56 // here. The key in this map is an array of 16-bit UTF16 values from WebKit.
55 // The value is a string containing the correct font family. 57 // The value is a string containing the correct font family.
56 base::Lock unicode_font_families_mutex_; 58 base::Lock unicode_font_families_mutex_;
57 std::map<string16, std::string> unicode_font_families_; 59 std::map<string16, WebKit::WebFontFamily> unicode_font_families_;
58 #endif 60 #endif
59 }; 61 };
60 62
61 #if defined(OS_WIN) 63 #if defined(OS_WIN)
62 64
63 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( 65 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
64 HFONT font) { 66 HFONT font) {
65 LOGFONT logfont; 67 LOGFONT logfont;
66 GetObject(font, sizeof(LOGFONT), &logfont); 68 GetObject(font, sizeof(LOGFONT), &logfont);
67 69
68 return ChildThread::current()->sync_message_filter()->Send( 70 return ChildThread::current()->sync_message_filter()->Send(
69 new ChildProcessHostMsg_PreCacheFont(logfont)); 71 new ChildProcessHostMsg_PreCacheFont(logfont));
70 } 72 }
71 73
72 #elif defined(OS_MACOSX) 74 #elif defined(OS_MACOSX)
73 75
74 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont( 76 bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
75 NSFont* src_font, 77 NSFont* src_font,
76 CGFontRef* out, 78 CGFontRef* out,
77 uint32_t* font_id) { 79 uint32_t* font_id) {
78 // TODO(brettw) this should do the something similar to what 80 // TODO(brettw) this should do the something similar to what
79 // RendererWebKitClientImpl does and request that the browser load the font. 81 // RendererWebKitClientImpl does and request that the browser load the font.
80 NOTIMPLEMENTED(); 82 NOTIMPLEMENTED();
81 return false; 83 return false;
82 } 84 }
83 85
84 #elif defined(OS_POSIX) 86 #elif defined(OS_POSIX)
85 87
86 WebString 88 void
87 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters( 89 PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
88 const WebUChar* characters, 90 const WebUChar* characters,
89 size_t num_characters, 91 size_t num_characters,
90 const char* preferred_locale) { 92 const char* preferred_locale,
93 WebKit::WebFontFamily* family) {
91 base::AutoLock lock(unicode_font_families_mutex_); 94 base::AutoLock lock(unicode_font_families_mutex_);
92 const string16 key(characters, num_characters); 95 const string16 key(characters, num_characters);
93 const std::map<string16, std::string>::const_iterator iter = 96 const std::map<string16, WebKit::WebFontFamily>::const_iterator iter =
94 unicode_font_families_.find(key); 97 unicode_font_families_.find(key);
95 if (iter != unicode_font_families_.end()) 98 if (iter != unicode_font_families_.end()) {
96 return WebString::fromUTF8(iter->second); 99 family->name = iter->second.name;
100 family->isBold = iter->second.isBold;
101 family->isItalic = iter->second.isItalic;
102 return;
103 }
97 104
98 const std::string family_name = content::GetFontFamilyForCharacters( 105 content::GetFontFamilyForCharacters(
99 characters, 106 characters,
100 num_characters, 107 num_characters,
101 preferred_locale); 108 preferred_locale,
102 unicode_font_families_.insert(make_pair(key, family_name)); 109 family);
103 return WebString::fromUTF8(family_name); 110 unicode_font_families_.insert(make_pair(key, *family));
104 } 111 }
105 112
106 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike( 113 void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
107 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) { 114 const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out) {
108 content::GetRenderStyleForStrike(family, sizeAndStyle, out); 115 content::GetRenderStyleForStrike(family, sizeAndStyle, out);
109 } 116 }
110 117
111 #endif 118 #endif
112 119
113 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl() 120 PpapiWebKitPlatformSupportImpl::PpapiWebKitPlatformSupportImpl()
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 248 }
242 249
243 WebKit::WebSerializedScriptValue 250 WebKit::WebSerializedScriptValue
244 PpapiWebKitPlatformSupportImpl::injectIDBKeyIntoSerializedValue( 251 PpapiWebKitPlatformSupportImpl::injectIDBKeyIntoSerializedValue(
245 const WebKit::WebIDBKey& key, 252 const WebKit::WebIDBKey& key,
246 const WebKit::WebSerializedScriptValue& value, 253 const WebKit::WebSerializedScriptValue& value,
247 const WebKit::WebString& keyPath) { 254 const WebKit::WebString& keyPath) {
248 NOTREACHED(); 255 NOTREACHED();
249 return WebKit::WebSerializedScriptValue(); 256 return WebKit::WebSerializedScriptValue();
250 } 257 }
OLDNEW
« no previous file with comments | « content/common/child_process_sandbox_support_impl_linux.cc ('k') | content/renderer/renderer_webkitplatformsupport_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698