1 /* Copyright 2013 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
8 * The sandbox isn't allowed to make XHRs, so they have to be proxied to the
9 * main process. The XMLHttpRequestProxy class is API-compatible with the
10 * XMLHttpRequest class, but forwards the requests to the main process where
11 * they can be serviced. The forwarding of XHRs and responses is handled by
12 * the WcsSandboxContent class; this class is just a thin wrapper to hook XHR
13 * creations by JS running in the sandbox.
15 * Because XMLHttpRequest is implemented natively, and because the intent is
16 * to replace its functionality entirely, prototype linking is not a suitable
17 * approach here, so much of the interface definition is duplicated from the
18 * w3c specification: http://www.w3.org/TR/XMLHttpRequest
23 /** @suppress {duplicate} */
24 var remoting = remoting || {};
28 * @extends {XMLHttpRequest}
30 remoting.XMLHttpRequestProxy = function() {
31 /** @type {{headers: Object}} */
35 /** @private {number} */
39 remoting.XMLHttpRequestProxy.prototype.open = function(
40 method, url, async, user, password) {
42 console.warn('Synchronous XHRs are not supported.');
44 this.sandboxIpc.method = method;
45 this.sandboxIpc.url = url.toString();
46 this.sandboxIpc.user = user;
47 this.sandboxIpc.password = password;
50 remoting.XMLHttpRequestProxy.prototype.send = function(data) {
51 if (remoting.sandboxContent) {
52 this.sandboxIpc.data = data;
53 this.xhrId_ = remoting.sandboxContent.sendXhr(this);
57 remoting.XMLHttpRequestProxy.prototype.setRequestHeader = function(
59 this.sandboxIpc.headers[header] = value;
62 remoting.XMLHttpRequestProxy.prototype.abort = function() {
63 if (this.xhrId_ != -1) {
64 remoting.sandboxContent.abortXhr(this.xhrId_);
68 remoting.XMLHttpRequestProxy.prototype.getResponseHeader = function(header) {
69 console.error('Sandbox: unproxied getResponseHeader(' + header + ') called.');
72 remoting.XMLHttpRequestProxy.prototype.getAllResponseHeaders = function() {
73 console.error('Sandbox: unproxied getAllResponseHeaders called.');
76 remoting.XMLHttpRequestProxy.prototype.overrideMimeType = function() {
77 console.error('Sandbox: unproxied overrideMimeType called.');
80 remoting.XMLHttpRequestProxy.prototype.UNSENT = 0;
81 remoting.XMLHttpRequestProxy.prototype.OPENED = 1;
82 remoting.XMLHttpRequestProxy.prototype.HEADERS_RECEIVED = 2;
83 remoting.XMLHttpRequestProxy.prototype.LOADING = 3;
84 remoting.XMLHttpRequestProxy.prototype.DONE = 4;