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 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/child/npapi/webplugin.h"
15 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_sender.h"
17 #include "skia/ext/refptr.h"
18 #include "third_party/skia/include/core/SkCanvas.h"
20 #include "ui/gl/gpu_preference.h"
21 #include "ui/surface/transport_dib.h"
23 #if defined(OS_MACOSX)
24 #include <ApplicationServices/ApplicationServices.h>
26 #include "base/mac/scoped_cftyperef.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 ~WebPluginProxy() override
;
52 void set_delegate(WebPluginDelegateImpl
* d
) { delegate_
= d
; }
54 // WebPlugin overrides
55 void SetWindow(gfx::PluginWindowHandle window
) override
;
56 void SetAcceptsInputEvents(bool accepts
) override
;
57 void WillDestroyWindow(gfx::PluginWindowHandle window
) override
;
58 void CancelResource(unsigned long id
) override
;
59 void Invalidate() override
;
60 void InvalidateRect(const gfx::Rect
& rect
) override
;
61 NPObject
* GetWindowScriptNPObject() override
;
62 NPObject
* GetPluginElement() override
;
63 bool FindProxyForUrl(const GURL
& url
, std::string
* proxy_list
) override
;
64 void SetCookie(const GURL
& url
,
65 const GURL
& first_party_for_cookies
,
66 const std::string
& cookie
) override
;
67 std::string
GetCookies(const GURL
& url
,
68 const GURL
& first_party_for_cookies
) override
;
69 void HandleURLRequest(const char* url
,
76 bool notify_redirects
) override
;
77 void UpdateGeometry(const gfx::Rect
& window_rect
,
78 const gfx::Rect
& clip_rect
,
79 const TransportDIB::Handle
& windowless_buffer0
,
80 const TransportDIB::Handle
& windowless_buffer1
,
81 int windowless_buffer_index
);
82 void CancelDocumentLoad() override
;
83 void InitiateHTTPRangeRequest(const char* url
,
84 const char* range_info
,
85 int range_request_id
) override
;
86 void DidStartLoading() override
;
87 void DidStopLoading() override
;
88 void SetDeferResourceLoading(unsigned long resource_id
, bool defer
) override
;
89 bool IsOffTheRecord() override
;
90 void ResourceClientDeleted(WebPluginResourceClient
* resource_client
) override
;
91 void URLRedirectResponse(bool allow
, int resource_id
) override
;
92 bool CheckIfRunInsecureContent(const GURL
& url
) override
;
94 void SetWindowlessData(HANDLE pump_messages_event
,
95 gfx::NativeViewId dummy_activation_window
) override
;
97 #if defined(OS_MACOSX)
98 void FocusChanged(bool focused
) override
;
99 void StartIme() override
;
100 WebPluginAcceleratedSurface
* GetAcceleratedSurface(
101 gfx::GpuPreference gpu_preference
) override
;
102 void AcceleratedPluginEnabledRendering() override
;
103 void AcceleratedPluginAllocatedIOSurface(int32 width
,
105 uint32 surface_id
) override
;
106 void AcceleratedPluginSwappedIOSurface() override
;
109 // IPC::Sender implementation.
110 bool Send(IPC::Message
* msg
) override
;
112 // class-specific methods
114 // Returns a WebPluginResourceClient object given its id, or NULL if no
115 // object with that id exists.
116 WebPluginResourceClient
* GetResourceClient(int id
);
118 // Returns the id of the renderer that contains this plugin.
121 // Returns the id of the associated render view.
122 int host_render_view_routing_id() const {
123 return host_render_view_routing_id_
;
126 // For windowless plugins, paints the given rectangle into the local buffer.
127 void Paint(const gfx::Rect
& rect
);
129 // Callback from the renderer to let us know that a paint occurred.
132 // Notification received on a plugin issued resource request creation.
133 void OnResourceCreated(int resource_id
, WebPluginResourceClient
* client
);
135 #if defined(OS_WIN) && !defined(USE_AURA)
136 // Retrieves the IME status from a windowless plugin and sends it to a
137 // renderer process. A renderer process will convert the coordinates from
138 // local to the window coordinates and send the converted coordinates to a
140 void UpdateIMEStatus();
144 class SharedTransportDIB
: public base::RefCounted
<SharedTransportDIB
> {
146 explicit SharedTransportDIB(TransportDIB
* dib
);
147 TransportDIB
* dib() { return dib_
.get(); }
149 friend class base::RefCounted
<SharedTransportDIB
>;
150 ~SharedTransportDIB();
152 scoped_ptr
<TransportDIB
> dib_
;
155 // Handler for sending over the paint event to the plugin.
156 void OnPaint(const gfx::Rect
& damaged_rect
);
159 void CreateCanvasFromHandle(const TransportDIB::Handle
& dib_handle
,
160 const gfx::Rect
& window_rect
,
161 skia::RefPtr
<SkCanvas
>* canvas
);
162 #elif defined(OS_MACOSX)
163 static void CreateDIBAndCGContextFromHandle(
164 const TransportDIB::Handle
& dib_handle
,
165 const gfx::Rect
& window_rect
,
166 scoped_ptr
<TransportDIB
>* dib_out
,
167 base::ScopedCFTypeRef
<CGContextRef
>* cg_context_out
);
170 // Updates the shared memory sections where windowless plugins paint.
171 void SetWindowlessBuffers(const TransportDIB::Handle
& windowless_buffer0
,
172 const TransportDIB::Handle
& windowless_buffer1
,
173 const gfx::Rect
& window_rect
);
175 #if defined(OS_MACOSX)
176 CGContextRef
windowless_context() const {
177 return windowless_contexts_
[windowless_buffer_index_
].get();
180 skia::RefPtr
<SkCanvas
> windowless_canvas() const {
181 return windowless_canvases_
[windowless_buffer_index_
];
185 typedef base::hash_map
<int, WebPluginResourceClient
*> ResourceClientMap
;
186 ResourceClientMap resource_clients_
;
188 scoped_refptr
<PluginChannel
> channel_
;
190 NPObject
* window_npobject_
;
191 NPObject
* plugin_element_
;
192 WebPluginDelegateImpl
* delegate_
;
193 gfx::Rect damaged_rect_
;
194 bool waiting_for_paint_
;
195 // The url of the main frame hosting the plugin.
198 // Variables used for desynchronized windowless plugin painting. See note in
199 // webplugin_delegate_proxy.h for how this works. The two sets of windowless_*
200 // fields are for the front-buffer and back-buffer of a buffer flipping system
201 // and windowless_buffer_index_ identifies which set we are using as the
202 // back-buffer at any given time.
203 int windowless_buffer_index_
;
204 #if defined(OS_MACOSX)
205 scoped_ptr
<TransportDIB
> windowless_dibs_
[2];
206 base::ScopedCFTypeRef
<CGContextRef
> windowless_contexts_
[2];
207 scoped_ptr
<WebPluginAcceleratedSurfaceProxy
> accelerated_surface_
;
209 skia::RefPtr
<SkCanvas
> windowless_canvases_
[2];
212 // Contains the routing id of the host render view.
213 int host_render_view_routing_id_
;
215 base::WeakPtrFactory
<WebPluginProxy
> weak_factory_
;
218 } // namespace content
220 #endif // CONTENT_PLUGIN_WEBPLUGIN_PROXY_H_