Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: content/renderer/pepper/ppb_broker_impl.cc

Issue 22300003: Move broker creation out of PepperHelperImpl to PPB_Broker_Impl in the effort to eliminate PepperHe… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/renderer/pepper/common.h" 9 #include "content/renderer/pepper/common.h"
9 #include "content/renderer/pepper/host_globals.h" 10 #include "content/renderer/pepper/host_globals.h"
10 #include "content/renderer/pepper/pepper_broker.h" 11 #include "content/renderer/pepper/pepper_broker.h"
11 #include "content/renderer/pepper/pepper_helper_impl.h" 12 #include "content/renderer/pepper/pepper_helper_impl.h"
12 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
13 #include "content/renderer/pepper/plugin_module.h" 14 #include "content/renderer/pepper/plugin_module.h"
15 #include "content/renderer/render_thread_impl.h"
16 #include "content/renderer/render_view_impl.h"
14 #include "ppapi/c/pp_errors.h" 17 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/shared_impl/platform_file.h" 18 #include "ppapi/shared_impl/platform_file.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 19 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebElement.h" 20 #include "third_party/WebKit/public/web/WebElement.h"
18 #include "third_party/WebKit/public/web/WebPluginContainer.h" 21 #include "third_party/WebKit/public/web/WebPluginContainer.h"
19 22
20 using ppapi::PlatformFileToInt; 23 using ppapi::PlatformFileToInt;
21 using ppapi::thunk::PPB_Broker_API; 24 using ppapi::thunk::PPB_Broker_API;
22 using ppapi::TrackedCallback; 25 using ppapi::TrackedCallback;
23 26
24 namespace content { 27 namespace content {
25 28
26 // PPB_Broker_Impl ------------------------------------------------------ 29 // PPB_Broker_Impl ------------------------------------------------------
27 30
28 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) 31 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance)
29 : Resource(::ppapi::OBJECT_IS_IMPL, instance), 32 : Resource(::ppapi::OBJECT_IS_IMPL, instance),
30 broker_(NULL), 33 broker_(NULL),
31 connect_callback_(), 34 connect_callback_(),
32 pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)) { 35 pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)),
36 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) {
37 ChildThread::current()->AddRoute(routing_id_, this);
33 } 38 }
34 39
35 PPB_Broker_Impl::~PPB_Broker_Impl() { 40 PPB_Broker_Impl::~PPB_Broker_Impl() {
36 if (broker_) { 41 if (broker_) {
37 broker_->Disconnect(this); 42 broker_->Disconnect(this);
38 broker_ = NULL; 43 broker_ = NULL;
39 } 44 }
40 45
41 // The plugin owns the handle. 46 // The plugin owns the handle.
42 pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue); 47 pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue);
48 ChildThread::current()->RemoveRoute(routing_id_);
43 } 49 }
44 50
45 PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() { 51 PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() {
46 return this; 52 return this;
47 } 53 }
48 54
49 int32_t PPB_Broker_Impl::Connect( 55 int32_t PPB_Broker_Impl::Connect(
50 scoped_refptr<TrackedCallback> connect_callback) { 56 scoped_refptr<TrackedCallback> connect_callback) {
51 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. 57 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process.
52 58
53 if (broker_) { 59 if (broker_) {
54 // May only be called once. 60 // May only be called once.
55 return PP_ERROR_FAILED; 61 return PP_ERROR_FAILED;
56 } 62 }
57 63
58 PepperPluginInstanceImpl* plugin_instance = 64 PepperPluginInstanceImpl* plugin_instance =
59 HostGlobals::Get()->GetInstance(pp_instance()); 65 HostGlobals::Get()->GetInstance(pp_instance());
60 if (!plugin_instance) 66 if (!plugin_instance)
61 return PP_ERROR_FAILED; 67 return PP_ERROR_FAILED;
68 PluginModule* module = plugin_instance->module();
69 const base::FilePath& broker_path = module->path();
62 70
63 // The callback must be populated now in case we are connected to the broker 71 // The callback must be populated now in case we are connected to the broker
64 // and BrokerConnected is called before ConnectToBroker returns. 72 // and BrokerConnected is called before ConnectToBroker returns.
65 // Because it must be created now, it must be aborted and cleared if 73 // Because it must be created now, it must be aborted and cleared if
66 // ConnectToBroker fails. 74 // ConnectToBroker fails.
67 connect_callback_ = connect_callback; 75 connect_callback_ = connect_callback;
68 76
69 broker_ = plugin_instance->helper()->ConnectToBroker(this); 77 broker_ = module->GetBroker();
70 if (!broker_) { 78 if (!broker_) {
71 connect_callback_->Abort(); 79 broker_ = new PepperBroker(module);
72 return PP_ERROR_FAILED; 80
81 // Have the browser start the broker process for us.
82 RenderThreadImpl::current()->Send(new ViewHostMsg_OpenChannelToPpapiBroker(
83 routing_id_, broker_path));
73 } 84 }
74 85
86 RenderThreadImpl::current()->Send(
87 new ViewHostMsg_RequestPpapiBrokerPermission(
88 plugin_instance->render_view()->GetRoutingID(),
89 routing_id_,
90 GetDocumentUrl(),
91 broker_path));
92
93 // Adds a reference, ensuring that the broker is not deleted when
94 // |broker| goes out of scope.
95 broker_->AddPendingConnect(this);
dmichael (off chromium) 2013/08/06 18:43:31 The comment is not quite right now; broker_ is jus
jam 2013/08/06 19:34:09 I believe that comment (which I moved) is referrin
dmichael(do not use this one) 2013/08/06 19:48:05 The old comment referred to a stack variable named
jam 2013/08/06 19:55:45 ah, I missed that. i'll update in my next cl, than
96
75 return PP_OK_COMPLETIONPENDING; 97 return PP_OK_COMPLETIONPENDING;
76 } 98 }
77 99
78 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { 100 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) {
79 if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)) 101 if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue))
80 return PP_ERROR_FAILED; // Handle not set yet. 102 return PP_ERROR_FAILED; // Handle not set yet.
81 *handle = pipe_handle_; 103 *handle = pipe_handle_;
82 return PP_OK; 104 return PP_OK;
83 } 105 }
84 106
(...skipping 11 matching lines...) Expand all
96 handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); 118 handle == PlatformFileToInt(base::kInvalidPlatformFileValue));
97 119
98 pipe_handle_ = handle; 120 pipe_handle_ = handle;
99 121
100 // Synchronous calls are not supported. 122 // Synchronous calls are not supported.
101 DCHECK(TrackedCallback::IsPending(connect_callback_)); 123 DCHECK(TrackedCallback::IsPending(connect_callback_));
102 124
103 connect_callback_->Run(result); 125 connect_callback_->Run(result);
104 } 126 }
105 127
128 bool PPB_Broker_Impl::OnMessageReceived(const IPC::Message& message) {
129 bool handled = true;
130 IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Impl, message)
131 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
132 OnPpapiBrokerChannelCreated)
133 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
134 OnPpapiBrokerPermissionResult)
135 IPC_MESSAGE_UNHANDLED(handled = false)
136 IPC_END_MESSAGE_MAP()
137 return handled;
138 }
139
140 void PPB_Broker_Impl::OnPpapiBrokerChannelCreated(
141 base::ProcessId broker_pid,
142 const IPC::ChannelHandle& handle) {
143 broker_->OnBrokerChannelConnected(broker_pid, handle);
144 }
145
146 void PPB_Broker_Impl::OnPpapiBrokerPermissionResult(bool result) {
147 broker_->OnBrokerPermissionResult(this, result);
dmichael (off chromium) 2013/08/06 18:43:31 nit: indentation is off
jam 2013/08/06 19:34:09 Done.
148 }
149
106 } // namespace content 150 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698