Add an UMA stat to be able to see if the User pods are show on start screen,
[chromium-blink-merge.git] / content / plugin / webplugin_proxy.h
blob458921afd02b7698999423267ef4a2a14cc0d98b
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_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"
23 #include "url/gurl.h"
24 #include "ui/gl/gpu_preference.h"
25 #include "ui/surface/transport_dib.h"
27 struct PluginMsg_FetchURL_Params;
29 namespace content {
30 class PluginChannel;
31 class WebPluginDelegateImpl;
33 #if defined(OS_MACOSX)
34 class WebPluginAcceleratedSurfaceProxy;
35 #endif
37 // This is an implementation of WebPlugin that proxies all calls to the
38 // renderer.
39 class WebPluginProxy : public WebPlugin,
40 public IPC::Sender {
41 public:
42 // Creates a new proxy for WebPlugin, using the given sender to send the
43 // marshalled WebPlugin calls.
44 WebPluginProxy(PluginChannel* channel,
45 int route_id,
46 const GURL& page_url,
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,
68 const char* method,
69 const char* target,
70 const char* buf,
71 unsigned int len,
72 int notify_id,
73 bool popups_allowed,
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;
91 #if defined(OS_WIN)
92 void SetWindowlessData(HANDLE pump_messages_event,
93 gfx::NativeViewId dummy_activation_window);
94 #endif
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,
102 int32 height,
103 uint32 surface_id) override;
104 void AcceleratedPluginSwappedIOSurface() override;
105 #endif
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.
117 int GetRendererId();
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.
128 void DidPaint();
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 plugin 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
137 // browser process.
138 void UpdateIMEStatus();
139 #endif
141 private:
142 class SharedTransportDIB : public base::RefCounted<SharedTransportDIB> {
143 public:
144 explicit SharedTransportDIB(TransportDIB* dib);
145 TransportDIB* dib() { return dib_.get(); }
146 private:
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);
156 #if defined(OS_WIN)
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);
166 #endif
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();
177 #else
178 skia::RefPtr<SkCanvas> windowless_canvas() const {
179 return windowless_canvases_[windowless_buffer_index_];
181 #endif
183 typedef base::hash_map<int, WebPluginResourceClient*> ResourceClientMap;
184 ResourceClientMap resource_clients_;
186 scoped_refptr<PluginChannel> channel_;
187 int route_id_;
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.
194 GURL page_url_;
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_;
206 #else
207 skia::RefPtr<SkCanvas> windowless_canvases_[2];
208 #endif
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_