| 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 "ppapi/proxy/ppp_instance_proxy.h" | 5 #include "ppapi/proxy/ppp_instance_proxy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "ppapi/c/pp_var.h" | 10 #include "ppapi/c/pp_var.h" |
| 11 #include "ppapi/c/ppb_core.h" | 11 #include "ppapi/c/ppb_core.h" |
| 12 #include "ppapi/c/ppb_fullscreen.h" | 12 #include "ppapi/c/ppb_fullscreen.h" |
| 13 #include "ppapi/c/ppp_instance.h" | 13 #include "ppapi/c/ppp_instance.h" |
| 14 #include "ppapi/proxy/host_dispatcher.h" | 14 #include "ppapi/proxy/host_dispatcher.h" |
| 15 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
| 16 #include "ppapi/proxy/plugin_globals.h" |
| 17 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| 16 #include "ppapi/proxy/plugin_resource_tracker.h" | 18 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 17 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
| 18 #include "ppapi/proxy/ppb_url_loader_proxy.h" | 20 #include "ppapi/proxy/url_loader_resource.h" |
| 19 #include "ppapi/shared_impl/ppapi_globals.h" | 21 #include "ppapi/shared_impl/ppapi_globals.h" |
| 20 #include "ppapi/shared_impl/ppb_view_shared.h" | 22 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 23 #include "ppapi/shared_impl/resource_tracker.h" |
| 21 #include "ppapi/shared_impl/scoped_pp_resource.h" | 24 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 22 #include "ppapi/thunk/enter.h" | 25 #include "ppapi/thunk/enter.h" |
| 23 #include "ppapi/thunk/ppb_flash_fullscreen_api.h" | 26 #include "ppapi/thunk/ppb_flash_fullscreen_api.h" |
| 24 #include "ppapi/thunk/ppb_view_api.h" | 27 #include "ppapi/thunk/ppb_view_api.h" |
| 25 | 28 |
| 26 namespace ppapi { | 29 namespace ppapi { |
| 27 namespace proxy { | 30 namespace proxy { |
| 28 | 31 |
| 29 using thunk::EnterInstanceAPINoLock; | 32 using thunk::EnterInstanceAPINoLock; |
| 30 using thunk::EnterInstanceNoLock; | 33 using thunk::EnterInstanceNoLock; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 API_ID_PPP_INSTANCE, instance, enter_view.object()->GetData(), | 79 API_ID_PPP_INSTANCE, instance, enter_view.object()->GetData(), |
| 77 flash_fullscreen)); | 80 flash_fullscreen)); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { | 83 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { |
| 81 HostDispatcher::GetForInstance(instance)->Send( | 84 HostDispatcher::GetForInstance(instance)->Send( |
| 82 new PpapiMsg_PPPInstance_DidChangeFocus(API_ID_PPP_INSTANCE, | 85 new PpapiMsg_PPPInstance_DidChangeFocus(API_ID_PPP_INSTANCE, |
| 83 instance, has_focus)); | 86 instance, has_focus)); |
| 84 } | 87 } |
| 85 | 88 |
| 86 PP_Bool HandleDocumentLoad(PP_Instance instance, | 89 PP_Bool HandleDocumentLoad(PP_Instance instance, PP_Resource url_loader) { |
| 87 PP_Resource url_loader) { | 90 // This should never get called. Out-of-process document loads are handled |
| 88 PP_Bool result = PP_FALSE; | 91 // specially. |
| 89 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 92 NOTREACHED(); |
| 90 | 93 return PP_FALSE; |
| 91 // Set up the URLLoader for proxying. | |
| 92 | |
| 93 PPB_URLLoader_Proxy* url_loader_proxy = static_cast<PPB_URLLoader_Proxy*>( | |
| 94 dispatcher->GetInterfaceProxy(API_ID_PPB_URL_LOADER)); | |
| 95 url_loader_proxy->PrepareURLLoaderForSendingToPlugin(url_loader); | |
| 96 | |
| 97 // PluginResourceTracker in the plugin process assumes that resources that it | |
| 98 // tracks have been addrefed on behalf of the plugin at the renderer side. So | |
| 99 // we explicitly do it for |url_loader| here. | |
| 100 // | |
| 101 // Please also see comments in PPP_Instance_Proxy::OnMsgHandleDocumentLoad() | |
| 102 // about releasing of this extra reference. | |
| 103 const PPB_Core* core = reinterpret_cast<const PPB_Core*>( | |
| 104 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); | |
| 105 if (!core) { | |
| 106 NOTREACHED(); | |
| 107 return PP_FALSE; | |
| 108 } | |
| 109 core->AddRefResource(url_loader); | |
| 110 | |
| 111 HostResource serialized_loader; | |
| 112 serialized_loader.SetHostResource(instance, url_loader); | |
| 113 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | |
| 114 API_ID_PPP_INSTANCE, instance, serialized_loader, &result)); | |
| 115 return result; | |
| 116 } | 94 } |
| 117 | 95 |
| 118 static const PPP_Instance_1_1 instance_interface = { | 96 static const PPP_Instance_1_1 instance_interface = { |
| 119 &DidCreate, | 97 &DidCreate, |
| 120 &DidDestroy, | 98 &DidDestroy, |
| 121 &DidChangeView, | 99 &DidChangeView, |
| 122 &DidChangeFocus, | 100 &DidChangeFocus, |
| 123 &HandleDocumentLoad | 101 &HandleDocumentLoad |
| 124 }; | 102 }; |
| 125 #endif // !defined(OS_NACL) | 103 #endif // !defined(OS_NACL) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 &new_data.clip_rect); | 224 &new_data.clip_rect); |
| 247 } | 225 } |
| 248 | 226 |
| 249 void PPP_Instance_Proxy::OnPluginMsgDidChangeFocus(PP_Instance instance, | 227 void PPP_Instance_Proxy::OnPluginMsgDidChangeFocus(PP_Instance instance, |
| 250 PP_Bool has_focus) { | 228 PP_Bool has_focus) { |
| 251 combined_interface_->DidChangeFocus(instance, has_focus); | 229 combined_interface_->DidChangeFocus(instance, has_focus); |
| 252 } | 230 } |
| 253 | 231 |
| 254 void PPP_Instance_Proxy::OnPluginMsgHandleDocumentLoad( | 232 void PPP_Instance_Proxy::OnPluginMsgHandleDocumentLoad( |
| 255 PP_Instance instance, | 233 PP_Instance instance, |
| 256 const HostResource& url_loader, | 234 int pending_loader_host_id, |
| 257 PP_Bool* result) { | 235 const URLResponseInfoData& data) { |
| 258 PP_Resource plugin_loader = | 236 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 259 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); | 237 if (!dispatcher) |
| 260 *result = combined_interface_->HandleDocumentLoad(instance, plugin_loader); | 238 return; |
| 239 Connection connection(PluginGlobals::Get()->GetBrowserSender(), |
| 240 dispatcher); |
| 261 | 241 |
| 262 // This balances the one reference that TrackPluginResource() initialized it | 242 scoped_refptr<URLLoaderResource> loader_resource( |
| 263 // with. The plugin will normally take an additional reference which will keep | 243 new URLLoaderResource(connection, instance, |
| 264 // the resource alive in the plugin (and the one reference in the renderer | 244 pending_loader_host_id, data)); |
| 265 // representing all plugin references). | 245 |
| 266 // Once all references at the plugin side are released, the renderer side will | 246 PP_Resource loader_pp_resource = loader_resource->GetReference(); |
| 267 // be notified and release the reference added in HandleDocumentLoad() above. | 247 if (!combined_interface_->HandleDocumentLoad(instance, loader_pp_resource)) |
| 268 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(plugin_loader); | 248 loader_resource->Close(); |
| 249 // We don't pass a ref into the plugin, if it wants one, it will have taken |
| 250 // an additional one. |
| 251 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource( |
| 252 loader_pp_resource); |
| 269 } | 253 } |
| 270 | 254 |
| 271 } // namespace proxy | 255 } // namespace proxy |
| 272 } // namespace ppapi | 256 } // namespace ppapi |
| OLD | NEW |