OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/plugins/ppapi/ppb_flash_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "webkit/plugins/ppapi/host_globals.h" | 28 #include "webkit/plugins/ppapi/host_globals.h" |
29 #include "webkit/plugins/ppapi/plugin_delegate.h" | 29 #include "webkit/plugins/ppapi/plugin_delegate.h" |
30 #include "webkit/plugins/ppapi/plugin_module.h" | 30 #include "webkit/plugins/ppapi/plugin_module.h" |
31 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 31 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
32 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 32 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
33 #include "webkit/plugins/ppapi/resource_helper.h" | 33 #include "webkit/plugins/ppapi/resource_helper.h" |
34 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 34 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
35 | 35 |
36 using ppapi::PPTimeToTime; | 36 using ppapi::PPTimeToTime; |
37 using ppapi::StringVar; | 37 using ppapi::StringVar; |
38 using ppapi::thunk::EnterResource; | 38 using ppapi::thunk::EnterResourceNoLock; |
39 using ppapi::thunk::PPB_ImageData_API; | 39 using ppapi::thunk::PPB_ImageData_API; |
40 using ppapi::thunk::PPB_URLRequestInfo_API; | 40 using ppapi::thunk::PPB_URLRequestInfo_API; |
41 | 41 |
42 namespace webkit { | 42 namespace webkit { |
43 namespace ppapi { | 43 namespace ppapi { |
44 | 44 |
45 namespace { | 45 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) |
46 | 46 : instance_(instance) { |
47 void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { | |
48 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
49 if (!instance) | |
50 return; | |
51 instance->set_always_on_top(PPBoolToBool(on_top)); | |
52 } | 47 } |
53 | 48 |
| 49 PPB_Flash_Impl::~PPB_Flash_Impl() { |
| 50 } |
54 | 51 |
55 PP_Bool DrawGlyphs(PP_Instance, | 52 void PPB_Flash_Impl::SetInstanceAlwaysOnTop(PP_Instance instance, |
56 PP_Resource pp_image_data, | 53 PP_Bool on_top) { |
57 const PP_FontDescription_Dev* font_desc, | 54 instance_->set_always_on_top(PP_ToBool(on_top)); |
58 uint32_t color, | 55 } |
59 const PP_Point* position, | 56 |
60 const PP_Rect* clip, | 57 PP_Bool PPB_Flash_Impl::DrawGlyphs(PP_Instance instance, |
61 const float transformation[3][3], | 58 PP_Resource pp_image_data, |
62 PP_Bool allow_subpixel_aa, | 59 const PP_FontDescription_Dev* font_desc, |
63 uint32_t glyph_count, | 60 uint32_t color, |
64 const uint16_t glyph_indices[], | 61 const PP_Point* position, |
65 const PP_Point glyph_advances[]) { | 62 const PP_Rect* clip, |
66 EnterResource<PPB_ImageData_API> enter(pp_image_data, true); | 63 const float transformation[3][3], |
| 64 PP_Bool allow_subpixel_aa, |
| 65 uint32_t glyph_count, |
| 66 const uint16_t glyph_indices[], |
| 67 const PP_Point glyph_advances[]) { |
| 68 EnterResourceNoLock<PPB_ImageData_API> enter(pp_image_data, true); |
67 if (enter.failed()) | 69 if (enter.failed()) |
68 return PP_FALSE; | 70 return PP_FALSE; |
69 PPB_ImageData_Impl* image_resource = | 71 PPB_ImageData_Impl* image_resource = |
70 static_cast<PPB_ImageData_Impl*>(enter.object()); | 72 static_cast<PPB_ImageData_Impl*>(enter.object()); |
71 | 73 |
72 ImageDataAutoMapper mapper(image_resource); | 74 ImageDataAutoMapper mapper(image_resource); |
73 if (!mapper.is_valid()) | 75 if (!mapper.is_valid()) |
74 return PP_FALSE; | 76 return PP_FALSE; |
75 | 77 |
76 // Set up the typeface. | 78 // Set up the typeface. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 sk_positions[i].set(x, y); | 139 sk_positions[i].set(x, y); |
138 x += SkFloatToScalar(glyph_advances[i].x); | 140 x += SkFloatToScalar(glyph_advances[i].x); |
139 y += SkFloatToScalar(glyph_advances[i].y); | 141 y += SkFloatToScalar(glyph_advances[i].y); |
140 } | 142 } |
141 | 143 |
142 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint); | 144 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint); |
143 | 145 |
144 return PP_TRUE; | 146 return PP_TRUE; |
145 } | 147 } |
146 | 148 |
147 PP_Bool DrawGlyphs11(PP_Instance instance, | 149 PP_Var PPB_Flash_Impl::GetProxyForURL(PP_Instance instance, |
148 PP_Resource pp_image_data, | 150 const char* url) { |
149 const PP_FontDescription_Dev* font_desc, | |
150 uint32_t color, | |
151 PP_Point position, | |
152 PP_Rect clip, | |
153 const float transformation[3][3], | |
154 uint32_t glyph_count, | |
155 const uint16_t glyph_indices[], | |
156 const PP_Point glyph_advances[]) { | |
157 return DrawGlyphs(instance, pp_image_data, font_desc, color, &position, | |
158 &clip, transformation, PP_TRUE, glyph_count, | |
159 glyph_indices, glyph_advances); | |
160 } | |
161 | |
162 PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { | |
163 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
164 if (!instance) | |
165 return PP_MakeUndefined(); | |
166 | |
167 GURL gurl(url); | 151 GURL gurl(url); |
168 if (!gurl.is_valid()) | 152 if (!gurl.is_valid()) |
169 return PP_MakeUndefined(); | 153 return PP_MakeUndefined(); |
170 | 154 |
171 std::string proxy_host = instance->delegate()->ResolveProxy(gurl); | 155 std::string proxy_host = instance_->delegate()->ResolveProxy(gurl); |
172 if (proxy_host.empty()) | 156 if (proxy_host.empty()) |
173 return PP_MakeUndefined(); // No proxy. | 157 return PP_MakeUndefined(); // No proxy. |
174 return StringVar::StringToPPVar(proxy_host); | 158 return StringVar::StringToPPVar(proxy_host); |
175 } | 159 } |
176 | 160 |
177 int32_t Navigate(PP_Resource request_id, | 161 int32_t PPB_Flash_Impl::Navigate(PP_Instance instance, |
178 const char* target, | 162 PP_Resource request_info, |
179 PP_Bool from_user_action) { | 163 const char* target, |
180 EnterResource<PPB_URLRequestInfo_API> enter(request_id, true); | 164 PP_Bool from_user_action) { |
| 165 EnterResourceNoLock<PPB_URLRequestInfo_API> enter(request_info, true); |
181 if (enter.failed()) | 166 if (enter.failed()) |
182 return PP_ERROR_BADRESOURCE; | 167 return PP_ERROR_BADRESOURCE; |
183 PPB_URLRequestInfo_Impl* request = | 168 PPB_URLRequestInfo_Impl* request = |
184 static_cast<PPB_URLRequestInfo_Impl*>(enter.object()); | 169 static_cast<PPB_URLRequestInfo_Impl*>(enter.object()); |
185 | 170 |
186 if (!target) | 171 if (!target) |
187 return PP_ERROR_BADARGUMENT; | 172 return PP_ERROR_BADARGUMENT; |
188 | 173 return instance_->Navigate(request, target, PP_ToBool(from_user_action)); |
189 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(request); | |
190 if (!plugin_instance) | |
191 return PP_ERROR_FAILED; | |
192 return plugin_instance->Navigate(request, target, | |
193 PP_ToBool(from_user_action)); | |
194 } | 174 } |
195 | 175 |
196 int32_t Navigate11(PP_Resource request_id, | 176 void PPB_Flash_Impl::RunMessageLoop(PP_Instance instance) { |
197 const char* target, | |
198 bool from_user_action) { | |
199 return Navigate(request_id, target, PP_FromBool(from_user_action)); | |
200 } | |
201 | |
202 void RunMessageLoop(PP_Instance instance) { | |
203 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 177 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
204 MessageLoop::current()->Run(); | 178 MessageLoop::current()->Run(); |
205 } | 179 } |
206 | 180 |
207 void QuitMessageLoop(PP_Instance instance) { | 181 void PPB_Flash_Impl::QuitMessageLoop(PP_Instance instance) { |
208 MessageLoop::current()->QuitNow(); | 182 MessageLoop::current()->QuitNow(); |
209 } | 183 } |
210 | 184 |
211 double GetLocalTimeZoneOffset(PP_Instance pp_instance, PP_Time t) { | 185 double PPB_Flash_Impl::GetLocalTimeZoneOffset(PP_Instance instance, |
212 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 186 PP_Time t) { |
213 if (!instance) | |
214 return 0.0; | |
215 | |
216 // Evil hack. The time code handles exact "0" values as special, and produces | 187 // Evil hack. The time code handles exact "0" values as special, and produces |
217 // a "null" Time object. This will represent some date hundreds of years ago | 188 // a "null" Time object. This will represent some date hundreds of years ago |
218 // and will give us funny results at 1970 (there are some tests where this | 189 // and will give us funny results at 1970 (there are some tests where this |
219 // comes up, but it shouldn't happen in real life). To work around this | 190 // comes up, but it shouldn't happen in real life). To work around this |
220 // special handling, we just need to give it some nonzero value. | 191 // special handling, we just need to give it some nonzero value. |
221 if (t == 0.0) | 192 if (t == 0.0) |
222 t = 0.0000000001; | 193 t = 0.0000000001; |
223 | 194 |
224 // We can't do the conversion here because on Linux, the localtime calls | 195 // We can't do the conversion here because on Linux, the localtime calls |
225 // require filesystem access prohibited by the sandbox. | 196 // require filesystem access prohibited by the sandbox. |
226 return instance->delegate()->GetLocalTimeZoneOffset(PPTimeToTime(t)); | 197 return instance_->delegate()->GetLocalTimeZoneOffset(PPTimeToTime(t)); |
227 } | 198 } |
228 | 199 |
229 PP_Var GetCommandLineArgs(PP_Module pp_module) { | 200 PP_Bool PPB_Flash_Impl::IsRectTopmost(PP_Instance instance, |
230 PluginModule* module = HostGlobals::Get()->GetModule(pp_module); | 201 const PP_Rect* rect) { |
231 if (!module) | 202 return PP_FromBool(instance_->IsRectTopmost( |
232 return PP_MakeUndefined(); | |
233 | |
234 PluginInstance* instance = module->GetSomeInstance(); | |
235 if (!instance) | |
236 return PP_MakeUndefined(); | |
237 | |
238 std::string args = instance->delegate()->GetFlashCommandLineArgs(); | |
239 return StringVar::StringToPPVar(args); | |
240 } | |
241 | |
242 void PreLoadFontWin(const void* logfontw) { | |
243 // Not implemented in-process. | |
244 } | |
245 | |
246 PP_Bool IsRectTopmost(PP_Instance pp_instance, const PP_Rect* rect) { | |
247 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
248 if (!instance) | |
249 return PP_FALSE; | |
250 return PP_FromBool(instance->IsRectTopmost( | |
251 gfx::Rect(rect->point.x, rect->point.y, | 203 gfx::Rect(rect->point.x, rect->point.y, |
252 rect->size.width, rect->size.height))); | 204 rect->size.width, rect->size.height))); |
253 } | 205 } |
254 | 206 |
255 int32_t InvokePrinting(PP_Instance pp_instance) { | 207 int32_t PPB_Flash_Impl::InvokePrinting(PP_Instance instance) { |
256 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
257 if (!instance) | |
258 return PP_ERROR_BADARGUMENT; | |
259 | |
260 // TODO(viettrungluu): Implement me. | 208 // TODO(viettrungluu): Implement me. |
261 | |
262 return PP_ERROR_NOTSUPPORTED; | 209 return PP_ERROR_NOTSUPPORTED; |
263 } | 210 } |
264 | 211 |
265 void UpdateActivity(PP_Instance pp_instance) { | 212 void PPB_Flash_Impl::UpdateActivity(PP_Instance pp_instance) { |
266 // Not supported in-process. | 213 // Not supported in-process. |
267 } | 214 } |
268 | 215 |
269 PP_Var GetDeviceID(PP_Instance pp_instance) { | 216 PP_Var PPB_Flash_Impl::GetDeviceID(PP_Instance pp_instance) { |
270 // Not supported in-process. | 217 // Not supported in-process. |
271 return PP_MakeUndefined(); | 218 return PP_MakeUndefined(); |
272 } | 219 } |
273 | 220 |
274 const PPB_Flash_11 ppb_flash_11 = { | 221 PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) { |
275 &SetInstanceAlwaysOnTop, | 222 return PP_FromBool(instance_->flash_fullscreen()); |
276 &DrawGlyphs11, | |
277 &GetProxyForURL, | |
278 &Navigate11, | |
279 &RunMessageLoop, | |
280 &QuitMessageLoop, | |
281 &GetLocalTimeZoneOffset, | |
282 &GetCommandLineArgs | |
283 }; | |
284 | |
285 const PPB_Flash_12_0 ppb_flash_12_0 = { | |
286 &SetInstanceAlwaysOnTop, | |
287 &DrawGlyphs, | |
288 &GetProxyForURL, | |
289 &Navigate, | |
290 &RunMessageLoop, | |
291 &QuitMessageLoop, | |
292 &GetLocalTimeZoneOffset, | |
293 &GetCommandLineArgs, | |
294 &PreLoadFontWin | |
295 }; | |
296 | |
297 const PPB_Flash_12_1 ppb_flash_12_1 = { | |
298 &SetInstanceAlwaysOnTop, | |
299 &DrawGlyphs, | |
300 &GetProxyForURL, | |
301 &Navigate, | |
302 &RunMessageLoop, | |
303 &QuitMessageLoop, | |
304 &GetLocalTimeZoneOffset, | |
305 &GetCommandLineArgs, | |
306 &PreLoadFontWin, | |
307 &IsRectTopmost, | |
308 &InvokePrinting, | |
309 &UpdateActivity | |
310 }; | |
311 | |
312 const PPB_Flash_12_2 ppb_flash_12_2 = { | |
313 &SetInstanceAlwaysOnTop, | |
314 &DrawGlyphs, | |
315 &GetProxyForURL, | |
316 &Navigate, | |
317 &RunMessageLoop, | |
318 &QuitMessageLoop, | |
319 &GetLocalTimeZoneOffset, | |
320 &GetCommandLineArgs, | |
321 &PreLoadFontWin, | |
322 &IsRectTopmost, | |
323 &InvokePrinting, | |
324 &UpdateActivity, | |
325 &GetDeviceID | |
326 }; | |
327 | |
328 } // namespace | |
329 | |
330 // static | |
331 const PPB_Flash_11* PPB_Flash_Impl::GetInterface11() { | |
332 return &ppb_flash_11; | |
333 } | 223 } |
334 | 224 |
335 // static | 225 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance, |
336 const PPB_Flash_12_0* PPB_Flash_Impl::GetInterface12_0() { | 226 PP_Bool fullscreen) { |
337 return &ppb_flash_12_0; | 227 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); |
| 228 return PP_TRUE; |
338 } | 229 } |
339 | 230 |
340 // static | 231 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance, |
341 const PPB_Flash_12_1* PPB_Flash_Impl::GetInterface12_1() { | 232 PP_Size* size) { |
342 return &ppb_flash_12_1; | 233 return instance_->GetScreenSize(instance, size); |
343 } | |
344 | |
345 // static | |
346 const PPB_Flash_12_2* PPB_Flash_Impl::GetInterface12_2() { | |
347 return &ppb_flash_12_2; | |
348 } | 234 } |
349 | 235 |
350 } // namespace ppapi | 236 } // namespace ppapi |
351 } // namespace webkit | 237 } // namespace webkit |
OLD | NEW |