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

Unified Diff: content/renderer/pepper/pepper_broker_impl.cc

Issue 10854040: Add hooks to content to request permission to connect to the PPAPI broker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/pepper/pepper_broker_impl.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/pepper/pepper_broker_impl.cc
diff --git a/content/renderer/pepper/pepper_broker_impl.cc b/content/renderer/pepper/pepper_broker_impl.cc
index 67fdd84d80a10d79fb2ecd3524ebb1df273d7282..cda23e7808a8eb2a69783fcda32716d7eb87c5ea 100644
--- a/content/renderer/pepper/pepper_broker_impl.cc
+++ b/content/renderer/pepper/pepper_broker_impl.cc
@@ -116,24 +116,14 @@ PepperBrokerImpl::PepperBrokerImpl(webkit::ppapi::PluginModule* plugin_module,
}
PepperBrokerImpl::~PepperBrokerImpl() {
- // Report failure to all clients that had pending operations.
- for (ClientMap::iterator i = pending_connects_.begin();
- i != pending_connects_.end(); ++i) {
- base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = i->second;
- if (weak_ptr) {
- weak_ptr->BrokerConnected(
- ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue),
- PP_ERROR_ABORTED);
- }
- }
- pending_connects_.clear();
-
+ ReportFailureToClients(PP_ERROR_ABORTED);
plugin_module_->SetBroker(NULL);
plugin_module_ = NULL;
}
// If the channel is not ready, queue the connection.
-void PepperBrokerImpl::Connect(webkit::ppapi::PPB_Broker_Impl* client) {
+void PepperBrokerImpl::AddPendingConnect(
+ webkit::ppapi::PPB_Broker_Impl* client) {
DCHECK(pending_connects_.find(client) == pending_connects_.end())
<< "Connect was already called for this client";
@@ -146,13 +136,7 @@ void PepperBrokerImpl::Connect(webkit::ppapi::PPB_Broker_Impl* client) {
// longer using it.
AddRef();
- if (!dispatcher_.get()) {
- pending_connects_[client] = client->AsWeakPtr();
- return;
- }
- DCHECK(pending_connects_.empty());
-
- ConnectPluginToBroker(client);
+ pending_connects_[client].client = client->AsWeakPtr();
}
void PepperBrokerImpl::Disconnect(webkit::ppapi::PPB_Broker_Impl* client) {
@@ -179,7 +163,7 @@ void PepperBrokerImpl::Disconnect(webkit::ppapi::PPB_Broker_Impl* client) {
bool stopped = delegate_->StopWaitingForBrokerConnection(this);
// Verify the assumption that there are no references other than the one
- // client holds, which will be released below.
+ // |client| holds, which will be released below.
DCHECK(!stopped || HasOneRef());
}
}
@@ -193,26 +177,81 @@ void PepperBrokerImpl::OnBrokerChannelConnected(
const IPC::ChannelHandle& channel_handle) {
scoped_ptr<PepperBrokerDispatcherWrapper> dispatcher(
new PepperBrokerDispatcherWrapper);
- if (dispatcher->Init(channel_handle)) {
- dispatcher_.reset(dispatcher.release());
-
- // Process all pending channel requests from the plugins.
- for (ClientMap::iterator i = pending_connects_.begin();
- i != pending_connects_.end(); ++i) {
- base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = i->second;
- if (weak_ptr)
- ConnectPluginToBroker(weak_ptr);
+ if (!dispatcher->Init(channel_handle)) {
+ ReportFailureToClients(PP_ERROR_FAILED);
+ return;
+ }
+
+ dispatcher_.reset(dispatcher.release());
+
+ // Process all pending channel requests from the plugins.
+ for (ClientMap::iterator i = pending_connects_.begin();
+ i != pending_connects_.end();) {
+ base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr =
+ i->second.client;
+ if (!i->second.is_authorized) {
+ ++i;
+ continue;
}
- } else {
- // Report failure to all clients.
- for (ClientMap::iterator i = pending_connects_.begin();
- i != pending_connects_.end(); ++i) {
- base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = i->second;
- if (weak_ptr) {
- weak_ptr->BrokerConnected(
- ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue),
- PP_ERROR_FAILED);
- }
+
+ if (weak_ptr)
+ ConnectPluginToBroker(weak_ptr);
+
+ pending_connects_.erase(i++);
+ }
+}
+
+void PepperBrokerImpl::OnBrokerPermissionResult(
+ webkit::ppapi::PPB_Broker_Impl* client,
+ bool result) {
+ ClientMap::iterator entry = pending_connects_.find(client);
+ if (entry == pending_connects_.end())
+ return;
+
+ if (!entry->second.client) {
+ // Client has gone away.
+ pending_connects_.erase(entry);
+ return;
+ }
+
+ if (!result) {
+ // Report failure.
+ client->BrokerConnected(
+ ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue),
+ PP_ERROR_NOACCESS);
+ pending_connects_.erase(entry);
+ return;
+ }
+
+ if (dispatcher_.get()) {
+ ConnectPluginToBroker(client);
+ pending_connects_.erase(entry);
+ return;
+ }
+
+ // Mark the request as authorized, continue waiting for the broker
+ // connection.
+ DCHECK(!entry->second.is_authorized);
+ entry->second.is_authorized = true;
+}
+
+PepperBrokerImpl::PendingConnection::PendingConnection()
+ : is_authorized(false) {
+}
+
+PepperBrokerImpl::PendingConnection::~PendingConnection() {
+}
+
+void PepperBrokerImpl::ReportFailureToClients(int error_code) {
+ DCHECK_NE(PP_OK, error_code);
+ for (ClientMap::iterator i = pending_connects_.begin();
+ i != pending_connects_.end(); ++i) {
+ base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr =
+ i->second.client;
+ if (weak_ptr) {
+ weak_ptr->BrokerConnected(
+ ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue),
+ error_code);
}
}
pending_connects_.clear();
« no previous file with comments | « content/renderer/pepper/pepper_broker_impl.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698