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/pepper/pepper_in_process_router.h" | 5 #include "content/renderer/pepper/pepper_in_process_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/public/renderer/render_thread.h" | 9 #include "content/public/renderer/render_thread.h" |
10 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 10 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // If the resource doesn't exist, it may have been destroyed so just ignore | 96 // If the resource doesn't exist, it may have been destroyed so just ignore |
97 // the message. | 97 // the message. |
98 if (resource) | 98 if (resource) |
99 resource->OnReplyReceived(reply_params, nested_msg); | 99 resource->OnReplyReceived(reply_params, nested_msg); |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 bool PepperInProcessRouter::SendToHost(IPC::Message* msg) { | 103 bool PepperInProcessRouter::SendToHost(IPC::Message* msg) { |
104 scoped_ptr<IPC::Message> message(msg); | 104 scoped_ptr<IPC::Message> message(msg); |
105 | 105 |
| 106 // Unpack the message so we can peek at its nested type. |
| 107 uint32 call_type = 0; |
| 108 if (message->type() == PpapiHostMsg_ResourceCall::ID) { |
| 109 ppapi::proxy::ResourceMessageCallParams call_params; |
| 110 IPC::Message nested_msg; |
| 111 if (!UnpackMessage<PpapiHostMsg_ResourceCall>(*msg, &call_params, |
| 112 &nested_msg)) { |
| 113 NOTREACHED(); |
| 114 return false; |
| 115 } |
| 116 call_type = nested_msg.type(); |
| 117 // Repack the message. |
| 118 message.reset(new PpapiHostMsg_ResourceCall(call_params, nested_msg)); |
| 119 } |
| 120 |
106 if (!message->is_sync()) { | 121 if (!message->is_sync()) { |
107 // If this is a resource destroyed message, post a task to dispatch it. | |
108 // Dispatching it synchronously can cause the host to re-enter the proxy | |
109 // code while we're still in the resource destructor, leading to a crash. | |
110 // http://crbug.com/276368. | |
111 // This won't cause message reordering problems because the resource | |
112 // destroyed message is always the last one sent for a resource. | |
113 if (message->type() == PpapiHostMsg_ResourceDestroyed::ID) { | 122 if (message->type() == PpapiHostMsg_ResourceDestroyed::ID) { |
| 123 // If this is a resource destroyed message, post a task to dispatch it. |
| 124 // Dispatching it synchronously can cause the host to re-enter the proxy |
| 125 // code while we're still in the resource destructor, leading to a crash. |
| 126 // http://crbug.com/276368. |
| 127 // This won't cause message reordering problems because the resource |
| 128 // destroyed message is always the last one sent for a resource. |
114 base::MessageLoop::current()->PostTask( | 129 base::MessageLoop::current()->PostTask( |
115 FROM_HERE, | 130 FROM_HERE, |
116 base::Bind(&PepperInProcessRouter::DispatchHostMsg, | 131 base::Bind(&PepperInProcessRouter::DispatchHostMsg, |
| 132 weak_factory_.GetWeakPtr(), |
| 133 base::Owned(message.release()))); |
| 134 return true; |
| 135 } else if (call_type == PpapiHostMsg_URLLoader_Close::ID) { |
| 136 // If this is a PpapiHostMsg_URLLoader_Close, it could trigger the |
| 137 // destruction of the instance (crbug.com/372548) so post a task to |
| 138 // dispatch it as well. Because PpapiHostMsg_ResourceDestroyed messages |
| 139 // are also posted above, ordering with respect to those messages will |
| 140 // still be correct. Ordering with respect to other messages should not |
| 141 // be important. |
| 142 base::MessageLoop::current()->PostTask( |
| 143 FROM_HERE, |
| 144 base::Bind(&PepperInProcessRouter::DispatchHostMsg, |
117 weak_factory_.GetWeakPtr(), | 145 weak_factory_.GetWeakPtr(), |
118 base::Owned(message.release()))); | 146 base::Owned(message.release()))); |
119 return true; | 147 return true; |
120 } else { | 148 } else { |
121 bool result = host_impl_->GetPpapiHost()->OnMessageReceived(*message); | 149 bool result = host_impl_->GetPpapiHost()->OnMessageReceived(*message); |
122 DCHECK(result) << "The message was not handled by the host."; | 150 DCHECK(result) << "The message was not handled by the host."; |
123 return true; | 151 return true; |
124 } | 152 } |
125 } | 153 } |
126 | 154 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 void PepperInProcessRouter::DispatchPluginMsg(IPC::Message* msg) { | 191 void PepperInProcessRouter::DispatchPluginMsg(IPC::Message* msg) { |
164 bool handled = OnPluginMsgReceived(*msg); | 192 bool handled = OnPluginMsgReceived(*msg); |
165 DCHECK(handled); | 193 DCHECK(handled); |
166 } | 194 } |
167 | 195 |
168 bool PepperInProcessRouter::SendToBrowser(IPC::Message* msg) { | 196 bool PepperInProcessRouter::SendToBrowser(IPC::Message* msg) { |
169 return RenderThread::Get()->Send(msg); | 197 return RenderThread::Get()->Send(msg); |
170 } | 198 } |
171 | 199 |
172 } // namespace content | 200 } // namespace content |
OLD | NEW |