Path: blob/trunk/third_party/closure/goog/labs/net/webchannel/channel.js
1865 views
// Copyright 2013 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview A shared interface for WebChannelBase and BaseTestChannel.16*17* @visibility {:internal}18*/192021goog.provide('goog.labs.net.webChannel.Channel');22232425/**26* Shared interface between Channel and TestChannel to support callbacks27* between WebChannelBase and BaseTestChannel and between Channel and28* ChannelRequest.29*30* @interface31*/32goog.labs.net.webChannel.Channel = function() {};333435goog.scope(function() {36var Channel = goog.labs.net.webChannel.Channel;373839/**40* Determines whether to use a secondary domain when the server gives us41* a host prefix. This allows us to work around browser per-domain42* connection limits.43*44* If you need to use secondary domains on different browsers and IE10,45* you have two choices:46* 1) If you only care about browsers that support CORS47* (https://developer.mozilla.org/en-US/docs/HTTP_access_control), you48* can use {@link #setSupportsCrossDomainXhrs} and set the appropriate49* CORS response headers on the server.50* 2) Or, override this method in a subclass, and make sure that those51* browsers use some messaging mechanism that works cross-domain (e.g52* iframes and window.postMessage).53*54* @return {boolean} Whether to use secondary domains.55* @see http://code.google.com/p/closure-library/issues/detail?id=33956*/57Channel.prototype.shouldUseSecondaryDomains = goog.abstractMethod;585960/**61* Called when creating an XhrIo object. Override in a subclass if62* you need to customize the behavior, for example to enable the creation of63* XHR's capable of calling a secondary domain. Will also allow calling64* a secondary domain if withCredentials (CORS) is enabled.65* @param {?string} hostPrefix The host prefix, if we need an XhrIo object66* capable of calling a secondary domain.67* @return {!goog.net.XhrIo} A new XhrIo object.68*/69Channel.prototype.createXhrIo = goog.abstractMethod;707172/**73* Callback from ChannelRequest that indicates a request has completed.74* @param {!goog.labs.net.webChannel.ChannelRequest} request75* The request object.76*/77Channel.prototype.onRequestComplete = goog.abstractMethod;787980/**81* Returns whether the channel is closed82* @return {boolean} true if the channel is closed.83*/84Channel.prototype.isClosed = goog.abstractMethod;858687/**88* Callback from ChannelRequest for when new data is received89* @param {goog.labs.net.webChannel.ChannelRequest} request90* The request object.91* @param {string} responseText The text of the response.92*/93Channel.prototype.onRequestData = goog.abstractMethod;949596/**97* Gets whether this channel is currently active. This is used to determine the98* length of time to wait before retrying. This call delegates to the handler.99* @return {boolean} Whether the channel is currently active.100*/101Channel.prototype.isActive = goog.abstractMethod;102103104/**105* Not needed for testchannel.106*107* Gets the Uri used for the connection that sends data to the server.108* @param {string} path The path on the host.109* @return {goog.Uri} The forward channel URI.110*/111Channel.prototype.getForwardChannelUri = goog.abstractMethod;112113114/**115* Not needed for testchannel.116*117* Gets the Uri used for the connection that receives data from the server.118* @param {?string} hostPrefix The host prefix.119* @param {string} path The path on the host.120* @return {goog.Uri} The back channel URI.121*/122Channel.prototype.getBackChannelUri = goog.abstractMethod;123124125/**126* Not needed for testchannel.127*128* Allows the handler to override a host prefix provided by the server. Will129* be called whenever the channel has received such a prefix and is considering130* its use.131* @param {?string} serverHostPrefix The host prefix provided by the server.132* @return {?string} The host prefix the client should use.133*/134Channel.prototype.correctHostPrefix = goog.abstractMethod;135136137/**138* Not needed for testchannel.139*140* Creates a data Uri applying logic for secondary hostprefix, port141* overrides, and versioning.142* @param {?string} hostPrefix The host prefix.143* @param {string} path The path on the host (may be absolute or relative).144* @param {number=} opt_overridePort Optional override port.145* @return {goog.Uri} The data URI.146*/147Channel.prototype.createDataUri = goog.abstractMethod;148149150/**151* Not needed for testchannel.152*153* Callback from TestChannel for when the channel is finished.154* @param {goog.labs.net.webChannel.BaseTestChannel} testChannel155* The TestChannel.156* @param {boolean} useChunked Whether we can chunk responses.157*/158Channel.prototype.testConnectionFinished = goog.abstractMethod;159160161/**162* Not needed for testchannel.163*164* Callback from TestChannel for when the channel has an error.165* @param {goog.labs.net.webChannel.BaseTestChannel} testChannel166* The TestChannel.167* @param {goog.labs.net.webChannel.ChannelRequest.Error} errorCode168* The error code of the failure.169*/170Channel.prototype.testConnectionFailure = goog.abstractMethod;171172173/**174* Not needed for testchannel.175* Gets the result of previous connectivity tests.176*177* @return {!goog.labs.net.webChannel.ConnectionState} The connectivity state.178*/179Channel.prototype.getConnectionState = goog.abstractMethod;180181182/**183* Sets the parameter name for the http session id.184*185* @param {?string} httpSessionIdParam The parameter name for http session id186*/187Channel.prototype.setHttpSessionIdParam = goog.abstractMethod;188189190/**191* Gets the parameter name for the http session id.192*193* @return {?string} The parameter name for the http session id.194*/195Channel.prototype.getHttpSessionIdParam = goog.abstractMethod;196197198/**199* Sets the http session id.200*201* @param {string} httpSessionId The http session id202*/203Channel.prototype.setHttpSessionId = goog.abstractMethod;204205206/**207* Gets the http session id.208*209* @return {?string} The http session id if there is one in effect.210*/211Channel.prototype.getHttpSessionId = goog.abstractMethod;212213214/**215* Returns true if the channel-test is done in background.216*217* @return {boolean} if the channel-test is done in background.218*/219Channel.prototype.getBackgroundChannelTest = goog.abstractMethod;220}); // goog.scope221222223