2013-01-18 09:21:43 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-04-20 07:36:50 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
#ifndef mozilla_dom_XMLHttpRequestMainThread_h
|
|
|
|
#define mozilla_dom_XMLHttpRequestMainThread_h
|
2006-04-20 07:36:50 +04:00
|
|
|
|
2016-07-08 19:46:12 +03:00
|
|
|
#include <bitset>
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2006-04-20 07:36:50 +04:00
|
|
|
#include "nsIXMLHttpRequest.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
2006-04-20 07:36:51 +04:00
|
|
|
#include "nsIURI.h"
|
2006-04-20 07:37:18 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2006-04-20 07:36:50 +04:00
|
|
|
#include "nsIDocument.h"
|
2006-04-20 07:37:08 +04:00
|
|
|
#include "nsIStreamListener.h"
|
2006-04-20 07:36:54 +04:00
|
|
|
#include "nsWeakReference.h"
|
2006-04-20 07:39:29 +04:00
|
|
|
#include "nsIChannelEventSink.h"
|
2010-08-05 06:15:55 +04:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2006-04-20 07:38:01 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2006-04-20 07:38:12 +04:00
|
|
|
#include "nsIHttpHeaderVisitor.h"
|
2006-04-20 07:39:18 +04:00
|
|
|
#include "nsIProgressEventSink.h"
|
2006-05-26 05:00:21 +04:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsTArray.h"
|
2008-10-20 01:26:37 +04:00
|
|
|
#include "nsITimer.h"
|
2012-03-31 08:42:20 +04:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2013-01-18 09:21:43 +04:00
|
|
|
#include "nsISizeOfEventTarget.h"
|
2014-11-02 23:01:55 +03:00
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsIInputStream.h"
|
2012-08-04 21:05:15 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2016-06-09 09:11:00 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2018-01-23 18:38:54 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2016-06-09 09:11:00 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2016-09-29 08:12:56 +03:00
|
|
|
#include "mozilla/dom/MutableBlobStorage.h"
|
2017-01-24 14:13:31 +03:00
|
|
|
#include "mozilla/dom/BodyExtractor.h"
|
2018-01-23 18:38:54 +03:00
|
|
|
#include "mozilla/dom/ClientInfo.h"
|
2012-08-04 21:05:15 +04:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2017-01-24 14:14:00 +03:00
|
|
|
#include "mozilla/dom/File.h"
|
|
|
|
#include "mozilla/dom/FormData.h"
|
2018-01-23 18:38:54 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerDescriptor.h"
|
2017-01-24 14:14:00 +03:00
|
|
|
#include "mozilla/dom/URLSearchParams.h"
|
2016-06-27 20:13:41 +03:00
|
|
|
#include "mozilla/dom/XMLHttpRequest.h"
|
2012-08-04 11:44:00 +04:00
|
|
|
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
2016-06-27 20:13:41 +03:00
|
|
|
#include "mozilla/dom/XMLHttpRequestEventTarget.h"
|
2016-09-12 10:06:06 +03:00
|
|
|
#include "mozilla/dom/XMLHttpRequestString.h"
|
2017-04-27 13:27:03 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
2012-08-04 21:05:15 +04:00
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
#ifdef Status
|
|
|
|
/* Xlib headers insist on this for some reason... Nuke it because
|
|
|
|
it'll override our member name */
|
|
|
|
#undef Status
|
|
|
|
#endif
|
|
|
|
|
2013-08-22 10:29:30 +04:00
|
|
|
class nsIJARChannel;
|
|
|
|
class nsILoadGroup;
|
2013-09-06 21:50:24 +04:00
|
|
|
class nsIJSID;
|
2006-04-20 07:36:50 +04:00
|
|
|
|
2013-08-28 03:55:31 +04:00
|
|
|
namespace mozilla {
|
2014-06-26 20:47:44 +04:00
|
|
|
namespace dom {
|
2016-06-27 20:13:41 +03:00
|
|
|
|
2016-09-29 08:12:37 +03:00
|
|
|
class BlobSet;
|
2017-01-19 06:20:15 +03:00
|
|
|
class DOMString;
|
2016-06-27 20:13:41 +03:00
|
|
|
class XMLHttpRequestUpload;
|
2016-07-06 07:06:25 +03:00
|
|
|
struct OriginAttributesDictionary;
|
2014-06-26 20:47:44 +04:00
|
|
|
|
2013-08-28 03:55:31 +04:00
|
|
|
// A helper for building up an ArrayBuffer object's data
|
|
|
|
// before creating the ArrayBuffer itself. Will do doubling
|
|
|
|
// based reallocation, up to an optional maximum growth given.
|
|
|
|
//
|
|
|
|
// When all the data has been appended, call getArrayBuffer,
|
|
|
|
// passing in the JSContext* for which the ArrayBuffer object
|
|
|
|
// is to be created. This also implicitly resets the builder,
|
|
|
|
// or it can be reset explicitly at any point by calling reset().
|
|
|
|
class ArrayBufferBuilder
|
|
|
|
{
|
|
|
|
uint8_t* mDataPtr;
|
|
|
|
uint32_t mCapacity;
|
|
|
|
uint32_t mLength;
|
2014-05-16 09:34:43 +04:00
|
|
|
void* mMapPtr;
|
2013-08-28 03:55:31 +04:00
|
|
|
public:
|
|
|
|
ArrayBufferBuilder();
|
|
|
|
~ArrayBufferBuilder();
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
// Will truncate if aNewCap is < length().
|
|
|
|
bool setCapacity(uint32_t aNewCap);
|
|
|
|
|
|
|
|
// Append aDataLen bytes from data to the current buffer. If we
|
|
|
|
// need to grow the buffer, grow by doubling the size up to a
|
|
|
|
// maximum of aMaxGrowth (if given). If aDataLen is greater than
|
|
|
|
// what the new capacity would end up as, then grow by aDataLen.
|
|
|
|
//
|
|
|
|
// The data parameter must not overlap with anything beyond the
|
|
|
|
// builder's current valid contents [0..length)
|
|
|
|
bool append(const uint8_t* aNewData, uint32_t aDataLen,
|
|
|
|
uint32_t aMaxGrowth = 0);
|
|
|
|
|
|
|
|
uint32_t length() { return mLength; }
|
|
|
|
uint32_t capacity() { return mCapacity; }
|
|
|
|
|
|
|
|
JSObject* getArrayBuffer(JSContext* aCx);
|
|
|
|
|
2014-05-16 09:34:43 +04:00
|
|
|
// Memory mapping to starting position of file(aFile) in the zip
|
|
|
|
// package(aJarFile).
|
|
|
|
//
|
|
|
|
// The file in the zip package has to be uncompressed and the starting
|
|
|
|
// position of the file must be aligned according to array buffer settings
|
|
|
|
// in JS engine.
|
|
|
|
nsresult mapToFileInPackage(const nsCString& aFile, nsIFile* aJarFile);
|
|
|
|
|
2013-08-29 02:57:10 +04:00
|
|
|
protected:
|
2013-08-28 03:55:31 +04:00
|
|
|
static bool areOverlappingRegions(const uint8_t* aStart1, uint32_t aLength1,
|
|
|
|
const uint8_t* aStart2, uint32_t aLength2);
|
|
|
|
};
|
|
|
|
|
2012-09-07 18:51:35 +04:00
|
|
|
class nsXMLHttpRequestXPCOMifier;
|
|
|
|
|
2016-08-19 03:15:37 +03:00
|
|
|
class RequestHeaders
|
|
|
|
{
|
|
|
|
struct RequestHeader
|
|
|
|
{
|
|
|
|
nsCString mName;
|
|
|
|
nsCString mValue;
|
|
|
|
};
|
|
|
|
nsTArray<RequestHeader> mHeaders;
|
|
|
|
RequestHeader* Find(const nsACString& aName);
|
|
|
|
|
|
|
|
public:
|
|
|
|
class CharsetIterator
|
|
|
|
{
|
|
|
|
bool mValid;
|
|
|
|
int32_t mCurPos, mCurLen, mCutoff;
|
|
|
|
nsACString& mSource;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit CharsetIterator(nsACString& aSource);
|
|
|
|
bool Equals(const nsACString& aOther, const nsCStringComparator& aCmp) const;
|
|
|
|
void Replace(const nsACString& aReplacement);
|
|
|
|
bool Next();
|
|
|
|
};
|
|
|
|
|
|
|
|
bool Has(const char* aName);
|
|
|
|
bool Has(const nsACString& aName);
|
|
|
|
void Get(const char* aName, nsACString& aValue);
|
|
|
|
void Get(const nsACString& aName, nsACString& aValue);
|
|
|
|
void Set(const char* aName, const nsACString& aValue);
|
|
|
|
void Set(const nsACString& aName, const nsACString& aValue);
|
|
|
|
void MergeOrSet(const char* aName, const nsACString& aValue);
|
|
|
|
void MergeOrSet(const nsACString& aName, const nsACString& aValue);
|
|
|
|
void Clear();
|
|
|
|
void ApplyToChannel(nsIHttpChannel* aChannel) const;
|
|
|
|
void GetCORSUnsafeHeaders(nsTArray<nsCString>& aArray) const;
|
|
|
|
};
|
|
|
|
|
2012-09-07 18:51:35 +04:00
|
|
|
// Make sure that any non-DOM interfaces added here are also added to
|
|
|
|
// nsXMLHttpRequestXPCOMifier.
|
2016-06-27 20:13:41 +03:00
|
|
|
class XMLHttpRequestMainThread final : public XMLHttpRequest,
|
|
|
|
public nsIXMLHttpRequest,
|
|
|
|
public nsIStreamListener,
|
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIProgressEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsITimerCallback,
|
2016-09-29 08:12:56 +03:00
|
|
|
public nsISizeOfEventTarget,
|
2016-11-04 23:36:06 +03:00
|
|
|
public nsINamed,
|
2016-09-29 08:12:56 +03:00
|
|
|
public MutableBlobStorageCallback
|
2006-04-20 07:36:50 +04:00
|
|
|
{
|
2011-11-16 11:38:51 +04:00
|
|
|
friend class nsXHRParseEndListener;
|
2012-09-07 18:51:35 +04:00
|
|
|
friend class nsXMLHttpRequestXPCOMifier;
|
|
|
|
|
2006-04-20 07:36:50 +04:00
|
|
|
public:
|
2016-07-08 19:44:33 +03:00
|
|
|
enum class ProgressEventType : uint8_t {
|
|
|
|
loadstart,
|
|
|
|
progress,
|
|
|
|
error,
|
|
|
|
abort,
|
|
|
|
timeout,
|
|
|
|
load,
|
|
|
|
loadend,
|
|
|
|
ENUM_MAX
|
|
|
|
};
|
|
|
|
|
2017-05-24 15:44:38 +03:00
|
|
|
enum class ErrorType : uint16_t {
|
|
|
|
eOK,
|
|
|
|
eRequest,
|
|
|
|
eUnreachable,
|
|
|
|
eChannelOpen,
|
|
|
|
eRedirect,
|
2017-09-25 19:58:23 +03:00
|
|
|
eTerminated,
|
2017-05-24 15:44:38 +03:00
|
|
|
ENUM_MAX
|
|
|
|
};
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
XMLHttpRequestMainThread();
|
2012-09-07 19:07:12 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void Construct(nsIPrincipal* aPrincipal,
|
2013-04-04 13:30:36 +04:00
|
|
|
nsIGlobalObject* aGlobalObject,
|
2015-01-08 19:21:52 +03:00
|
|
|
nsIURI* aBaseURI = nullptr,
|
2018-01-24 21:47:48 +03:00
|
|
|
nsILoadGroup* aLoadGroup = nullptr)
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
Bug 1389300 - Inherit style backend into NS_NewDOMDocument. r=smaug,r=heycam
Our current machinery for enabling stylo requires a docshell - if there isn't
one, we default to the Gecko style system.
When getComputedStyle operates on an element without a presshell, it uses the
caller's presshell instead. If the element has previously been styled with
one style system (but no longer has a presshell), and the caller uses a
different style backend, using the caller's style system can cause crashes when
we pull bits of cached data off the DOM (like cached style attributes).
So we want to throw when window.getComputedStyle(element) is called for a
(window, element) pair with different style backends (which is what the next
patch in this bug does).
However, that causes a few failures where stylo-backed documents try to do
getComputedStyle on an XHR document (which, without a docshell, will use the
gecko style system).
So this patch does some work to propagate the creator's style backend into
various docshell-less documents. This should allow both chrome (which uses gecko)
and content (which uses stylo) to use getComputedStyle on the response document
for XHRs they create.
Note that the second patch in this bug will make
chromeWin.getComputedStyle(contentObj) throw. If we discover code that does
that, we can just make it invoke the content's getComputedStyle method over Xrays.
MozReview-Commit-ID: 5OsmHJKq5Ui
2017-08-15 05:50:28 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobalObject);
|
|
|
|
if (win) {
|
|
|
|
if (win->GetExtantDoc()) {
|
|
|
|
mStyleBackend = win->GetExtantDoc()->GetStyleBackendType();
|
|
|
|
}
|
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
mPrincipal = aPrincipal;
|
2013-04-04 13:30:36 +04:00
|
|
|
BindToOwner(aGlobalObject);
|
2012-03-31 08:42:20 +04:00
|
|
|
mBaseURI = aBaseURI;
|
2015-01-08 19:21:52 +03:00
|
|
|
mLoadGroup = aLoadGroup;
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 11:21:55 +04:00
|
|
|
void InitParameters(bool aAnon, bool aSystem);
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2012-09-17 04:20:16 +04:00
|
|
|
void SetParameters(bool aAnon, bool aSystem)
|
|
|
|
{
|
2013-10-16 21:20:51 +04:00
|
|
|
mIsAnon = aAnon || aSystem;
|
2012-09-17 04:20:16 +04:00
|
|
|
mIsSystem = aSystem;
|
|
|
|
}
|
|
|
|
|
2018-01-23 18:38:54 +03:00
|
|
|
void SetClientInfoAndController(const ClientInfo& aClientInfo,
|
|
|
|
const Maybe<ServiceWorkerDescriptor>& aController);
|
|
|
|
|
2008-08-14 15:07:46 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2006-04-20 07:36:50 +04:00
|
|
|
|
2006-04-20 07:39:09 +04:00
|
|
|
// nsIXMLHttpRequest
|
2006-04-20 07:36:50 +04:00
|
|
|
NS_DECL_NSIXMLHTTPREQUEST
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(XMLHttpRequestEventTarget::)
|
2008-08-14 15:04:43 +04:00
|
|
|
|
2006-04-20 07:37:13 +04:00
|
|
|
// nsIStreamListener
|
2006-04-20 07:37:08 +04:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
|
2006-04-20 07:37:13 +04:00
|
|
|
// nsIRequestObserver
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
|
2006-04-20 07:39:29 +04:00
|
|
|
// nsIChannelEventSink
|
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2006-04-20 07:38:01 +04:00
|
|
|
|
2006-04-20 07:39:18 +04:00
|
|
|
// nsIProgressEventSink
|
|
|
|
NS_DECL_NSIPROGRESSEVENTSINK
|
|
|
|
|
2006-04-20 07:38:01 +04:00
|
|
|
// nsIInterfaceRequestor
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2006-05-26 05:00:21 +04:00
|
|
|
|
2008-10-20 01:26:37 +04:00
|
|
|
// nsITimerCallback
|
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
|
2016-11-04 23:36:06 +03:00
|
|
|
// nsINamed
|
|
|
|
NS_DECL_NSINAMED
|
|
|
|
|
2013-01-18 09:21:43 +04:00
|
|
|
// nsISizeOfEventTarget
|
|
|
|
virtual size_t
|
2016-06-27 20:13:41 +03:00
|
|
|
SizeOfEventTargetIncludingThis(MallocSizeOf aMallocSizeOf) const override;
|
2013-01-18 09:21:43 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(XMLHttpRequestEventTarget)
|
2008-08-14 15:04:43 +04:00
|
|
|
|
2012-03-26 19:38:06 +04:00
|
|
|
// states
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual uint16_t ReadyState() const override;
|
2012-03-26 19:38:06 +04:00
|
|
|
|
|
|
|
// request
|
2016-08-19 03:16:00 +03:00
|
|
|
nsresult CreateChannel();
|
2017-10-19 12:39:30 +03:00
|
|
|
nsresult InitiateFetch(already_AddRefed<nsIInputStream> aUploadStream,
|
2016-08-19 03:16:00 +03:00
|
|
|
int64_t aUploadLength,
|
|
|
|
nsACString& aUploadContentType);
|
2016-07-20 20:02:36 +03:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
Open(const nsACString& aMethod, const nsAString& aUrl,
|
2016-07-20 20:02:36 +03:00
|
|
|
ErrorResult& aRv) override;
|
2016-06-27 20:13:41 +03:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
|
2016-09-12 16:48:30 +03:00
|
|
|
const nsAString& aUsername, const nsAString& aPassword,
|
2016-07-20 20:02:36 +03:00
|
|
|
ErrorResult& aRv) override;
|
2016-06-27 20:13:41 +03:00
|
|
|
|
2016-09-12 16:48:30 +03:00
|
|
|
nsresult
|
|
|
|
Open(const nsACString& aMethod,
|
|
|
|
const nsACString& aUrl,
|
2016-09-14 21:50:58 +03:00
|
|
|
bool aAsync,
|
|
|
|
const nsAString& aUsername,
|
|
|
|
const nsAString& aPassword);
|
2016-09-12 16:48:30 +03:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
2016-08-02 19:50:10 +03:00
|
|
|
SetRequestHeader(const nsACString& aName, const nsACString& aValue,
|
2016-06-27 20:13:41 +03:00
|
|
|
ErrorResult& aRv) override
|
2012-03-26 19:38:06 +04:00
|
|
|
{
|
2016-08-02 19:50:10 +03:00
|
|
|
aRv = SetRequestHeader(aName, aValue);
|
2012-03-26 19:38:06 +04:00
|
|
|
}
|
2016-06-27 20:13:41 +03:00
|
|
|
|
|
|
|
virtual uint32_t
|
|
|
|
Timeout() const override
|
2012-03-26 19:38:06 +04:00
|
|
|
{
|
|
|
|
return mTimeoutMilliseconds;
|
|
|
|
}
|
2016-06-27 20:13:41 +03:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
SetTimeout(uint32_t aTimeout, ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual bool WithCredentials() const override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
SetWithCredentials(bool aWithCredentials, ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual XMLHttpRequestUpload*
|
|
|
|
GetUpload(ErrorResult& aRv) override;
|
2012-03-26 19:38:06 +04:00
|
|
|
|
|
|
|
private:
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual ~XMLHttpRequestMainThread();
|
2014-07-09 01:23:16 +04:00
|
|
|
|
2017-09-29 18:36:55 +03:00
|
|
|
nsresult MaybeSilentSendFailure(nsresult aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
nsresult SendInternal(const BodyExtractorBase* aBody);
|
2012-03-26 19:38:06 +04:00
|
|
|
|
2016-06-09 09:11:00 +03:00
|
|
|
bool IsCrossSiteCORSRequest() const;
|
2015-12-07 02:33:15 +03:00
|
|
|
bool IsDeniedCrossSiteCORSRequest();
|
2014-05-17 04:24:37 +04:00
|
|
|
|
2015-03-03 04:09:07 +03:00
|
|
|
// Tell our channel what network interface ID we were told to use.
|
|
|
|
// If it's an HTTP channel and we were told to use a non-default
|
|
|
|
// interface ID.
|
|
|
|
void PopulateNetworkInterfaceId();
|
|
|
|
|
2017-02-03 13:16:00 +03:00
|
|
|
void UnsuppressEventHandlingAndResume();
|
|
|
|
|
2017-05-18 14:02:22 +03:00
|
|
|
// Check pref "dom.mapped_arraybuffer.enabled" to make sure ArrayBuffer is
|
|
|
|
// supported.
|
|
|
|
static bool IsMappedArrayBufferEnabled();
|
|
|
|
|
|
|
|
// Check pref "dom.xhr.lowercase_header.enabled" to make sure lowercased
|
|
|
|
// response header is supported.
|
|
|
|
static bool IsLowercaseResponseHeader();
|
|
|
|
|
2017-05-19 08:28:00 +03:00
|
|
|
void MaybeLowerChannelPriority();
|
|
|
|
|
2012-03-26 19:38:06 +04:00
|
|
|
public:
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
2017-08-25 16:30:33 +03:00
|
|
|
Send(JSContext* aCx,
|
|
|
|
const Nullable<DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString>& aData,
|
|
|
|
ErrorResult& aRv) override;
|
2012-03-26 19:38:06 +04:00
|
|
|
|
2017-08-25 16:31:15 +03:00
|
|
|
virtual void
|
|
|
|
SendInputStream(nsIInputStream* aInputStream, ErrorResult& aRv) override
|
|
|
|
{
|
|
|
|
BodyExtractor<nsIInputStream> body(aInputStream);
|
|
|
|
aRv = SendInternal(&body);
|
|
|
|
}
|
|
|
|
|
2016-11-21 09:30:00 +03:00
|
|
|
void
|
|
|
|
RequestErrorSteps(const ProgressEventType aEventType,
|
|
|
|
const nsresult aOptionalException,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
void
|
2017-06-16 09:07:00 +03:00
|
|
|
Abort()
|
|
|
|
{
|
2017-11-13 12:17:05 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
AbortInternal(rv);
|
2016-06-27 20:13:41 +03:00
|
|
|
MOZ_ASSERT(!rv.Failed());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
Abort(ErrorResult& aRv) override;
|
2012-03-26 19:38:06 +04:00
|
|
|
|
|
|
|
// response
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
GetResponseURL(nsAString& aUrl) override;
|
|
|
|
|
|
|
|
virtual uint32_t
|
|
|
|
GetStatus(ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetStatusText(nsACString& aStatusText, ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetResponseHeader(const nsACString& aHeader, nsACString& aResult,
|
|
|
|
ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
void
|
|
|
|
GetResponseHeader(const nsAString& aHeader, nsAString& aResult,
|
|
|
|
ErrorResult& aRv)
|
2012-03-26 19:38:06 +04:00
|
|
|
{
|
2016-06-27 20:13:41 +03:00
|
|
|
nsAutoCString result;
|
2012-03-26 19:38:06 +04:00
|
|
|
GetResponseHeader(NS_ConvertUTF16toUTF8(aHeader), result, aRv);
|
|
|
|
if (result.IsVoid()) {
|
|
|
|
aResult.SetIsVoid(true);
|
|
|
|
}
|
|
|
|
else {
|
2012-10-03 00:38:51 +04:00
|
|
|
// The result value should be inflated:
|
|
|
|
CopyASCIItoUTF16(result, aResult);
|
2012-03-26 19:38:06 +04:00
|
|
|
}
|
|
|
|
}
|
2016-06-27 20:13:41 +03:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetAllResponseHeaders(nsACString& aResponseHeaders,
|
|
|
|
ErrorResult& aRv) override;
|
|
|
|
|
2016-06-09 09:11:00 +03:00
|
|
|
bool IsSafeHeader(const nsACString& aHeaderName,
|
2016-06-27 20:13:41 +03:00
|
|
|
NotNull<nsIHttpChannel*> aHttpChannel) const;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual XMLHttpRequestResponseType
|
|
|
|
ResponseType() const override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
2016-06-27 20:13:41 +03:00
|
|
|
return XMLHttpRequestResponseType(mResponseType);
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
2012-03-26 19:38:06 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
SetResponseType(XMLHttpRequestResponseType aType,
|
|
|
|
ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetResponse(JSContext* aCx, JS::MutableHandle<JS::Value> aResponse,
|
|
|
|
ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual void
|
2017-01-19 06:20:15 +03:00
|
|
|
GetResponseText(DOMString& aResponseText, ErrorResult& aRv) override;
|
2012-03-26 19:38:06 +04:00
|
|
|
|
2016-09-12 10:06:33 +03:00
|
|
|
void
|
|
|
|
GetResponseText(XMLHttpRequestStringSnapshot& aSnapshot,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual nsIDocument*
|
|
|
|
GetResponseXML(ErrorResult& aRv) override;
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual bool
|
|
|
|
MozBackgroundRequest() const override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
SetMozBackgroundRequest(bool aMozBackgroundRequest, ErrorResult& aRv) override;
|
|
|
|
|
2017-05-24 15:52:15 +03:00
|
|
|
virtual uint16_t
|
|
|
|
ErrorCode() const override
|
|
|
|
{
|
|
|
|
return static_cast<uint16_t>(mErrorLoad);
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual bool
|
|
|
|
MozAnon() const override;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
MozSystem() const override;
|
|
|
|
|
|
|
|
virtual nsIChannel*
|
|
|
|
GetChannel() const override
|
2012-03-26 19:38:06 +04:00
|
|
|
{
|
|
|
|
return mChannel;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
GetNetworkInterfaceId(nsACString& aId) const override
|
2015-03-03 04:09:07 +03:00
|
|
|
{
|
|
|
|
aId = mNetworkInterfaceId;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
SetNetworkInterfaceId(const nsACString& aId) override
|
2015-03-03 04:09:07 +03:00
|
|
|
{
|
|
|
|
mNetworkInterfaceId = aId;
|
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
// We need a GetInterface callable from JS for chrome JS
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
GetInterface(JSContext* aCx, nsIJSID* aIID,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
|
|
ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-07-08 19:50:48 +03:00
|
|
|
// This fires a trusted readystatechange event, which is not cancelable and
|
2008-08-14 15:07:46 +04:00
|
|
|
// doesn't bubble.
|
2016-07-08 19:50:48 +03:00
|
|
|
nsresult FireReadystatechangeEvent();
|
2016-06-27 20:13:41 +03:00
|
|
|
void DispatchProgressEvent(DOMEventTargetHelper* aTarget,
|
2016-07-08 19:44:33 +03:00
|
|
|
const ProgressEventType aType,
|
2015-01-08 22:48:52 +03:00
|
|
|
int64_t aLoaded, int64_t aTotal);
|
2008-08-14 15:07:46 +04:00
|
|
|
|
2007-12-12 11:33:32 +03:00
|
|
|
// This is called by the factory constructor.
|
|
|
|
nsresult Init();
|
|
|
|
|
2013-04-04 13:30:36 +04:00
|
|
|
nsresult init(nsIPrincipal* principal,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* globalObject,
|
2013-04-04 13:30:36 +04:00
|
|
|
nsIURI* baseURI);
|
|
|
|
|
2008-10-01 03:56:57 +04:00
|
|
|
void SetRequestObserver(nsIRequestObserver* aObserver);
|
|
|
|
|
2017-01-25 04:40:11 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(XMLHttpRequestMainThread,
|
|
|
|
XMLHttpRequest)
|
|
|
|
virtual bool IsCertainlyAliveForCC() const override;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool AllowUploadProgress();
|
2012-03-13 04:56:07 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DisconnectFromOwner() override;
|
2013-01-18 09:21:43 +04:00
|
|
|
|
2014-02-10 22:35:25 +04:00
|
|
|
static void SetDontWarnAboutSyncXHR(bool aVal)
|
|
|
|
{
|
|
|
|
sDontWarnAboutSyncXHR = aVal;
|
|
|
|
}
|
|
|
|
static bool DontWarnAboutSyncXHR()
|
|
|
|
{
|
|
|
|
return sDontWarnAboutSyncXHR;
|
|
|
|
}
|
2016-07-06 07:06:25 +03:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
SetOriginAttributes(const mozilla::dom::OriginAttributesDictionary& aAttrs) override;
|
|
|
|
|
2016-09-29 08:12:56 +03:00
|
|
|
void BlobStoreCompleted(MutableBlobStorage* aBlobStorage,
|
|
|
|
Blob* aBlob,
|
|
|
|
nsresult aResult) override;
|
|
|
|
|
2017-02-08 16:34:42 +03:00
|
|
|
void
|
|
|
|
LocalFileToBlobCompleted(Blob* aBlob);
|
|
|
|
|
2006-04-20 07:36:50 +04:00
|
|
|
protected:
|
2016-07-08 19:46:12 +03:00
|
|
|
// XHR states are meant to mirror the XHR2 spec:
|
|
|
|
// https://xhr.spec.whatwg.org/#states
|
|
|
|
enum class State : uint8_t {
|
|
|
|
unsent, // object has been constructed.
|
|
|
|
opened, // open() has been successfully invoked.
|
|
|
|
headers_received, // redirects followed and response headers received.
|
|
|
|
loading, // response body is being received.
|
|
|
|
done, // data transfer concluded, whether success or error.
|
|
|
|
};
|
|
|
|
|
2011-09-24 05:57:36 +04:00
|
|
|
nsresult DetectCharset();
|
2017-10-15 00:50:33 +03:00
|
|
|
nsresult AppendToResponseText(const char * aBuffer, uint32_t aBufferLen);
|
2016-08-12 10:36:22 +03:00
|
|
|
static nsresult StreamReaderFunc(nsIInputStream* in,
|
|
|
|
void* closure,
|
|
|
|
const char* fromRawSegment,
|
|
|
|
uint32_t toOffset,
|
|
|
|
uint32_t count,
|
|
|
|
uint32_t *writeCount);
|
2011-09-09 02:12:18 +04:00
|
|
|
nsresult CreateResponseParsedJSON(JSContext* aCx);
|
2006-04-20 07:39:23 +04:00
|
|
|
// Change the state of the object with this. The broadcast argument
|
|
|
|
// determines if the onreadystatechange listener should be called.
|
2016-07-08 19:46:12 +03:00
|
|
|
nsresult ChangeState(State aState, bool aBroadcast = true);
|
2011-08-24 21:46:53 +04:00
|
|
|
already_AddRefed<nsILoadGroup> GetLoadGroup() const;
|
2008-10-15 04:12:28 +04:00
|
|
|
nsIURI *GetBaseURI();
|
2006-05-05 21:01:53 +04:00
|
|
|
|
2006-04-20 07:38:52 +04:00
|
|
|
already_AddRefed<nsIHttpChannel> GetCurrentHttpChannel();
|
2012-10-26 05:57:57 +04:00
|
|
|
already_AddRefed<nsIJARChannel> GetCurrentJARChannel();
|
2006-04-20 07:36:50 +04:00
|
|
|
|
2016-09-12 10:05:42 +03:00
|
|
|
void TruncateResponseText();
|
|
|
|
|
2016-06-09 09:11:00 +03:00
|
|
|
bool IsSystemXHR() const;
|
2016-08-04 04:58:17 +03:00
|
|
|
bool InUploadPhase() const;
|
2011-03-17 19:19:13 +03:00
|
|
|
|
2016-08-06 06:47:40 +03:00
|
|
|
void OnBodyParseEnd();
|
2011-11-16 11:38:51 +04:00
|
|
|
void ChangeStateToDone();
|
|
|
|
|
2008-10-20 01:26:37 +04:00
|
|
|
void StartProgressEventTimer();
|
2016-08-04 04:58:17 +03:00
|
|
|
void StopProgressEventTimer();
|
2008-10-20 01:26:37 +04:00
|
|
|
|
2016-09-29 08:12:56 +03:00
|
|
|
void MaybeCreateBlobStorage();
|
|
|
|
|
2015-12-07 02:33:15 +03:00
|
|
|
nsresult OnRedirectVerifyCallback(nsresult result);
|
2010-08-05 06:15:55 +04:00
|
|
|
|
2016-11-04 23:36:06 +03:00
|
|
|
void SetTimerEventTarget(nsITimer* aTimer);
|
|
|
|
|
2017-05-09 11:14:51 +03:00
|
|
|
nsresult DispatchToMainThread(already_AddRefed<nsIRunnable> aRunnable);
|
|
|
|
|
2017-06-16 09:07:00 +03:00
|
|
|
void DispatchOrStoreEvent(DOMEventTargetHelper* aTarget, Event* aEvent);
|
|
|
|
|
2012-09-07 18:51:35 +04:00
|
|
|
already_AddRefed<nsXMLHttpRequestXPCOMifier> EnsureXPCOMifier();
|
|
|
|
|
2017-06-16 09:07:00 +03:00
|
|
|
void SuspendEventDispatching();
|
|
|
|
void ResumeEventDispatching();
|
|
|
|
|
2017-11-13 12:17:05 +03:00
|
|
|
void
|
|
|
|
AbortInternal(ErrorResult& aRv);
|
|
|
|
|
2017-06-16 09:07:00 +03:00
|
|
|
struct PendingEvent
|
|
|
|
{
|
|
|
|
RefPtr<DOMEventTargetHelper> mTarget;
|
|
|
|
RefPtr<Event> mEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTArray<PendingEvent> mPendingEvents;
|
|
|
|
|
2006-04-20 07:37:08 +04:00
|
|
|
nsCOMPtr<nsISupports> mContext;
|
2007-07-02 17:20:01 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2006-04-20 07:37:29 +04:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2016-07-20 20:02:36 +03:00
|
|
|
nsCString mRequestMethod;
|
|
|
|
nsCOMPtr<nsIURI> mRequestURL;
|
2012-03-26 19:38:06 +04:00
|
|
|
nsCOMPtr<nsIDocument> mResponseXML;
|
2006-04-20 07:37:23 +04:00
|
|
|
|
2006-04-20 07:38:20 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> mXMLParserStreamListener;
|
|
|
|
|
2006-04-20 07:37:18 +04:00
|
|
|
// used to implement getAllResponseHeaders()
|
2015-03-27 21:52:19 +03:00
|
|
|
class nsHeaderVisitor : public nsIHttpHeaderVisitor
|
|
|
|
{
|
2017-05-17 10:18:46 +03:00
|
|
|
struct HeaderEntry final
|
|
|
|
{
|
|
|
|
nsCString mName;
|
|
|
|
nsCString mValue;
|
|
|
|
|
|
|
|
HeaderEntry(const nsACString& aName, const nsACString& aValue)
|
|
|
|
: mName(aName), mValue(aValue)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const HeaderEntry& aOther) const
|
|
|
|
{
|
|
|
|
return mName == aOther.mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator<(const HeaderEntry& aOther) const
|
|
|
|
{
|
|
|
|
return mName < aOther.mName;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-04-20 07:37:18 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIHTTPHEADERVISITOR
|
2016-06-27 20:13:41 +03:00
|
|
|
nsHeaderVisitor(const XMLHttpRequestMainThread& aXMLHttpRequest,
|
|
|
|
NotNull<nsIHttpChannel*> aHttpChannel)
|
2013-01-11 02:47:43 +04:00
|
|
|
: mXHR(aXMLHttpRequest), mHttpChannel(aHttpChannel) {}
|
2017-05-17 10:18:46 +03:00
|
|
|
const nsACString &Headers()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mHeaderList.Length(); i++) {
|
|
|
|
HeaderEntry& header = mHeaderList.ElementAt(i);
|
|
|
|
|
|
|
|
mHeaders.Append(header.mName);
|
|
|
|
mHeaders.AppendLiteral(": ");
|
|
|
|
mHeaders.Append(header.mValue);
|
|
|
|
mHeaders.AppendLiteral("\r\n");
|
|
|
|
}
|
|
|
|
return mHeaders;
|
|
|
|
}
|
|
|
|
|
2006-04-20 07:37:18 +04:00
|
|
|
private:
|
2014-06-25 06:09:15 +04:00
|
|
|
virtual ~nsHeaderVisitor() {}
|
|
|
|
|
2017-05-17 10:18:46 +03:00
|
|
|
nsTArray<HeaderEntry> mHeaderList;
|
2006-04-20 07:37:18 +04:00
|
|
|
nsCString mHeaders;
|
2016-06-27 20:13:41 +03:00
|
|
|
const XMLHttpRequestMainThread& mXHR;
|
|
|
|
NotNull<nsCOMPtr<nsIHttpChannel>> mHttpChannel;
|
2006-04-20 07:37:18 +04:00
|
|
|
};
|
|
|
|
|
2011-09-24 05:57:36 +04:00
|
|
|
// The bytes of our response body. Only used for DEFAULT, ARRAYBUFFER and
|
|
|
|
// BLOB responseTypes
|
2006-04-20 07:37:08 +04:00
|
|
|
nsCString mResponseBody;
|
|
|
|
|
2011-09-24 05:57:36 +04:00
|
|
|
// The text version of our response body. This is incrementally decoded into
|
|
|
|
// as we receive network data. However for the DEFAULT responseType we
|
|
|
|
// lazily decode into this from mResponseBody only when .responseText is
|
|
|
|
// accessed.
|
|
|
|
// Only used for DEFAULT and TEXT responseTypes.
|
2016-09-12 10:06:06 +03:00
|
|
|
XMLHttpRequestString mResponseText;
|
2013-01-18 09:21:43 +04:00
|
|
|
|
2011-09-24 05:57:36 +04:00
|
|
|
// For DEFAULT responseType we use this to keep track of how far we've
|
|
|
|
// lazily decoded from mResponseBody to mResponseText
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mResponseBodyDecodedPos;
|
2011-09-24 05:57:36 +04:00
|
|
|
|
|
|
|
// Decoder used for decoding into mResponseText
|
|
|
|
// Only used for DEFAULT, TEXT and JSON responseTypes.
|
|
|
|
// In cases where we've only received half a surrogate, the decoder itself
|
|
|
|
// carries the state to remember this. Next time we receive more data we
|
|
|
|
// simply feed the new data into the decoder which will handle the second
|
|
|
|
// part of the surrogate.
|
2017-04-27 13:27:03 +03:00
|
|
|
mozilla::UniquePtr<mozilla::Decoder> mDecoder;
|
2011-09-24 05:57:36 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
const Encoding* mResponseCharset;
|
2010-04-23 21:37:02 +04:00
|
|
|
|
2016-08-29 23:30:36 +03:00
|
|
|
void MatchCharsetAndDecoderToResponseDocument();
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
XMLHttpRequestResponseType mResponseType;
|
2011-05-11 03:18:55 +04:00
|
|
|
|
2012-01-30 14:33:59 +04:00
|
|
|
// It is either a cached blob-response from the last call to GetResponse,
|
|
|
|
// but is also explicitly set in OnStopRequest.
|
2016-06-27 20:13:41 +03:00
|
|
|
RefPtr<Blob> mResponseBlob;
|
2017-02-08 16:34:42 +03:00
|
|
|
// We stream data to mBlobStorage when response type is "blob".
|
2016-09-29 08:12:56 +03:00
|
|
|
RefPtr<MutableBlobStorage> mBlobStorage;
|
2011-05-11 03:18:55 +04:00
|
|
|
|
2012-03-26 19:38:06 +04:00
|
|
|
nsString mOverrideMimeType;
|
2006-04-20 07:39:09 +04:00
|
|
|
|
2006-04-20 07:39:34 +04:00
|
|
|
/**
|
|
|
|
* The notification callbacks the channel had when Send() was
|
|
|
|
* called. We want to forward things here as needed.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mNotificationCallbacks;
|
|
|
|
/**
|
|
|
|
* Sink interfaces that we implement that mNotificationCallbacks may
|
|
|
|
* want to also be notified for. These are inited lazily if we're
|
|
|
|
* asked for the relevant interface.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIChannelEventSink> mChannelEventSink;
|
|
|
|
nsCOMPtr<nsIProgressEventSink> mProgressEventSink;
|
|
|
|
|
2008-10-01 03:56:57 +04:00
|
|
|
nsIRequestObserver* mRequestObserver;
|
|
|
|
|
2008-12-31 01:24:58 +03:00
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
2015-01-08 19:21:52 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2008-12-31 01:24:58 +03:00
|
|
|
|
2018-01-23 18:38:54 +03:00
|
|
|
Maybe<ClientInfo> mClientInfo;
|
|
|
|
Maybe<ServiceWorkerDescriptor> mController;
|
|
|
|
|
2016-07-08 19:46:12 +03:00
|
|
|
State mState;
|
|
|
|
|
Bug 1389300 - Inherit style backend into NS_NewDOMDocument. r=smaug,r=heycam
Our current machinery for enabling stylo requires a docshell - if there isn't
one, we default to the Gecko style system.
When getComputedStyle operates on an element without a presshell, it uses the
caller's presshell instead. If the element has previously been styled with
one style system (but no longer has a presshell), and the caller uses a
different style backend, using the caller's style system can cause crashes when
we pull bits of cached data off the DOM (like cached style attributes).
So we want to throw when window.getComputedStyle(element) is called for a
(window, element) pair with different style backends (which is what the next
patch in this bug does).
However, that causes a few failures where stylo-backed documents try to do
getComputedStyle on an XHR document (which, without a docshell, will use the
gecko style system).
So this patch does some work to propagate the creator's style backend into
various docshell-less documents. This should allow both chrome (which uses gecko)
and content (which uses stylo) to use getComputedStyle on the response document
for XHRs they create.
Note that the second patch in this bug will make
chromeWin.getComputedStyle(contentObj) throw. If we discover code that does
that, we can just make it invoke the content's getComputedStyle method over Xrays.
MozReview-Commit-ID: 5OsmHJKq5Ui
2017-08-15 05:50:28 +03:00
|
|
|
StyleBackendType mStyleBackend;
|
|
|
|
|
2016-07-08 19:49:40 +03:00
|
|
|
bool mFlagSynchronous;
|
2016-07-08 19:46:12 +03:00
|
|
|
bool mFlagAborted;
|
|
|
|
bool mFlagParseBody;
|
|
|
|
bool mFlagSyncLooping;
|
|
|
|
bool mFlagBackgroundRequest;
|
|
|
|
bool mFlagHadUploadListenersOnSend;
|
|
|
|
bool mFlagACwithCredentials;
|
|
|
|
bool mFlagTimedOut;
|
|
|
|
bool mFlagDeleted;
|
2016-07-07 18:51:51 +03:00
|
|
|
|
2016-07-08 19:50:19 +03:00
|
|
|
// The XHR2 spec's send() flag. Set when the XHR begins uploading, until it
|
|
|
|
// finishes downloading (or an error/abort has occurred during either phase).
|
|
|
|
// Used to guard against the user trying to alter headers/etc when it's too
|
|
|
|
// late, and ensure the XHR only handles one in-flight request at once.
|
|
|
|
bool mFlagSend;
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
RefPtr<XMLHttpRequestUpload> mUpload;
|
2015-01-08 22:48:52 +03:00
|
|
|
int64_t mUploadTransferred;
|
|
|
|
int64_t mUploadTotal;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mUploadComplete;
|
|
|
|
bool mProgressSinceLastProgressEvent;
|
2008-08-14 15:07:46 +04:00
|
|
|
|
2012-01-26 14:02:22 +04:00
|
|
|
// Timeout support
|
|
|
|
PRTime mRequestSentTime;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mTimeoutMilliseconds;
|
2012-01-26 14:02:22 +04:00
|
|
|
nsCOMPtr<nsITimer> mTimeoutTimer;
|
|
|
|
void StartTimeoutTimer();
|
|
|
|
void HandleTimeoutCallback();
|
|
|
|
|
2017-02-03 13:16:00 +03:00
|
|
|
nsCOMPtr<nsIDocument> mSuspendedDoc;
|
|
|
|
nsCOMPtr<nsIRunnable> mResumeTimeoutRunnable;
|
|
|
|
|
2016-10-16 09:46:10 +03:00
|
|
|
nsCOMPtr<nsITimer> mSyncTimeoutTimer;
|
|
|
|
|
|
|
|
enum SyncTimeoutType {
|
|
|
|
eErrorOrExpired,
|
|
|
|
eTimerStarted,
|
|
|
|
eNoTimerNeeded
|
|
|
|
};
|
|
|
|
|
|
|
|
SyncTimeoutType MaybeStartSyncTimeoutTimer();
|
|
|
|
void HandleSyncTimeoutTimer();
|
|
|
|
void CancelSyncTimeoutTimer();
|
|
|
|
|
2017-05-24 15:44:38 +03:00
|
|
|
ErrorType mErrorLoad;
|
2016-08-29 23:30:36 +03:00
|
|
|
bool mErrorParsingXML;
|
2012-02-16 20:45:25 +04:00
|
|
|
bool mWaitingForOnStopRequest;
|
2012-01-26 14:02:22 +04:00
|
|
|
bool mProgressTimerIsActive;
|
2011-11-16 11:38:51 +04:00
|
|
|
bool mIsHtml;
|
|
|
|
bool mWarnAboutSyncHtml;
|
2016-10-06 17:13:08 +03:00
|
|
|
int64_t mLoadTotal; // -1 if not known.
|
2014-07-24 09:47:00 +04:00
|
|
|
// Number of HTTP message body bytes received so far. This quantity is
|
|
|
|
// in the same units as Content-Length and mLoadTotal, and hence counts
|
|
|
|
// compressed bytes when the channel has gzip Content-Encoding. If the
|
|
|
|
// channel does not have Content-Encoding, this will be the same as
|
|
|
|
// mDataReceived except between the OnProgress that changes mLoadTransferred
|
|
|
|
// and the corresponding OnDataAvailable (which changes mDataReceived).
|
|
|
|
// Ordering of OnProgress and OnDataAvailable is undefined.
|
2015-01-08 22:48:52 +03:00
|
|
|
int64_t mLoadTransferred;
|
2008-10-20 01:26:37 +04:00
|
|
|
nsCOMPtr<nsITimer> mProgressNotifier;
|
2012-01-26 14:02:22 +04:00
|
|
|
void HandleProgressTimerCallback();
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
bool mIsSystem;
|
|
|
|
bool mIsAnon;
|
|
|
|
|
2015-03-03 04:09:07 +03:00
|
|
|
// A platform-specific identifer to represent the network interface
|
|
|
|
// that this request is associated with.
|
|
|
|
nsCString mNetworkInterfaceId;
|
|
|
|
|
2016-07-16 20:56:36 +03:00
|
|
|
/**
|
|
|
|
* Close the XMLHttpRequest's channels.
|
|
|
|
*/
|
|
|
|
void CloseRequest();
|
|
|
|
|
2017-09-25 19:58:23 +03:00
|
|
|
void TerminateOngoingFetch();
|
|
|
|
|
2012-01-26 14:02:22 +04:00
|
|
|
/**
|
|
|
|
* Close the XMLHttpRequest's channels and dispatch appropriate progress
|
|
|
|
* events.
|
|
|
|
*
|
|
|
|
* @param aType The progress event type.
|
|
|
|
*/
|
2016-07-08 19:46:12 +03:00
|
|
|
void CloseRequestWithError(const ProgressEventType aType);
|
2008-10-20 01:26:37 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFirstStartRequestSeen;
|
|
|
|
bool mInLoadProgressEvent;
|
2013-06-18 14:00:37 +04:00
|
|
|
|
2010-08-05 06:15:55 +04:00
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mNewRedirectChannel;
|
2013-06-18 14:00:37 +04:00
|
|
|
|
|
|
|
JS::Heap<JS::Value> mResultJSON;
|
2013-04-27 23:25:24 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
ArrayBufferBuilder mArrayBufferBuilder;
|
2013-06-18 14:00:38 +04:00
|
|
|
JS::Heap<JSObject*> mResultArrayBuffer;
|
2014-05-16 09:34:43 +04:00
|
|
|
bool mIsMappedArrayBuffer;
|
2010-03-22 04:52:35 +03:00
|
|
|
|
2011-09-24 05:57:22 +04:00
|
|
|
void ResetResponse();
|
|
|
|
|
2015-12-30 21:47:55 +03:00
|
|
|
bool ShouldBlockAuthPrompt();
|
|
|
|
|
2016-08-19 03:15:37 +03:00
|
|
|
RequestHeaders mAuthorRequestHeaders;
|
2013-02-04 04:56:09 +04:00
|
|
|
|
2012-09-07 18:51:35 +04:00
|
|
|
// Helper object to manage our XPCOM scriptability bits
|
|
|
|
nsXMLHttpRequestXPCOMifier* mXPCOMifier;
|
2014-02-10 22:35:25 +04:00
|
|
|
|
2017-06-16 09:07:00 +03:00
|
|
|
// When this is set to true, the event dispatching is suspended. This is
|
|
|
|
// useful to change the correct state when XHR is working sync.
|
|
|
|
bool mEventDispatchingSuspended;
|
|
|
|
|
2014-02-10 22:35:25 +04:00
|
|
|
static bool sDontWarnAboutSyncXHR;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MOZ_STACK_CLASS AutoDontWarnAboutSyncXHR
|
|
|
|
{
|
|
|
|
public:
|
2016-06-27 20:13:41 +03:00
|
|
|
AutoDontWarnAboutSyncXHR() : mOldVal(XMLHttpRequestMainThread::DontWarnAboutSyncXHR())
|
2014-02-10 22:35:25 +04:00
|
|
|
{
|
2016-06-27 20:13:41 +03:00
|
|
|
XMLHttpRequestMainThread::SetDontWarnAboutSyncXHR(true);
|
2014-02-10 22:35:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoDontWarnAboutSyncXHR()
|
|
|
|
{
|
2016-06-27 20:13:41 +03:00
|
|
|
XMLHttpRequestMainThread::SetDontWarnAboutSyncXHR(mOldVal);
|
2014-02-10 22:35:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mOldVal;
|
2006-04-20 07:36:50 +04:00
|
|
|
};
|
|
|
|
|
2012-09-07 18:51:35 +04:00
|
|
|
// A shim class designed to expose the non-DOM interfaces of
|
|
|
|
// XMLHttpRequest via XPCOM stuff.
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXMLHttpRequestXPCOMifier final : public nsIStreamListener,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIChannelEventSink,
|
2015-12-07 02:33:15 +03:00
|
|
|
public nsIAsyncVerifyRedirectCallback,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIProgressEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
2017-07-26 21:18:20 +03:00
|
|
|
public nsITimerCallback,
|
|
|
|
public nsINamed
|
2012-09-07 18:51:35 +04:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXMLHttpRequestXPCOMifier,
|
|
|
|
nsIStreamListener)
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
explicit nsXMLHttpRequestXPCOMifier(XMLHttpRequestMainThread* aXHR) :
|
2012-09-07 18:51:35 +04:00
|
|
|
mXHR(aXHR)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
private:
|
2012-09-07 18:51:35 +04:00
|
|
|
~nsXMLHttpRequestXPCOMifier() {
|
|
|
|
if (mXHR) {
|
|
|
|
mXHR->mXPCOMifier = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
public:
|
2012-09-07 18:51:35 +04:00
|
|
|
NS_FORWARD_NSISTREAMLISTENER(mXHR->)
|
|
|
|
NS_FORWARD_NSIREQUESTOBSERVER(mXHR->)
|
|
|
|
NS_FORWARD_NSICHANNELEVENTSINK(mXHR->)
|
2015-12-07 02:33:15 +03:00
|
|
|
NS_FORWARD_NSIASYNCVERIFYREDIRECTCALLBACK(mXHR->)
|
2012-09-07 18:51:35 +04:00
|
|
|
NS_FORWARD_NSIPROGRESSEVENTSINK(mXHR->)
|
|
|
|
NS_FORWARD_NSITIMERCALLBACK(mXHR->)
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_FORWARD_NSINAMED(mXHR->)
|
2012-09-07 18:51:35 +04:00
|
|
|
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
|
|
|
|
private:
|
2016-06-27 20:13:41 +03:00
|
|
|
RefPtr<XMLHttpRequestMainThread> mXHR;
|
2012-09-07 18:51:35 +04:00
|
|
|
};
|
|
|
|
|
2011-11-16 11:38:51 +04:00
|
|
|
class nsXHRParseEndListener : public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent *event) override
|
2011-11-16 11:38:51 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> xhr = do_QueryReferent(mXHR);
|
|
|
|
if (xhr) {
|
2016-08-06 06:47:40 +03:00
|
|
|
static_cast<XMLHttpRequestMainThread*>(xhr.get())->OnBodyParseEnd();
|
2011-11-16 11:38:51 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mXHR = nullptr;
|
2011-11-16 11:38:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit nsXHRParseEndListener(nsIXMLHttpRequest* aXHR)
|
2011-11-16 11:38:51 +04:00
|
|
|
: mXHR(do_GetWeakReference(aXHR)) {}
|
|
|
|
private:
|
2014-06-25 06:09:15 +04:00
|
|
|
virtual ~nsXHRParseEndListener() {}
|
|
|
|
|
2011-11-16 11:38:51 +04:00
|
|
|
nsWeakPtr mXHR;
|
|
|
|
};
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|
|
|
|
|
|
|
|
#endif // mozilla_dom_XMLHttpRequestMainThread_h
|