net.IframeIo Extends goog.events.EventTarget
Class for managing requests via iFrames.

Inheritance

Constructor

goog.net.IframeIo()

Instance Methods

Public Protected Private
abort(opt_failureCode)
Abort the current Iframe request
Arguments:
opt_failureCode : goog.net.ErrorCode=
Optional error code to use - defaults to ABORT.
code »
appendIframe_()
Appends the Iframe to the document body.
code »
clearForm_()
Removes all the child nodes from the static form so it can be reused again. This should happen right after sending a request. Otherwise, there can be issues when another iframe uses this form right after the first iframe.
code »
createIframe_()
Creates an iframe to be used with a request. We use a new iframe for each request so that requests don't create history entries.
code »
disposeForm_()
Disposes of the Form. Since IE6 leaks form nodes, this just cleans up the DOM and nullifies the instances reference so the form can be used for another request.
code »
disposeIframes_()
Disposes any iframes.
code »
disposeInternal()
No description.
code »
getContentDocument_() HTMLDocument
No description.
Returns: HTMLDocument  The appropriate content document.
code »
getErrorChecker() Function
Gets the callback function used to check if a loaded IFrame is in an error state.
Returns: Function  A callback that expects a document object as it's single argument.
code »
getLastCustomError() Object
Gets the last custom error.
Returns: Object  Last custom error.
code »
getLastError() string
Gets the last error message.
Returns: string  Last error message.
code »
getLastErrorCode() goog.net.ErrorCode
Gets the last error code.
Returns: goog.net.ErrorCode  Last error code.
code »
getLastUri() goog.Uri
Get the uri of the last request.
Returns: goog.Uri  Uri of last request.
code »
getRequestIframe() HTMLIFrameElement
No description.
Returns: HTMLIFrameElement  The appropriate iframe to use for requests (created in sendForm_).
code »
getResponseHtml() ?string
Returns the last response html (i.e. the innerHtml of the iframe).
Returns: ?string  Result from the server.
code »
getResponseJson() Object
Parses the content as JSON. This is a safe parse and may throw an error if the response is malformed. Use goog.json.unsafeparse(this.getResponseText()) if you are sure of the state of the returned content.
Returns: Object  The parsed content.
code »
getResponseText() ?string
Returns the last response text (i.e. the text content of the iframe). Assumes plain text!
Returns: ?string  Result from the server.
code »
getResponseXml() HTMLDocument
Returns the document object from the last request. Not truely XML, but used to mirror the XhrIo interface.
Returns: HTMLDocument  The document object from the last request.
code »
getTimeoutInterval() number
Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
Returns: number  Timeout interval in milliseconds.
code »
handleError_(errorCodeopt_customError)
Handles errors.
Arguments:
errorCode : goog.net.ErrorCode
Error code.
opt_customError : Object=
If error is CUSTOM_ERROR, this is the client-provided custom error.
code »
handleIncrementalData_(data)
Dispatches an event indicating that the IframeIo instance has received a data packet via incremental loading. The event object has a 'data' member.
Arguments:
data : Object
Data.
code »
handleLoad_(contentDocument)
Handles generic post-load
Arguments:
contentDocument : HTMLDocument
The frame's document.
code »
isActive() boolean
No description.
Returns: boolean  True if a transfer is in progress.
code »
isComplete() boolean
No description.
Returns: boolean  True if transfer is complete.
code »
isIgnoringResponse() boolean
No description.
Returns: boolean  Whether the server response is being ignored.
code »
isSuccess() boolean
No description.
Returns: boolean  True if transfer was successful.
code »
makeReady_()
Finalizes the request, schedules the iframe for disposal, and maybe disposes the form.
code »
onIeReadyStateChange_(e)
Handles the load event of the iframe for IE, determines if the request was successful or not, handles clean up and dispatching of appropriate events.
Arguments:
e : goog.events.BrowserEvent
The browser event.
code »
onIframeLoaded_(e)
Handles the load event of the iframe for non-IE browsers.
Arguments:
e : goog.events.BrowserEvent
The browser event.
code »
scheduleIframeDisposal_()
Schedules an iframe for disposal, async. We can't remove the iframes in the same execution context as the response, otherwise some versions of Firefox will not detect that the response has correctly finished and the loading bar will stay active forever.
code »
send(uriopt_methodopt_noCacheopt_data)
Sends a request via an iframe. A HTML form is used and submitted to the iframe, this simplifies the difference between GET and POST requests. The iframe needs to be created and destroyed for each request otherwise the request will contribute to the history stack. sendFromForm does some clever trickery (thanks jlim) in non-IE browsers to stop a history entry being added for POST requests.
Arguments:
uri : goog.Uri | string
Uri of the request.
opt_method : string=
Default is GET, POST uses a form to submit the request.
opt_noCache : boolean=
Append a timestamp to the request to avoid caching.
opt_data : Object | goog.structs.Map=
Map of key-value pairs.
code »
sendFormInternal_()
Submits the internal form to the iframe.
code »
sendFromForm(formopt_uriopt_noCache)
Sends the data stored in an existing form to the server. The HTTP method should be specified on the form, the action can also be specified but can be overridden by the optional URI param. This can be used in conjunction will a file-upload input to upload a file in the background without affecting history. Example form:
  <form action="/server/" enctype="multipart/form-data" method="POST">
    <input name="userfile" type="file">
  </form>
Arguments:
form : HTMLFormElement
Form element used to send the request to the server.
opt_uri : string=
Uri to set for the destination of the request, by default the uri will come from the form.
opt_noCache : boolean=
Append a timestamp to the request to avoid caching.
code »
setErrorChecker(fn)
Sets the callback function used to check if a loaded IFrame is in an error state.
Arguments:
fn : Function
Callback that expects a document object as it's single argument.
code »
setIgnoreResponse(ignore)
Sets whether to ignore the response from the server by not adding any event handlers to fire when the iframe loads. This is necessary when using IframeIo to submit to a server on another domain, to avoid same-origin violations when trying to access the response. If this is set to true, the IframeIo instance will be a single-use instance that is only usable for one request. It will only clean up its resources (iframes and forms) when it is disposed.
Arguments:
ignore : boolean
Whether to ignore the server response.
code »
setTimeoutInterval(ms)
Sets the number of milliseconds after which an incomplete request will be aborted and a goog.net.EventType.TIMEOUT event raised; 0 means no timeout is set.
Arguments:
ms : number
Timeout interval in milliseconds; 0 means none.
code »
testForFirefoxSilentError_()
Tests for a silent failure by firefox that can occur when the connection is reset by the server or is made to an illegal URL.
code »
addEventListener(typeopt_captureopt_handlerScope)
Use #listen instead, when possible. Otherwise, use goog.events.listen if you are passing Object (instead of Function) as handler. Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.
Arguments:
type : string
The type of the event to listen for.
: ?function():? | ?{handleEvent:function():?
No description.
opt_capture : boolean=
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope : Object=
Object in whose scope to call the listener.
code »
assertInitialized_()
Asserts that the event target instance is initialized properly.
code »
dispatchEvent()
No description.
code »
disposeInternal()
Removes listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners.
code »
fireListeners()
No description.
code »
getListener()
No description.
code »
getListeners()
No description.
code »
getParentEventTarget() goog.events.EventTarget
Returns the parent of this event target to use for bubbling.
Returns: goog.events.EventTarget  The parent EventTarget or null if there is no parent.
code »
hasListener()
No description.
code »
listen()
No description.
code »
listenOnce()
No description.
code »
removeAllListeners()
No description.
code »
removeEventListener(typeopt_captureopt_handlerScope)
Use #unlisten instead, when possible. Otherwise, use goog.events.unlisten if you are passing Object (instead of Function) as handler. Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
Arguments:
type : string
The type of the event to listen for.
: ?function():? | ?{handleEvent:function():?
No description.
opt_capture : boolean=
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope : Object=
Object in whose scope to call the listener.
code »
setParentEventTarget(parent)
Sets the parent of this event target to use for capture/bubble mechanism.
Arguments:
parent : goog.events.EventTarget
Parent listenable (null if none).
code »
setTargetForTesting(target)
Sets the target to be used for event.target when firing event. Mainly used for testing. For example, see goog.testing.events.mixinListenable.
Arguments:
target : !Object
The target.
code »
unlisten()
No description.
code »
unlistenByKey()
No description.
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback : function(this:T):?
The callback function.
opt_scope : T=
An optional scope to call the callback in.
code »
dispose() void
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: void  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
  mypackage.MyClass = function() {
    mypackage.MyClass.base(this, 'constructor');
    // Constructor logic specific to MyClass.
    ...
  };
  goog.inherits(mypackage.MyClass, goog.Disposable);

  mypackage.MyClass.prototype.disposeInternal = function() {
    // Dispose logic specific to MyClass.
    ...
    // Call superclass's disposeInternal at the end of the subclass's, like
    // in C++, to avoid hard-to-catch issues.
    mypackage.MyClass.base(this, 'disposeInternal');
  };
code »
getDisposed() boolean
Use #isDisposed instead. No description.
Returns: boolean  Whether the object has been disposed of.
code »
isDisposed() boolean
No description.
Returns: boolean  Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable : goog.disposable.IDisposable
that will be disposed when this object is disposed.
code »

Instance Properties

active_ :
Whether the object is currently active with a request.
Code »
complete_ :
Whether the last request is complete.
Code »
constructor :
No description.
Code »
errorHandled_ :
This is used to ensure that we don't handle errors twice for the same error. We can reach the #handleError_ method twice in IE if the form is submitted while IE is offline and the URL is not available.
Code »
firefoxSilentErrorTimeout_ :
Window timeout ID used to detect when firefox silently fails.
Code »
form_ :
Reference to form element that gets reused for requests to the iframe.
Code »
iframeDisposalTimer_ :
Window timeout ID used by the timer that disposes the iframes.
Code »
iframeName_ :
Name of the iframe being used for the current request, or null if no request is currently active.
Code »
iframe_ :
Reference to the iframe being used for the current request, or null if no request is currently active.
Code »
iframesForDisposal_ :
An array of iframes that have been finished with. We need them to be disposed async, so we don't confuse the browser (see below).
Code »
ignoreResponse_ :
Whether to suppress the listeners that determine when the iframe loads.
Code »
lastContent_ :
The text content of the last request.
Code »
lastErrorCode_ :
Last error code
Code »
lastUri_ : goog.Uri
The URI for the last request.
Code »
logger_ : goog.debug.Logger
Reference to a logger for the IframeIo objects
Code »
name_ :
Name for this IframeIo and frame
Code »
nextIframeId_ :
Next id so that iframe names are unique.
Code »
success_ :
Whether the last request was a success.
Code »
timeoutId_ :
Window timeout ID used to cancel the timeout event handler if the request completes successfully.
Code »
timeoutInterval_ :
Number of milliseconds after which an incomplete request will be aborted and a goog.net.EventType.TIMEOUT event raised; 0 means no timeout is set.
Code »
actualEventTarget_ : goog.events.EventTarget
The object to use for event.target. Useful when mixing in an EventTarget to another object.
Code »
constructor :
No description.
Code »
eventTargetListeners_ : goog.events.ListenerMap
Maps of event type to an array of listeners.
Code »
parentEventTarget_ : goog.events.EventTarget
Parent event target, used during event bubbling. TODO(user): Change this to goog.events.Listenable. This currently breaks people who expect getParentEventTarget to return goog.events.EventTarget.
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
Callbacks to invoke when this object is disposed.
Code »

Static Methods

goog.net.IframeIo.addFormInputs_(formdata)
Adds the key value pairs from a map like data structure to a form
Arguments:
form : HTMLFormElement
The form to add to.
data : Object | goog.structs.Map | goog.Uri.QueryData
The data to add.
code »
goog.net.IframeIo.getForm_() !HTMLFormElement
Gets a static form, one for all instances of IframeIo since IE6 leaks form nodes that are created/removed from the document.
Returns: !HTMLFormElement  The static form.
code »
goog.net.IframeIo.getIframeByName(fname) HTMLIFrameElement
Find an iframe by name (assumes the context is goog.global since that is where IframeIo's iframes are kept).
Arguments:
fname : string
The name to find.
Returns: HTMLIFrameElement  The iframe element with that name.
code »
goog.net.IframeIo.getInstanceByName(fname) goog.net.IframeIo
Find an instance of the IframeIo object by name.
Arguments:
fname : string
The name to find.
Returns: goog.net.IframeIo  The instance of IframeIo.
code »
goog.net.IframeIo.getNextName_() string
No description.
Returns: string  The next iframe name.
code »
goog.net.IframeIo.handleIncrementalData(windata)
Handles incremental data and routes it to the correct iframeIo instance. The HTML page requested by the IframeIo instance should contain script blocks that call an externed reference to this method.
Arguments:
win : Window
The window object.
data : Object
The data object.
code »
goog.net.IframeIo.send(uriopt_callbackopt_methodopt_noCacheopt_data)
Static send that creates a short lived instance of IframeIo to send the request.
Arguments:
uri : goog.Uri | string
Uri of the request, it is up the caller to manage query string params.
opt_callback : Function=
Event handler for when request is completed.
opt_method : string=
Default is GET, POST uses a form to submit the request.
opt_noCache : boolean=
Append a timestamp to the request to avoid caching.
opt_data : Object | goog.structs.Map=
Map of key-value pairs that will be posted to the server via the iframe's form.
code »
goog.net.IframeIo.useIeReadyStateCodePath_() boolean
No description.
Returns: boolean  Whether we can use readyState to monitor iframe loading.
code »

Static Properties

goog.net.IframeIo.FRAME_NAME_PREFIX :
Prefix for frame names
Code »
goog.net.IframeIo.IFRAME_DISPOSE_DELAY_MS :
The number of milliseconds after a request is completed to dispose the iframes. This can be done lazily so we wait long enough for any processing that occurred as a result of the response to finish.
Code »
goog.net.IframeIo.INNER_FRAME_SUFFIX :
Suffix that is added to inner frames used for sending requests in non-IE browsers
Code »
goog.net.IframeIo.counter_ :
Counter used when creating iframes
Code »
goog.net.IframeIo.form_ :
Form element to post to.
Code »
goog.net.IframeIo.instances_ :
Object used as a map to lookup instances of IframeIo objects by name.
Code »
goog.net.IframeIo.superClass_ :
No description.
Code »

Package net

Package Reference