wrapperxmlhttpfactory.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2010 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. * @fileoverview Implementation of XmlHttpFactory which allows construction from
  16. * simple factory methods.
  17. * @author dbk@google.com (David Barrett-Kahn)
  18. */
  19. goog.provide('goog.net.WrapperXmlHttpFactory');
  20. /** @suppress {extraRequire} Typedef. */
  21. goog.require('goog.net.XhrLike');
  22. goog.require('goog.net.XmlHttpFactory');
  23. /**
  24. * An xhr factory subclass which can be constructed using two factory methods.
  25. * This exists partly to allow the preservation of goog.net.XmlHttp.setFactory()
  26. * with an unchanged signature.
  27. * @param {function():!goog.net.XhrLike.OrNative} xhrFactory
  28. * A function which returns a new XHR object.
  29. * @param {function():!Object} optionsFactory A function which returns the
  30. * options associated with xhr objects from this factory.
  31. * @extends {goog.net.XmlHttpFactory}
  32. * @constructor
  33. * @final
  34. */
  35. goog.net.WrapperXmlHttpFactory = function(xhrFactory, optionsFactory) {
  36. goog.net.XmlHttpFactory.call(this);
  37. /**
  38. * XHR factory method.
  39. * @type {function() : !goog.net.XhrLike.OrNative}
  40. * @private
  41. */
  42. this.xhrFactory_ = xhrFactory;
  43. /**
  44. * Options factory method.
  45. * @type {function() : !Object}
  46. * @private
  47. */
  48. this.optionsFactory_ = optionsFactory;
  49. };
  50. goog.inherits(goog.net.WrapperXmlHttpFactory, goog.net.XmlHttpFactory);
  51. /** @override */
  52. goog.net.WrapperXmlHttpFactory.prototype.createInstance = function() {
  53. return this.xhrFactory_();
  54. };
  55. /** @override */
  56. goog.net.WrapperXmlHttpFactory.prototype.getOptions = function() {
  57. return this.optionsFactory_();
  58. };