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

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_impl.cc

Issue 10091003: Convert flash to thunk (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months 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) 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
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::EnterResource;
yzshen1 2012/04/18 17:57:22 This is not needed anymore.
39 using ppapi::thunk::EnterResourceNoLock;
39 using ppapi::thunk::PPB_ImageData_API; 40 using ppapi::thunk::PPB_ImageData_API;
40 using ppapi::thunk::PPB_URLRequestInfo_API; 41 using ppapi::thunk::PPB_URLRequestInfo_API;
41 42
42 namespace webkit { 43 namespace webkit {
43 namespace ppapi { 44 namespace ppapi {
44 45
45 namespace { 46 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance)
46 47 : 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 } 48 }
53 49
50 PPB_Flash_Impl::~PPB_Flash_Impl() {
51 }
54 52
55 PP_Bool DrawGlyphs(PP_Instance, 53 void PPB_Flash_Impl::SetInstanceAlwaysOnTop(PP_Instance instance,
56 PP_Resource pp_image_data, 54 PP_Bool on_top) {
57 const PP_FontDescription_Dev* font_desc, 55 instance_->set_always_on_top(PP_ToBool(on_top));
58 uint32_t color, 56 }
59 const PP_Point* position, 57
60 const PP_Rect* clip, 58 PP_Bool PPB_Flash_Impl::DrawGlyphs(PP_Instance instance,
61 const float transformation[3][3], 59 PP_Resource pp_image_data,
62 PP_Bool allow_subpixel_aa, 60 const PP_FontDescription_Dev* font_desc,
63 uint32_t glyph_count, 61 uint32_t color,
64 const uint16_t glyph_indices[], 62 const PP_Point* position,
65 const PP_Point glyph_advances[]) { 63 const PP_Rect* clip,
66 EnterResource<PPB_ImageData_API> enter(pp_image_data, true); 64 const float transformation[3][3],
65 PP_Bool allow_subpixel_aa,
66 uint32_t glyph_count,
67 const uint16_t glyph_indices[],
68 const PP_Point glyph_advances[]) {
69 EnterResourceNoLock<PPB_ImageData_API> enter(pp_image_data, true);
67 if (enter.failed()) 70 if (enter.failed())
68 return PP_FALSE; 71 return PP_FALSE;
69 PPB_ImageData_Impl* image_resource = 72 PPB_ImageData_Impl* image_resource =
70 static_cast<PPB_ImageData_Impl*>(enter.object()); 73 static_cast<PPB_ImageData_Impl*>(enter.object());
71 74
72 ImageDataAutoMapper mapper(image_resource); 75 ImageDataAutoMapper mapper(image_resource);
73 if (!mapper.is_valid()) 76 if (!mapper.is_valid())
74 return PP_FALSE; 77 return PP_FALSE;
75 78
76 // Set up the typeface. 79 // Set up the typeface.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 sk_positions[i].set(x, y); 140 sk_positions[i].set(x, y);
138 x += SkFloatToScalar(glyph_advances[i].x); 141 x += SkFloatToScalar(glyph_advances[i].x);
139 y += SkFloatToScalar(glyph_advances[i].y); 142 y += SkFloatToScalar(glyph_advances[i].y);
140 } 143 }
141 144
142 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint); 145 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint);
143 146
144 return PP_TRUE; 147 return PP_TRUE;
145 } 148 }
146 149
147 PP_Bool DrawGlyphs11(PP_Instance instance, 150 PP_Var PPB_Flash_Impl::GetProxyForURL(PP_Instance instance,
148 PP_Resource pp_image_data, 151 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); 152 GURL gurl(url);
168 if (!gurl.is_valid()) 153 if (!gurl.is_valid())
169 return PP_MakeUndefined(); 154 return PP_MakeUndefined();
170 155
171 std::string proxy_host = instance->delegate()->ResolveProxy(gurl); 156 std::string proxy_host = instance_->delegate()->ResolveProxy(gurl);
172 if (proxy_host.empty()) 157 if (proxy_host.empty())
173 return PP_MakeUndefined(); // No proxy. 158 return PP_MakeUndefined(); // No proxy.
174 return StringVar::StringToPPVar(proxy_host); 159 return StringVar::StringToPPVar(proxy_host);
175 } 160 }
176 161
177 int32_t Navigate(PP_Resource request_id, 162 int32_t PPB_Flash_Impl::Navigate(PP_Instance instance,
178 const char* target, 163 PP_Resource request_info,
179 PP_Bool from_user_action) { 164 const char* target,
180 EnterResource<PPB_URLRequestInfo_API> enter(request_id, true); 165 PP_Bool from_user_action) {
166 EnterResourceNoLock<PPB_URLRequestInfo_API> enter(request_info, true);
181 if (enter.failed()) 167 if (enter.failed())
182 return PP_ERROR_BADRESOURCE; 168 return PP_ERROR_BADRESOURCE;
183 PPB_URLRequestInfo_Impl* request = 169 PPB_URLRequestInfo_Impl* request =
184 static_cast<PPB_URLRequestInfo_Impl*>(enter.object()); 170 static_cast<PPB_URLRequestInfo_Impl*>(enter.object());
185 171
186 if (!target) 172 if (!target)
187 return PP_ERROR_BADARGUMENT; 173 return PP_ERROR_BADARGUMENT;
188 174 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 } 175 }
195 176
196 int32_t Navigate11(PP_Resource request_id, 177 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()); 178 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
204 MessageLoop::current()->Run(); 179 MessageLoop::current()->Run();
205 } 180 }
206 181
207 void QuitMessageLoop(PP_Instance instance) { 182 void PPB_Flash_Impl::QuitMessageLoop(PP_Instance instance) {
208 MessageLoop::current()->QuitNow(); 183 MessageLoop::current()->QuitNow();
209 } 184 }
210 185
211 double GetLocalTimeZoneOffset(PP_Instance pp_instance, PP_Time t) { 186 double PPB_Flash_Impl::GetLocalTimeZoneOffset(PP_Instance instance,
212 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 187 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 188 // 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 189 // 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 190 // 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 191 // 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. 192 // special handling, we just need to give it some nonzero value.
221 if (t == 0.0) 193 if (t == 0.0)
222 t = 0.0000000001; 194 t = 0.0000000001;
223 195
224 // We can't do the conversion here because on Linux, the localtime calls 196 // We can't do the conversion here because on Linux, the localtime calls
225 // require filesystem access prohibited by the sandbox. 197 // require filesystem access prohibited by the sandbox.
226 return instance->delegate()->GetLocalTimeZoneOffset(PPTimeToTime(t)); 198 return instance_->delegate()->GetLocalTimeZoneOffset(PPTimeToTime(t));
227 } 199 }
228 200
229 PP_Var GetCommandLineArgs(PP_Module pp_module) { 201 PP_Bool PPB_Flash_Impl::IsRectTopmost(PP_Instance instance,
230 PluginModule* module = HostGlobals::Get()->GetModule(pp_module); 202 const PP_Rect* rect) {
231 if (!module) 203 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, 204 gfx::Rect(rect->point.x, rect->point.y,
252 rect->size.width, rect->size.height))); 205 rect->size.width, rect->size.height)));
253 } 206 }
254 207
255 int32_t InvokePrinting(PP_Instance pp_instance) { 208 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. 209 // TODO(viettrungluu): Implement me.
261
262 return PP_ERROR_NOTSUPPORTED; 210 return PP_ERROR_NOTSUPPORTED;
263 } 211 }
264 212
265 void UpdateActivity(PP_Instance pp_instance) { 213 void PPB_Flash_Impl::UpdateActivity(PP_Instance instance) {
266 // TODO(viettrungluu): Implement me. 214 // TODO(viettrungluu): Implement me.
267 } 215 }
268 216
269 PP_Var GetDeviceID(PP_Instance pp_instance) { 217 PP_Var PPB_Flash_Impl::GetDeviceID(PP_Instance instance) {
270 // TODO(brettw) implement me. 218 // TODO(brettw) implement me.
271 return PP_MakeUndefined(); 219 return PP_MakeUndefined();
272 } 220 }
273 221
274 const PPB_Flash_11 ppb_flash_11 = { 222 PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) {
275 &SetInstanceAlwaysOnTop, 223 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 } 224 }
334 225
335 // static 226 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance,
336 const PPB_Flash_12_0* PPB_Flash_Impl::GetInterface12_0() { 227 PP_Bool fullscreen) {
337 return &ppb_flash_12_0; 228 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true);
229 return PP_TRUE;
338 } 230 }
339 231
340 // static 232 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance,
341 const PPB_Flash_12_1* PPB_Flash_Impl::GetInterface12_1() { 233 PP_Size* size) {
342 return &ppb_flash_12_1; 234 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 } 235 }
349 236
350 } // namespace ppapi 237 } // namespace ppapi
351 } // namespace webkit 238 } // namespace webkit
OLDNEW
« webkit/plugins/ppapi/ppb_flash_impl.h ('K') | « webkit/plugins/ppapi/ppb_flash_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698