OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_ |
| 6 #define WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_ |
| 7 |
| 8 #include "third_party/npapi/bindings/npruntime.h" |
| 9 #include "webkit/plugins/ppapi/resource.h" |
| 10 |
| 11 struct PP_Var; |
| 12 |
| 13 namespace webkit { |
| 14 namespace ppapi { |
| 15 |
| 16 class PluginInstance; |
| 17 |
| 18 // MessageChannel implements bidirectional postMessage functionality, allowing |
| 19 // calls from JavaScript to plugins and vice-versa. See |
| 20 // PPB_Instance::PostMessage and PPP_Instance::HandleMessage for more |
| 21 // information. |
| 22 // |
| 23 // Currently, only 1 MessageChannel can exist, to implement postMessage |
| 24 // functionality for the instance interfaces. In the future, if we create a |
| 25 // MessageChannel or MessagePort type in PPAPI, those may be implemented here |
| 26 // as well with a small amount of refactoring. |
| 27 // |
| 28 class MessageChannel { |
| 29 public: |
| 30 // MessageChannelNPObject is a simple struct that adds a pointer back to a |
| 31 // MessageChannel instance. This way, we can use an NPObject to allow |
| 32 // JavaScript interactions without forcing MessageChannel to inherit from |
| 33 // NPObject. |
| 34 struct MessageChannelNPObject : public NPObject { |
| 35 MessageChannelNPObject(); |
| 36 ~MessageChannelNPObject(); |
| 37 |
| 38 MessageChannel* message_channel; |
| 39 }; |
| 40 |
| 41 explicit MessageChannel(PluginInstance* instance); |
| 42 ~MessageChannel(); |
| 43 |
| 44 void PostMessageToJavaScript(PP_Var message_data); |
| 45 void PostMessageToNative(PP_Var message_data); |
| 46 |
| 47 // TODO(dmichael): Remove passthrough_object when PPB_Class and |
| 48 // PPP_Class_Deprecated go away. |
| 49 NPObject* passthrough_object() { |
| 50 return passthrough_object_; |
| 51 } |
| 52 void set_passthrough_object(NPObject* passthrough) { |
| 53 passthrough_object_ = passthrough; |
| 54 } |
| 55 |
| 56 NPObject* np_object() { return np_object_; } |
| 57 |
| 58 PluginInstance* instance() { |
| 59 return instance_; |
| 60 } |
| 61 |
| 62 private: |
| 63 PluginInstance* instance_; |
| 64 |
| 65 // To support backwards-compatibility, we pass all calls through to the |
| 66 // passthrough_object_. This way, a plugin can use PPB_Class or |
| 67 // PPP_Class_Deprecated and also postMessage. |
| 68 // TODO(dmichael): Delete this if/when PPB_Class.* go away. |
| 69 NPObject* passthrough_object_; |
| 70 |
| 71 // The NPObject we use to expose postMessage to JavaScript. |
| 72 MessageChannelNPObject* np_object_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(MessageChannel); |
| 75 }; |
| 76 |
| 77 } // namespace ppapi |
| 78 } // namespace webkit |
| 79 |
| 80 #endif // WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_ |
| 81 |
OLD | NEW |