Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 #ifndef CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ | 5 #ifndef CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ |
| 6 #define CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ | 6 #define CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "content/common/message_router.h" | 15 #include "content/common/message_router.h" |
| 16 #include "content/plugin/npobject_base.h" | 16 #include "content/plugin/npobject_base.h" |
| 17 #include "ipc/ipc_channel_handle.h" | 17 #include "ipc/ipc_channel_handle.h" |
| 18 #include "ipc/ipc_sync_channel.h" | 18 #include "ipc/ipc_sync_channel.h" |
| 19 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class MessageLoopProxy; | 22 class MessageLoopProxy; |
| 23 } | 23 } |
| 24 | 24 |
| 25 #if defined(COMPILER_GCC) | |
| 26 namespace __gnu_cxx { | |
| 27 | |
| 28 template<> | |
| 29 struct hash<NPObject*> { | |
| 30 std::size_t operator()(NPObject* const& ptr) const { | |
| 31 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | |
| 32 } | |
| 33 }; | |
| 34 | |
| 35 } // namespace __gnu_cxx | |
| 36 #elif defined(COMPILER_MSVC) | |
| 37 namespace stdext { | |
| 38 | |
| 39 template<> | |
| 40 inline size_t hash_value(NPObject* const& ptr) { | |
| 41 return hash_value(reinterpret_cast<size_t>(ptr)); | |
| 42 } | |
| 43 | |
| 44 } // namespace stdext | |
| 45 #endif // COMPILER | |
| 46 | |
| 25 // Encapsulates an IPC channel between a renderer and a plugin process. | 47 // Encapsulates an IPC channel between a renderer and a plugin process. |
| 26 class PluginChannelBase : public IPC::Channel::Listener, | 48 class PluginChannelBase : public IPC::Channel::Listener, |
| 27 public IPC::Message::Sender, | 49 public IPC::Message::Sender, |
| 28 public base::RefCountedThreadSafe<PluginChannelBase> { | 50 public base::RefCountedThreadSafe<PluginChannelBase> { |
| 29 public: | 51 public: |
| 30 | 52 |
| 31 // WebPlugin[Delegate] call these on construction and destruction to setup | 53 // WebPlugin[Delegate] call these on construction and destruction to setup |
| 32 // the routing and manage lifetime of this object. This is also called by | 54 // the routing and manage lifetime of this object. This is also called by |
| 33 // NPObjectProxy and NPObjectStub. However the latter don't control the | 55 // NPObjectProxy and NPObjectStub. However the latter don't control the |
| 34 // lifetime of this object (by passing true for npobject) because we don't | 56 // lifetime of this object (by passing true for npobject) because we don't |
| 35 // want a leak of an NPObject in a plugin to keep the channel around longer | 57 // want a leak of an NPObject in a plugin to keep the channel around longer |
| 36 // than necessary. | 58 // than necessary. |
| 37 void AddRoute(int route_id, IPC::Channel::Listener* listener, | 59 void AddRoute(int route_id, IPC::Channel::Listener* listener, |
| 38 NPObjectBase* npobject); | 60 NPObjectBase* npobject); |
| 39 void RemoveRoute(int route_id); | 61 void RemoveRoute(int route_id); |
| 40 | 62 |
| 63 | |
| 64 void AddMappingForProxy(int route_id, NPObject* object); | |
|
jam
2011/05/20 23:22:22
nit: we have several proxy/stub types. can you ca
Kelly Norton
2011/05/23 15:02:56
Done.
| |
| 65 void RemoveMappingForProxy(int route_id); | |
| 66 | |
| 67 void AddMappingForStub(int route_id, NPObject* object); | |
| 68 void RemoveMappingForStub(int route_id, NPObject* object); | |
| 69 | |
| 70 NPObject* GetExistingProxy(int route_id); | |
| 71 int GetExistingRouteForStub(NPObject* npobject); | |
| 72 | |
| 73 | |
| 41 // IPC::Message::Sender implementation: | 74 // IPC::Message::Sender implementation: |
| 42 virtual bool Send(IPC::Message* msg); | 75 virtual bool Send(IPC::Message* msg); |
| 43 | 76 |
| 44 int peer_pid() { return peer_pid_; } | 77 int peer_pid() { return peer_pid_; } |
| 45 IPC::ChannelHandle channel_handle() const { return channel_handle_; } | 78 IPC::ChannelHandle channel_handle() const { return channel_handle_; } |
| 46 | 79 |
| 47 // Returns the number of open plugin channels in this process. | 80 // Returns the number of open plugin channels in this process. |
| 48 static int Count(); | 81 static int Count(); |
| 49 | 82 |
| 50 // Returns a new route id. | 83 // Returns a new route id. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 int peer_pid_; | 148 int peer_pid_; |
| 116 | 149 |
| 117 // true when in the middle of a RemoveRoute call | 150 // true when in the middle of a RemoveRoute call |
| 118 bool in_remove_route_; | 151 bool in_remove_route_; |
| 119 | 152 |
| 120 // Keep track of all the registered NPObjects proxies/stubs so that when the | 153 // Keep track of all the registered NPObjects proxies/stubs so that when the |
| 121 // channel is closed we can inform them. | 154 // channel is closed we can inform them. |
| 122 typedef base::hash_map<int, NPObjectBase*> ListenerMap; | 155 typedef base::hash_map<int, NPObjectBase*> ListenerMap; |
| 123 ListenerMap npobject_listeners_; | 156 ListenerMap npobject_listeners_; |
| 124 | 157 |
| 158 typedef base::hash_map<int, NPObject*> ProxyMap; | |
| 159 ProxyMap proxy_map_; | |
| 160 | |
| 161 typedef base::hash_map<NPObject*, int> StubMap; | |
| 162 StubMap stub_map_; | |
| 163 | |
| 125 // Used to implement message routing functionality to WebPlugin[Delegate] | 164 // Used to implement message routing functionality to WebPlugin[Delegate] |
| 126 // objects | 165 // objects |
| 127 MessageRouter router_; | 166 MessageRouter router_; |
| 128 | 167 |
| 129 // A channel is invalid if it is disconnected as a result of a channel | 168 // A channel is invalid if it is disconnected as a result of a channel |
| 130 // error. This flag is used to indicate the same. | 169 // error. This flag is used to indicate the same. |
| 131 bool channel_valid_; | 170 bool channel_valid_; |
| 132 | 171 |
| 133 // Track whether we're dispatching a message with the unblock flag; works like | 172 // Track whether we're dispatching a message with the unblock flag; works like |
| 134 // a refcount, 0 when we're not. | 173 // a refcount, 0 when we're not. |
| 135 int in_unblock_dispatch_; | 174 int in_unblock_dispatch_; |
| 136 | 175 |
| 137 // If true, sync messages will only be marked as unblocking if the channel is | 176 // If true, sync messages will only be marked as unblocking if the channel is |
| 138 // in the middle of dispatching an unblocking message. | 177 // in the middle of dispatching an unblocking message. |
| 139 // The plugin process wants to avoid setting the unblock flag on its sync | 178 // The plugin process wants to avoid setting the unblock flag on its sync |
| 140 // messages unless necessary, since it can potentially introduce reentrancy | 179 // messages unless necessary, since it can potentially introduce reentrancy |
| 141 // into WebKit in ways that it doesn't expect (i.e. causing layout during | 180 // into WebKit in ways that it doesn't expect (i.e. causing layout during |
| 142 // paint). However to avoid deadlock, we must ensure that any message that's | 181 // paint). However to avoid deadlock, we must ensure that any message that's |
| 143 // sent as a result of a sync call from the renderer must unblock the | 182 // sent as a result of a sync call from the renderer must unblock the |
| 144 // renderer. We additionally have to do this for async messages from the | 183 // renderer. We additionally have to do this for async messages from the |
| 145 // renderer that have the unblock flag set, since they could be followed by a | 184 // renderer that have the unblock flag set, since they could be followed by a |
| 146 // sync message that won't get dispatched until the call to the renderer is | 185 // sync message that won't get dispatched until the call to the renderer is |
| 147 // complete. | 186 // complete. |
| 148 bool send_unblocking_only_during_unblock_dispatch_; | 187 bool send_unblocking_only_during_unblock_dispatch_; |
| 149 | 188 |
| 150 DISALLOW_COPY_AND_ASSIGN(PluginChannelBase); | 189 DISALLOW_COPY_AND_ASSIGN(PluginChannelBase); |
| 151 }; | 190 }; |
| 152 | 191 |
| 153 #endif // CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ | 192 #endif // CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ |
| OLD | NEW |