| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/plugin/webplugin_proxy.h" | 5 #include "content/plugin/webplugin_proxy.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "content/child/npapi/npobject_proxy.h" | |
| 12 #include "content/child/npapi/npobject_util.h" | |
| 13 #include "content/child/npapi/webplugin_delegate_impl.h" | 11 #include "content/child/npapi/webplugin_delegate_impl.h" |
| 14 #include "content/child/plugin_messages.h" | 12 #include "content/child/plugin_messages.h" |
| 15 #include "content/plugin/plugin_channel.h" | 13 #include "content/plugin/plugin_channel.h" |
| 16 #include "content/plugin/plugin_thread.h" | 14 #include "content/plugin/plugin_thread.h" |
| 17 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
| 18 #include "skia/ext/platform_canvas.h" | 16 #include "skia/ext/platform_canvas.h" |
| 19 #include "third_party/WebKit/public/web/WebBindings.h" | |
| 20 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 21 #include "url/url_constants.h" | 18 #include "url/url_constants.h" |
| 22 | 19 |
| 23 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
| 24 #include "base/mac/mac_util.h" | 21 #include "base/mac/mac_util.h" |
| 25 #include "base/mac/scoped_cftyperef.h" | 22 #include "base/mac/scoped_cftyperef.h" |
| 26 #include "content/plugin/webplugin_accelerated_surface_proxy_mac.h" | 23 #include "content/plugin/webplugin_accelerated_surface_proxy_mac.h" |
| 27 #endif | 24 #endif |
| 28 | 25 |
| 29 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 30 #include "content/common/plugin_process_messages.h" | 27 #include "content/common/plugin_process_messages.h" |
| 31 #include "content/public/common/sandbox_init.h" | 28 #include "content/public/common/sandbox_init.h" |
| 32 #endif | 29 #endif |
| 33 | 30 |
| 34 using blink::WebBindings; | |
| 35 | |
| 36 namespace content { | 31 namespace content { |
| 37 | 32 |
| 38 WebPluginProxy::SharedTransportDIB::SharedTransportDIB(TransportDIB* dib) | 33 WebPluginProxy::SharedTransportDIB::SharedTransportDIB(TransportDIB* dib) |
| 39 : dib_(dib) { | 34 : dib_(dib) { |
| 40 } | 35 } |
| 41 | 36 |
| 42 WebPluginProxy::SharedTransportDIB::~SharedTransportDIB() { | 37 WebPluginProxy::SharedTransportDIB::~SharedTransportDIB() { |
| 43 } | 38 } |
| 44 | 39 |
| 45 WebPluginProxy::WebPluginProxy( | 40 WebPluginProxy::WebPluginProxy( |
| 46 PluginChannel* channel, | 41 PluginChannel* channel, |
| 47 int route_id, | 42 int route_id, |
| 48 const GURL& page_url, | 43 const GURL& page_url, |
| 49 int host_render_view_routing_id) | 44 int host_render_view_routing_id) |
| 50 : channel_(channel), | 45 : channel_(channel), |
| 51 route_id_(route_id), | 46 route_id_(route_id), |
| 52 window_npobject_(NULL), | |
| 53 plugin_element_(NULL), | |
| 54 delegate_(NULL), | 47 delegate_(NULL), |
| 55 waiting_for_paint_(false), | 48 waiting_for_paint_(false), |
| 56 page_url_(page_url), | 49 page_url_(page_url), |
| 57 windowless_buffer_index_(0), | 50 windowless_buffer_index_(0), |
| 58 host_render_view_routing_id_(host_render_view_routing_id), | 51 host_render_view_routing_id_(host_render_view_routing_id), |
| 59 weak_factory_(this) { | 52 weak_factory_(this) { |
| 60 } | 53 } |
| 61 | 54 |
| 62 WebPluginProxy::~WebPluginProxy() { | 55 WebPluginProxy::~WebPluginProxy() { |
| 63 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
| 64 // Destroy the surface early, since it may send messages during cleanup. | 57 // Destroy the surface early, since it may send messages during cleanup. |
| 65 if (accelerated_surface_) | 58 if (accelerated_surface_) |
| 66 accelerated_surface_.reset(); | 59 accelerated_surface_.reset(); |
| 67 #endif | 60 #endif |
| 68 | |
| 69 if (plugin_element_) | |
| 70 WebBindings::releaseObject(plugin_element_); | |
| 71 if (window_npobject_) | |
| 72 WebBindings::releaseObject(window_npobject_); | |
| 73 } | 61 } |
| 74 | 62 |
| 75 bool WebPluginProxy::Send(IPC::Message* msg) { | 63 bool WebPluginProxy::Send(IPC::Message* msg) { |
| 76 return channel_->Send(msg); | 64 return channel_->Send(msg); |
| 77 } | 65 } |
| 78 | 66 |
| 79 void WebPluginProxy::Invalidate() { | 67 void WebPluginProxy::Invalidate() { |
| 80 gfx::Rect rect(0, 0, | 68 gfx::Rect rect(0, 0, |
| 81 delegate_->GetRect().width(), | 69 delegate_->GetRect().width(), |
| 82 delegate_->GetRect().height()); | 70 delegate_->GetRect().height()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // need to be painted asynchronously as per the NPAPI spec. | 111 // need to be painted asynchronously as per the NPAPI spec. |
| 124 base::MessageLoop::current()->PostTask( | 112 base::MessageLoop::current()->PostTask( |
| 125 FROM_HERE, | 113 FROM_HERE, |
| 126 base::Bind(&WebPluginProxy::OnPaint, | 114 base::Bind(&WebPluginProxy::OnPaint, |
| 127 weak_factory_.GetWeakPtr(), | 115 weak_factory_.GetWeakPtr(), |
| 128 damaged_rect_)); | 116 damaged_rect_)); |
| 129 damaged_rect_ = gfx::Rect(); | 117 damaged_rect_ = gfx::Rect(); |
| 130 } | 118 } |
| 131 } | 119 } |
| 132 | 120 |
| 133 NPObject* WebPluginProxy::GetWindowScriptNPObject() { | |
| 134 if (window_npobject_) | |
| 135 return window_npobject_; | |
| 136 | |
| 137 int npobject_route_id = channel_->GenerateRouteID(); | |
| 138 bool success = false; | |
| 139 Send(new PluginHostMsg_GetWindowScriptNPObject( | |
| 140 route_id_, npobject_route_id, &success)); | |
| 141 if (!success) | |
| 142 return NULL; | |
| 143 | |
| 144 // PluginChannel creates a dummy owner identifier for unknown owners, so | |
| 145 // use that. | |
| 146 NPP owner = channel_->GetExistingNPObjectOwner(MSG_ROUTING_NONE); | |
| 147 | |
| 148 window_npobject_ = NPObjectProxy::Create(channel_.get(), | |
| 149 npobject_route_id, | |
| 150 host_render_view_routing_id_, | |
| 151 page_url_, | |
| 152 owner); | |
| 153 | |
| 154 return window_npobject_; | |
| 155 } | |
| 156 | |
| 157 NPObject* WebPluginProxy::GetPluginElement() { | |
| 158 if (plugin_element_) | |
| 159 return plugin_element_; | |
| 160 | |
| 161 int npobject_route_id = channel_->GenerateRouteID(); | |
| 162 bool success = false; | |
| 163 Send(new PluginHostMsg_GetPluginElement(route_id_, npobject_route_id, | |
| 164 &success)); | |
| 165 if (!success) | |
| 166 return NULL; | |
| 167 | |
| 168 // PluginChannel creates a dummy owner identifier for unknown owners, so | |
| 169 // use that. | |
| 170 NPP owner = channel_->GetExistingNPObjectOwner(MSG_ROUTING_NONE); | |
| 171 | |
| 172 plugin_element_ = NPObjectProxy::Create(channel_.get(), | |
| 173 npobject_route_id, | |
| 174 host_render_view_routing_id_, | |
| 175 page_url_, | |
| 176 owner); | |
| 177 | |
| 178 return plugin_element_; | |
| 179 } | |
| 180 | |
| 181 bool WebPluginProxy::FindProxyForUrl(const GURL& url, std::string* proxy_list) { | 121 bool WebPluginProxy::FindProxyForUrl(const GURL& url, std::string* proxy_list) { |
| 182 bool result = false; | 122 bool result = false; |
| 183 Send(new PluginHostMsg_ResolveProxy(route_id_, url, &result, proxy_list)); | 123 Send(new PluginHostMsg_ResolveProxy(route_id_, url, &result, proxy_list)); |
| 184 return result; | 124 return result; |
| 185 } | 125 } |
| 186 | 126 |
| 187 void WebPluginProxy::SetCookie(const GURL& url, | 127 void WebPluginProxy::SetCookie(const GURL& url, |
| 188 const GURL& first_party_for_cookies, | 128 const GURL& first_party_for_cookies, |
| 189 const std::string& cookie) { | 129 const std::string& cookie) { |
| 190 Send(new PluginHostMsg_SetCookie(route_id_, url, | 130 Send(new PluginHostMsg_SetCookie(route_id_, url, |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 396 |
| 457 Paint(damaged_rect); | 397 Paint(damaged_rect); |
| 458 Send(new PluginHostMsg_InvalidateRect(route_id_, damaged_rect)); | 398 Send(new PluginHostMsg_InvalidateRect(route_id_, damaged_rect)); |
| 459 } | 399 } |
| 460 | 400 |
| 461 bool WebPluginProxy::IsOffTheRecord() { | 401 bool WebPluginProxy::IsOffTheRecord() { |
| 462 return channel_->incognito(); | 402 return channel_->incognito(); |
| 463 } | 403 } |
| 464 | 404 |
| 465 } // namespace content | 405 } // namespace content |
| OLD | NEW |