2015-05-03 12:32:37 -07: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-23 22:03:20 -07: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/. */
|
|
|
|
|
|
|
|
#include "InternalRequest.h"
|
|
|
|
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIDocument.h"
|
2015-02-19 17:24:24 -08:00
|
|
|
#include "nsStreamUtils.h"
|
2014-09-23 22:03:20 -07:00
|
|
|
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
|
|
|
#include "mozilla/dom/workers/Workers.h"
|
|
|
|
|
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
// The global is used to extract the principal.
|
|
|
|
already_AddRefed<InternalRequest>
|
|
|
|
InternalRequest::GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
nsRefPtr<InternalRequest> copy = new InternalRequest();
|
|
|
|
copy->mURL.Assign(mURL);
|
|
|
|
copy->SetMethod(mMethod);
|
2014-10-02 10:59:20 -07:00
|
|
|
copy->mHeaders = new InternalHeaders(*mHeaders);
|
2015-01-07 15:50:54 -08:00
|
|
|
copy->SetUnsafeRequest();
|
2014-09-23 22:03:20 -07:00
|
|
|
|
|
|
|
copy->mBodyStream = mBodyStream;
|
2015-01-07 15:50:54 -08:00
|
|
|
copy->mForceOriginHeader = true;
|
|
|
|
// The "client" is not stored in our implementation. Fetch API users should
|
|
|
|
// use the appropriate window/document/principal and other Gecko security
|
|
|
|
// mechanisms as appropriate.
|
|
|
|
copy->mSameOriginDataURL = true;
|
2014-09-23 22:03:20 -07:00
|
|
|
copy->mPreserveContentCodings = true;
|
2015-01-07 15:50:54 -08:00
|
|
|
// The default referrer is already about:client.
|
2014-09-23 22:03:20 -07:00
|
|
|
|
2015-01-27 15:43:09 -08:00
|
|
|
copy->mContentPolicyType = nsIContentPolicy::TYPE_FETCH;
|
2014-09-23 22:03:20 -07:00
|
|
|
copy->mMode = mMode;
|
|
|
|
copy->mCredentialsMode = mCredentialsMode;
|
2015-01-07 16:24:40 -08:00
|
|
|
copy->mCacheMode = mCacheMode;
|
2015-03-27 03:47:00 -07:00
|
|
|
copy->mCreatedByFetchEvent = mCreatedByFetchEvent;
|
2014-09-23 22:03:20 -07:00
|
|
|
return copy.forget();
|
|
|
|
}
|
|
|
|
|
2015-02-19 17:24:24 -08:00
|
|
|
already_AddRefed<InternalRequest>
|
|
|
|
InternalRequest::Clone()
|
|
|
|
{
|
|
|
|
nsRefPtr<InternalRequest> clone = new InternalRequest(*this);
|
|
|
|
|
|
|
|
if (!mBodyStream) {
|
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> clonedBody;
|
|
|
|
nsCOMPtr<nsIInputStream> replacementBody;
|
|
|
|
|
|
|
|
nsresult rv = NS_CloneInputStream(mBodyStream, getter_AddRefs(clonedBody),
|
|
|
|
getter_AddRefs(replacementBody));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) { return nullptr; }
|
|
|
|
|
|
|
|
clone->mBodyStream.swap(clonedBody);
|
|
|
|
if (replacementBody) {
|
|
|
|
mBodyStream.swap(replacementBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalRequest::InternalRequest(const InternalRequest& aOther)
|
|
|
|
: mMethod(aOther.mMethod)
|
|
|
|
, mURL(aOther.mURL)
|
|
|
|
, mHeaders(new InternalHeaders(*aOther.mHeaders))
|
|
|
|
, mContentPolicyType(aOther.mContentPolicyType)
|
|
|
|
, mReferrer(aOther.mReferrer)
|
|
|
|
, mMode(aOther.mMode)
|
|
|
|
, mCredentialsMode(aOther.mCredentialsMode)
|
|
|
|
, mResponseTainting(aOther.mResponseTainting)
|
|
|
|
, mCacheMode(aOther.mCacheMode)
|
|
|
|
, mAuthenticationFlag(aOther.mAuthenticationFlag)
|
|
|
|
, mForceOriginHeader(aOther.mForceOriginHeader)
|
|
|
|
, mPreserveContentCodings(aOther.mPreserveContentCodings)
|
|
|
|
, mSameOriginDataURL(aOther.mSameOriginDataURL)
|
|
|
|
, mSandboxedStorageAreaURLs(aOther.mSandboxedStorageAreaURLs)
|
|
|
|
, mSkipServiceWorker(aOther.mSkipServiceWorker)
|
|
|
|
, mSynchronous(aOther.mSynchronous)
|
|
|
|
, mUnsafeRequest(aOther.mUnsafeRequest)
|
|
|
|
, mUseURLCredentials(aOther.mUseURLCredentials)
|
2015-03-27 03:47:00 -07:00
|
|
|
, mCreatedByFetchEvent(aOther.mCreatedByFetchEvent)
|
2015-02-19 17:24:24 -08:00
|
|
|
{
|
|
|
|
// NOTE: does not copy body stream... use the fallible Clone() for that
|
|
|
|
}
|
|
|
|
|
2014-09-23 22:03:20 -07:00
|
|
|
InternalRequest::~InternalRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-25 13:38:42 -07:00
|
|
|
void
|
|
|
|
InternalRequest::SetContentPolicyType(nsContentPolicyType aContentPolicyType)
|
|
|
|
{
|
|
|
|
mContentPolicyType = aContentPolicyType;
|
2015-06-15 13:12:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
RequestContext
|
|
|
|
InternalRequest::MapContentPolicyTypeToRequestContext(nsContentPolicyType aContentPolicyType)
|
|
|
|
{
|
|
|
|
RequestContext context = RequestContext::Internal;
|
2015-03-25 13:38:42 -07:00
|
|
|
switch (aContentPolicyType) {
|
|
|
|
case nsIContentPolicy::TYPE_OTHER:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
2015-06-16 18:21:08 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Script;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
2015-06-16 18:21:08 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_WORKER:
|
|
|
|
context = RequestContext::Worker;
|
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
|
|
|
|
context = RequestContext::Sharedworker;
|
|
|
|
break;
|
2015-03-25 13:38:42 -07:00
|
|
|
case nsIContentPolicy::TYPE_IMAGE:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Image;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_STYLESHEET:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Style;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_OBJECT:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Object;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_DOCUMENT:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_SUBDOCUMENT:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Iframe;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_REFRESH:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_XBL:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_PING:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Ping;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_XMLHTTPREQUEST:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Xmlhttprequest;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_OBJECT_SUBREQUEST:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Plugin;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_DTD:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_FONT:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Font;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
2015-06-15 13:45:27 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_AUDIO:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Audio;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
2015-06-15 13:45:27 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_VIDEO:
|
|
|
|
context = RequestContext::Video;
|
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_TRACK:
|
|
|
|
context = RequestContext::Track;
|
|
|
|
break;
|
2015-03-25 13:38:42 -07:00
|
|
|
case nsIContentPolicy::TYPE_WEBSOCKET:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_CSP_REPORT:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Cspreport;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_XSLT:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Xslt;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_BEACON:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Beacon;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_FETCH:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Fetch;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_IMAGESET:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Imageset;
|
2015-03-25 13:38:42 -07:00
|
|
|
break;
|
2015-06-02 12:42:19 -07:00
|
|
|
case nsIContentPolicy::TYPE_WEB_MANIFEST:
|
2015-06-15 13:12:45 -07:00
|
|
|
context = RequestContext::Manifest;
|
2015-06-02 12:42:19 -07:00
|
|
|
break;
|
2015-03-25 13:38:42 -07:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "Unhandled nsContentPolicyType value");
|
|
|
|
break;
|
|
|
|
}
|
2015-06-15 13:12:45 -07:00
|
|
|
return context;
|
2015-03-25 13:38:42 -07:00
|
|
|
}
|
|
|
|
|
2014-09-23 22:03:20 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|