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

Side by Side Diff: ppapi/proxy/host_dispatcher.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
« no previous file with comments | « ppapi/proxy/host_dispatcher.h ('k') | ppapi/proxy/host_dispatcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/host_dispatcher.h" 5 #include "ppapi/proxy/host_dispatcher.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ppapi/c/dev/ppb_var_deprecated.h" 10 #include "ppapi/c/dev/ppb_var_deprecated.h"
(...skipping 12 matching lines...) Expand all
23 23
24 HostDispatcher::HostDispatcher(base::ProcessHandle remote_process_handle, 24 HostDispatcher::HostDispatcher(base::ProcessHandle remote_process_handle,
25 PP_Module module, 25 PP_Module module,
26 GetInterfaceFunc local_get_interface) 26 GetInterfaceFunc local_get_interface)
27 : Dispatcher(remote_process_handle, local_get_interface) { 27 : Dispatcher(remote_process_handle, local_get_interface) {
28 set_pp_module(module); 28 set_pp_module(module);
29 const PPB_Var_Deprecated* var_interface = 29 const PPB_Var_Deprecated* var_interface =
30 static_cast<const PPB_Var_Deprecated*>( 30 static_cast<const PPB_Var_Deprecated*>(
31 local_get_interface(PPB_VAR_DEPRECATED_INTERFACE)); 31 local_get_interface(PPB_VAR_DEPRECATED_INTERFACE));
32 SetSerializationRules(new HostVarSerializationRules(var_interface, module)); 32 SetSerializationRules(new HostVarSerializationRules(var_interface, module));
33
34 memset(plugin_interface_support_, 0,
35 sizeof(PluginInterfaceSupport) * INTERFACE_ID_COUNT);
33 } 36 }
34 37
35 HostDispatcher::~HostDispatcher() { 38 HostDispatcher::~HostDispatcher() {
36 // Notify the plugin that it should exit. 39 // Notify the plugin that it should exit.
37 Send(new PpapiMsg_Shutdown()); 40 Send(new PpapiMsg_Shutdown());
38 } 41 }
39 42
40 bool HostDispatcher::InitializeModule() { 43 bool HostDispatcher::InitializeModule() {
41 bool init_result = false; 44 bool init_result = false;
42 Send(new PpapiMsg_InitializeModule(pp_module(), &init_result)); 45 Send(new PpapiMsg_InitializeModule(pp_module(), &init_result));
(...skipping 26 matching lines...) Expand all
69 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( 72 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find(
70 instance); 73 instance);
71 if (found != g_instance_to_dispatcher->end()) 74 if (found != g_instance_to_dispatcher->end())
72 g_instance_to_dispatcher->erase(found); 75 g_instance_to_dispatcher->erase(found);
73 } 76 }
74 77
75 bool HostDispatcher::IsPlugin() const { 78 bool HostDispatcher::IsPlugin() const {
76 return false; 79 return false;
77 } 80 }
78 81
82 bool HostDispatcher::OnMessageReceived(const IPC::Message& msg) {
83 // Handle common control messages.
84 if (Dispatcher::OnMessageReceived(msg))
85 return true;
86
87 if (msg.routing_id() <= 0 && msg.routing_id() >= INTERFACE_ID_COUNT) {
88 NOTREACHED();
89 // TODO(brettw): kill the plugin if it starts sending invalid messages?
90 return true;
91 }
92
93 InterfaceProxy* proxy = target_proxies_[msg.routing_id()].get();
94 if (!proxy) {
95 // Autocreate any proxy objects to handle requests from the plugin. Since
96 // we always support all known PPB_* interfaces (modulo the trusted bit),
97 // there's very little checking necessary.
98 const InterfaceProxy::Info* info = GetPPBInterfaceInfo(
99 static_cast<InterfaceID>(msg.routing_id()));
100 if (!info ||
101 (info->is_trusted && disallow_trusted_interfaces()))
102 return true;
103
104 const void* local_interface = GetLocalInterface(info->name);
105 if (!local_interface) {
106 // This should always succeed since the browser should support the stuff
107 // the proxy does. If this happens, something is out of sync.
108 NOTREACHED();
109 return true;
110 }
111
112 proxy = info->create_proxy(this, local_interface);
113 target_proxies_[info->id].reset(proxy);
114 }
115
116 return proxy->OnMessageReceived(msg);
117 }
118
119 const void* HostDispatcher::GetProxiedInterface(const std::string& interface) {
120 // First see if we even have a proxy for this interface.
121 const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface);
122 if (!info)
123 return NULL;
124
125 if (plugin_interface_support_[static_cast<int>(info->id)] !=
126 INTERFACE_UNQUERIED) {
127 // Already queried the plugin if it supports this interface.
128 if (plugin_interface_support_[info->id] == INTERFACE_SUPPORTED)
129 return info->interface;
130 return NULL;
131 }
132
133 // Need to re-query. Cache the result so we only do this once.
134 bool supported = false;
135 Send(new PpapiMsg_SupportsInterface(interface, &supported));
136 plugin_interface_support_[static_cast<int>(info->id)] =
137 supported ? INTERFACE_SUPPORTED : INTERFACE_UNSUPPORTED;
138
139 if (supported)
140 return info->interface;
141 return NULL;
142 }
143
79 } // namespace proxy 144 } // namespace proxy
80 } // namespace pp 145 } // namespace pp
81 146
OLDNEW
« no previous file with comments | « ppapi/proxy/host_dispatcher.h ('k') | ppapi/proxy/host_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698