OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_COMMON_NP_CHANNEL_BASE_H_ | 5 #ifndef CONTENT_COMMON_NP_CHANNEL_BASE_H_ |
6 #define CONTENT_COMMON_NP_CHANNEL_BASE_H_ | 6 #define CONTENT_COMMON_NP_CHANNEL_BASE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 template<> | 40 template<> |
41 inline size_t hash_value(NPObject* const& ptr) { | 41 inline size_t hash_value(NPObject* const& ptr) { |
42 return hash_value(reinterpret_cast<size_t>(ptr)); | 42 return hash_value(reinterpret_cast<size_t>(ptr)); |
43 } | 43 } |
44 | 44 |
45 } // namespace stdext | 45 } // namespace stdext |
46 #endif // COMPILER | 46 #endif // COMPILER |
47 | 47 |
48 // Encapsulates an IPC channel between a renderer and another process. Used to | 48 // Encapsulates an IPC channel between a renderer and another process. Used to |
49 // proxy access to NP objects. | 49 // proxy access to NP objects. |
50 class NPChannelBase : public IPC::Channel::Listener, | 50 class NPChannelBase : public IPC::Listener, |
51 public IPC::Message::Sender, | 51 public IPC::Sender, |
52 public base::RefCountedThreadSafe<NPChannelBase> { | 52 public base::RefCountedThreadSafe<NPChannelBase> { |
53 public: | 53 public: |
54 | 54 |
55 // WebPlugin[Delegate] call these on construction and destruction to setup | 55 // WebPlugin[Delegate] call these on construction and destruction to setup |
56 // the routing and manage lifetime of this object (they pass NULL for | 56 // the routing and manage lifetime of this object (they pass NULL for |
57 // npobject). These are also called by NPObjectProxy and NPObjectStub (which | 57 // npobject). These are also called by NPObjectProxy and NPObjectStub (which |
58 // pass themselves for npobject). However the latter don't control the | 58 // pass themselves for npobject). However the latter don't control the |
59 // lifetime of this object because we don't want a leak of an NPObject to | 59 // lifetime of this object because we don't want a leak of an NPObject to |
60 // keep the channel around longer than necessary. | 60 // keep the channel around longer than necessary. |
61 void AddRoute(int route_id, IPC::Channel::Listener* listener, | 61 void AddRoute(int route_id, IPC::Listener* listener, NPObjectBase* npobject); |
62 NPObjectBase* npobject); | |
63 void RemoveRoute(int route_id); | 62 void RemoveRoute(int route_id); |
64 | 63 |
65 | 64 |
66 void AddMappingForNPObjectProxy(int route_id, NPObject* object); | 65 void AddMappingForNPObjectProxy(int route_id, NPObject* object); |
67 void RemoveMappingForNPObjectProxy(int route_id); | 66 void RemoveMappingForNPObjectProxy(int route_id); |
68 | 67 |
69 void AddMappingForNPObjectStub(int route_id, NPObject* object); | 68 void AddMappingForNPObjectStub(int route_id, NPObject* object); |
70 void RemoveMappingForNPObjectStub(int route_id, NPObject* object); | 69 void RemoveMappingForNPObjectStub(int route_id, NPObject* object); |
71 | 70 |
72 NPObject* GetExistingNPObjectProxy(int route_id); | 71 NPObject* GetExistingNPObjectProxy(int route_id); |
73 int GetExistingRouteForNPObjectStub(NPObject* npobject); | 72 int GetExistingRouteForNPObjectStub(NPObject* npobject); |
74 | 73 |
75 | 74 |
76 // IPC::Message::Sender implementation: | 75 // IPC::Sender implementation: |
77 virtual bool Send(IPC::Message* msg) OVERRIDE; | 76 virtual bool Send(IPC::Message* msg) OVERRIDE; |
78 | 77 |
79 base::ProcessId peer_pid() { return channel_->peer_pid(); } | 78 base::ProcessId peer_pid() { return channel_->peer_pid(); } |
80 IPC::ChannelHandle channel_handle() const { return channel_handle_; } | 79 IPC::ChannelHandle channel_handle() const { return channel_handle_; } |
81 | 80 |
82 // Returns the number of open NPObject channels in this process. | 81 // Returns the number of open NPObject channels in this process. |
83 static int Count(); | 82 static int Count(); |
84 | 83 |
85 // Returns a new route id. | 84 // Returns a new route id. |
86 virtual int GenerateRouteID() = 0; | 85 virtual int GenerateRouteID() = 0; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 static void Broadcast(IPC::Message* message); | 127 static void Broadcast(IPC::Message* message); |
129 | 128 |
130 // Called on the worker thread | 129 // Called on the worker thread |
131 NPChannelBase(); | 130 NPChannelBase(); |
132 | 131 |
133 virtual void CleanUp() { } | 132 virtual void CleanUp() { } |
134 | 133 |
135 // Implemented by derived classes to handle control messages | 134 // Implemented by derived classes to handle control messages |
136 virtual bool OnControlMessageReceived(const IPC::Message& msg); | 135 virtual bool OnControlMessageReceived(const IPC::Message& msg); |
137 | 136 |
138 // IPC::Channel::Listener implementation: | 137 // IPC::Listener implementation: |
139 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 138 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
140 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 139 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
141 virtual void OnChannelError() OVERRIDE; | 140 virtual void OnChannelError() OVERRIDE; |
142 | 141 |
143 void set_send_unblocking_only_during_unblock_dispatch() { | 142 void set_send_unblocking_only_during_unblock_dispatch() { |
144 send_unblocking_only_during_unblock_dispatch_ = true; | 143 send_unblocking_only_during_unblock_dispatch_ = true; |
145 } | 144 } |
146 | 145 |
147 virtual bool Init(base::MessageLoopProxy* ipc_message_loop, | 146 virtual bool Init(base::MessageLoopProxy* ipc_message_loop, |
148 bool create_pipe_now, | 147 bool create_pipe_now, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // a result of a sync call from the renderer must unblock the renderer. We | 193 // a result of a sync call from the renderer must unblock the renderer. We |
195 // additionally have to do this for async messages from the renderer that | 194 // additionally have to do this for async messages from the renderer that |
196 // have the unblock flag set, since they could be followed by a sync message | 195 // have the unblock flag set, since they could be followed by a sync message |
197 // that won't get dispatched until the call to the renderer is complete. | 196 // that won't get dispatched until the call to the renderer is complete. |
198 bool send_unblocking_only_during_unblock_dispatch_; | 197 bool send_unblocking_only_during_unblock_dispatch_; |
199 | 198 |
200 DISALLOW_COPY_AND_ASSIGN(NPChannelBase); | 199 DISALLOW_COPY_AND_ASSIGN(NPChannelBase); |
201 }; | 200 }; |
202 | 201 |
203 #endif // CONTENT_COMMON_NP_CHANNEL_BASE_H_ | 202 #endif // CONTENT_COMMON_NP_CHANNEL_BASE_H_ |
OLD | NEW |