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/npapi/npobject_util.h" // For CreateNPVariant() | 8 #include "content/child/npapi/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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 IPC::ChannelHandle channel_handle; | 29 IPC::ChannelHandle channel_handle; |
30 Send(new JavaBridgeHostMsg_GetChannelHandle(routing_id(), &channel_handle)); | 30 Send(new JavaBridgeHostMsg_GetChannelHandle(routing_id(), &channel_handle)); |
31 | 31 |
32 channel_ = JavaBridgeChannel::GetJavaBridgeChannel( | 32 channel_ = JavaBridgeChannel::GetJavaBridgeChannel( |
33 channel_handle, ChildProcess::current()->io_message_loop_proxy()); | 33 channel_handle, ChildProcess::current()->io_message_loop_proxy()); |
34 } | 34 } |
35 | 35 |
36 JavaBridgeDispatcher::~JavaBridgeDispatcher() { | 36 JavaBridgeDispatcher::~JavaBridgeDispatcher() { |
37 for (ObjectMap::const_iterator iter = objects_.begin(); | 37 for (ObjectMap::const_iterator iter = objects_.begin(); |
38 iter != objects_.end(); ++iter) { | 38 iter != objects_.end(); ++iter) { |
39 WebKit::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); | 39 blink::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 bool JavaBridgeDispatcher::OnMessageReceived(const IPC::Message& msg) { | 43 bool JavaBridgeDispatcher::OnMessageReceived(const IPC::Message& msg) { |
44 bool handled = true; | 44 bool handled = true; |
45 IPC_BEGIN_MESSAGE_MAP(JavaBridgeDispatcher, msg) | 45 IPC_BEGIN_MESSAGE_MAP(JavaBridgeDispatcher, msg) |
46 IPC_MESSAGE_HANDLER(JavaBridgeMsg_AddNamedObject, OnAddNamedObject) | 46 IPC_MESSAGE_HANDLER(JavaBridgeMsg_AddNamedObject, OnAddNamedObject) |
47 IPC_MESSAGE_HANDLER(JavaBridgeMsg_RemoveNamedObject, | 47 IPC_MESSAGE_HANDLER(JavaBridgeMsg_RemoveNamedObject, |
48 OnRemoveNamedObject) | 48 OnRemoveNamedObject) |
49 IPC_MESSAGE_UNHANDLED(handled = false) | 49 IPC_MESSAGE_UNHANDLED(handled = false) |
50 IPC_END_MESSAGE_MAP() | 50 IPC_END_MESSAGE_MAP() |
51 return handled; | 51 return handled; |
52 } | 52 } |
53 | 53 |
54 void JavaBridgeDispatcher::DidClearWindowObject(WebKit::WebFrame* web_frame) { | 54 void JavaBridgeDispatcher::DidClearWindowObject(blink::WebFrame* web_frame) { |
55 // Note that we have to (re)bind all objects, as they will have been unbound | 55 // Note that we have to (re)bind all objects, as they will have been unbound |
56 // when the window object was cleared. | 56 // when the window object was cleared. |
57 for (ObjectMap::const_iterator iter = objects_.begin(); | 57 for (ObjectMap::const_iterator iter = objects_.begin(); |
58 iter != objects_.end(); ++iter) { | 58 iter != objects_.end(); ++iter) { |
59 // This refs the NPObject. This reference is dropped when either the window | 59 // This refs the NPObject. This reference is dropped when either the window |
60 // object is later cleared, or the object is GC'ed. So the object may be | 60 // object is later cleared, or the object is GC'ed. So the object may be |
61 // deleted at any time after OnRemoveNamedObject() is called. | 61 // deleted at any time after OnRemoveNamedObject() is called. |
62 web_frame->bindToWindowObject(iter->first, | 62 web_frame->bindToWindowObject(iter->first, |
63 NPVARIANT_TO_OBJECT(iter->second)); | 63 NPVARIANT_TO_OBJECT(iter->second)); |
64 } | 64 } |
(...skipping 18 matching lines...) Expand all Loading... |
83 NPVariant variant; | 83 NPVariant variant; |
84 bool created = | 84 bool created = |
85 CreateNPVariant(variant_param, channel_.get(), &variant, 0, GURL()); | 85 CreateNPVariant(variant_param, channel_.get(), &variant, 0, GURL()); |
86 DCHECK(created); | 86 DCHECK(created); |
87 DCHECK_EQ(variant.type, NPVariantType_Object); | 87 DCHECK_EQ(variant.type, NPVariantType_Object); |
88 | 88 |
89 // The NPObject is created with a ref count of one, which we remove when | 89 // The NPObject is created with a ref count of one, which we remove when |
90 // OnRemoveNamedObject() is called for that object. | 90 // OnRemoveNamedObject() is called for that object. |
91 ObjectMap::iterator iter = objects_.find(name); | 91 ObjectMap::iterator iter = objects_.find(name); |
92 if (iter != objects_.end()) { | 92 if (iter != objects_.end()) { |
93 WebKit::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); | 93 blink::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); |
94 } | 94 } |
95 objects_[name] = variant; | 95 objects_[name] = variant; |
96 } | 96 } |
97 | 97 |
98 void JavaBridgeDispatcher::OnRemoveNamedObject(const string16& name) { | 98 void JavaBridgeDispatcher::OnRemoveNamedObject(const string16& name) { |
99 if (!channel_.get()) { | 99 if (!channel_.get()) { |
100 DCHECK(objects_.empty()); | 100 DCHECK(objects_.empty()); |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 // 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 |
105 // 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 |
106 // is present. | 106 // is present. |
107 ObjectMap::iterator iter = objects_.find(name); | 107 ObjectMap::iterator iter = objects_.find(name); |
108 DCHECK(iter != objects_.end()); | 108 DCHECK(iter != objects_.end()); |
109 WebKit::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); | 109 blink::WebBindings::releaseObject(NPVARIANT_TO_OBJECT(iter->second)); |
110 objects_.erase(iter); | 110 objects_.erase(iter); |
111 } | 111 } |
112 | 112 |
113 } // namespace content | 113 } // namespace content |
OLD | NEW |