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