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_handle.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/shared_memory.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/timer/timer.h"
20 #include "content/child/npapi/webplugin.h"
21 #include "ipc/ipc_message.h"
22 #include "ipc/ipc_sender.h"
23 #include "skia/ext/refptr.h"
24 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "ui/gl/gpu_preference.h"
27 #include "ui/surface/transport_dib.h"
29 struct PluginMsg_FetchURL_Params
;
33 class WebPluginDelegateImpl
;
35 #if defined(OS_MACOSX)
36 class WebPluginAcceleratedSurfaceProxy
;
39 // This is an implementation of WebPlugin that proxies all calls to the
41 class WebPluginProxy
: public WebPlugin
,
44 // Creates a new proxy for WebPlugin, using the given sender to send the
45 // marshalled WebPlugin calls.
46 WebPluginProxy(PluginChannel
* channel
,
49 int host_render_view_routing_id
);
50 virtual ~WebPluginProxy();
52 void set_delegate(WebPluginDelegateImpl
* d
) { delegate_
= d
; }
54 // WebPlugin overrides
55 virtual void SetWindow(gfx::PluginWindowHandle window
) OVERRIDE
;
56 virtual void SetAcceptsInputEvents(bool accepts
) OVERRIDE
;
57 virtual void WillDestroyWindow(gfx::PluginWindowHandle window
) OVERRIDE
;
58 virtual void CancelResource(unsigned long id
) OVERRIDE
;
59 virtual void Invalidate() OVERRIDE
;
60 virtual void InvalidateRect(const gfx::Rect
& rect
) OVERRIDE
;
61 virtual NPObject
* GetWindowScriptNPObject() OVERRIDE
;
62 virtual NPObject
* GetPluginElement() OVERRIDE
;
63 virtual bool FindProxyForUrl(const GURL
& url
,
64 std::string
* proxy_list
) OVERRIDE
;
65 virtual void SetCookie(const GURL
& url
,
66 const GURL
& first_party_for_cookies
,
67 const std::string
& cookie
) OVERRIDE
;
68 virtual std::string
GetCookies(const GURL
& url
,
69 const GURL
& first_party_for_cookies
) OVERRIDE
;
70 virtual void HandleURLRequest(const char* url
,
77 bool notify_redirects
) OVERRIDE
;
78 void UpdateGeometry(const gfx::Rect
& window_rect
,
79 const gfx::Rect
& clip_rect
,
80 const TransportDIB::Handle
& windowless_buffer0
,
81 const TransportDIB::Handle
& windowless_buffer1
,
82 int windowless_buffer_index
);
83 virtual void CancelDocumentLoad() OVERRIDE
;
84 virtual void InitiateHTTPRangeRequest(
85 const char* url
, const char* range_info
, int range_request_id
) OVERRIDE
;
86 virtual void DidStartLoading() OVERRIDE
;
87 virtual void DidStopLoading() OVERRIDE
;
88 virtual void SetDeferResourceLoading(unsigned long resource_id
,
90 virtual bool IsOffTheRecord() OVERRIDE
;
91 virtual void ResourceClientDeleted(
92 WebPluginResourceClient
* resource_client
) OVERRIDE
;
93 virtual void URLRedirectResponse(bool allow
, int resource_id
) OVERRIDE
;
94 virtual bool CheckIfRunInsecureContent(const GURL
& url
) OVERRIDE
;
96 void SetWindowlessData(HANDLE pump_messages_event
,
97 gfx::NativeViewId dummy_activation_window
);
99 #if defined(OS_MACOSX)
100 virtual void FocusChanged(bool focused
) OVERRIDE
;
101 virtual void StartIme() OVERRIDE
;
102 virtual WebPluginAcceleratedSurface
*
103 GetAcceleratedSurface(gfx::GpuPreference gpu_preference
) OVERRIDE
;
104 virtual void AcceleratedPluginEnabledRendering() OVERRIDE
;
105 virtual void AcceleratedPluginAllocatedIOSurface(int32 width
,
107 uint32 surface_id
) OVERRIDE
;
108 virtual void AcceleratedPluginSwappedIOSurface() OVERRIDE
;
111 // IPC::Sender implementation.
112 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
114 // class-specific methods
116 // Returns a WebPluginResourceClient object given its id, or NULL if no
117 // object with that id exists.
118 WebPluginResourceClient
* GetResourceClient(int id
);
120 // Returns the id of the renderer that contains this plugin.
123 // Returns the id of the associated render view.
124 int host_render_view_routing_id() const {
125 return host_render_view_routing_id_
;
128 // For windowless plugins, paints the given rectangle into the local buffer.
129 void Paint(const gfx::Rect
& rect
);
131 // Callback from the renderer to let us know that a paint occurred.
134 // Notification received on a plugin issued resource request creation.
135 void OnResourceCreated(int resource_id
, WebPluginResourceClient
* client
);
137 #if defined(OS_WIN) && !defined(USE_AURA)
138 // Retrieves the IME status from a windowless plug-in and sends it to a
139 // renderer process. A renderer process will convert the coordinates from
140 // local to the window coordinates and send the converted coordinates to a
142 void UpdateIMEStatus();
146 class SharedTransportDIB
: public base::RefCounted
<SharedTransportDIB
> {
148 explicit SharedTransportDIB(TransportDIB
* dib
);
149 TransportDIB
* dib() { return dib_
.get(); }
151 friend class base::RefCounted
<SharedTransportDIB
>;
152 ~SharedTransportDIB();
154 scoped_ptr
<TransportDIB
> dib_
;
157 // Handler for sending over the paint event to the plugin.
158 void OnPaint(const gfx::Rect
& damaged_rect
);
161 void CreateCanvasFromHandle(const TransportDIB::Handle
& dib_handle
,
162 const gfx::Rect
& window_rect
,
163 skia::RefPtr
<SkCanvas
>* canvas
);
164 #elif defined(OS_MACOSX)
165 static void CreateDIBAndCGContextFromHandle(
166 const TransportDIB::Handle
& dib_handle
,
167 const gfx::Rect
& window_rect
,
168 scoped_ptr
<TransportDIB
>* dib_out
,
169 base::ScopedCFTypeRef
<CGContextRef
>* cg_context_out
);
172 // Updates the shared memory sections where windowless plugins paint.
173 void SetWindowlessBuffers(const TransportDIB::Handle
& windowless_buffer0
,
174 const TransportDIB::Handle
& windowless_buffer1
,
175 const gfx::Rect
& window_rect
);
177 #if defined(OS_MACOSX)
178 CGContextRef
windowless_context() const {
179 return windowless_contexts_
[windowless_buffer_index_
].get();
182 skia::RefPtr
<SkCanvas
> windowless_canvas() const {
183 return windowless_canvases_
[windowless_buffer_index_
];
187 typedef base::hash_map
<int, WebPluginResourceClient
*> ResourceClientMap
;
188 ResourceClientMap resource_clients_
;
190 scoped_refptr
<PluginChannel
> channel_
;
192 NPObject
* window_npobject_
;
193 NPObject
* plugin_element_
;
194 WebPluginDelegateImpl
* delegate_
;
195 gfx::Rect damaged_rect_
;
196 bool waiting_for_paint_
;
197 // The url of the main frame hosting the plugin.
200 // Variables used for desynchronized windowless plugin painting. See note in
201 // webplugin_delegate_proxy.h for how this works. The two sets of windowless_*
202 // fields are for the front-buffer and back-buffer of a buffer flipping system
203 // and windowless_buffer_index_ identifies which set we are using as the
204 // back-buffer at any given time.
205 int windowless_buffer_index_
;
206 #if defined(OS_MACOSX)
207 scoped_ptr
<TransportDIB
> windowless_dibs_
[2];
208 base::ScopedCFTypeRef
<CGContextRef
> windowless_contexts_
[2];
209 scoped_ptr
<WebPluginAcceleratedSurfaceProxy
> accelerated_surface_
;
211 skia::RefPtr
<SkCanvas
> windowless_canvases_
[2];
214 // Contains the routing id of the host render view.
215 int host_render_view_routing_id_
;
217 base::WeakPtrFactory
<WebPluginProxy
> weak_factory_
;
220 } // namespace content
222 #endif // CONTENT_PLUGIN_WEBPLUGIN_PROXY_H_