Blink roll 172110:172126
[chromium-blink-merge.git] / ppapi / shared_impl / ppp_instance_combined.cc
blobffde05e7ca7829e799a973106e9c8bd152e6cadf
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/shared_impl/ppp_instance_combined.h"
6 #include "ppapi/shared_impl/proxy_lock.h"
8 namespace ppapi {
10 // static
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);
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);
27 // No supported PPP_Instance version found.
28 return NULL;
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;
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) {}
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);
52 void PPP_Instance_Combined::DidDestroy(PP_Instance instance) {
53 return CallWhileUnlocked(instance_1_1_.DidDestroy, instance);
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);
68 void PPP_Instance_Combined::DidChangeFocus(PP_Instance instance,
69 PP_Bool has_focus) {
70 CallWhileUnlocked(instance_1_1_.DidChangeFocus, instance, has_focus);
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);
79 } // namespace ppapi