1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423 |
- goog.provide('goog.net.IframeIo');
- goog.provide('goog.net.IframeIo.IncrementalDataEvent');
- goog.require('goog.Timer');
- goog.require('goog.Uri');
- goog.require('goog.array');
- goog.require('goog.asserts');
- goog.require('goog.debug.HtmlFormatter');
- goog.require('goog.dom');
- goog.require('goog.dom.InputType');
- goog.require('goog.dom.TagName');
- goog.require('goog.dom.safe');
- goog.require('goog.events');
- goog.require('goog.events.Event');
- goog.require('goog.events.EventTarget');
- goog.require('goog.events.EventType');
- goog.require('goog.html.uncheckedconversions');
- goog.require('goog.json');
- goog.require('goog.log');
- goog.require('goog.log.Level');
- goog.require('goog.net.ErrorCode');
- goog.require('goog.net.EventType');
- goog.require('goog.reflect');
- goog.require('goog.string');
- goog.require('goog.string.Const');
- goog.require('goog.structs');
- goog.require('goog.userAgent');
- goog.net.IframeIo = function() {
- goog.net.IframeIo.base(this, 'constructor');
-
- this.name_ = goog.net.IframeIo.getNextName_();
-
- this.iframesForDisposal_ = [];
-
-
-
-
- goog.net.IframeIo.instances_[this.name_] = this;
- };
- goog.inherits(goog.net.IframeIo, goog.events.EventTarget);
- goog.net.IframeIo.instances_ = {};
- goog.net.IframeIo.FRAME_NAME_PREFIX = 'closure_frame';
- goog.net.IframeIo.INNER_FRAME_SUFFIX = '_inner';
- goog.net.IframeIo.IFRAME_DISPOSE_DELAY_MS = 2000;
- goog.net.IframeIo.counter_ = 0;
- goog.net.IframeIo.form_;
- goog.net.IframeIo.send = function(
- uri, opt_callback, opt_method, opt_noCache, opt_data) {
- var io = new goog.net.IframeIo();
- goog.events.listen(io, goog.net.EventType.READY, io.dispose, false, io);
- if (opt_callback) {
- goog.events.listen(io, goog.net.EventType.COMPLETE, opt_callback);
- }
- io.send(uri, opt_method, opt_noCache, opt_data);
- };
- goog.net.IframeIo.getIframeByName = function(fname) {
- return window.frames[fname];
- };
- goog.net.IframeIo.getInstanceByName = function(fname) {
- return goog.net.IframeIo.instances_[fname];
- };
- goog.net.IframeIo.handleIncrementalData = function(win, data) {
-
- var iframeName =
- goog.string.endsWith(win.name, goog.net.IframeIo.INNER_FRAME_SUFFIX) ?
- win.parent.name :
- win.name;
- var iframeIoName = iframeName.substring(0, iframeName.lastIndexOf('_'));
- var iframeIo = goog.net.IframeIo.getInstanceByName(iframeIoName);
- if (iframeIo && iframeName == iframeIo.iframeName_) {
- iframeIo.handleIncrementalData_(data);
- } else {
- var logger = goog.log.getLogger('goog.net.IframeIo');
- goog.log.info(logger, 'Incremental iframe data routed for unknown iframe');
- }
- };
- goog.net.IframeIo.getNextName_ = function() {
- return goog.net.IframeIo.FRAME_NAME_PREFIX + goog.net.IframeIo.counter_++;
- };
- goog.net.IframeIo.getForm_ = function() {
- if (!goog.net.IframeIo.form_) {
- goog.net.IframeIo.form_ = goog.dom.createDom(goog.dom.TagName.FORM);
- goog.net.IframeIo.form_.acceptCharset = 'utf-8';
-
- var s = goog.net.IframeIo.form_.style;
- s.position = 'absolute';
- s.visibility = 'hidden';
- s.top = s.left = '-10px';
- s.width = s.height = '10px';
- s.overflow = 'hidden';
- goog.dom.getDocument().body.appendChild(goog.net.IframeIo.form_);
- }
- return goog.net.IframeIo.form_;
- };
- goog.net.IframeIo.addFormInputs_ = function(form, data) {
- var helper = goog.dom.getDomHelper(form);
- goog.structs.forEach(data, function(value, key) {
- if (!goog.isArray(value)) {
- value = [value];
- }
- goog.array.forEach(value, function(value) {
- var inp = helper.createDom(
- goog.dom.TagName.INPUT,
- {'type': goog.dom.InputType.HIDDEN, 'name': key, 'value': value});
- form.appendChild(inp);
- });
- });
- };
- goog.net.IframeIo.useIeReadyStateCodePath_ = function() {
-
- return goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('11');
- };
- goog.net.IframeIo.prototype.logger_ = goog.log.getLogger('goog.net.IframeIo');
- goog.net.IframeIo.prototype.form_ = null;
- goog.net.IframeIo.prototype.iframe_ = null;
- goog.net.IframeIo.prototype.iframeName_ = null;
- goog.net.IframeIo.prototype.nextIframeId_ = 0;
- goog.net.IframeIo.prototype.active_ = false;
- goog.net.IframeIo.prototype.complete_ = false;
- goog.net.IframeIo.prototype.success_ = false;
- goog.net.IframeIo.prototype.lastUri_ = null;
- goog.net.IframeIo.prototype.lastContent_ = null;
- goog.net.IframeIo.prototype.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
- goog.net.IframeIo.prototype.firefoxSilentErrorTimeout_ = null;
- goog.net.IframeIo.prototype.iframeDisposalTimer_ = null;
- goog.net.IframeIo.prototype.errorHandled_;
- goog.net.IframeIo.prototype.ignoreResponse_ = false;
- goog.net.IframeIo.prototype.errorChecker_;
- goog.net.IframeIo.prototype.lastCustomError_;
- goog.net.IframeIo.prototype.lastContentHtml_;
- goog.net.IframeIo.prototype.send = function(
- uri, opt_method, opt_noCache, opt_data) {
- if (this.active_) {
- throw Error('[goog.net.IframeIo] Unable to send, already active.');
- }
- var uriObj = new goog.Uri(uri);
- this.lastUri_ = uriObj;
- var method = opt_method ? opt_method.toUpperCase() : 'GET';
- if (opt_noCache) {
- uriObj.makeUnique();
- }
- goog.log.info(
- this.logger_, 'Sending iframe request: ' + uriObj + ' [' + method + ']');
-
- this.form_ = goog.net.IframeIo.getForm_();
- if (method == 'GET') {
-
-
-
- goog.net.IframeIo.addFormInputs_(this.form_, uriObj.getQueryData());
- }
- if (opt_data) {
-
- goog.net.IframeIo.addFormInputs_(this.form_, opt_data);
- }
-
- this.form_.action = uriObj.toString();
- this.form_.method = method;
- this.sendFormInternal_();
- this.clearForm_();
- };
- goog.net.IframeIo.prototype.sendFromForm = function(
- form, opt_uri, opt_noCache) {
- if (this.active_) {
- throw Error('[goog.net.IframeIo] Unable to send, already active.');
- }
- var uri = new goog.Uri(opt_uri || form.action);
- if (opt_noCache) {
- uri.makeUnique();
- }
- goog.log.info(this.logger_, 'Sending iframe request from form: ' + uri);
- this.lastUri_ = uri;
- this.form_ = form;
- this.form_.action = uri.toString();
- this.sendFormInternal_();
- };
- goog.net.IframeIo.prototype.abort = function(opt_failureCode) {
- if (this.active_) {
- goog.log.info(this.logger_, 'Request aborted');
- var requestIframe = this.getRequestIframe();
- goog.asserts.assert(requestIframe);
- goog.events.removeAll(requestIframe);
- this.complete_ = false;
- this.active_ = false;
- this.success_ = false;
- this.lastErrorCode_ = opt_failureCode || goog.net.ErrorCode.ABORT;
- this.dispatchEvent(goog.net.EventType.ABORT);
- this.makeReady_();
- }
- };
- goog.net.IframeIo.prototype.disposeInternal = function() {
- goog.log.fine(this.logger_, 'Disposing iframeIo instance');
-
- if (this.active_) {
- goog.log.fine(this.logger_, 'Aborting active request');
- this.abort();
- }
-
- goog.net.IframeIo.superClass_.disposeInternal.call(this);
-
- if (this.iframe_) {
- this.scheduleIframeDisposal_();
- }
-
- this.disposeForm_();
-
- delete this.errorChecker_;
- this.form_ = null;
- this.lastCustomError_ = this.lastContent_ = this.lastContentHtml_ = null;
- this.lastUri_ = null;
- this.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
- delete goog.net.IframeIo.instances_[this.name_];
- };
- goog.net.IframeIo.prototype.isComplete = function() {
- return this.complete_;
- };
- goog.net.IframeIo.prototype.isSuccess = function() {
- return this.success_;
- };
- goog.net.IframeIo.prototype.isActive = function() {
- return this.active_;
- };
- goog.net.IframeIo.prototype.getResponseText = function() {
- return this.lastContent_;
- };
- goog.net.IframeIo.prototype.getResponseHtml = function() {
- return this.lastContentHtml_;
- };
- goog.net.IframeIo.prototype.getResponseJson = function() {
- return goog.json.parse(this.lastContent_);
- };
- goog.net.IframeIo.prototype.getResponseXml = function() {
- if (!this.iframe_) return null;
- return this.getContentDocument_();
- };
- goog.net.IframeIo.prototype.getLastUri = function() {
- return this.lastUri_;
- };
- goog.net.IframeIo.prototype.getLastErrorCode = function() {
- return this.lastErrorCode_;
- };
- goog.net.IframeIo.prototype.getLastError = function() {
- return goog.net.ErrorCode.getDebugMessage(this.lastErrorCode_);
- };
- goog.net.IframeIo.prototype.getLastCustomError = function() {
- return this.lastCustomError_;
- };
- goog.net.IframeIo.prototype.setErrorChecker = function(fn) {
- this.errorChecker_ = fn;
- };
- goog.net.IframeIo.prototype.getErrorChecker = function() {
- return this.errorChecker_;
- };
- goog.net.IframeIo.prototype.isIgnoringResponse = function() {
- return this.ignoreResponse_;
- };
- goog.net.IframeIo.prototype.setIgnoreResponse = function(ignore) {
- this.ignoreResponse_ = ignore;
- };
- goog.net.IframeIo.prototype.sendFormInternal_ = function() {
- this.active_ = true;
- this.complete_ = false;
- this.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
-
- this.createIframe_();
- if (goog.net.IframeIo.useIeReadyStateCodePath_()) {
-
-
-
-
- this.form_.target = this.iframeName_ || '';
- this.appendIframe_();
- if (!this.ignoreResponse_) {
- goog.events.listen(
- this.iframe_, goog.events.EventType.READYSTATECHANGE,
- this.onIeReadyStateChange_, false, this);
- }
- try {
- this.errorHandled_ = false;
- this.form_.submit();
- } catch (e) {
-
-
-
-
-
- if (!this.ignoreResponse_) {
- goog.events.unlisten(
- this.iframe_, goog.events.EventType.READYSTATECHANGE,
- this.onIeReadyStateChange_, false, this);
- }
- this.handleError_(goog.net.ErrorCode.ACCESS_DENIED);
- }
- } else {
-
-
- goog.log.fine(this.logger_, 'Setting up iframes and cloning form');
- this.appendIframe_();
- var innerFrameName =
- this.iframeName_ + goog.net.IframeIo.INNER_FRAME_SUFFIX;
-
- var doc = goog.dom.getFrameContentDocument(this.iframe_);
- var html;
- if (document.baseURI) {
-
- html = goog.net.IframeIo.createIframeHtmlWithBaseUri_(innerFrameName);
- } else {
- html = goog.net.IframeIo.createIframeHtml_(innerFrameName);
- }
- if (goog.userAgent.OPERA && !goog.userAgent.WEBKIT) {
-
-
- goog.dom.safe.setInnerHtml(doc.documentElement, html);
- } else {
- goog.dom.safe.documentWrite(doc, html);
- }
-
- if (!this.ignoreResponse_) {
- goog.events.listen(
- doc.getElementById(innerFrameName), goog.events.EventType.LOAD,
- this.onIframeLoaded_, false, this);
- }
-
- var textareas = goog.dom.getElementsByTagName(
- goog.dom.TagName.TEXTAREA, goog.asserts.assert(this.form_));
- for (var i = 0, n = textareas.length; i < n; i++) {
-
-
-
- var value = textareas[i].value;
- if (goog.dom.getRawTextContent(textareas[i]) != value) {
- goog.dom.setTextContent(textareas[i], value);
- textareas[i].value = value;
- }
- }
-
- var clone = doc.importNode(this.form_, true);
- clone.target = innerFrameName;
-
- clone.action = this.form_.action;
- doc.body.appendChild(clone);
-
- var selects = goog.dom.getElementsByTagName(
- goog.dom.TagName.SELECT, goog.asserts.assert(this.form_));
- var clones = goog.dom.getElementsByTagName(
- goog.dom.TagName.SELECT, (clone));
- for (var i = 0, n = selects.length; i < n; i++) {
- var selectsOptions =
- goog.dom.getElementsByTagName(goog.dom.TagName.OPTION, selects[i]);
- var clonesOptions =
- goog.dom.getElementsByTagName(goog.dom.TagName.OPTION, clones[i]);
- for (var j = 0, m = selectsOptions.length; j < m; j++) {
- clonesOptions[j].selected = selectsOptions[j].selected;
- }
- }
-
-
-
-
- var inputs = goog.dom.getElementsByTagName(
- goog.dom.TagName.INPUT, goog.asserts.assert(this.form_));
- var inputClones = goog.dom.getElementsByTagName(
- goog.dom.TagName.INPUT, (clone));
- for (var i = 0, n = inputs.length; i < n; i++) {
- if (inputs[i].type == goog.dom.InputType.FILE) {
- if (inputs[i].value != inputClones[i].value) {
- goog.log.fine(
- this.logger_, 'File input value not cloned properly. Will ' +
- 'submit using original form.');
- this.form_.target = innerFrameName;
- clone = this.form_;
- break;
- }
- }
- }
- goog.log.fine(this.logger_, 'Submitting form');
- try {
- this.errorHandled_ = false;
- clone.submit();
- doc.close();
- if (goog.userAgent.GECKO) {
-
-
- this.firefoxSilentErrorTimeout_ =
- goog.Timer.callOnce(this.testForFirefoxSilentError_, 250, this);
- }
- } catch (e) {
-
-
-
-
- goog.log.error(
- this.logger_,
- 'Error when submitting form: ' +
- goog.debug.HtmlFormatter.exposeException(e));
- if (!this.ignoreResponse_) {
- goog.events.unlisten(
- doc.getElementById(innerFrameName), goog.events.EventType.LOAD,
- this.onIframeLoaded_, false, this);
- }
- doc.close();
- this.handleError_(goog.net.ErrorCode.FILE_NOT_FOUND);
- }
- }
- };
- goog.net.IframeIo.createIframeHtml_ = function(innerFrameName) {
- var innerFrameNameEscaped = goog.string.htmlEscape(innerFrameName);
- return goog.html.uncheckedconversions
- .safeHtmlFromStringKnownToSatisfyTypeContract(
- goog.string.Const.from(
- 'Short HTML snippet, input escaped, for performance'),
- '<body><iframe id="' + innerFrameNameEscaped + '" name="' +
- innerFrameNameEscaped + '"></iframe>');
- };
- goog.net.IframeIo.createIframeHtmlWithBaseUri_ = function(innerFrameName) {
- var innerFrameNameEscaped = goog.string.htmlEscape(innerFrameName);
- return goog.html.uncheckedconversions
- .safeHtmlFromStringKnownToSatisfyTypeContract(
- goog.string.Const.from(
- 'Short HTML snippet, input escaped, safe URL, for performance'),
- '<head><base href="' +
- goog.string.htmlEscape( (document.baseURI)) +
- '"></head>' +
- '<body><iframe id="' + innerFrameNameEscaped + '" name="' +
- innerFrameNameEscaped + '"></iframe>');
- };
- goog.net.IframeIo.prototype.onIeReadyStateChange_ = function(e) {
- if (this.iframe_.readyState == 'complete') {
- goog.events.unlisten(
- this.iframe_, goog.events.EventType.READYSTATECHANGE,
- this.onIeReadyStateChange_, false, this);
- var doc;
- try {
- doc = goog.dom.getFrameContentDocument(this.iframe_);
-
- if (goog.userAgent.IE && doc.location == 'about:blank' &&
- !navigator.onLine) {
- this.handleError_(goog.net.ErrorCode.OFFLINE);
- return;
- }
- } catch (ex) {
- this.handleError_(goog.net.ErrorCode.ACCESS_DENIED);
- return;
- }
- this.handleLoad_( (doc));
- }
- };
- goog.net.IframeIo.prototype.onIframeLoaded_ = function(e) {
-
-
- if (goog.userAgent.OPERA && !goog.userAgent.WEBKIT &&
- this.getContentDocument_().location == 'about:blank') {
- return;
- }
- goog.events.unlisten(
- this.getRequestIframe(), goog.events.EventType.LOAD, this.onIframeLoaded_,
- false, this);
- try {
- this.handleLoad_(this.getContentDocument_());
- } catch (ex) {
- this.handleError_(goog.net.ErrorCode.ACCESS_DENIED);
- }
- };
- goog.net.IframeIo.prototype.handleLoad_ = function(contentDocument) {
- goog.log.fine(this.logger_, 'Iframe loaded');
- this.complete_ = true;
- this.active_ = false;
- var errorCode;
-
-
-
- try {
- var body = contentDocument.body;
- this.lastContent_ = body.textContent || body.innerText;
- this.lastContentHtml_ = body.innerHTML;
- } catch (ex) {
- errorCode = goog.net.ErrorCode.ACCESS_DENIED;
- }
-
-
-
- var customError;
- if (!errorCode && typeof this.errorChecker_ == 'function') {
- customError = this.errorChecker_(contentDocument);
- if (customError) {
- errorCode = goog.net.ErrorCode.CUSTOM_ERROR;
- }
- }
- goog.log.log(
- this.logger_, goog.log.Level.FINER, 'Last content: ' + this.lastContent_);
- goog.log.log(
- this.logger_, goog.log.Level.FINER, 'Last uri: ' + this.lastUri_);
- if (errorCode) {
- goog.log.fine(this.logger_, 'Load event occurred but failed');
- this.handleError_(errorCode, customError);
- } else {
- goog.log.fine(this.logger_, 'Load succeeded');
- this.success_ = true;
- this.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
- this.dispatchEvent(goog.net.EventType.COMPLETE);
- this.dispatchEvent(goog.net.EventType.SUCCESS);
- this.makeReady_();
- }
- };
- goog.net.IframeIo.prototype.handleError_ = function(
- errorCode, opt_customError) {
- if (!this.errorHandled_) {
- this.success_ = false;
- this.active_ = false;
- this.complete_ = true;
- this.lastErrorCode_ = errorCode;
- if (errorCode == goog.net.ErrorCode.CUSTOM_ERROR) {
- goog.asserts.assert(goog.isDef(opt_customError));
- this.lastCustomError_ = opt_customError;
- }
- this.dispatchEvent(goog.net.EventType.COMPLETE);
- this.dispatchEvent(goog.net.EventType.ERROR);
- this.makeReady_();
- this.errorHandled_ = true;
- }
- };
- goog.net.IframeIo.prototype.handleIncrementalData_ = function(data) {
- this.dispatchEvent(new goog.net.IframeIo.IncrementalDataEvent(data));
- };
- goog.net.IframeIo.prototype.makeReady_ = function() {
- goog.log.info(this.logger_, 'Ready for new requests');
- this.scheduleIframeDisposal_();
- this.disposeForm_();
- this.dispatchEvent(goog.net.EventType.READY);
- };
- goog.net.IframeIo.prototype.createIframe_ = function() {
- goog.log.fine(this.logger_, 'Creating iframe');
- this.iframeName_ = this.name_ + '_' + (this.nextIframeId_++).toString(36);
- var dom = goog.dom.getDomHelper(this.form_);
- this.iframe_ = dom.createDom(
- goog.dom.TagName.IFRAME,
- {'name': this.iframeName_, 'id': this.iframeName_});
-
-
- if (goog.userAgent.IE && Number(goog.userAgent.VERSION) < 7) {
- this.iframe_.src = 'javascript:""';
- }
- var s = this.iframe_.style;
- s.visibility = 'hidden';
- s.width = s.height = '10px';
-
-
- s.display = 'none';
-
-
- if (!goog.userAgent.WEBKIT) {
- s.position = 'absolute';
- s.top = s.left = '-10px';
- } else {
- s.marginTop = s.marginLeft = '-10px';
- }
- };
- goog.net.IframeIo.prototype.appendIframe_ = function() {
- goog.dom.getDomHelper(this.form_)
- .getDocument()
- .body.appendChild(this.iframe_);
- };
- goog.net.IframeIo.prototype.scheduleIframeDisposal_ = function() {
- var iframe = this.iframe_;
-
-
- if (iframe) {
-
-
-
- iframe.onreadystatechange = null;
- iframe.onload = null;
- iframe.onerror = null;
- this.iframesForDisposal_.push(iframe);
- }
- if (this.iframeDisposalTimer_) {
- goog.Timer.clear(this.iframeDisposalTimer_);
- this.iframeDisposalTimer_ = null;
- }
- if (goog.userAgent.GECKO ||
- (goog.userAgent.OPERA && !goog.userAgent.WEBKIT)) {
-
-
-
-
- this.iframeDisposalTimer_ = goog.Timer.callOnce(
- this.disposeIframes_, goog.net.IframeIo.IFRAME_DISPOSE_DELAY_MS, this);
- } else {
-
- this.disposeIframes_();
- }
-
- this.iframe_ = null;
- this.iframeName_ = null;
- };
- goog.net.IframeIo.prototype.disposeIframes_ = function() {
- if (this.iframeDisposalTimer_) {
-
- goog.Timer.clear(this.iframeDisposalTimer_);
- this.iframeDisposalTimer_ = null;
- }
- while (this.iframesForDisposal_.length != 0) {
- var iframe = this.iframesForDisposal_.pop();
- goog.log.info(this.logger_, 'Disposing iframe');
- goog.dom.removeNode(iframe);
- }
- };
- goog.net.IframeIo.prototype.clearForm_ = function() {
- if (this.form_ && this.form_ == goog.net.IframeIo.form_) {
- goog.dom.removeChildren(this.form_);
- }
- };
- goog.net.IframeIo.prototype.disposeForm_ = function() {
- this.clearForm_();
- this.form_ = null;
- };
- goog.net.IframeIo.prototype.getContentDocument_ = function() {
- if (this.iframe_) {
- return (
- goog.dom.getFrameContentDocument(this.getRequestIframe()));
- }
- return null;
- };
- goog.net.IframeIo.prototype.getRequestIframe = function() {
- if (this.iframe_) {
- return (
- goog.net.IframeIo.useIeReadyStateCodePath_() ?
- this.iframe_ :
- goog.dom.getFrameContentDocument(this.iframe_)
- .getElementById(
- this.iframeName_ + goog.net.IframeIo.INNER_FRAME_SUFFIX));
- }
- return null;
- };
- goog.net.IframeIo.prototype.testForFirefoxSilentError_ = function() {
- if (this.active_) {
- var doc = this.getContentDocument_();
-
-
-
- if (doc && !goog.reflect.canAccessProperty(doc, 'documentUri')) {
- if (!this.ignoreResponse_) {
- goog.events.unlisten(
- this.getRequestIframe(), goog.events.EventType.LOAD,
- this.onIframeLoaded_, false, this);
- }
- if (navigator.onLine) {
- goog.log.warning(this.logger_, 'Silent Firefox error detected');
- this.handleError_(goog.net.ErrorCode.FF_SILENT_ERROR);
- } else {
- goog.log.warning(
- this.logger_, 'Firefox is offline so report offline error ' +
- 'instead of silent error');
- this.handleError_(goog.net.ErrorCode.OFFLINE);
- }
- return;
- }
- this.firefoxSilentErrorTimeout_ =
- goog.Timer.callOnce(this.testForFirefoxSilentError_, 250, this);
- }
- };
- goog.net.IframeIo.IncrementalDataEvent = function(data) {
- goog.events.Event.call(this, goog.net.EventType.INCREMENTAL_DATA);
-
- this.data = data;
- };
- goog.inherits(goog.net.IframeIo.IncrementalDataEvent, goog.events.Event);
|