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 "content/renderer/pepper/ppb_broker_impl.h" | 5 #include "content/renderer/pepper/ppb_broker_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/view_messages.h" | 8 #include "content/common/view_messages.h" |
9 #include "content/renderer/pepper/common.h" | 9 #include "content/renderer/pepper/common.h" |
10 #include "content/renderer/pepper/host_globals.h" | 10 #include "content/renderer/pepper/host_globals.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 if (broker_) { | 40 if (broker_) { |
41 broker_->Disconnect(this); | 41 broker_->Disconnect(this); |
42 broker_ = NULL; | 42 broker_ = NULL; |
43 } | 43 } |
44 | 44 |
45 // The plugin owns the handle. | 45 // The plugin owns the handle. |
46 pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue); | 46 pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue); |
47 ChildThread::current()->GetRouter()->RemoveRoute(routing_id_); | 47 ChildThread::current()->GetRouter()->RemoveRoute(routing_id_); |
48 } | 48 } |
49 | 49 |
50 PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() { | 50 PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() { return this; } |
51 return this; | |
52 } | |
53 | 51 |
54 int32_t PPB_Broker_Impl::Connect( | 52 int32_t PPB_Broker_Impl::Connect( |
55 scoped_refptr<TrackedCallback> connect_callback) { | 53 scoped_refptr<TrackedCallback> connect_callback) { |
56 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. | 54 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. |
57 | 55 |
58 if (broker_) { | 56 if (broker_) { |
59 // May only be called once. | 57 // May only be called once. |
60 return PP_ERROR_FAILED; | 58 return PP_ERROR_FAILED; |
61 } | 59 } |
62 | 60 |
63 PepperPluginInstanceImpl* plugin_instance = | 61 PepperPluginInstanceImpl* plugin_instance = |
64 HostGlobals::Get()->GetInstance(pp_instance()); | 62 HostGlobals::Get()->GetInstance(pp_instance()); |
65 if (!plugin_instance) | 63 if (!plugin_instance) |
66 return PP_ERROR_FAILED; | 64 return PP_ERROR_FAILED; |
67 PluginModule* module = plugin_instance->module(); | 65 PluginModule* module = plugin_instance->module(); |
68 const base::FilePath& broker_path = module->path(); | 66 const base::FilePath& broker_path = module->path(); |
69 | 67 |
70 // The callback must be populated now in case we are connected to the broker | 68 // The callback must be populated now in case we are connected to the broker |
71 // and BrokerConnected is called before ConnectToBroker returns. | 69 // and BrokerConnected is called before ConnectToBroker returns. |
72 // Because it must be created now, it must be aborted and cleared if | 70 // Because it must be created now, it must be aborted and cleared if |
73 // ConnectToBroker fails. | 71 // ConnectToBroker fails. |
74 connect_callback_ = connect_callback; | 72 connect_callback_ = connect_callback; |
75 | 73 |
76 broker_ = module->GetBroker(); | 74 broker_ = module->GetBroker(); |
77 if (!broker_) { | 75 if (!broker_) { |
78 broker_ = new PepperBroker(module); | 76 broker_ = new PepperBroker(module); |
79 | 77 |
80 // Have the browser start the broker process for us. | 78 // Have the browser start the broker process for us. |
81 RenderThreadImpl::current()->Send(new ViewHostMsg_OpenChannelToPpapiBroker( | 79 RenderThreadImpl::current()->Send( |
82 routing_id_, broker_path)); | 80 new ViewHostMsg_OpenChannelToPpapiBroker(routing_id_, broker_path)); |
83 } | 81 } |
84 | 82 |
85 RenderThreadImpl::current()->Send( | 83 RenderThreadImpl::current()->Send( |
86 new ViewHostMsg_RequestPpapiBrokerPermission( | 84 new ViewHostMsg_RequestPpapiBrokerPermission( |
87 plugin_instance->render_frame()->render_view()->GetRoutingID(), | 85 plugin_instance->render_frame()->render_view()->GetRoutingID(), |
88 routing_id_, | 86 routing_id_, |
89 GetDocumentUrl(), | 87 GetDocumentUrl(), |
90 broker_path)); | 88 broker_path)); |
91 | 89 |
92 // Adds a reference, ensuring that the broker is not deleted when | 90 // Adds a reference, ensuring that the broker is not deleted when |
(...skipping 11 matching lines...) Expand all Loading... |
104 } | 102 } |
105 | 103 |
106 GURL PPB_Broker_Impl::GetDocumentUrl() { | 104 GURL PPB_Broker_Impl::GetDocumentUrl() { |
107 PepperPluginInstanceImpl* plugin_instance = | 105 PepperPluginInstanceImpl* plugin_instance = |
108 HostGlobals::Get()->GetInstance(pp_instance()); | 106 HostGlobals::Get()->GetInstance(pp_instance()); |
109 return plugin_instance->container()->element().document().url(); | 107 return plugin_instance->container()->element().document().url(); |
110 } | 108 } |
111 | 109 |
112 // Transfers ownership of the handle to the plugin. | 110 // Transfers ownership of the handle to the plugin. |
113 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { | 111 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { |
114 DCHECK(pipe_handle_ == | 112 DCHECK(pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)); |
115 PlatformFileToInt(base::kInvalidPlatformFileValue)); | |
116 DCHECK(result == PP_OK || | 113 DCHECK(result == PP_OK || |
117 handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); | 114 handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); |
118 | 115 |
119 pipe_handle_ = handle; | 116 pipe_handle_ = handle; |
120 | 117 |
121 // Synchronous calls are not supported. | 118 // Synchronous calls are not supported. |
122 DCHECK(TrackedCallback::IsPending(connect_callback_)); | 119 DCHECK(TrackedCallback::IsPending(connect_callback_)); |
123 | 120 |
124 connect_callback_->Run(result); | 121 connect_callback_->Run(result); |
125 } | 122 } |
126 | 123 |
127 bool PPB_Broker_Impl::OnMessageReceived(const IPC::Message& message) { | 124 bool PPB_Broker_Impl::OnMessageReceived(const IPC::Message& message) { |
128 bool handled = true; | 125 bool handled = true; |
129 IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Impl, message) | 126 IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Impl, message) |
130 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, | 127 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, |
131 OnPpapiBrokerChannelCreated) | 128 OnPpapiBrokerChannelCreated) |
132 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, | 129 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, |
133 OnPpapiBrokerPermissionResult) | 130 OnPpapiBrokerPermissionResult) |
134 IPC_MESSAGE_UNHANDLED(handled = false) | 131 IPC_MESSAGE_UNHANDLED(handled = false) |
135 IPC_END_MESSAGE_MAP() | 132 IPC_END_MESSAGE_MAP() |
136 return handled; | 133 return handled; |
137 } | 134 } |
138 | 135 |
139 void PPB_Broker_Impl::OnPpapiBrokerChannelCreated( | 136 void PPB_Broker_Impl::OnPpapiBrokerChannelCreated( |
140 base::ProcessId broker_pid, | 137 base::ProcessId broker_pid, |
141 const IPC::ChannelHandle& handle) { | 138 const IPC::ChannelHandle& handle) { |
142 broker_->OnBrokerChannelConnected(broker_pid, handle); | 139 broker_->OnBrokerChannelConnected(broker_pid, handle); |
143 } | 140 } |
144 | 141 |
145 void PPB_Broker_Impl::OnPpapiBrokerPermissionResult(bool result) { | 142 void PPB_Broker_Impl::OnPpapiBrokerPermissionResult(bool result) { |
146 broker_->OnBrokerPermissionResult(this, result); | 143 broker_->OnBrokerPermissionResult(this, result); |
147 } | 144 } |
148 | 145 |
149 } // namespace content | 146 } // namespace content |
OLD | NEW |