transport.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Contains the base class for transports.
  16. *
  17. */
  18. goog.provide('goog.net.xpc.Transport');
  19. goog.require('goog.Disposable');
  20. goog.require('goog.dom');
  21. goog.require('goog.net.xpc.TransportNames');
  22. /**
  23. * The base class for transports.
  24. * @param {goog.dom.DomHelper=} opt_domHelper The dom helper to use for
  25. * finding the window objects.
  26. * @constructor
  27. * @extends {goog.Disposable};
  28. */
  29. goog.net.xpc.Transport = function(opt_domHelper) {
  30. goog.Disposable.call(this);
  31. /**
  32. * The dom helper to use for finding the window objects to reference.
  33. * @type {goog.dom.DomHelper}
  34. * @private
  35. */
  36. this.domHelper_ = opt_domHelper || goog.dom.getDomHelper();
  37. };
  38. goog.inherits(goog.net.xpc.Transport, goog.Disposable);
  39. /**
  40. * The transport type.
  41. * @type {number}
  42. * @protected
  43. */
  44. goog.net.xpc.Transport.prototype.transportType = 0;
  45. /**
  46. * @return {number} The transport type identifier.
  47. */
  48. goog.net.xpc.Transport.prototype.getType = function() {
  49. return this.transportType;
  50. };
  51. /**
  52. * Returns the window associated with this transport instance.
  53. * @return {!Window} The window to use.
  54. */
  55. goog.net.xpc.Transport.prototype.getWindow = function() {
  56. return this.domHelper_.getWindow();
  57. };
  58. /**
  59. * Return the transport name.
  60. * @return {string} the transport name.
  61. */
  62. goog.net.xpc.Transport.prototype.getName = function() {
  63. return goog.net.xpc.TransportNames[String(this.transportType)] || '';
  64. };
  65. /**
  66. * Handles transport service messages (internal signalling).
  67. * @param {string} payload The message content.
  68. */
  69. goog.net.xpc.Transport.prototype.transportServiceHandler = goog.abstractMethod;
  70. /**
  71. * Connects this transport.
  72. * The transport implementation is expected to call
  73. * CrossPageChannel.prototype.notifyConnected when the channel is ready
  74. * to be used.
  75. */
  76. goog.net.xpc.Transport.prototype.connect = goog.abstractMethod;
  77. /**
  78. * Sends a message.
  79. * @param {string} service The name off the service the message is to be
  80. * delivered to.
  81. * @param {string} payload The message content.
  82. */
  83. goog.net.xpc.Transport.prototype.send = goog.abstractMethod;