| 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_dispatcher.h" | 5 #include "content/renderer/java/java_bridge_dispatcher.h" |
| 6 | 6 |
| 7 #include "content/child/child_process.h" | 7 #include "content/child/child_process.h" |
| 8 #include "content/child/npobject_util.h" // For CreateNPVariant() | 8 #include "content/child/npobject_util.h" // For CreateNPVariant() |
| 9 #include "content/common/java_bridge_messages.h" | 9 #include "content/common/java_bridge_messages.h" |
| 10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| 11 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 12 #include "content/renderer/java/java_bridge_channel.h" | 12 #include "content/renderer/java/java_bridge_channel.h" |
| 13 #include "third_party/WebKit/public/web/WebBindings.h" | 13 #include "third_party/WebKit/public/web/WebBindings.h" |
| 14 #include "third_party/WebKit/public/web/WebDocument.h" | 14 #include "third_party/WebKit/public/web/WebDocument.h" |
| 15 #include "third_party/WebKit/public/web/WebFrame.h" | 15 #include "third_party/WebKit/public/web/WebFrame.h" |
| 16 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 JavaBridgeDispatcher::JavaBridgeDispatcher(RenderView* render_view) | 20 JavaBridgeDispatcher::JavaBridgeDispatcher(RenderView* render_view) |
| 21 : RenderViewObserver(render_view), owner_id_(new struct _NPP) { | 21 : RenderViewObserver(render_view) { |
| 22 WebKit::WebBindings::registerObjectOwner(owner_id_.get()); | |
| 23 } | 22 } |
| 24 | 23 |
| 25 void JavaBridgeDispatcher::EnsureChannelIsSetUp() { | 24 void JavaBridgeDispatcher::EnsureChannelIsSetUp() { |
| 26 if (channel_.get()) { | 25 if (channel_.get()) { |
| 27 return; | 26 return; |
| 28 } | 27 } |
| 29 | 28 |
| 30 IPC::ChannelHandle channel_handle; | 29 IPC::ChannelHandle channel_handle; |
| 31 Send(new JavaBridgeHostMsg_GetChannelHandle(routing_id(), &channel_handle)); | 30 Send(new JavaBridgeHostMsg_GetChannelHandle(routing_id(), &channel_handle)); |
| 32 | 31 |
| 33 channel_ = JavaBridgeChannel::GetJavaBridgeChannel( | 32 channel_ = JavaBridgeChannel::GetJavaBridgeChannel( |
| 34 channel_handle, ChildProcess::current()->io_message_loop_proxy()); | 33 channel_handle, ChildProcess::current()->io_message_loop_proxy()); |
| 35 | |
| 36 // All objects received from the Browser process belong to us. | |
| 37 channel_->SetDefaultNPObjectOwner(owner_id_.get()); | |
| 38 } | 34 } |
| 39 | 35 |
| 40 JavaBridgeDispatcher::~JavaBridgeDispatcher() { | 36 JavaBridgeDispatcher::~JavaBridgeDispatcher() { |
| 41 for (ObjectMap::const_iterator iter = objects_.begin(); | 37 for (ObjectMap::const_iterator iter = objects_.begin(); |
| 42 iter != objects_.end(); ++iter) { | 38 iter != objects_.end(); ++iter) { |
| 43 WebKit::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); | 39 WebKit::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); |
| 44 } | 40 } |
| 45 | |
| 46 WebKit::WebBindings::unregisterObjectOwner(owner_id_.get()); | |
| 47 } | 41 } |
| 48 | 42 |
| 49 bool JavaBridgeDispatcher::OnMessageReceived(const IPC::Message& msg) { | 43 bool JavaBridgeDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 50 bool handled = true; | 44 bool handled = true; |
| 51 IPC_BEGIN_MESSAGE_MAP(JavaBridgeDispatcher, msg) | 45 IPC_BEGIN_MESSAGE_MAP(JavaBridgeDispatcher, msg) |
| 52 IPC_MESSAGE_HANDLER(JavaBridgeMsg_AddNamedObject, OnAddNamedObject) | 46 IPC_MESSAGE_HANDLER(JavaBridgeMsg_AddNamedObject, OnAddNamedObject) |
| 53 IPC_MESSAGE_HANDLER(JavaBridgeMsg_RemoveNamedObject, | 47 IPC_MESSAGE_HANDLER(JavaBridgeMsg_RemoveNamedObject, |
| 54 OnRemoveNamedObject) | 48 OnRemoveNamedObject) |
| 55 IPC_MESSAGE_UNHANDLED(handled = false) | 49 IPC_MESSAGE_UNHANDLED(handled = false) |
| 56 IPC_END_MESSAGE_MAP() | 50 IPC_END_MESSAGE_MAP() |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Removing an object does not unbind it from JavaScript until the window | 104 // Removing an object does not unbind it from JavaScript until the window |
| 111 // object is next cleared. Note that the browser checks that the named object | 105 // object is next cleared. Note that the browser checks that the named object |
| 112 // is present. | 106 // is present. |
| 113 ObjectMap::iterator iter = objects_.find(name); | 107 ObjectMap::iterator iter = objects_.find(name); |
| 114 DCHECK(iter != objects_.end()); | 108 DCHECK(iter != objects_.end()); |
| 115 WebKit::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); | 109 WebKit::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); |
| 116 objects_.erase(iter); | 110 objects_.erase(iter); |
| 117 } | 111 } |
| 118 | 112 |
| 119 } // namespace content | 113 } // namespace content |
| OLD | NEW |