Chromium Code Reviews| Index: content/renderer/pepper/message_channel.h |
| diff --git a/content/renderer/pepper/message_channel.h b/content/renderer/pepper/message_channel.h |
| index 4682399939d8cc369bf7dc5711e9259a675794b2..b7ae8734215c0e1e7998a1e8401b01e003c9aa06 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,64 +46,80 @@ 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; |
| - }; |
| + static gin::WrapperInfo kWrapperInfo; |
|
dmichael (off chromium)
2014/08/20 23:09:15
Can it be made const?
|
| + |
| + 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; |
| - explicit MessageChannel(PepperPluginInstanceImpl* instance); |
| - ~MessageChannel(); |
| + // Post a message to the onmessage handler for this channel's instance |
| + // asynchronously. |
| + void PostMessageToJavaScript(PP_Var message_data); |
| // 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_; } |
| - bool GetReadOnlyProperty(NPIdentifier key, NPVariant* value) const; |
| void SetReadOnlyProperty(PP_Var key, PP_Var value); |
| - // Post a message to the onmessage handler for this channel's instance |
| - // asynchronously. |
| - void PostMessageToJavaScript(PP_Var message_data); |
| + private: |
| + // Struct for storing the result of a v8 object being converted to a PP_Var. |
| + struct VarConversionResult; |
| + |
| + 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(const NPVariant* message_data); |
| - |
| + 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(const NPVariant* message_data, |
| - NPVariant* np_result); |
| - |
| - private: |
| - // Struct for storing the result of a NPVariant being converted to a PP_Var. |
| - struct VarConversionResult; |
| + void PostBlockingMessageToNative(gin::Arguments* args); |
| // 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); |
| - void EnqueuePluginMessage(const NPVariant* variant); |
| + PluginObject* GetPluginObject(v8::Isolate* isolate); |
| + |
| + void EnqueuePluginMessage(v8::Handle<v8::Value> v8_value); |
| void FromV8ValueComplete(VarConversionResult* result_holder, |
| const ppapi::ScopedPPVar& result_var, |
| @@ -110,10 +135,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_; |
| + v8::Persistent<v8::Object> passthrough_object_; |
| std::deque<blink::WebSerializedScriptValue> early_message_queue_; |
| enum EarlyMessageQueueState { |
| @@ -132,7 +154,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. |
| @@ -144,3 +167,4 @@ class MessageChannel { |
| } // namespace content |
| #endif // CONTENT_RENDERER_PEPPER_MESSAGE_CHANNEL_H_ |
| + |