Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: content/browser/renderer_host/java_bridge_dispatcher_host.cc

Issue 8525016: Move Java Bridge files to new java/ subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "content/browser/renderer_host/java_bridge_dispatcher_host.h"
6
7 #include "content/browser/renderer_host/browser_render_process_host.h"
8 #include "content/browser/renderer_host/java_bridge_channel_host.h"
9 #include "content/browser/renderer_host/render_view_host.h"
10 #include "content/common/child_process.h"
11 #include "content/common/java_bridge_messages.h"
12 #include "content/common/npobject_stub.h"
13 #include "content/common/npobject_util.h" // For CreateNPVariantParam()
14 #include "content/public/browser/browser_thread.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
16
17 using content::BrowserThread;
18
19 JavaBridgeDispatcherHost::JavaBridgeDispatcherHost(
20 RenderViewHost* render_view_host)
21 : render_view_host_(render_view_host) {
22 DCHECK(render_view_host_);
23 }
24
25 JavaBridgeDispatcherHost::~JavaBridgeDispatcherHost() {
26 }
27
28 void JavaBridgeDispatcherHost::AddNamedObject(const string16& name,
29 NPObject* object) {
30 // Post to the WEBKIT thread, as that's where we want injected objects to
31 // live.
32 WebKit::WebBindings::retainObject(object);
33 BrowserThread::PostTask(
34 BrowserThread::WEBKIT,
35 FROM_HERE,
36 NewRunnableMethod(this,
37 &JavaBridgeDispatcherHost::DoAddNamedObject,
38 name,
39 object));
40 }
41
42 void JavaBridgeDispatcherHost::RemoveNamedObject(const string16& name) {
43 // On receipt of this message, the JavaBridgeDispatcher will drop its
44 // reference to the corresponding proxy object. When the last reference is
45 // removed, the proxy object will delete its NPObjectProxy, which will cause
46 // the NPObjectStub to be deleted, which will drop its reference to the
47 // original NPObject.
48 render_view_host_->Send(new JavaBridgeMsg_RemoveNamedObject(
49 render_view_host_->routing_id(), name));
50 }
51
52 void JavaBridgeDispatcherHost::DoAddNamedObject(const string16& name,
53 NPObject* object) {
54 EnsureChannelIsSetUp();
55
56 NPVariant variant;
57 OBJECT_TO_NPVARIANT(object, variant);
58 DCHECK_EQ(variant.type, NPVariantType_Object);
59
60 // Create an NPVariantParam suitable for serialization over IPC from our
61 // NPVariant. Internally, this will create an NPObjectStub, which takes a
62 // reference to the underlying NPObject. We pass release = true to release
63 // the ref added in AddNamedObject(). We don't need the containing window or
64 // the page URL, as we don't do re-entrant sync IPC.
65 NPVariant_Param variant_param;
66 CreateNPVariantParam(variant, channel_, &variant_param, true, 0, GURL());
67 DCHECK_EQ(variant_param.type, NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID);
68
69 render_view_host_->Send(new JavaBridgeMsg_AddNamedObject(
70 render_view_host_->routing_id(), name, variant_param));
71 }
72
73 void JavaBridgeDispatcherHost::EnsureChannelIsSetUp() {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
75 if (channel_) {
76 return;
77 }
78
79 channel_ = JavaBridgeChannelHost::GetJavaBridgeChannelHost(
80 render_view_host_->process()->id(),
81 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
82
83 // The channel creates the channel handle based on the renderer ID we passed
84 // to GetJavaBridgeChannelHost() and, on POSIX, the file descriptor used by
85 // the underlying channel.
86 IPC::ChannelHandle channel_handle = channel_->channel_handle();
87
88 bool sent = render_view_host_->Send(new JavaBridgeMsg_Init(
89 render_view_host_->routing_id(), channel_handle));
90 DCHECK(sent);
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698