| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/c/dev/ppb_fullscreen_dev.h" | 9 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 10 #include "ppapi/c/pp_var.h" | 10 #include "ppapi/c/pp_var.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 instance, *position, *clip, | 58 instance, *position, *clip, |
| 59 fullscreen)); | 59 fullscreen)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { | 62 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { |
| 63 HostDispatcher::GetForInstance(instance)->Send( | 63 HostDispatcher::GetForInstance(instance)->Send( |
| 64 new PpapiMsg_PPPInstance_DidChangeFocus(INTERFACE_ID_PPP_INSTANCE, | 64 new PpapiMsg_PPPInstance_DidChangeFocus(INTERFACE_ID_PPP_INSTANCE, |
| 65 instance, has_focus)); | 65 instance, has_focus)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 PP_Bool HandleInputEvent(PP_Instance instance, | |
| 69 const PP_InputEvent* event) { | |
| 70 PP_Bool result = PP_FALSE; | |
| 71 IPC::Message* msg = new PpapiMsg_PPPInstance_HandleInputEvent( | |
| 72 INTERFACE_ID_PPP_INSTANCE, instance, *event, &result); | |
| 73 // Make this message not unblock, to avoid re-entrancy problems when the | |
| 74 // plugin does a synchronous call to the renderer. This will force any | |
| 75 // synchronous calls from the plugin to complete before processing this | |
| 76 // message. We avoid deadlock by never un-setting the unblock flag on messages | |
| 77 // from the plugin to the renderer. | |
| 78 msg->set_unblock(false); | |
| 79 HostDispatcher::GetForInstance(instance)->Send(msg); | |
| 80 return result; | |
| 81 } | |
| 82 | |
| 83 PP_Bool HandleDocumentLoad(PP_Instance instance, | 68 PP_Bool HandleDocumentLoad(PP_Instance instance, |
| 84 PP_Resource url_loader) { | 69 PP_Resource url_loader) { |
| 85 PP_Bool result = PP_FALSE; | 70 PP_Bool result = PP_FALSE; |
| 86 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 71 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 87 | 72 |
| 88 // Set up the URLLoader for proxying. | 73 // Set up the URLLoader for proxying. |
| 89 | 74 |
| 90 PPB_URLLoader_Proxy* url_loader_proxy = static_cast<PPB_URLLoader_Proxy*>( | 75 PPB_URLLoader_Proxy* url_loader_proxy = static_cast<PPB_URLLoader_Proxy*>( |
| 91 dispatcher->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_URL_LOADER)); | 76 dispatcher->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_URL_LOADER)); |
| 92 url_loader_proxy->PrepareURLLoaderForSendingToPlugin(url_loader); | 77 url_loader_proxy->PrepareURLLoaderForSendingToPlugin(url_loader); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 } | 90 } |
| 106 core->AddRefResource(url_loader); | 91 core->AddRefResource(url_loader); |
| 107 | 92 |
| 108 HostResource serialized_loader; | 93 HostResource serialized_loader; |
| 109 serialized_loader.SetHostResource(instance, url_loader); | 94 serialized_loader.SetHostResource(instance, url_loader); |
| 110 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 95 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
| 111 INTERFACE_ID_PPP_INSTANCE, instance, serialized_loader, &result)); | 96 INTERFACE_ID_PPP_INSTANCE, instance, serialized_loader, &result)); |
| 112 return result; | 97 return result; |
| 113 } | 98 } |
| 114 | 99 |
| 115 static const PPP_Instance_0_5 instance_interface_0_5 = { | 100 static const PPP_Instance_1_0 instance_interface_1_0 = { |
| 116 &DidCreate, | 101 &DidCreate, |
| 117 &DidDestroy, | 102 &DidDestroy, |
| 118 &DidChangeView, | 103 &DidChangeView, |
| 119 &DidChangeFocus, | 104 &DidChangeFocus, |
| 120 &HandleInputEvent, | |
| 121 &HandleDocumentLoad | 105 &HandleDocumentLoad |
| 122 }; | 106 }; |
| 123 | 107 |
| 124 template <class PPP_Instance_Type> | 108 template <class PPP_Instance_Type> |
| 125 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher, | 109 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher, |
| 126 const void* target_interface) { | 110 const void* target_interface) { |
| 127 return new PPP_Instance_Proxy( | 111 return new PPP_Instance_Proxy( |
| 128 dispatcher, | 112 dispatcher, |
| 129 static_cast<const PPP_Instance_Type*>(target_interface)); | 113 static_cast<const PPP_Instance_Type*>(target_interface)); |
| 130 } | 114 } |
| 131 | 115 |
| 132 } // namespace | 116 } // namespace |
| 133 | 117 |
| 134 PPP_Instance_Proxy::~PPP_Instance_Proxy() { | 118 PPP_Instance_Proxy::~PPP_Instance_Proxy() { |
| 135 } | 119 } |
| 136 | 120 |
| 137 // static | 121 // static |
| 138 const InterfaceProxy::Info* PPP_Instance_Proxy::GetInfo0_5() { | 122 const InterfaceProxy::Info* PPP_Instance_Proxy::GetInfo1_0() { |
| 139 static const Info info = { | 123 static const Info info = { |
| 140 &instance_interface_0_5, | 124 &instance_interface_1_0, |
| 141 PPP_INSTANCE_INTERFACE_0_5, | 125 PPP_INSTANCE_INTERFACE_1_0, |
| 142 INTERFACE_ID_PPP_INSTANCE, | 126 INTERFACE_ID_PPP_INSTANCE, |
| 143 false, | 127 false, |
| 144 &CreateInstanceProxy<PPP_Instance_0_5>, | 128 &CreateInstanceProxy<PPP_Instance_1_0>, |
| 145 }; | 129 }; |
| 146 return &info; | 130 return &info; |
| 147 } | 131 } |
| 148 | 132 |
| 149 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { | 133 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 150 bool handled = true; | 134 bool handled = true; |
| 151 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) | 135 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) |
| 152 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, | 136 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, |
| 153 OnMsgDidCreate) | 137 OnMsgDidCreate) |
| 154 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, | 138 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, |
| 155 OnMsgDidDestroy) | 139 OnMsgDidDestroy) |
| 156 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, | 140 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, |
| 157 OnMsgDidChangeView) | 141 OnMsgDidChangeView) |
| 158 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, | 142 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, |
| 159 OnMsgDidChangeFocus) | 143 OnMsgDidChangeFocus) |
| 160 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_HandleInputEvent, | |
| 161 OnMsgHandleInputEvent) | |
| 162 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_HandleDocumentLoad, | 144 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_HandleDocumentLoad, |
| 163 OnMsgHandleDocumentLoad) | 145 OnMsgHandleDocumentLoad) |
| 164 IPC_MESSAGE_UNHANDLED(handled = false) | 146 IPC_MESSAGE_UNHANDLED(handled = false) |
| 165 IPC_END_MESSAGE_MAP() | 147 IPC_END_MESSAGE_MAP() |
| 166 return handled; | 148 return handled; |
| 167 } | 149 } |
| 168 | 150 |
| 169 void PPP_Instance_Proxy::OnMsgDidCreate( | 151 void PPP_Instance_Proxy::OnMsgDidCreate( |
| 170 PP_Instance instance, | 152 PP_Instance instance, |
| 171 const std::vector<std::string>& argn, | 153 const std::vector<std::string>& argn, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 data->position = position; | 199 data->position = position; |
| 218 data->fullscreen = fullscreen; | 200 data->fullscreen = fullscreen; |
| 219 combined_interface_->DidChangeView(instance, &position, &clip); | 201 combined_interface_->DidChangeView(instance, &position, &clip); |
| 220 } | 202 } |
| 221 | 203 |
| 222 void PPP_Instance_Proxy::OnMsgDidChangeFocus(PP_Instance instance, | 204 void PPP_Instance_Proxy::OnMsgDidChangeFocus(PP_Instance instance, |
| 223 PP_Bool has_focus) { | 205 PP_Bool has_focus) { |
| 224 combined_interface_->DidChangeFocus(instance, has_focus); | 206 combined_interface_->DidChangeFocus(instance, has_focus); |
| 225 } | 207 } |
| 226 | 208 |
| 227 void PPP_Instance_Proxy::OnMsgHandleInputEvent(PP_Instance instance, | |
| 228 const PP_InputEvent& event, | |
| 229 PP_Bool* result) { | |
| 230 *result = combined_interface_->HandleInputEvent(instance, &event); | |
| 231 } | |
| 232 | |
| 233 void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance, | 209 void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance, |
| 234 const HostResource& url_loader, | 210 const HostResource& url_loader, |
| 235 PP_Bool* result) { | 211 PP_Bool* result) { |
| 236 PP_Resource plugin_loader = | 212 PP_Resource plugin_loader = |
| 237 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); | 213 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); |
| 238 *result = combined_interface_->HandleDocumentLoad(instance, plugin_loader); | 214 *result = combined_interface_->HandleDocumentLoad(instance, plugin_loader); |
| 239 | 215 |
| 240 // This balances the one reference that TrackPluginResource() initialized it | 216 // This balances the one reference that TrackPluginResource() initialized it |
| 241 // with. The plugin will normally take an additional reference which will keep | 217 // with. The plugin will normally take an additional reference which will keep |
| 242 // the resource alive in the plugin (and the one reference in the renderer | 218 // the resource alive in the plugin (and the one reference in the renderer |
| 243 // representing all plugin references). | 219 // representing all plugin references). |
| 244 // Once all references at the plugin side are released, the renderer side will | 220 // Once all references at the plugin side are released, the renderer side will |
| 245 // be notified and release the reference added in HandleDocumentLoad() above. | 221 // be notified and release the reference added in HandleDocumentLoad() above. |
| 246 PluginResourceTracker::GetInstance()->ReleaseResource(plugin_loader); | 222 PluginResourceTracker::GetInstance()->ReleaseResource(plugin_loader); |
| 247 } | 223 } |
| 248 | 224 |
| 249 } // namespace proxy | 225 } // namespace proxy |
| 250 } // namespace pp | 226 } // namespace pp |
| OLD | NEW |