Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / plugin / webplugin_proxy.h
blob2a561edb427c4b8fdc0a150df0af2d2588ec75b5
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 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/shared_memory.h"
14 #include "base/memory/weak_ptr.h"
15 #include "content/child/npapi/webplugin.h"
16 #include "ipc/ipc_message.h"
17 #include "ipc/ipc_sender.h"
18 #include "skia/ext/refptr.h"
19 #include "third_party/skia/include/core/SkCanvas.h"
20 #include "url/gurl.h"
21 #include "ui/gl/gpu_preference.h"
22 #include "ui/surface/transport_dib.h"
24 #if defined(OS_MACOSX)
25 #include <ApplicationServices/ApplicationServices.h>
27 #include "base/mac/scoped_cftyperef.h"
28 #endif
30 struct PluginMsg_FetchURL_Params;
32 namespace content {
33 class PluginChannel;
34 class WebPluginDelegateImpl;
36 #if defined(OS_MACOSX)
37 class WebPluginAcceleratedSurfaceProxy;
38 #endif
40 // This is an implementation of WebPlugin that proxies all calls to the
41 // renderer.
42 class WebPluginProxy : public WebPlugin,
43 public IPC::Sender {
44 public:
45 // Creates a new proxy for WebPlugin, using the given sender to send the
46 // marshalled WebPlugin calls.
47 WebPluginProxy(PluginChannel* channel,
48 int route_id,
49 const GURL& page_url,
50 int host_render_view_routing_id);
51 ~WebPluginProxy() override;
53 void set_delegate(WebPluginDelegateImpl* d) { delegate_ = d; }
55 // WebPlugin overrides
56 void SetWindow(gfx::PluginWindowHandle window) override;
57 void SetAcceptsInputEvents(bool accepts) override;
58 void WillDestroyWindow(gfx::PluginWindowHandle window) override;
59 void CancelResource(unsigned long id) override;
60 void Invalidate() override;
61 void InvalidateRect(const gfx::Rect& rect) override;
62 NPObject* GetWindowScriptNPObject() override;
63 NPObject* GetPluginElement() override;
64 bool FindProxyForUrl(const GURL& url, std::string* proxy_list) override;
65 void SetCookie(const GURL& url,
66 const GURL& first_party_for_cookies,
67 const std::string& cookie) override;
68 std::string GetCookies(const GURL& url,
69 const GURL& first_party_for_cookies) override;
70 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 void CancelDocumentLoad() override;
84 void InitiateHTTPRangeRequest(const char* url,
85 const char* range_info,
86 int range_request_id) override;
87 void DidStartLoading() override;
88 void DidStopLoading() override;
89 void SetDeferResourceLoading(unsigned long resource_id, bool defer) override;
90 bool IsOffTheRecord() override;
91 void ResourceClientDeleted(WebPluginResourceClient* resource_client) override;
92 void URLRedirectResponse(bool allow, int resource_id) override;
93 bool CheckIfRunInsecureContent(const GURL& url) override;
94 #if defined(OS_WIN)
95 void SetWindowlessData(HANDLE pump_messages_event,
96 gfx::NativeViewId dummy_activation_window) override;
97 #endif
98 #if defined(OS_MACOSX)
99 void FocusChanged(bool focused) override;
100 void StartIme() override;
101 WebPluginAcceleratedSurface* GetAcceleratedSurface(
102 gfx::GpuPreference gpu_preference) override;
103 void AcceleratedPluginEnabledRendering() override;
104 void AcceleratedPluginAllocatedIOSurface(int32 width,
105 int32 height,
106 uint32 surface_id) override;
107 void AcceleratedPluginSwappedIOSurface() override;
108 #endif
110 // IPC::Sender implementation.
111 bool Send(IPC::Message* msg) override;
113 // class-specific methods
115 // Returns a WebPluginResourceClient object given its id, or NULL if no
116 // object with that id exists.
117 WebPluginResourceClient* GetResourceClient(int id);
119 // Returns the id of the renderer that contains this plugin.
120 int GetRendererId();
122 // Returns the id of the associated render view.
123 int host_render_view_routing_id() const {
124 return host_render_view_routing_id_;
127 // For windowless plugins, paints the given rectangle into the local buffer.
128 void Paint(const gfx::Rect& rect);
130 // Callback from the renderer to let us know that a paint occurred.
131 void DidPaint();
133 // Notification received on a plugin issued resource request creation.
134 void OnResourceCreated(int resource_id, WebPluginResourceClient* client);
136 #if defined(OS_WIN) && !defined(USE_AURA)
137 // Retrieves the IME status from a windowless plugin and sends it to a
138 // renderer process. A renderer process will convert the coordinates from
139 // local to the window coordinates and send the converted coordinates to a
140 // browser process.
141 void UpdateIMEStatus();
142 #endif
144 private:
145 class SharedTransportDIB : public base::RefCounted<SharedTransportDIB> {
146 public:
147 explicit SharedTransportDIB(TransportDIB* dib);
148 TransportDIB* dib() { return dib_.get(); }
149 private:
150 friend class base::RefCounted<SharedTransportDIB>;
151 ~SharedTransportDIB();
153 scoped_ptr<TransportDIB> dib_;
156 // Handler for sending over the paint event to the plugin.
157 void OnPaint(const gfx::Rect& damaged_rect);
159 #if defined(OS_WIN)
160 void CreateCanvasFromHandle(const TransportDIB::Handle& dib_handle,
161 const gfx::Rect& window_rect,
162 skia::RefPtr<SkCanvas>* canvas);
163 #elif defined(OS_MACOSX)
164 static void CreateDIBAndCGContextFromHandle(
165 const TransportDIB::Handle& dib_handle,
166 const gfx::Rect& window_rect,
167 scoped_ptr<TransportDIB>* dib_out,
168 base::ScopedCFTypeRef<CGContextRef>* cg_context_out);
169 #endif
171 // Updates the shared memory sections where windowless plugins paint.
172 void SetWindowlessBuffers(const TransportDIB::Handle& windowless_buffer0,
173 const TransportDIB::Handle& windowless_buffer1,
174 const gfx::Rect& window_rect);
176 #if defined(OS_MACOSX)
177 CGContextRef windowless_context() const {
178 return windowless_contexts_[windowless_buffer_index_].get();
180 #else
181 skia::RefPtr<SkCanvas> windowless_canvas() const {
182 return windowless_canvases_[windowless_buffer_index_];
184 #endif
186 typedef base::hash_map<int, WebPluginResourceClient*> ResourceClientMap;
187 ResourceClientMap resource_clients_;
189 scoped_refptr<PluginChannel> channel_;
190 int route_id_;
191 NPObject* window_npobject_;
192 NPObject* plugin_element_;
193 WebPluginDelegateImpl* delegate_;
194 gfx::Rect damaged_rect_;
195 bool waiting_for_paint_;
196 // The url of the main frame hosting the plugin.
197 GURL page_url_;
199 // Variables used for desynchronized windowless plugin painting. See note in
200 // webplugin_delegate_proxy.h for how this works. The two sets of windowless_*
201 // fields are for the front-buffer and back-buffer of a buffer flipping system
202 // and windowless_buffer_index_ identifies which set we are using as the
203 // back-buffer at any given time.
204 int windowless_buffer_index_;
205 #if defined(OS_MACOSX)
206 scoped_ptr<TransportDIB> windowless_dibs_[2];
207 base::ScopedCFTypeRef<CGContextRef> windowless_contexts_[2];
208 scoped_ptr<WebPluginAcceleratedSurfaceProxy> accelerated_surface_;
209 #else
210 skia::RefPtr<SkCanvas> windowless_canvases_[2];
211 #endif
213 // Contains the routing id of the host render view.
214 int host_render_view_routing_id_;
216 base::WeakPtrFactory<WebPluginProxy> weak_factory_;
219 } // namespace content
221 #endif // CONTENT_PLUGIN_WEBPLUGIN_PROXY_H_