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/java/java_bridge_channel.h" | 5 #include "content/renderer/java/java_bridge_channel.h" |
6 | 6 |
7 #include "content/child/child_process.h" | 7 #include "content/child/child_process.h" |
8 #include "content/child/plugin_messages.h" | 8 #include "content/child/plugin_messages.h" |
9 #include "content/common/java_bridge_messages.h" | 9 #include "content/common/java_bridge_messages.h" |
| 10 #include "third_party/WebKit/public/web/WebBindings.h" |
10 | 11 |
11 namespace content { | 12 namespace content { |
12 | 13 |
13 JavaBridgeChannel* JavaBridgeChannel::GetJavaBridgeChannel( | 14 JavaBridgeChannel* JavaBridgeChannel::GetJavaBridgeChannel( |
14 const IPC::ChannelHandle& channel_handle, | 15 const IPC::ChannelHandle& channel_handle, |
15 base::MessageLoopProxy* ipc_message_loop) { | 16 base::MessageLoopProxy* ipc_message_loop) { |
16 return static_cast<JavaBridgeChannel*>(NPChannelBase::GetChannel( | 17 return static_cast<JavaBridgeChannel*>(NPChannelBase::GetChannel( |
17 channel_handle, | 18 channel_handle, |
18 IPC::Channel::MODE_CLIENT, | 19 IPC::Channel::MODE_CLIENT, |
19 ClassFactory, | 20 ClassFactory, |
20 ipc_message_loop, | 21 ipc_message_loop, |
21 true, | 22 true, |
22 ChildProcess::current()->GetShutDownEvent())); | 23 ChildProcess::current()->GetShutDownEvent())); |
23 } | 24 } |
24 | 25 |
25 JavaBridgeChannel::JavaBridgeChannel() { | 26 JavaBridgeChannel::JavaBridgeChannel() |
| 27 : peer_owner_id_(new struct _NPP) { |
| 28 // Register the dummy owner Id for our peer (the Browser process) as an object |
| 29 // owner, and have all objects received from the peer owned by it. |
| 30 WebKit::WebBindings::registerObjectOwner(peer_owner_id_.get()); |
| 31 SetDefaultNPObjectOwner(peer_owner_id_.get()); |
26 } | 32 } |
27 | 33 |
28 JavaBridgeChannel::~JavaBridgeChannel() { | 34 JavaBridgeChannel::~JavaBridgeChannel() { |
| 35 WebKit::WebBindings::unregisterObjectOwner(peer_owner_id_.get()); |
29 } | 36 } |
30 | 37 |
31 int JavaBridgeChannel::GenerateRouteID() { | 38 int JavaBridgeChannel::GenerateRouteID() { |
32 // Use a control message as this going to the JavaBridgeChannelHost, not an | 39 // Use a control message as this going to the JavaBridgeChannelHost, not an |
33 // injected object. | 40 // injected object. |
34 int route_id = MSG_ROUTING_NONE; | 41 int route_id = MSG_ROUTING_NONE; |
35 Send(new JavaBridgeMsg_GenerateRouteID(&route_id)); | 42 Send(new JavaBridgeMsg_GenerateRouteID(&route_id)); |
36 // This should never fail, as the JavaBridgeChannelHost should always outlive | 43 // This should never fail, as the JavaBridgeChannelHost should always outlive |
37 // us. | 44 // us. |
38 DCHECK_NE(MSG_ROUTING_NONE, route_id); | 45 DCHECK_NE(MSG_ROUTING_NONE, route_id); |
39 return route_id; | 46 return route_id; |
40 } | 47 } |
41 | 48 |
42 bool JavaBridgeChannel::OnControlMessageReceived(const IPC::Message& msg) { | 49 bool JavaBridgeChannel::OnControlMessageReceived(const IPC::Message& msg) { |
43 // We need to intercept these two message types because the default | 50 // We need to intercept these two message types because the default |
44 // implementation of NPChannelBase::OnControlMessageReceived() is to | 51 // implementation of NPChannelBase::OnControlMessageReceived() is to |
45 // DCHECK(false). However, we don't need to do anything, as we don't need to | 52 // DCHECK(false). However, we don't need to do anything, as we don't need to |
46 // worry about the window system hanging when a modal dialog is displayed. | 53 // worry about the window system hanging when a modal dialog is displayed. |
47 // This is because, unlike in the case of plugins, the host does not need to | 54 // This is because, unlike in the case of plugins, the host does not need to |
48 // pump the message queue to avoid hangs. | 55 // pump the message queue to avoid hangs. |
49 if (msg.type() == PluginMsg_SignalModalDialogEvent::ID || | 56 if (msg.type() == PluginMsg_SignalModalDialogEvent::ID || |
50 msg.type() == PluginMsg_ResetModalDialogEvent::ID) { | 57 msg.type() == PluginMsg_ResetModalDialogEvent::ID) { |
51 return true; | 58 return true; |
52 } | 59 } |
53 return NPChannelBase::OnControlMessageReceived(msg); | 60 return NPChannelBase::OnControlMessageReceived(msg); |
54 } | 61 } |
55 | 62 |
56 } // namespace content | 63 } // namespace content |
OLD | NEW |