Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: ppapi/proxy/ppp_instance_proxy.cc

Issue 6286070: Remove all uses of the global Dispatcher Get function. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 static const PPP_Instance instance_interface = { 93 static const PPP_Instance instance_interface = {
94 &DidCreate, 94 &DidCreate,
95 &DidDestroy, 95 &DidDestroy,
96 &DidChangeView, 96 &DidChangeView,
97 &DidChangeFocus, 97 &DidChangeFocus,
98 &HandleInputEvent, 98 &HandleInputEvent,
99 &HandleDocumentLoad, 99 &HandleDocumentLoad,
100 &GetInstanceObject 100 &GetInstanceObject
101 }; 101 };
102 102
103 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher,
104 const void* target_interface) {
105 return new PPP_Instance_Proxy(dispatcher, target_interface);
106 }
107
103 } // namespace 108 } // namespace
104 109
105 PPP_Instance_Proxy::PPP_Instance_Proxy(Dispatcher* dispatcher, 110 PPP_Instance_Proxy::PPP_Instance_Proxy(Dispatcher* dispatcher,
106 const void* target_interface) 111 const void* target_interface)
107 : InterfaceProxy(dispatcher, target_interface) { 112 : InterfaceProxy(dispatcher, target_interface) {
108 } 113 }
109 114
110 PPP_Instance_Proxy::~PPP_Instance_Proxy() { 115 PPP_Instance_Proxy::~PPP_Instance_Proxy() {
111 } 116 }
112 117
113 const void* PPP_Instance_Proxy::GetSourceInterface() const { 118 // static
114 return &instance_interface; 119 const InterfaceProxy::Info* PPP_Instance_Proxy::GetInfo() {
115 } 120 static const Info info = {
116 121 &instance_interface,
117 InterfaceID PPP_Instance_Proxy::GetInterfaceId() const { 122 PPP_INSTANCE_INTERFACE,
118 return INTERFACE_ID_PPP_INSTANCE; 123 INTERFACE_ID_PPP_INSTANCE,
124 false,
125 &CreateInstanceProxy,
126 };
127 return &info;
119 } 128 }
120 129
121 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { 130 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
122 bool handled = true; 131 bool handled = true;
123 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) 132 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg)
124 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, 133 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate,
125 OnMsgDidCreate) 134 OnMsgDidCreate)
126 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, 135 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy,
127 OnMsgDidDestroy) 136 OnMsgDidDestroy)
128 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, 137 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView,
(...skipping 13 matching lines...) Expand all
142 151
143 void PPP_Instance_Proxy::OnMsgDidCreate( 152 void PPP_Instance_Proxy::OnMsgDidCreate(
144 PP_Instance instance, 153 PP_Instance instance,
145 const std::vector<std::string>& argn, 154 const std::vector<std::string>& argn,
146 const std::vector<std::string>& argv, 155 const std::vector<std::string>& argv,
147 PP_Bool* result) { 156 PP_Bool* result) {
148 *result = PP_FALSE; 157 *result = PP_FALSE;
149 if (argn.size() != argv.size()) 158 if (argn.size() != argv.size())
150 return; 159 return;
151 160
152 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 161 // Set up the routing associating this new instance with the dispatcher we
153 if (!dispatcher) 162 // just got the message from. This must be done before calling into the
154 return; 163 // plugin so it can in turn call PPAPI functions.
155 dispatcher->DidCreateInstance(instance); 164 PluginDispatcher* plugin_dispatcher =
165 static_cast<PluginDispatcher*>(dispatcher());
166 PluginDispatcher::SetForInstance(instance, plugin_dispatcher);
167 plugin_dispatcher->DidCreateInstance(instance);
piman 2011/02/07 21:29:22 Maybe we can combine SetForInstance and DidCreateI
brettw 2011/02/08 00:28:04 Good idea.
156 168
157 // Make sure the arrays always have at least one element so we can take the 169 // Make sure the arrays always have at least one element so we can take the
158 // address below. 170 // address below.
159 std::vector<const char*> argn_array( 171 std::vector<const char*> argn_array(
160 std::max(static_cast<size_t>(1), argn.size())); 172 std::max(static_cast<size_t>(1), argn.size()));
161 std::vector<const char*> argv_array( 173 std::vector<const char*> argv_array(
162 std::max(static_cast<size_t>(1), argn.size())); 174 std::max(static_cast<size_t>(1), argn.size()));
163 for (size_t i = 0; i < argn.size(); i++) { 175 for (size_t i = 0; i < argn.size(); i++) {
164 argn_array[i] = argn[i].c_str(); 176 argn_array[i] = argn[i].c_str();
165 argv_array[i] = argv[i].c_str(); 177 argv_array[i] = argv[i].c_str();
166 } 178 }
167 179
168 DCHECK(ppp_instance_target()); 180 DCHECK(ppp_instance_target());
169 *result = ppp_instance_target()->DidCreate(instance, 181 *result = ppp_instance_target()->DidCreate(instance,
170 static_cast<uint32_t>(argn.size()), 182 static_cast<uint32_t>(argn.size()),
171 &argn_array[0], &argv_array[0]); 183 &argn_array[0], &argv_array[0]);
172 DCHECK(*result); 184 if (!*result) {
185 // In the failure to create case, this plugin instance will be torn down
186 // without further notification, so we also need to undo the routing.
187 PluginDispatcher::RemoveForInstance(instance);
188 }
173 } 189 }
174 190
175 void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { 191 void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) {
176 ppp_instance_target()->DidDestroy(instance); 192 ppp_instance_target()->DidDestroy(instance);
177 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 193 PluginDispatcher::RemoveForInstance(instance);
178 if (!dispatcher) 194 static_cast<PluginDispatcher*>(dispatcher())->DidDestroyInstance(instance);
179 return;
180
181 dispatcher->DidDestroyInstance(instance);
182 } 195 }
183 196
184 void PPP_Instance_Proxy::OnMsgDidChangeView(PP_Instance instance, 197 void PPP_Instance_Proxy::OnMsgDidChangeView(PP_Instance instance,
185 const PP_Rect& position, 198 const PP_Rect& position,
186 const PP_Rect& clip) { 199 const PP_Rect& clip) {
187 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 200 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
188 if (!dispatcher) 201 if (!dispatcher)
189 return; 202 return;
190 InstanceData* data = dispatcher->GetInstanceData(instance); 203 InstanceData* data = dispatcher->GetInstanceData(instance);
191 if (!data) 204 if (!data)
(...skipping 24 matching lines...) Expand all
216 229
217 void PPP_Instance_Proxy::OnMsgGetInstanceObject( 230 void PPP_Instance_Proxy::OnMsgGetInstanceObject(
218 PP_Instance instance, 231 PP_Instance instance,
219 SerializedVarReturnValue result) { 232 SerializedVarReturnValue result) {
220 result.Return(dispatcher(), 233 result.Return(dispatcher(),
221 ppp_instance_target()->GetInstanceObject(instance)); 234 ppp_instance_target()->GetInstanceObject(instance));
222 } 235 }
223 236
224 } // namespace proxy 237 } // namespace proxy
225 } // namespace pp 238 } // namespace pp
OLDNEW
« ppapi/proxy/ppapi_proxy_test.cc ('K') | « ppapi/proxy/ppp_instance_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698