OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_GUEST_TO_EMBEDDER_CHANNEL_H_ | |
6 #define CONTENT_RENDERER_BROWSER_PLUGIN_GUEST_TO_EMBEDDER_CHANNEL_H_ | |
7 #pragma once | |
8 | |
9 #include "base/memory/ref_counted.h" | |
10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | |
11 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" | |
12 #include "content/renderer/render_view_impl.h" | |
13 #include "ipc/ipc_channel_handle.h" | |
14 #include "ppapi/c/pp_bool.h" | |
15 #include "ppapi/c/pp_instance.h" | |
16 #include "ppapi/shared_impl/ppb_view_shared.h" | |
17 #include "ppapi/proxy/plugin_dispatcher.h" | |
18 #include "ppapi/proxy/serialized_var.h" | |
19 #include "ppapi/shared_impl/host_resource.h" | |
20 #include "ppapi/shared_impl/ppapi_preferences.h" | |
21 #include "ppapi/shared_impl/ppb_input_event_shared.h" | |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC
ontext3D.h" | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
24 | |
25 namespace content { | |
26 | |
27 class BrowserPluginChannelManager; | |
28 | |
29 // GuestToEmbedderChannel is a Dispatcher that sends and receives ppapi messages | |
30 // from the browser plugin embedder. It is reference counted because it is held | |
31 // by a RenderViewImpl which (indirectly) owns a PpapiCommandBufferProxy through | |
32 // a WebGraphicsContext3DCommandBufferImpl which is owned by WebKit. Since the | |
33 // lifetime of this context is less than the lifetime of the RenderViewImpl, we | |
34 // keep the GuestToEmbedderChannel alive as long as a RenderViewImpl has access | |
35 // to it. If the context is lost, then the PpapiCommandBufferProxy is destroyed | |
36 // and we can safely release the reference to this GuestToEmbedderChannel held | |
37 // by RenderViewImpl. | |
38 class GuestToEmbedderChannel | |
39 : public ppapi::proxy::Dispatcher, | |
40 public base::RefCounted<GuestToEmbedderChannel> { | |
41 public: | |
42 GuestToEmbedderChannel( | |
43 const std::string& embedder_channel_name, | |
44 const IPC::ChannelHandle& embedder_channel_handle); | |
45 | |
46 // This must be called before anything else. Returns true on success. | |
47 bool InitChannel(const IPC::ChannelHandle& channel_handle); | |
48 | |
49 // Creates a new WebGraphicsContext3DCommandBufferImpl and returns it. | |
50 WebGraphicsContext3DCommandBufferImpl* CreateWebGraphicsContext3D( | |
51 RenderViewImpl* render_view, | |
52 const WebKit::WebGraphicsContext3D::Attributes& attributes, | |
53 bool offscreen); | |
54 | |
55 // Inform the host to invalidate its plugin container after a swap buffer. | |
56 void IssueSwapBuffers(const ppapi::HostResource& resource); | |
57 | |
58 // Request the receipt of events from the embedder renderer. | |
59 void RequestInputEvents(PP_Instance instance); | |
60 | |
61 // Request a graphics context from the embedder renderer. | |
62 bool CreateGraphicsContext( | |
63 WebGraphicsContext3DCommandBufferImpl* context, | |
64 const WebKit::WebGraphicsContext3D::Attributes& attributes, | |
65 bool offscreen, | |
66 RenderViewImpl* render_view); | |
67 | |
68 // Register the given RenderView with the given PP_Instance. | |
69 void AddGuest(PP_Instance instance, RenderViewImpl* render_view); | |
70 | |
71 // Removes the guest with the given instance identifier from the | |
72 // InstanceMap. | |
73 void RemoveGuest(PP_Instance instance); | |
74 | |
75 const std::string& embedder_channel_name() const { | |
76 return embedder_channel_name_; | |
77 } | |
78 | |
79 const IPC::ChannelHandle& embedder_channel_handle() const { | |
80 return embedder_channel_handle_; | |
81 } | |
82 | |
83 // ppapi::proxy::Dispatcher implementation. | |
84 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | |
85 virtual bool Send(IPC::Message* message) OVERRIDE; | |
86 virtual void OnChannelError() OVERRIDE; | |
87 virtual bool IsPlugin() const OVERRIDE; | |
88 | |
89 private: | |
90 friend class base::RefCounted<GuestToEmbedderChannel>; | |
91 typedef std::map<PP_Instance, base::WeakPtr<RenderViewImpl> > InstanceMap; | |
92 typedef std::map<int, int> RoutingIDToInstanceMap; | |
93 | |
94 virtual ~GuestToEmbedderChannel(); | |
95 | |
96 void OnSupportsInterface(const std::string& interface_name, bool* result); | |
97 void OnSetPreferences(const ppapi::Preferences& prefs); | |
98 void OnReserveInstanceId(PP_Instance instance, bool* usable); | |
99 void OnDidCreate(PP_Instance instance, | |
100 const std::vector<std::string>& argn, | |
101 const std::vector<std::string>& argv, | |
102 PP_Bool* result); | |
103 void OnDidDestroy(PP_Instance instance); | |
104 void OnDidChangeView(PP_Instance instance, | |
105 const ppapi::ViewData& new_data, | |
106 PP_Bool flash_fullscreen); | |
107 void OnDidChangeFocus(PP_Instance instance, PP_Bool has_focus); | |
108 void OnGetInstanceObject(PP_Instance instance, | |
109 ppapi::proxy::SerializedVarReturnValue result); | |
110 | |
111 void OnHandleMessage(PP_Instance instance, | |
112 ppapi::proxy::SerializedVarReceiveInput data); | |
113 | |
114 void OnHandleFilteredInputEvent(PP_Instance instance, | |
115 const ppapi::InputEventData& data, | |
116 PP_Bool* result); | |
117 | |
118 void OnSwapBuffersACK(const ppapi::HostResource& context, | |
119 int32_t pp_error); | |
120 | |
121 void OnContextLost(PP_Instance instance); | |
122 | |
123 void OnGuestReady(PP_Instance instance, int embedder_container_id); | |
124 | |
125 base::WeakPtr<RenderViewImpl> render_view_; | |
126 std::string embedder_channel_name_; | |
127 IPC::ChannelHandle embedder_channel_handle_; | |
128 PepperProxyChannelDelegateImpl delegate_; | |
129 | |
130 InstanceMap render_view_instances_; | |
131 RoutingIDToInstanceMap routing_id_instance_map_; | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(GuestToEmbedderChannel); | |
134 }; | |
135 | |
136 } // namespace content | |
137 | |
138 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_GUEST_TO_EMBEDDER_CHANNEL_H_ | |
OLD | NEW |