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

Unified Diff: content/renderer/pepper/message_channel.h

Issue 400823004: gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
Index: content/renderer/pepper/message_channel.h
diff --git a/content/renderer/pepper/message_channel.h b/content/renderer/pepper/message_channel.h
index 8c744a044191c5003dc6cc29102803523b9a1f9d..e038fdc76048615898ec8f74178150b4b542f83f 100644
--- a/content/renderer/pepper/message_channel.h
+++ b/content/renderer/pepper/message_channel.h
@@ -9,20 +9,29 @@
#include <list>
#include <map>
+#include "base/basictypes.h"
#include "base/memory/weak_ptr.h"
+#include "gin/handle.h"
+#include "gin/interceptor.h"
+#include "gin/wrappable.h"
#include "ppapi/shared_impl/resource.h"
#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
-#include "third_party/npapi/bindings/npruntime.h"
+#include "v8/include/v8.h"
struct PP_Var;
+namespace gin {
+class Arguments;
+} // namespace gin
+
namespace ppapi {
class ScopedPPVar;
-}
+} // namespace ppapi
namespace content {
class PepperPluginInstanceImpl;
+class PluginObject;
// MessageChannel implements bidirectional postMessage functionality, allowing
// calls from JavaScript to plugins and vice-versa. See
@@ -37,63 +46,86 @@ class PepperPluginInstanceImpl;
// - The message target won't be limited to instance, and should support
// either plugin-provided or JS objects.
// TODO(dmichael): Add support for separate MessagePorts.
-class MessageChannel {
+class MessageChannel : public gin::Wrappable<MessageChannel>,
+ public gin::NamedPropertyInterceptor,
+ public gin::IndexedPropertyInterceptor {
public:
- // MessageChannelNPObject is a simple struct that adds a pointer back to a
- // MessageChannel instance. This way, we can use an NPObject to allow
- // JavaScript interactions without forcing MessageChannel to inherit from
- // NPObject.
- struct MessageChannelNPObject : public NPObject {
- MessageChannelNPObject();
- ~MessageChannelNPObject();
-
- base::WeakPtr<MessageChannel> message_channel;
- };
-
- explicit MessageChannel(PepperPluginInstanceImpl* instance);
- ~MessageChannel();
+ static gin::WrapperInfo kWrapperInfo;
+
+ static void Create(PepperPluginInstanceImpl* instance,
+ v8::Persistent<v8::Object>* result);
+
+ virtual ~MessageChannel();
+
+ // gin::NamedPropertyInterceptor
+ virtual v8::Local<v8::Value> GetNamedProperty(
+ v8::Isolate* isolate,
+ const std::string& property) OVERRIDE;
+ virtual void SetNamedProperty(v8::Isolate* isolate,
+ const std::string& property,
+ v8::Local<v8::Value> value) OVERRIDE;
+ virtual std::vector<std::string> EnumerateNamedProperties(
+ v8::Isolate* isolate) OVERRIDE;
+
+ // gin::IndexedPropertyInterceptor
+ virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate,
+ uint32_t index) OVERRIDE;
+ virtual void SetIndexedProperty(v8::Isolate* isolate,
+ uint32_t index,
+ v8::Local<v8::Value> value) OVERRIDE;
+ virtual std::vector<uint32_t> EnumerateIndexedProperties(
+ v8::Isolate* isolate) OVERRIDE;
// Post a message to the onmessage handler for this channel's instance
// asynchronously.
void PostMessageToJavaScript(PP_Var message_data);
- // Post a message to the plugin's HandleMessage function for this channel's
- // instance.
- void PostMessageToNative(const NPVariant* message_data);
- // Post a message to the plugin's HandleBlocking Message function for this
- // channel's instance synchronously, and return a result.
- void PostBlockingMessageToNative(const NPVariant* message_data,
- NPVariant* np_result);
+ // Messages are queued initially. After the PepperPluginInstanceImpl is ready
+ // to send and handle messages, users of MessageChannel should call
+ // Start().
+ void Start();
- // Return the NPObject* to which we should forward any calls which aren't
- // related to postMessage. Note that this can be NULL; it only gets set if
+ // Set the V8Object to which we should forward any calls which aren't
+ // related to postMessage. Note that this can be empty; it only gets set if
// there is a scriptable 'InstanceObject' associated with this channel's
// instance.
- NPObject* passthrough_object() { return passthrough_object_; }
- void SetPassthroughObject(NPObject* passthrough);
-
- NPObject* np_object() { return np_object_; }
+ void SetPassthroughObject(v8::Handle<v8::Object> passthrough);
PepperPluginInstanceImpl* instance() { return instance_; }
- // Messages are queued initially. After the PepperPluginInstanceImpl is ready
- // to send and handle messages, users of MessageChannel should call
- // Start().
- void Start();
-
- bool GetReadOnlyProperty(NPIdentifier key, NPVariant* value) const;
void SetReadOnlyProperty(PP_Var key, PP_Var value);
private:
- // Struct for storing the result of a NPVariant being converted to a PP_Var.
+ // Struct for storing the result of a v8 object being converted to a PP_Var.
struct VarConversionResult;
- void EnqueuePluginMessage(const NPVariant* variant);
+ explicit MessageChannel(PepperPluginInstanceImpl* instance);
+
+ // gin::Wrappable
+ virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
+ v8::Isolate* isolate) OVERRIDE;
+
+ // Post a message to the plugin's HandleMessage function for this channel's
+ // instance.
+ void PostMessageToNative(gin::Arguments* args);
+ // Post a message to the plugin's HandleBlocking Message function for this
+ // channel's instance synchronously, and return a result.
+ void PostBlockingMessageToNative(gin::Arguments* args);
+
+ PluginObject* GetPluginObject(v8::Isolate* isolate);
+
+ void EnqueuePluginMessage(v8::Handle<v8::Value> v8_value);
void FromV8ValueComplete(VarConversionResult* result_holder,
const ppapi::ScopedPPVar& result_var,
bool success);
void DrainCompletedPluginMessages();
+ void DrainEarlyMessageQueue();
+
+ // Post a message to the onmessage handler for this channel's instance
+ // synchronously. This is used by PostMessageToJavaScript.
+ void PostMessageToJavaScriptImpl(
+ const blink::WebSerializedScriptValue& message_data);
PepperPluginInstanceImpl* instance_;
@@ -102,20 +134,7 @@ class MessageChannel {
// postMessage. This is necessary to support backwards-compatibility, and
// also trusted plugins for which we will continue to support synchronous
// scripting.
- NPObject* passthrough_object_;
-
- // The NPObject we use to expose postMessage to JavaScript.
- MessageChannelNPObject* np_object_;
-
- // Post a message to the onmessage handler for this channel's instance
- // synchronously. This is used by PostMessageToJavaScript.
- void PostMessageToJavaScriptImpl(
- const blink::WebSerializedScriptValue& message_data);
- // Post a message to the PPP_Instance HandleMessage function for this
- // channel's instance. This is used by PostMessageToNative.
- void PostMessageToNativeImpl(PP_Var message_data);
-
- void DrainEarlyMessageQueue();
+ v8::Persistent<v8::Object> passthrough_object_;
std::deque<blink::WebSerializedScriptValue> early_message_queue_;
enum EarlyMessageQueueState {
@@ -134,7 +153,8 @@ class MessageChannel {
// probably also work, but is less clearly specified).
std::list<VarConversionResult> plugin_message_queue_;
- std::map<NPIdentifier, ppapi::ScopedPPVar> internal_properties_;
+ std::map<std::string, ppapi::ScopedPPVar> internal_named_properties_;
+ std::map<uint32_t, ppapi::ScopedPPVar> internal_indexed_properties_;
// This is used to ensure pending tasks will not fire after this object is
// destroyed.
@@ -146,3 +166,4 @@ class MessageChannel {
} // namespace content
#endif // CONTENT_RENDERER_PEPPER_MESSAGE_CHANNEL_H_
+

Powered by Google App Engine
This is Rietveld 408576698