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