OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppp_instance_proxy.h" | 5 #include "ppapi/proxy/ppp_instance_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ppapi/c/pp_var.h" | 9 #include "ppapi/c/pp_var.h" |
10 #include "ppapi/c/ppp_instance.h" | 10 #include "ppapi/c/ppp_instance.h" |
11 #include "ppapi/proxy/host_dispatcher.h" | 11 #include "ppapi/proxy/host_dispatcher.h" |
12 #include "ppapi/proxy/ppapi_messages.h" | 12 #include "ppapi/proxy/ppapi_messages.h" |
13 #include "ppapi/proxy/ppb_url_loader_proxy.h" | 13 #include "ppapi/proxy/ppb_url_loader_proxy.h" |
14 | 14 |
15 namespace pp { | 15 namespace pp { |
16 namespace proxy { | 16 namespace proxy { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 bool DidCreate(PP_Instance instance, | 20 PP_Bool DidCreate(PP_Instance instance, |
21 uint32_t argc, | 21 uint32_t argc, |
22 const char* argn[], | 22 const char* argn[], |
23 const char* argv[]) { | 23 const char* argv[]) { |
24 std::vector<std::string> argn_vect; | 24 std::vector<std::string> argn_vect; |
25 std::vector<std::string> argv_vect; | 25 std::vector<std::string> argv_vect; |
26 for (uint32_t i = 0; i < argc; i++) { | 26 for (uint32_t i = 0; i < argc; i++) { |
27 argn_vect.push_back(std::string(argn[i])); | 27 argn_vect.push_back(std::string(argn[i])); |
28 argv_vect.push_back(std::string(argv[i])); | 28 argv_vect.push_back(std::string(argv[i])); |
29 } | 29 } |
30 | 30 |
31 bool result = false; | 31 PP_Bool result = PP_FALSE; |
32 HostDispatcher::GetForInstance(instance)->Send( | 32 HostDispatcher::GetForInstance(instance)->Send( |
33 new PpapiMsg_PPPInstance_DidCreate(INTERFACE_ID_PPP_INSTANCE, instance, | 33 new PpapiMsg_PPPInstance_DidCreate(INTERFACE_ID_PPP_INSTANCE, instance, |
34 argn_vect, argv_vect, &result)); | 34 argn_vect, argv_vect, &result)); |
35 return result; | 35 return result; |
36 } | 36 } |
37 | 37 |
38 void DidDestroy(PP_Instance instance) { | 38 void DidDestroy(PP_Instance instance) { |
39 HostDispatcher::GetForInstance(instance)->Send( | 39 HostDispatcher::GetForInstance(instance)->Send( |
40 new PpapiMsg_PPPInstance_DidDestroy(INTERFACE_ID_PPP_INSTANCE, instance)); | 40 new PpapiMsg_PPPInstance_DidDestroy(INTERFACE_ID_PPP_INSTANCE, instance)); |
41 } | 41 } |
42 | 42 |
43 void DidChangeView(PP_Instance instance, | 43 void DidChangeView(PP_Instance instance, |
44 const PP_Rect* position, | 44 const PP_Rect* position, |
45 const PP_Rect* clip) { | 45 const PP_Rect* clip) { |
46 HostDispatcher::GetForInstance(instance)->Send( | 46 HostDispatcher::GetForInstance(instance)->Send( |
47 new PpapiMsg_PPPInstance_DidChangeView(INTERFACE_ID_PPP_INSTANCE, | 47 new PpapiMsg_PPPInstance_DidChangeView(INTERFACE_ID_PPP_INSTANCE, |
48 instance, *position, *clip)); | 48 instance, *position, *clip)); |
49 } | 49 } |
50 | 50 |
51 void DidChangeFocus(PP_Instance instance, bool has_focus) { | 51 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { |
52 HostDispatcher::GetForInstance(instance)->Send( | 52 HostDispatcher::GetForInstance(instance)->Send( |
53 new PpapiMsg_PPPInstance_DidChangeFocus(INTERFACE_ID_PPP_INSTANCE, | 53 new PpapiMsg_PPPInstance_DidChangeFocus(INTERFACE_ID_PPP_INSTANCE, |
54 instance, has_focus)); | 54 instance, has_focus)); |
55 } | 55 } |
56 | 56 |
57 bool HandleInputEvent(PP_Instance instance, | 57 PP_Bool HandleInputEvent(PP_Instance instance, |
58 const PP_InputEvent* event) { | 58 const PP_InputEvent* event) { |
59 bool result = false; | 59 PP_Bool result = PP_FALSE; |
60 HostDispatcher::GetForInstance(instance)->Send( | 60 HostDispatcher::GetForInstance(instance)->Send( |
61 new PpapiMsg_PPPInstance_HandleInputEvent(INTERFACE_ID_PPP_INSTANCE, | 61 new PpapiMsg_PPPInstance_HandleInputEvent(INTERFACE_ID_PPP_INSTANCE, |
62 instance, *event, &result)); | 62 instance, *event, &result)); |
63 return result; | 63 return result; |
64 } | 64 } |
65 | 65 |
66 bool HandleDocumentLoad(PP_Instance instance, | 66 PP_Bool HandleDocumentLoad(PP_Instance instance, |
67 PP_Resource url_loader) { | 67 PP_Resource url_loader) { |
68 bool result = false; | 68 PP_Bool result = PP_FALSE; |
69 HostDispatcher::GetForInstance(instance)->Send( | 69 HostDispatcher::GetForInstance(instance)->Send( |
70 new PpapiMsg_PPPInstance_HandleDocumentLoad(INTERFACE_ID_PPP_INSTANCE, | 70 new PpapiMsg_PPPInstance_HandleDocumentLoad(INTERFACE_ID_PPP_INSTANCE, |
71 instance, url_loader, | 71 instance, url_loader, |
72 &result)); | 72 &result)); |
73 return result; | 73 return result; |
74 } | 74 } |
75 | 75 |
76 PP_Var GetInstanceObject(PP_Instance instance) { | 76 PP_Var GetInstanceObject(PP_Instance instance) { |
77 Dispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 77 Dispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
78 ReceiveSerializedVarReturnValue result; | 78 ReceiveSerializedVarReturnValue result; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 OnMsgHandleDocumentLoad) | 125 OnMsgHandleDocumentLoad) |
126 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_GetInstanceObject, | 126 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_GetInstanceObject, |
127 OnMsgGetInstanceObject) | 127 OnMsgGetInstanceObject) |
128 IPC_END_MESSAGE_MAP() | 128 IPC_END_MESSAGE_MAP() |
129 } | 129 } |
130 | 130 |
131 void PPP_Instance_Proxy::OnMsgDidCreate( | 131 void PPP_Instance_Proxy::OnMsgDidCreate( |
132 PP_Instance instance, | 132 PP_Instance instance, |
133 const std::vector<std::string>& argn, | 133 const std::vector<std::string>& argn, |
134 const std::vector<std::string>& argv, | 134 const std::vector<std::string>& argv, |
135 bool* result) { | 135 PP_Bool* result) { |
136 *result = false; | 136 *result = PP_FALSE; |
137 if (argn.size() != argv.size()) | 137 if (argn.size() != argv.size()) |
138 return; | 138 return; |
139 | 139 |
140 // Make sure the arrays always have at least one element so we can take the | 140 // Make sure the arrays always have at least one element so we can take the |
141 // address below. | 141 // address below. |
142 std::vector<const char*> argn_array( | 142 std::vector<const char*> argn_array( |
143 std::max(static_cast<size_t>(1), argn.size())); | 143 std::max(static_cast<size_t>(1), argn.size())); |
144 std::vector<const char*> argv_array; | 144 std::vector<const char*> argv_array( |
145 std::max(static_cast<size_t>(1), argn.size())); | 145 std::max(static_cast<size_t>(1), argn.size())); |
146 for (size_t i = 0; i < argn.size(); i++) { | 146 for (size_t i = 0; i < argn.size(); i++) { |
147 argn_array[i] = argn[i].c_str(); | 147 argn_array[i] = argn[i].c_str(); |
148 argv_array[i] = argv[i].c_str(); | 148 argv_array[i] = argv[i].c_str(); |
149 } | 149 } |
150 | 150 |
151 DCHECK(ppp_instance_target()); | 151 DCHECK(ppp_instance_target()); |
152 *result = ppp_instance_target()->DidCreate(instance, | 152 *result = ppp_instance_target()->DidCreate(instance, |
153 static_cast<uint32_t>(argn.size()), | 153 static_cast<uint32_t>(argn.size()), |
154 &argn_array[0], &argv_array[0]); | 154 &argn_array[0], &argv_array[0]); |
155 DCHECK(*result); | 155 DCHECK(*result); |
156 } | 156 } |
157 | 157 |
158 void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { | 158 void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { |
159 ppp_instance_target()->DidDestroy(instance); | 159 ppp_instance_target()->DidDestroy(instance); |
160 } | 160 } |
161 | 161 |
162 void PPP_Instance_Proxy::OnMsgDidChangeView(PP_Instance instance, | 162 void PPP_Instance_Proxy::OnMsgDidChangeView(PP_Instance instance, |
163 const PP_Rect& position, | 163 const PP_Rect& position, |
164 const PP_Rect& clip) { | 164 const PP_Rect& clip) { |
165 ppp_instance_target()->DidChangeView(instance, &position, &clip); | 165 ppp_instance_target()->DidChangeView(instance, &position, &clip); |
166 } | 166 } |
167 | 167 |
168 void PPP_Instance_Proxy::OnMsgDidChangeFocus(PP_Instance instance, | 168 void PPP_Instance_Proxy::OnMsgDidChangeFocus(PP_Instance instance, |
169 bool has_focus) { | 169 PP_Bool has_focus) { |
170 ppp_instance_target()->DidChangeFocus(instance, has_focus); | 170 ppp_instance_target()->DidChangeFocus(instance, has_focus); |
171 } | 171 } |
172 | 172 |
173 void PPP_Instance_Proxy::OnMsgHandleInputEvent(PP_Instance instance, | 173 void PPP_Instance_Proxy::OnMsgHandleInputEvent(PP_Instance instance, |
174 const PP_InputEvent& event, | 174 const PP_InputEvent& event, |
175 bool* result) { | 175 PP_Bool* result) { |
176 *result = ppp_instance_target()->HandleInputEvent(instance, &event); | 176 *result = ppp_instance_target()->HandleInputEvent(instance, &event); |
177 } | 177 } |
178 | 178 |
179 void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance, | 179 void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance, |
180 PP_Resource url_loader, | 180 PP_Resource url_loader, |
181 bool* result) { | 181 PP_Bool* result) { |
182 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); | 182 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); |
183 *result = ppp_instance_target()->HandleDocumentLoad( | 183 *result = ppp_instance_target()->HandleDocumentLoad( |
184 instance, url_loader); | 184 instance, url_loader); |
185 } | 185 } |
186 | 186 |
187 void PPP_Instance_Proxy::OnMsgGetInstanceObject( | 187 void PPP_Instance_Proxy::OnMsgGetInstanceObject( |
188 PP_Instance instance, | 188 PP_Instance instance, |
189 SerializedVarReturnValue result) { | 189 SerializedVarReturnValue result) { |
190 result.Return(dispatcher(), | 190 result.Return(dispatcher(), |
191 ppp_instance_target()->GetInstanceObject(instance)); | 191 ppp_instance_target()->GetInstanceObject(instance)); |
192 } | 192 } |
193 | 193 |
194 } // namespace proxy | 194 } // namespace proxy |
195 } // namespace pp | 195 } // namespace pp |
OLD | NEW |