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_PLUGIN_WEBPLUGIN_PROXY_H_
6 #define CONTENT_PLUGIN_WEBPLUGIN_PROXY_H_
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h"
12 #if defined(OS_MACOSX)
13 #include "base/mac/scoped_cftyperef.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/shared_memory.h"
17 #include "base/memory/weak_ptr.h"
18 #include "content/child/npapi/webplugin.h"
19 #include "ipc/ipc_message.h"
20 #include "ipc/ipc_sender.h"
21 #include "skia/ext/refptr.h"
22 #include "third_party/skia/include/core/SkCanvas.h"
24 #include "ui/gl/gpu_preference.h"
25 #include "ui/surface/transport_dib.h"
27 struct PluginMsg_FetchURL_Params
;
31 class WebPluginDelegateImpl
;
33 #if defined(OS_MACOSX)
34 class WebPluginAcceleratedSurfaceProxy
;
37 // This is an implementation of WebPlugin that proxies all calls to the
39 class WebPluginProxy
: public WebPlugin
,
42 // Creates a new proxy for WebPlugin, using the given sender to send the
43 // marshalled WebPlugin calls.
44 WebPluginProxy(PluginChannel
* channel
,
47 int host_render_view_routing_id
);
48 ~WebPluginProxy() override
;
50 void set_delegate(WebPluginDelegateImpl
* d
) { delegate_
= d
; }
52 // WebPlugin overrides
53 void SetWindow(gfx::PluginWindowHandle window
) override
;
54 void SetAcceptsInputEvents(bool accepts
) override
;
55 void WillDestroyWindow(gfx::PluginWindowHandle window
) override
;
56 void CancelResource(unsigned long id
) override
;
57 void Invalidate() override
;
58 void InvalidateRect(const gfx::Rect
& rect
) override
;
59 NPObject
* GetWindowScriptNPObject() override
;
60 NPObject
* GetPluginElement() override
;
61 bool FindProxyForUrl(const GURL
& url
, std::string
* proxy_list
) override
;
62 void SetCookie(const GURL
& url
,
63 const GURL
& first_party_for_cookies
,
64 const std::string
& cookie
) override
;
65 std::string
GetCookies(const GURL
& url
,
66 const GURL
& first_party_for_cookies
) override
;
67 void HandleURLRequest(const char* url
,
74 bool notify_redirects
) override
;
75 void UpdateGeometry(const gfx::Rect
& window_rect
,
76 const gfx::Rect
& clip_rect
,
77 const TransportDIB::Handle
& windowless_buffer0
,
78 const TransportDIB::Handle
& windowless_buffer1
,
79 int windowless_buffer_index
);
80 void CancelDocumentLoad() override
;
81 void InitiateHTTPRangeRequest(const char* url
,
82 const char* range_info
,
83 int range_request_id
) override
;
84 void DidStartLoading() override
;
85 void DidStopLoading() override
;
86 void SetDeferResourceLoading(unsigned long resource_id
, bool defer
) override
;
87 bool IsOffTheRecord() override
;
88 void ResourceClientDeleted(WebPluginResourceClient
* resource_client
) override
;
89 void URLRedirectResponse(bool allow
, int resource_id
) override
;
90 bool CheckIfRunInsecureContent(const GURL
& url
) override
;
92 void SetWindowlessData(HANDLE pump_messages_event
,
93 gfx::NativeViewId dummy_activation_window
);
95 #if defined(OS_MACOSX)
96 void FocusChanged(bool focused
) override
;
97 void StartIme() override
;
98 WebPluginAcceleratedSurface
* GetAcceleratedSurface(
99 gfx::GpuPreference gpu_preference
) override
;
100 void AcceleratedPluginEnabledRendering() override
;
101 void AcceleratedPluginAllocatedIOSurface(int32 width
,
103 uint32 surface_id
) override
;
104 void AcceleratedPluginSwappedIOSurface() override
;
107 // IPC::Sender implementation.
108 bool Send(IPC::Message
* msg
) override
;
110 // class-specific methods
112 // Returns a WebPluginResourceClient object given its id, or NULL if no
113 // object with that id exists.
114 WebPluginResourceClient
* GetResourceClient(int id
);
116 // Returns the id of the renderer that contains this plugin.
119 // Returns the id of the associated render view.
120 int host_render_view_routing_id() const {
121 return host_render_view_routing_id_
;
124 // For windowless plugins, paints the given rectangle into the local buffer.
125 void Paint(const gfx::Rect
& rect
);
127 // Callback from the renderer to let us know that a paint occurred.
130 // Notification received on a plugin issued resource request creation.
131 void OnResourceCreated(int resource_id
, WebPluginResourceClient
* client
);
133 #if defined(OS_WIN) && !defined(USE_AURA)
134 // Retrieves the IME status from a windowless plug-in and sends it to a
135 // renderer process. A renderer process will convert the coordinates from
136 // local to the window coordinates and send the converted coordinates to a
138 void UpdateIMEStatus();
142 class SharedTransportDIB
: public base::RefCounted
<SharedTransportDIB
> {
144 explicit SharedTransportDIB(TransportDIB
* dib
);
145 TransportDIB
* dib() { return dib_
.get(); }
147 friend class base::RefCounted
<SharedTransportDIB
>;
148 ~SharedTransportDIB();
150 scoped_ptr
<TransportDIB
> dib_
;
153 // Handler for sending over the paint event to the plugin.
154 void OnPaint(const gfx::Rect
& damaged_rect
);
157 void CreateCanvasFromHandle(const TransportDIB::Handle
& dib_handle
,
158 const gfx::Rect
& window_rect
,
159 skia::RefPtr
<SkCanvas
>* canvas
);
160 #elif defined(OS_MACOSX)
161 static void CreateDIBAndCGContextFromHandle(
162 const TransportDIB::Handle
& dib_handle
,
163 const gfx::Rect
& window_rect
,
164 scoped_ptr
<TransportDIB
>* dib_out
,
165 base::ScopedCFTypeRef
<CGContextRef
>* cg_context_out
);
168 // Updates the shared memory sections where windowless plugins paint.
169 void SetWindowlessBuffers(const TransportDIB::Handle
& windowless_buffer0
,
170 const TransportDIB::Handle
& windowless_buffer1
,
171 const gfx::Rect
& window_rect
);
173 #if defined(OS_MACOSX)
174 CGContextRef
windowless_context() const {
175 return windowless_contexts_
[windowless_buffer_index_
].get();
178 skia::RefPtr
<SkCanvas
> windowless_canvas() const {
179 return windowless_canvases_
[windowless_buffer_index_
];
183 typedef base::hash_map
<int, WebPluginResourceClient
*> ResourceClientMap
;
184 ResourceClientMap resource_clients_
;
186 scoped_refptr
<PluginChannel
> channel_
;
188 NPObject
* window_npobject_
;
189 NPObject
* plugin_element_
;
190 WebPluginDelegateImpl
* delegate_
;
191 gfx::Rect damaged_rect_
;
192 bool waiting_for_paint_
;
193 // The url of the main frame hosting the plugin.
196 // Variables used for desynchronized windowless plugin painting. See note in
197 // webplugin_delegate_proxy.h for how this works. The two sets of windowless_*
198 // fields are for the front-buffer and back-buffer of a buffer flipping system
199 // and windowless_buffer_index_ identifies which set we are using as the
200 // back-buffer at any given time.
201 int windowless_buffer_index_
;
202 #if defined(OS_MACOSX)
203 scoped_ptr
<TransportDIB
> windowless_dibs_
[2];
204 base::ScopedCFTypeRef
<CGContextRef
> windowless_contexts_
[2];
205 scoped_ptr
<WebPluginAcceleratedSurfaceProxy
> accelerated_surface_
;
207 skia::RefPtr
<SkCanvas
> windowless_canvases_
[2];
210 // Contains the routing id of the host render view.
211 int host_render_view_routing_id_
;
213 base::WeakPtrFactory
<WebPluginProxy
> weak_factory_
;
216 } // namespace content
218 #endif // CONTENT_PLUGIN_WEBPLUGIN_PROXY_H_