Home

# Class goog.net.BrowserChannel

Encapsulates the logic for a single BrowserChannel.

Instance Method Summary
| `addAdditionalParams_(?goog.Uri uri)` Adds the additional parameters from the handler to the given URI.
| `cancelRequests_()` Cancels all outstanding requests.
| `clearDeadBackchannelTimer_()` Clears the timer that indicates that our backchannel is no longer able to successfully receive data from the server.
| `connect(string testPath, string channelPath, ?Object extraParams, string= opt_oldSessionId, number= opt_oldArrayId)` Starts the channel. This initiates connections to the server.
| `connectChannel_()` Starts the regular channel which is run after the test channel is complete.
| `connectTest_(string testPath)` Starts the test channel to determine network conditions.
| `correctHostPrefix(?string serverHostPrefix) ⇒ ?string` Decides which host prefix should be used, if any. If there is a handler, allows the handler to validate a host prefix provided by the server, and optionally override it.
| `createDataUri(?string hostPrefix, string path, number= opt_overridePort) ⇒ ?goog.Uri` Creates a data Uri applying logic for secondary hostprefix, port overrides, and versioning.
| `createXhrIo(?string hostPrefix) ⇒ !goog.net.XhrIo` Called when BC needs to create an XhrIo object. Override in a subclass if you need to customize the behavior, for example to enable the creation of XHR's capable of calling a secondary domain.
| `dequeueOutgoingMaps_() ⇒ string` Returns the request text from the outgoing maps and resets it.
| `disconnect()` Disconnects and closes the channel.
| `ensureBackChannel_()` Ensures there is a backchannel request for receiving data from the server.
| `ensureForwardChannel_()` Ensures that a forward channel request is scheduled.
| `ensureInState_((number|undefined) var_args)` Helper to ensure the BrowserChannel is in the expected state.
| `getAllowChunkedMode() ⇒ boolean` Returns whether chunked mode is allowed. In certain debugging situations, it's useful for the application to have a way to disable chunked mode for a user.
| `getAllowHostPrefix() ⇒ boolean` Returns whether the channel allows the use of a subdomain. There may be cases where this isn't allowed.
| `getBackChannelMaxRetries() ⇒ number`
| `getBackChannelUri(?string hostPrefix, string path) ⇒ ?goog.Uri` Gets the Uri used for the connection that receives data from the server.
| `getChannelDebug() ⇒ ?goog.net.ChannelDebug` Returns the browserchannel logger.
| `getExtraHeaders() ⇒ ?Object` Returns the extra HTTP headers to add to all the requests sent to the server.
| `getForwardChannelMaxRetries() ⇒ number`
| `getForwardChannelUri(string path) ⇒ ?goog.Uri` Gets the Uri used for the connection that sends data to the server.
| `getHandler() ⇒ ?goog.net.BrowserChannel.Handler` Returns the handler used for channel callback events.
| `getLastArrayId() ⇒ number`
| `getLastStatusCode() ⇒ number` Return the last status code received for a request.
| `getRetryTime_(number retryCount) ⇒ number`
| `getSessionId() ⇒ string` Returns the session id of the channel. Only available after the channel has been opened.
| `getState() ⇒ ?goog.net.BrowserChannel.State` Returns the browser channel state.
| `handleBackchannelMissing_()` Handles a POST response from the server telling us that it has detected that we have no hanging GET connection.
| `handlePostResponse_(?Array responseValues)` Handles a POST response from the server.
| `hasOutstandingRequests() ⇒ boolean` Returns whether there are outstanding requests servicing the channel.
| `isActive() ⇒ boolean` Gets whether this channel is currently active. This is used to determine the length of time to wait before retrying. This call delegates to the handler.
| `isBuffered() ⇒ boolean` Returns whether the channel is buffered or not. This state is valid for querying only after the test connection has completed. This may be queried in the goog.net.BrowserChannel.okToMakeRequest() callback. A channel may be buffered if the test connection determines that a chunked response could not be sent down within a suitable time.
| `isClosed() ⇒ boolean` Returns whether the channel is closed
| `makeForwardChannelRequest_(?goog.net.ChannelRequest= opt_retryRequest)` Makes a forward channel request using XMLHTTP.
| `maybeRetryBackChannel_() ⇒ boolean` Schedules a back-channel retry, unless the max retries has been reached.
| `maybeRetryForwardChannel_(?goog.net.ChannelRequest request) ⇒ boolean` Schedules a forward-channel retry for the specified request, unless the max retries has been reached.
| `okToMakeRequest_() ⇒ boolean` Gives the handler a chance to return an error code and stop channel execution. A handler might want to do this to check that the user is still logged in, for example.
| `onBackChannelDead_()` Handles the timer that indicates that our backchannel is no longer able to successfully receive data from the server.
| `onClose_()` Called when the channel has been closed. It notifiers the handler of the event, and reports any pending or undelivered maps.
| `onError_(?goog.net.BrowserChannel.Error error)` Called when we've determined the final error for a channel. It closes the notifiers the handler of the error and closes the channel.
| `onInput_(?Array respArray)` Processes the data returned by the server.
| `onRequestComplete(?goog.net.ChannelRequest request)` Callback from ChannelRequest that indicates a request has completed.
| `onRequestData(?goog.net.ChannelRequest request, string responseText)` Callback from ChannelRequest for when new data is received
| `onStartBackChannelTimer_()` Timer callback for ensureBackChannel_.
| `onStartForwardChannelTimer_(?goog.net.ChannelRequest= opt_retryRequest)` Timer callback for ensureForwardChannel
| `open_()` Establishes a new channel session with the the server.
| `outstandingRequests_() ⇒ number` Returns the number of outstanding requests.
| `requeuePendingMaps_()` Requeues unacknowledged sent arrays for retransmission in the next forward channel request.
| `sendMap((Object|goog.structs.Map|null) map)` Sends a request to the server. The format of the request is a Map data structure of key/value pairs. These maps are then encoded in a format suitable for the wire and then reconstituted as a Map data structure that the server can process.
| `setAllowChunkedMode(boolean allowChunkedMode)` Sets whether chunked mode is allowed. In certain debugging situations, it's useful for the application to have a way to disable chunked mode for a user.
| `setAllowHostPrefix(boolean allowHostPrefix)` Sets whether the channel allows the use of a subdomain. There may be cases where this isn't allowed, for example, logging in with troutboard where using a subdomain causes Apache to force the user to authenticate twice.
| `setChannelDebug(?goog.net.ChannelDebug channelDebug)` Set the browserchannel logger. TODO(user): Add interface for channel loggers or remove this function.
| `setExtraHeaders(?Object extraHeaders)` Sets extra HTTP headers to add to all the requests sent to the server.
| `setFailFast(boolean failFast)` When set to true, this changes the behavior of the forward channel so it will not retry requests; it will fail after one network failure, and if there was already one network failure, the request will fail immediately.
| `setHandler(?goog.net.BrowserChannel.Handler handler)` Sets the handler used for channel callback events.
| `shouldRetryBackChannel_(number outstandingBytes) ⇒ boolean` Determines whether we should start the process of retrying a possibly dead backchannel.

`shouldUseSecondaryDomains() ⇒ boolean`

Determines whether to use a secondary domain when the server gives us a host prefix. This allows us to work around browser per-domain connection limits. Currently, we only use secondary domains when using Trident's ActiveXObject, because it supports cross-domain requests out of the box. Even if we wanted to use secondary domains on Gecko/Webkit, they wouldn't work due to security restrictions on cross-origin XHRs. If you need to use secondary domains on other browsers, you'll need to override this method in a subclass, and make sure that those browsers use some messaging mechanism that works cross-domain.

| `signalError_(?goog.net.BrowserChannel.Error error)` Signals an error has occurred.
| `startBackChannel_()` Begins a new back channel operation to the server.
| `startForwardChannel_(?goog.net.ChannelRequest= opt_retryRequest)` Begins a new forward channel operation to the server.
| `testConnectionBlocked(?goog.net.BrowserTestChannel testChannel)` Callback from BrowserTestChannel for when the channel is blocked.
| `testConnectionFailure(?goog.net.BrowserTestChannel testChannel, ?goog.net.ChannelRequest.Error errorCode)` Callback from BrowserTestChannel for when the channel has an error.
| `testConnectionFinished(?goog.net.BrowserTestChannel testChannel, boolean useChunked)` Callback from BrowserTestChannel for when the channel is finished.
| `testGoogleComCallback_(boolean networkUp)` Callback for testGoogleCom during error handling.

Static Method Summary
| `createChannelRequest((goog.net.BrowserChannel|goog.net.BrowserTestChannel|null) channel, ?goog.net.ChannelDebug channelDebug, string= opt_sessionId, (number|string=) opt_requestId, number= opt_retryId) ⇒ ?goog.net.ChannelRequest` Instantiates a ChannelRequest with the given parameters. Overidden in tests.
| `endExecutionHook_()` Application provided execution hook for the end hook.
| `getStatEventTarget() ⇒ ?goog.events.EventTarget` Returns the singleton event target for stat events.
| `isFatalError_(?goog.net.ChannelRequest.Error error, number statusCode) ⇒ boolean` Returns whether or not the given error/status combination is fatal or not. On fatal errors we immediately close the session rather than retrying the failed request.
| `notifyStatEvent(?goog.net.BrowserChannel.Stat stat)` Helper function to call the stat event callback.
| `notifyTimingEvent(number size, number rtt, number retries)` Helper function to notify listeners about POST request performance.
| `onEndExecution()` Helper function to call the end hook
| `onStartExecution()` Helper function to call the start hook
| `setEndThreadExecutionHook(?Function endHook)` Allows the application to set an execution hooks for when BrowserChannel stops processing requests. This is useful to track timing or logging special information. The function takes no parameters and return void.
| `setStartThreadExecutionHook(?Function startHook)` Allows the application to set an execution hooks for when BrowserChannel starts processing requests. This is useful to track timing or logging special information. The function takes no parameters and return void.
| `setTimeout(?Function fn, number ms) ⇒ number` Wrapper around SafeTimeout which calls the start and end execution hooks with a try...finally block.
| `startExecutionHook_()` Application provided execution hook for the start hook.