Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / lib / transports / htmlfile.js
1 /**
2  * socket.io
3  * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
4  * MIT Licensed
5  */
6
7 (function (exports, io) {
8
9   /**
10    * Expose constructor.
11    */
12
13   exports.htmlfile = HTMLFile;
14
15   /**
16    * The HTMLFile transport creates a `forever iframe` based transport
17    * for Internet Explorer. Regular forever iframe implementations will 
18    * continuously trigger the browsers buzy indicators. If the forever iframe
19    * is created inside a `htmlfile` these indicators will not be trigged.
20    *
21    * @constructor
22    * @extends {io.Transport.XHR}
23    * @api public
24    */
25
26   function HTMLFile (socket) {
27     io.Transport.XHR.apply(this, arguments);
28   };
29
30   /**
31    * Inherits from XHR transport.
32    */
33
34   io.util.inherit(HTMLFile, io.Transport.XHR);
35
36   /**
37    * Transport name
38    *
39    * @api public
40    */
41
42   HTMLFile.prototype.name = 'htmlfile';
43
44   /**
45    * Creates a new ActiveX `htmlfile` with a forever loading iframe
46    * that can be used to listen to messages. Inside the generated
47    * `htmlfile` a reference will be made to the HTMLFile transport.
48    *
49    * @api private
50    */
51
52   HTMLFile.prototype.get = function () {
53     this.doc = new ActiveXObject('htmlfile');
54     this.doc.open();
55     this.doc.write('<html></html>');
56     this.doc.close();
57     this.doc.parentWindow.s = this;
58
59     var iframeC = this.doc.createElement('div');
60     iframeC.className = 'socketio';
61
62     this.doc.body.appendChild(iframeC);
63     this.iframe = this.doc.createElement('iframe');
64
65     iframeC.appendChild(this.iframe);
66
67     var self = this
68       , query = io.util.query(this.socket.options.query, 't='+ +new Date);
69
70     this.iframe.src = this.prepareUrl() + query;
71
72     io.util.on(window, 'unload', function () {
73       self.destroy();
74     });
75   };
76
77   /**
78    * The Socket.IO server will write script tags inside the forever
79    * iframe, this function will be used as callback for the incoming
80    * information.
81    *
82    * @param {String} data The message
83    * @param {document} doc Reference to the context
84    * @api private
85    */
86
87   HTMLFile.prototype._ = function (data, doc) {
88     // unescape all forward slashes. see GH-1251
89     data = data.replace(/\\\//g, '/');
90     this.onData(data);
91     try {
92       var script = doc.getElementsByTagName('script')[0];
93       script.parentNode.removeChild(script);
94     } catch (e) { }
95   };
96
97   /**
98    * Destroy the established connection, iframe and `htmlfile`.
99    * And calls the `CollectGarbage` function of Internet Explorer
100    * to release the memory.
101    *
102    * @api private
103    */
104
105   HTMLFile.prototype.destroy = function () {
106     if (this.iframe){
107       try {
108         this.iframe.src = 'about:blank';
109       } catch(e){}
110
111       this.doc = null;
112       this.iframe.parentNode.removeChild(this.iframe);
113       this.iframe = null;
114
115       CollectGarbage();
116     }
117   };
118
119   /**
120    * Disconnects the established connection.
121    *
122    * @returns {Transport} Chaining.
123    * @api public
124    */
125
126   HTMLFile.prototype.close = function () {
127     this.destroy();
128     return io.Transport.XHR.prototype.close.call(this);
129   };
130
131   /**
132    * Checks if the browser supports this transport. The browser
133    * must have an `ActiveXObject` implementation.
134    *
135    * @return {Boolean}
136    * @api public
137    */
138
139   HTMLFile.check = function (socket) {
140     if (typeof window != "undefined" && 'ActiveXObject' in window){
141       try {
142         var a = new ActiveXObject('htmlfile');
143         return a && io.Transport.XHR.check(socket);
144       } catch(e){}
145     }
146     return false;
147   };
148
149   /**
150    * Check if cross domain requests are supported.
151    *
152    * @returns {Boolean}
153    * @api public
154    */
155
156   HTMLFile.xdomainCheck = function () {
157     // we can probably do handling for sub-domains, we should
158     // test that it's cross domain but a subdomain here
159     return false;
160   };
161
162   /**
163    * Add the transport to your public io.transports array.
164    *
165    * @api private
166    */
167
168   io.transports.push('htmlfile');
169
170 })(
171     'undefined' != typeof io ? io.Transport : module.exports
172   , 'undefined' != typeof io ? io : module.parent.exports
173 );