summaryrefslogtreecommitdiffstats
path: root/ppapi/examples/scripting
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-13 23:11:54 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-13 23:11:54 +0000
commit8585fd865df3044b8215e4486698422562712e6c (patch)
treef6f2b49818fac61ed3039dc9aa1402b9647c7fed /ppapi/examples/scripting
parent5e8d27087b478de2d7136fa9016c4e178e19305e (diff)
downloadchromium_src-8585fd865df3044b8215e4486698422562712e6c.zip
chromium_src-8585fd865df3044b8215e4486698422562712e6c.tar.gz
chromium_src-8585fd865df3044b8215e4486698422562712e6c.tar.bz2
Fix event dispatching for PPB_Messaging::PostMessage. I asked Adam about the "plugin.onmessage = function(x){...}" style vs the 'plugin.addEventListener' style, and it seems that we should prefer supporting the addEventListener style.
This breaks the ability to do "plugin.onmessage =" :-(. I expected dispatchEvent to do it for me, but it does not. To add that support (if desired), I could work on making dispatchEvent do it, or I could fake it out via the script in MessageChannel (Basically have the old path of invoking onmessage directly, plus the new dispatchEvent code). Brett, please focus on PPAPI-specific stuff. Adam, please focus on my event code (especially message_channel.cc and the JavaScript in test_post_message.cc). BUG=None TEST=test_post_message.cc Review URL: http://codereview.chromium.org/6901060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85348 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/examples/scripting')
-rw-r--r--ppapi/examples/scripting/post_message.html63
1 files changed, 32 insertions, 31 deletions
diff --git a/ppapi/examples/scripting/post_message.html b/ppapi/examples/scripting/post_message.html
index 883d312..46e0c34 100644
--- a/ppapi/examples/scripting/post_message.html
+++ b/ppapi/examples/scripting/post_message.html
@@ -7,44 +7,45 @@
-->
<head>
<title>postMessage Example</title>
-</head>
-
-<body>
+ <script>
-<script type="text/javascript">
-
-function SendString() {
- plugin = document.getElementById('plugin');
-
- // If we haven't already done it, set up an 'onmessage' function. This will
- // get invoked whenever the plugin calls Instance::PostMessage in C++ (or
- // PPB_Messaging::PostMessage in C). In this case, we're expecting a bool to
- // tell us whether the string we passed was a palindrome.
- if (!plugin.onmessage) {
- plugin.onmessage = function(message_event) {
- if (message_event.data) {
- alert("The string was a palindrome.");
- } else {
- alert("The string was not a palindrome.");
- }
+ function HandleMessage(message_event) {
+ if (message_event.data) {
+ alert("The string was a palindrome.");
+ } else {
+ alert("The string was not a palindrome.");
}
}
- var inputBox = document.getElementById("inputBox");
+ function AddListener() {
+ var plugin = document.getElementById("plugin");
+ plugin.addEventListener("message", HandleMessage, false);
+ }
+ document.addEventListener("DOMContentLoaded", AddListener, false);
+
+ </script>
+</head>
+
+<body>
+ <script>
- // Send the string to the plugin using postMessage. This results in a call
- // to Instance::HandleMessage in C++ (or PPP_Messaging::HandleMessage in C).
- plugin.postMessage(inputBox.value);
-}
+ function SendString() {
+ var plugin = document.getElementById("plugin");
+ var inputBox = document.getElementById("inputBox");
+
+ // Send the string to the plugin using postMessage. This results in a call
+ // to Instance::HandleMessage in C++ (or PPP_Messaging::HandleMessage in C).
+ plugin.postMessage(inputBox.value);
+ }
-</script>
+ </script>
-<input type="text" id="inputBox" name="inputBox" value="ablewasiereisawelba"/>
-<p>
-<button onclick='SendString()'>Is Palindrome</button>
-<object id="plugin" type="application/x-ppapi-post-message-example"
- width="0" height="0"/>
-<hr>
+ <input type="text" id="inputBox" name="inputBox" value="ablewasiereisawelba"/>
+ <p>
+ <button onclick="SendString()">Is Palindrome</button>
+ <object id="plugin" type="application/x-ppapi-post-message-example"
+ width="1" height="1"/>
+ <hr>
</body>
</html>