Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / ppapi / thunk / ppb_flash_thunk.cc
blobec8e17e326fb957706c5b67852086551e40e4b3c
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 "ppapi/c/pp_array_output.h"
6 #include "ppapi/c/pp_errors.h"
7 #include "ppapi/c/private/ppb_flash.h"
8 #include "ppapi/shared_impl/ppapi_globals.h"
9 #include "ppapi/shared_impl/proxy_lock.h"
10 #include "ppapi/shared_impl/var.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppb_flash_api.h"
13 #include "ppapi/thunk/ppb_flash_functions_api.h"
14 #include "ppapi/thunk/ppb_instance_api.h"
15 #include "ppapi/thunk/ppb_video_capture_api.h"
16 #include "ppapi/thunk/thunk.h"
18 namespace ppapi {
19 namespace thunk {
21 namespace {
23 void SetInstanceAlwaysOnTop(PP_Instance instance, PP_Bool on_top) {
24 EnterInstance enter(instance);
25 if (enter.failed())
26 return;
27 enter.functions()->GetFlashAPI()->SetInstanceAlwaysOnTop(instance, on_top);
30 PP_Bool DrawGlyphs(PP_Instance instance,
31 PP_Resource pp_image_data,
32 const PP_FontDescription_Dev* font_desc,
33 uint32_t color,
34 const PP_Point* position,
35 const PP_Rect* clip,
36 const float transformation[3][3],
37 PP_Bool allow_subpixel_aa,
38 uint32_t glyph_count,
39 const uint16_t glyph_indices[],
40 const PP_Point glyph_advances[]) {
41 EnterInstance enter(instance);
42 if (enter.failed())
43 return PP_FALSE;
44 return enter.functions()->GetFlashAPI()->DrawGlyphs(
45 instance, pp_image_data, font_desc, color, position, clip, transformation,
46 allow_subpixel_aa, glyph_count, glyph_indices, glyph_advances);
49 PP_Var GetProxyForURL(PP_Instance instance, const char* url) {
50 EnterInstance enter(instance);
51 if (enter.failed())
52 return PP_MakeUndefined();
53 return enter.functions()->GetFlashAPI()->GetProxyForURL(instance, url);
56 int32_t Navigate(PP_Resource request_id,
57 const char* target,
58 PP_Bool from_user_action) {
59 // TODO(brettw): this function should take an instance.
60 // To work around this, use the PP_Instance from the resource.
61 PP_Instance instance;
63 thunk::EnterResource<thunk::PPB_URLRequestInfo_API> enter(request_id, true);
64 if (enter.failed())
65 return PP_ERROR_BADRESOURCE;
66 instance = enter.resource()->pp_instance();
69 EnterInstance enter(instance);
70 if (enter.failed())
71 return PP_ERROR_BADARGUMENT;
72 return enter.functions()->GetFlashAPI()->Navigate(instance, request_id,
73 target, from_user_action);
76 void RunMessageLoop(PP_Instance instance) {
77 EnterInstance enter(instance);
78 if (enter.failed())
79 return;
80 enter.functions()->GetFlashAPI()->RunMessageLoop(instance);
83 void QuitMessageLoop(PP_Instance instance) {
84 EnterInstance enter(instance);
85 if (enter.failed())
86 return;
87 enter.functions()->GetFlashAPI()->QuitMessageLoop(instance);
90 double GetLocalTimeZoneOffset(PP_Instance instance, PP_Time t) {
91 EnterInstance enter(instance);
92 if (enter.failed())
93 return 0.0;
94 return enter.functions()->GetFlashAPI()->GetLocalTimeZoneOffset(instance, t);
97 PP_Var GetCommandLineArgs(PP_Module /* pp_module */) {
98 // There's no instance so we have to reach into the globals without thunking.
99 ProxyAutoLock lock;
100 return StringVar::StringToPPVar(PpapiGlobals::Get()->GetCmdLine());
103 void PreLoadFontWin(const void* logfontw) {
104 // There's no instance so we have to reach into the delegate without
105 // thunking.
106 ProxyAutoLock lock;
107 PpapiGlobals::Get()->PreCacheFontForFlash(logfontw);
110 PP_Bool IsRectTopmost(PP_Instance instance, const PP_Rect* rect) {
111 EnterInstance enter(instance);
112 if (enter.failed())
113 return PP_FALSE;
114 return enter.functions()->GetFlashAPI()->IsRectTopmost(instance, rect);
117 int32_t InvokePrinting(PP_Instance instance) {
118 // This function is no longer supported, use PPB_Flash_Print instead.
119 return PP_ERROR_NOTSUPPORTED;
122 void UpdateActivity(PP_Instance instance) {
123 EnterInstance enter(instance);
124 if (enter.failed())
125 return;
126 enter.functions()->GetFlashAPI()->UpdateActivity(instance);
129 PP_Var GetDeviceID(PP_Instance instance) {
130 EnterInstance enter(instance);
131 if (enter.failed())
132 return PP_MakeUndefined();
133 return enter.functions()->GetFlashAPI()->GetDeviceID(instance);
136 int32_t GetSettingInt(PP_Instance instance, PP_FlashSetting setting) {
137 EnterInstance enter(instance);
138 if (enter.failed())
139 return -1;
140 return enter.functions()->GetFlashAPI()->GetSettingInt(instance, setting);
143 PP_Var GetSetting(PP_Instance instance, PP_FlashSetting setting) {
144 EnterInstance enter(instance);
145 if (enter.failed())
146 return PP_MakeUndefined();
147 return enter.functions()->GetFlashAPI()->GetSetting(instance, setting);
150 PP_Bool SetCrashData(PP_Instance instance,
151 PP_FlashCrashKey key,
152 PP_Var value) {
153 EnterInstance enter(instance);
154 if (enter.failed())
155 return PP_FALSE;
156 return enter.functions()->GetFlashAPI()->SetCrashData(instance, key, value);
159 int32_t EnumerateVideoCaptureDevices(PP_Instance instance,
160 PP_Resource video_capture,
161 PP_ArrayOutput devices) {
162 thunk::EnterResource<thunk::PPB_VideoCapture_API> enter(video_capture, true);
163 if (enter.failed())
164 return enter.retval();
165 return enter.object()->EnumerateDevicesSync(devices);
168 const PPB_Flash_12_0 g_ppb_flash_12_0_thunk = {
169 &SetInstanceAlwaysOnTop,
170 &DrawGlyphs,
171 &GetProxyForURL,
172 &Navigate,
173 &RunMessageLoop,
174 &QuitMessageLoop,
175 &GetLocalTimeZoneOffset,
176 &GetCommandLineArgs,
177 &PreLoadFontWin
180 const PPB_Flash_12_1 g_ppb_flash_12_1_thunk = {
181 &SetInstanceAlwaysOnTop,
182 &DrawGlyphs,
183 &GetProxyForURL,
184 &Navigate,
185 &RunMessageLoop,
186 &QuitMessageLoop,
187 &GetLocalTimeZoneOffset,
188 &GetCommandLineArgs,
189 &PreLoadFontWin,
190 &IsRectTopmost,
191 &InvokePrinting,
192 &UpdateActivity
195 const PPB_Flash_12_2 g_ppb_flash_12_2_thunk = {
196 &SetInstanceAlwaysOnTop,
197 &DrawGlyphs,
198 &GetProxyForURL,
199 &Navigate,
200 &RunMessageLoop,
201 &QuitMessageLoop,
202 &GetLocalTimeZoneOffset,
203 &GetCommandLineArgs,
204 &PreLoadFontWin,
205 &IsRectTopmost,
206 &InvokePrinting,
207 &UpdateActivity,
208 &GetDeviceID
211 const PPB_Flash_12_3 g_ppb_flash_12_3_thunk = {
212 &SetInstanceAlwaysOnTop,
213 &DrawGlyphs,
214 &GetProxyForURL,
215 &Navigate,
216 &RunMessageLoop,
217 &QuitMessageLoop,
218 &GetLocalTimeZoneOffset,
219 &GetCommandLineArgs,
220 &PreLoadFontWin,
221 &IsRectTopmost,
222 &InvokePrinting,
223 &UpdateActivity,
224 &GetDeviceID,
225 &GetSettingInt
228 const PPB_Flash_12_4 g_ppb_flash_12_4_thunk = {
229 &SetInstanceAlwaysOnTop,
230 &DrawGlyphs,
231 &GetProxyForURL,
232 &Navigate,
233 &RunMessageLoop,
234 &QuitMessageLoop,
235 &GetLocalTimeZoneOffset,
236 &GetCommandLineArgs,
237 &PreLoadFontWin,
238 &IsRectTopmost,
239 &InvokePrinting,
240 &UpdateActivity,
241 &GetDeviceID,
242 &GetSettingInt,
243 &GetSetting
246 const PPB_Flash_12_5 g_ppb_flash_12_5_thunk = {
247 &SetInstanceAlwaysOnTop,
248 &DrawGlyphs,
249 &GetProxyForURL,
250 &Navigate,
251 &RunMessageLoop,
252 &QuitMessageLoop,
253 &GetLocalTimeZoneOffset,
254 &GetCommandLineArgs,
255 &PreLoadFontWin,
256 &IsRectTopmost,
257 &InvokePrinting,
258 &UpdateActivity,
259 &GetDeviceID,
260 &GetSettingInt,
261 &GetSetting,
262 &SetCrashData
265 const PPB_Flash_12_6 g_ppb_flash_12_6_thunk = {
266 &SetInstanceAlwaysOnTop,
267 &DrawGlyphs,
268 &GetProxyForURL,
269 &Navigate,
270 &RunMessageLoop,
271 &QuitMessageLoop,
272 &GetLocalTimeZoneOffset,
273 &GetCommandLineArgs,
274 &PreLoadFontWin,
275 &IsRectTopmost,
276 &InvokePrinting,
277 &UpdateActivity,
278 &GetDeviceID,
279 &GetSettingInt,
280 &GetSetting,
281 &SetCrashData,
282 &EnumerateVideoCaptureDevices
285 } // namespace
287 const PPB_Flash_12_0* GetPPB_Flash_12_0_Thunk() {
288 return &g_ppb_flash_12_0_thunk;
291 const PPB_Flash_12_1* GetPPB_Flash_12_1_Thunk() {
292 return &g_ppb_flash_12_1_thunk;
295 const PPB_Flash_12_2* GetPPB_Flash_12_2_Thunk() {
296 return &g_ppb_flash_12_2_thunk;
299 const PPB_Flash_12_3* GetPPB_Flash_12_3_Thunk() {
300 return &g_ppb_flash_12_3_thunk;
303 const PPB_Flash_12_4* GetPPB_Flash_12_4_Thunk() {
304 return &g_ppb_flash_12_4_thunk;
307 const PPB_Flash_12_5* GetPPB_Flash_12_5_Thunk() {
308 return &g_ppb_flash_12_5_thunk;
311 const PPB_Flash_12_6* GetPPB_Flash_12_6_Thunk() {
312 return &g_ppb_flash_12_6_thunk;
315 } // namespace thunk
316 } // namespace ppapi