OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/proxy/ppp_instance_proxy.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "ppapi/c/pp_var.h" |
| 10 #include "ppapi/c/ppp_instance.h" |
| 11 #include "ppapi/proxy/host_dispatcher.h" |
| 12 #include "ppapi/proxy/ppapi_messages.h" |
| 13 #include "ppapi/proxy/ppb_url_loader_proxy.h" |
| 14 |
| 15 namespace pp { |
| 16 namespace proxy { |
| 17 |
| 18 namespace { |
| 19 |
| 20 bool DidCreate(PP_Instance instance, |
| 21 uint32_t argc, |
| 22 const char* argn[], |
| 23 const char* argv[]) { |
| 24 std::vector<std::string> argn_vect; |
| 25 std::vector<std::string> argv_vect; |
| 26 for (uint32_t i = 0; i < argc; i++) { |
| 27 argn_vect.push_back(std::string(argn[i])); |
| 28 argv_vect.push_back(std::string(argv[i])); |
| 29 } |
| 30 |
| 31 bool result = false; |
| 32 HostDispatcher::GetForInstance(instance)->Send( |
| 33 new PpapiMsg_PPPInstance_DidCreate(INTERFACE_ID_PPP_INSTANCE, instance, |
| 34 argn_vect, argv_vect, &result)); |
| 35 return result; |
| 36 } |
| 37 |
| 38 void DidDestroy(PP_Instance instance) { |
| 39 HostDispatcher::GetForInstance(instance)->Send( |
| 40 new PpapiMsg_PPPInstance_DidDestroy(INTERFACE_ID_PPP_INSTANCE, instance)); |
| 41 } |
| 42 |
| 43 void DidChangeView(PP_Instance instance, |
| 44 const PP_Rect* position, |
| 45 const PP_Rect* clip) { |
| 46 HostDispatcher::GetForInstance(instance)->Send( |
| 47 new PpapiMsg_PPPInstance_DidChangeView(INTERFACE_ID_PPP_INSTANCE, |
| 48 instance, *position, *clip)); |
| 49 } |
| 50 |
| 51 void DidChangeFocus(PP_Instance instance, bool has_focus) { |
| 52 HostDispatcher::GetForInstance(instance)->Send( |
| 53 new PpapiMsg_PPPInstance_DidChangeFocus(INTERFACE_ID_PPP_INSTANCE, |
| 54 instance, has_focus)); |
| 55 } |
| 56 |
| 57 bool HandleInputEvent(PP_Instance instance, |
| 58 const PP_InputEvent* event) { |
| 59 bool result = false; |
| 60 HostDispatcher::GetForInstance(instance)->Send( |
| 61 new PpapiMsg_PPPInstance_HandleInputEvent(INTERFACE_ID_PPP_INSTANCE, |
| 62 instance, *event, &result)); |
| 63 return result; |
| 64 } |
| 65 |
| 66 bool HandleDocumentLoad(PP_Instance instance, |
| 67 PP_Resource url_loader) { |
| 68 bool result = false; |
| 69 HostDispatcher::GetForInstance(instance)->Send( |
| 70 new PpapiMsg_PPPInstance_HandleDocumentLoad(INTERFACE_ID_PPP_INSTANCE, |
| 71 instance, url_loader, |
| 72 &result)); |
| 73 return result; |
| 74 } |
| 75 |
| 76 PP_Var GetInstanceObject(PP_Instance instance) { |
| 77 Dispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 78 ReceiveSerializedVarReturnValue result; |
| 79 dispatcher->Send(new PpapiMsg_PPPInstance_GetInstanceObject( |
| 80 instance, INTERFACE_ID_PPP_INSTANCE, &result)); |
| 81 return result.Return(dispatcher); |
| 82 } |
| 83 |
| 84 static const PPP_Instance instance_interface = { |
| 85 &DidCreate, |
| 86 &DidDestroy, |
| 87 &DidChangeView, |
| 88 &DidChangeFocus, |
| 89 &HandleInputEvent, |
| 90 &HandleDocumentLoad, |
| 91 &GetInstanceObject |
| 92 }; |
| 93 |
| 94 } // namespace |
| 95 |
| 96 PPP_Instance_Proxy::PPP_Instance_Proxy(Dispatcher* dispatcher, |
| 97 const void* target_interface) |
| 98 : InterfaceProxy(dispatcher, target_interface) { |
| 99 } |
| 100 |
| 101 PPP_Instance_Proxy::~PPP_Instance_Proxy() { |
| 102 } |
| 103 |
| 104 const void* PPP_Instance_Proxy::GetSourceInterface() const { |
| 105 return &instance_interface; |
| 106 } |
| 107 |
| 108 InterfaceID PPP_Instance_Proxy::GetInterfaceId() const { |
| 109 return INTERFACE_ID_PPP_INSTANCE; |
| 110 } |
| 111 |
| 112 void PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 113 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) |
| 114 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, |
| 115 OnMsgDidCreate) |
| 116 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, |
| 117 OnMsgDidDestroy) |
| 118 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, |
| 119 OnMsgDidChangeView) |
| 120 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, |
| 121 OnMsgDidChangeFocus) |
| 122 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_HandleInputEvent, |
| 123 OnMsgHandleInputEvent) |
| 124 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_HandleDocumentLoad, |
| 125 OnMsgHandleDocumentLoad) |
| 126 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_GetInstanceObject, |
| 127 OnMsgGetInstanceObject) |
| 128 IPC_END_MESSAGE_MAP() |
| 129 } |
| 130 |
| 131 void PPP_Instance_Proxy::OnMsgDidCreate( |
| 132 PP_Instance instance, |
| 133 const std::vector<std::string>& argn, |
| 134 const std::vector<std::string>& argv, |
| 135 bool* result) { |
| 136 *result = false; |
| 137 if (argn.size() != argv.size()) |
| 138 return; |
| 139 |
| 140 // Make sure the arrays always have at least one element so we can take the |
| 141 // address below. |
| 142 std::vector<const char*> argn_array( |
| 143 std::max(static_cast<size_t>(1), argn.size())); |
| 144 std::vector<const char*> argv_array; |
| 145 std::max(static_cast<size_t>(1), argn.size())); |
| 146 for (size_t i = 0; i < argn.size(); i++) { |
| 147 argn_array[i] = argn[i].c_str(); |
| 148 argv_array[i] = argv[i].c_str(); |
| 149 } |
| 150 |
| 151 DCHECK(ppp_instance_target()); |
| 152 *result = ppp_instance_target()->DidCreate(instance, |
| 153 static_cast<uint32_t>(argn.size()), |
| 154 &argn_array[0], &argv_array[0]); |
| 155 DCHECK(*result); |
| 156 } |
| 157 |
| 158 void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { |
| 159 ppp_instance_target()->DidDestroy(instance); |
| 160 } |
| 161 |
| 162 void PPP_Instance_Proxy::OnMsgDidChangeView(PP_Instance instance, |
| 163 const PP_Rect& position, |
| 164 const PP_Rect& clip) { |
| 165 ppp_instance_target()->DidChangeView(instance, &position, &clip); |
| 166 } |
| 167 |
| 168 void PPP_Instance_Proxy::OnMsgDidChangeFocus(PP_Instance instance, |
| 169 bool has_focus) { |
| 170 ppp_instance_target()->DidChangeFocus(instance, has_focus); |
| 171 } |
| 172 |
| 173 void PPP_Instance_Proxy::OnMsgHandleInputEvent(PP_Instance instance, |
| 174 const PP_InputEvent& event, |
| 175 bool* result) { |
| 176 *result = ppp_instance_target()->HandleInputEvent(instance, &event); |
| 177 } |
| 178 |
| 179 void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance, |
| 180 PP_Resource url_loader, |
| 181 bool* result) { |
| 182 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); |
| 183 *result = ppp_instance_target()->HandleDocumentLoad( |
| 184 instance, url_loader); |
| 185 } |
| 186 |
| 187 void PPP_Instance_Proxy::OnMsgGetInstanceObject( |
| 188 PP_Instance instance, |
| 189 SerializedVarReturnValue result) { |
| 190 result.Return(dispatcher(), |
| 191 ppp_instance_target()->GetInstanceObject(instance)); |
| 192 } |
| 193 |
| 194 } // namespace proxy |
| 195 } // namespace pp |
OLD | NEW |