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 13 matching lines...) Expand all Loading... |
24 using ppapi::TrackedCallback; | 24 using ppapi::TrackedCallback; |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 // PPB_Broker_Impl ------------------------------------------------------ | 28 // PPB_Broker_Impl ------------------------------------------------------ |
29 | 29 |
30 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) | 30 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) |
31 : Resource(ppapi::OBJECT_IS_IMPL, instance), | 31 : Resource(ppapi::OBJECT_IS_IMPL, instance), |
32 broker_(NULL), | 32 broker_(NULL), |
33 connect_callback_(), | 33 connect_callback_(), |
34 pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)), | 34 pipe_handle_(PlatformFileToInt(base::SyncSocket::kInvalidHandle)), |
35 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) { | 35 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) { |
36 ChildThread::current()->GetRouter()->AddRoute(routing_id_, this); | 36 ChildThread::current()->GetRouter()->AddRoute(routing_id_, this); |
37 } | 37 } |
38 | 38 |
39 PPB_Broker_Impl::~PPB_Broker_Impl() { | 39 PPB_Broker_Impl::~PPB_Broker_Impl() { |
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::SyncSocket::kInvalidHandle); |
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() { return this; } | 50 PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() { return this; } |
51 | 51 |
52 int32_t PPB_Broker_Impl::Connect( | 52 int32_t PPB_Broker_Impl::Connect( |
53 scoped_refptr<TrackedCallback> connect_callback) { | 53 scoped_refptr<TrackedCallback> connect_callback) { |
54 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. | 54 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. |
55 | 55 |
56 if (broker_) { | 56 if (broker_) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 broker_path)); | 88 broker_path)); |
89 | 89 |
90 // Adds a reference, ensuring that the broker is not deleted when | 90 // Adds a reference, ensuring that the broker is not deleted when |
91 // |broker| goes out of scope. | 91 // |broker| goes out of scope. |
92 broker_->AddPendingConnect(this); | 92 broker_->AddPendingConnect(this); |
93 | 93 |
94 return PP_OK_COMPLETIONPENDING; | 94 return PP_OK_COMPLETIONPENDING; |
95 } | 95 } |
96 | 96 |
97 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { | 97 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { |
98 if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)) | 98 if (pipe_handle_ == PlatformFileToInt(base::SyncSocket::kInvalidHandle)) |
99 return PP_ERROR_FAILED; // Handle not set yet. | 99 return PP_ERROR_FAILED; // Handle not set yet. |
100 *handle = pipe_handle_; | 100 *handle = pipe_handle_; |
101 return PP_OK; | 101 return PP_OK; |
102 } | 102 } |
103 | 103 |
104 GURL PPB_Broker_Impl::GetDocumentUrl() { | 104 GURL PPB_Broker_Impl::GetDocumentUrl() { |
105 PepperPluginInstanceImpl* plugin_instance = | 105 PepperPluginInstanceImpl* plugin_instance = |
106 HostGlobals::Get()->GetInstance(pp_instance()); | 106 HostGlobals::Get()->GetInstance(pp_instance()); |
107 return plugin_instance->container()->element().document().url(); | 107 return plugin_instance->container()->element().document().url(); |
108 } | 108 } |
109 | 109 |
110 // Transfers ownership of the handle to the plugin. | 110 // Transfers ownership of the handle to the plugin. |
111 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { | 111 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { |
112 DCHECK(pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)); | 112 DCHECK(pipe_handle_ == PlatformFileToInt(base::SyncSocket::kInvalidHandle)); |
113 DCHECK(result == PP_OK || | 113 DCHECK(result == PP_OK || |
114 handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); | 114 handle == PlatformFileToInt(base::SyncSocket::kInvalidHandle)); |
115 | 115 |
116 pipe_handle_ = handle; | 116 pipe_handle_ = handle; |
117 | 117 |
118 // Synchronous calls are not supported. | 118 // Synchronous calls are not supported. |
119 DCHECK(TrackedCallback::IsPending(connect_callback_)); | 119 DCHECK(TrackedCallback::IsPending(connect_callback_)); |
120 | 120 |
121 connect_callback_->Run(result); | 121 connect_callback_->Run(result); |
122 } | 122 } |
123 | 123 |
124 bool PPB_Broker_Impl::OnMessageReceived(const IPC::Message& message) { | 124 bool PPB_Broker_Impl::OnMessageReceived(const IPC::Message& message) { |
(...skipping 12 matching lines...) Expand all Loading... |
137 base::ProcessId broker_pid, | 137 base::ProcessId broker_pid, |
138 const IPC::ChannelHandle& handle) { | 138 const IPC::ChannelHandle& handle) { |
139 broker_->OnBrokerChannelConnected(broker_pid, handle); | 139 broker_->OnBrokerChannelConnected(broker_pid, handle); |
140 } | 140 } |
141 | 141 |
142 void PPB_Broker_Impl::OnPpapiBrokerPermissionResult(bool result) { | 142 void PPB_Broker_Impl::OnPpapiBrokerPermissionResult(bool result) { |
143 broker_->OnBrokerPermissionResult(this, result); | 143 broker_->OnBrokerPermissionResult(this, result); |
144 } | 144 } |
145 | 145 |
146 } // namespace content | 146 } // namespace content |
OLD | NEW |