| 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 "base/message_loop.h" | |
| 16 #include "content/common/message_router.h" | 15 #include "content/common/message_router.h" |
| 17 #include "content/plugin/npobject_base.h" | 16 #include "content/plugin/npobject_base.h" |
| 18 #include "ipc/ipc_channel_handle.h" | 17 #include "ipc/ipc_channel_handle.h" |
| 19 #include "ipc/ipc_sync_channel.h" | 18 #include "ipc/ipc_sync_channel.h" |
| 20 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
| 21 | 20 |
| 21 namespace base { |
| 22 class MessageLoopProxy; |
| 23 } |
| 24 |
| 22 // Encapsulates an IPC channel between a renderer and a plugin process. | 25 // Encapsulates an IPC channel between a renderer and a plugin process. |
| 23 class PluginChannelBase : public IPC::Channel::Listener, | 26 class PluginChannelBase : public IPC::Channel::Listener, |
| 24 public IPC::Message::Sender, | 27 public IPC::Message::Sender, |
| 25 public base::RefCountedThreadSafe<PluginChannelBase> { | 28 public base::RefCountedThreadSafe<PluginChannelBase> { |
| 26 public: | 29 public: |
| 27 | 30 |
| 28 // WebPlugin[Delegate] call these on construction and destruction to setup | 31 // WebPlugin[Delegate] call these on construction and destruction to setup |
| 29 // the routing and manage lifetime of this object. This is also called by | 32 // the routing and manage lifetime of this object. This is also called by |
| 30 // NPObjectProxy and NPObjectStub. However the latter don't control the | 33 // NPObjectProxy and NPObjectStub. However the latter don't control the |
| 31 // lifetime of this object (by passing true for npobject) because we don't | 34 // lifetime of this object (by passing true for npobject) because we don't |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 73 |
| 71 virtual ~PluginChannelBase(); | 74 virtual ~PluginChannelBase(); |
| 72 | 75 |
| 73 // Returns a PluginChannelBase derived object for the given channel name. | 76 // Returns a PluginChannelBase derived object for the given channel name. |
| 74 // If an existing channel exists returns that object, otherwise creates a | 77 // If an existing channel exists returns that object, otherwise creates a |
| 75 // new one. Even though on creation the object is refcounted, each caller | 78 // new one. Even though on creation the object is refcounted, each caller |
| 76 // must still ref count the returned value. When there are no more routes | 79 // must still ref count the returned value. When there are no more routes |
| 77 // on the channel and its ref count is 0, the object deletes itself. | 80 // on the channel and its ref count is 0, the object deletes itself. |
| 78 static PluginChannelBase* GetChannel( | 81 static PluginChannelBase* GetChannel( |
| 79 const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode, | 82 const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode, |
| 80 PluginChannelFactory factory, MessageLoop* ipc_message_loop, | 83 PluginChannelFactory factory, base::MessageLoopProxy* ipc_message_loop, |
| 81 bool create_pipe_now); | 84 bool create_pipe_now); |
| 82 | 85 |
| 83 // Sends a message to all instances. | 86 // Sends a message to all instances. |
| 84 static void Broadcast(IPC::Message* message); | 87 static void Broadcast(IPC::Message* message); |
| 85 | 88 |
| 86 // Called on the worker thread | 89 // Called on the worker thread |
| 87 PluginChannelBase(); | 90 PluginChannelBase(); |
| 88 | 91 |
| 89 virtual void CleanUp() { } | 92 virtual void CleanUp() { } |
| 90 | 93 |
| 91 // Implemented by derived classes to handle control messages | 94 // Implemented by derived classes to handle control messages |
| 92 virtual bool OnControlMessageReceived(const IPC::Message& msg); | 95 virtual bool OnControlMessageReceived(const IPC::Message& msg); |
| 93 | 96 |
| 94 // IPC::Channel::Listener implementation: | 97 // IPC::Channel::Listener implementation: |
| 95 virtual bool OnMessageReceived(const IPC::Message& msg); | 98 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 96 virtual void OnChannelConnected(int32 peer_pid); | 99 virtual void OnChannelConnected(int32 peer_pid); |
| 97 virtual void OnChannelError(); | 100 virtual void OnChannelError(); |
| 98 | 101 |
| 99 void set_send_unblocking_only_during_unblock_dispatch() { | 102 void set_send_unblocking_only_during_unblock_dispatch() { |
| 100 send_unblocking_only_during_unblock_dispatch_ = true; | 103 send_unblocking_only_during_unblock_dispatch_ = true; |
| 101 } | 104 } |
| 102 | 105 |
| 103 virtual bool Init(MessageLoop* ipc_message_loop, bool create_pipe_now); | 106 virtual bool Init(base::MessageLoopProxy* ipc_message_loop, |
| 107 bool create_pipe_now); |
| 104 | 108 |
| 105 scoped_ptr<IPC::SyncChannel> channel_; | 109 scoped_ptr<IPC::SyncChannel> channel_; |
| 106 | 110 |
| 107 private: | 111 private: |
| 108 IPC::Channel::Mode mode_; | 112 IPC::Channel::Mode mode_; |
| 109 IPC::ChannelHandle channel_handle_; | 113 IPC::ChannelHandle channel_handle_; |
| 110 int plugin_count_; | 114 int plugin_count_; |
| 111 int peer_pid_; | 115 int peer_pid_; |
| 112 | 116 |
| 113 // true when in the middle of a RemoveRoute call | 117 // true when in the middle of a RemoveRoute call |
| (...skipping 26 matching lines...) Expand all Loading... |
| 140 // renderer. We additionally have to do this for async messages from the | 144 // renderer. We additionally have to do this for async messages from the |
| 141 // renderer that have the unblock flag set, since they could be followed by a | 145 // renderer that have the unblock flag set, since they could be followed by a |
| 142 // sync message that won't get dispatched until the call to the renderer is | 146 // sync message that won't get dispatched until the call to the renderer is |
| 143 // complete. | 147 // complete. |
| 144 bool send_unblocking_only_during_unblock_dispatch_; | 148 bool send_unblocking_only_during_unblock_dispatch_; |
| 145 | 149 |
| 146 DISALLOW_COPY_AND_ASSIGN(PluginChannelBase); | 150 DISALLOW_COPY_AND_ASSIGN(PluginChannelBase); |
| 147 }; | 151 }; |
| 148 | 152 |
| 149 #endif // CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ | 153 #endif // CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_ |
| OLD | NEW |