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

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

Issue 19744007: Create a public API around webkit::ppapi::PluginInstance and use it in chrome. After this, webkit/p… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_ 5 #ifndef WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_
6 #define WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_ 6 #define WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "ppapi/shared_impl/resource.h" 11 #include "ppapi/shared_impl/resource.h"
12 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 12 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
13 #include "third_party/npapi/bindings/npruntime.h" 13 #include "third_party/npapi/bindings/npruntime.h"
14 14
15 struct PP_Var; 15 struct PP_Var;
16 16
17 namespace webkit { 17 namespace webkit {
18 namespace ppapi { 18 namespace ppapi {
19 19
20 class PluginInstance; 20 class PluginInstanceImpl;
21 21
22 // MessageChannel implements bidirectional postMessage functionality, allowing 22 // MessageChannel implements bidirectional postMessage functionality, allowing
23 // calls from JavaScript to plugins and vice-versa. See 23 // calls from JavaScript to plugins and vice-versa. See
24 // PPB_Messaging::PostMessage and PPP_Messaging::HandleMessage for more 24 // PPB_Messaging::PostMessage and PPP_Messaging::HandleMessage for more
25 // information. 25 // information.
26 // 26 //
27 // Currently, only 1 MessageChannel can exist, to implement postMessage 27 // Currently, only 1 MessageChannel can exist, to implement postMessage
28 // functionality for the instance interfaces. In the future, when we create a 28 // functionality for the instance interfaces. In the future, when we create a
29 // MessagePort type in PPAPI, those may be implemented here as well with some 29 // MessagePort type in PPAPI, those may be implemented here as well with some
30 // refactoring. 30 // refactoring.
31 // - Separate message ports won't require the passthrough object. 31 // - Separate message ports won't require the passthrough object.
32 // - The message target won't be limited to instance, and should support 32 // - The message target won't be limited to instance, and should support
33 // either plugin-provided or JS objects. 33 // either plugin-provided or JS objects.
34 // TODO(dmichael): Add support for separate MessagePorts. 34 // TODO(dmichael): Add support for separate MessagePorts.
35 class MessageChannel { 35 class MessageChannel {
36 public: 36 public:
37 // MessageChannelNPObject is a simple struct that adds a pointer back to a 37 // MessageChannelNPObject is a simple struct that adds a pointer back to a
38 // MessageChannel instance. This way, we can use an NPObject to allow 38 // MessageChannel instance. This way, we can use an NPObject to allow
39 // JavaScript interactions without forcing MessageChannel to inherit from 39 // JavaScript interactions without forcing MessageChannel to inherit from
40 // NPObject. 40 // NPObject.
41 struct MessageChannelNPObject : public NPObject { 41 struct MessageChannelNPObject : public NPObject {
42 MessageChannelNPObject(); 42 MessageChannelNPObject();
43 ~MessageChannelNPObject(); 43 ~MessageChannelNPObject();
44 44
45 base::WeakPtr<MessageChannel> message_channel; 45 base::WeakPtr<MessageChannel> message_channel;
46 }; 46 };
47 47
48 explicit MessageChannel(PluginInstance* instance); 48 explicit MessageChannel(PluginInstanceImpl* instance);
49 ~MessageChannel(); 49 ~MessageChannel();
50 50
51 // Post a message to the onmessage handler for this channel's instance 51 // Post a message to the onmessage handler for this channel's instance
52 // asynchronously. 52 // asynchronously.
53 void PostMessageToJavaScript(PP_Var message_data); 53 void PostMessageToJavaScript(PP_Var message_data);
54 // Post a message to the PPP_Instance HandleMessage function for this 54 // Post a message to the PPP_Instance HandleMessage function for this
55 // channel's instance. 55 // channel's instance.
56 void PostMessageToNative(PP_Var message_data); 56 void PostMessageToNative(PP_Var message_data);
57 57
58 // Return the NPObject* to which we should forward any calls which aren't 58 // Return the NPObject* to which we should forward any calls which aren't
59 // related to postMessage. Note that this can be NULL; it only gets set if 59 // related to postMessage. Note that this can be NULL; it only gets set if
60 // there is a scriptable 'InstanceObject' associated with this channel's 60 // there is a scriptable 'InstanceObject' associated with this channel's
61 // instance. 61 // instance.
62 NPObject* passthrough_object() { 62 NPObject* passthrough_object() {
63 return passthrough_object_; 63 return passthrough_object_;
64 } 64 }
65 void SetPassthroughObject(NPObject* passthrough); 65 void SetPassthroughObject(NPObject* passthrough);
66 66
67 NPObject* np_object() { return np_object_; } 67 NPObject* np_object() { return np_object_; }
68 68
69 PluginInstance* instance() { 69 PluginInstanceImpl* instance() {
70 return instance_; 70 return instance_;
71 } 71 }
72 72
73 // Messages sent to JavaScript are queued by default. After the DOM is 73 // Messages sent to JavaScript are queued by default. After the DOM is
74 // set up for the plugin, users of MessageChannel should call 74 // set up for the plugin, users of MessageChannel should call
75 // StopQueueingJavaScriptMessages to start dispatching messages to JavaScript. 75 // StopQueueingJavaScriptMessages to start dispatching messages to JavaScript.
76 void QueueJavaScriptMessages(); 76 void QueueJavaScriptMessages();
77 void StopQueueingJavaScriptMessages(); 77 void StopQueueingJavaScriptMessages();
78 78
79 private: 79 private:
80 PluginInstance* instance_; 80 PluginInstanceImpl* instance_;
81 81
82 // We pass all non-postMessage calls through to the passthrough_object_. 82 // We pass all non-postMessage calls through to the passthrough_object_.
83 // This way, a plugin can use PPB_Class or PPP_Class_Deprecated and also 83 // This way, a plugin can use PPB_Class or PPP_Class_Deprecated and also
84 // postMessage. This is necessary to support backwards-compatibility, and 84 // postMessage. This is necessary to support backwards-compatibility, and
85 // also trusted plugins for which we will continue to support synchronous 85 // also trusted plugins for which we will continue to support synchronous
86 // scripting. 86 // scripting.
87 NPObject* passthrough_object_; 87 NPObject* passthrough_object_;
88 88
89 // The NPObject we use to expose postMessage to JavaScript. 89 // The NPObject we use to expose postMessage to JavaScript.
90 MessageChannelNPObject* np_object_; 90 MessageChannelNPObject* np_object_;
(...skipping 23 matching lines...) Expand all
114 }; 114 };
115 EarlyMessageQueueState early_message_queue_state_; 115 EarlyMessageQueueState early_message_queue_state_;
116 116
117 DISALLOW_COPY_AND_ASSIGN(MessageChannel); 117 DISALLOW_COPY_AND_ASSIGN(MessageChannel);
118 }; 118 };
119 119
120 } // namespace ppapi 120 } // namespace ppapi
121 } // namespace webkit 121 } // namespace webkit
122 122
123 #endif // WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_ 123 #endif // WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698