OLD | NEW |
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 "ppapi/proxy/ppb_font_proxy.h" | 5 #include "ppapi/proxy/ppb_font_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
11 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
12 #include "ppapi/proxy/ppb_image_data_proxy.h" | 12 #include "ppapi/proxy/ppb_image_data_proxy.h" |
13 #include "ppapi/proxy/serialized_var.h" | 13 #include "ppapi/proxy/serialized_var.h" |
14 #include "ppapi/shared_impl/ppapi_preferences.h" | 14 #include "ppapi/shared_impl/ppapi_preferences.h" |
15 #include "ppapi/shared_impl/resource_object_base.h" | 15 #include "ppapi/shared_impl/resource_object_base.h" |
| 16 #include "ppapi/shared_impl/var.h" |
16 #include "ppapi/thunk/enter.h" | 17 #include "ppapi/thunk/enter.h" |
17 #include "ppapi/thunk/ppb_image_data_api.h" | 18 #include "ppapi/thunk/ppb_image_data_api.h" |
18 #include "ppapi/thunk/thunk.h" | 19 #include "ppapi/thunk/thunk.h" |
19 | 20 |
| 21 using ppapi::StringVar; |
20 using ppapi::thunk::EnterResourceNoLock; | 22 using ppapi::thunk::EnterResourceNoLock; |
21 using ppapi::thunk::PPB_ImageData_API; | 23 using ppapi::thunk::PPB_ImageData_API; |
22 using ppapi::WebKitForwarding; | 24 using ppapi::WebKitForwarding; |
23 | 25 |
24 namespace pp { | 26 namespace pp { |
25 namespace proxy { | 27 namespace proxy { |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, | 31 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, |
30 WebKitForwarding::Font::TextRun* output) { | 32 WebKitForwarding::Font::TextRun* output) { |
31 const std::string* str = PluginVarTracker::GetInstance()->GetExistingString( | 33 scoped_refptr<StringVar> str(StringVar::FromPPVar(run->text)); |
32 run->text); | |
33 if (!str) | 34 if (!str) |
34 return false; | 35 return false; |
35 | 36 |
36 output->text = *str; | 37 output->text = str->value(); |
37 output->rtl = PP_ToBool(run->rtl); | 38 output->rtl = PP_ToBool(run->rtl); |
38 output->override_direction = PP_ToBool(run->override_direction); | 39 output->override_direction = PP_ToBool(run->override_direction); |
39 return true; | 40 return true; |
40 } | 41 } |
41 | 42 |
42 InterfaceProxy* CreateFontProxy(Dispatcher* dispatcher, | 43 InterfaceProxy* CreateFontProxy(Dispatcher* dispatcher, |
43 const void* target_interface) { | 44 const void* target_interface) { |
44 return new PPB_Font_Proxy(dispatcher, target_interface); | 45 return new PPB_Font_Proxy(dispatcher, target_interface); |
45 } | 46 } |
46 | 47 |
(...skipping 28 matching lines...) Expand all Loading... |
75 if (!dispatcher) | 76 if (!dispatcher) |
76 return PP_MakeUndefined(); | 77 return PP_MakeUndefined(); |
77 | 78 |
78 // Assume the font families don't change, so we can cache the result globally. | 79 // Assume the font families don't change, so we can cache the result globally. |
79 static std::string families; | 80 static std::string families; |
80 if (families.empty()) { | 81 if (families.empty()) { |
81 dispatcher->SendToBrowser( | 82 dispatcher->SendToBrowser( |
82 new PpapiHostMsg_PPBFont_GetFontFamilies(&families)); | 83 new PpapiHostMsg_PPBFont_GetFontFamilies(&families)); |
83 } | 84 } |
84 | 85 |
85 PP_Var result; | 86 return StringVar::StringToPPVar(0, families); |
86 result.type = PP_VARTYPE_STRING; | |
87 result.value.as_id = PluginVarTracker::GetInstance()->MakeString(families); | |
88 return result; | |
89 } | 87 } |
90 | 88 |
91 bool PPB_Font_Proxy::OnMessageReceived(const IPC::Message& msg) { | 89 bool PPB_Font_Proxy::OnMessageReceived(const IPC::Message& msg) { |
92 // There aren't any font messages. | 90 // There aren't any font messages. |
93 NOTREACHED(); | 91 NOTREACHED(); |
94 return false; | 92 return false; |
95 } | 93 } |
96 | 94 |
97 Font::Font(const HostResource& resource, | 95 Font::Font(const HostResource& resource, |
98 const PP_FontDescription_Dev& desc) | 96 const PP_FontDescription_Dev& desc) |
99 : PluginResource(resource), | 97 : PluginResource(resource), |
100 webkit_event_(false, false) { | 98 webkit_event_(false, false) { |
101 TRACE_EVENT0("ppapi proxy", "Font::Font"); | 99 TRACE_EVENT0("ppapi proxy", "Font::Font"); |
102 const std::string* face = PluginVarTracker::GetInstance()->GetExistingString( | 100 scoped_refptr<StringVar> face(StringVar::FromPPVar(desc.face)); |
103 desc.face); | |
104 | 101 |
105 WebKitForwarding* forwarding = GetDispatcher()->GetWebKitForwarding(); | 102 WebKitForwarding* forwarding = GetDispatcher()->GetWebKitForwarding(); |
106 | 103 |
107 WebKitForwarding::Font* result = NULL; | 104 WebKitForwarding::Font* result = NULL; |
108 RunOnWebKitThread(base::Bind(&WebKitForwarding::CreateFontForwarding, | 105 RunOnWebKitThread(base::Bind(&WebKitForwarding::CreateFontForwarding, |
109 base::Unretained(forwarding), | 106 base::Unretained(forwarding), |
110 &webkit_event_, desc, | 107 &webkit_event_, desc, |
111 face ? *face : std::string(), | 108 face.get() ? face->value() : std::string(), |
112 GetDispatcher()->preferences(), | 109 GetDispatcher()->preferences(), |
113 &result)); | 110 &result)); |
114 font_forwarding_.reset(result); | 111 font_forwarding_.reset(result); |
115 } | 112 } |
116 | 113 |
117 Font::~Font() { | 114 Font::~Font() { |
118 } | 115 } |
119 | 116 |
120 ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { | 117 ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { |
121 return this; | 118 return this; |
122 } | 119 } |
123 | 120 |
124 Font* Font::AsFont() { | 121 Font* Font::AsFont() { |
125 return this; | 122 return this; |
126 } | 123 } |
127 | 124 |
128 PP_Bool Font::Describe(PP_FontDescription_Dev* description, | 125 PP_Bool Font::Describe(PP_FontDescription_Dev* description, |
129 PP_FontMetrics_Dev* metrics) { | 126 PP_FontMetrics_Dev* metrics) { |
130 TRACE_EVENT0("ppapi proxy", "Font::Describe"); | 127 TRACE_EVENT0("ppapi proxy", "Font::Describe"); |
131 std::string face; | 128 std::string face; |
132 PP_Bool result = PP_FALSE; | 129 PP_Bool result = PP_FALSE; |
133 RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::Describe, | 130 RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::Describe, |
134 base::Unretained(font_forwarding_.get()), | 131 base::Unretained(font_forwarding_.get()), |
135 &webkit_event_, description, &face, metrics, | 132 &webkit_event_, description, &face, metrics, |
136 &result)); | 133 &result)); |
137 | 134 |
138 if (result == PP_TRUE) { | 135 if (PP_ToBool(result)) |
139 description->face.type = PP_VARTYPE_STRING; | 136 description->face = StringVar::StringToPPVar(0, face); |
140 description->face.value.as_id = | 137 else |
141 PluginVarTracker::GetInstance()->MakeString(face); | 138 description->face = PP_MakeUndefined(); |
142 } else { | |
143 description->face.type = PP_VARTYPE_UNDEFINED; | |
144 } | |
145 return result; | 139 return result; |
146 } | 140 } |
147 | 141 |
148 PP_Bool Font::DrawTextAt(PP_Resource pp_image_data, | 142 PP_Bool Font::DrawTextAt(PP_Resource pp_image_data, |
149 const PP_TextRun_Dev* text, | 143 const PP_TextRun_Dev* text, |
150 const PP_Point* position, | 144 const PP_Point* position, |
151 uint32_t color, | 145 uint32_t color, |
152 const PP_Rect* clip, | 146 const PP_Rect* clip, |
153 PP_Bool image_data_is_opaque) { | 147 PP_Bool image_data_is_opaque) { |
154 TRACE_EVENT0("ppapi proxy", "Font::DrawTextAt"); | 148 TRACE_EVENT0("ppapi proxy", "Font::DrawTextAt"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 return result; | 218 return result; |
225 } | 219 } |
226 | 220 |
227 void Font::RunOnWebKitThread(const base::Closure& task) { | 221 void Font::RunOnWebKitThread(const base::Closure& task) { |
228 GetDispatcher()->PostToWebKitThread(FROM_HERE, task); | 222 GetDispatcher()->PostToWebKitThread(FROM_HERE, task); |
229 webkit_event_.Wait(); | 223 webkit_event_.Wait(); |
230 } | 224 } |
231 | 225 |
232 } // namespace proxy | 226 } // namespace proxy |
233 } // namespace pp | 227 } // namespace pp |
OLD | NEW |