Revert of Enabling audio quality test on mac. (patchset #1 id:1 of https://codereview...
[chromium-blink-merge.git] / remoting / webapp / xhr_proxy.js
blobc2cadb560285e6e3368abb1b1d2654e414011bfd
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.
4 */
6 /**
7 * @fileoverview
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
21 'use strict';
23 /** @suppress {duplicate} */
24 var remoting = remoting || {};
26 /**
27 * @constructor
28 * @extends {XMLHttpRequest}
30 remoting.XMLHttpRequestProxy = function() {
31 /**
32 * @type {{headers: Object}}
34 this.sandbox_ipc = {
35 headers: {}
37 /**
38 * @type {number}
39 * @private
41 this.xhr_id_ = -1;
44 remoting.XMLHttpRequestProxy.prototype.open = function(
45 method, url, async, user, password) {
46 if (!async) {
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(
63 header, value) {
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;