| 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 #include <windows.h> | |
| 6 | |
| 7 #include "chrome/plugin/plugin_channel.h" | 5 #include "chrome/plugin/plugin_channel.h" |
| 8 | 6 |
| 9 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 10 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 11 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 12 #include "chrome/common/child_process.h" | 10 #include "chrome/common/child_process.h" |
| 13 #include "chrome/common/plugin_messages.h" | 11 #include "chrome/common/plugin_messages.h" |
| 14 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/plugin/plugin_thread.h" | 13 #include "chrome/plugin/plugin_thread.h" |
| 16 | 14 |
| 17 PluginChannel* PluginChannel::GetPluginChannel(MessageLoop* ipc_message_loop) { | 15 PluginChannel* PluginChannel::GetPluginChannel(MessageLoop* ipc_message_loop) { |
| 18 static int next_id; | 16 static int next_id; |
| 19 std::wstring channel_name = StringPrintf( | 17 std::wstring channel_name = StringPrintf( |
| 20 L"%d.r%d", GetCurrentProcessId(), ++next_id); | 18 L"%d.r%d", base::GetCurrentProcId(), ++next_id); |
| 21 | 19 |
| 22 return static_cast<PluginChannel*>(PluginChannelBase::GetChannel( | 20 return static_cast<PluginChannel*>(PluginChannelBase::GetChannel( |
| 23 channel_name, | 21 channel_name, |
| 24 IPC::Channel::MODE_SERVER, | 22 IPC::Channel::MODE_SERVER, |
| 25 ClassFactory, | 23 ClassFactory, |
| 26 ipc_message_loop, | 24 ipc_message_loop, |
| 27 false)); | 25 false)); |
| 28 } | 26 } |
| 29 | 27 |
| 30 PluginChannel::PluginChannel() : in_send_(0), off_the_record_(false) { | 28 PluginChannel::PluginChannel() : renderer_handle_(0), in_send_(0), |
| 29 off_the_record_(false) { |
| 31 SendUnblockingOnlyDuringDispatch(); | 30 SendUnblockingOnlyDuringDispatch(); |
| 32 ChildProcess::current()->AddRefProcess(); | 31 ChildProcess::current()->AddRefProcess(); |
| 33 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 32 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 34 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); | 33 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
| 35 } | 34 } |
| 36 | 35 |
| 37 PluginChannel::~PluginChannel() { | 36 PluginChannel::~PluginChannel() { |
| 37 if (renderer_handle_) |
| 38 base::CloseProcessHandle(renderer_handle_); |
| 38 ChildProcess::current()->ReleaseProcess(); | 39 ChildProcess::current()->ReleaseProcess(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 bool PluginChannel::Send(IPC::Message* msg) { | 42 bool PluginChannel::Send(IPC::Message* msg) { |
| 42 in_send_++; | 43 in_send_++; |
| 43 if (log_messages_) { | 44 if (log_messages_) { |
| 44 LOG(INFO) << "sending message @" << msg << " on channel @" << this | 45 LOG(INFO) << "sending message @" << msg << " on channel @" << this |
| 45 << " with type " << msg->type(); | 46 << " with type " << msg->type(); |
| 46 } | 47 } |
| 47 bool result = PluginChannelBase::Send(msg); | 48 bool result = PluginChannelBase::Send(msg); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 89 } |
| 89 | 90 |
| 90 NOTREACHED() << "Couldn't find WebPluginDelegateStub to destroy"; | 91 NOTREACHED() << "Couldn't find WebPluginDelegateStub to destroy"; |
| 91 } | 92 } |
| 92 | 93 |
| 93 void PluginChannel::OnGenerateRouteID(int* route_id) { | 94 void PluginChannel::OnGenerateRouteID(int* route_id) { |
| 94 *route_id = GenerateRouteID(); | 95 *route_id = GenerateRouteID(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 int PluginChannel::GenerateRouteID() { | 98 int PluginChannel::GenerateRouteID() { |
| 98 static LONG last_id = 0; | 99 static int last_id = 0; |
| 99 return InterlockedIncrement(&last_id); | 100 return ++last_id; |
| 100 } | 101 } |
| 101 | 102 |
| 102 void PluginChannel::OnChannelConnected(int32 peer_pid) { | 103 void PluginChannel::OnChannelConnected(int32 peer_pid) { |
| 103 base::ProcessHandle handle; | 104 base::ProcessHandle handle; |
| 104 if (!base::OpenProcessHandle(peer_pid, &handle)) { | 105 if (!base::OpenProcessHandle(peer_pid, &handle)) { |
| 105 NOTREACHED(); | 106 NOTREACHED(); |
| 106 } | 107 } |
| 107 renderer_handle_.Set(handle); | 108 renderer_handle_ = handle; |
| 108 PluginChannelBase::OnChannelConnected(peer_pid); | 109 PluginChannelBase::OnChannelConnected(peer_pid); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void PluginChannel::OnChannelError() { | 112 void PluginChannel::OnChannelError() { |
| 112 renderer_handle_.Set(NULL); | 113 base::CloseProcessHandle(renderer_handle_); |
| 114 renderer_handle_ = 0; |
| 113 PluginChannelBase::OnChannelError(); | 115 PluginChannelBase::OnChannelError(); |
| 114 CleanUp(); | 116 CleanUp(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void PluginChannel::CleanUp() { | 119 void PluginChannel::CleanUp() { |
| 118 // We need to clean up the stubs so that they call NPPDestroy. This will | 120 // We need to clean up the stubs so that they call NPPDestroy. This will |
| 119 // also lead to them releasing their reference on this object so that it can | 121 // also lead to them releasing their reference on this object so that it can |
| 120 // be deleted. | 122 // be deleted. |
| 121 for (size_t i = 0; i < plugin_stubs_.size(); ++i) | 123 for (size_t i = 0; i < plugin_stubs_.size(); ++i) |
| 122 RemoveRoute(plugin_stubs_[i]->instance_id()); | 124 RemoveRoute(plugin_stubs_[i]->instance_id()); |
| 123 | 125 |
| 124 // Need to addref this object temporarily because otherwise removing the last | 126 // Need to addref this object temporarily because otherwise removing the last |
| 125 // stub will cause the destructor of this object to be called, however at | 127 // stub will cause the destructor of this object to be called, however at |
| 126 // that point plugin_stubs_ will have one element and its destructor will be | 128 // that point plugin_stubs_ will have one element and its destructor will be |
| 127 // called twice. | 129 // called twice. |
| 128 scoped_refptr<PluginChannel> me(this); | 130 scoped_refptr<PluginChannel> me(this); |
| 129 | 131 |
| 130 plugin_stubs_.clear(); | 132 plugin_stubs_.clear(); |
| 131 } | 133 } |
| OLD | NEW |