| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_PLUGIN_PLUGIN_CHANNEL_H_ | 5 #ifndef CHROME_PLUGIN_PLUGIN_CHANNEL_H_ |
| 6 #define CHROME_PLUGIN_PLUGIN_CHANNEL_H_ | 6 #define CHROME_PLUGIN_PLUGIN_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include "base/scoped_handle.h" | 9 #include "base/scoped_handle.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/plugin/plugin_channel_base.h" | 11 #include "chrome/plugin/plugin_channel_base.h" |
| 12 #include "chrome/plugin/webplugin_delegate_stub.h" | 12 #include "chrome/plugin/webplugin_delegate_stub.h" |
| 13 | 13 |
| 14 // Encapsulates an IPC channel between the plugin process and one renderer | 14 // Encapsulates an IPC channel between the plugin process and one renderer |
| 15 // process. On the renderer side there's a corresponding PluginChannelHost. | 15 // process. On the renderer side there's a corresponding PluginChannelHost. |
| 16 class PluginChannel : public PluginChannelBase { | 16 class PluginChannel : public PluginChannelBase { |
| 17 public: | 17 public: |
| 18 // Get a new PluginChannel object for the current process. | 18 // Get a new PluginChannel object for the current process. |
| 19 // POSIX only: If |channel_fd| > 0, use that file descriptor for the | 19 // POSIX only: If |channel_fd| > 0, use that file descriptor for the |
| 20 // channel socket. | 20 // channel socket. |
| 21 static PluginChannel* GetPluginChannel(int process_id, | 21 static PluginChannel* GetPluginChannel(int process_id, |
| 22 MessageLoop* ipc_message_loop, | 22 MessageLoop* ipc_message_loop); |
| 23 int channel_fd); | |
| 24 | 23 |
| 25 ~PluginChannel(); | 24 ~PluginChannel(); |
| 26 | 25 |
| 27 virtual bool Send(IPC::Message* msg); | 26 virtual bool Send(IPC::Message* msg); |
| 28 virtual void OnMessageReceived(const IPC::Message& message); | 27 virtual void OnMessageReceived(const IPC::Message& message); |
| 29 | 28 |
| 30 base::ProcessHandle renderer_handle() const { return renderer_handle_; } | 29 base::ProcessHandle renderer_handle() const { return renderer_handle_; } |
| 31 int GenerateRouteID(); | 30 int GenerateRouteID(); |
| 32 | 31 |
| 32 #if defined(OS_POSIX) |
| 33 // When first created, the PluginChannel gets assigned the file descriptor |
| 34 // for the renderer. |
| 35 // After the first time we pass it through the IPC, we don't need it anymore, |
| 36 // and we close it. At that time, we reset renderer_fd_ to -1. |
| 37 int DisownRendererFd() { |
| 38 int value = renderer_fd_; |
| 39 renderer_fd_ = -1; |
| 40 return value; |
| 41 } |
| 42 #endif |
| 43 |
| 33 bool in_send() { return in_send_ != 0; } | 44 bool in_send() { return in_send_ != 0; } |
| 34 | 45 |
| 35 bool off_the_record() { return off_the_record_; } | 46 bool off_the_record() { return off_the_record_; } |
| 36 void set_off_the_record(bool value) { off_the_record_ = value; } | 47 void set_off_the_record(bool value) { off_the_record_ = value; } |
| 37 | 48 |
| 38 protected: | 49 protected: |
| 39 // IPC::Channel::Listener implementation: | 50 // IPC::Channel::Listener implementation: |
| 40 virtual void OnChannelConnected(int32 peer_pid); | 51 virtual void OnChannelConnected(int32 peer_pid); |
| 41 virtual void OnChannelError(); | 52 virtual void OnChannelError(); |
| 42 | 53 |
| 43 virtual void CleanUp(); | 54 virtual void CleanUp(); |
| 44 | 55 |
| 56 // Overrides PluginChannelBase::Init. |
| 57 virtual bool Init(MessageLoop* ipc_message_loop, bool create_pipe_now); |
| 58 |
| 45 private: | 59 private: |
| 46 // Called on the plugin thread | 60 // Called on the plugin thread |
| 47 PluginChannel(); | 61 PluginChannel(); |
| 48 | 62 |
| 49 void OnControlMessageReceived(const IPC::Message& msg); | 63 void OnControlMessageReceived(const IPC::Message& msg); |
| 50 | 64 |
| 51 static PluginChannelBase* ClassFactory() { return new PluginChannel(); } | 65 static PluginChannelBase* ClassFactory() { return new PluginChannel(); } |
| 52 | 66 |
| 53 void OnCreateInstance(const std::string& mime_type, int* instance_id); | 67 void OnCreateInstance(const std::string& mime_type, int* instance_id); |
| 54 void OnDestroyInstance(int instance_id, IPC::Message* reply_msg); | 68 void OnDestroyInstance(int instance_id, IPC::Message* reply_msg); |
| 55 void OnGenerateRouteID(int* route_id); | 69 void OnGenerateRouteID(int* route_id); |
| 56 | 70 |
| 57 std::vector<scoped_refptr<WebPluginDelegateStub> > plugin_stubs_; | 71 std::vector<scoped_refptr<WebPluginDelegateStub> > plugin_stubs_; |
| 58 | 72 |
| 59 // Handle to the renderer process who is on the other side of the channel. | 73 // Handle to the renderer process who is on the other side of the channel. |
| 60 base::ProcessHandle renderer_handle_; | 74 base::ProcessHandle renderer_handle_; |
| 61 | 75 |
| 76 #if defined(OS_POSIX) |
| 77 // FD for the renderer end of the pipe. It is stored until we send it over |
| 78 // IPC after which it is cleared. It will be closed by the IPC mechanism. |
| 79 int renderer_fd_; |
| 80 #endif |
| 81 |
| 62 int in_send_; // Tracks if we're in a Send call. | 82 int in_send_; // Tracks if we're in a Send call. |
| 63 bool log_messages_; // True if we should log sent and received messages. | 83 bool log_messages_; // True if we should log sent and received messages. |
| 64 bool off_the_record_; // True if the renderer is in off the record mode. | 84 bool off_the_record_; // True if the renderer is in off the record mode. |
| 65 | 85 |
| 66 DISALLOW_EVIL_CONSTRUCTORS(PluginChannel); | 86 DISALLOW_EVIL_CONSTRUCTORS(PluginChannel); |
| 67 }; | 87 }; |
| 68 | 88 |
| 69 #endif // CHROME_PLUGIN_PLUGIN_CHANNEL_H_ | 89 #endif // CHROME_PLUGIN_PLUGIN_CHANNEL_H_ |
| OLD | NEW |