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
3 // found in the LICENSE file.
5 #include "content/renderer/java/java_bridge_channel.h"
7 #include "content/child/child_process.h"
8 #include "content/child/plugin_messages.h"
9 #include "content/common/java_bridge_messages.h"
10 #include "third_party/WebKit/public/web/WebBindings.h"
14 JavaBridgeChannel
* JavaBridgeChannel::GetJavaBridgeChannel(
15 const IPC::ChannelHandle
& channel_handle
,
16 base::MessageLoopProxy
* ipc_message_loop
) {
17 return static_cast<JavaBridgeChannel
*>(NPChannelBase::GetChannel(
19 IPC::Channel::MODE_CLIENT
,
23 ChildProcess::current()->GetShutDownEvent()));
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 blink::WebBindings::registerObjectOwner(peer_owner_id_
.get());
31 SetDefaultNPObjectOwner(peer_owner_id_
.get());
34 JavaBridgeChannel::~JavaBridgeChannel() {
35 blink::WebBindings::unregisterObjectOwner(peer_owner_id_
.get());
38 int JavaBridgeChannel::GenerateRouteID() {
39 // Use a control message as this going to the JavaBridgeChannelHost, not an
41 int route_id
= MSG_ROUTING_NONE
;
42 Send(new JavaBridgeMsg_GenerateRouteID(&route_id
));
43 // This should never fail, as the JavaBridgeChannelHost should always outlive
45 DCHECK_NE(MSG_ROUTING_NONE
, route_id
);
49 bool JavaBridgeChannel::OnControlMessageReceived(const IPC::Message
& msg
) {
50 // We need to intercept these two message types because the default
51 // implementation of NPChannelBase::OnControlMessageReceived() is to
52 // DCHECK(false). However, we don't need to do anything, as we don't need to
53 // worry about the window system hanging when a modal dialog is displayed.
54 // This is because, unlike in the case of plugins, the host does not need to
55 // pump the message queue to avoid hangs.
56 if (msg
.type() == PluginMsg_SignalModalDialogEvent::ID
||
57 msg
.type() == PluginMsg_ResetModalDialogEvent::ID
) {
60 return NPChannelBase::OnControlMessageReceived(msg
);
63 } // namespace content