inner_peer.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE html>
  2. <!--
  3. This file is responsible for setting up the inner peer half of an XPC
  4. communication channel. It instantiates a CrossPageChannel and attempts to
  5. connect to the outer peer. The XPC configuration should match that of the
  6. outer peer (i.e. same channel name, polling URIs, etc).
  7. -->
  8. <html>
  9. <!--
  10. Copyright 2009 The Closure Library Authors. All Rights Reserved.
  11. Use of this source code is governed by the Apache License, Version 2.0.
  12. See the COPYING file for details.
  13. -->
  14. <head>
  15. <title>XPC test inner frame</title>
  16. <script src="../../../base.js" type="text/javascript"></script>
  17. <script type="text/javascript">
  18. goog.require('goog.debug.Logger');
  19. goog.require('goog.dom');
  20. goog.require('goog.events');
  21. goog.require('goog.events.EventType');
  22. goog.require('goog.net.xpc.CrossPageChannel');
  23. </script>
  24. <script type="text/javascript">
  25. var channel;
  26. var queuedMessage;
  27. var OBJECT_RESULT_FROM_SERVICE = {'favorites': 'pie'};
  28. function clearDebug() {
  29. document.getElementById('debugDiv').innerHTML = '';
  30. }
  31. function instantiateChannel(cfg) {
  32. if (window.channel) {
  33. window.channel.dispose();
  34. }
  35. window.channel = new goog.net.xpc.CrossPageChannel(cfg);
  36. window.channel.registerService('echo', echoHandler);
  37. window.channel.registerService('response', responseHandler);
  38. connectChannel(
  39. parent.driver && parent.driver.innerFrameConnected ?
  40. goog.bind(parent.driver.innerFrameConnected, parent.driver) : null);
  41. }
  42. function connectChannel(opt_callback) {
  43. window.channel.connect(opt_callback || goog.nullFunction);
  44. }
  45. function sendEcho(payload) {
  46. window.channel.send('echo', payload);
  47. }
  48. function echoHandler(payload) {
  49. window.channel.send('response', payload);
  50. return OBJECT_RESULT_FROM_SERVICE;
  51. }
  52. function isConnected() {
  53. return window.channel && window.channel.isConnected();
  54. }
  55. function responseHandler(payload) {
  56. if (parent.driver && parent.driver.innerFrameGotResponse) {
  57. parent.driver.innerFrameGotResponse(payload);
  58. }
  59. }
  60. </script>
  61. </head>
  62. <body>
  63. <div style="position:absolute">
  64. Debug [<a href="#" onclick="clearDebug()">clear</a>]: <br>
  65. <div id=debugDiv style="border: 1px #000000 solid; font-size:xx-small"></div>
  66. </div>
  67. <script type="text/javascript">
  68. var debugDiv = goog.dom.getElement('debugDiv');
  69. var logger = goog.debug.Logger.getLogger('goog.net.xpc');
  70. logger.setLevel(goog.debug.Logger.Level.ALL);
  71. logger.addHandler(function(logRecord) {
  72. var msgElm = goog.dom.createDom('div');
  73. msgElm.innerHTML = logRecord.getMessage();
  74. goog.dom.appendChild(debugDiv, msgElm);
  75. });
  76. if (parent && parent.iframeLoadHandler) {
  77. parent.iframeLoadHandler();
  78. }
  79. </script>
  80. </body>
  81. </html>