[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 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 "ppapi/shared_impl/ppp_instance_combined.h" |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 6 | #include "ppapi/shared_impl/proxy_lock.h" |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 7 | |
| 8 | namespace ppapi { |
| 9 | |
[email protected] | ba7cc8c | 2012-06-19 19:03:39 | [diff] [blame] | 10 | // static |
| 11 | PPP_Instance_Combined* PPP_Instance_Combined::Create( |
Jun Cai | 45a6a17 | 2020-02-29 00:37:08 | [diff] [blame] | 12 | base::RepeatingCallback<const void*(const char*)> get_interface_func) { |
[email protected] | ba7cc8c | 2012-06-19 19:03:39 | [diff] [blame] | 13 | // Try 1.1. |
| 14 | const void* ppp_instance = get_interface_func.Run(PPP_INSTANCE_INTERFACE_1_1); |
| 15 | if (ppp_instance) { |
| 16 | const PPP_Instance_1_1* ppp_instance_1_1 = |
| 17 | static_cast<const PPP_Instance_1_1*>(ppp_instance); |
| 18 | return new PPP_Instance_Combined(*ppp_instance_1_1); |
| 19 | } |
| 20 | // Failing that, try 1.0. |
| 21 | ppp_instance = get_interface_func.Run(PPP_INSTANCE_INTERFACE_1_0); |
| 22 | if (ppp_instance) { |
| 23 | const PPP_Instance_1_0* ppp_instance_1_0 = |
| 24 | static_cast<const PPP_Instance_1_0*>(ppp_instance); |
| 25 | return new PPP_Instance_Combined(*ppp_instance_1_0); |
| 26 | } |
| 27 | // No supported PPP_Instance version found. |
| 28 | return NULL; |
| 29 | } |
| 30 | |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 31 | PPP_Instance_Combined::PPP_Instance_Combined( |
| 32 | const PPP_Instance_1_0& instance_if) |
| 33 | : did_change_view_1_0_(instance_if.DidChangeView) { |
| 34 | instance_1_1_.DidCreate = instance_if.DidCreate; |
| 35 | instance_1_1_.DidDestroy = instance_if.DidDestroy; |
| 36 | instance_1_1_.DidChangeView = NULL; |
| 37 | instance_1_1_.DidChangeFocus = instance_if.DidChangeFocus; |
| 38 | instance_1_1_.HandleDocumentLoad = instance_if.HandleDocumentLoad; |
| 39 | } |
| 40 | |
| 41 | PPP_Instance_Combined::PPP_Instance_Combined( |
| 42 | const PPP_Instance_1_1& instance_if) |
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 43 | : instance_1_1_(instance_if), did_change_view_1_0_(NULL) {} |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 44 | |
| 45 | PP_Bool PPP_Instance_Combined::DidCreate(PP_Instance instance, |
| 46 | uint32_t argc, |
| 47 | const char* argn[], |
| 48 | const char* argv[]) { |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 49 | return CallWhileUnlocked(instance_1_1_.DidCreate, instance, argc, argn, argv); |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void PPP_Instance_Combined::DidDestroy(PP_Instance instance) { |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 53 | return CallWhileUnlocked(instance_1_1_.DidDestroy, instance); |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void PPP_Instance_Combined::DidChangeView(PP_Instance instance, |
| 57 | PP_Resource view_changed_resource, |
| 58 | const struct PP_Rect* position, |
| 59 | const struct PP_Rect* clip) { |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 60 | if (instance_1_1_.DidChangeView) { |
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 61 | CallWhileUnlocked( |
| 62 | instance_1_1_.DidChangeView, instance, view_changed_resource); |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 63 | } else { |
| 64 | CallWhileUnlocked(did_change_view_1_0_, instance, position, clip); |
| 65 | } |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void PPP_Instance_Combined::DidChangeFocus(PP_Instance instance, |
| 69 | PP_Bool has_focus) { |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 70 | CallWhileUnlocked(instance_1_1_.DidChangeFocus, instance, has_focus); |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | PP_Bool PPP_Instance_Combined::HandleDocumentLoad(PP_Instance instance, |
| 74 | PP_Resource url_loader) { |
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 75 | return CallWhileUnlocked( |
| 76 | instance_1_1_.HandleDocumentLoad, instance, url_loader); |
[email protected] | ccc5fab | 2012-01-04 13:48:29 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | } // namespace ppapi |