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() {
32 * @type {{headers: Object}}
44 remoting
.XMLHttpRequestProxy
.prototype.open = function(
45 method
, url
, async
, user
, password
) {
47 console
.warn('Synchronous XHRs are not supported.');
49 this.sandbox_ipc
.method
= method
;
50 this.sandbox_ipc
.url
= url
.toString();
51 this.sandbox_ipc
.user
= user
;
52 this.sandbox_ipc
.password
= password
;
55 remoting
.XMLHttpRequestProxy
.prototype.send = function(data
) {
56 if (remoting
.sandboxContent
) {
57 this.sandbox_ipc
.data
= data
;
58 this.xhr_id_
= remoting
.sandboxContent
.sendXhr(this);
62 remoting
.XMLHttpRequestProxy
.prototype.setRequestHeader = function(
64 this.sandbox_ipc
.headers
[header
] = value
;
67 remoting
.XMLHttpRequestProxy
.prototype.abort = function() {
68 if (this.xhr_id_
!= -1) {
69 remoting
.sandboxContent
.abortXhr(this.xhr_id_
);
73 remoting
.XMLHttpRequestProxy
.prototype.getResponseHeader = function(header
) {
74 console
.error('Sandbox: unproxied getResponseHeader(' + header
+ ') called.');
77 remoting
.XMLHttpRequestProxy
.prototype.getAllResponseHeaders = function() {
78 console
.error('Sandbox: unproxied getAllResponseHeaders called.');
81 remoting
.XMLHttpRequestProxy
.prototype.overrideMimeType = function() {
82 console
.error('Sandbox: unproxied overrideMimeType called.');
85 remoting
.XMLHttpRequestProxy
.prototype.UNSENT
= 0;
86 remoting
.XMLHttpRequestProxy
.prototype.OPENED
= 1;
87 remoting
.XMLHttpRequestProxy
.prototype.HEADERS_RECEIVED
= 2;
88 remoting
.XMLHttpRequestProxy
.prototype.LOADING
= 3;
89 remoting
.XMLHttpRequestProxy
.prototype.DONE
= 4;