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/. */
|
|
|
|
|
|
|
|
#include "InternalRequest.h"
|
|
|
|
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIDocument.h"
|
2015-02-20 04:24:24 +03:00
|
|
|
#include "nsStreamUtils.h"
|
2014-09-24 09:03:20 +04: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 21:59:20 +04:00
|
|
|
copy->mHeaders = new InternalHeaders(*mHeaders);
|
2015-01-08 02:50:54 +03:00
|
|
|
copy->SetUnsafeRequest();
|
2014-09-24 09:03:20 +04:00
|
|
|
|
|
|
|
copy->mBodyStream = mBodyStream;
|
2015-01-08 02:50:54 +03: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-24 09:03:20 +04:00
|
|
|
copy->mPreserveContentCodings = true;
|
2015-01-08 02:50:54 +03:00
|
|
|
// The default referrer is already about:client.
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2015-01-28 02:43:09 +03:00
|
|
|
copy->mContentPolicyType = nsIContentPolicy::TYPE_FETCH;
|
2014-09-24 09:03:20 +04:00
|
|
|
copy->mMode = mMode;
|
|
|
|
copy->mCredentialsMode = mCredentialsMode;
|
2015-01-08 03:24:40 +03:00
|
|
|
copy->mCacheMode = mCacheMode;
|
2015-03-27 13:47:00 +03:00
|
|
|
copy->mCreatedByFetchEvent = mCreatedByFetchEvent;
|
2014-09-24 09:03:20 +04:00
|
|
|
return copy.forget();
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:24:24 +03: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 13:47:00 +03:00
|
|
|
, mCreatedByFetchEvent(aOther.mCreatedByFetchEvent)
|
2015-02-20 04:24:24 +03:00
|
|
|
{
|
|
|
|
// NOTE: does not copy body stream... use the fallible Clone() for that
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
InternalRequest::~InternalRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-25 23:38:42 +03:00
|
|
|
void
|
|
|
|
InternalRequest::SetContentPolicyType(nsContentPolicyType aContentPolicyType)
|
|
|
|
{
|
|
|
|
mContentPolicyType = aContentPolicyType;
|
2015-06-15 23:12:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
RequestContext
|
|
|
|
InternalRequest::MapContentPolicyTypeToRequestContext(nsContentPolicyType aContentPolicyType)
|
|
|
|
{
|
|
|
|
RequestContext context = RequestContext::Internal;
|
2015-03-25 23:38:42 +03:00
|
|
|
switch (aContentPolicyType) {
|
|
|
|
case nsIContentPolicy::TYPE_OTHER:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_SCRIPT:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Script;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_IMAGE:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Image;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_STYLESHEET:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Style;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_OBJECT:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Object;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_DOCUMENT:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_SUBDOCUMENT:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Iframe;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_REFRESH:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_XBL:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_PING:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Ping;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_XMLHTTPREQUEST:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Xmlhttprequest;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_OBJECT_SUBREQUEST:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Plugin;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_DTD:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_FONT:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Font;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
2015-06-17 00:48:15 +03:00
|
|
|
case nsIContentPolicy::TYPE_MEDIA:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Audio;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_WEBSOCKET:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Internal;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_CSP_REPORT:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Cspreport;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_XSLT:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Xslt;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_BEACON:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Beacon;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_FETCH:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Fetch;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
|
|
|
case nsIContentPolicy::TYPE_IMAGESET:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Imageset;
|
2015-03-25 23:38:42 +03:00
|
|
|
break;
|
2015-06-02 22:42:19 +03:00
|
|
|
case nsIContentPolicy::TYPE_WEB_MANIFEST:
|
2015-06-15 23:12:45 +03:00
|
|
|
context = RequestContext::Manifest;
|
2015-06-02 22:42:19 +03:00
|
|
|
break;
|
2015-03-25 23:38:42 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "Unhandled nsContentPolicyType value");
|
|
|
|
break;
|
|
|
|
}
|
2015-06-15 23:12:45 +03:00
|
|
|
return context;
|
2015-03-25 23:38:42 +03:00
|
|
|
}
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|