2015-05-03 19:32:37 +00: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 05:03:20 +00: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 17:59:20 +00:00
|
|
|
#include "mozilla/dom/HeadersBinding.h"
|
|
|
|
#include "mozilla/dom/InternalHeaders.h"
|
2014-09-24 05:03:20 +00:00
|
|
|
#include "mozilla/dom/RequestBinding.h"
|
2015-10-22 18:07:32 +00:00
|
|
|
#include "mozilla/LoadTainting.h"
|
2014-09-24 05:03:20 +00:00
|
|
|
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2014-12-23 15:56:19 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsIURLParser.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#endif
|
2014-09-24 05:03:20 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-25 20:38:42 +00:00
|
|
|
/*
|
|
|
|
* The mapping of RequestContext and nsContentPolicyType is currently as the
|
|
|
|
* following. Note that this mapping is not perfect yet (see the TODO comments
|
2015-06-15 20:12:45 +00:00
|
|
|
* below for examples).
|
2015-03-25 20:38:42 +00:00
|
|
|
*
|
|
|
|
* RequestContext | nsContentPolicyType
|
|
|
|
* ------------------+--------------------
|
2015-06-15 20:45:27 +00:00
|
|
|
* audio | TYPE_INTERNAL_AUDIO
|
2015-03-25 20:38:42 +00:00
|
|
|
* beacon | TYPE_BEACON
|
|
|
|
* cspreport | TYPE_CSP_REPORT
|
|
|
|
* download |
|
2015-07-18 15:51:00 +00:00
|
|
|
* embed | TYPE_INTERNAL_EMBED
|
2015-03-25 20:38:42 +00:00
|
|
|
* eventsource |
|
|
|
|
* favicon |
|
|
|
|
* fetch | TYPE_FETCH
|
|
|
|
* font | TYPE_FONT
|
|
|
|
* form |
|
2015-07-13 21:06:53 +00:00
|
|
|
* frame | TYPE_INTERNAL_FRAME
|
2015-03-25 20:38:42 +00:00
|
|
|
* hyperlink |
|
2015-07-13 21:06:53 +00:00
|
|
|
* iframe | TYPE_INTERNAL_IFRAME
|
2015-09-20 21:55:44 +00:00
|
|
|
* image | TYPE_INTERNAL_IMAGE, TYPE_INTERNAL_IMAGE_PRELOAD
|
2015-03-25 20:38:42 +00:00
|
|
|
* imageset | TYPE_IMAGESET
|
|
|
|
* import | Not supported by Gecko
|
|
|
|
* internal | TYPE_DOCUMENT, TYPE_XBL, TYPE_OTHER
|
|
|
|
* location |
|
2015-06-02 19:42:19 +00:00
|
|
|
* manifest | TYPE_WEB_MANIFEST
|
2015-07-18 15:51:00 +00:00
|
|
|
* object | TYPE_INTERNAL_OBJECT
|
2015-03-25 20:38:42 +00:00
|
|
|
* ping | TYPE_PING
|
|
|
|
* plugin | TYPE_OBJECT_SUBREQUEST
|
|
|
|
* prefetch |
|
2015-09-20 21:55:44 +00:00
|
|
|
* script | TYPE_INTERNAL_SCRIPT, TYPE_INTERNAL_SCRIPT_PRELOAD
|
2015-06-17 01:21:08 +00:00
|
|
|
* sharedworker | TYPE_INTERNAL_SHARED_WORKER
|
2015-03-25 20:38:42 +00:00
|
|
|
* subresource | Not supported by Gecko
|
2015-09-20 21:55:44 +00:00
|
|
|
* style | TYPE_INTERNAL_STYLESHEET, TYPE_INTERNAL_STYLESHEET_PRELOAD
|
2015-06-15 20:45:27 +00:00
|
|
|
* track | TYPE_INTERNAL_TRACK
|
|
|
|
* video | TYPE_INTERNAL_VIDEO
|
2015-06-17 01:21:08 +00:00
|
|
|
* worker | TYPE_INTERNAL_WORKER
|
2015-08-06 18:17:24 +00:00
|
|
|
* xmlhttprequest | TYPE_INTERNAL_XMLHTTPREQUEST
|
|
|
|
* eventsource | TYPE_INTERNAL_EVENTSOURCE
|
2015-03-25 20:38:42 +00:00
|
|
|
* xslt | TYPE_XSLT
|
|
|
|
*
|
|
|
|
* TODO: Figure out if TYPE_REFRESH maps to anything useful
|
|
|
|
* TODO: Figure out if TYPE_DTD maps to anything useful
|
|
|
|
* TODO: Figure out if TYPE_WEBSOCKET maps to anything useful
|
|
|
|
* TODO: Add a content type for prefetch
|
|
|
|
* TODO: Use the content type for manifest when it becomes available
|
|
|
|
* TODO: Add a content type for location
|
|
|
|
* TODO: Add a content type for hyperlink
|
|
|
|
* TODO: Add a content type for form
|
|
|
|
* TODO: Add a content type for favicon
|
|
|
|
* TODO: Add a content type for download
|
|
|
|
*/
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
class Request;
|
|
|
|
|
2014-12-23 15:56:19 +00:00
|
|
|
#define kFETCH_CLIENT_REFERRER_STR "about:client"
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class InternalRequest final
|
2014-09-24 05:03:20 +00:00
|
|
|
{
|
|
|
|
friend class Request;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalRequest)
|
|
|
|
|
|
|
|
explicit InternalRequest()
|
|
|
|
: mMethod("GET")
|
2014-10-02 17:59:20 +00:00
|
|
|
, mHeaders(new InternalHeaders(HeadersGuardEnum::None))
|
2014-12-23 15:56:19 +00:00
|
|
|
, mReferrer(NS_LITERAL_STRING(kFETCH_CLIENT_REFERRER_STR))
|
2014-09-24 05:03:20 +00:00
|
|
|
, mMode(RequestMode::No_cors)
|
|
|
|
, mCredentialsMode(RequestCredentials::Omit)
|
2015-10-22 18:07:32 +00:00
|
|
|
, mResponseTainting(LoadTainting::Basic)
|
2015-01-08 00:24:40 +00:00
|
|
|
, mCacheMode(RequestCache::Default)
|
2015-08-31 21:26:29 +00:00
|
|
|
, mRedirectMode(RequestRedirect::Follow)
|
2014-09-24 05:03:20 +00:00
|
|
|
, mAuthenticationFlag(false)
|
|
|
|
, mForceOriginHeader(false)
|
|
|
|
, mPreserveContentCodings(false)
|
2014-10-06 18:01:20 +00:00
|
|
|
// FIXME(nsm): This should be false by default, but will lead to the
|
|
|
|
// algorithm never loading data: URLs right now. See Bug 1018872 about
|
|
|
|
// how certain contexts will override it to set it to true. Fetch
|
|
|
|
// specification does not handle this yet.
|
|
|
|
, mSameOriginDataURL(true)
|
2014-09-24 05:03:20 +00:00
|
|
|
, mSkipServiceWorker(false)
|
|
|
|
, mSynchronous(false)
|
|
|
|
, mUnsafeRequest(false)
|
|
|
|
, mUseURLCredentials(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-20 01:24:24 +00:00
|
|
|
already_AddRefed<InternalRequest> Clone();
|
2014-09-24 05:03:20 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
GetMethod(nsCString& aMethod) const
|
|
|
|
{
|
|
|
|
aMethod.Assign(mMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetMethod(const nsACString& aMethod)
|
|
|
|
{
|
|
|
|
mMethod.Assign(aMethod);
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:01:20 +00:00
|
|
|
bool
|
|
|
|
HasSimpleMethod() const
|
|
|
|
{
|
|
|
|
return mMethod.LowerCaseEqualsASCII("get") ||
|
|
|
|
mMethod.LowerCaseEqualsASCII("post") ||
|
|
|
|
mMethod.LowerCaseEqualsASCII("head");
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
void
|
|
|
|
GetURL(nsCString& aURL) const
|
|
|
|
{
|
|
|
|
aURL.Assign(mURL);
|
|
|
|
}
|
|
|
|
|
2015-01-07 21:47:18 +00:00
|
|
|
void
|
|
|
|
SetURL(const nsACString& aURL)
|
|
|
|
{
|
|
|
|
mURL.Assign(aURL);
|
|
|
|
}
|
|
|
|
|
2014-12-23 15:56:19 +00:00
|
|
|
void
|
|
|
|
GetReferrer(nsAString& aReferrer) const
|
2014-09-24 05:03:20 +00:00
|
|
|
{
|
2014-12-23 15:56:19 +00:00
|
|
|
aReferrer.Assign(mReferrer);
|
2014-09-24 05:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-23 15:56:19 +00: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 05:03:20 +00:00
|
|
|
}
|
|
|
|
|
2014-12-24 10:08:41 +00:00
|
|
|
bool
|
|
|
|
SkipServiceWorker() const
|
|
|
|
{
|
|
|
|
return mSkipServiceWorker;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetSkipServiceWorker()
|
|
|
|
{
|
|
|
|
mSkipServiceWorker = true;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
bool
|
|
|
|
IsSynchronous() const
|
|
|
|
{
|
|
|
|
return mSynchronous;
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:59:20 +00:00
|
|
|
RequestMode
|
|
|
|
Mode() const
|
|
|
|
{
|
|
|
|
return mMode;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
void
|
|
|
|
SetMode(RequestMode aMode)
|
|
|
|
{
|
|
|
|
mMode = aMode;
|
|
|
|
}
|
|
|
|
|
2015-01-07 23:50:54 +00:00
|
|
|
RequestCredentials
|
|
|
|
GetCredentialsMode() const
|
|
|
|
{
|
|
|
|
return mCredentialsMode;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
void
|
|
|
|
SetCredentialsMode(RequestCredentials aCredentialsMode)
|
|
|
|
{
|
|
|
|
mCredentialsMode = aCredentialsMode;
|
|
|
|
}
|
|
|
|
|
2015-10-22 18:07:32 +00:00
|
|
|
LoadTainting
|
2014-10-06 18:01:20 +00:00
|
|
|
GetResponseTainting() const
|
|
|
|
{
|
|
|
|
return mResponseTainting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 18:07:32 +00:00
|
|
|
MaybeIncreaseResponseTainting(LoadTainting aTainting)
|
2014-10-06 18:01:20 +00:00
|
|
|
{
|
2015-10-22 18:07:32 +00:00
|
|
|
if (aTainting > mResponseTainting) {
|
|
|
|
mResponseTainting = aTainting;
|
|
|
|
}
|
2014-10-06 18:01:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 00:24:40 +00:00
|
|
|
RequestCache
|
|
|
|
GetCacheMode() const
|
|
|
|
{
|
|
|
|
return mCacheMode;
|
|
|
|
}
|
|
|
|
|
2015-03-22 17:12:43 +00:00
|
|
|
void
|
|
|
|
SetCacheMode(RequestCache aCacheMode)
|
|
|
|
{
|
|
|
|
mCacheMode = aCacheMode;
|
|
|
|
}
|
|
|
|
|
2015-08-31 21:26:29 +00:00
|
|
|
RequestRedirect
|
|
|
|
GetRedirectMode() const
|
|
|
|
{
|
|
|
|
return mRedirectMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetRedirectMode(RequestRedirect aRedirectMode)
|
|
|
|
{
|
|
|
|
mRedirectMode = aRedirectMode;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
nsContentPolicyType
|
2015-01-27 23:43:09 +00:00
|
|
|
ContentPolicyType() const
|
2014-09-24 05:03:20 +00:00
|
|
|
{
|
2015-01-27 23:43:09 +00:00
|
|
|
return mContentPolicyType;
|
2014-09-24 05:03:20 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 13:08:00 +00:00
|
|
|
void
|
2015-03-25 20:38:42 +00:00
|
|
|
SetContentPolicyType(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
|
|
|
RequestContext
|
|
|
|
Context() const
|
|
|
|
{
|
2015-06-15 20:12:45 +00:00
|
|
|
return MapContentPolicyTypeToRequestContext(mContentPolicyType);
|
2015-03-02 13:08:00 +00:00
|
|
|
}
|
|
|
|
|
2014-10-06 18:01:20 +00:00
|
|
|
bool
|
|
|
|
UnsafeRequest() const
|
|
|
|
{
|
|
|
|
return mUnsafeRequest;
|
|
|
|
}
|
|
|
|
|
2015-01-07 23:50:54 +00:00
|
|
|
void
|
|
|
|
SetUnsafeRequest()
|
|
|
|
{
|
|
|
|
mUnsafeRequest = true;
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:59:20 +00:00
|
|
|
InternalHeaders*
|
|
|
|
Headers()
|
2014-09-24 05:03:20 +00:00
|
|
|
{
|
|
|
|
return mHeaders;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ForceOriginHeader()
|
|
|
|
{
|
|
|
|
return mForceOriginHeader;
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:01:20 +00:00
|
|
|
bool
|
|
|
|
SameOriginDataURL() const
|
|
|
|
{
|
|
|
|
return mSameOriginDataURL;
|
|
|
|
}
|
|
|
|
|
2015-01-07 21:47:18 +00:00
|
|
|
void
|
|
|
|
UnsetSameOriginDataURL()
|
|
|
|
{
|
|
|
|
mSameOriginDataURL = false;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
void
|
|
|
|
SetBody(nsIInputStream* aStream)
|
|
|
|
{
|
2014-12-10 08:51:59 +00:00
|
|
|
// A request's body may not be reset once set.
|
2015-08-10 19:06:00 +00:00
|
|
|
MOZ_ASSERT_IF(aStream, !mBodyStream);
|
2014-09-24 05:03:20 +00:00
|
|
|
mBodyStream = aStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Will return the original stream!
|
|
|
|
// Use a tee or copy if you don't want to erase the original.
|
|
|
|
void
|
|
|
|
GetBody(nsIInputStream** aStream)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIInputStream> s = mBodyStream;
|
|
|
|
s.forget(aStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The global is used as the client for the new object.
|
|
|
|
already_AddRefed<InternalRequest>
|
|
|
|
GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult& aRv) const;
|
|
|
|
|
2015-03-27 10:47:00 +00:00
|
|
|
bool
|
|
|
|
WasCreatedByFetchEvent() const
|
|
|
|
{
|
|
|
|
return mCreatedByFetchEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetCreatedByFetchEvent()
|
|
|
|
{
|
|
|
|
mCreatedByFetchEvent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearCreatedByFetchEvent()
|
|
|
|
{
|
|
|
|
mCreatedByFetchEvent = false;
|
|
|
|
}
|
|
|
|
|
2015-07-14 20:11:26 +00:00
|
|
|
bool
|
|
|
|
IsNavigationRequest() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsWorkerRequest() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsClientRequest() const;
|
|
|
|
|
2015-09-01 14:58:34 +00:00
|
|
|
static RequestMode
|
|
|
|
MapChannelToRequestMode(nsIChannel* aChannel);
|
2015-07-14 20:11:26 +00:00
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
private:
|
2015-02-20 01:24:24 +00:00
|
|
|
// Does not copy mBodyStream. Use fallible Clone() for complete copy.
|
|
|
|
explicit InternalRequest(const InternalRequest& aOther);
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
~InternalRequest();
|
|
|
|
|
2015-06-15 20:12:45 +00:00
|
|
|
static RequestContext
|
|
|
|
MapContentPolicyTypeToRequestContext(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
2015-09-01 14:58:34 +00:00
|
|
|
static bool
|
|
|
|
IsNavigationContentPolicy(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsWorkerContentPolicy(nsContentPolicyType aContentPolicyType);
|
|
|
|
|
2014-09-24 05:03:20 +00:00
|
|
|
nsCString mMethod;
|
2015-08-13 15:22:19 +00:00
|
|
|
// mURL always stores the url with the ref stripped
|
2014-09-24 05:03:20 +00:00
|
|
|
nsCString mURL;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<InternalHeaders> mHeaders;
|
2014-09-24 05:03:20 +00:00
|
|
|
nsCOMPtr<nsIInputStream> mBodyStream;
|
|
|
|
|
2015-01-27 23:43:09 +00:00
|
|
|
nsContentPolicyType mContentPolicyType;
|
2014-09-24 05:03:20 +00:00
|
|
|
|
2014-12-23 15:56:19 +00:00
|
|
|
// Empty string: no-referrer
|
|
|
|
// "about:client": client (default)
|
|
|
|
// URL: an URL
|
|
|
|
nsString mReferrer;
|
2014-09-24 05:03:20 +00:00
|
|
|
|
|
|
|
RequestMode mMode;
|
|
|
|
RequestCredentials mCredentialsMode;
|
2015-10-22 18:07:32 +00:00
|
|
|
LoadTainting mResponseTainting;
|
2015-01-08 00:24:40 +00:00
|
|
|
RequestCache mCacheMode;
|
2015-08-31 21:26:29 +00:00
|
|
|
RequestRedirect mRedirectMode;
|
2014-09-24 05:03:20 +00:00
|
|
|
|
|
|
|
bool mAuthenticationFlag;
|
|
|
|
bool mForceOriginHeader;
|
|
|
|
bool mPreserveContentCodings;
|
|
|
|
bool mSameOriginDataURL;
|
|
|
|
bool mSandboxedStorageAreaURLs;
|
|
|
|
bool mSkipServiceWorker;
|
|
|
|
bool mSynchronous;
|
|
|
|
bool mUnsafeRequest;
|
|
|
|
bool mUseURLCredentials;
|
2015-03-27 10:47:00 +00: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;
|
2014-09-24 05:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_InternalRequest_h
|