blob: 8c72a2266e10339caca1a5d08ffa40568aa35d6f [file] [log] [blame] [edit]
// Copyright 2015 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// https://www.w3.org/TR/2014/WD-XMLHttpRequest-20140130/#xmlhttprequest
[
Constructor,
ConstructorCallWith=EnvironmentSettings,
] interface XMLHttpRequest : XMLHttpRequestEventTarget {
// event handler
attribute EventHandler onreadystatechange;
// states
const unsigned short UNSENT = 0;
const unsigned short OPENED = 1;
const unsigned short HEADERS_RECEIVED = 2;
const unsigned short LOADING = 3;
const unsigned short DONE = 4;
readonly attribute unsigned short readyState;
// request
[RaisesException] void open(DOMString method, DOMString url);
[RaisesException] void open(DOMString method, DOMString url,
boolean async,
optional DOMString? username,
optional DOMString? password);
[RaisesException] void setRequestHeader(DOMString header, DOMString value);
attribute unsigned long timeout;
[RaisesException=Setter] attribute boolean withCredentials;
readonly attribute XMLHttpRequestUpload upload;
// TODO: Upgrade to void send(optional (Document or BodyInit)? body = null);
// See https://xhr.spec.whatwg.org/#interface-xmlhttprequest.
[RaisesException] void send(
optional (DOMString or ArrayBufferView or ArrayBuffer)? requestBody);
void abort();
// FetchAPI: replacement for "send" when fetch functionality is needed.
[RaisesException] void fetch(
FetchUpdateCallback fetchCallback, FetchModeCallback modeCallback,
(DOMString or ArrayBufferView or ArrayBuffer)? requestBody);
// response
readonly attribute unsigned short status;
readonly attribute DOMString statusText;
DOMString? getResponseHeader(DOMString header);
DOMString getAllResponseHeaders();
[RaisesException] void overrideMimeType(DOMString mimeType);
[RaisesException=Setter] attribute DOMString responseType;
// TODO: Use a union type for all the possible response types.
[RaisesException] readonly attribute (DOMString or ArrayBuffer) response;
[RaisesException] readonly attribute DOMString responseText;
[RaisesException] readonly attribute Document? responseXML;
// Not part of the spec. Enable verbose XHR logging.
static attribute boolean verbose;
};
// TODO: The IDL defines EventHandler as a nullable callback function. Define it
// as a nullable EventListener for now until we can do some refactoring to
// accept both in the EventTarget implementation.
typedef EventListener? EventHandler;
// FetchAPI: custom callback to allow progressive updates.
callback FetchUpdateCallback = void(Uint8Array data);
// FetchAPI: custom callback to distinguish between mode.
callback FetchModeCallback = void(boolean isCorsMode);