[email protected] | a5f73fea | 2012-02-15 18:09:17 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 5 | #include "content/plugin/webplugin_proxy.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 2f5b1a1 | 2009-07-30 19:26:52 | [diff] [blame] | 7 | #include "build/build_config.h" |
[email protected] | 2f5b1a1 | 2009-07-30 19:26:52 | [diff] [blame] | 8 | |
[email protected] | a488837 | 2011-11-19 02:13:33 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 10 | #include "base/lazy_instance.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/scoped_handle.h" |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 12 | #include "base/shared_memory.h" |
[email protected] | 157e5d2 | 2009-04-23 18:43:35 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | d3fd748b | 2011-09-20 17:39:17 | [diff] [blame] | 14 | #include "content/common/npobject_proxy.h" |
| 15 | #include "content/common/npobject_util.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 16 | #include "content/common/plugin_messages.h" |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 17 | #include "content/plugin/plugin_channel.h" |
| 18 | #include "content/plugin/plugin_thread.h" |
[email protected] | 5d1fa24 | 2011-10-18 23:35:38 | [diff] [blame] | 19 | #include "content/public/common/content_client.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 20 | #include "content/public/common/url_constants.h" |
[email protected] | 91ef7b0 | 2011-08-02 15:26:03 | [diff] [blame] | 21 | #include "skia/ext/platform_canvas.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 22 | #include "skia/ext/platform_device.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 23 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 24 | #include "ui/gfx/blit.h" |
| 25 | #include "ui/gfx/canvas.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 26 | #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 27 | |
[email protected] | fd85ad6 | 2010-12-31 20:39:02 | [diff] [blame] | 28 | #if defined(OS_MACOSX) |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 29 | #include "base/mac/mac_util.h" |
[email protected] | fd85ad6 | 2010-12-31 20:39:02 | [diff] [blame] | 30 | #include "base/mac/scoped_cftyperef.h" |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 31 | #include "content/plugin/webplugin_accelerated_surface_proxy_mac.h" |
[email protected] | fd85ad6 | 2010-12-31 20:39:02 | [diff] [blame] | 32 | #endif |
| 33 | |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 34 | #if defined(USE_X11) |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 35 | #include "ui/base/x/x11_util_internal.h" |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 36 | #endif |
| 37 | |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 38 | #if defined(OS_WIN) |
[email protected] | d30ce6e | 2012-04-16 15:32:36 | [diff] [blame] | 39 | #include "content/public/common/sandbox_init.h" |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 40 | #endif |
| 41 | |
[email protected] | a392929 | 2009-07-30 00:35:33 | [diff] [blame] | 42 | using WebKit::WebBindings; |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 43 | |
| 44 | using webkit::npapi::WebPluginResourceClient; |
[email protected] | 8b4755f | 2010-10-01 18:04:06 | [diff] [blame] | 45 | #if defined(OS_MACOSX) |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 46 | using webkit::npapi::WebPluginAcceleratedSurface; |
[email protected] | 8b4755f | 2010-10-01 18:04:06 | [diff] [blame] | 47 | #endif |
[email protected] | a392929 | 2009-07-30 00:35:33 | [diff] [blame] | 48 | |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 49 | |
| 50 | WebPluginProxy::SharedTransportDIB::SharedTransportDIB(TransportDIB* dib) |
| 51 | : dib_(dib) { |
| 52 | } |
| 53 | |
| 54 | WebPluginProxy::SharedTransportDIB::~SharedTransportDIB() { |
| 55 | } |
| 56 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 57 | WebPluginProxy::WebPluginProxy( |
| 58 | PluginChannel* channel, |
| 59 | int route_id, |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 60 | const GURL& page_url, |
[email protected] | 2799c02a | 2009-11-07 15:39:55 | [diff] [blame] | 61 | gfx::NativeViewId containing_window, |
| 62 | int host_render_view_routing_id) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | : channel_(channel), |
| 64 | route_id_(route_id), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | window_npobject_(NULL), |
| 66 | plugin_element_(NULL), |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 67 | delegate_(NULL), |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 68 | waiting_for_paint_(false), |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 69 | containing_window_(containing_window), |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 70 | page_url_(page_url), |
[email protected] | ab7f274 | 2010-04-14 17:24:51 | [diff] [blame] | 71 | transparent_(false), |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 72 | windowless_buffer_index_(0), |
[email protected] | 2799c02a | 2009-11-07 15:39:55 | [diff] [blame] | 73 | host_render_view_routing_id_(host_render_view_routing_id), |
[email protected] | a488837 | 2011-11-19 02:13:33 | [diff] [blame] | 74 | ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 75 | #if defined(USE_X11) |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 76 | windowless_shm_pixmaps_[0] = None; |
| 77 | windowless_shm_pixmaps_[1] = None; |
| 78 | use_shm_pixmap_ = false; |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 79 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 80 | // If the X server supports SHM pixmaps |
| 81 | // and the color depth and masks match, |
| 82 | // then consider using SHM pixmaps for windowless plugin painting. |
| 83 | Display* display = ui::GetXDisplay(); |
| 84 | if (ui::QuerySharedMemorySupport(display) == ui::SHARED_MEMORY_PIXMAP && |
| 85 | ui::BitsPerPixelForPixmapDepth( |
[email protected] | 88a8ffa | 2011-10-13 01:41:05 | [diff] [blame] | 86 | display, DefaultDepth(display, DefaultScreen(display))) == 32) { |
| 87 | Visual* vis = DefaultVisual(display, DefaultScreen(display)); |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 88 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 89 | if (vis->red_mask == 0xff0000 && |
| 90 | vis->green_mask == 0xff00 && |
| 91 | vis->blue_mask == 0xff) |
| 92 | use_shm_pixmap_ = true; |
| 93 | } |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 94 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | WebPluginProxy::~WebPluginProxy() { |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 98 | #if defined(USE_X11) |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 99 | if (windowless_shm_pixmaps_[0] != None) |
| 100 | XFreePixmap(ui::GetXDisplay(), windowless_shm_pixmaps_[0]); |
| 101 | if (windowless_shm_pixmaps_[1] != None) |
| 102 | XFreePixmap(ui::GetXDisplay(), windowless_shm_pixmaps_[1]); |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 103 | #endif |
[email protected] | 8b4755f | 2010-10-01 18:04:06 | [diff] [blame] | 104 | |
| 105 | #if defined(OS_MACOSX) |
| 106 | // Destroy the surface early, since it may send messages during cleanup. |
| 107 | if (accelerated_surface_.get()) |
| 108 | accelerated_surface_.reset(); |
| 109 | #endif |
[email protected] | 1eb70a2 | 2011-06-23 06:27:30 | [diff] [blame] | 110 | |
| 111 | if (plugin_element_) |
| 112 | WebBindings::releaseObject(plugin_element_); |
| 113 | if (window_npobject_) |
| 114 | WebBindings::releaseObject(window_npobject_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | bool WebPluginProxy::Send(IPC::Message* msg) { |
| 118 | return channel_->Send(msg); |
| 119 | } |
| 120 | |
[email protected] | 700d3d5 | 2009-07-07 17:40:46 | [diff] [blame] | 121 | void WebPluginProxy::SetWindow(gfx::PluginWindowHandle window) { |
| 122 | Send(new PluginHostMsg_SetWindow(route_id_, window)); |
[email protected] | 875d489 | 2009-04-21 21:48:36 | [diff] [blame] | 123 | } |
[email protected] | 096d5cd | 2009-03-26 19:39:29 | [diff] [blame] | 124 | |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 125 | void WebPluginProxy::SetAcceptsInputEvents(bool accepts) { |
| 126 | NOTREACHED(); |
| 127 | } |
| 128 | |
[email protected] | 140c303 | 2009-06-26 18:22:54 | [diff] [blame] | 129 | void WebPluginProxy::WillDestroyWindow(gfx::PluginWindowHandle window) { |
[email protected] | 875d489 | 2009-04-21 21:48:36 | [diff] [blame] | 130 | #if defined(OS_WIN) |
| 131 | PluginThread::current()->Send( |
| 132 | new PluginProcessHostMsg_PluginWindowDestroyed( |
| 133 | window, ::GetParent(window))); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 134 | #elif defined(USE_X11) |
[email protected] | c0478b09 | 2009-08-25 20:50:32 | [diff] [blame] | 135 | // Nothing to do. |
[email protected] | 140c303 | 2009-06-26 18:22:54 | [diff] [blame] | 136 | #else |
| 137 | NOTIMPLEMENTED(); |
[email protected] | 875d489 | 2009-04-21 21:48:36 | [diff] [blame] | 138 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | 829c284 | 2009-04-01 01:48:52 | [diff] [blame] | 141 | #if defined(OS_WIN) |
| 142 | void WebPluginProxy::SetWindowlessPumpEvent(HANDLE pump_messages_event) { |
| 143 | HANDLE pump_messages_event_for_renderer = NULL; |
[email protected] | d30ce6e | 2012-04-16 15:32:36 | [diff] [blame] | 144 | content::BrokerDuplicateHandle(pump_messages_event, channel_->peer_pid(), |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 145 | &pump_messages_event_for_renderer, |
| 146 | SYNCHRONIZE | EVENT_MODIFY_STATE, 0); |
[email protected] | 829c284 | 2009-04-01 01:48:52 | [diff] [blame] | 147 | DCHECK(pump_messages_event_for_renderer != NULL); |
| 148 | Send(new PluginHostMsg_SetWindowlessPumpEvent( |
| 149 | route_id_, pump_messages_event_for_renderer)); |
| 150 | } |
[email protected] | 829c284 | 2009-04-01 01:48:52 | [diff] [blame] | 151 | #endif |
| 152 | |
[email protected] | 3d248b2 | 2009-12-03 07:11:34 | [diff] [blame] | 153 | void WebPluginProxy::CancelResource(unsigned long id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | Send(new PluginHostMsg_CancelResource(route_id_, id)); |
| 155 | resource_clients_.erase(id); |
| 156 | } |
| 157 | |
| 158 | void WebPluginProxy::Invalidate() { |
[email protected] | b94d332 | 2009-02-12 19:49:04 | [diff] [blame] | 159 | gfx::Rect rect(0, 0, |
| 160 | delegate_->GetRect().width(), |
| 161 | delegate_->GetRect().height()); |
[email protected] | c20b454 | 2008-10-01 00:38:11 | [diff] [blame] | 162 | InvalidateRect(rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void WebPluginProxy::InvalidateRect(const gfx::Rect& rect) { |
[email protected] | 831058cb | 2009-08-27 17:42:53 | [diff] [blame] | 166 | #if defined(OS_MACOSX) |
[email protected] | 23607ccf | 2010-06-03 23:15:33 | [diff] [blame] | 167 | // If this is a Core Animation plugin, all we need to do is inform the |
| 168 | // delegate. |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 169 | if (!windowless_context()) { |
[email protected] | 23607ccf | 2010-06-03 23:15:33 | [diff] [blame] | 170 | delegate_->PluginDidInvalidate(); |
| 171 | return; |
| 172 | } |
[email protected] | 51a0bb5 | 2010-06-03 21:34:06 | [diff] [blame] | 173 | |
[email protected] | 831058cb | 2009-08-27 17:42:53 | [diff] [blame] | 174 | // Some plugins will send invalidates larger than their own rect when |
| 175 | // offscreen, so constrain invalidates to the plugin rect. |
| 176 | gfx::Rect plugin_rect = delegate_->GetRect(); |
| 177 | plugin_rect.set_origin(gfx::Point(0, 0)); |
| 178 | const gfx::Rect invalidate_rect(rect.Intersect(plugin_rect)); |
| 179 | #else |
| 180 | const gfx::Rect invalidate_rect(rect); |
| 181 | #endif |
| 182 | damaged_rect_ = damaged_rect_.Union(invalidate_rect); |
[email protected] | 20c011b3 | 2008-10-09 20:38:57 | [diff] [blame] | 183 | // Ignore NPN_InvalidateRect calls with empty rects. Also don't send an |
| 184 | // invalidate if it's outside the clipping region, since if we did it won't |
| 185 | // lead to a paint and we'll be stuck waiting forever for a DidPaint response. |
[email protected] | 56fcc3f | 2009-08-07 00:34:55 | [diff] [blame] | 186 | // |
| 187 | // TODO(piman): There is a race condition here, because this test assumes |
| 188 | // that when the paint actually occurs, the clip rect will not have changed. |
| 189 | // This is not true because scrolling (or window resize) could occur and be |
| 190 | // handled by the renderer before it receives the InvalidateRect message, |
| 191 | // changing the clip rect and then not painting. |
[email protected] | a3edf844 | 2010-04-14 23:57:50 | [diff] [blame] | 192 | if (damaged_rect_.IsEmpty() || |
| 193 | !delegate_->GetClipRect().Intersects(damaged_rect_)) |
[email protected] | c20b454 | 2008-10-01 00:38:11 | [diff] [blame] | 194 | return; |
| 195 | |
[email protected] | c20b454 | 2008-10-01 00:38:11 | [diff] [blame] | 196 | // Only send a single InvalidateRect message at a time. From DidPaint we |
| 197 | // will dispatch an additional InvalidateRect message if necessary. |
| 198 | if (!waiting_for_paint_) { |
| 199 | waiting_for_paint_ = true; |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 200 | // Invalidates caused by calls to NPN_InvalidateRect/NPN_InvalidateRgn |
| 201 | // need to be painted asynchronously as per the NPAPI spec. |
| 202 | MessageLoop::current()->PostTask(FROM_HERE, |
[email protected] | a488837 | 2011-11-19 02:13:33 | [diff] [blame] | 203 | base::Bind(&WebPluginProxy::OnPaint, weak_factory_.GetWeakPtr(), |
| 204 | damaged_rect_)); |
[email protected] | c20b454 | 2008-10-01 00:38:11 | [diff] [blame] | 205 | damaged_rect_ = gfx::Rect(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | NPObject* WebPluginProxy::GetWindowScriptNPObject() { |
| 210 | if (window_npobject_) |
[email protected] | 1eb70a2 | 2011-06-23 06:27:30 | [diff] [blame] | 211 | return window_npobject_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | |
| 213 | int npobject_route_id = channel_->GenerateRouteID(); |
| 214 | bool success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 215 | Send(new PluginHostMsg_GetWindowScriptNPObject( |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 216 | route_id_, npobject_route_id, &success)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 217 | if (!success) |
| 218 | return NULL; |
| 219 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 220 | window_npobject_ = NPObjectProxy::Create( |
[email protected] | 4da8a2e | 2010-01-20 07:05:23 | [diff] [blame] | 221 | channel_, npobject_route_id, containing_window_, page_url_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 222 | |
| 223 | return window_npobject_; |
| 224 | } |
| 225 | |
| 226 | NPObject* WebPluginProxy::GetPluginElement() { |
| 227 | if (plugin_element_) |
[email protected] | 1eb70a2 | 2011-06-23 06:27:30 | [diff] [blame] | 228 | return plugin_element_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 229 | |
| 230 | int npobject_route_id = channel_->GenerateRouteID(); |
| 231 | bool success = false; |
[email protected] | df0ca6c8 | 2010-10-17 04:09:06 | [diff] [blame] | 232 | Send(new PluginHostMsg_GetPluginElement(route_id_, npobject_route_id, |
| 233 | &success)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 234 | if (!success) |
| 235 | return NULL; |
| 236 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 237 | plugin_element_ = NPObjectProxy::Create( |
[email protected] | 4da8a2e | 2010-01-20 07:05:23 | [diff] [blame] | 238 | channel_, npobject_route_id, containing_window_, page_url_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 239 | |
| 240 | return plugin_element_; |
| 241 | } |
| 242 | |
[email protected] | 2dd868f | 2011-08-29 23:03:57 | [diff] [blame] | 243 | bool WebPluginProxy::FindProxyForUrl(const GURL& url, std::string* proxy_list) { |
| 244 | bool result = false; |
| 245 | Send(new PluginHostMsg_ResolveProxy(route_id_, url, &result, proxy_list)); |
| 246 | return result; |
| 247 | } |
| 248 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 249 | void WebPluginProxy::SetCookie(const GURL& url, |
[email protected] | 79e6a40 | 2009-11-18 19:31:40 | [diff] [blame] | 250 | const GURL& first_party_for_cookies, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 251 | const std::string& cookie) { |
[email protected] | 79e6a40 | 2009-11-18 19:31:40 | [diff] [blame] | 252 | Send(new PluginHostMsg_SetCookie(route_id_, url, |
| 253 | first_party_for_cookies, cookie)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | std::string WebPluginProxy::GetCookies(const GURL& url, |
[email protected] | 79e6a40 | 2009-11-18 19:31:40 | [diff] [blame] | 257 | const GURL& first_party_for_cookies) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | std::string cookies; |
[email protected] | 79e6a40 | 2009-11-18 19:31:40 | [diff] [blame] | 259 | Send(new PluginHostMsg_GetCookies(route_id_, url, |
| 260 | first_party_for_cookies, &cookies)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 261 | |
| 262 | return cookies; |
| 263 | } |
| 264 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | WebPluginResourceClient* WebPluginProxy::GetResourceClient(int id) { |
| 266 | ResourceClientMap::iterator iterator = resource_clients_.find(id); |
[email protected] | e15e9c49 | 2009-08-04 07:06:39 | [diff] [blame] | 267 | // The IPC messages which deal with streams are now asynchronous. It is |
| 268 | // now possible to receive stream messages from the renderer for streams |
| 269 | // which may have been cancelled by the plugin. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 270 | if (iterator == resource_clients_.end()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 271 | return NULL; |
| 272 | } |
| 273 | |
| 274 | return iterator->second; |
| 275 | } |
| 276 | |
[email protected] | c84a785 | 2009-09-16 21:36:44 | [diff] [blame] | 277 | int WebPluginProxy::GetRendererId() { |
[email protected] | 3513551 | 2009-07-23 20:36:49 | [diff] [blame] | 278 | if (channel_.get()) |
[email protected] | c84a785 | 2009-09-16 21:36:44 | [diff] [blame] | 279 | return channel_->renderer_id(); |
| 280 | return -1; |
[email protected] | 3513551 | 2009-07-23 20:36:49 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | c20b454 | 2008-10-01 00:38:11 | [diff] [blame] | 283 | void WebPluginProxy::DidPaint() { |
| 284 | // If we have an accumulated damaged rect, then check to see if we need to |
| 285 | // send out another InvalidateRect message. |
| 286 | waiting_for_paint_ = false; |
| 287 | if (!damaged_rect_.IsEmpty()) |
| 288 | InvalidateRect(damaged_rect_); |
| 289 | } |
| 290 | |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 291 | void WebPluginProxy::OnResourceCreated(int resource_id, |
| 292 | WebPluginResourceClient* client) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 293 | DCHECK(resource_clients_.find(resource_id) == resource_clients_.end()); |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 294 | resource_clients_[resource_id] = client; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 297 | void WebPluginProxy::HandleURLRequest(const char* url, |
[email protected] | d8627c1 | 2010-02-27 02:29:05 | [diff] [blame] | 298 | const char* method, |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 299 | const char* target, |
| 300 | const char* buf, |
| 301 | unsigned int len, |
| 302 | int notify_id, |
[email protected] | 65e82a56 | 2010-11-23 00:34:27 | [diff] [blame] | 303 | bool popups_allowed, |
| 304 | bool notify_redirects) { |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 305 | if (!target && (0 == base::strcasecmp(method, "GET"))) { |
[email protected] | c82a523 | 2009-01-16 01:41:16 | [diff] [blame] | 306 | // Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=366082 |
| 307 | // for more details on this. |
[email protected] | b94d332 | 2009-02-12 19:49:04 | [diff] [blame] | 308 | if (delegate_->GetQuirks() & |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 309 | webkit::npapi::WebPluginDelegateImpl:: |
| 310 | PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS) { |
[email protected] | c82a523 | 2009-01-16 01:41:16 | [diff] [blame] | 311 | GURL request_url(url); |
[email protected] | abbfaec | 2011-05-23 23:57:33 | [diff] [blame] | 312 | if (!request_url.SchemeIs(chrome::kHttpScheme) && |
| 313 | !request_url.SchemeIs(chrome::kHttpsScheme) && |
| 314 | !request_url.SchemeIs(chrome::kFtpScheme)) { |
[email protected] | c82a523 | 2009-01-16 01:41:16 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 320 | PluginHostMsg_URLRequest_Params params; |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 321 | params.url = url; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 322 | params.method = method; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 323 | if (target) |
| 324 | params.target = std::string(target); |
| 325 | |
| 326 | if (len) { |
| 327 | params.buffer.resize(len); |
| 328 | memcpy(¶ms.buffer.front(), buf, len); |
| 329 | } |
| 330 | |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 331 | params.notify_id = notify_id; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 332 | params.popups_allowed = popups_allowed; |
[email protected] | 65e82a56 | 2010-11-23 00:34:27 | [diff] [blame] | 333 | params.notify_redirects = notify_redirects; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 334 | |
| 335 | Send(new PluginHostMsg_URLRequest(route_id_, params)); |
| 336 | } |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 337 | |
[email protected] | c20b454 | 2008-10-01 00:38:11 | [diff] [blame] | 338 | void WebPluginProxy::Paint(const gfx::Rect& rect) { |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 339 | #if defined(OS_MACOSX) |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 340 | if (!windowless_context()) |
[email protected] | 6bf1a81 | 2009-07-11 01:57:28 | [diff] [blame] | 341 | return; |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 342 | #else |
[email protected] | 42a36ed | 2012-02-24 17:49:57 | [diff] [blame] | 343 | if (!windowless_canvas() || !windowless_canvas()->getDevice()) |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 344 | return; |
[email protected] | 6bf1a81 | 2009-07-11 01:57:28 | [diff] [blame] | 345 | #endif |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 346 | |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 347 | // Clear the damaged area so that if the plugin doesn't paint there we won't |
| 348 | // end up with the old values. |
[email protected] | c20b454 | 2008-10-01 00:38:11 | [diff] [blame] | 349 | gfx::Rect offset_rect = rect; |
[email protected] | b94d332 | 2009-02-12 19:49:04 | [diff] [blame] | 350 | offset_rect.Offset(delegate_->GetRect().origin()); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 351 | #if defined(OS_MACOSX) |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 352 | CGContextSaveGState(windowless_context()); |
| 353 | // It is possible for windowless_contexts_ to change during plugin painting |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 354 | // (since the plugin can make a synchronous call during paint event handling), |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 355 | // in which case we don't want to try to restore later. Not an owning ref |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 356 | // since owning the ref without owning the shared backing memory doesn't make |
| 357 | // sense, so this should only be used for pointer comparisons. |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 358 | CGContextRef saved_context_weak = windowless_context(); |
| 359 | // We also save the buffer index for the comparison because if we flip buffers |
| 360 | // but haven't reallocated them then we do need to restore the context because |
| 361 | // it is going to continue to be used. |
| 362 | int saved_index = windowless_buffer_index_; |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 363 | |
[email protected] | b9ae5690 | 2010-04-12 18:34:15 | [diff] [blame] | 364 | if (background_context_.get()) { |
[email protected] | df0ca6c8 | 2010-10-17 04:09:06 | [diff] [blame] | 365 | base::mac::ScopedCFTypeRef<CGImageRef> image( |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 366 | CGBitmapContextCreateImage(background_context_)); |
| 367 | CGRect source_rect = rect.ToCGRect(); |
| 368 | // Flip the rect we use to pull from the canvas, since it's upside-down. |
| 369 | source_rect.origin.y = CGImageGetHeight(image) - rect.y() - rect.height(); |
[email protected] | df0ca6c8 | 2010-10-17 04:09:06 | [diff] [blame] | 370 | base::mac::ScopedCFTypeRef<CGImageRef> sub_image( |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 371 | CGImageCreateWithImageInRect(image, source_rect)); |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 372 | CGContextDrawImage(windowless_context(), rect.ToCGRect(), sub_image); |
[email protected] | ab7f274 | 2010-04-14 17:24:51 | [diff] [blame] | 373 | } else if (transparent_) { |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 374 | CGContextClearRect(windowless_context(), rect.ToCGRect()); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 375 | } |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 376 | CGContextClipToRect(windowless_context(), rect.ToCGRect()); |
[email protected] | 44f854c | 2011-05-25 19:02:11 | [diff] [blame] | 377 | // TODO(caryclark): This is a temporary workaround to allow the Darwin / Skia |
| 378 | // port to share code with the Darwin / CG port. All ports will eventually use |
| 379 | // the common code below. |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 380 | delegate_->CGPaint(windowless_context(), rect); |
| 381 | if (windowless_contexts_[saved_index].get() == saved_context_weak) |
| 382 | CGContextRestoreGState(windowless_contexts_[saved_index]); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 383 | #else |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 384 | // See above comment about windowless_context_ changing. |
| 385 | // http::/crbug.com/139462 |
| 386 | skia::PlatformCanvas* saved_canvas = windowless_canvas(); |
| 387 | SkAutoRef local_ref(saved_canvas); |
| 388 | #if defined(USE_X11) |
| 389 | scoped_refptr<SharedTransportDIB> local_dib_ref( |
| 390 | windowless_dibs_[windowless_buffer_index_]); |
| 391 | #endif |
| 392 | |
| 393 | saved_canvas->save(); |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 394 | |
[email protected] | 1d99bfac | 2009-10-29 19:58:43 | [diff] [blame] | 395 | // The given clip rect is relative to the plugin coordinate system. |
[email protected] | 558833a | 2009-10-23 16:20:01 | [diff] [blame] | 396 | SkRect sk_rect = { SkIntToScalar(rect.x()), |
| 397 | SkIntToScalar(rect.y()), |
| 398 | SkIntToScalar(rect.right()), |
| 399 | SkIntToScalar(rect.bottom()) }; |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 400 | saved_canvas->clipRect(sk_rect); |
[email protected] | 558833a | 2009-10-23 16:20:01 | [diff] [blame] | 401 | |
| 402 | // Setup the background. |
[email protected] | 42a36ed | 2012-02-24 17:49:57 | [diff] [blame] | 403 | if (background_canvas_.get() && background_canvas_.get()->getDevice()) { |
[email protected] | 1d99bfac | 2009-10-29 19:58:43 | [diff] [blame] | 404 | // When a background canvas is given, we're in transparent mode. This means |
| 405 | // the plugin wants to have the image of the page in the canvas it's drawing |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 406 | // into (which is windowless_canvases_) so it can do blending. So we copy |
| 407 | // the background bitmap into the windowless canvas. |
[email protected] | 1d99bfac | 2009-10-29 19:58:43 | [diff] [blame] | 408 | const SkBitmap& background_bitmap = |
[email protected] | 62f2e80 | 2011-05-26 14:28:35 | [diff] [blame] | 409 | skia::GetTopDevice(*background_canvas_)->accessBitmap(false); |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 410 | saved_canvas->drawBitmap(background_bitmap, 0, 0); |
[email protected] | 1d99bfac | 2009-10-29 19:58:43 | [diff] [blame] | 411 | } else { |
| 412 | // In non-transparent mode, the plugin doesn't care what's underneath, so we |
| 413 | // can just give it black. |
[email protected] | 558833a | 2009-10-23 16:20:01 | [diff] [blame] | 414 | SkPaint black_fill_paint; |
| 415 | black_fill_paint.setARGB(0xFF, 0x00, 0x00, 0x00); |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 416 | saved_canvas->drawPaint(black_fill_paint); |
[email protected] | 558833a | 2009-10-23 16:20:01 | [diff] [blame] | 417 | } |
[email protected] | 24e86324 | 2009-03-27 16:21:25 | [diff] [blame] | 418 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 419 | // Bring the windowless canvas into the window coordinate system, which is |
[email protected] | 1d99bfac | 2009-10-29 19:58:43 | [diff] [blame] | 420 | // how the plugin expects to draw (since the windowless API was originally |
| 421 | // designed just for scribbling over the web page). |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 422 | saved_canvas->translate(SkIntToScalar(-delegate_->GetRect().x()), |
| 423 | SkIntToScalar(-delegate_->GetRect().y())); |
[email protected] | 1d99bfac | 2009-10-29 19:58:43 | [diff] [blame] | 424 | |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 425 | // Before we send the invalidate, paint so that renderer uses the updated |
| 426 | // bitmap. |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 427 | delegate_->Paint(saved_canvas, offset_rect); |
[email protected] | 24e86324 | 2009-03-27 16:21:25 | [diff] [blame] | 428 | |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 429 | saved_canvas->restore(); |
[email protected] | 157e5d2 | 2009-04-23 18:43:35 | [diff] [blame] | 430 | #endif |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void WebPluginProxy::UpdateGeometry( |
| 434 | const gfx::Rect& window_rect, |
| 435 | const gfx::Rect& clip_rect, |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 436 | const TransportDIB::Handle& windowless_buffer0, |
| 437 | const TransportDIB::Handle& windowless_buffer1, |
| 438 | int windowless_buffer_index, |
[email protected] | ab7f274 | 2010-04-14 17:24:51 | [diff] [blame] | 439 | const TransportDIB::Handle& background_buffer, |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 440 | bool transparent) { |
[email protected] | b94d332 | 2009-02-12 19:49:04 | [diff] [blame] | 441 | gfx::Rect old = delegate_->GetRect(); |
| 442 | gfx::Rect old_clip_rect = delegate_->GetClipRect(); |
[email protected] | ab7f274 | 2010-04-14 17:24:51 | [diff] [blame] | 443 | transparent_ = transparent; |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 444 | |
[email protected] | 2b5b8ba | 2010-03-06 15:32:44 | [diff] [blame] | 445 | // Update the buffers before doing anything that could call into plugin code, |
| 446 | // so that we don't process buffer changes out of order if plugins make |
| 447 | // synchronous calls that lead to nested UpdateGeometry calls. |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 448 | if (TransportDIB::is_valid_handle(windowless_buffer0)) { |
| 449 | // The plugin's rect changed, so now we have new buffers to draw into. |
| 450 | SetWindowlessBuffers(windowless_buffer0, |
| 451 | windowless_buffer1, |
| 452 | background_buffer, |
| 453 | window_rect); |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 454 | } |
[email protected] | 558833a | 2009-10-23 16:20:01 | [diff] [blame] | 455 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 456 | DCHECK(0 <= windowless_buffer_index && windowless_buffer_index <= 1); |
| 457 | windowless_buffer_index_ = windowless_buffer_index; |
| 458 | #if defined(USE_X11) |
| 459 | delegate_->SetWindowlessShmPixmap(windowless_shm_pixmap()); |
| 460 | #endif |
| 461 | |
[email protected] | 2b5b8ba | 2010-03-06 15:32:44 | [diff] [blame] | 462 | #if defined(OS_MACOSX) |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 463 | delegate_->UpdateGeometryAndContext( |
| 464 | window_rect, clip_rect, windowless_context()); |
[email protected] | 2b5b8ba | 2010-03-06 15:32:44 | [diff] [blame] | 465 | #else |
| 466 | delegate_->UpdateGeometry(window_rect, clip_rect); |
| 467 | #endif |
| 468 | |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 469 | // Send over any pending invalidates which occured when the plugin was |
| 470 | // off screen. |
[email protected] | b94d332 | 2009-02-12 19:49:04 | [diff] [blame] | 471 | if (delegate_->IsWindowless() && !clip_rect.IsEmpty() && |
[email protected] | a3edf844 | 2010-04-14 23:57:50 | [diff] [blame] | 472 | !damaged_rect_.IsEmpty()) { |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 473 | InvalidateRect(damaged_rect_); |
| 474 | } |
[email protected] | 22c54fdc | 2008-09-22 22:26:59 | [diff] [blame] | 475 | } |
| 476 | |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 477 | #if defined(OS_WIN) |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 478 | |
| 479 | void WebPluginProxy::CreateCanvasFromHandle( |
| 480 | const TransportDIB::Handle& dib_handle, |
| 481 | const gfx::Rect& window_rect, |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 482 | SkAutoTUnref<skia::PlatformCanvas>* canvas) { |
| 483 | canvas->reset(new skia::PlatformCanvas); |
| 484 | if (!canvas->get()->initialize( |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 485 | window_rect.width(), |
| 486 | window_rect.height(), |
| 487 | true, |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 488 | dib_handle)) { |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 489 | canvas->reset(NULL); |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 490 | } |
[email protected] | 1bfecd0 | 2011-07-29 00:54:20 | [diff] [blame] | 491 | // The canvas does not own the section so we need to close it now. |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 492 | CloseHandle(dib_handle); |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void WebPluginProxy::SetWindowlessBuffers( |
| 496 | const TransportDIB::Handle& windowless_buffer0, |
| 497 | const TransportDIB::Handle& windowless_buffer1, |
| 498 | const TransportDIB::Handle& background_buffer, |
| 499 | const gfx::Rect& window_rect) { |
| 500 | CreateCanvasFromHandle(windowless_buffer0, |
| 501 | window_rect, |
| 502 | &windowless_canvases_[0]); |
| 503 | if (!windowless_canvases_[0].get()) { |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 504 | windowless_canvases_[1].reset(NULL); |
| 505 | background_canvas_.reset(NULL); |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 506 | return; |
| 507 | } |
| 508 | CreateCanvasFromHandle(windowless_buffer1, |
| 509 | window_rect, |
| 510 | &windowless_canvases_[1]); |
| 511 | if (!windowless_canvases_[1].get()) { |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 512 | windowless_canvases_[0].reset(NULL); |
| 513 | background_canvas_.reset(NULL); |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 514 | return; |
| 515 | } |
| 516 | |
| 517 | if (background_buffer) { |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 518 | CreateCanvasFromHandle(background_buffer, |
| 519 | window_rect, |
| 520 | &background_canvas_); |
| 521 | if (!background_canvas_.get()) { |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 522 | windowless_canvases_[0].reset(NULL); |
| 523 | windowless_canvases_[1].reset(NULL); |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 524 | return; |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | #elif defined(OS_MACOSX) |
| 530 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 531 | void WebPluginProxy::CreateDIBAndCGContextFromHandle( |
| 532 | const TransportDIB::Handle& dib_handle, |
| 533 | const gfx::Rect& window_rect, |
| 534 | scoped_ptr<TransportDIB>* dib_out, |
| 535 | base::mac::ScopedCFTypeRef<CGContextRef>* cg_context_out) { |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 536 | // Convert the shared memory handle to a handle that works in our process, |
| 537 | // and then use that to create a CGContextRef. |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 538 | TransportDIB* dib = TransportDIB::Map(dib_handle); |
| 539 | CGContextRef cg_context = NULL; |
| 540 | if (dib) { |
| 541 | cg_context = CGBitmapContextCreate( |
| 542 | dib->memory(), |
[email protected] | 2b5b8ba | 2010-03-06 15:32:44 | [diff] [blame] | 543 | window_rect.width(), |
| 544 | window_rect.height(), |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 545 | 8, |
| 546 | 4 * window_rect.width(), |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 547 | base::mac::GetSystemColorSpace(), |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 548 | kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host); |
| 549 | CGContextTranslateCTM(cg_context, 0, window_rect.height()); |
| 550 | CGContextScaleCTM(cg_context, 1, -1); |
[email protected] | 6bf1a81 | 2009-07-11 01:57:28 | [diff] [blame] | 551 | } |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 552 | dib_out->reset(dib); |
| 553 | cg_context_out->reset(cg_context); |
| 554 | } |
| 555 | |
| 556 | void WebPluginProxy::SetWindowlessBuffers( |
| 557 | const TransportDIB::Handle& windowless_buffer0, |
| 558 | const TransportDIB::Handle& windowless_buffer1, |
| 559 | const TransportDIB::Handle& background_buffer, |
| 560 | const gfx::Rect& window_rect) { |
| 561 | CreateDIBAndCGContextFromHandle(windowless_buffer0, |
| 562 | window_rect, |
| 563 | &windowless_dibs_[0], |
| 564 | &windowless_contexts_[0]); |
| 565 | CreateDIBAndCGContextFromHandle(windowless_buffer1, |
| 566 | window_rect, |
| 567 | &windowless_dibs_[1], |
| 568 | &windowless_contexts_[1]); |
| 569 | CreateDIBAndCGContextFromHandle(background_buffer, |
| 570 | window_rect, |
| 571 | &background_dib_, |
| 572 | &background_context_); |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | #elif defined(USE_X11) |
| 576 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 577 | void WebPluginProxy::CreateDIBAndCanvasFromHandle( |
| 578 | const TransportDIB::Handle& dib_handle, |
| 579 | const gfx::Rect& window_rect, |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 580 | scoped_refptr<SharedTransportDIB>* dib_out, |
| 581 | SkAutoTUnref<skia::PlatformCanvas>* canvas) { |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 582 | TransportDIB* dib = TransportDIB::Map(dib_handle); |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 583 | // dib may be NULL if the renderer has already destroyed the TransportDIB by |
| 584 | // the time we receive the handle, e.g. in case of multiple resizes. |
| 585 | if (dib) { |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 586 | canvas->reset( |
| 587 | dib->GetPlatformCanvas(window_rect.width(), window_rect.height())); |
| 588 | } else { |
| 589 | canvas->reset(NULL); |
[email protected] | d8683e3 | 2010-10-06 11:52:32 | [diff] [blame] | 590 | } |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 591 | *dib_out = new SharedTransportDIB(dib); |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 592 | } |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 593 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 594 | void WebPluginProxy::CreateShmPixmapFromDIB( |
| 595 | TransportDIB* dib, |
| 596 | const gfx::Rect& window_rect, |
| 597 | XID* pixmap_out) { |
| 598 | if (dib) { |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 599 | Display* display = ui::GetXDisplay(); |
| 600 | XID root_window = ui::GetX11RootWindow(); |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 601 | XShmSegmentInfo shminfo = {0}; |
| 602 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 603 | if (*pixmap_out != None) |
| 604 | XFreePixmap(display, *pixmap_out); |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 605 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 606 | shminfo.shmseg = dib->MapToX(display); |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 607 | // Create a shared memory pixmap based on the image buffer. |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 608 | *pixmap_out = XShmCreatePixmap(display, root_window, |
| 609 | NULL, &shminfo, |
| 610 | window_rect.width(), window_rect.height(), |
[email protected] | 88a8ffa | 2011-10-13 01:41:05 | [diff] [blame] | 611 | DefaultDepth(display, |
| 612 | DefaultScreen(display))); |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 613 | } |
| 614 | } |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 615 | |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 616 | void WebPluginProxy::SetWindowlessBuffers( |
| 617 | const TransportDIB::Handle& windowless_buffer0, |
| 618 | const TransportDIB::Handle& windowless_buffer1, |
| 619 | const TransportDIB::Handle& background_buffer, |
| 620 | const gfx::Rect& window_rect) { |
| 621 | CreateDIBAndCanvasFromHandle(windowless_buffer0, |
| 622 | window_rect, |
| 623 | &windowless_dibs_[0], |
| 624 | &windowless_canvases_[0]); |
| 625 | CreateDIBAndCanvasFromHandle(windowless_buffer1, |
| 626 | window_rect, |
| 627 | &windowless_dibs_[1], |
| 628 | &windowless_canvases_[1]); |
| 629 | CreateDIBAndCanvasFromHandle(background_buffer, |
| 630 | window_rect, |
| 631 | &background_dib_, |
| 632 | &background_canvas_); |
| 633 | |
| 634 | // If SHM pixmaps support is available, create SHM pixmaps to pass to the |
| 635 | // delegate for windowless plugin painting. |
| 636 | if (delegate_->IsWindowless() && use_shm_pixmap_) { |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 637 | CreateShmPixmapFromDIB(windowless_dibs_[0]->dib(), |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 638 | window_rect, |
| 639 | &windowless_shm_pixmaps_[0]); |
[email protected] | 78d17234 | 2012-08-15 20:27:35 | [diff] [blame] | 640 | CreateShmPixmapFromDIB(windowless_dibs_[1]->dib(), |
[email protected] | 9cf75568 | 2011-07-25 22:13:52 | [diff] [blame] | 641 | window_rect, |
| 642 | &windowless_shm_pixmaps_[1]); |
[email protected] | cb632c3 | 2010-08-05 02:54:42 | [diff] [blame] | 643 | } |
[email protected] | ae849ea | 2010-10-20 18:00:36 | [diff] [blame] | 644 | } |
[email protected] | d8683e3 | 2010-10-06 11:52:32 | [diff] [blame] | 645 | |
[email protected] | e082556 | 2012-05-10 01:50:47 | [diff] [blame] | 646 | #elif defined(OS_ANDROID) |
| 647 | |
| 648 | void WebPluginProxy::SetWindowlessBuffers( |
| 649 | const TransportDIB::Handle& windowless_buffer0, |
| 650 | const TransportDIB::Handle& windowless_buffer1, |
| 651 | const TransportDIB::Handle& background_buffer, |
| 652 | const gfx::Rect& window_rect) { |
| 653 | NOTIMPLEMENTED(); |
| 654 | } |
| 655 | |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 656 | #endif |
| 657 | |
[email protected] | 6f863cd | 2008-12-05 22:27:39 | [diff] [blame] | 658 | void WebPluginProxy::CancelDocumentLoad() { |
| 659 | Send(new PluginHostMsg_CancelDocumentLoad(route_id_)); |
| 660 | } |
| 661 | |
[email protected] | ea3d1d8 | 2010-01-29 22:35:33 | [diff] [blame] | 662 | void WebPluginProxy::InitiateHTTPRangeRequest( |
| 663 | const char* url, const char* range_info, int range_request_id) { |
| 664 | Send(new PluginHostMsg_InitiateHTTPRangeRequest( |
| 665 | route_id_, url, range_info, range_request_id)); |
[email protected] | 84f89ca | 2008-09-19 02:09:49 | [diff] [blame] | 666 | } |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 667 | |
[email protected] | 3d248b2 | 2009-12-03 07:11:34 | [diff] [blame] | 668 | void WebPluginProxy::SetDeferResourceLoading(unsigned long resource_id, |
| 669 | bool defer) { |
[email protected] | e15e9c49 | 2009-08-04 07:06:39 | [diff] [blame] | 670 | Send(new PluginHostMsg_DeferResourceLoading(route_id_, resource_id, defer)); |
| 671 | } |
| 672 | |
[email protected] | 3d1e89d | 2010-03-10 20:01:35 | [diff] [blame] | 673 | #if defined(OS_MACOSX) |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 674 | void WebPluginProxy::FocusChanged(bool focused) { |
| 675 | IPC::Message* msg = new PluginHostMsg_FocusChanged(route_id_, focused); |
| 676 | Send(msg); |
| 677 | } |
| 678 | |
| 679 | void WebPluginProxy::StartIme() { |
| 680 | IPC::Message* msg = new PluginHostMsg_StartIme(route_id_); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 681 | // This message can be sent during event-handling, and needs to be delivered |
| 682 | // within that context. |
| 683 | msg->set_unblock(true); |
| 684 | Send(msg); |
| 685 | } |
| 686 | |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 687 | void WebPluginProxy::BindFakePluginWindowHandle(bool opaque) { |
| 688 | Send(new PluginHostMsg_BindFakePluginWindowHandle(route_id_, opaque)); |
[email protected] | 3d1e89d | 2010-03-10 20:01:35 | [diff] [blame] | 689 | } |
| 690 | |
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 691 | WebPluginAcceleratedSurface* WebPluginProxy::GetAcceleratedSurface( |
| 692 | gfx::GpuPreference gpu_preference) { |
[email protected] | 8b4755f | 2010-10-01 18:04:06 | [diff] [blame] | 693 | if (!accelerated_surface_.get()) |
[email protected] | dc51d1c | 2011-11-30 04:42:21 | [diff] [blame] | 694 | accelerated_surface_.reset( |
| 695 | WebPluginAcceleratedSurfaceProxy::Create(this, gpu_preference)); |
[email protected] | 8b4755f | 2010-10-01 18:04:06 | [diff] [blame] | 696 | return accelerated_surface_.get(); |
| 697 | } |
| 698 | |
[email protected] | 3d1e89d | 2010-03-10 20:01:35 | [diff] [blame] | 699 | void WebPluginProxy::AcceleratedFrameBuffersDidSwap( |
[email protected] | 7de8fb7 | 2012-03-14 04:24:32 | [diff] [blame] | 700 | gfx::PluginWindowHandle window, uint64 surface_handle) { |
[email protected] | f35d667 | 2010-10-28 21:39:14 | [diff] [blame] | 701 | Send(new PluginHostMsg_AcceleratedSurfaceBuffersSwapped( |
[email protected] | 7de8fb7 | 2012-03-14 04:24:32 | [diff] [blame] | 702 | route_id_, window, surface_handle)); |
[email protected] | 3d1e89d | 2010-03-10 20:01:35 | [diff] [blame] | 703 | } |
| 704 | |
[email protected] | 8b4755f | 2010-10-01 18:04:06 | [diff] [blame] | 705 | void WebPluginProxy::SetAcceleratedSurface( |
| 706 | gfx::PluginWindowHandle window, |
| 707 | const gfx::Size& size, |
[email protected] | 3d1e89d | 2010-03-10 20:01:35 | [diff] [blame] | 708 | uint64 accelerated_surface_identifier) { |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 709 | Send(new PluginHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 8b4755f | 2010-10-01 18:04:06 | [diff] [blame] | 710 | route_id_, window, size.width(), size.height(), |
| 711 | accelerated_surface_identifier)); |
| 712 | } |
| 713 | |
| 714 | void WebPluginProxy::SetAcceleratedDIB( |
| 715 | gfx::PluginWindowHandle window, |
| 716 | const gfx::Size& size, |
| 717 | const TransportDIB::Handle& dib_handle) { |
| 718 | Send(new PluginHostMsg_AcceleratedSurfaceSetTransportDIB( |
| 719 | route_id_, window, size.width(), size.height(), dib_handle)); |
| 720 | } |
| 721 | |
| 722 | void WebPluginProxy::AllocSurfaceDIB(const size_t size, |
| 723 | TransportDIB::Handle* dib_handle) { |
| 724 | Send(new PluginHostMsg_AllocTransportDIB(route_id_, size, dib_handle)); |
| 725 | } |
| 726 | |
| 727 | void WebPluginProxy::FreeSurfaceDIB(TransportDIB::Id dib_id) { |
| 728 | Send(new PluginHostMsg_FreeTransportDIB(route_id_, dib_id)); |
[email protected] | 3d1e89d | 2010-03-10 20:01:35 | [diff] [blame] | 729 | } |
[email protected] | dc51d1c | 2011-11-30 04:42:21 | [diff] [blame] | 730 | |
| 731 | void WebPluginProxy::AcceleratedPluginEnabledRendering() { |
| 732 | Send(new PluginHostMsg_AcceleratedPluginEnabledRendering(route_id_)); |
| 733 | } |
| 734 | |
| 735 | void WebPluginProxy::AcceleratedPluginAllocatedIOSurface(int32 width, |
| 736 | int32 height, |
| 737 | uint32 surface_id) { |
| 738 | Send(new PluginHostMsg_AcceleratedPluginAllocatedIOSurface( |
| 739 | route_id_, width, height, surface_id)); |
| 740 | } |
| 741 | |
| 742 | void WebPluginProxy::AcceleratedPluginSwappedIOSurface() { |
| 743 | Send(new PluginHostMsg_AcceleratedPluginSwappedIOSurface( |
| 744 | route_id_)); |
| 745 | } |
[email protected] | 3d1e89d | 2010-03-10 20:01:35 | [diff] [blame] | 746 | #endif |
| 747 | |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 748 | void WebPluginProxy::OnPaint(const gfx::Rect& damaged_rect) { |
[email protected] | a82151cc | 2011-03-15 20:42:39 | [diff] [blame] | 749 | content::GetContentClient()->SetActiveURL(page_url_); |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 750 | |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 751 | Paint(damaged_rect); |
[email protected] | a0b4cb8 | 2012-09-11 19:47:18 | [diff] [blame] | 752 | Send(new PluginHostMsg_InvalidateRect(route_id_, damaged_rect)); |
[email protected] | f1a0eae | 2008-11-21 18:29:14 | [diff] [blame] | 753 | } |
[email protected] | 3c8bd9f | 2009-03-26 19:40:29 | [diff] [blame] | 754 | |
| 755 | bool WebPluginProxy::IsOffTheRecord() { |
[email protected] | d5e4445 | 2011-03-10 18:12:10 | [diff] [blame] | 756 | return channel_->incognito(); |
[email protected] | 3c8bd9f | 2009-03-26 19:40:29 | [diff] [blame] | 757 | } |
[email protected] | 0a70323 | 2009-05-23 01:30:33 | [diff] [blame] | 758 | |
| 759 | void WebPluginProxy::ResourceClientDeleted( |
| 760 | WebPluginResourceClient* resource_client) { |
| 761 | ResourceClientMap::iterator index = resource_clients_.begin(); |
| 762 | while (index != resource_clients_.end()) { |
| 763 | WebPluginResourceClient* client = (*index).second; |
| 764 | |
| 765 | if (client == resource_client) { |
| 766 | resource_clients_.erase(index++); |
| 767 | } else { |
| 768 | index++; |
| 769 | } |
| 770 | } |
| 771 | } |
[email protected] | 65e82a56 | 2010-11-23 00:34:27 | [diff] [blame] | 772 | |
| 773 | void WebPluginProxy::URLRedirectResponse(bool allow, int resource_id) { |
| 774 | Send(new PluginHostMsg_URLRedirectResponse(route_id_, allow, resource_id)); |
| 775 | } |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 776 | |
[email protected] | e5b307f | 2011-10-06 22:55:28 | [diff] [blame] | 777 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 778 | void WebPluginProxy::UpdateIMEStatus() { |
| 779 | // Retrieve the IME status from a plug-in and send it to a renderer process |
| 780 | // when the plug-in has updated it. |
| 781 | int input_type; |
| 782 | gfx::Rect caret_rect; |
| 783 | if (!delegate_->GetIMEStatus(&input_type, &caret_rect)) |
| 784 | return; |
| 785 | |
| 786 | Send(new PluginHostMsg_NotifyIMEStatus(route_id_, input_type, caret_rect)); |
| 787 | } |
| 788 | #endif |