2015-05-03 22:32:37 +03: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: */
|
2014-09-24 09:03:20 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_InternalRequest_h
|
|
|
|
#define mozilla_dom_InternalRequest_h
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
#include "mozilla/dom/HeadersBinding.h"
|
|
|
|
#include "mozilla/dom/InternalHeaders.h"
|
2014-09-24 09:03:20 +04:00
|
|
|
#include "mozilla/dom/RequestBinding.h"
|
2015-10-22 21:07:32 +03:00
|
|
|
#include "mozilla/LoadTainting.h"
|
2016-04-01 06:52:28 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2014-09-24 09:03:20 +04:00
|
|
|
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2014-12-23 18:56:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsIURLParser.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#endif
|
2014-09-24 09:03:20 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2016-10-26 10:07:25 +03:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
|
|
|
} // namespace ipc
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2015-03-25 23:38:42 +03:00
|
|
|
/*
|
2018-03-09 17:11:27 +03:00
|
|
|
* The mapping of RequestDestination and nsContentPolicyType is currently as the
|
2015-03-25 23:38:42 +03:00
|
|
|
* following. Note that this mapping is not perfect yet (see the TODO comments
|
2015-06-15 23:12:45 +03:00
|
|
|
* below for examples).
|
2015-03-25 23:38:42 +03:00
|
|
|
*
|
2018-03-09 17:11:27 +03:00
|
|
|
* RequestDestination| nsContentPolicyType
|
2015-03-25 23:38:42 +03:00
|
|
|
* ------------------+--------------------
|
2015-06-15 23:45:27 +03:00
|
|
|
* audio | TYPE_INTERNAL_AUDIO
|
2018-03-09 17:11:27 +03:00
|
|
|
* audioworklet | TODO
|
|
|
|
* document | TYPE_DOCUMENT, TYPE_INTERNAL_IFRAME, TYPE_SUBDOCUMENT
|
2015-07-18 18:51:00 +03:00
|
|
|
* embed | TYPE_INTERNAL_EMBED
|
2015-03-25 23:38:42 +03:00
|
|
|
* font | TYPE_FONT
|
2018-03-09 17:11:27 +03:00
|
|
|
* image | TYPE_INTERNAL_IMAGE, TYPE_INTERNAL_IMAGE_PRELOAD,
|
|
|
|
* | TYPE_IMAGE, TYPE_INTERNAL_IMAGE_FAVICON, TYPE_IMAGESET
|
2015-06-02 22:42:19 +03:00
|
|
|
* manifest | TYPE_WEB_MANIFEST
|
2018-03-09 17:11:27 +03:00
|
|
|
* object | TYPE_INTERNAL_OBJECT, TYPE_OBJECT
|
|
|
|
* "paintworklet" | TODO
|
|
|
|
* report" | TODO
|
|
|
|
* script | TYPE_INTERNAL_SCRIPT, TYPE_INTERNAL_SCRIPT_PRELOAD, TYPE_SCRIPT
|
|
|
|
* | TYPE_INTERNAL_SERVICE_WORKER, TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS
|
2015-06-17 04:21:08 +03:00
|
|
|
* sharedworker | TYPE_INTERNAL_SHARED_WORKER
|
2018-03-09 17:11:27 +03:00
|
|
|
* serviceworker | The spec lists this as a valid value for the enum,however it
|
|
|
|
* | is impossible to observe a request with this destination value.
|
|
|
|
* style | TYPE_INTERNAL_STYLESHEET, TYPE_INTERNAL_STYLESHEET_PRELOAD,
|
|
|
|
* | TYPE_STYLESHEET
|
2015-06-15 23:45:27 +03:00
|
|
|
* track | TYPE_INTERNAL_TRACK
|
|
|
|
* video | TYPE_INTERNAL_VIDEO
|
2015-06-17 04:21:08 +03:00
|
|
|
* worker | TYPE_INTERNAL_WORKER
|
2015-03-25 23:38:42 +03:00
|
|
|
* xslt | TYPE_XSLT
|
2018-03-09 17:11:27 +03:00
|
|
|
* _empty | Default for everything else.
|
2015-03-25 23:38:42 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
class Request;
|
2016-06-07 12:46:03 +03:00
|
|
|
class IPCInternalRequest;
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2014-12-23 18:56:19 +03:00
|
|
|
#define kFETCH_CLIENT_REFERRER_STR "about:client"
|
2015-03-21 19:28:04 +03:00
|
|
|
class InternalRequest final
|
2014-09-24 09:03:20 +04:00
|
|
|
{
|
|
|
|
friend class Request;
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalRequest)
|
2016-11-07 05:16:34 +03:00
|
|
|
InternalRequest(const nsACString& aURL, const nsACString& aFragment);
|
2016-01-14 02:14:38 +03:00
|
|
|
InternalRequest(const nsACString& aURL,
|
2016-11-07 05:16:34 +03:00
|
|
|
const nsACString& aFragment,
|
2016-01-14 02:14:38 +03:00
|
|
|
const nsACString& aMethod,
|
|
|
|
already_AddRefed<InternalHeaders> aHeaders,
|
2016-02-29 02:05:40 +03:00
|
|
|
RequestCache aCacheMode,
|
2016-01-14 02:14:38 +03:00
|
|
|
RequestMode aMode,
|
|
|
|
RequestRedirect aRequestRedirect,
|
|
|
|
RequestCredentials aRequestCredentials,
|
|
|
|
const nsAString& aReferrer,
|
2016-02-27 01:36:45 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
2016-09-07 05:20:23 +03:00
|
|
|
nsContentPolicyType aContentPolicyType,
|
2016-10-26 10:07:25 +03:00
|
|
|
const nsAString& aIntegrity);
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2016-06-07 12:46:03 +03:00
|
|
|
explicit InternalRequest(const IPCInternalRequest& aIPCRequest);
|
|
|
|
|
|
|
|
void ToIPC(IPCInternalRequest* aIPCRequest);
|
|
|
|
|
2015-02-20 04:24:24 +03:00
|
|
|
already_AddRefed<InternalRequest> Clone();
|
2014-09-24 09:03:20 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
GetMethod(nsCString& aMethod) const
|
|
|
|
{
|
|
|
|
aMethod.Assign(mMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetMethod(const nsACString& aMethod)
|
|
|
|
{
|
|
|
|
mMethod.Assign(aMethod);
|
|
|
|
}
|
|
|
|
|
2014-10-06 22:01:20 +04:00
|
|
|
bool
|
|
|
|
HasSimpleMethod() const
|
|
|
|
{
|
|
|
|
return mMethod.LowerCaseEqualsASCII("get") ||
|
|
|
|
mMethod.LowerCaseEqualsASCII("post") ||
|
|
|
|
mMethod.LowerCaseEqualsASCII("head");
|
|
|
|
}
|
2016-11-07 05:16:34 +03:00
|
|
|
// GetURL should get the request's current url with fragment. A request has
|
|
|
|
// an associated current url. It is a pointer to the last fetch URL in
|
|
|
|
// request's url list.
|
2014-09-24 09:03:20 +04:00
|
|
|
void
|
2016-05-03 04:48:40 +03:00
|
|
|
GetURL(nsACString& aURL) const
|
2014-09-24 09:03:20 +04:00
|
|
|
{
|
2016-11-07 05:16:34 +03:00
|
|
|
aURL.Assign(GetURLWithoutFragment());
|
|
|
|
if (GetFragment().IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 04:25:25 +03:00
|
|
|
aURL.AppendLiteral("#");
|
2016-11-07 05:16:34 +03:00
|
|
|
aURL.Append(GetFragment());
|
2016-05-03 04:48:40 +03:00
|
|
|
}
|
|
|
|
|
2016-11-07 05:16:34 +03:00
|
|
|
const nsCString&
|
|
|
|
GetURLWithoutFragment() const
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(!mURLList.IsEmpty(),
|
|
|
|
"Internal Request's urlList should not be empty.");
|
|
|
|
|
|
|
|
return mURLList.LastElement();
|
|
|
|
}
|
2016-05-03 04:48:40 +03:00
|
|
|
// AddURL should append the url into url list.
|
2016-11-07 05:16:34 +03:00
|
|
|
// Normally we strip the fragment from the URL in Request::Constructor and
|
|
|
|
// pass the fragment as the second argument into it.
|
|
|
|
// If a fragment is present in the URL it must be stripped and passed in
|
|
|
|
// separately.
|
2016-05-03 04:48:40 +03:00
|
|
|
void
|
2016-11-07 05:16:34 +03:00
|
|
|
AddURL(const nsACString& aURL, const nsACString& aFragment)
|
2016-05-03 04:48:40 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aURL.IsEmpty());
|
2016-11-07 05:16:34 +03:00
|
|
|
MOZ_ASSERT(!aURL.Contains('#'));
|
|
|
|
|
2016-05-03 04:48:40 +03:00
|
|
|
mURLList.AppendElement(aURL);
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2016-11-07 05:16:34 +03:00
|
|
|
mFragment.Assign(aFragment);
|
|
|
|
}
|
|
|
|
// Get the URL list without their fragments.
|
2015-01-08 00:47:18 +03:00
|
|
|
void
|
2016-11-07 05:16:34 +03:00
|
|
|
GetURLListWithoutFragment(nsTArray<nsCString>& aURLList)
|
2015-01-08 00:47:18 +03:00
|
|
|
{
|
2016-05-03 04:48:40 +03:00
|
|
|
aURLList.Assign(mURLList);
|
2015-01-08 00:47:18 +03:00
|
|
|
}
|
2014-12-23 18:56:19 +03:00
|
|
|
void
|
|
|
|
GetReferrer(nsAString& aReferrer) const
|
2014-09-24 09:03:20 +04:00
|
|
|
{
|
2014-12-23 18:56:19 +03:00
|
|
|
aReferrer.Assign(mReferrer);
|
2014-09-24 09:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-23 18:56:19 +03:00
|
|
|
SetReferrer(const nsAString& aReferrer)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool validReferrer = false;
|
|
|
|
if (aReferrer.IsEmpty() ||
|
|
|
|
aReferrer.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) {
|
|
|
|
validReferrer = true;
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIURLParser> parser = do_GetService(NS_STDURLPARSER_CONTRACTID);
|
|
|
|
if (!parser) {
|
|
|
|
NS_WARNING("Could not get parser to validate URL!");
|
|
|
|
} else {
|
|
|
|
uint32_t schemePos;
|
|
|
|
int32_t schemeLen;
|
|
|
|
uint32_t authorityPos;
|
|
|
|
int32_t authorityLen;
|
|
|
|
uint32_t pathPos;
|
|
|
|
int32_t pathLen;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 ref(aReferrer);
|
|
|
|
nsresult rv = parser->ParseURL(ref.get(), ref.Length(),
|
|
|
|
&schemePos, &schemeLen,
|
|
|
|
&authorityPos, &authorityLen,
|
|
|
|
&pathPos, &pathLen);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Invalid referrer URL!");
|
|
|
|
} else if (schemeLen < 0 || authorityLen < 0) {
|
|
|
|
NS_WARNING("Invalid referrer URL!");
|
|
|
|
} else {
|
|
|
|
validReferrer = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(validReferrer);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mReferrer.Assign(aReferrer);
|
2014-09-24 09:03:20 +04:00
|
|
|
}
|
|
|
|
|
2016-02-27 01:36:45 +03:00
|
|
|
ReferrerPolicy
|
|
|
|
ReferrerPolicy_() const
|
|
|
|
{
|
|
|
|
return mReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetReferrerPolicy(ReferrerPolicy aReferrerPolicy)
|
|
|
|
{
|
|
|
|
mReferrerPolicy = aReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
2016-11-14 10:15:32 +03:00
|
|
|
void
|
|
|
|
SetReferrerPolicy(net::ReferrerPolicy aReferrerPolicy)
|
|
|
|
{
|
|
|
|
switch (aReferrerPolicy) {
|
|
|
|
case net::RP_Unset:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::_empty;
|
|
|
|
break;
|
|
|
|
case net::RP_No_Referrer:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::No_referrer;
|
|
|
|
break;
|
|
|
|
case net::RP_No_Referrer_When_Downgrade:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::No_referrer_when_downgrade;
|
|
|
|
break;
|
|
|
|
case net::RP_Origin:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::Origin;
|
|
|
|
break;
|
|
|
|
case net::RP_Origin_When_Crossorigin:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::Origin_when_cross_origin;
|
|
|
|
break;
|
|
|
|
case net::RP_Unsafe_URL:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::Unsafe_url;
|
|
|
|
break;
|
|
|
|
case net::RP_Same_Origin:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::Same_origin;
|
|
|
|
break;
|
|
|
|
case net::RP_Strict_Origin:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::Strict_origin;
|
|
|
|
break;
|
|
|
|
case net::RP_Strict_Origin_When_Cross_Origin:
|
|
|
|
mReferrerPolicy = ReferrerPolicy::Strict_origin_when_cross_origin;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy value");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
net::ReferrerPolicy
|
|
|
|
GetReferrerPolicy()
|
|
|
|
{
|
|
|
|
switch (mReferrerPolicy) {
|
|
|
|
case ReferrerPolicy::_empty:
|
|
|
|
return net::RP_Unset;
|
|
|
|
case ReferrerPolicy::No_referrer:
|
|
|
|
return net::RP_No_Referrer;
|
|
|
|
case ReferrerPolicy::No_referrer_when_downgrade:
|
|
|
|
return net::RP_No_Referrer_When_Downgrade;
|
|
|
|
case ReferrerPolicy::Origin:
|
|
|
|
return net::RP_Origin;
|
|
|
|
case ReferrerPolicy::Origin_when_cross_origin:
|
|
|
|
return net::RP_Origin_When_Crossorigin;
|
|
|
|
case ReferrerPolicy::Unsafe_url:
|
|
|
|
return net::RP_Unsafe_URL;
|
|
|
|
case ReferrerPolicy::Strict_origin:
|
|
|
|
return net::RP_Strict_Origin;
|
|
|
|
case ReferrerPolicy::Same_origin:
|
|
|
|
return net::RP_Same_Origin;
|
|
|
|
case ReferrerPolicy::Strict_origin_when_cross_origin:
|
|
|
|
return net::RP_Strict_Origin_When_Cross_Origin;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy enum value?");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return net::RP_Unset;
|
|
|
|
}
|
|
|
|
|
2016-04-01 06:52:28 +03:00
|
|
|
net::ReferrerPolicy
|
|
|
|
GetEnvironmentReferrerPolicy() const
|
|
|
|
{
|
|
|
|
return mEnvironmentReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetEnvironmentReferrerPolicy(net::ReferrerPolicy aReferrerPolicy)
|
|
|
|
{
|
|
|
|
mEnvironmentReferrerPolicy = aReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
2014-12-24 13:08:41 +03:00
|
|
|
bool
|
|
|
|
SkipServiceWorker() const
|
|
|
|
{
|
|
|
|
return mSkipServiceWorker;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetSkipServiceWorker()
|
|
|
|
{
|
|
|
|
mSkipServiceWorker = true;
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
bool
|
|
|
|
IsSynchronous() const
|
|
|
|
{
|
|
|
|
return mSynchronous;
|
|
|
|
}
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
RequestMode
|
|
|
|
Mode() const
|
|
|
|
{
|
|
|
|
return mMode;
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
void
|
|
|
|
SetMode(RequestMode aMode)
|
|
|
|
{
|
|
|
|
mMode = aMode;
|
|
|
|
}
|
|
|
|
|
2015-01-08 02:50:54 +03:00
|
|
|
RequestCredentials
|
|
|
|
GetCredentialsMode() const
|
|
|
|
{
|
|
|
|
return mCredentialsMode;
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
void
|
|
|
|
SetCredentialsMode(RequestCredentials aCredentialsMode)
|
|
|
|
{
|
|
|
|
mCredentialsMode = aCredentialsMode;
|
|
|
|
}
|
|
|
|
|
2015-10-22 21:07:32 +03:00
|
|
|
LoadTainting
|
2014-10-06 22:01:20 +04:00
|
|
|
GetResponseTainting() const
|
|
|
|
{
|
|
|
|
return mResponseTainting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 21:07:32 +03:00
|
|
|
MaybeIncreaseResponseTainting(LoadTainting aTainting)
|
2014-10-06 22:01:20 +04:00
|
|
|
{
|
2015-10-22 21:07:32 +03:00
|
|
|
if (aTainting > mResponseTainting) {
|
|
|
|
mResponseTainting = aTainting;
|
|
|
|
}
|
2014-10-06 22:01:20 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 03:24:40 +03:00
|
|
|
RequestCache
|
|
|
|
GetCacheMode() const
|
|
|
|
{
|
|
|
|
return mCacheMode;
|
|
|
|
}
|
|
|
|
|
2015-03-22 20:12:43 +03:00
|
|
|
void
|
|
|
|
SetCacheMode(RequestCache aCacheMode)
|
|
|
|
{
|
|
|
|
mCacheMode = aCacheMode;
|
|
|
|
}
|
|
|
|
|
2015-09-01 00:26:29 +03:00
|
|
|
RequestRedirect
|
|
|
|
GetRedirectMode() const
|
|
|
|
{
|
|
|
|
return mRedirectMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetRedirectMode(RequestRedirect aRedirectMode)
|
|
|
|
{
|
|
|
|
mRedirectMode = aRedirectMode;
|
|
|
|
}
|
|
|
|
|
2016-09-07 05:20:23 +03:00
|
|
|
const nsString&
|
|
|
|
GetIntegrity() const
|
|
|
|
{
|
|
|
|
return mIntegrity;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
SetIntegrity(const nsAString& aIntegrity)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIntegrity.IsEmpty());
|
|
|
|
mIntegrity.Assign(aIntegrity);
|
|
|
|
}
|
2017-11-21 01:07:26 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
MozErrors() const
|
|
|
|
{
|
|
|
|
return mMozErrors;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetMozErrors()
|
|
|
|
{
|
|
|
|
mMozErrors = true;
|
|
|
|
}
|
|
|
|
|
2016-11-07 05:16:34 +03:00
|
|
|
const nsCString&
|
|
|
|
GetFragment() const
|
|
|
|
{
|
|
|
|
return mFragment;
|
|
|
|
}
|
2016-09-07 05:20:23 +03:00
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
nsContentPolicyType
|
2015-01-28 02:43:09 +03:00
|
|
|
ContentPolicyType() const
|
2014-09-24 09:03:20 +04:00
|
|
|
{
|
2015-01-28 02:43:09 +03:00
|
|
|
return mContentPolicyType;
|
2014-09-24 09:03:20 +04:00
|
|
|
}
|
2015-03-02 16:08:00 +03:00
|
|
|
void
|
2015-03-25 23:38:42 +03:00
|
|
|
SetContentPolicyType(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
2016-04-08 00:13:09 +03:00
|
|
|
void
|
|
|
|
OverrideContentPolicyType(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
2018-03-09 17:11:27 +03:00
|
|
|
RequestDestination
|
|
|
|
Destination() const
|
2015-03-25 23:38:42 +03:00
|
|
|
{
|
2018-03-09 17:11:27 +03:00
|
|
|
return MapContentPolicyTypeToRequestDestination(mContentPolicyType);
|
2015-03-02 16:08:00 +03:00
|
|
|
}
|
|
|
|
|
2014-10-06 22:01:20 +04:00
|
|
|
bool
|
|
|
|
UnsafeRequest() const
|
|
|
|
{
|
|
|
|
return mUnsafeRequest;
|
|
|
|
}
|
|
|
|
|
2015-01-08 02:50:54 +03:00
|
|
|
void
|
|
|
|
SetUnsafeRequest()
|
|
|
|
{
|
|
|
|
mUnsafeRequest = true;
|
|
|
|
}
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
InternalHeaders*
|
|
|
|
Headers()
|
2014-09-24 09:03:20 +04:00
|
|
|
{
|
|
|
|
return mHeaders;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ForceOriginHeader()
|
|
|
|
{
|
|
|
|
return mForceOriginHeader;
|
|
|
|
}
|
|
|
|
|
2014-10-06 22:01:20 +04:00
|
|
|
bool
|
|
|
|
SameOriginDataURL() const
|
|
|
|
{
|
|
|
|
return mSameOriginDataURL;
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:47:18 +03:00
|
|
|
void
|
|
|
|
UnsetSameOriginDataURL()
|
|
|
|
{
|
|
|
|
mSameOriginDataURL = false;
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
void
|
2017-09-08 17:06:26 +03:00
|
|
|
SetBody(nsIInputStream* aStream, int64_t aBodyLength)
|
2014-09-24 09:03:20 +04:00
|
|
|
{
|
2014-12-10 11:51:59 +03:00
|
|
|
// A request's body may not be reset once set.
|
2015-08-10 22:06:00 +03:00
|
|
|
MOZ_ASSERT_IF(aStream, !mBodyStream);
|
2014-09-24 09:03:20 +04:00
|
|
|
mBodyStream = aStream;
|
2017-09-08 17:06:26 +03:00
|
|
|
mBodyLength = aBodyLength;
|
2014-09-24 09:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Will return the original stream!
|
|
|
|
// Use a tee or copy if you don't want to erase the original.
|
|
|
|
void
|
2017-09-08 17:06:26 +03:00
|
|
|
GetBody(nsIInputStream** aStream, int64_t* aBodyLength = nullptr)
|
2014-09-24 09:03:20 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIInputStream> s = mBodyStream;
|
|
|
|
s.forget(aStream);
|
2017-09-08 17:06:26 +03:00
|
|
|
|
|
|
|
if (aBodyLength) {
|
|
|
|
*aBodyLength = mBodyLength;
|
|
|
|
}
|
2014-09-24 09:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The global is used as the client for the new object.
|
|
|
|
already_AddRefed<InternalRequest>
|
|
|
|
GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult& aRv) const;
|
|
|
|
|
2015-03-27 13:47:00 +03:00
|
|
|
bool
|
|
|
|
WasCreatedByFetchEvent() const
|
|
|
|
{
|
|
|
|
return mCreatedByFetchEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetCreatedByFetchEvent()
|
|
|
|
{
|
|
|
|
mCreatedByFetchEvent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearCreatedByFetchEvent()
|
|
|
|
{
|
|
|
|
mCreatedByFetchEvent = false;
|
|
|
|
}
|
|
|
|
|
2015-07-14 23:11:26 +03:00
|
|
|
bool
|
|
|
|
IsNavigationRequest() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsWorkerRequest() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsClientRequest() const;
|
|
|
|
|
2016-03-03 02:09:30 +03:00
|
|
|
void
|
|
|
|
MaybeSkipCacheIfPerformingRevalidation();
|
|
|
|
|
2016-04-08 00:13:09 +03:00
|
|
|
bool
|
|
|
|
IsContentPolicyTypeOverridden() const
|
|
|
|
{
|
|
|
|
return mContentPolicyTypeOverridden;
|
|
|
|
}
|
|
|
|
|
2015-09-01 17:58:34 +03:00
|
|
|
static RequestMode
|
|
|
|
MapChannelToRequestMode(nsIChannel* aChannel);
|
2015-07-14 23:11:26 +03:00
|
|
|
|
2016-01-25 09:18:29 +03:00
|
|
|
static RequestCredentials
|
|
|
|
MapChannelToRequestCredentials(nsIChannel* aChannel);
|
|
|
|
|
2016-10-26 10:07:25 +03:00
|
|
|
// Takes ownership of the principal info.
|
|
|
|
void
|
|
|
|
SetPrincipalInfo(UniquePtr<mozilla::ipc::PrincipalInfo> aPrincipalInfo);
|
|
|
|
|
|
|
|
const UniquePtr<mozilla::ipc::PrincipalInfo>&
|
|
|
|
GetPrincipalInfo() const
|
|
|
|
{
|
|
|
|
return mPrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2017-12-04 09:39:10 +03:00
|
|
|
const nsCString&
|
|
|
|
GetPreferredAlternativeDataType() const
|
|
|
|
{
|
|
|
|
return mPreferredAlternativeDataType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetPreferredAlternativeDataType(const nsACString& aDataType)
|
|
|
|
{
|
|
|
|
mPreferredAlternativeDataType = aDataType;
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
private:
|
2015-02-20 04:24:24 +03:00
|
|
|
// Does not copy mBodyStream. Use fallible Clone() for complete copy.
|
|
|
|
explicit InternalRequest(const InternalRequest& aOther);
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
~InternalRequest();
|
|
|
|
|
2018-03-09 17:11:27 +03:00
|
|
|
// Map the content policy type to the associated fetch destination, as defined
|
|
|
|
// by the spec at https://fetch.spec.whatwg.org/#concept-request-destination.
|
|
|
|
// Note that while the HTML spec for the "Link" element and its "as" attribute
|
|
|
|
// (https://html.spec.whatwg.org/#attr-link-as) reuse fetch's definition of
|
|
|
|
// destination, and the Link class has an internal Link::AsDestination enum type,
|
|
|
|
// the latter is only a support type to map the string values via
|
|
|
|
// Link::ParseAsValue and Link::AsValueToContentPolicy to our canonical nsContentPolicyType.
|
|
|
|
static RequestDestination
|
|
|
|
MapContentPolicyTypeToRequestDestination(nsContentPolicyType aContentPolicyType);
|
2015-06-15 23:12:45 +03:00
|
|
|
|
2015-09-01 17:58:34 +03:00
|
|
|
static bool
|
|
|
|
IsNavigationContentPolicy(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsWorkerContentPolicy(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
nsCString mMethod;
|
2016-05-03 04:48:40 +03:00
|
|
|
// mURLList: a list of one or more fetch URLs
|
|
|
|
nsTArray<nsCString> mURLList;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InternalHeaders> mHeaders;
|
2014-09-24 09:03:20 +04:00
|
|
|
nsCOMPtr<nsIInputStream> mBodyStream;
|
2017-09-08 17:06:26 +03:00
|
|
|
int64_t mBodyLength;
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2017-12-04 09:39:10 +03:00
|
|
|
nsCString mPreferredAlternativeDataType;
|
|
|
|
|
2015-01-28 02:43:09 +03:00
|
|
|
nsContentPolicyType mContentPolicyType;
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2014-12-23 18:56:19 +03:00
|
|
|
// Empty string: no-referrer
|
|
|
|
// "about:client": client (default)
|
|
|
|
// URL: an URL
|
|
|
|
nsString mReferrer;
|
2016-02-27 01:36:45 +03:00
|
|
|
ReferrerPolicy mReferrerPolicy;
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2016-04-01 06:52:28 +03:00
|
|
|
// This will be used for request created from Window or Worker contexts
|
|
|
|
// In case there's no Referrer Policy in Request, this will be passed to
|
|
|
|
// channel.
|
|
|
|
// The Environment Referrer Policy should be net::ReferrerPolicy so that it
|
|
|
|
// could be associated with nsIHttpChannel.
|
|
|
|
net::ReferrerPolicy mEnvironmentReferrerPolicy;
|
2014-09-24 09:03:20 +04:00
|
|
|
RequestMode mMode;
|
|
|
|
RequestCredentials mCredentialsMode;
|
2016-06-30 10:05:00 +03:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR LoadTainting mResponseTainting;
|
2015-01-08 03:24:40 +03:00
|
|
|
RequestCache mCacheMode;
|
2015-09-01 00:26:29 +03:00
|
|
|
RequestRedirect mRedirectMode;
|
2016-09-07 05:20:23 +03:00
|
|
|
nsString mIntegrity;
|
2017-11-21 01:07:26 +03:00
|
|
|
bool mMozErrors;
|
2016-11-07 05:16:34 +03:00
|
|
|
nsCString mFragment;
|
2016-06-30 10:05:00 +03:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mAuthenticationFlag;
|
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mForceOriginHeader;
|
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mPreserveContentCodings;
|
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mSameOriginDataURL;
|
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mSkipServiceWorker;
|
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mSynchronous;
|
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mUnsafeRequest;
|
|
|
|
MOZ_INIT_OUTSIDE_CTOR bool mUseURLCredentials;
|
2015-03-27 13:47:00 +03:00
|
|
|
// This is only set when a Request object is created by a fetch event. We
|
|
|
|
// use it to check if Service Workers are simply fetching intercepted Request
|
|
|
|
// objects without modifying them.
|
|
|
|
bool mCreatedByFetchEvent = false;
|
2016-04-08 00:13:09 +03:00
|
|
|
// This is only set when Request.overrideContentPolicyType() has been set.
|
|
|
|
// It is illegal to pass such a Request object to a fetch() method unless
|
|
|
|
// if the caller has chrome privileges.
|
|
|
|
bool mContentPolicyTypeOverridden = false;
|
2016-10-26 10:07:25 +03:00
|
|
|
|
|
|
|
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
2014-09-24 09:03:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_InternalRequest_h
|