summaryrefslogtreecommitdiffstats
path: root/webkit/plugins
diff options
context:
space:
mode:
authorddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 22:37:36 +0000
committerddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 22:37:36 +0000
commit6788b080965ee06e7bc329526834cd1490a5b772 (patch)
treef265dd4bd700ef2ecef652dfa38014d3db7ae614 /webkit/plugins
parent1e44a9a4adccf4f31d817177e2ee47b58c93f40d (diff)
downloadchromium_src-6788b080965ee06e7bc329526834cd1490a5b772.zip
chromium_src-6788b080965ee06e7bc329526834cd1490a5b772.tar.gz
chromium_src-6788b080965ee06e7bc329526834cd1490a5b772.tar.bz2
Added PPB_BrokerTrusted interface and a basic Chrome implementation of it.
The broker is not launched or connected yet. BUG=none TEST=none Review URL: http://codereview.chromium.org/6677178 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc6
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h2
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h23
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.h6
-rw-r--r--webkit/plugins/ppapi/ppb_broker_impl.cc135
-rw-r--r--webkit/plugins/ppapi/ppb_broker_impl.h55
-rw-r--r--webkit/plugins/ppapi/resource.h1
8 files changed, 228 insertions, 4 deletions
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index 10aee19..5376483 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -52,6 +52,12 @@ MockPluginDelegate::PlatformAudio* MockPluginDelegate::CreateAudio(
return NULL;
}
+MockPluginDelegate::PpapiBroker* MockPluginDelegate::ConnectToPpapiBroker(
+ PluginInstance* instance,
+ PPB_Broker_Impl* client) {
+ return NULL;
+}
+
void MockPluginDelegate::NumberOfFindResultsChanged(int identifier,
int total,
bool final_result) {
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index 9e91160..754282f7 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -26,6 +26,8 @@ class MockPluginDelegate : public PluginDelegate {
virtual PlatformAudio* CreateAudio(uint32_t sample_rate,
uint32_t sample_count,
PlatformAudio::Client* client);
+ virtual PpapiBroker* ConnectToPpapiBroker(PluginInstance* instance,
+ PPB_Broker_Impl* client);
virtual void NumberOfFindResultsChanged(int identifier,
int total,
bool final_result);
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index 6112d53..6349cd9 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -67,6 +67,7 @@ class FullscreenContainer;
class PepperFilePath;
class PluginInstance;
class PluginModule;
+class PPB_Broker_Impl;
class PPB_Flash_Menu_Impl;
class PPB_Flash_NetConnector_Impl;
@@ -95,7 +96,7 @@ class PluginDelegate {
};
// This class is implemented by the PluginDelegate implementation and is
- // designed to manage the lifetime and communicatin with the proxy's
+ // designed to manage the lifetime and communication with the proxy's
// HostDispatcher for out-of-process PPAPI plugins.
//
// The point of this is to avoid having a relationship from the PPAPI plugin
@@ -204,6 +205,18 @@ class PluginDelegate {
virtual ~PlatformVideoDecoder() {}
};
+ // Provides access to the ppapi broker.
+ class PpapiBroker {
+ public:
+ virtual ~PpapiBroker() {}
+
+ // Decrements the references to the broker for the instance.
+ // When the references reach 0 for all instances in this renderer, this
+ // object may be destroyed. When the references reach 0 for all instances
+ // using the same module, the broker may shut down.
+ virtual void Release(PluginInstance* instance) = 0;
+ };
+
// Notification that the given plugin has crashed. When a plugin crashes, all
// instances associated with that plugin will notify that they've crashed via
// this function.
@@ -237,6 +250,14 @@ class PluginDelegate {
uint32_t sample_count,
PlatformAudio::Client* client) = 0;
+ // A pointer is returned immediately, but it is not ready to be used until
+ // BrokerConnected has been called.
+ // The caller is responsible for calling Release() on the returned pointer
+ // to clean up the corresponding resources allocated during this call.
+ virtual PpapiBroker* ConnectToPpapiBroker(
+ PluginInstance* instance,
+ webkit::ppapi::PPB_Broker_Impl* client) = 0;
+
// Notifies that the number of find results has changed.
virtual void NumberOfFindResultsChanged(int identifier,
int total,
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index b4ab5f0..6a7c397 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -58,12 +58,14 @@
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/c/private/ppb_proxy_private.h"
#include "ppapi/c/private/ppb_nacl_private.h"
+#include "ppapi/c/trusted/ppb_broker_trusted.h"
#include "ppapi/c/trusted/ppb_image_data_trusted.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
#include "webkit/plugins/ppapi/callbacks.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_audio_impl.h"
+#include "webkit/plugins/ppapi/ppb_broker_impl.h"
#include "webkit/plugins/ppapi/ppb_buffer_impl.h"
#include "webkit/plugins/ppapi/ppb_char_set_impl.h"
#include "webkit/plugins/ppapi/ppb_console_impl.h"
@@ -225,6 +227,8 @@ const void* GetInterface(const char* name) {
return PPB_Audio_Impl::GetInterface();
if (strcmp(name, PPB_AUDIO_TRUSTED_INTERFACE) == 0)
return PPB_Audio_Impl::GetTrustedInterface();
+ if (strcmp(name, PPB_BROKER_TRUSTED_INTERFACE) == 0)
+ return PPB_Broker_Impl::GetTrustedInterface();
if (strcmp(name, PPB_BUFFER_DEV_INTERFACE) == 0)
return PPB_Buffer_Impl::GetInterface();
if (strcmp(name, PPB_CHAR_SET_DEV_INTERFACE) == 0)
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.h b/webkit/plugins/ppapi/ppb_audio_impl.h
index 62f33d4..9ea2588 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.h
+++ b/webkit/plugins/ppapi/ppb_audio_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_
-#define WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_
+#ifndef WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_
+#define WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
@@ -105,4 +105,4 @@ class PPB_Audio_Impl : public Resource,
} // namespace ppapi
} // namespace webkit
-#endif // WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_
+#endif // WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_
diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc
new file mode 100644
index 0000000..d214c7b
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_broker_impl.cc
@@ -0,0 +1,135 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/plugins/ppapi/ppb_broker_impl.h"
+
+#include "base/logging.h"
+#include "webkit/plugins/ppapi/common.h"
+#include "webkit/plugins/ppapi/plugin_module.h"
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+// PPB_BrokerTrusted ----------------------------------------------------
+
+PP_Resource CreateTrusted(PP_Instance instance_id) {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
+ if (!instance)
+ return 0;
+ scoped_refptr<PPB_Broker_Impl> broker(new PPB_Broker_Impl(instance));
+ return broker->GetReference();
+}
+
+PP_Bool IsBrokerTrusted(PP_Resource resource) {
+ scoped_refptr<PPB_Broker_Impl> broker =
+ Resource::GetAs<PPB_Broker_Impl>(resource);
+ return BoolToPPBool(!!broker);
+}
+
+int32_t Connect(PP_Resource broker_id,
+ PP_CompletionCallback connect_callback) {
+ scoped_refptr<PPB_Broker_Impl> broker =
+ Resource::GetAs<PPB_Broker_Impl>(broker_id);
+ if (!broker)
+ return PP_ERROR_BADRESOURCE;
+ if (!connect_callback.func) {
+ // Synchronous calls are not supported.
+ return PP_ERROR_BADARGUMENT;
+ }
+ return broker->Connect(broker->instance()->delegate(), connect_callback);
+}
+
+int32_t GetHandle(PP_Resource broker_id, int32_t* handle) {
+ scoped_refptr<PPB_Broker_Impl> broker =
+ Resource::GetAs<PPB_Broker_Impl>(broker_id);
+ if (!broker)
+ return PP_ERROR_BADRESOURCE;
+ if (!handle)
+ return PP_ERROR_BADARGUMENT;
+ return broker->GetHandle(handle);
+}
+
+const PPB_BrokerTrusted ppb_brokertrusted = {
+ &CreateTrusted,
+ &IsBrokerTrusted,
+ &Connect,
+ &GetHandle,
+};
+
+} // namespace
+
+// PPB_Broker_Impl ------------------------------------------------------
+
+PPB_Broker_Impl::PPB_Broker_Impl(PluginInstance* instance)
+ : Resource(instance),
+ broker_(NULL),
+ connect_callback_(),
+ pipe_handle_(0) {
+}
+
+PPB_Broker_Impl::~PPB_Broker_Impl() {
+ if (broker_) {
+ broker_->Release(instance());
+ broker_ = NULL;
+ }
+
+ // TODO(ddorwin): Should the plugin or Chrome free the handle?
+ pipe_handle_ = 0;
+}
+
+const PPB_BrokerTrusted* PPB_Broker_Impl::GetTrustedInterface() {
+ return &ppb_brokertrusted;
+}
+
+int32_t PPB_Broker_Impl::Connect(
+ PluginDelegate* plugin_delegate,
+ PP_CompletionCallback connect_callback) {
+ // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process.
+
+ if (broker_) {
+ // May only be called once.
+ return PP_ERROR_FAILED;
+ }
+
+ broker_ = plugin_delegate->ConnectToPpapiBroker(instance(), this);
+ if (!broker_)
+ return PP_ERROR_FAILED;
+
+ PP_Resource resource_id = GetReferenceNoAddRef();
+ CHECK(resource_id);
+ connect_callback_ = new TrackedCompletionCallback(
+ instance()->module()->GetCallbackTracker(), resource_id,
+ connect_callback);
+ return PP_ERROR_WOULDBLOCK;
+}
+
+int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) {
+ *handle = pipe_handle_;
+
+ if (!*handle)
+ return PP_ERROR_FAILED;
+
+ return PP_OK;
+}
+
+PPB_Broker_Impl* PPB_Broker_Impl::AsPPB_Broker_Impl() {
+ return this;
+}
+
+void PPB_Broker_Impl::BrokerConnected(int32_t handle) {
+ DCHECK(handle);
+ pipe_handle_ = handle;
+
+ // Synchronous calls are not supported.
+ DCHECK(connect_callback_.get() && !connect_callback_->completed());
+
+ scoped_refptr<TrackedCompletionCallback> callback;
+ callback.swap(connect_callback_);
+ callback->Run(0); // Will complete abortively if necessary.
+}
+
+} // namespace ppapi
+} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h
new file mode 100644
index 0000000..f83d280
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_broker_impl.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_PLUGINS_PPAPI_PPB_BROKER_IMPL_H_
+#define WEBKIT_PLUGINS_PPAPI_PPB_BROKER_IMPL_H_
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/trusted/ppb_broker_trusted.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/callbacks.h"
+#include "webkit/plugins/ppapi/resource.h"
+
+namespace webkit {
+namespace ppapi {
+
+class PluginInstance;
+
+class PPB_Broker_Impl : public Resource {
+ public:
+ explicit PPB_Broker_Impl(PluginInstance* instance);
+ virtual ~PPB_Broker_Impl();
+
+ static const PPB_BrokerTrusted* GetTrustedInterface();
+
+ // PPB_BrokerTrusted implementation.
+ int32_t Connect(PluginDelegate* plugin_delegate,
+ PP_CompletionCallback connect_callback);
+ int32_t GetHandle(int32_t* handle);
+
+ // Resource override.
+ virtual PPB_Broker_Impl* AsPPB_Broker_Impl();
+
+ virtual void BrokerConnected(int32_t handle);
+
+ private:
+ // PluginDelegate ppapi broker object.
+ // We don't own this pointer but are responsible for calling Release on it.
+ PluginDelegate::PpapiBroker* broker_;
+
+ // Callback invoked from BrokerConnected.
+ scoped_refptr<TrackedCompletionCallback> connect_callback_;
+
+ // Pipe handle for the plugin instance to use to communicate with the broker.
+ int32_t pipe_handle_;
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_Broker_Impl);
+};
+
+} // namespace ppapi
+} // namespace webkit
+
+#endif // WEBKIT_PLUGINS_PPAPI_PPB_BROKER_IMPL_H_
diff --git a/webkit/plugins/ppapi/resource.h b/webkit/plugins/ppapi/resource.h
index 018988f..267249b 100644
--- a/webkit/plugins/ppapi/resource.h
+++ b/webkit/plugins/ppapi/resource.h
@@ -18,6 +18,7 @@ namespace ppapi {
F(MockResource) \
F(PPB_AudioConfig_Impl) \
F(PPB_Audio_Impl) \
+ F(PPB_Broker_Impl) \
F(PPB_Buffer_Impl) \
F(PPB_Context3D_Impl) \
F(PPB_DirectoryReader_Impl) \