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/pp_var.h" | 9 #include "ppapi/c/pp_var.h" |
10 #include "ppapi/c/ppb_core.h" | 10 #include "ppapi/c/ppb_core.h" |
| 11 #include "ppapi/c/ppb_fullscreen.h" |
11 #include "ppapi/c/ppp_instance.h" | 12 #include "ppapi/c/ppp_instance.h" |
12 #include "ppapi/c/private/ppb_flash_fullscreen.h" | 13 #include "ppapi/c/private/ppb_flash_fullscreen.h" |
13 #include "ppapi/proxy/host_dispatcher.h" | 14 #include "ppapi/proxy/host_dispatcher.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
15 #include "ppapi/proxy/plugin_resource_tracker.h" | 16 #include "ppapi/proxy/plugin_resource_tracker.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "ppapi/proxy/ppb_url_loader_proxy.h" | 18 #include "ppapi/proxy/ppb_url_loader_proxy.h" |
18 #include "ppapi/shared_impl/ppapi_globals.h" | 19 #include "ppapi/shared_impl/ppapi_globals.h" |
| 20 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 21 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 22 #include "ppapi/thunk/enter.h" |
| 23 #include "ppapi/thunk/ppb_view_api.h" |
19 | 24 |
20 namespace ppapi { | 25 namespace ppapi { |
21 namespace proxy { | 26 namespace proxy { |
22 | 27 |
23 namespace { | 28 namespace { |
24 | 29 |
| 30 void GetFullscreenStates(PP_Instance instance, |
| 31 HostDispatcher* dispatcher, |
| 32 PP_Bool* fullscreen, |
| 33 PP_Bool* flash_fullscreen) { |
| 34 const PPB_Fullscreen* fullscreen_interface = |
| 35 static_cast<const PPB_Fullscreen*>( |
| 36 dispatcher->local_get_interface()(PPB_FULLSCREEN_INTERFACE)); |
| 37 DCHECK(fullscreen_interface); |
| 38 *fullscreen = fullscreen_interface->IsFullscreen(instance); |
| 39 } |
| 40 |
| 41 PP_Bool IsFlashFullscreen(PP_Instance instance, |
| 42 HostDispatcher* dispatcher) { |
| 43 const PPB_FlashFullscreen* flash_fullscreen_interface = |
| 44 static_cast<const PPB_FlashFullscreen*>( |
| 45 dispatcher->local_get_interface()(PPB_FLASHFULLSCREEN_INTERFACE)); |
| 46 DCHECK(flash_fullscreen_interface); |
| 47 return flash_fullscreen_interface->IsFullscreen(instance); |
| 48 } |
| 49 |
25 PP_Bool DidCreate(PP_Instance instance, | 50 PP_Bool DidCreate(PP_Instance instance, |
26 uint32_t argc, | 51 uint32_t argc, |
27 const char* argn[], | 52 const char* argn[], |
28 const char* argv[]) { | 53 const char* argv[]) { |
29 std::vector<std::string> argn_vect; | 54 std::vector<std::string> argn_vect; |
30 std::vector<std::string> argv_vect; | 55 std::vector<std::string> argv_vect; |
31 for (uint32_t i = 0; i < argc; i++) { | 56 for (uint32_t i = 0; i < argc; i++) { |
32 argn_vect.push_back(std::string(argn[i])); | 57 argn_vect.push_back(std::string(argn[i])); |
33 argv_vect.push_back(std::string(argv[i])); | 58 argv_vect.push_back(std::string(argv[i])); |
34 } | 59 } |
35 | 60 |
36 PP_Bool result = PP_FALSE; | 61 PP_Bool result = PP_FALSE; |
37 HostDispatcher::GetForInstance(instance)->Send( | 62 HostDispatcher::GetForInstance(instance)->Send( |
38 new PpapiMsg_PPPInstance_DidCreate(API_ID_PPP_INSTANCE, instance, | 63 new PpapiMsg_PPPInstance_DidCreate(API_ID_PPP_INSTANCE, instance, |
39 argn_vect, argv_vect, &result)); | 64 argn_vect, argv_vect, &result)); |
40 return result; | 65 return result; |
41 } | 66 } |
42 | 67 |
43 void DidDestroy(PP_Instance instance) { | 68 void DidDestroy(PP_Instance instance) { |
44 HostDispatcher::GetForInstance(instance)->Send( | 69 HostDispatcher::GetForInstance(instance)->Send( |
45 new PpapiMsg_PPPInstance_DidDestroy(API_ID_PPP_INSTANCE, instance)); | 70 new PpapiMsg_PPPInstance_DidDestroy(API_ID_PPP_INSTANCE, instance)); |
46 } | 71 } |
47 | 72 |
48 void DidChangeView(PP_Instance instance, | 73 void DidChangeView(PP_Instance instance, PP_Resource view_resource) { |
49 const PP_Rect* position, | |
50 const PP_Rect* clip) { | |
51 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 74 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
52 const PPB_FlashFullscreen* fullscreen_interface = | 75 |
53 static_cast<const PPB_FlashFullscreen*>( | 76 thunk::EnterResourceNoLock<thunk::PPB_View_API> enter(view_resource, false); |
54 dispatcher->local_get_interface()(PPB_FLASHFULLSCREEN_INTERFACE)); | 77 if (enter.failed()) { |
55 DCHECK(fullscreen_interface); | 78 NOTREACHED(); |
56 const PPB_FlashFullscreen* flash_fullscreen_interface = | 79 return; |
57 static_cast<const PPB_FlashFullscreen*>( | 80 } |
58 dispatcher->local_get_interface()(PPB_FLASHFULLSCREEN_INTERFACE)); | 81 |
59 DCHECK(flash_fullscreen_interface); | 82 dispatcher->Send(new PpapiMsg_PPPInstance_DidChangeView( |
60 PP_Bool fullscreen = fullscreen_interface->IsFullscreen(instance); | 83 API_ID_PPP_INSTANCE, instance, enter.object()->GetData(), |
61 PP_Bool flash_fullscreen = | 84 IsFlashFullscreen(instance, dispatcher))); |
62 flash_fullscreen_interface->IsFullscreen(instance); | |
63 dispatcher->Send( | |
64 new PpapiMsg_PPPInstance_DidChangeView(API_ID_PPP_INSTANCE, | |
65 instance, *position, *clip, | |
66 fullscreen, | |
67 flash_fullscreen)); | |
68 } | 85 } |
69 | 86 |
70 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { | 87 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { |
71 HostDispatcher::GetForInstance(instance)->Send( | 88 HostDispatcher::GetForInstance(instance)->Send( |
72 new PpapiMsg_PPPInstance_DidChangeFocus(API_ID_PPP_INSTANCE, | 89 new PpapiMsg_PPPInstance_DidChangeFocus(API_ID_PPP_INSTANCE, |
73 instance, has_focus)); | 90 instance, has_focus)); |
74 } | 91 } |
75 | 92 |
76 PP_Bool HandleDocumentLoad(PP_Instance instance, | 93 PP_Bool HandleDocumentLoad(PP_Instance instance, |
77 PP_Resource url_loader) { | 94 PP_Resource url_loader) { |
(...skipping 20 matching lines...) Expand all Loading... |
98 } | 115 } |
99 core->AddRefResource(url_loader); | 116 core->AddRefResource(url_loader); |
100 | 117 |
101 HostResource serialized_loader; | 118 HostResource serialized_loader; |
102 serialized_loader.SetHostResource(instance, url_loader); | 119 serialized_loader.SetHostResource(instance, url_loader); |
103 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 120 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
104 API_ID_PPP_INSTANCE, instance, serialized_loader, &result)); | 121 API_ID_PPP_INSTANCE, instance, serialized_loader, &result)); |
105 return result; | 122 return result; |
106 } | 123 } |
107 | 124 |
108 static const PPP_Instance_1_0 instance_interface_1_0 = { | 125 static const PPP_Instance_1_1 instance_interface = { |
109 &DidCreate, | 126 &DidCreate, |
110 &DidDestroy, | 127 &DidDestroy, |
111 &DidChangeView, | 128 &DidChangeView, |
112 &DidChangeFocus, | 129 &DidChangeFocus, |
113 &HandleDocumentLoad | 130 &HandleDocumentLoad |
114 }; | 131 }; |
115 | 132 |
116 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher) { | |
117 return new PPP_Instance_Proxy(dispatcher); | |
118 } | |
119 | |
120 } // namespace | 133 } // namespace |
121 | 134 |
122 PPP_Instance_Proxy::PPP_Instance_Proxy(Dispatcher* dispatcher) | 135 PPP_Instance_Proxy::PPP_Instance_Proxy(Dispatcher* dispatcher) |
123 : InterfaceProxy(dispatcher) { | 136 : InterfaceProxy(dispatcher) { |
124 if (dispatcher->IsPlugin()) { | 137 if (dispatcher->IsPlugin()) { |
125 combined_interface_.reset( | 138 // The PPP_Instance proxy works by always proxying the 1.1 version of the |
126 new PPP_Instance_Combined(*static_cast<const PPP_Instance_1_0*>( | 139 // interface, and then detecting in the plugin process which one to use. |
127 dispatcher->local_get_interface()(PPP_INSTANCE_INTERFACE_1_0)))); | 140 // PPP_Instance_Combined handles dispatching to whatever interface is |
| 141 // supported. |
| 142 // |
| 143 // This means that if the plugin supports either 1.0 or 1.1 version of |
| 144 // the interface, we want to say it supports the 1.1 version since we'll |
| 145 // convert it here. This magic conversion code is hardcoded into |
| 146 // PluginDispatcher::OnMsgSupportsInterface. |
| 147 const PPP_Instance* instance = static_cast<const PPP_Instance*>( |
| 148 dispatcher->local_get_interface()(PPP_INSTANCE_INTERFACE)); |
| 149 if (instance) { |
| 150 combined_interface_.reset(new PPP_Instance_Combined(*instance)); |
| 151 } else { |
| 152 const PPP_Instance_1_0* instance_1_0 = |
| 153 static_cast<const PPP_Instance_1_0*>( |
| 154 dispatcher->local_get_interface()(PPP_INSTANCE_INTERFACE_1_0)); |
| 155 combined_interface_.reset(new PPP_Instance_Combined(*instance_1_0)); |
| 156 } |
128 } | 157 } |
129 } | 158 } |
130 | 159 |
131 PPP_Instance_Proxy::~PPP_Instance_Proxy() { | 160 PPP_Instance_Proxy::~PPP_Instance_Proxy() { |
132 } | 161 } |
133 | 162 |
134 // static | 163 // static |
135 const InterfaceProxy::Info* PPP_Instance_Proxy::GetInfo1_0() { | 164 const PPP_Instance* PPP_Instance_Proxy::GetInstanceInterface() { |
136 static const Info info = { | 165 return &instance_interface; |
137 &instance_interface_1_0, | |
138 PPP_INSTANCE_INTERFACE_1_0, | |
139 API_ID_PPP_INSTANCE, | |
140 false, | |
141 &CreateInstanceProxy | |
142 }; | |
143 return &info; | |
144 } | 166 } |
145 | 167 |
146 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { | 168 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { |
147 bool handled = true; | 169 bool handled = true; |
148 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) | 170 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) |
149 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, | 171 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, |
150 OnMsgDidCreate) | 172 OnPluginMsgDidCreate) |
151 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, | 173 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, |
152 OnMsgDidDestroy) | 174 OnPluginMsgDidDestroy) |
153 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, | 175 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, |
154 OnMsgDidChangeView) | 176 OnPluginMsgDidChangeView) |
155 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, | 177 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, |
156 OnMsgDidChangeFocus) | 178 OnPluginMsgDidChangeFocus) |
157 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_HandleDocumentLoad, | 179 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_HandleDocumentLoad, |
158 OnMsgHandleDocumentLoad) | 180 OnPluginMsgHandleDocumentLoad) |
159 IPC_MESSAGE_UNHANDLED(handled = false) | 181 IPC_MESSAGE_UNHANDLED(handled = false) |
160 IPC_END_MESSAGE_MAP() | 182 IPC_END_MESSAGE_MAP() |
161 return handled; | 183 return handled; |
162 } | 184 } |
163 | 185 |
164 void PPP_Instance_Proxy::OnMsgDidCreate( | 186 void PPP_Instance_Proxy::OnPluginMsgDidCreate( |
165 PP_Instance instance, | 187 PP_Instance instance, |
166 const std::vector<std::string>& argn, | 188 const std::vector<std::string>& argn, |
167 const std::vector<std::string>& argv, | 189 const std::vector<std::string>& argv, |
168 PP_Bool* result) { | 190 PP_Bool* result) { |
169 *result = PP_FALSE; | 191 *result = PP_FALSE; |
170 if (argn.size() != argv.size()) | 192 if (argn.size() != argv.size()) |
171 return; | 193 return; |
172 | 194 |
173 // Set up the routing associating this new instance with the dispatcher we | 195 // Set up the routing associating this new instance with the dispatcher we |
174 // just got the message from. This must be done before calling into the | 196 // just got the message from. This must be done before calling into the |
(...skipping 13 matching lines...) Expand all Loading... |
188 argn_array[i] = argn[i].c_str(); | 210 argn_array[i] = argn[i].c_str(); |
189 argv_array[i] = argv[i].c_str(); | 211 argv_array[i] = argv[i].c_str(); |
190 } | 212 } |
191 | 213 |
192 DCHECK(combined_interface_.get()); | 214 DCHECK(combined_interface_.get()); |
193 *result = combined_interface_->DidCreate(instance, | 215 *result = combined_interface_->DidCreate(instance, |
194 static_cast<uint32_t>(argn.size()), | 216 static_cast<uint32_t>(argn.size()), |
195 &argn_array[0], &argv_array[0]); | 217 &argn_array[0], &argv_array[0]); |
196 } | 218 } |
197 | 219 |
198 void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { | 220 void PPP_Instance_Proxy::OnPluginMsgDidDestroy(PP_Instance instance) { |
199 combined_interface_->DidDestroy(instance); | 221 combined_interface_->DidDestroy(instance); |
200 PpapiGlobals::Get()->GetResourceTracker()->DidDeleteInstance(instance); | 222 PpapiGlobals::Get()->GetResourceTracker()->DidDeleteInstance(instance); |
201 static_cast<PluginDispatcher*>(dispatcher())->DidDestroyInstance(instance); | 223 static_cast<PluginDispatcher*>(dispatcher())->DidDestroyInstance(instance); |
202 } | 224 } |
203 | 225 |
204 void PPP_Instance_Proxy::OnMsgDidChangeView(PP_Instance instance, | 226 void PPP_Instance_Proxy::OnPluginMsgDidChangeView( |
205 const PP_Rect& position, | 227 PP_Instance instance, |
206 const PP_Rect& clip, | 228 const ViewData& new_data, |
207 PP_Bool fullscreen, | 229 PP_Bool flash_fullscreen) { |
208 PP_Bool flash_fullscreen) { | |
209 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 230 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
210 if (!dispatcher) | 231 if (!dispatcher) |
211 return; | 232 return; |
212 InstanceData* data = dispatcher->GetInstanceData(instance); | 233 InstanceData* data = dispatcher->GetInstanceData(instance); |
213 if (!data) | 234 if (!data) |
214 return; | 235 return; |
215 data->position = position; | 236 |
216 data->fullscreen = fullscreen; | 237 data->view = new_data; |
217 data->flash_fullscreen = flash_fullscreen; | 238 data->flash_fullscreen = flash_fullscreen; |
218 combined_interface_->DidChangeView(instance, &position, &clip); | 239 |
| 240 ScopedPPResource resource( |
| 241 ScopedPPResource::PassRef(), |
| 242 (new PPB_View_Shared(PPB_View_Shared::InitAsProxy(), |
| 243 instance, new_data))->GetReference()); |
| 244 |
| 245 combined_interface_->DidChangeView(instance, resource, |
| 246 &new_data.rect, |
| 247 &new_data.clip_rect); |
219 } | 248 } |
220 | 249 |
221 void PPP_Instance_Proxy::OnMsgDidChangeFocus(PP_Instance instance, | 250 void PPP_Instance_Proxy::OnPluginMsgDidChangeFocus(PP_Instance instance, |
222 PP_Bool has_focus) { | 251 PP_Bool has_focus) { |
223 combined_interface_->DidChangeFocus(instance, has_focus); | 252 combined_interface_->DidChangeFocus(instance, has_focus); |
224 } | 253 } |
225 | 254 |
226 void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance, | 255 void PPP_Instance_Proxy::OnPluginMsgHandleDocumentLoad( |
227 const HostResource& url_loader, | 256 PP_Instance instance, |
228 PP_Bool* result) { | 257 const HostResource& url_loader, |
| 258 PP_Bool* result) { |
229 PP_Resource plugin_loader = | 259 PP_Resource plugin_loader = |
230 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); | 260 PPB_URLLoader_Proxy::TrackPluginResource(url_loader); |
231 *result = combined_interface_->HandleDocumentLoad(instance, plugin_loader); | 261 *result = combined_interface_->HandleDocumentLoad(instance, plugin_loader); |
232 | 262 |
233 // This balances the one reference that TrackPluginResource() initialized it | 263 // This balances the one reference that TrackPluginResource() initialized it |
234 // with. The plugin will normally take an additional reference which will keep | 264 // with. The plugin will normally take an additional reference which will keep |
235 // the resource alive in the plugin (and the one reference in the renderer | 265 // the resource alive in the plugin (and the one reference in the renderer |
236 // representing all plugin references). | 266 // representing all plugin references). |
237 // Once all references at the plugin side are released, the renderer side will | 267 // Once all references at the plugin side are released, the renderer side will |
238 // be notified and release the reference added in HandleDocumentLoad() above. | 268 // be notified and release the reference added in HandleDocumentLoad() above. |
239 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(plugin_loader); | 269 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(plugin_loader); |
240 } | 270 } |
241 | 271 |
242 } // namespace proxy | 272 } // namespace proxy |
243 } // namespace ppapi | 273 } // namespace ppapi |
OLD | NEW |