Remove const WebMediaPlayer::didLoadingProgress() implementations.
[chromium-blink-merge.git] / content / plugin / webplugin_proxy.h
blob314bd5a30775c7f3af927076cc9c23ece8dc2287
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_
8 #include <string>
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"
14 #endif
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"
25 #include "url/gurl.h"
26 #include "ui/gl/gpu_preference.h"
27 #include "ui/surface/transport_dib.h"
29 struct PluginMsg_FetchURL_Params;
31 namespace content {
32 class PluginChannel;
33 class WebPluginDelegateImpl;
35 #if defined(OS_MACOSX)
36 class WebPluginAcceleratedSurfaceProxy;
37 #endif
39 // This is an implementation of WebPlugin that proxies all calls to the
40 // renderer.
41 class WebPluginProxy : public WebPlugin,
42 public IPC::Sender {
43 public:
44 // Creates a new proxy for WebPlugin, using the given sender to send the
45 // marshalled WebPlugin calls.
46 WebPluginProxy(PluginChannel* channel,
47 int route_id,
48 const GURL& page_url,
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,
71 const char* method,
72 const char* target,
73 const char* buf,
74 unsigned int len,
75 int notify_id,
76 bool popups_allowed,
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,
89 bool defer) OVERRIDE;
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;
95 #if defined(OS_WIN)
96 void SetWindowlessData(HANDLE pump_messages_event,
97 gfx::NativeViewId dummy_activation_window);
98 #endif
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,
106 int32 height,
107 uint32 surface_id) OVERRIDE;
108 virtual void AcceleratedPluginSwappedIOSurface() OVERRIDE;
109 #endif
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.
121 int GetRendererId();
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.
132 void DidPaint();
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
141 // browser process.
142 void UpdateIMEStatus();
143 #endif
145 private:
146 class SharedTransportDIB : public base::RefCounted<SharedTransportDIB> {
147 public:
148 explicit SharedTransportDIB(TransportDIB* dib);
149 TransportDIB* dib() { return dib_.get(); }
150 private:
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);
160 #if defined(OS_WIN)
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);
170 #endif
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();
181 #else
182 skia::RefPtr<SkCanvas> windowless_canvas() const {
183 return windowless_canvases_[windowless_buffer_index_];
185 #endif
187 typedef base::hash_map<int, WebPluginResourceClient*> ResourceClientMap;
188 ResourceClientMap resource_clients_;
190 scoped_refptr<PluginChannel> channel_;
191 int route_id_;
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.
198 GURL page_url_;
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_;
210 #else
211 skia::RefPtr<SkCanvas> windowless_canvases_[2];
212 #endif
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_