Commit ea0309c5 authored by jam@chromium.org's avatar jam@chromium.org

Move broker creation out of PepperHelperImpl to PPB_Broker_Impl in the effort...

Move broker creation out of PepperHelperImpl to PPB_Broker_Impl in the effort to eliminate PepperHelperImpl. This also simplifies things as we can eliminate the bookkeeping and race condition handling.

BUG=263054
R=dmichael@chromium.org

Review URL: https://codereview.chromium.org/22300003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215949 0039d316-1c4b-4281-b951-d872f2087c98
parent 93c19fd2
...@@ -171,11 +171,9 @@ class OpenChannelToPpapiBrokerCallback ...@@ -171,11 +171,9 @@ class OpenChannelToPpapiBrokerCallback
: public PpapiPluginProcessHost::BrokerClient { : public PpapiPluginProcessHost::BrokerClient {
public: public:
OpenChannelToPpapiBrokerCallback(RenderMessageFilter* filter, OpenChannelToPpapiBrokerCallback(RenderMessageFilter* filter,
int routing_id, int routing_id)
int request_id)
: filter_(filter), : filter_(filter),
routing_id_(routing_id), routing_id_(routing_id) {
request_id_(request_id) {
} }
virtual ~OpenChannelToPpapiBrokerCallback() {} virtual ~OpenChannelToPpapiBrokerCallback() {}
...@@ -190,7 +188,6 @@ class OpenChannelToPpapiBrokerCallback ...@@ -190,7 +188,6 @@ class OpenChannelToPpapiBrokerCallback
base::ProcessId plugin_pid, base::ProcessId plugin_pid,
int /* plugin_child_id */) OVERRIDE { int /* plugin_child_id */) OVERRIDE {
filter_->Send(new ViewMsg_PpapiBrokerChannelCreated(routing_id_, filter_->Send(new ViewMsg_PpapiBrokerChannelCreated(routing_id_,
request_id_,
plugin_pid, plugin_pid,
channel_handle)); channel_handle));
delete this; delete this;
...@@ -203,7 +200,6 @@ class OpenChannelToPpapiBrokerCallback ...@@ -203,7 +200,6 @@ class OpenChannelToPpapiBrokerCallback
private: private:
scoped_refptr<RenderMessageFilter> filter_; scoped_refptr<RenderMessageFilter> filter_;
int routing_id_; int routing_id_;
int request_id_;
}; };
} // namespace } // namespace
...@@ -788,12 +784,11 @@ void RenderMessageFilter::OnDidDeleteOutOfProcessPepperInstance( ...@@ -788,12 +784,11 @@ void RenderMessageFilter::OnDidDeleteOutOfProcessPepperInstance(
void RenderMessageFilter::OnOpenChannelToPpapiBroker( void RenderMessageFilter::OnOpenChannelToPpapiBroker(
int routing_id, int routing_id,
int request_id,
const base::FilePath& path) { const base::FilePath& path) {
plugin_service_->OpenChannelToPpapiBroker( plugin_service_->OpenChannelToPpapiBroker(
render_process_id_, render_process_id_,
path, path,
new OpenChannelToPpapiBrokerCallback(this, routing_id, request_id)); new OpenChannelToPpapiBrokerCallback(this, routing_id));
} }
void RenderMessageFilter::OnGenerateRoutingID(int* route_id) { void RenderMessageFilter::OnGenerateRoutingID(int* route_id) {
......
...@@ -184,7 +184,6 @@ class RenderMessageFilter : public BrowserMessageFilter { ...@@ -184,7 +184,6 @@ class RenderMessageFilter : public BrowserMessageFilter {
int32 pp_instance, int32 pp_instance,
bool is_external); bool is_external);
void OnOpenChannelToPpapiBroker(int routing_id, void OnOpenChannelToPpapiBroker(int routing_id,
int request_id,
const base::FilePath& path); const base::FilePath& path);
void OnGenerateRoutingID(int* route_id); void OnGenerateRoutingID(int* route_id);
void OnDownloadUrl(const IPC::Message& message, void OnDownloadUrl(const IPC::Message& message,
......
...@@ -2485,29 +2485,26 @@ void WebContentsImpl::OnWebUISend(const GURL& source_url, ...@@ -2485,29 +2485,26 @@ void WebContentsImpl::OnWebUISend(const GURL& source_url,
} }
void WebContentsImpl::OnRequestPpapiBrokerPermission( void WebContentsImpl::OnRequestPpapiBrokerPermission(
int request_id, int routing_id,
const GURL& url, const GURL& url,
const base::FilePath& plugin_path) { const base::FilePath& plugin_path) {
if (!delegate_) { if (!delegate_) {
OnPpapiBrokerPermissionResult(request_id, false); OnPpapiBrokerPermissionResult(routing_id, false);
return; return;
} }
if (!delegate_->RequestPpapiBrokerPermission( if (!delegate_->RequestPpapiBrokerPermission(
this, url, plugin_path, this, url, plugin_path,
base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult, base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
base::Unretained(this), request_id))) { base::Unretained(this), routing_id))) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
OnPpapiBrokerPermissionResult(request_id, false); OnPpapiBrokerPermissionResult(routing_id, false);
} }
} }
void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
bool result) { bool result) {
RenderViewHostImpl* rvh = GetRenderViewHostImpl(); Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
request_id,
result));
} }
void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) { void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
......
...@@ -554,7 +554,7 @@ class CONTENT_EXPORT WebContentsImpl ...@@ -554,7 +554,7 @@ class CONTENT_EXPORT WebContentsImpl
// Callback function when requesting permission to access the PPAPI broker. // Callback function when requesting permission to access the PPAPI broker.
// |result| is true if permission was granted. // |result| is true if permission was granted.
void OnPpapiBrokerPermissionResult(int request_id, bool result); void OnPpapiBrokerPermissionResult(int routing_id, bool result);
// IPC message handlers. // IPC message handlers.
void OnDidLoadResourceFromMemoryCache(const GURL& url, void OnDidLoadResourceFromMemoryCache(const GURL& url,
...@@ -611,7 +611,7 @@ class CONTENT_EXPORT WebContentsImpl ...@@ -611,7 +611,7 @@ class CONTENT_EXPORT WebContentsImpl
void OnWebUISend(const GURL& source_url, void OnWebUISend(const GURL& source_url,
const std::string& name, const std::string& name,
const base::ListValue& args); const base::ListValue& args);
void OnRequestPpapiBrokerPermission(int request_id, void OnRequestPpapiBrokerPermission(int routing_id,
const GURL& url, const GURL& url,
const base::FilePath& plugin_path); const base::FilePath& plugin_path);
void OnBrowserPluginMessage(const IPC::Message& message); void OnBrowserPluginMessage(const IPC::Message& message);
......
...@@ -1217,16 +1217,14 @@ IPC_MESSAGE_CONTROL1(ViewMsg_NetworkStateChanged, ...@@ -1217,16 +1217,14 @@ IPC_MESSAGE_CONTROL1(ViewMsg_NetworkStateChanged,
// Reply to ViewHostMsg_OpenChannelToPpapiBroker // Reply to ViewHostMsg_OpenChannelToPpapiBroker
// Tells the renderer that the channel to the broker has been created. // Tells the renderer that the channel to the broker has been created.
IPC_MESSAGE_ROUTED3(ViewMsg_PpapiBrokerChannelCreated, IPC_MESSAGE_ROUTED2(ViewMsg_PpapiBrokerChannelCreated,
int /* request_id */,
base::ProcessId /* broker_pid */, base::ProcessId /* broker_pid */,
IPC::ChannelHandle /* handle */) IPC::ChannelHandle /* handle */)
// Reply to ViewHostMsg_RequestPpapiBrokerPermission. // Reply to ViewHostMsg_RequestPpapiBrokerPermission.
// Tells the renderer whether permission to access to PPAPI broker was granted // Tells the renderer whether permission to access to PPAPI broker was granted
// or not. // or not.
IPC_MESSAGE_ROUTED2(ViewMsg_PpapiBrokerPermissionResult, IPC_MESSAGE_ROUTED1(ViewMsg_PpapiBrokerPermissionResult,
int /* request_id */,
bool /* result */) bool /* result */)
// Tells the renderer to empty its plugin list cache, optional reloading // Tells the renderer to empty its plugin list cache, optional reloading
...@@ -1908,9 +1906,8 @@ IPC_MESSAGE_CONTROL1(ViewHostMsg_DidDeleteInProcessInstance, ...@@ -1908,9 +1906,8 @@ IPC_MESSAGE_CONTROL1(ViewHostMsg_DidDeleteInProcessInstance,
// if necessary, and will return a handle to the channel on success. // if necessary, and will return a handle to the channel on success.
// On error an empty string is returned. // On error an empty string is returned.
// The browser will respond with ViewMsg_PpapiBrokerChannelCreated. // The browser will respond with ViewMsg_PpapiBrokerChannelCreated.
IPC_MESSAGE_CONTROL3(ViewHostMsg_OpenChannelToPpapiBroker, IPC_MESSAGE_CONTROL2(ViewHostMsg_OpenChannelToPpapiBroker,
int /* routing_id */, int /* routing_id */,
int /* request_id */,
base::FilePath /* path */) base::FilePath /* path */)
// Opens a Pepper file asynchronously. The response returns a file descriptor // Opens a Pepper file asynchronously. The response returns a file descriptor
...@@ -1926,7 +1923,7 @@ IPC_MESSAGE_CONTROL4(ViewHostMsg_AsyncOpenPepperFile, ...@@ -1926,7 +1923,7 @@ IPC_MESSAGE_CONTROL4(ViewHostMsg_AsyncOpenPepperFile,
// for every connection. // for every connection.
// The browser will respond with ViewMsg_PpapiBrokerPermissionResult. // The browser will respond with ViewMsg_PpapiBrokerPermissionResult.
IPC_MESSAGE_ROUTED3(ViewHostMsg_RequestPpapiBrokerPermission, IPC_MESSAGE_ROUTED3(ViewHostMsg_RequestPpapiBrokerPermission,
int /* request_id */, int /* routing_id */,
GURL /* document_url */, GURL /* document_url */,
base::FilePath /* plugin_path */) base::FilePath /* plugin_path */)
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "content/renderer/pepper/pepper_broker.h" #include "content/renderer/pepper/pepper_broker.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/renderer/pepper/pepper_helper_impl.h"
#include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
#include "content/renderer/pepper/plugin_module.h" #include "content/renderer/pepper/plugin_module.h"
#include "content/renderer/pepper/ppb_broker_impl.h" #include "content/renderer/pepper/ppb_broker_impl.h"
...@@ -107,12 +106,9 @@ int32_t PepperBrokerDispatcherWrapper::SendHandleToBroker( ...@@ -107,12 +106,9 @@ int32_t PepperBrokerDispatcherWrapper::SendHandleToBroker(
return result; return result;
} }
PepperBroker::PepperBroker(PluginModule* plugin_module, PepperBroker::PepperBroker(PluginModule* plugin_module)
PepperHelperImpl* helper) : plugin_module_(plugin_module) {
: plugin_module_(plugin_module),
helper_(helper->AsWeakPtr()) {
DCHECK(plugin_module_); DCHECK(plugin_module_);
DCHECK(helper_.get());
plugin_module_->SetBroker(this); plugin_module_->SetBroker(this);
} }
...@@ -147,28 +143,6 @@ void PepperBroker::Disconnect(PPB_Broker_Impl* client) { ...@@ -147,28 +143,6 @@ void PepperBroker::Disconnect(PPB_Broker_Impl* client) {
// TODO(ddorwin): Send message disconnect message using dispatcher_. // TODO(ddorwin): Send message disconnect message using dispatcher_.
if (pending_connects_.empty()) {
// There are no more clients of this broker. Ensure it will be deleted even
// if the IPC response never comes and OnPepperBrokerChannelCreated is not
// called to remove this object from pending_connect_broker_.
// Before the broker is connected, clients must either be in
// pending_connects_ or not yet associated with this object. Thus, if this
// object is in pending_connect_broker_, there can be no associated clients
// once pending_connects_ is empty and it is thus safe to remove this from
// pending_connect_broker_. Doing so will cause this object to be deleted,
// removing it from the PluginModule. Any new clients will create a new
// instance of this object.
// This doesn't solve all potential problems, but it helps with the ones
// we can influence.
if (helper_.get()) {
bool stopped = helper_->StopWaitingForBrokerConnection(this);
// Verify the assumption that there are no references other than the one
// |client| holds, which will be released below.
DCHECK(!stopped || HasOneRef());
}
}
// Release the reference added in Connect(). // Release the reference added in Connect().
// This must be the last statement because it may delete this object. // This must be the last statement because it may delete this object.
Release(); Release();
......
...@@ -24,7 +24,6 @@ class BrokerDispatcher; ...@@ -24,7 +24,6 @@ class BrokerDispatcher;
namespace content { namespace content {
class PepperHelperImpl;
class PluginModule; class PluginModule;
// This object is NOT thread-safe. // This object is NOT thread-safe.
...@@ -46,7 +45,7 @@ class CONTENT_EXPORT PepperBrokerDispatcherWrapper { ...@@ -46,7 +45,7 @@ class CONTENT_EXPORT PepperBrokerDispatcherWrapper {
class PepperBroker : public base::RefCountedThreadSafe<PepperBroker>{ class PepperBroker : public base::RefCountedThreadSafe<PepperBroker>{
public: public:
PepperBroker(PluginModule* plugin_module, PepperHelperImpl* helper); explicit PepperBroker(PluginModule* plugin_module);
// Decrements the references to the broker. // Decrements the references to the broker.
// When there are no more references, this renderer's dispatcher is // When there are no more references, this renderer's dispatcher is
...@@ -97,8 +96,6 @@ class PepperBroker : public base::RefCountedThreadSafe<PepperBroker>{ ...@@ -97,8 +96,6 @@ class PepperBroker : public base::RefCountedThreadSafe<PepperBroker>{
// Always set and cleared at the same time as the module's pointer to this. // Always set and cleared at the same time as the module's pointer to this.
PluginModule* plugin_module_; PluginModule* plugin_module_;
base::WeakPtr<PepperHelperImpl> helper_;
DISALLOW_COPY_AND_ASSIGN(PepperBroker); DISALLOW_COPY_AND_ASSIGN(PepperBroker);
}; };
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "content/renderer/pepper/content_renderer_pepper_host_factory.h" #include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
#include "content/renderer/pepper/host_dispatcher_wrapper.h" #include "content/renderer/pepper/host_dispatcher_wrapper.h"
#include "content/renderer/pepper/host_globals.h" #include "content/renderer/pepper/host_globals.h"
#include "content/renderer/pepper/pepper_broker.h"
#include "content/renderer/pepper/pepper_browser_connection.h" #include "content/renderer/pepper/pepper_browser_connection.h"
#include "content/renderer/pepper/pepper_file_system_host.h" #include "content/renderer/pepper/pepper_file_system_host.h"
#include "content/renderer/pepper/pepper_graphics_2d_host.h" #include "content/renderer/pepper/pepper_graphics_2d_host.h"
...@@ -201,26 +200,6 @@ scoped_refptr<PluginModule> PepperHelperImpl::CreatePepperPluginModule( ...@@ -201,26 +200,6 @@ scoped_refptr<PluginModule> PepperHelperImpl::CreatePepperPluginModule(
return module; return module;
} }
scoped_refptr<PepperBroker> PepperHelperImpl::CreateBroker(
PluginModule* plugin_module) {
DCHECK(plugin_module);
DCHECK(!plugin_module->GetBroker());
// The broker path is the same as the plugin.
const base::FilePath& broker_path = plugin_module->path();
scoped_refptr<PepperBroker> broker = new PepperBroker(plugin_module, this);
int request_id =
pending_connect_broker_.Add(new scoped_refptr<PepperBroker>(broker));
// Have the browser start the broker process for us.
Send(new ViewHostMsg_OpenChannelToPpapiBroker(
routing_id(), request_id, broker_path));
return broker;
}
RendererPpapiHost* PepperHelperImpl::CreateOutOfProcessModule( RendererPpapiHost* PepperHelperImpl::CreateOutOfProcessModule(
PluginModule* module, PluginModule* module,
const base::FilePath& path, const base::FilePath& path,
...@@ -253,42 +232,6 @@ RendererPpapiHost* PepperHelperImpl::CreateOutOfProcessModule( ...@@ -253,42 +232,6 @@ RendererPpapiHost* PepperHelperImpl::CreateOutOfProcessModule(
return host_impl; return host_impl;
} }
void PepperHelperImpl::OnPpapiBrokerChannelCreated(
int request_id,
base::ProcessId broker_pid,
const IPC::ChannelHandle& handle) {
scoped_refptr<PepperBroker>* broker_ptr =
pending_connect_broker_.Lookup(request_id);
if (broker_ptr) {
scoped_refptr<PepperBroker> broker = *broker_ptr;
pending_connect_broker_.Remove(request_id);
broker->OnBrokerChannelConnected(broker_pid, handle);
} else {
// There is no broker waiting for this channel. Close it so the broker can
// clean up and possibly exit.
// The easiest way to clean it up is to just put it in an object
// and then close them. This failure case is not performance critical.
PepperBrokerDispatcherWrapper temp_dispatcher;
temp_dispatcher.Init(broker_pid, handle);
}
}
// Iterates through pending_connect_broker_ to find the broker.
// Cannot use Lookup() directly because pending_connect_broker_ does not store
// the raw pointer to the broker. Assumes maximum of one copy of broker exists.
bool PepperHelperImpl::StopWaitingForBrokerConnection(
PepperBroker* broker) {
for (BrokerMap::iterator i(&pending_connect_broker_);
!i.IsAtEnd(); i.Advance()) {
if (i.GetCurrentValue()->get() == broker) {
pending_connect_broker_.Remove(i.GetCurrentKey());
return true;
}
}
return false;
}
void PepperHelperImpl::ViewWillInitiatePaint() { void PepperHelperImpl::ViewWillInitiatePaint() {
// Notify all of our instances that we started painting. This is used for // Notify all of our instances that we started painting. This is used for
// internal bookkeeping only, so we know that the set can not change under // internal bookkeeping only, so we know that the set can not change under
...@@ -518,55 +461,6 @@ void PepperHelperImpl::InstanceDeleted( ...@@ -518,55 +461,6 @@ void PepperHelperImpl::InstanceDeleted(
} }
} }
// If a broker has not already been created for this plugin, creates one.
PepperBroker* PepperHelperImpl::ConnectToBroker(
PPB_Broker_Impl* client) {
DCHECK(client);
PluginModule* plugin_module =
HostGlobals::Get()->GetInstance(client->pp_instance())->module();
if (!plugin_module)
return NULL;
scoped_refptr<PepperBroker> broker =
static_cast<PepperBroker*>(plugin_module->GetBroker());
if (!broker.get())
broker = CreateBroker(plugin_module);
int request_id = pending_permission_requests_.Add(
new base::WeakPtr<PPB_Broker_Impl>(client->AsWeakPtr()));
Send(new ViewHostMsg_RequestPpapiBrokerPermission(
routing_id(),
request_id,
client->GetDocumentUrl(),
plugin_module->path()));
// Adds a reference, ensuring that the broker is not deleted when
// |broker| goes out of scope.
broker->AddPendingConnect(client);
return broker.get();
}
void PepperHelperImpl::OnPpapiBrokerPermissionResult(int request_id,
bool result) {
scoped_ptr<base::WeakPtr<PPB_Broker_Impl> > client_ptr(
pending_permission_requests_.Lookup(request_id));
DCHECK(client_ptr.get());
pending_permission_requests_.Remove(request_id);
base::WeakPtr<PPB_Broker_Impl> client = *client_ptr;
if (!client.get())
return;
PluginModule* plugin_module =
HostGlobals::Get()->GetInstance(client->pp_instance())->module();
if (!plugin_module)
return;
PepperBroker* broker = static_cast<PepperBroker*>(plugin_module->GetBroker());
broker->OnBrokerPermissionResult(client.get(), result);
}
void PepperHelperImpl::OnSetFocus(bool has_focus) { void PepperHelperImpl::OnSetFocus(bool has_focus) {
for (std::set<PepperPluginInstanceImpl*>::iterator i = for (std::set<PepperPluginInstanceImpl*>::iterator i =
active_instances_.begin(); active_instances_.begin();
...@@ -630,18 +524,6 @@ void PepperHelperImpl::DidReceiveMouseEvent( ...@@ -630,18 +524,6 @@ void PepperHelperImpl::DidReceiveMouseEvent(
last_mouse_event_target_ = instance; last_mouse_event_target_ = instance;
} }
bool PepperHelperImpl::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PepperHelperImpl, message)
IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
OnPpapiBrokerChannelCreated)
IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
OnPpapiBrokerPermissionResult)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PepperHelperImpl::OnDestruct() { void PepperHelperImpl::OnDestruct() {
// Nothing to do here. Default implementation in RenderViewObserver does // Nothing to do here. Default implementation in RenderViewObserver does
// 'delete this' but it's not suitable for PepperHelperImpl because // 'delete this' but it's not suitable for PepperHelperImpl because
......
...@@ -38,9 +38,7 @@ struct WebCursorInfo; ...@@ -38,9 +38,7 @@ struct WebCursorInfo;
namespace content { namespace content {
class ContextProviderCommandBuffer; class ContextProviderCommandBuffer;
class PepperBroker;
class PluginModule; class PluginModule;
class PPB_Broker_Impl;
class RenderViewImpl; class RenderViewImpl;
struct WebPluginInfo; struct WebPluginInfo;
...@@ -53,15 +51,6 @@ class PepperHelperImpl : public PepperHelper, ...@@ -53,15 +51,6 @@ class PepperHelperImpl : public PepperHelper,
RenderViewImpl* render_view() { return render_view_; } RenderViewImpl* render_view() { return render_view_; }
// A pointer is returned immediately, but it is not ready to be used until
// BrokerConnected has been called.
// The caller is responsible for calling Disconnect() on the returned pointer
// to clean up the corresponding resources allocated during this call.
PepperBroker* ConnectToBroker(PPB_Broker_Impl* client);
// Removes broker from pending_connect_broker_ if present. Returns true if so.
bool StopWaitingForBrokerConnection(PepperBroker* broker);
// Notifies that |instance| has changed the cursor. // Notifies that |instance| has changed the cursor.
// This will update the cursor appearance if it is currently over the plugin // This will update the cursor appearance if it is currently over the plugin
// instance. // instance.
...@@ -136,14 +125,8 @@ class PepperHelperImpl : public PepperHelper, ...@@ -136,14 +125,8 @@ class PepperHelperImpl : public PepperHelper,
virtual void WillHandleMouseEvent() OVERRIDE; virtual void WillHandleMouseEvent() OVERRIDE;
// RenderViewObserver implementation. // RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnDestruct() OVERRIDE; virtual void OnDestruct() OVERRIDE;
void OnPpapiBrokerChannelCreated(int request_id,
base::ProcessId broker_pid,
const IPC::ChannelHandle& handle);
void OnPpapiBrokerPermissionResult(int request_id, bool result);
// Attempts to create a PPAPI plugin for the given filepath. On success, it // Attempts to create a PPAPI plugin for the given filepath. On success, it
// will return the newly-created module. // will return the newly-created module.
// //
...@@ -157,9 +140,6 @@ class PepperHelperImpl : public PepperHelper, ...@@ -157,9 +140,6 @@ class PepperHelperImpl : public PepperHelper,
const WebPluginInfo& webplugin_info, const WebPluginInfo& webplugin_info,
bool* pepper_plugin_was_registered); bool* pepper_plugin_was_registered);
// Asynchronously attempts to create a PPAPI broker for the given plugin.
scoped_refptr<PepperBroker> CreateBroker(PluginModule* plugin_module);
// Create a new HostDispatcher for proxying, hook it to the PluginModule, // Create a new HostDispatcher for proxying, hook it to the PluginModule,
// and perform other common initialization. // and perform other common initialization.
RendererPpapiHost* CreateOutOfProcessModule( RendererPpapiHost* CreateOutOfProcessModule(
...@@ -176,12 +156,6 @@ class PepperHelperImpl : public PepperHelper, ...@@ -176,12 +156,6 @@ class PepperHelperImpl : public PepperHelper,
std::set<PepperPluginInstanceImpl*> active_instances_; std::set<PepperPluginInstanceImpl*> active_instances_;
typedef IDMap<scoped_refptr<PepperBroker>, IDMapOwnPointer> BrokerMap;
BrokerMap pending_connect_broker_;
typedef IDMap<base::WeakPtr<PPB_Broker_Impl> > PermissionRequestMap;
PermissionRequestMap pending_permission_requests_;
// Whether or not the focus is on a PPAPI plugin // Whether or not the focus is on a PPAPI plugin
PepperPluginInstanceImpl* focused_plugin_; PepperPluginInstanceImpl* focused_plugin_;
......
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
#include "content/renderer/pepper/ppb_broker_impl.h" #include "content/renderer/pepper/ppb_broker_impl.h"
#include "base/logging.h" #include "base/logging.h"
#include "content/common/view_messages.h"
#include "content/renderer/pepper/common.h" #include "content/renderer/pepper/common.h"
#include "content/renderer/pepper/host_globals.h" #include "content/renderer/pepper/host_globals.h"
#include "content/renderer/pepper/pepper_broker.h" #include "content/renderer/pepper/pepper_broker.h"
#include "content/renderer/pepper/pepper_helper_impl.h" #include "content/renderer/pepper/pepper_helper_impl.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h" #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/plugin_module.h" #include "content/renderer/pepper/plugin_module.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/shared_impl/platform_file.h" #include "ppapi/shared_impl/platform_file.h"
#include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebDocument.h"
...@@ -29,7 +32,9 @@ PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) ...@@ -29,7 +32,9 @@ PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance)
: Resource(::ppapi::OBJECT_IS_IMPL, instance), : Resource(::ppapi::OBJECT_IS_IMPL, instance),
broker_(NULL), broker_(NULL),
connect_callback_(), connect_callback_(),
pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)) { pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)),
routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) {
ChildThread::current()->AddRoute(routing_id_, this);
} }
PPB_Broker_Impl::~PPB_Broker_Impl() { PPB_Broker_Impl::~PPB_Broker_Impl() {
...@@ -40,6 +45,7 @@ PPB_Broker_Impl::~PPB_Broker_Impl() { ...@@ -40,6 +45,7 @@ PPB_Broker_Impl::~PPB_Broker_Impl() {
// The plugin owns the handle. // The plugin owns the handle.
pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue); pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue);
ChildThread::current()->RemoveRoute(routing_id_);
} }
PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() { PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() {
...@@ -59,6 +65,8 @@ int32_t PPB_Broker_Impl::Connect( ...@@ -59,6 +65,8 @@ int32_t PPB_Broker_Impl::Connect(
HostGlobals::Get()->GetInstance(pp_instance()); HostGlobals::Get()->GetInstance(pp_instance());
if (!plugin_instance) if (!plugin_instance)
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
PluginModule* module = plugin_instance->module();
const base::FilePath& broker_path = module->path();
// The callback must be populated now in case we are connected to the broker // The callback must be populated now in case we are connected to the broker
// and BrokerConnected is called before ConnectToBroker returns. // and BrokerConnected is called before ConnectToBroker returns.
...@@ -66,12 +74,26 @@ int32_t PPB_Broker_Impl::Connect( ...@@ -66,12 +74,26 @@ int32_t PPB_Broker_Impl::Connect(
// ConnectToBroker fails. // ConnectToBroker fails.
connect_callback_ = connect_callback; connect_callback_ = connect_callback;
broker_ = plugin_instance->helper()->ConnectToBroker(this); broker_ = module->GetBroker();
if (!broker_) { if (!broker_) {
connect_callback_->Abort(); broker_ = new PepperBroker(module);
return PP_ERROR_FAILED;
// Have the browser start the broker process for us.
RenderThreadImpl::current()->Send(new ViewHostMsg_OpenChannelToPpapiBroker(
routing_id_, broker_path));
} }
RenderThreadImpl::current()->Send(
new ViewHostMsg_RequestPpapiBrokerPermission(
plugin_instance->render_view()->GetRoutingID(),
routing_id_,
GetDocumentUrl(),
broker_path));
// Adds a reference, ensuring that the broker is not deleted when
// |broker| goes out of scope.
broker_->AddPendingConnect(this);
return PP_OK_COMPLETIONPENDING; return PP_OK_COMPLETIONPENDING;
} }
...@@ -103,4 +125,26 @@ void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { ...@@ -103,4 +125,26 @@ void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) {
connect_callback_->Run(result); connect_callback_->Run(result);
} }
bool PPB_Broker_Impl::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Impl, message)
IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
OnPpapiBrokerChannelCreated)
IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
OnPpapiBrokerPermissionResult)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PPB_Broker_Impl::OnPpapiBrokerChannelCreated(
base::ProcessId broker_pid,
const IPC::ChannelHandle& handle) {
broker_->OnBrokerChannelConnected(broker_pid, handle);
}
void PPB_Broker_Impl::OnPpapiBrokerPermissionResult(bool result) {
broker_->OnBrokerPermissionResult(this, result);
}
} // namespace content } // namespace content
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/process/process.h"
#include "ipc/ipc_listener.h"
#include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/trusted/ppb_broker_trusted.h" #include "ppapi/c/trusted/ppb_broker_trusted.h"
#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource.h"
...@@ -16,11 +18,16 @@ ...@@ -16,11 +18,16 @@
class GURL; class GURL;
namespace IPC {
struct ChannelHandle;
}
namespace content { namespace content {
class PepperBroker; class PepperBroker;
class PPB_Broker_Impl : public ::ppapi::Resource, class PPB_Broker_Impl : public ::ppapi::Resource,
public ::ppapi::thunk::PPB_Broker_API, public ::ppapi::thunk::PPB_Broker_API,
public IPC::Listener,
public base::SupportsWeakPtr<PPB_Broker_Impl> { public base::SupportsWeakPtr<PPB_Broker_Impl> {
public: public:
explicit PPB_Broker_Impl(PP_Instance instance); explicit PPB_Broker_Impl(PP_Instance instance);
...@@ -42,6 +49,13 @@ class PPB_Broker_Impl : public ::ppapi::Resource, ...@@ -42,6 +49,13 @@ class PPB_Broker_Impl : public ::ppapi::Resource,
private: private:
virtual ~PPB_Broker_Impl(); virtual ~PPB_Broker_Impl();
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
void OnPpapiBrokerChannelCreated(base::ProcessId broker_pid,
const IPC::ChannelHandle& handle);
void OnPpapiBrokerPermissionResult(bool result);
// PluginDelegate ppapi broker object. // PluginDelegate ppapi broker object.
// We don't own this pointer but are responsible for calling Disconnect on it. // We don't own this pointer but are responsible for calling Disconnect on it.
PepperBroker* broker_; PepperBroker* broker_;
...@@ -53,6 +67,8 @@ class PPB_Broker_Impl : public ::ppapi::Resource, ...@@ -53,6 +67,8 @@ class PPB_Broker_Impl : public ::ppapi::Resource,
// Never owned by this object. // Never owned by this object.
int32_t pipe_handle_; int32_t pipe_handle_;
int routing_id_;
DISALLOW_COPY_AND_ASSIGN(PPB_Broker_Impl); DISALLOW_COPY_AND_ASSIGN(PPB_Broker_Impl);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment