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 #ifndef CONTENT_RENDERER_JAVA_JAVA_BRIDGE_DISPATCHER_H_
6 #define CONTENT_RENDERER_JAVA_JAVA_BRIDGE_DISPATCHER_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h"
12 #include "content/public/renderer/render_frame_observer.h"
13 #include "ipc/ipc_channel_handle.h"
14 #include "third_party/npapi/bindings/npruntime.h"
17 class JavaBridgeChannel;
18 struct NPVariant_Param;
20 // This class handles injecting Java objects into the main frame of a
21 // RenderView. The 'add' and 'remove' messages received from the browser
22 // process modify the entries in a map of 'pending' objects. These objects are
23 // bound to the window object of the main frame when that window object is next
24 // cleared. These objects remain bound until the window object is cleared
26 class JavaBridgeDispatcher : public RenderFrameObserver {
28 JavaBridgeDispatcher(RenderFrame* render_frame);
29 virtual ~JavaBridgeDispatcher();
32 // RenderViewObserver override:
33 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
34 virtual void DidClearWindowObject() OVERRIDE;
37 void OnAddNamedObject(const base::string16& name,
38 const NPVariant_Param& variant_param);
39 void OnRemoveNamedObject(const base::string16& name);
41 void EnsureChannelIsSetUp();
43 // Objects that will be bound to the window when the window object is next
44 // cleared. We hold a ref to these.
45 typedef std::map<base::string16, NPVariant> ObjectMap;
47 scoped_refptr<JavaBridgeChannel> channel_;
50 } // namespace content
52 #endif // CONTENT_RENDERER_JAVA_JAVA_BRIDGE_DISPATCHER_H_