[email protected] | 6189cd9 | 2012-01-28 02:16:20 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 5 | #include "content/plugin/plugin_channel.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | a488837 | 2011-11-19 02:13:33 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 54724e2 | 2013-07-25 13:02:15 | [diff] [blame] | 9 | #include "base/process/process_handle.h" |
[email protected] | 26dd01c | 2013-06-12 13:52:13 | [diff] [blame] | 10 | #include "base/strings/string_util.h" |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 11 | #include "base/synchronization/lock.h" |
[email protected] | 44f9c95 | 2011-01-02 06:05:39 | [diff] [blame] | 12 | #include "base/synchronization/waitable_event.h" |
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 14 | #include "content/child/child_process.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 15 | #include "content/child/npapi/plugin_instance.h" |
[email protected] | 93cabae | 2013-10-01 16:11:36 | [diff] [blame] | 16 | #include "content/child/npapi/webplugin_delegate_impl.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 17 | #include "content/child/plugin_messages.h" |
[email protected] | 872f3a9 | 2013-05-21 08:16:08 | [diff] [blame] | 18 | #include "content/common/plugin_process_messages.h" |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 19 | #include "content/plugin/plugin_thread.h" |
| 20 | #include "content/plugin/webplugin_delegate_stub.h" |
| 21 | #include "content/plugin/webplugin_proxy.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 22 | #include "content/public/common/content_switches.h" |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 23 | #include "ipc/message_filter.h" |
[email protected] | a84bb146 | 2013-06-21 15:59:50 | [diff] [blame] | 24 | #include "third_party/WebKit/public/web/WebBindings.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | |
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 26 | #if defined(OS_POSIX) |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 27 | #include "ipc/ipc_channel_posix.h" |
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 28 | #endif |
| 29 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 30 | using blink::WebBindings; |
[email protected] | a84bb146 | 2013-06-21 15:59:50 | [diff] [blame] | 31 | |
[email protected] | 91355a8 | 2012-10-21 19:52:47 | [diff] [blame] | 32 | namespace content { |
| 33 | |
[email protected] | 4f15d284 | 2011-02-15 17:36:33 | [diff] [blame] | 34 | namespace { |
| 35 | |
[email protected] | f137d13a | 2009-08-07 22:57:06 | [diff] [blame] | 36 | // How long we wait before releasing the plugin process. |
[email protected] | 6189cd9 | 2012-01-28 02:16:20 | [diff] [blame] | 37 | const int kPluginReleaseTimeMinutes = 5; |
[email protected] | f137d13a | 2009-08-07 22:57:06 | [diff] [blame] | 38 | |
[email protected] | 4f15d284 | 2011-02-15 17:36:33 | [diff] [blame] | 39 | } // namespace |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 40 | |
| 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 |
| 43 | // happen in a single process browser and avoid deadlock. |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 44 | class PluginChannel::MessageFilter : public IPC::MessageFilter { |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 45 | public: |
[email protected] | d1549b8 | 2014-06-13 06:07:14 | [diff] [blame] | 46 | MessageFilter() : sender_(NULL) { } |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 47 | |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 48 | base::WaitableEvent* GetModalDialogEvent(int render_view_id) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 49 | base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 50 | if (!modal_dialog_event_map_.count(render_view_id)) { |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 51 | NOTREACHED(); |
| 52 | return NULL; |
| 53 | } |
| 54 | |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 55 | return modal_dialog_event_map_[render_view_id].event; |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | // Decrement the ref count associated with the modal dialog event for the |
| 59 | // given tab. |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 60 | void ReleaseModalDialogEvent(int render_view_id) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 61 | base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 62 | if (!modal_dialog_event_map_.count(render_view_id)) { |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 63 | NOTREACHED(); |
| 64 | return; |
| 65 | } |
| 66 | |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 67 | if (--(modal_dialog_event_map_[render_view_id].refcount)) |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 68 | return; |
| 69 | |
| 70 | // Delete the event when the stack unwinds as it could be in use now. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 71 | base::MessageLoop::current()->DeleteSoon( |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 72 | FROM_HERE, modal_dialog_event_map_[render_view_id].event); |
| 73 | modal_dialog_event_map_.erase(render_view_id); |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | bool Send(IPC::Message* message) { |
| 77 | // Need this function for the IPC_MESSAGE_HANDLER_DELAY_REPLY macro. |
[email protected] | d1549b8 | 2014-06-13 06:07:14 | [diff] [blame] | 78 | return sender_->Send(message); |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 79 | } |
| 80 | |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 81 | // IPC::MessageFilter: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 82 | void OnFilterAdded(IPC::Sender* sender) override { sender_ = sender; } |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 83 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 84 | bool OnMessageReceived(const IPC::Message& message) override { |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 85 | IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) |
| 86 | IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) |
| 87 | IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, |
| 88 | OnSignalModalDialogEvent) |
| 89 | IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, |
| 90 | OnResetModalDialogEvent) |
| 91 | IPC_END_MESSAGE_MAP() |
| 92 | return message.type() == PluginMsg_SignalModalDialogEvent::ID || |
| 93 | message.type() == PluginMsg_ResetModalDialogEvent::ID; |
| 94 | } |
| 95 | |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 96 | protected: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 97 | ~MessageFilter() override { |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 98 | // Clean up in case of renderer crash. |
| 99 | for (ModalDialogEventMap::iterator i = modal_dialog_event_map_.begin(); |
| 100 | i != modal_dialog_event_map_.end(); ++i) { |
| 101 | delete i->second.event; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | private: |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 106 | void OnInit(const PluginMsg_Init_Params& params, IPC::Message* reply_msg) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 107 | base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 108 | if (modal_dialog_event_map_.count(params.host_render_view_routing_id)) { |
| 109 | modal_dialog_event_map_[params.host_render_view_routing_id].refcount++; |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 110 | return; |
| 111 | } |
| 112 | |
| 113 | WaitableEventWrapper wrapper; |
| 114 | wrapper.event = new base::WaitableEvent(true, false); |
| 115 | wrapper.refcount = 1; |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 116 | modal_dialog_event_map_[params.host_render_view_routing_id] = wrapper; |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 119 | void OnSignalModalDialogEvent(int render_view_id) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 120 | base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 121 | if (modal_dialog_event_map_.count(render_view_id)) |
| 122 | modal_dialog_event_map_[render_view_id].event->Signal(); |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 123 | } |
| 124 | |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 125 | void OnResetModalDialogEvent(int render_view_id) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 126 | base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 127 | if (modal_dialog_event_map_.count(render_view_id)) |
| 128 | modal_dialog_event_map_[render_view_id].event->Reset(); |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | struct WaitableEventWrapper { |
| 132 | base::WaitableEvent* event; |
| 133 | int refcount; // There could be multiple plugin instances per tab. |
| 134 | }; |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 135 | typedef std::map<int, WaitableEventWrapper> ModalDialogEventMap; |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 136 | ModalDialogEventMap modal_dialog_event_map_; |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 137 | base::Lock modal_dialog_event_map_lock_; |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 138 | |
[email protected] | d1549b8 | 2014-06-13 06:07:14 | [diff] [blame] | 139 | IPC::Sender* sender_; |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 140 | }; |
| 141 | |
[email protected] | 92bf906 | 2011-05-02 18:00:49 | [diff] [blame] | 142 | PluginChannel* PluginChannel::GetPluginChannel( |
erikchen | f7f98882 | 2015-06-17 23:27:07 | [diff] [blame] | 143 | int renderer_id, |
| 144 | base::SingleThreadTaskRunner* ipc_task_runner, |
| 145 | IPC::AttachmentBroker* broker) { |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 146 | // Map renderer ID to a (single) channel to that process. |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 147 | std::string channel_key = base::StringPrintf( |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 148 | "%d.r%d", base::GetCurrentProcId(), renderer_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 149 | |
[email protected] | c84a785 | 2009-09-16 21:36:44 | [diff] [blame] | 150 | PluginChannel* channel = |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 151 | static_cast<PluginChannel*>(NPChannelBase::GetChannel( |
erikchen | f7f98882 | 2015-06-17 23:27:07 | [diff] [blame] | 152 | channel_key, IPC::Channel::MODE_SERVER, ClassFactory, ipc_task_runner, |
| 153 | false, ChildProcess::current()->GetShutDownEvent(), broker)); |
[email protected] | c84a785 | 2009-09-16 21:36:44 | [diff] [blame] | 154 | |
| 155 | if (channel) |
| 156 | channel->renderer_id_ = renderer_id; |
| 157 | |
| 158 | return channel; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 159 | } |
| 160 | |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 161 | // static |
| 162 | void PluginChannel::NotifyRenderersOfPendingShutdown() { |
| 163 | Broadcast(new PluginHostMsg_PluginShuttingDown()); |
| 164 | } |
| 165 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 166 | bool PluginChannel::Send(IPC::Message* msg) { |
| 167 | in_send_++; |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 168 | if (log_messages_) { |
[email protected] | 3cd3202 | 2010-10-21 20:40:57 | [diff] [blame] | 169 | VLOG(1) << "sending message @" << msg << " on channel @" << this |
| 170 | << " with type " << msg->type(); |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 171 | } |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 172 | bool result = NPChannelBase::Send(msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 173 | in_send_--; |
| 174 | return result; |
| 175 | } |
| 176 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 177 | bool PluginChannel::OnMessageReceived(const IPC::Message& msg) { |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 178 | if (log_messages_) { |
[email protected] | 3cd3202 | 2010-10-21 20:40:57 | [diff] [blame] | 179 | VLOG(1) << "received message @" << &msg << " on channel @" << this |
| 180 | << " with type " << msg.type(); |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 181 | } |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 182 | return NPChannelBase::OnMessageReceived(msg); |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 185 | void PluginChannel::OnChannelError() { |
| 186 | NPChannelBase::OnChannelError(); |
| 187 | CleanUp(); |
| 188 | } |
| 189 | |
| 190 | int PluginChannel::GenerateRouteID() { |
| 191 | static int last_id = 0; |
| 192 | return ++last_id; |
| 193 | } |
| 194 | |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 195 | base::WaitableEvent* PluginChannel::GetModalDialogEvent(int render_view_id) { |
| 196 | return filter_->GetModalDialogEvent(render_view_id); |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | PluginChannel::~PluginChannel() { |
[email protected] | 01cb1991 | 2013-09-11 19:13:03 | [diff] [blame] | 200 | PluginThread::current()->Send(new PluginProcessHostMsg_ChannelDestroyed( |
| 201 | renderer_id_)); |
[email protected] | 1673caf | 2013-11-12 20:15:54 | [diff] [blame] | 202 | process_ref_.ReleaseWithDelay( |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 203 | base::TimeDelta::FromMinutes(kPluginReleaseTimeMinutes)); |
| 204 | } |
| 205 | |
| 206 | void PluginChannel::CleanUp() { |
| 207 | // We need to clean up the stubs so that they call NPPDestroy. This will |
| 208 | // also lead to them releasing their reference on this object so that it can |
| 209 | // be deleted. |
| 210 | for (size_t i = 0; i < plugin_stubs_.size(); ++i) |
| 211 | RemoveRoute(plugin_stubs_[i]->instance_id()); |
| 212 | |
| 213 | // Need to addref this object temporarily because otherwise removing the last |
| 214 | // stub will cause the destructor of this object to be called, however at |
| 215 | // that point plugin_stubs_ will have one element and its destructor will be |
| 216 | // called twice. |
| 217 | scoped_refptr<PluginChannel> me(this); |
| 218 | |
[email protected] | f0938f3a | 2014-01-04 01:40:52 | [diff] [blame] | 219 | while (!plugin_stubs_.empty()) { |
| 220 | // Separate vector::erase and ~WebPluginDelegateStub. |
| 221 | // See https://code.google.com/p/chromium/issues/detail?id=314088 |
| 222 | scoped_refptr<WebPluginDelegateStub> stub = plugin_stubs_[0]; |
| 223 | plugin_stubs_.erase(plugin_stubs_.begin()); |
| 224 | } |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 225 | } |
| 226 | |
skyostil | 12262cf | 2015-05-21 14:49:31 | [diff] [blame] | 227 | bool PluginChannel::Init(base::SingleThreadTaskRunner* ipc_task_runner, |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 228 | bool create_pipe_now, |
erikchen | f7f98882 | 2015-06-17 23:27:07 | [diff] [blame] | 229 | base::WaitableEvent* shutdown_event, |
| 230 | IPC::AttachmentBroker* broker) { |
| 231 | if (!NPChannelBase::Init(ipc_task_runner, create_pipe_now, shutdown_event, |
| 232 | broker)) { |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 233 | return false; |
erikchen | f7f98882 | 2015-06-17 23:27:07 | [diff] [blame] | 234 | } |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 235 | |
| 236 | channel_->AddFilter(filter_.get()); |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | PluginChannel::PluginChannel() |
| 241 | : renderer_id_(-1), |
| 242 | in_send_(0), |
| 243 | incognito_(false), |
[email protected] | a84bb146 | 2013-06-21 15:59:50 | [diff] [blame] | 244 | filter_(new MessageFilter()), |
| 245 | npp_(new struct _NPP) { |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 246 | set_send_unblocking_only_during_unblock_dispatch(); |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 247 | const base::CommandLine* command_line = |
| 248 | base::CommandLine::ForCurrentProcess(); |
[email protected] | 2fe8d191 | 2014-05-05 20:48:33 | [diff] [blame] | 249 | log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
[email protected] | a84bb146 | 2013-06-21 15:59:50 | [diff] [blame] | 250 | |
| 251 | // Register |npp_| as the default owner for any object we receive via IPC, |
| 252 | // and register it with WebBindings as a valid owner. |
| 253 | SetDefaultNPObjectOwner(npp_.get()); |
| 254 | WebBindings::registerObjectOwner(npp_.get()); |
[email protected] | 871da30 | 2012-05-11 19:30:55 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 257 | bool PluginChannel::OnControlMessageReceived(const IPC::Message& msg) { |
| 258 | bool handled = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 259 | IPC_BEGIN_MESSAGE_MAP(PluginChannel, msg) |
| 260 | IPC_MESSAGE_HANDLER(PluginMsg_CreateInstance, OnCreateInstance) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 261 | IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_DestroyInstance, |
| 262 | OnDestroyInstance) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 263 | IPC_MESSAGE_HANDLER(PluginMsg_GenerateRouteID, OnGenerateRouteID) |
[email protected] | 872f3a9 | 2013-05-21 08:16:08 | [diff] [blame] | 264 | IPC_MESSAGE_HANDLER(PluginProcessMsg_ClearSiteData, OnClearSiteData) |
[email protected] | 93cabae | 2013-10-01 16:11:36 | [diff] [blame] | 265 | IPC_MESSAGE_HANDLER(PluginHostMsg_DidAbortLoading, OnDidAbortLoading) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 266 | IPC_MESSAGE_UNHANDLED(handled = false) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 267 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 268 | DCHECK(handled); |
| 269 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void PluginChannel::OnCreateInstance(const std::string& mime_type, |
| 273 | int* instance_id) { |
| 274 | *instance_id = GenerateRouteID(); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 275 | scoped_refptr<WebPluginDelegateStub> stub(new WebPluginDelegateStub( |
| 276 | mime_type, *instance_id, this)); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 277 | AddRoute(*instance_id, stub.get(), NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 278 | plugin_stubs_.push_back(stub); |
| 279 | } |
| 280 | |
| 281 | void PluginChannel::OnDestroyInstance(int instance_id, |
| 282 | IPC::Message* reply_msg) { |
| 283 | for (size_t i = 0; i < plugin_stubs_.size(); ++i) { |
| 284 | if (plugin_stubs_[i]->instance_id() == instance_id) { |
[email protected] | 49f69ae | 2009-10-06 19:11:22 | [diff] [blame] | 285 | scoped_refptr<MessageFilter> filter(filter_); |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 286 | int render_view_id = |
| 287 | plugin_stubs_[i]->webplugin()->host_render_view_routing_id(); |
[email protected] | f0938f3a | 2014-01-04 01:40:52 | [diff] [blame] | 288 | // Separate vector::erase and ~WebPluginDelegateStub. |
| 289 | // See https://code.google.com/p/chromium/issues/detail?id=314088 |
| 290 | scoped_refptr<WebPluginDelegateStub> stub = plugin_stubs_[i]; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | plugin_stubs_.erase(plugin_stubs_.begin() + i); |
[email protected] | f0938f3a | 2014-01-04 01:40:52 | [diff] [blame] | 292 | stub = NULL; |
| 293 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 294 | Send(reply_msg); |
[email protected] | 49f69ae | 2009-10-06 19:11:22 | [diff] [blame] | 295 | RemoveRoute(instance_id); |
| 296 | // NOTE: *this* might be deleted as a result of calling RemoveRoute. |
| 297 | // Don't release the modal dialog event right away, but do it after the |
| 298 | // stack unwinds since the plugin can be destroyed later if it's in use |
| 299 | // right now. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 300 | base::MessageLoop::current()->PostNonNestableTask( |
| 301 | FROM_HERE, |
| 302 | base::Bind(&MessageFilter::ReleaseModalDialogEvent, |
| 303 | filter.get(), |
| 304 | render_view_id)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | NOTREACHED() << "Couldn't find WebPluginDelegateStub to destroy"; |
| 310 | } |
| 311 | |
| 312 | void PluginChannel::OnGenerateRouteID(int* route_id) { |
| 313 | *route_id = GenerateRouteID(); |
| 314 | } |
| 315 | |
[email protected] | a4b146f | 2011-01-11 12:43:36 | [diff] [blame] | 316 | void PluginChannel::OnClearSiteData(const std::string& site, |
| 317 | uint64 flags, |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 318 | uint64 max_age) { |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 319 | bool success = false; |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 320 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 321 | base::FilePath path = command_line->GetSwitchValuePath(switches::kPluginPath); |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 322 | scoped_refptr<PluginLib> plugin_lib(PluginLib::CreatePluginLib(path)); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 323 | if (plugin_lib.get()) { |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 324 | NPError err = plugin_lib->NP_Initialize(); |
| 325 | if (err == NPERR_NO_ERROR) { |
[email protected] | a4b146f | 2011-01-11 12:43:36 | [diff] [blame] | 326 | const char* site_str = site.empty() ? NULL : site.c_str(); |
[email protected] | a4b146f | 2011-01-11 12:43:36 | [diff] [blame] | 327 | err = plugin_lib->NP_ClearSiteData(site_str, flags, max_age); |
[email protected] | b1f172a7 | 2011-04-11 17:26:07 | [diff] [blame] | 328 | std::string site_name = |
| 329 | site.empty() ? "NULL" |
| 330 | : base::StringPrintf("\"%s\"", site_str); |
| 331 | VLOG(1) << "NPP_ClearSiteData(" << site_name << ", " << flags << ", " |
| 332 | << max_age << ") returned " << err; |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 333 | success = (err == NPERR_NO_ERROR); |
| 334 | } |
| 335 | } |
[email protected] | 872f3a9 | 2013-05-21 08:16:08 | [diff] [blame] | 336 | Send(new PluginProcessHostMsg_ClearSiteDataResult(success)); |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 337 | } |
[email protected] | 91355a8 | 2012-10-21 19:52:47 | [diff] [blame] | 338 | |
[email protected] | 93cabae | 2013-10-01 16:11:36 | [diff] [blame] | 339 | void PluginChannel::OnDidAbortLoading(int render_view_id) { |
| 340 | for (size_t i = 0; i < plugin_stubs_.size(); ++i) { |
| 341 | if (plugin_stubs_[i]->webplugin()->host_render_view_routing_id() == |
| 342 | render_view_id) { |
| 343 | plugin_stubs_[i]->delegate()->instance()->CloseStreams(); |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
[email protected] | 91355a8 | 2012-10-21 19:52:47 | [diff] [blame] | 348 | } // namespace content |