channel.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // Copyright 2013 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 A shared interface for WebChannelBase and BaseTestChannel.
  16. *
  17. * @visibility {:internal}
  18. */
  19. goog.provide('goog.labs.net.webChannel.Channel');
  20. /**
  21. * Shared interface between Channel and TestChannel to support callbacks
  22. * between WebChannelBase and BaseTestChannel and between Channel and
  23. * ChannelRequest.
  24. *
  25. * @interface
  26. */
  27. goog.labs.net.webChannel.Channel = function() {};
  28. goog.scope(function() {
  29. var Channel = goog.labs.net.webChannel.Channel;
  30. /**
  31. * Determines whether to use a secondary domain when the server gives us
  32. * a host prefix. This allows us to work around browser per-domain
  33. * connection limits.
  34. *
  35. * If you need to use secondary domains on different browsers and IE10,
  36. * you have two choices:
  37. * 1) If you only care about browsers that support CORS
  38. * (https://developer.mozilla.org/en-US/docs/HTTP_access_control), you
  39. * can use {@link #setSupportsCrossDomainXhrs} and set the appropriate
  40. * CORS response headers on the server.
  41. * 2) Or, override this method in a subclass, and make sure that those
  42. * browsers use some messaging mechanism that works cross-domain (e.g
  43. * iframes and window.postMessage).
  44. *
  45. * @return {boolean} Whether to use secondary domains.
  46. * @see http://code.google.com/p/closure-library/issues/detail?id=339
  47. */
  48. Channel.prototype.shouldUseSecondaryDomains = goog.abstractMethod;
  49. /**
  50. * Called when creating an XhrIo object. Override in a subclass if
  51. * you need to customize the behavior, for example to enable the creation of
  52. * XHR's capable of calling a secondary domain. Will also allow calling
  53. * a secondary domain if withCredentials (CORS) is enabled.
  54. * @param {?string} hostPrefix The host prefix, if we need an XhrIo object
  55. * capable of calling a secondary domain.
  56. * @return {!goog.net.XhrIo} A new XhrIo object.
  57. */
  58. Channel.prototype.createXhrIo = goog.abstractMethod;
  59. /**
  60. * Callback from ChannelRequest that indicates a request has completed.
  61. * @param {!goog.labs.net.webChannel.ChannelRequest} request
  62. * The request object.
  63. */
  64. Channel.prototype.onRequestComplete = goog.abstractMethod;
  65. /**
  66. * Returns whether the channel is closed
  67. * @return {boolean} true if the channel is closed.
  68. */
  69. Channel.prototype.isClosed = goog.abstractMethod;
  70. /**
  71. * Callback from ChannelRequest for when new data is received
  72. * @param {goog.labs.net.webChannel.ChannelRequest} request
  73. * The request object.
  74. * @param {string} responseText The text of the response.
  75. */
  76. Channel.prototype.onRequestData = goog.abstractMethod;
  77. /**
  78. * Gets whether this channel is currently active. This is used to determine the
  79. * length of time to wait before retrying. This call delegates to the handler.
  80. * @return {boolean} Whether the channel is currently active.
  81. */
  82. Channel.prototype.isActive = goog.abstractMethod;
  83. /**
  84. * Not needed for testchannel.
  85. *
  86. * Gets the Uri used for the connection that sends data to the server.
  87. * @param {string} path The path on the host.
  88. * @return {goog.Uri} The forward channel URI.
  89. */
  90. Channel.prototype.getForwardChannelUri = goog.abstractMethod;
  91. /**
  92. * Not needed for testchannel.
  93. *
  94. * Gets the Uri used for the connection that receives data from the server.
  95. * @param {?string} hostPrefix The host prefix.
  96. * @param {string} path The path on the host.
  97. * @return {goog.Uri} The back channel URI.
  98. */
  99. Channel.prototype.getBackChannelUri = goog.abstractMethod;
  100. /**
  101. * Not needed for testchannel.
  102. *
  103. * Allows the handler to override a host prefix provided by the server. Will
  104. * be called whenever the channel has received such a prefix and is considering
  105. * its use.
  106. * @param {?string} serverHostPrefix The host prefix provided by the server.
  107. * @return {?string} The host prefix the client should use.
  108. */
  109. Channel.prototype.correctHostPrefix = goog.abstractMethod;
  110. /**
  111. * Not needed for testchannel.
  112. *
  113. * Creates a data Uri applying logic for secondary hostprefix, port
  114. * overrides, and versioning.
  115. * @param {?string} hostPrefix The host prefix.
  116. * @param {string} path The path on the host (may be absolute or relative).
  117. * @param {number=} opt_overridePort Optional override port.
  118. * @return {goog.Uri} The data URI.
  119. */
  120. Channel.prototype.createDataUri = goog.abstractMethod;
  121. /**
  122. * Not needed for testchannel.
  123. *
  124. * Callback from TestChannel for when the channel is finished.
  125. * @param {goog.labs.net.webChannel.BaseTestChannel} testChannel
  126. * The TestChannel.
  127. * @param {boolean} useChunked Whether we can chunk responses.
  128. */
  129. Channel.prototype.testConnectionFinished = goog.abstractMethod;
  130. /**
  131. * Not needed for testchannel.
  132. *
  133. * Callback from TestChannel for when the channel has an error.
  134. * @param {goog.labs.net.webChannel.BaseTestChannel} testChannel
  135. * The TestChannel.
  136. * @param {goog.labs.net.webChannel.ChannelRequest.Error} errorCode
  137. * The error code of the failure.
  138. */
  139. Channel.prototype.testConnectionFailure = goog.abstractMethod;
  140. /**
  141. * Not needed for testchannel.
  142. * Gets the result of previous connectivity tests.
  143. *
  144. * @return {!goog.labs.net.webChannel.ConnectionState} The connectivity state.
  145. */
  146. Channel.prototype.getConnectionState = goog.abstractMethod;
  147. /**
  148. * Sets the parameter name for the http session id.
  149. *
  150. * @param {?string} httpSessionIdParam The parameter name for http session id
  151. */
  152. Channel.prototype.setHttpSessionIdParam = goog.abstractMethod;
  153. /**
  154. * Gets the parameter name for the http session id.
  155. *
  156. * @return {?string} The parameter name for the http session id.
  157. */
  158. Channel.prototype.getHttpSessionIdParam = goog.abstractMethod;
  159. /**
  160. * Sets the http session id.
  161. *
  162. * @param {string} httpSessionId The http session id
  163. */
  164. Channel.prototype.setHttpSessionId = goog.abstractMethod;
  165. /**
  166. * Gets the http session id.
  167. *
  168. * @return {?string} The http session id if there is one in effect.
  169. */
  170. Channel.prototype.getHttpSessionId = goog.abstractMethod;
  171. /**
  172. * Returns true if the channel-test is done in background.
  173. *
  174. * @return {boolean} if the channel-test is done in background.
  175. */
  176. Channel.prototype.getBackgroundChannelTest = goog.abstractMethod;
  177. }); // goog.scope