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.
4
5 #include "base/logging.h"
6 #include "ppapi/c/pp_array_output.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/private/ppb_flash.h"
9 #include "ppapi/shared_impl/ppapi_globals.h"
10 #include "ppapi/shared_impl/proxy_lock.h"
11 #include "ppapi/shared_impl/var.h"
12 #include "ppapi/thunk/enter.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"
17
18 namespace ppapi {
19 namespace thunk {
20
21 namespace {
22
SetInstanceAlwaysOnTop(PP_Instance instance,PP_Bool on_top)23 void SetInstanceAlwaysOnTop(PP_Instance instance, PP_Bool on_top) {
24 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
25 if (enter.failed())
26 return;
27 enter.functions()->SetInstanceAlwaysOnTop(instance, on_top);
28 }
29
DrawGlyphs(PP_Instance instance,PP_Resource pp_image_data,const PP_BrowserFont_Trusted_Description * font_desc,uint32_t color,const PP_Point * position,const PP_Rect * clip,const float transformation[3][3],PP_Bool allow_subpixel_aa,uint32_t glyph_count,const uint16_t glyph_indices[],const PP_Point glyph_advances[])30 PP_Bool DrawGlyphs(PP_Instance instance,
31 PP_Resource pp_image_data,
32 const PP_BrowserFont_Trusted_Description* 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 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
42 if (enter.failed())
43 return PP_FALSE;
44 return enter.functions()->DrawGlyphs(
45 instance, pp_image_data, font_desc, color, position, clip, transformation,
46 allow_subpixel_aa, glyph_count, glyph_indices, glyph_advances);
47 }
48
GetProxyForURL(PP_Instance instance,const char * url)49 PP_Var GetProxyForURL(PP_Instance instance, const char* url) {
50 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
51 if (enter.failed())
52 return PP_MakeUndefined();
53 return enter.functions()->GetProxyForURL(instance, url);
54 }
55
Navigate(PP_Resource request_id,const char * target,PP_Bool from_user_action)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;
62 {
63 EnterResource<PPB_URLRequestInfo_API> enter(request_id, true);
64 if (enter.failed())
65 return PP_ERROR_BADRESOURCE;
66 instance = enter.resource()->pp_instance();
67 }
68
69 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
70 if (enter.failed())
71 return PP_ERROR_BADARGUMENT;
72 return enter.functions()->Navigate(instance, request_id, target,
73 from_user_action);
74 }
75
RunMessageLoop(PP_Instance instance)76 void RunMessageLoop(PP_Instance instance) {
77 // Deprecated.
78 NOTREACHED();
79 return;
80 }
81
QuitMessageLoop(PP_Instance instance)82 void QuitMessageLoop(PP_Instance instance) {
83 // Deprecated.
84 NOTREACHED();
85 return;
86 }
87
GetLocalTimeZoneOffset(PP_Instance instance,PP_Time t)88 double GetLocalTimeZoneOffset(PP_Instance instance, PP_Time t) {
89 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
90 if (enter.failed())
91 return 0.0;
92 return enter.functions()->GetLocalTimeZoneOffset(instance, t);
93 }
94
GetCommandLineArgs(PP_Module)95 PP_Var GetCommandLineArgs(PP_Module /* pp_module */) {
96 // There's no instance so we have to reach into the globals without thunking.
97 ProxyAutoLock lock;
98 return StringVar::StringToPPVar(PpapiGlobals::Get()->GetCmdLine());
99 }
100
PreLoadFontWin(const void * logfontw)101 void PreLoadFontWin(const void* logfontw) {
102 // There's no instance so we have to reach into the delegate without
103 // thunking.
104 ProxyAutoLock lock;
105 PpapiGlobals::Get()->PreCacheFontForFlash(logfontw);
106 }
107
IsRectTopmost(PP_Instance instance,const PP_Rect * rect)108 PP_Bool IsRectTopmost(PP_Instance instance, const PP_Rect* rect) {
109 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
110 if (enter.failed())
111 return PP_FALSE;
112 return enter.functions()->IsRectTopmost(instance, rect);
113 }
114
InvokePrinting(PP_Instance instance)115 int32_t InvokePrinting(PP_Instance instance) {
116 // This function is no longer supported, use PPB_Flash_Print instead.
117 return PP_ERROR_NOTSUPPORTED;
118 }
119
UpdateActivity(PP_Instance instance)120 void UpdateActivity(PP_Instance instance) {
121 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
122 if (enter.failed())
123 return;
124 enter.functions()->UpdateActivity(instance);
125 }
126
GetDeviceID(PP_Instance instance)127 PP_Var GetDeviceID(PP_Instance instance) {
128 // Deprecated.
129 NOTREACHED();
130 return PP_MakeUndefined();
131 }
132
GetSettingInt(PP_Instance instance,PP_FlashSetting setting)133 int32_t GetSettingInt(PP_Instance instance, PP_FlashSetting setting) {
134 // Deprecated.
135 NOTREACHED();
136 return -1;
137 }
138
GetSetting(PP_Instance instance,PP_FlashSetting setting)139 PP_Var GetSetting(PP_Instance instance, PP_FlashSetting setting) {
140 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
141 if (enter.failed())
142 return PP_MakeUndefined();
143 return enter.functions()->GetSetting(instance, setting);
144 }
145
SetCrashData(PP_Instance instance,PP_FlashCrashKey key,PP_Var value)146 PP_Bool SetCrashData(PP_Instance instance,
147 PP_FlashCrashKey key,
148 PP_Var value) {
149 EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance);
150 if (enter.failed())
151 return PP_FALSE;
152 return enter.functions()->SetCrashData(instance, key, value);
153 }
154
EnumerateVideoCaptureDevices(PP_Instance instance,PP_Resource video_capture,PP_ArrayOutput devices)155 int32_t EnumerateVideoCaptureDevices(PP_Instance instance,
156 PP_Resource video_capture,
157 PP_ArrayOutput devices) {
158 EnterResource<PPB_VideoCapture_API> enter(video_capture, true);
159 if (enter.failed())
160 return enter.retval();
161 return enter.object()->EnumerateDevicesSync(devices);
162 }
163
164 const PPB_Flash_12_4 g_ppb_flash_12_4_thunk = {
165 &SetInstanceAlwaysOnTop,
166 &DrawGlyphs,
167 &GetProxyForURL,
168 &Navigate,
169 &RunMessageLoop,
170 &QuitMessageLoop,
171 &GetLocalTimeZoneOffset,
172 &GetCommandLineArgs,
173 &PreLoadFontWin,
174 &IsRectTopmost,
175 &InvokePrinting,
176 &UpdateActivity,
177 &GetDeviceID,
178 &GetSettingInt,
179 &GetSetting
180 };
181
182 const PPB_Flash_12_5 g_ppb_flash_12_5_thunk = {
183 &SetInstanceAlwaysOnTop,
184 &DrawGlyphs,
185 &GetProxyForURL,
186 &Navigate,
187 &RunMessageLoop,
188 &QuitMessageLoop,
189 &GetLocalTimeZoneOffset,
190 &GetCommandLineArgs,
191 &PreLoadFontWin,
192 &IsRectTopmost,
193 &InvokePrinting,
194 &UpdateActivity,
195 &GetDeviceID,
196 &GetSettingInt,
197 &GetSetting,
198 &SetCrashData
199 };
200
201 const PPB_Flash_12_6 g_ppb_flash_12_6_thunk = {
202 &SetInstanceAlwaysOnTop,
203 &DrawGlyphs,
204 &GetProxyForURL,
205 &Navigate,
206 &RunMessageLoop,
207 &QuitMessageLoop,
208 &GetLocalTimeZoneOffset,
209 &GetCommandLineArgs,
210 &PreLoadFontWin,
211 &IsRectTopmost,
212 &InvokePrinting,
213 &UpdateActivity,
214 &GetDeviceID,
215 &GetSettingInt,
216 &GetSetting,
217 &SetCrashData,
218 &EnumerateVideoCaptureDevices
219 };
220
221 const PPB_Flash_13_0 g_ppb_flash_13_0_thunk = {
222 &SetInstanceAlwaysOnTop,
223 &DrawGlyphs,
224 &GetProxyForURL,
225 &Navigate,
226 &GetLocalTimeZoneOffset,
227 &GetCommandLineArgs,
228 &PreLoadFontWin,
229 &IsRectTopmost,
230 &UpdateActivity,
231 &GetSetting,
232 &SetCrashData,
233 &EnumerateVideoCaptureDevices
234 };
235
236 } // namespace
237
GetPPB_Flash_12_4_Thunk()238 const PPB_Flash_12_4* GetPPB_Flash_12_4_Thunk() {
239 return &g_ppb_flash_12_4_thunk;
240 }
241
GetPPB_Flash_12_5_Thunk()242 const PPB_Flash_12_5* GetPPB_Flash_12_5_Thunk() {
243 return &g_ppb_flash_12_5_thunk;
244 }
245
GetPPB_Flash_12_6_Thunk()246 const PPB_Flash_12_6* GetPPB_Flash_12_6_Thunk() {
247 return &g_ppb_flash_12_6_thunk;
248 }
249
GetPPB_Flash_13_0_Thunk()250 const PPB_Flash_13_0* GetPPB_Flash_13_0_Thunk() {
251 return &g_ppb_flash_13_0_thunk;
252 }
253
254 } // namespace thunk
255 } // namespace ppapi
256