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 "ppapi/shared_impl/ppp_instance_combined.h"
6 #include "ppapi/shared_impl/proxy_lock.h"
7
8 namespace ppapi {
9
10 // static
Create(base::Callback<const void * (const char *)> get_interface_func)11 PPP_Instance_Combined* PPP_Instance_Combined::Create(
12 base::Callback<const void*(const char*)> get_interface_func) {
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
PPP_Instance_Combined(const PPP_Instance_1_0 & instance_if)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
PPP_Instance_Combined(const PPP_Instance_1_1 & instance_if)41 PPP_Instance_Combined::PPP_Instance_Combined(
42 const PPP_Instance_1_1& instance_if)
43 : instance_1_1_(instance_if), did_change_view_1_0_(NULL) {}
44
DidCreate(PP_Instance instance,uint32_t argc,const char * argn[],const char * argv[])45 PP_Bool PPP_Instance_Combined::DidCreate(PP_Instance instance,
46 uint32_t argc,
47 const char* argn[],
48 const char* argv[]) {
49 return CallWhileUnlocked(instance_1_1_.DidCreate, instance, argc, argn, argv);
50 }
51
DidDestroy(PP_Instance instance)52 void PPP_Instance_Combined::DidDestroy(PP_Instance instance) {
53 return CallWhileUnlocked(instance_1_1_.DidDestroy, instance);
54 }
55
DidChangeView(PP_Instance instance,PP_Resource view_changed_resource,const struct PP_Rect * position,const struct PP_Rect * clip)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) {
60 if (instance_1_1_.DidChangeView) {
61 CallWhileUnlocked(
62 instance_1_1_.DidChangeView, instance, view_changed_resource);
63 } else {
64 CallWhileUnlocked(did_change_view_1_0_, instance, position, clip);
65 }
66 }
67
DidChangeFocus(PP_Instance instance,PP_Bool has_focus)68 void PPP_Instance_Combined::DidChangeFocus(PP_Instance instance,
69 PP_Bool has_focus) {
70 CallWhileUnlocked(instance_1_1_.DidChangeFocus, instance, has_focus);
71 }
72
HandleDocumentLoad(PP_Instance instance,PP_Resource url_loader)73 PP_Bool PPP_Instance_Combined::HandleDocumentLoad(PP_Instance instance,
74 PP_Resource url_loader) {
75 return CallWhileUnlocked(
76 instance_1_1_.HandleDocumentLoad, instance, url_loader);
77 }
78
79 } // namespace ppapi
80