| 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 a dummy owner Id for objects received from the Browser process. |
| 29 WebKit::WebBindings::registerObjectOwner(peer_owner_id_.get()); |
| 30 SetDefaultNPObjectOwner(peer_owner_id_.get()); |
| 26 } | 31 } |
| 27 | 32 |
| 28 JavaBridgeChannel::~JavaBridgeChannel() { | 33 JavaBridgeChannel::~JavaBridgeChannel() { |
| 34 WebKit::WebBindings::unregisterObjectOwner(peer_owner_id_.get()); |
| 29 } | 35 } |
| 30 | 36 |
| 31 int JavaBridgeChannel::GenerateRouteID() { | 37 int JavaBridgeChannel::GenerateRouteID() { |
| 32 // Use a control message as this going to the JavaBridgeChannelHost, not an | 38 // Use a control message as this going to the JavaBridgeChannelHost, not an |
| 33 // injected object. | 39 // injected object. |
| 34 int route_id = MSG_ROUTING_NONE; | 40 int route_id = MSG_ROUTING_NONE; |
| 35 Send(new JavaBridgeMsg_GenerateRouteID(&route_id)); | 41 Send(new JavaBridgeMsg_GenerateRouteID(&route_id)); |
| 36 // This should never fail, as the JavaBridgeChannelHost should always outlive | 42 // This should never fail, as the JavaBridgeChannelHost should always outlive |
| 37 // us. | 43 // us. |
| 38 DCHECK_NE(MSG_ROUTING_NONE, route_id); | 44 DCHECK_NE(MSG_ROUTING_NONE, route_id); |
| 39 return route_id; | 45 return route_id; |
| 40 } | 46 } |
| 41 | 47 |
| 42 bool JavaBridgeChannel::OnControlMessageReceived(const IPC::Message& msg) { | 48 bool JavaBridgeChannel::OnControlMessageReceived(const IPC::Message& msg) { |
| 43 // We need to intercept these two message types because the default | 49 // We need to intercept these two message types because the default |
| 44 // implementation of NPChannelBase::OnControlMessageReceived() is to | 50 // implementation of NPChannelBase::OnControlMessageReceived() is to |
| 45 // DCHECK(false). However, we don't need to do anything, as we don't need to | 51 // 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. | 52 // 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 | 53 // This is because, unlike in the case of plugins, the host does not need to |
| 48 // pump the message queue to avoid hangs. | 54 // pump the message queue to avoid hangs. |
| 49 if (msg.type() == PluginMsg_SignalModalDialogEvent::ID || | 55 if (msg.type() == PluginMsg_SignalModalDialogEvent::ID || |
| 50 msg.type() == PluginMsg_ResetModalDialogEvent::ID) { | 56 msg.type() == PluginMsg_ResetModalDialogEvent::ID) { |
| 51 return true; | 57 return true; |
| 52 } | 58 } |
| 53 return NPChannelBase::OnControlMessageReceived(msg); | 59 return NPChannelBase::OnControlMessageReceived(msg); |
| 54 } | 60 } |
| 55 | 61 |
| 56 } // namespace content | 62 } // namespace content |
| OLD | NEW |