| 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 #include "content/plugin/plugin_channel.h" | 5 #include "content/plugin/plugin_channel.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // How long we wait before releasing the plugin process. | 36 // How long we wait before releasing the plugin process. |
| 37 const int kPluginReleaseTimeMinutes = 5; | 37 const int kPluginReleaseTimeMinutes = 5; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 // If a sync call to the renderer results in a modal dialog, we need to have a | 41 // If a sync call to the renderer results in a modal dialog, we need to have a |
| 42 // way to know so that we can run a nested message loop to simulate what would | 42 // way to know so that we can run a nested message loop to simulate what would |
| 43 // happen in a single process browser and avoid deadlock. | 43 // happen in a single process browser and avoid deadlock. |
| 44 class PluginChannel::MessageFilter : public IPC::MessageFilter { | 44 class PluginChannel::MessageFilter : public IPC::MessageFilter { |
| 45 public: | 45 public: |
| 46 MessageFilter() : channel_(NULL) { } | 46 MessageFilter() : sender_(NULL) { } |
| 47 | 47 |
| 48 base::WaitableEvent* GetModalDialogEvent(int render_view_id) { | 48 base::WaitableEvent* GetModalDialogEvent(int render_view_id) { |
| 49 base::AutoLock auto_lock(modal_dialog_event_map_lock_); | 49 base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
| 50 if (!modal_dialog_event_map_.count(render_view_id)) { | 50 if (!modal_dialog_event_map_.count(render_view_id)) { |
| 51 NOTREACHED(); | 51 NOTREACHED(); |
| 52 return NULL; | 52 return NULL; |
| 53 } | 53 } |
| 54 | 54 |
| 55 return modal_dialog_event_map_[render_view_id].event; | 55 return modal_dialog_event_map_[render_view_id].event; |
| 56 } | 56 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 68 return; | 68 return; |
| 69 | 69 |
| 70 // Delete the event when the stack unwinds as it could be in use now. | 70 // Delete the event when the stack unwinds as it could be in use now. |
| 71 base::MessageLoop::current()->DeleteSoon( | 71 base::MessageLoop::current()->DeleteSoon( |
| 72 FROM_HERE, modal_dialog_event_map_[render_view_id].event); | 72 FROM_HERE, modal_dialog_event_map_[render_view_id].event); |
| 73 modal_dialog_event_map_.erase(render_view_id); | 73 modal_dialog_event_map_.erase(render_view_id); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool Send(IPC::Message* message) { | 76 bool Send(IPC::Message* message) { |
| 77 // Need this function for the IPC_MESSAGE_HANDLER_DELAY_REPLY macro. | 77 // Need this function for the IPC_MESSAGE_HANDLER_DELAY_REPLY macro. |
| 78 return channel_->Send(message); | 78 return sender_->Send(message); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // IPC::MessageFilter: | 81 // IPC::MessageFilter: |
| 82 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE { | 82 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE { |
| 83 channel_ = channel; | 83 sender_ = sender; |
| 84 } | 84 } |
| 85 | 85 |
| 86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 87 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) | 87 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) |
| 88 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) | 88 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) |
| 89 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, | 89 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, |
| 90 OnSignalModalDialogEvent) | 90 OnSignalModalDialogEvent) |
| 91 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, | 91 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, |
| 92 OnResetModalDialogEvent) | 92 OnResetModalDialogEvent) |
| 93 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 131 } |
| 132 | 132 |
| 133 struct WaitableEventWrapper { | 133 struct WaitableEventWrapper { |
| 134 base::WaitableEvent* event; | 134 base::WaitableEvent* event; |
| 135 int refcount; // There could be multiple plugin instances per tab. | 135 int refcount; // There could be multiple plugin instances per tab. |
| 136 }; | 136 }; |
| 137 typedef std::map<int, WaitableEventWrapper> ModalDialogEventMap; | 137 typedef std::map<int, WaitableEventWrapper> ModalDialogEventMap; |
| 138 ModalDialogEventMap modal_dialog_event_map_; | 138 ModalDialogEventMap modal_dialog_event_map_; |
| 139 base::Lock modal_dialog_event_map_lock_; | 139 base::Lock modal_dialog_event_map_lock_; |
| 140 | 140 |
| 141 IPC::Channel* channel_; | 141 IPC::Sender* sender_; |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 PluginChannel* PluginChannel::GetPluginChannel( | 144 PluginChannel* PluginChannel::GetPluginChannel( |
| 145 int renderer_id, base::MessageLoopProxy* ipc_message_loop) { | 145 int renderer_id, base::MessageLoopProxy* ipc_message_loop) { |
| 146 // Map renderer ID to a (single) channel to that process. | 146 // Map renderer ID to a (single) channel to that process. |
| 147 std::string channel_key = base::StringPrintf( | 147 std::string channel_key = base::StringPrintf( |
| 148 "%d.r%d", base::GetCurrentProcId(), renderer_id); | 148 "%d.r%d", base::GetCurrentProcId(), renderer_id); |
| 149 | 149 |
| 150 PluginChannel* channel = | 150 PluginChannel* channel = |
| 151 static_cast<PluginChannel*>(NPChannelBase::GetChannel( | 151 static_cast<PluginChannel*>(NPChannelBase::GetChannel( |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void PluginChannel::OnDidAbortLoading(int render_view_id) { | 339 void PluginChannel::OnDidAbortLoading(int render_view_id) { |
| 340 for (size_t i = 0; i < plugin_stubs_.size(); ++i) { | 340 for (size_t i = 0; i < plugin_stubs_.size(); ++i) { |
| 341 if (plugin_stubs_[i]->webplugin()->host_render_view_routing_id() == | 341 if (plugin_stubs_[i]->webplugin()->host_render_view_routing_id() == |
| 342 render_view_id) { | 342 render_view_id) { |
| 343 plugin_stubs_[i]->delegate()->instance()->CloseStreams(); | 343 plugin_stubs_[i]->delegate()->instance()->CloseStreams(); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace content | 348 } // namespace content |
| OLD | NEW |