| 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/renderer/npapi/plugin_channel_host.h" | 5 #include "content/renderer/npapi/plugin_channel_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "content/child/child_process.h" | 12 #include "content/child/child_process.h" |
| 13 #include "content/child/npapi/npobject_base.h" | |
| 14 #include "content/child/plugin_messages.h" | 13 #include "content/child/plugin_messages.h" |
| 15 | 14 |
| 16 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
| 17 #include "ipc/ipc_channel_posix.h" | 16 #include "ipc/ipc_channel_posix.h" |
| 18 #endif | 17 #endif |
| 19 | 18 |
| 20 #include "third_party/WebKit/public/web/WebBindings.h" | |
| 21 | |
| 22 // TODO(shess): Debugging for http://crbug.com/97285 | 19 // TODO(shess): Debugging for http://crbug.com/97285 |
| 23 // | 20 // |
| 24 // The hypothesis at #55 requires that RemoveRoute() be called between | 21 // The hypothesis at #55 requires that RemoveRoute() be called between |
| 25 // sending ViewHostMsg_OpenChannelToPlugin to the browser, and calling | 22 // sending ViewHostMsg_OpenChannelToPlugin to the browser, and calling |
| 26 // GetPluginChannelHost() on the result. This code detects that case | 23 // GetPluginChannelHost() on the result. This code detects that case |
| 27 // and stores the backtrace of the RemoveRoute() in a breakpad key. | 24 // and stores the backtrace of the RemoveRoute() in a breakpad key. |
| 28 // The specific RemoveRoute() is not tracked (there could be multiple, | 25 // The specific RemoveRoute() is not tracked (there could be multiple, |
| 29 // and which is the one can't be known until the open completes), but | 26 // and which is the one can't be known until the open completes), but |
| 30 // the backtrace from any such nested call should be sufficient to | 27 // the backtrace from any such nested call should be sufficient to |
| 31 // drive a repro. | 28 // drive a repro. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 return NPChannelBase::Init(ipc_task_runner, create_pipe_now, shutdown_event); | 80 return NPChannelBase::Init(ipc_task_runner, create_pipe_now, shutdown_event); |
| 84 } | 81 } |
| 85 | 82 |
| 86 int PluginChannelHost::GenerateRouteID() { | 83 int PluginChannelHost::GenerateRouteID() { |
| 87 int route_id = MSG_ROUTING_NONE; | 84 int route_id = MSG_ROUTING_NONE; |
| 88 Send(new PluginMsg_GenerateRouteID(&route_id)); | 85 Send(new PluginMsg_GenerateRouteID(&route_id)); |
| 89 | 86 |
| 90 return route_id; | 87 return route_id; |
| 91 } | 88 } |
| 92 | 89 |
| 93 void PluginChannelHost::AddRoute(int route_id, | 90 void PluginChannelHost::AddRoute(int route_id, IPC::Listener* listener) { |
| 94 IPC::Listener* listener, | 91 NPChannelBase::AddRoute(route_id, listener); |
| 95 NPObjectBase* npobject) { | 92 proxies_[route_id] = listener; |
| 96 NPChannelBase::AddRoute(route_id, listener, npobject); | |
| 97 | |
| 98 if (!npobject) | |
| 99 proxies_[route_id] = listener; | |
| 100 } | 93 } |
| 101 | 94 |
| 102 void PluginChannelHost::RemoveRoute(int route_id) { | 95 void PluginChannelHost::RemoveRoute(int route_id) { |
| 103 #if defined(OS_MACOSX) | 96 #if defined(OS_MACOSX) |
| 104 if (remove_tracking) { | 97 if (remove_tracking) { |
| 105 base::debug::StackTrace trace; | 98 base::debug::StackTrace trace; |
| 106 size_t count = 0; | 99 size_t count = 0; |
| 107 const void* const* addresses = trace.Addresses(&count); | 100 const void* const* addresses = trace.Addresses(&count); |
| 108 base::debug::SetCrashKeyFromAddresses( | 101 base::debug::SetCrashKeyFromAddresses( |
| 109 kRemoveRouteTraceKey, addresses, count); | 102 kRemoveRouteTraceKey, addresses, count); |
| 110 } | 103 } |
| 111 #endif | 104 #endif |
| 112 | 105 |
| 113 proxies_.erase(route_id); | 106 proxies_.erase(route_id); |
| 114 NPChannelBase::RemoveRoute(route_id); | 107 NPChannelBase::RemoveRoute(route_id); |
| 115 } | 108 } |
| 116 | 109 |
| 117 bool PluginChannelHost::OnControlMessageReceived(const IPC::Message& message) { | 110 bool PluginChannelHost::OnControlMessageReceived(const IPC::Message& message) { |
| 118 bool handled = true; | 111 bool handled = true; |
| 119 IPC_BEGIN_MESSAGE_MAP(PluginChannelHost, message) | 112 IPC_BEGIN_MESSAGE_MAP(PluginChannelHost, message) |
| 120 IPC_MESSAGE_HANDLER(PluginHostMsg_SetException, OnSetException) | |
| 121 IPC_MESSAGE_HANDLER(PluginHostMsg_PluginShuttingDown, OnPluginShuttingDown) | 113 IPC_MESSAGE_HANDLER(PluginHostMsg_PluginShuttingDown, OnPluginShuttingDown) |
| 122 IPC_MESSAGE_UNHANDLED(handled = false) | 114 IPC_MESSAGE_UNHANDLED(handled = false) |
| 123 IPC_END_MESSAGE_MAP() | 115 IPC_END_MESSAGE_MAP() |
| 124 DCHECK(handled); | 116 DCHECK(handled); |
| 125 return handled; | 117 return handled; |
| 126 } | 118 } |
| 127 | 119 |
| 128 void PluginChannelHost::OnSetException(const std::string& message) { | |
| 129 blink::WebBindings::setException(NULL, message.c_str()); | |
| 130 } | |
| 131 | |
| 132 void PluginChannelHost::OnPluginShuttingDown() { | 120 void PluginChannelHost::OnPluginShuttingDown() { |
| 133 expecting_shutdown_ = true; | 121 expecting_shutdown_ = true; |
| 134 } | 122 } |
| 135 | 123 |
| 136 bool PluginChannelHost::Send(IPC::Message* msg) { | 124 bool PluginChannelHost::Send(IPC::Message* msg) { |
| 137 if (msg->is_sync()) { | 125 if (msg->is_sync()) { |
| 138 base::TimeTicks start_time(base::TimeTicks::Now()); | 126 base::TimeTicks start_time(base::TimeTicks::Now()); |
| 139 bool result = NPChannelBase::Send(msg); | 127 bool result = NPChannelBase::Send(msg); |
| 140 UMA_HISTOGRAM_TIMES("Plugin.SyncMessageTime", | 128 UMA_HISTOGRAM_TIMES("Plugin.SyncMessageTime", |
| 141 base::TimeTicks::Now() - start_time); | 129 base::TimeTicks::Now() - start_time); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 159 | 147 |
| 160 for (ProxyMap::iterator iter = proxies_.begin(); | 148 for (ProxyMap::iterator iter = proxies_.begin(); |
| 161 iter != proxies_.end(); iter++) { | 149 iter != proxies_.end(); iter++) { |
| 162 iter->second->OnChannelError(); | 150 iter->second->OnChannelError(); |
| 163 } | 151 } |
| 164 | 152 |
| 165 proxies_.clear(); | 153 proxies_.clear(); |
| 166 } | 154 } |
| 167 | 155 |
| 168 } // namespace content | 156 } // namespace content |
| OLD | NEW |