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/cpp/private/flash.h"
9 #include "ppapi/c/pp_bool.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/cpp/dev/device_ref_dev.h"
12 #include "ppapi/cpp/dev/video_capture_dev.h"
13 #include "ppapi/cpp/image_data.h"
14 #include "ppapi/cpp/instance_handle.h"
15 #include "ppapi/cpp/module.h"
16 #include "ppapi/cpp/module_impl.h"
17 #include "ppapi/cpp/point.h"
18 #include "ppapi/cpp/rect.h"
19 #include "ppapi/cpp/trusted/browser_font_trusted.h"
20 #include "ppapi/cpp/url_request_info.h"
21 #include "ppapi/cpp/var.h"
22 #include "ppapi/c/private/ppb_flash.h"
23 #include "ppapi/c/private/ppb_flash_print.h"
29 template <> const char* interface_name
<PPB_Flash_13_0
>() {
30 return PPB_FLASH_INTERFACE_13_0
;
33 template <> const char* interface_name
<PPB_Flash_12_6
>() {
34 return PPB_FLASH_INTERFACE_12_6
;
37 template <> const char* interface_name
<PPB_Flash_12_5
>() {
38 return PPB_FLASH_INTERFACE_12_5
;
41 template <> const char* interface_name
<PPB_Flash_12_4
>() {
42 return PPB_FLASH_INTERFACE_12_4
;
45 template <> const char* interface_name
<PPB_Flash_Print_1_0
>() {
46 return PPB_FLASH_PRINT_INTERFACE_1_0
;
49 // The combined Flash interface is all Flash v12.* interfaces. All v12
50 // interfaces just append one or more functions to the previous one, so we can
51 // have this meta one at the most recent version. Function pointers will be
52 // null if they're not supported on the current Chrome version.
53 bool initialized_combined_interface
= false;
54 PPB_Flash_12_6 flash_12_combined_interface
;
56 // Makes sure that the most recent version is loaded into the combined
57 // interface struct above. Any unsupported functions will be NULL. If there
58 // is no Flash interface supported, all functions will be NULL.
59 void InitializeCombinedInterface() {
60 if (initialized_combined_interface
)
62 if (has_interface
<PPB_Flash_12_6
>()) {
63 memcpy(&flash_12_combined_interface
, get_interface
<PPB_Flash_12_6
>(),
64 sizeof(PPB_Flash_12_6
));
65 } else if (has_interface
<PPB_Flash_12_5
>()) {
66 memcpy(&flash_12_combined_interface
, get_interface
<PPB_Flash_12_5
>(),
67 sizeof(PPB_Flash_12_5
));
68 } else if (has_interface
<PPB_Flash_12_4
>()) {
69 memcpy(&flash_12_combined_interface
, get_interface
<PPB_Flash_12_4
>(),
70 sizeof(PPB_Flash_12_4
));
72 initialized_combined_interface
= true;
80 bool Flash::IsAvailable() {
81 return has_interface
<PPB_Flash_13_0
>() ||
82 has_interface
<PPB_Flash_12_6
>() ||
83 has_interface
<PPB_Flash_12_5
>() ||
84 has_interface
<PPB_Flash_12_4
>();
88 void Flash::SetInstanceAlwaysOnTop(const InstanceHandle
& instance
,
90 InitializeCombinedInterface();
91 if (has_interface
<PPB_Flash_13_0
>()) {
92 get_interface
<PPB_Flash_13_0
>()->SetInstanceAlwaysOnTop(
93 instance
.pp_instance(), PP_FromBool(on_top
));
94 } else if (flash_12_combined_interface
.SetInstanceAlwaysOnTop
) {
95 flash_12_combined_interface
.SetInstanceAlwaysOnTop(
96 instance
.pp_instance(), PP_FromBool(on_top
));
101 bool Flash::DrawGlyphs(const InstanceHandle
& instance
,
103 const BrowserFontDescription
& font_desc
,
105 const Point
& position
,
107 const float transformation
[3][3],
108 bool allow_subpixel_aa
,
109 uint32_t glyph_count
,
110 const uint16_t glyph_indices
[],
111 const PP_Point glyph_advances
[]) {
112 InitializeCombinedInterface();
113 if (has_interface
<PPB_Flash_13_0
>()) {
114 return PP_ToBool(get_interface
<PPB_Flash_13_0
>()->DrawGlyphs(
115 instance
.pp_instance(),
116 image
->pp_resource(),
117 &font_desc
.pp_font_description(),
119 &position
.pp_point(),
122 PP_FromBool(allow_subpixel_aa
),
127 if (flash_12_combined_interface
.DrawGlyphs
) {
128 return PP_ToBool(flash_12_combined_interface
.DrawGlyphs(
129 instance
.pp_instance(),
130 image
->pp_resource(),
131 &font_desc
.pp_font_description(),
133 &position
.pp_point(),
136 PP_FromBool(allow_subpixel_aa
),
145 Var
Flash::GetProxyForURL(const InstanceHandle
& instance
,
146 const std::string
& url
) {
147 InitializeCombinedInterface();
148 if (has_interface
<PPB_Flash_13_0
>()) {
149 return Var(PASS_REF
, get_interface
<PPB_Flash_13_0
>()->GetProxyForURL(
150 instance
.pp_instance(), url
.c_str()));
152 if (flash_12_combined_interface
.GetProxyForURL
) {
153 return Var(PASS_REF
, flash_12_combined_interface
.GetProxyForURL(
154 instance
.pp_instance(), url
.c_str()));
160 int32_t Flash::Navigate(const URLRequestInfo
& request_info
,
161 const std::string
& target
,
162 bool from_user_action
) {
163 InitializeCombinedInterface();
164 if (has_interface
<PPB_Flash_13_0
>()) {
165 return get_interface
<PPB_Flash_13_0
>()->Navigate(
166 request_info
.pp_resource(),
168 PP_FromBool(from_user_action
));
170 if (flash_12_combined_interface
.Navigate
) {
171 return flash_12_combined_interface
.Navigate(
172 request_info
.pp_resource(),
174 PP_FromBool(from_user_action
));
176 return PP_ERROR_FAILED
;
180 double Flash::GetLocalTimeZoneOffset(const InstanceHandle
& instance
,
182 InitializeCombinedInterface();
183 if (has_interface
<PPB_Flash_13_0
>()) {
184 return get_interface
<PPB_Flash_13_0
>()->GetLocalTimeZoneOffset(
185 instance
.pp_instance(), t
);
187 if (flash_12_combined_interface
.GetLocalTimeZoneOffset
) {
188 return flash_12_combined_interface
.GetLocalTimeZoneOffset(
189 instance
.pp_instance(), t
);
195 Var
Flash::GetCommandLineArgs(Module
* module
) {
196 InitializeCombinedInterface();
197 if (has_interface
<PPB_Flash_13_0
>()) {
198 return Var(PASS_REF
, get_interface
<PPB_Flash_13_0
>()->GetCommandLineArgs(
199 module
->pp_module()));
201 if (flash_12_combined_interface
.GetCommandLineArgs
) {
204 flash_12_combined_interface
.GetCommandLineArgs(module
->pp_module()));
210 void Flash::PreloadFontWin(const void* logfontw
) {
211 InitializeCombinedInterface();
212 if (has_interface
<PPB_Flash_13_0
>())
213 return get_interface
<PPB_Flash_13_0
>()->PreloadFontWin(logfontw
);
214 if (flash_12_combined_interface
.PreloadFontWin
)
215 return flash_12_combined_interface
.PreloadFontWin(logfontw
);
219 bool Flash::IsRectTopmost(const InstanceHandle
& instance
, const Rect
& rect
) {
220 InitializeCombinedInterface();
221 if (has_interface
<PPB_Flash_13_0
>()) {
222 return PP_ToBool(get_interface
<PPB_Flash_13_0
>()->IsRectTopmost(
223 instance
.pp_instance(), &rect
.pp_rect()));
225 if (flash_12_combined_interface
.IsRectTopmost
) {
226 return PP_ToBool(flash_12_combined_interface
.IsRectTopmost(
227 instance
.pp_instance(), &rect
.pp_rect()));
233 void Flash::UpdateActivity(const InstanceHandle
& instance
) {
234 InitializeCombinedInterface();
235 if (has_interface
<PPB_Flash_13_0
>())
236 get_interface
<PPB_Flash_13_0
>()->UpdateActivity(instance
.pp_instance());
237 else if (flash_12_combined_interface
.UpdateActivity
)
238 flash_12_combined_interface
.UpdateActivity(instance
.pp_instance());
242 Var
Flash::GetSetting(const InstanceHandle
& instance
, PP_FlashSetting setting
) {
243 InitializeCombinedInterface();
244 if (has_interface
<PPB_Flash_13_0
>()) {
245 return Var(PASS_REF
, get_interface
<PPB_Flash_13_0
>()->GetSetting(
246 instance
.pp_instance(), setting
));
248 if (flash_12_combined_interface
.GetSetting
) {
250 flash_12_combined_interface
.GetSetting(instance
.pp_instance(),
258 bool Flash::SetCrashData(const InstanceHandle
& instance
,
259 PP_FlashCrashKey key
,
260 const pp::Var
& value
) {
261 InitializeCombinedInterface();
262 if (has_interface
<PPB_Flash_13_0
>()) {
263 return PP_ToBool(get_interface
<PPB_Flash_13_0
>()->SetCrashData(
264 instance
.pp_instance(), key
, value
.pp_var()));
266 if (flash_12_combined_interface
.SetCrashData
) {
268 flash_12_combined_interface
.SetCrashData(instance
.pp_instance(),
269 key
, value
.pp_var()));
275 int32_t Flash::EnumerateVideoCaptureDevices(
276 const InstanceHandle
& instance
,
277 const VideoCapture_Dev
& video_capture
,
278 std::vector
<DeviceRef_Dev
>* devices_out
) {
279 InitializeCombinedInterface();
280 if (has_interface
<PPB_Flash_13_0
>()) {
281 ResourceArrayOutputAdapter
<DeviceRef_Dev
> adapter(devices_out
);
282 return get_interface
<PPB_Flash_13_0
>()->EnumerateVideoCaptureDevices(
283 instance
.pp_instance(),
284 video_capture
.pp_resource(),
285 adapter
.pp_array_output());
287 if (flash_12_combined_interface
.EnumerateVideoCaptureDevices
) {
288 ResourceArrayOutputAdapter
<DeviceRef_Dev
> adapter(devices_out
);
289 return flash_12_combined_interface
.EnumerateVideoCaptureDevices(
290 instance
.pp_instance(),
291 video_capture
.pp_resource(),
292 adapter
.pp_array_output());
294 return PP_ERROR_FAILED
;
298 bool Flash::InvokePrinting(const InstanceHandle
& instance
) {
299 if (has_interface
<PPB_Flash_Print_1_0
>()) {
300 get_interface
<PPB_Flash_Print_1_0
>()->InvokePrinting(
301 instance
.pp_instance());