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