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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 HostDispatcher::GetForInstance(instance)->Send( | 43 HostDispatcher::GetForInstance(instance)->Send( |
44 new PpapiMsg_PPPInstance_DidDestroy(INTERFACE_ID_PPP_INSTANCE, instance)); | 44 new PpapiMsg_PPPInstance_DidDestroy(INTERFACE_ID_PPP_INSTANCE, instance)); |
45 } | 45 } |
46 | 46 |
47 void DidChangeView(PP_Instance instance, | 47 void DidChangeView(PP_Instance instance, |
48 const PP_Rect* position, | 48 const PP_Rect* position, |
49 const PP_Rect* clip) { | 49 const PP_Rect* clip) { |
50 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 50 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
51 const PPB_Fullscreen_Dev* fullscreen_interface = | 51 const PPB_Fullscreen_Dev* fullscreen_interface = |
52 static_cast<const PPB_Fullscreen_Dev*>( | 52 static_cast<const PPB_Fullscreen_Dev*>( |
53 dispatcher->GetLocalInterface(PPB_FULLSCREEN_DEV_INTERFACE)); | 53 dispatcher->local_get_interface()(PPB_FULLSCREEN_DEV_INTERFACE)); |
54 DCHECK(fullscreen_interface); | 54 DCHECK(fullscreen_interface); |
55 PP_Bool fullscreen = fullscreen_interface->IsFullscreen(instance); | 55 PP_Bool fullscreen = fullscreen_interface->IsFullscreen(instance); |
56 dispatcher->Send( | 56 dispatcher->Send( |
57 new PpapiMsg_PPPInstance_DidChangeView(INTERFACE_ID_PPP_INSTANCE, | 57 new PpapiMsg_PPPInstance_DidChangeView(INTERFACE_ID_PPP_INSTANCE, |
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 HandleDocumentLoad(PP_Instance instance, | 68 PP_Bool HandleDocumentLoad(PP_Instance instance, |
69 PP_Resource url_loader) { | 69 PP_Resource url_loader) { |
70 PP_Bool result = PP_FALSE; | 70 PP_Bool result = PP_FALSE; |
71 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 71 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
72 | 72 |
73 // Set up the URLLoader for proxying. | 73 // Set up the URLLoader for proxying. |
74 | 74 |
75 PPB_URLLoader_Proxy* url_loader_proxy = static_cast<PPB_URLLoader_Proxy*>( | 75 PPB_URLLoader_Proxy* url_loader_proxy = static_cast<PPB_URLLoader_Proxy*>( |
76 dispatcher->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_URL_LOADER)); | 76 dispatcher->GetInterfaceProxy(INTERFACE_ID_PPB_URL_LOADER)); |
77 url_loader_proxy->PrepareURLLoaderForSendingToPlugin(url_loader); | 77 url_loader_proxy->PrepareURLLoaderForSendingToPlugin(url_loader); |
78 | 78 |
79 // PluginResourceTracker in the plugin process assumes that resources that it | 79 // PluginResourceTracker in the plugin process assumes that resources that it |
80 // tracks have been addrefed on behalf of the plugin at the renderer side. So | 80 // tracks have been addrefed on behalf of the plugin at the renderer side. So |
81 // we explicitly do it for |url_loader| here. | 81 // we explicitly do it for |url_loader| here. |
82 // | 82 // |
83 // Please also see comments in PPP_Instance_Proxy::OnMsgHandleDocumentLoad() | 83 // Please also see comments in PPP_Instance_Proxy::OnMsgHandleDocumentLoad() |
84 // about releasing of this extra reference. | 84 // about releasing of this extra reference. |
85 const PPB_Core* core = reinterpret_cast<const PPB_Core*>( | 85 const PPB_Core* core = reinterpret_cast<const PPB_Core*>( |
86 dispatcher->GetLocalInterface(PPB_CORE_INTERFACE)); | 86 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); |
87 if (!core) { | 87 if (!core) { |
88 NOTREACHED(); | 88 NOTREACHED(); |
89 return PP_FALSE; | 89 return PP_FALSE; |
90 } | 90 } |
91 core->AddRefResource(url_loader); | 91 core->AddRefResource(url_loader); |
92 | 92 |
93 HostResource serialized_loader; | 93 HostResource serialized_loader; |
94 serialized_loader.SetHostResource(instance, url_loader); | 94 serialized_loader.SetHostResource(instance, url_loader); |
95 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 95 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
96 INTERFACE_ID_PPP_INSTANCE, instance, serialized_loader, &result)); | 96 INTERFACE_ID_PPP_INSTANCE, instance, serialized_loader, &result)); |
97 return result; | 97 return result; |
98 } | 98 } |
99 | 99 |
100 static const PPP_Instance_1_0 instance_interface_1_0 = { | 100 static const PPP_Instance_1_0 instance_interface_1_0 = { |
101 &DidCreate, | 101 &DidCreate, |
102 &DidDestroy, | 102 &DidDestroy, |
103 &DidChangeView, | 103 &DidChangeView, |
104 &DidChangeFocus, | 104 &DidChangeFocus, |
105 &HandleDocumentLoad | 105 &HandleDocumentLoad |
106 }; | 106 }; |
107 | 107 |
108 template <class PPP_Instance_Type> | 108 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher) { |
109 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher, | 109 return new PPP_Instance_Proxy(dispatcher); |
110 const void* target_interface) { | |
111 return new PPP_Instance_Proxy( | |
112 dispatcher, | |
113 static_cast<const PPP_Instance_Type*>(target_interface)); | |
114 } | 110 } |
115 | 111 |
116 } // namespace | 112 } // namespace |
117 | 113 |
| 114 PPP_Instance_Proxy::PPP_Instance_Proxy(Dispatcher* dispatcher) |
| 115 : InterfaceProxy(dispatcher) { |
| 116 if (dispatcher->IsPlugin()) { |
| 117 combined_interface_.reset( |
| 118 new PPP_Instance_Combined(*static_cast<const PPP_Instance_1_0*>( |
| 119 dispatcher->local_get_interface()(PPP_INSTANCE_INTERFACE_1_0)))); |
| 120 } |
| 121 } |
| 122 |
118 PPP_Instance_Proxy::~PPP_Instance_Proxy() { | 123 PPP_Instance_Proxy::~PPP_Instance_Proxy() { |
119 } | 124 } |
120 | 125 |
121 // static | 126 // static |
122 const InterfaceProxy::Info* PPP_Instance_Proxy::GetInfo1_0() { | 127 const InterfaceProxy::Info* PPP_Instance_Proxy::GetInfo1_0() { |
123 static const Info info = { | 128 static const Info info = { |
124 &instance_interface_1_0, | 129 &instance_interface_1_0, |
125 PPP_INSTANCE_INTERFACE_1_0, | 130 PPP_INSTANCE_INTERFACE_1_0, |
126 INTERFACE_ID_PPP_INSTANCE, | 131 INTERFACE_ID_PPP_INSTANCE, |
127 false, | 132 false, |
128 &CreateInstanceProxy<PPP_Instance_1_0>, | 133 &CreateInstanceProxy |
129 }; | 134 }; |
130 return &info; | 135 return &info; |
131 } | 136 } |
132 | 137 |
133 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { | 138 bool PPP_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { |
134 bool handled = true; | 139 bool handled = true; |
135 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) | 140 IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Proxy, msg) |
136 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, | 141 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, |
137 OnMsgDidCreate) | 142 OnMsgDidCreate) |
138 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, | 143 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // with. The plugin will normally take an additional reference which will keep | 224 // with. The plugin will normally take an additional reference which will keep |
220 // the resource alive in the plugin (and the one reference in the renderer | 225 // the resource alive in the plugin (and the one reference in the renderer |
221 // representing all plugin references). | 226 // representing all plugin references). |
222 // Once all references at the plugin side are released, the renderer side will | 227 // Once all references at the plugin side are released, the renderer side will |
223 // be notified and release the reference added in HandleDocumentLoad() above. | 228 // be notified and release the reference added in HandleDocumentLoad() above. |
224 PluginResourceTracker::GetInstance()->ReleaseResource(plugin_loader); | 229 PluginResourceTracker::GetInstance()->ReleaseResource(plugin_loader); |
225 } | 230 } |
226 | 231 |
227 } // namespace proxy | 232 } // namespace proxy |
228 } // namespace ppapi | 233 } // namespace ppapi |
OLD | NEW |