index.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <html>
  2. <!--
  3. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  4. Use of this source code is governed by the Apache License, Version 2.0.
  5. See the COPYING file for details.
  6. -->
  7. <head>
  8. <script type="text/javascript" src="../../../base.js"></script>
  9. <script type="text/javascript">
  10. goog.require('goog.dom');
  11. goog.require('goog.dom.TagName');
  12. goog.require('goog.events');
  13. goog.require('goog.net.xpc.CrossPageChannel');
  14. </script>
  15. <script type="text/javascript">
  16. var channel;
  17. var logEl;
  18. /**
  19. * Writes a message to the log.
  20. * @param {string} msg The message text.
  21. */
  22. function log(msg) {
  23. logEl || (logEl = goog.dom.getElement('log'));
  24. var msgEl = goog.dom.createDom(goog.dom.TagName.DIV);
  25. msgEl.innerHTML = msg;
  26. logEl.insertBefore(msgEl, logEl.firstChild);
  27. }
  28. goog.events.listen(window, 'load', function() {
  29. // Build the channel configuration.
  30. var cfg = {};
  31. var ownUri = new goog.Uri(window.location.href);
  32. var peerDomain = ownUri.getParameterValue('peerdomain') || ownUri.getDomain();
  33. var peerUri = ownUri.clone().setDomain(peerDomain);
  34. var localRelayUri = ownUri.resolve(new goog.Uri('relay.html'));
  35. var peerRelayUri = peerUri.resolve(new goog.Uri('relay.html'));
  36. var localPollUri = ownUri.resolve(new goog.Uri('blank.html'));
  37. var peerPollUri = peerUri.resolve(new goog.Uri('blank.html'));
  38. cfg[goog.net.xpc.CfgFields.LOCAL_RELAY_URI] = localRelayUri.toString();
  39. cfg[goog.net.xpc.CfgFields.PEER_RELAY_URI] = peerRelayUri.toString();
  40. cfg[goog.net.xpc.CfgFields.LOCAL_POLL_URI] = localPollUri.toString();
  41. cfg[goog.net.xpc.CfgFields.PEER_POLL_URI] = peerPollUri.toString();
  42. // Set the URI of the peer page.
  43. var peerUri = ownUri.resolve(
  44. new goog.Uri('inner.html')).setDomain(peerDomain);
  45. cfg[goog.net.xpc.CfgFields.PEER_URI] = peerUri;
  46. // Create the channel.
  47. channel = new goog.net.xpc.CrossPageChannel(cfg);
  48. // Create the peer iframe.
  49. channel.createPeerIframe(
  50. goog.dom.getElement('iframeContainer'));
  51. channel.registerService('log', log);
  52. channel.connect(function() {
  53. log('Channel connected.');
  54. });
  55. });
  56. </script>
  57. <style type="text/css">
  58. body, td {
  59. background-color: #eeeeff;
  60. font-family: arial,verdana;
  61. font-size: 12px;
  62. }
  63. </style>
  64. </head>
  65. <body>
  66. <table border=0 width="100%" height="100%"><tr><td width="50%" valign="top">
  67. <h3><script type="text/javascript">document.write(location.href.replace(/\?.*/,'?...'))</script></h3>
  68. <p>
  69. <input type="text" id="msgInput" value="Hello from the container page."
  70. style="width:250px">
  71. <input type="button" value="Send" onclick="
  72. channel.send('log', goog.dom.getElement('msgInput').value)">
  73. </p>
  74. <div id="log" style="border: 1px #000 solid;"></div>
  75. </td><td width="50%" valign="top" id="iframeContainer">
  76. </td></tr></table>
  77. </body>
  78. </html>