| 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/browser/renderer_host/java/java_bridge_dispatcher_host.h" | 5 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "content/browser/renderer_host/java/java_bridge_channel_host.h" | 10 #include "content/browser/renderer_host/java/java_bridge_channel_host.h" |
| 11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 12 #include "content/common/child_process.h" | 12 #include "content/common/child_process.h" |
| 13 #include "content/common/java_bridge_messages.h" | 13 #include "content/common/java_bridge_messages.h" |
| 14 #include "content/common/npobject_stub.h" | 14 #include "content/common/npobject_stub.h" |
| 15 #include "content/common/npobject_util.h" // For CreateNPVariantParam() | 15 #include "content/common/npobject_util.h" // For CreateNPVariantParam() |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 namespace content { |
| 21 using content::NPObjectStub; | |
| 22 using content::NPVariant_Param; | |
| 23 using content::RenderViewHost; | |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 class JavaBridgeThread : public base::Thread { | 23 class JavaBridgeThread : public base::Thread { |
| 27 public: | 24 public: |
| 28 JavaBridgeThread() : base::Thread("JavaBridge") { | 25 JavaBridgeThread() : base::Thread("JavaBridge") { |
| 29 Start(); | 26 Start(); |
| 30 } | 27 } |
| 31 virtual ~JavaBridgeThread() { | 28 virtual ~JavaBridgeThread() { |
| 32 Stop(); | 29 Stop(); |
| 33 } | 30 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // that is where Java objects will live, and CreateNPVariantParam() needs the | 106 // that is where Java objects will live, and CreateNPVariantParam() needs the |
| 110 // channel to create the NPObjectStub. To avoid blocking here until the | 107 // channel to create the NPObjectStub. To avoid blocking here until the |
| 111 // channel is ready, create the NPVariant_Param by hand, then post a message | 108 // channel is ready, create the NPVariant_Param by hand, then post a message |
| 112 // to the background thread to set up the channel and create the corresponding | 109 // to the background thread to set up the channel and create the corresponding |
| 113 // NPObjectStub. Post that message before doing any IPC, to make sure that | 110 // NPObjectStub. Post that message before doing any IPC, to make sure that |
| 114 // the channel and object proxies are ready before responses are received | 111 // the channel and object proxies are ready before responses are received |
| 115 // from the renderer. | 112 // from the renderer. |
| 116 | 113 |
| 117 // Create an NPVariantParam suitable for serialization over IPC from our | 114 // Create an NPVariantParam suitable for serialization over IPC from our |
| 118 // NPVariant. See CreateNPVariantParam() in npobject_utils. | 115 // NPVariant. See CreateNPVariantParam() in npobject_utils. |
| 119 param->type = content::NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID; | 116 param->type = NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID; |
| 120 int route_id = JavaBridgeChannelHost::ThreadsafeGenerateRouteID(); | 117 int route_id = JavaBridgeChannelHost::ThreadsafeGenerateRouteID(); |
| 121 param->npobject_routing_id = route_id; | 118 param->npobject_routing_id = route_id; |
| 122 | 119 |
| 123 WebKit::WebBindings::retainObject(object); | 120 WebKit::WebBindings::retainObject(object); |
| 124 g_background_thread.Get().message_loop()->PostTask( | 121 g_background_thread.Get().message_loop()->PostTask( |
| 125 FROM_HERE, | 122 FROM_HERE, |
| 126 base::Bind(&JavaBridgeDispatcherHost::CreateObjectStub, this, object, | 123 base::Bind(&JavaBridgeDispatcherHost::CreateObjectStub, this, object, |
| 127 route_id)); | 124 route_id)); |
| 128 } | 125 } |
| 129 | 126 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 // is governed by that of the NPObjectProxy in the renderer, via the channel. | 137 // is governed by that of the NPObjectProxy in the renderer, via the channel. |
| 141 // Pass 0 for the containing window, as it's only used by plugins to pump the | 138 // Pass 0 for the containing window, as it's only used by plugins to pump the |
| 142 // window message queue when a method on a renderer-side object causes a | 139 // window message queue when a method on a renderer-side object causes a |
| 143 // dialog to be displayed, and the Java Bridge does not need this | 140 // dialog to be displayed, and the Java Bridge does not need this |
| 144 // functionality. The page URL is also not required. | 141 // functionality. The page URL is also not required. |
| 145 new NPObjectStub(object, channel_, route_id, 0, GURL()); | 142 new NPObjectStub(object, channel_, route_id, 0, GURL()); |
| 146 // The NPObjectStub takes a reference to the NPObject. Release the ref added | 143 // The NPObjectStub takes a reference to the NPObject. Release the ref added |
| 147 // in CreateNPVariantParam(). | 144 // in CreateNPVariantParam(). |
| 148 WebKit::WebBindings::releaseObject(object); | 145 WebKit::WebBindings::releaseObject(object); |
| 149 } | 146 } |
| 147 |
| 148 } // namespace content |
| OLD | NEW |