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

Side by Side Diff: webkit/plugins/ppapi/message_channel.h

Issue 6716005: A proposal and implementation for an initial postMessage interface. These in... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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, when we create a
25 // MessagePort type in PPAPI, those may be implemented here as well with some
26 // refactoring.
27 // - Separate message ports won't require the passthrough object.
28 // - The message target won't be limited to instance, and should support
29 // either plugin-provided or JS objects.
30 // TODO(dmichael): Add support for separate MessagePorts.
31 class MessageChannel {
32 public:
33 // MessageChannelNPObject is a simple struct that adds a pointer back to a
34 // MessageChannel instance. This way, we can use an NPObject to allow
35 // JavaScript interactions without forcing MessageChannel to inherit from
36 // NPObject.
37 struct MessageChannelNPObject : public NPObject {
38 MessageChannelNPObject();
39 ~MessageChannelNPObject();
40
41 MessageChannel* message_channel;
42 };
43
44 explicit MessageChannel(PluginInstance* instance);
45 ~MessageChannel();
46
47 void PostMessageToJavaScript(PP_Var message_data);
48 void PostMessageToNative(PP_Var message_data);
49
50 NPObject* passthrough_object() {
51 return passthrough_object_;
52 }
53 void set_passthrough_object(NPObject* passthrough) {
54 passthrough_object_ = passthrough;
55 }
56
57 NPObject* np_object() { return np_object_; }
58
59 PluginInstance* instance() {
60 return instance_;
61 }
62
63 private:
64 PluginInstance* instance_;
65
66 // We pass all non-postMessage calls through to the passthrough_object_.
67 // This way, a plugin can use PPB_Class or PPP_Class_Deprecated and also
68 // postMessage. This is necessary to support backwards-compatibility, and
69 // also trusted plugins for which we will continue to support synchronous
70 // scripting.
71 NPObject* passthrough_object_;
72
73 // The NPObject we use to expose postMessage to JavaScript.
74 MessageChannelNPObject* np_object_;
75
76 // An NPVariant referring to the JavaScript function we use to send a message
77 // to a JavaScript target.
78 NPVariant onmessage_invoker_;
79
80 bool EvaluateOnMessageInvoker();
81
82 DISALLOW_COPY_AND_ASSIGN(MessageChannel);
83 };
84
85 } // namespace ppapi
86 } // namespace webkit
87
88 #endif // WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_
89
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698