OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugin_channel_host.h" | 5 #include "content/renderer/plugin_channel_host.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "content/common/child_process.h" | 9 #include "content/common/child_process.h" |
10 #include "content/common/npobject_base.h" | 10 #include "content/common/npobject_base.h" |
11 #include "content/common/plugin_messages.h" | 11 #include "content/common/plugin_messages.h" |
12 | 12 |
13 #if defined(OS_POSIX) | 13 #if defined(OS_POSIX) |
14 #include "ipc/ipc_channel_posix.h" | 14 #include "ipc/ipc_channel_posix.h" |
15 #endif | 15 #endif |
16 | 16 |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
18 | 18 |
| 19 // TODO(shess): Debugging for http://crbug.com/97285 |
| 20 // |
| 21 // The hypothesis at #55 requires that RemoveRoute() be called between |
| 22 // sending ViewHostMsg_OpenChannelToPlugin to the browser, and calling |
| 23 // GetPluginChannelHost() on the result. This code detects that case |
| 24 // and stores the backtrace of the RemoveRoute() in a breakpad key. |
| 25 // The specific RemoveRoute() is not tracked (there could be multiple, |
| 26 // and which is the one can't be known until the open completes), but |
| 27 // the backtrace from any such nested call should be sufficient to |
| 28 // drive a repro. |
| 29 #if defined(OS_MACOSX) |
| 30 #include "base/debug/stack_trace.h" |
| 31 #include "base/mac/crash_logging.h" |
| 32 #include "base/sys_string_conversions.h" |
| 33 |
| 34 namespace { |
| 35 |
| 36 // Breakpad key for the RemoveRoute() backtrace. |
| 37 const char* kRemoveRouteTraceKey = "remove_route_bt"; |
| 38 |
| 39 // GetRemoveTrackingFlag() exposes this so that |
| 40 // WebPluginDelegateProxy::Initialize() can do scoped set/reset. When |
| 41 // true, RemoveRoute() knows WBDP::Initialize() is on the stack, and |
| 42 // records the backtrace. |
| 43 bool remove_tracking = false; |
| 44 |
| 45 } // namespace |
| 46 #endif |
| 47 |
19 // A simple MessageFilter that will ignore all messages and respond to sync | 48 // A simple MessageFilter that will ignore all messages and respond to sync |
20 // messages with an error when is_listening_ is false. | 49 // messages with an error when is_listening_ is false. |
21 class IsListeningFilter : public IPC::ChannelProxy::MessageFilter { | 50 class IsListeningFilter : public IPC::ChannelProxy::MessageFilter { |
22 public: | 51 public: |
23 IsListeningFilter() : channel_(NULL) {} | 52 IsListeningFilter() : channel_(NULL) {} |
24 | 53 |
25 // MessageFilter overrides | 54 // MessageFilter overrides |
26 virtual void OnFilterRemoved() {} | 55 virtual void OnFilterRemoved() {} |
27 virtual void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } | 56 virtual void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } |
28 virtual bool OnMessageReceived(const IPC::Message& message); | 57 virtual bool OnMessageReceived(const IPC::Message& message); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // static | 92 // static |
64 bool PluginChannelHost::IsListening() { | 93 bool PluginChannelHost::IsListening() { |
65 return IsListeningFilter::is_listening_; | 94 return IsListeningFilter::is_listening_; |
66 } | 95 } |
67 | 96 |
68 // static | 97 // static |
69 void PluginChannelHost::SetListening(bool flag) { | 98 void PluginChannelHost::SetListening(bool flag) { |
70 IsListeningFilter::is_listening_ = flag; | 99 IsListeningFilter::is_listening_ = flag; |
71 } | 100 } |
72 | 101 |
| 102 #if defined(OS_MACOSX) |
| 103 // static |
| 104 bool* PluginChannelHost::GetRemoveTrackingFlag() { |
| 105 return &remove_tracking; |
| 106 } |
| 107 #endif |
| 108 |
| 109 // static |
73 PluginChannelHost* PluginChannelHost::GetPluginChannelHost( | 110 PluginChannelHost* PluginChannelHost::GetPluginChannelHost( |
74 const IPC::ChannelHandle& channel_handle, | 111 const IPC::ChannelHandle& channel_handle, |
75 base::MessageLoopProxy* ipc_message_loop) { | 112 base::MessageLoopProxy* ipc_message_loop) { |
76 PluginChannelHost* result = | 113 PluginChannelHost* result = |
77 static_cast<PluginChannelHost*>(NPChannelBase::GetChannel( | 114 static_cast<PluginChannelHost*>(NPChannelBase::GetChannel( |
78 channel_handle, | 115 channel_handle, |
79 IPC::Channel::MODE_CLIENT, | 116 IPC::Channel::MODE_CLIENT, |
80 ClassFactory, | 117 ClassFactory, |
81 ipc_message_loop, | 118 ipc_message_loop, |
82 true, | 119 true, |
(...skipping 27 matching lines...) Expand all Loading... |
110 void PluginChannelHost::AddRoute(int route_id, | 147 void PluginChannelHost::AddRoute(int route_id, |
111 IPC::Channel::Listener* listener, | 148 IPC::Channel::Listener* listener, |
112 NPObjectBase* npobject) { | 149 NPObjectBase* npobject) { |
113 NPChannelBase::AddRoute(route_id, listener, npobject); | 150 NPChannelBase::AddRoute(route_id, listener, npobject); |
114 | 151 |
115 if (!npobject) | 152 if (!npobject) |
116 proxies_[route_id] = listener; | 153 proxies_[route_id] = listener; |
117 } | 154 } |
118 | 155 |
119 void PluginChannelHost::RemoveRoute(int route_id) { | 156 void PluginChannelHost::RemoveRoute(int route_id) { |
| 157 #if defined(OS_MACOSX) |
| 158 if (remove_tracking) { |
| 159 base::debug::StackTrace trace; |
| 160 size_t count = 0; |
| 161 const void* const* addresses = trace.Addresses(&count); |
| 162 base::mac::SetCrashKeyFromAddresses( |
| 163 base::SysUTF8ToNSString(kRemoveRouteTraceKey), addresses, count); |
| 164 } |
| 165 #endif |
| 166 |
120 proxies_.erase(route_id); | 167 proxies_.erase(route_id); |
121 NPChannelBase::RemoveRoute(route_id); | 168 NPChannelBase::RemoveRoute(route_id); |
122 } | 169 } |
123 | 170 |
124 bool PluginChannelHost::OnControlMessageReceived(const IPC::Message& message) { | 171 bool PluginChannelHost::OnControlMessageReceived(const IPC::Message& message) { |
125 bool handled = true; | 172 bool handled = true; |
126 IPC_BEGIN_MESSAGE_MAP(PluginChannelHost, message) | 173 IPC_BEGIN_MESSAGE_MAP(PluginChannelHost, message) |
127 IPC_MESSAGE_HANDLER(PluginHostMsg_SetException, OnSetException) | 174 IPC_MESSAGE_HANDLER(PluginHostMsg_SetException, OnSetException) |
128 IPC_MESSAGE_HANDLER(PluginHostMsg_PluginShuttingDown, OnPluginShuttingDown) | 175 IPC_MESSAGE_HANDLER(PluginHostMsg_PluginShuttingDown, OnPluginShuttingDown) |
129 IPC_MESSAGE_UNHANDLED(handled = false) | 176 IPC_MESSAGE_UNHANDLED(handled = false) |
(...skipping 24 matching lines...) Expand all Loading... |
154 void PluginChannelHost::OnChannelError() { | 201 void PluginChannelHost::OnChannelError() { |
155 NPChannelBase::OnChannelError(); | 202 NPChannelBase::OnChannelError(); |
156 | 203 |
157 for (ProxyMap::iterator iter = proxies_.begin(); | 204 for (ProxyMap::iterator iter = proxies_.begin(); |
158 iter != proxies_.end(); iter++) { | 205 iter != proxies_.end(); iter++) { |
159 iter->second->OnChannelError(); | 206 iter->second->OnChannelError(); |
160 } | 207 } |
161 | 208 |
162 proxies_.clear(); | 209 proxies_.clear(); |
163 } | 210 } |
OLD | NEW |