2001-09-26 03:31:24 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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/. */
|
2001-01-12 23:06:48 +03:00
|
|
|
|
2006-03-31 12:00:42 +04:00
|
|
|
/*
|
|
|
|
* A service that provides methods for synchronously loading a DOM in various ways.
|
|
|
|
*/
|
|
|
|
|
2006-06-16 00:30:44 +04:00
|
|
|
#include "nsSyncLoadService.h"
|
2002-10-09 11:03:15 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIChannel.h"
|
2005-03-07 22:46:06 +03:00
|
|
|
#include "nsIChannelEventSink.h"
|
2010-08-05 06:15:55 +04:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2002-10-09 11:03:15 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2016-06-10 03:56:23 +03:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIURI.h"
|
2002-10-09 11:03:15 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWeakReference.h"
|
2001-08-03 00:29:20 +04:00
|
|
|
#include "nsIDocument.h"
|
2012-07-02 03:45:59 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2013-08-14 10:56:21 +04:00
|
|
|
#include "nsContentUtils.h" // for kLoadAsData
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2001-08-03 00:29:20 +04:00
|
|
|
#include "nsNetUtil.h"
|
2006-06-16 00:30:44 +04:00
|
|
|
#include "nsStreamUtils.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2017-10-26 12:40:12 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-11-18 16:47:20 +03:00
|
|
|
using mozilla::net::ReferrerPolicy;
|
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
/**
|
|
|
|
* This class manages loading a single XML document
|
|
|
|
*/
|
|
|
|
|
2011-06-18 07:05:41 +04:00
|
|
|
class nsSyncLoader : public nsIStreamListener,
|
2005-03-07 22:46:06 +03:00
|
|
|
public nsIChannelEventSink,
|
2002-10-09 11:03:15 +04:00
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
2018-06-16 17:21:46 +03:00
|
|
|
nsSyncLoader()
|
|
|
|
: mLoading(false)
|
|
|
|
, mAsyncLoadStatus(NS_ERROR_NOT_INITIALIZED)
|
|
|
|
{
|
|
|
|
}
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
nsresult LoadDocument(nsIChannel* aChannel,
|
|
|
|
bool aChannelIsSync, bool aForceToXML,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
2018-05-11 20:46:15 +03:00
|
|
|
nsIDocument** aResult);
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
NS_FORWARD_NSISTREAMLISTENER(mListener->)
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2006-06-16 00:30:44 +04:00
|
|
|
private:
|
2014-06-25 06:09:15 +04:00
|
|
|
virtual ~nsSyncLoader();
|
|
|
|
|
2002-10-09 12:06:53 +04:00
|
|
|
nsresult PushAsyncStream(nsIStreamListener* aListener);
|
|
|
|
nsresult PushSyncStream(nsIStreamListener* aListener);
|
2002-10-09 11:03:15 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2011-06-18 07:05:41 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mLoading;
|
2011-06-18 07:05:41 +04:00
|
|
|
nsresult mAsyncLoadStatus;
|
2002-10-09 11:03:15 +04:00
|
|
|
};
|
|
|
|
|
2003-05-05 13:17:36 +04:00
|
|
|
class nsForceXMLListener : public nsIStreamListener
|
|
|
|
{
|
2014-06-25 06:09:15 +04:00
|
|
|
virtual ~nsForceXMLListener();
|
|
|
|
|
2003-05-05 13:17:36 +04:00
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsForceXMLListener(nsIStreamListener* aListener);
|
2003-05-05 13:17:36 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_NSISTREAMLISTENER(mListener->)
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsForceXMLListener::nsForceXMLListener(nsIStreamListener* aListener)
|
|
|
|
: mListener(aListener)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsForceXMLListener::~nsForceXMLListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsForceXMLListener,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
2003-05-05 13:17:36 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsForceXMLListener::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
|
|
|
|
{
|
|
|
|
nsresult status;
|
|
|
|
aRequest->GetStatus(&status);
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
|
|
|
if (channel && NS_SUCCEEDED(status)) {
|
|
|
|
channel->SetContentType(NS_LITERAL_CSTRING("text/xml"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return mListener->OnStartRequest(aRequest, aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsForceXMLListener::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
|
|
|
|
nsresult aStatusCode)
|
|
|
|
{
|
|
|
|
return mListener->OnStopRequest(aRequest, aContext, aStatusCode);
|
|
|
|
}
|
|
|
|
|
2001-01-12 23:06:48 +03:00
|
|
|
nsSyncLoader::~nsSyncLoader()
|
|
|
|
{
|
2001-08-03 00:29:20 +04:00
|
|
|
if (mLoading && mChannel) {
|
|
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
|
|
}
|
2001-01-12 23:06:48 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSyncLoader,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver,
|
|
|
|
nsIChannelEventSink,
|
|
|
|
nsIInterfaceRequestor,
|
|
|
|
nsISupportsWeakReference)
|
2001-01-12 23:06:48 +03:00
|
|
|
|
2003-05-05 13:17:36 +04:00
|
|
|
nsresult
|
2002-10-09 11:03:15 +04:00
|
|
|
nsSyncLoader::LoadDocument(nsIChannel* aChannel,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aChannelIsSync,
|
|
|
|
bool aForceToXML,
|
2014-11-18 16:47:20 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
2018-05-11 20:46:15 +03:00
|
|
|
nsIDocument **aResult)
|
2001-01-12 23:06:48 +03:00
|
|
|
{
|
2015-10-27 00:22:59 +03:00
|
|
|
NS_ENSURE_ARG(aChannel);
|
2002-06-15 03:54:18 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2002-06-15 03:54:18 +04:00
|
|
|
nsresult rv = NS_OK;
|
2001-01-12 23:06:48 +03:00
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
mChannel = aChannel;
|
2006-05-05 15:48:07 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(mChannel);
|
|
|
|
if (http) {
|
2016-12-20 06:49:32 +03:00
|
|
|
rv = http->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
|
|
|
NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"),
|
|
|
|
false);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2015-10-27 00:22:59 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
|
|
|
|
if (loadInfo) {
|
|
|
|
nsCOMPtr<nsIURI> loaderUri;
|
|
|
|
loadInfo->TriggeringPrincipal()->GetURI(getter_AddRefs(loaderUri));
|
|
|
|
if (loaderUri) {
|
2016-12-20 06:49:32 +03:00
|
|
|
rv = http->SetReferrerWithPolicy(loaderUri, aReferrerPolicy);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2015-10-27 00:22:59 +03:00
|
|
|
}
|
2006-06-16 00:30:44 +04:00
|
|
|
}
|
2006-05-05 15:48:07 +04:00
|
|
|
}
|
2001-01-12 23:06:48 +03:00
|
|
|
|
2008-02-27 06:45:29 +03:00
|
|
|
// Hook us up to listen to redirects and the like.
|
|
|
|
// Do this before setting up the cross-site proxy since
|
|
|
|
// that installs its own proxies.
|
|
|
|
mChannel->SetNotificationCallbacks(this);
|
2001-08-03 00:29:20 +04:00
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
// Get the loadgroup of the channel
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
rv = aChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
2001-08-03 00:29:20 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
// Create document
|
2006-06-16 00:30:44 +04:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = NS_NewXMLDocument(getter_AddRefs(document));
|
2002-03-19 17:14:27 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-12 23:06:48 +03:00
|
|
|
|
2003-01-15 01:36:57 +03:00
|
|
|
// Start the document load. Do this before we attach the load listener
|
|
|
|
// since we reset the document which drops all observers.
|
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
2017-07-06 15:00:35 +03:00
|
|
|
rv = document->StartDocumentLoad(kLoadAsData, mChannel,
|
|
|
|
loadGroup, nullptr,
|
2003-01-15 01:36:57 +03:00
|
|
|
getter_AddRefs(listener),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2003-01-15 01:36:57 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-05-05 13:17:36 +04:00
|
|
|
if (aForceToXML) {
|
|
|
|
nsCOMPtr<nsIStreamListener> forceListener =
|
|
|
|
new nsForceXMLListener(listener);
|
|
|
|
listener.swap(forceListener);
|
|
|
|
}
|
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
if (aChannelIsSync) {
|
|
|
|
rv = PushSyncStream(listener);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = PushAsyncStream(listener);
|
|
|
|
}
|
|
|
|
|
2006-05-05 15:48:07 +04:00
|
|
|
http = do_QueryInterface(mChannel);
|
2011-06-18 07:05:41 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && http) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool succeeded;
|
2011-06-18 07:05:41 +04:00
|
|
|
if (NS_FAILED(http->GetRequestSucceeded(&succeeded)) || !succeeded) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
2006-05-05 15:48:07 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mChannel = nullptr;
|
2002-10-09 11:03:15 +04:00
|
|
|
|
|
|
|
// check that the load succeeded
|
2002-06-15 03:54:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-12 23:06:48 +03:00
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
NS_ENSURE_TRUE(document->GetRootElement(), NS_ERROR_FAILURE);
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2018-05-11 20:46:15 +03:00
|
|
|
document.forget(aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-10-09 11:03:15 +04:00
|
|
|
}
|
|
|
|
|
2002-10-09 12:06:53 +04:00
|
|
|
nsresult
|
2002-10-09 11:03:15 +04:00
|
|
|
nsSyncLoader::PushAsyncStream(nsIStreamListener* aListener)
|
|
|
|
{
|
2011-06-18 07:05:41 +04:00
|
|
|
mListener = aListener;
|
|
|
|
|
|
|
|
mAsyncLoadStatus = NS_OK;
|
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
// Start reading from the channel
|
2015-10-27 00:22:59 +03:00
|
|
|
nsresult rv = mChannel->AsyncOpen2(this);
|
2002-10-09 11:03:15 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// process events until we're finished.
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoading = true;
|
2006-05-10 21:30:15 +04:00
|
|
|
nsIThread *thread = NS_GetCurrentThread();
|
2002-10-09 11:03:15 +04:00
|
|
|
while (mLoading && NS_SUCCEEDED(rv)) {
|
2017-07-06 15:00:35 +03:00
|
|
|
bool processedEvent;
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = thread->ProcessNextEvent(true, &processedEvent);
|
2006-05-10 21:30:15 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && !processedEvent)
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-10-09 11:03:15 +04:00
|
|
|
}
|
2001-01-12 23:06:48 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2011-06-18 07:05:41 +04:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-02-21 03:00:44 +03:00
|
|
|
// Note that if AsyncOpen failed that's ok -- the only caller of
|
|
|
|
// this method nulls out mChannel immediately after we return.
|
2011-06-18 07:05:41 +04:00
|
|
|
|
|
|
|
return mAsyncLoadStatus;
|
2002-10-09 11:03:15 +04:00
|
|
|
}
|
|
|
|
|
2002-10-09 12:06:53 +04:00
|
|
|
nsresult
|
2002-10-09 11:03:15 +04:00
|
|
|
nsSyncLoader::PushSyncStream(nsIStreamListener* aListener)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIInputStream> in;
|
2015-10-27 00:22:59 +03:00
|
|
|
nsresult rv = mChannel->Open2(getter_AddRefs(in));
|
2002-10-09 11:03:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoading = true;
|
2017-10-19 12:39:30 +03:00
|
|
|
rv = nsSyncLoadService::PushSyncStreamToListener(in.forget(), aListener,
|
|
|
|
mChannel);
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoading = false;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-01-12 23:06:48 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-06-18 07:05:41 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSyncLoader::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
|
2001-01-12 23:06:48 +03:00
|
|
|
{
|
2011-06-18 07:05:41 +04:00
|
|
|
return mListener->OnStartRequest(aRequest, aContext);
|
2001-01-12 23:06:48 +03:00
|
|
|
}
|
|
|
|
|
2011-06-18 07:05:41 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSyncLoader::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
|
|
|
|
nsresult aStatusCode)
|
2001-01-12 23:06:48 +03:00
|
|
|
{
|
2011-06-18 07:05:41 +04:00
|
|
|
if (NS_SUCCEEDED(mAsyncLoadStatus) && NS_FAILED(aStatusCode)) {
|
|
|
|
mAsyncLoadStatus = aStatusCode;
|
2001-01-12 23:06:48 +03:00
|
|
|
}
|
2011-06-18 07:05:41 +04:00
|
|
|
nsresult rv = mListener->OnStopRequest(aRequest, aContext, aStatusCode);
|
|
|
|
if (NS_SUCCEEDED(mAsyncLoadStatus) && NS_FAILED(rv)) {
|
|
|
|
mAsyncLoadStatus = rv;
|
2001-01-12 23:06:48 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoading = false;
|
2001-01-12 23:06:48 +03:00
|
|
|
|
2011-06-18 07:05:41 +04:00
|
|
|
return rv;
|
2001-01-12 23:06:48 +03:00
|
|
|
}
|
2002-06-15 03:54:18 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-05 06:15:55 +04:00
|
|
|
nsSyncLoader::AsyncOnChannelRedirect(nsIChannel *aOldChannel,
|
|
|
|
nsIChannel *aNewChannel,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags,
|
2010-08-05 06:15:55 +04:00
|
|
|
nsIAsyncVerifyRedirectCallback *callback)
|
2002-06-15 03:54:18 +04:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aNewChannel, "Redirecting to null channel?");
|
2002-06-15 03:54:18 +04:00
|
|
|
|
|
|
|
mChannel = aNewChannel;
|
|
|
|
|
2010-08-05 06:15:55 +04:00
|
|
|
callback->OnRedirectVerifyCallback(NS_OK);
|
2002-06-15 03:54:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSyncLoader::GetInterface(const nsIID & aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
return QueryInterface(aIID, aResult);
|
|
|
|
}
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2006-06-16 00:30:44 +04:00
|
|
|
/* static */
|
2002-10-09 11:03:15 +04:00
|
|
|
nsresult
|
2015-10-27 00:22:59 +03:00
|
|
|
nsSyncLoadService::LoadDocument(nsIURI *aURI,
|
|
|
|
nsContentPolicyType aContentPolicyType,
|
|
|
|
nsIPrincipal *aLoaderPrincipal,
|
|
|
|
nsSecurityFlags aSecurityFlags,
|
|
|
|
nsILoadGroup *aLoadGroup,
|
|
|
|
bool aForceToXML,
|
2014-11-18 16:47:20 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
2018-05-11 20:46:15 +03:00
|
|
|
nsIDocument** aResult)
|
2002-10-09 11:03:15 +04:00
|
|
|
{
|
2006-06-16 00:30:44 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2014-09-21 20:36:25 +04:00
|
|
|
nsresult rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
aURI,
|
|
|
|
aLoaderPrincipal,
|
2015-10-27 00:22:59 +03:00
|
|
|
aSecurityFlags,
|
|
|
|
aContentPolicyType,
|
2018-01-24 19:17:31 +03:00
|
|
|
nullptr, // PerformanceStorage
|
2006-06-16 00:30:44 +04:00
|
|
|
aLoadGroup);
|
2002-10-09 11:03:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-06-16 00:30:44 +04:00
|
|
|
if (!aForceToXML) {
|
|
|
|
channel->SetContentType(NS_LITERAL_CSTRING("text/xml"));
|
|
|
|
}
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false, isResource = false;
|
2015-12-01 07:13:20 +03:00
|
|
|
// if the load needs to enforce CORS, then force the load to be async
|
2015-10-27 00:22:59 +03:00
|
|
|
bool isSync =
|
2015-12-01 07:13:20 +03:00
|
|
|
!(aSecurityFlags & nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS) &&
|
|
|
|
((NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome) ||
|
|
|
|
(NS_SUCCEEDED(aURI->SchemeIs("resource", &isResource)) && isResource));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSyncLoader> loader = new nsSyncLoader();
|
2015-10-27 00:22:59 +03:00
|
|
|
return loader->LoadDocument(channel, isSync, aForceToXML,
|
|
|
|
aReferrerPolicy, aResult);
|
2002-10-09 11:03:15 +04:00
|
|
|
}
|
|
|
|
|
2006-06-16 00:30:44 +04:00
|
|
|
/* static */
|
2002-10-09 11:03:15 +04:00
|
|
|
nsresult
|
2017-10-19 12:39:30 +03:00
|
|
|
nsSyncLoadService::PushSyncStreamToListener(already_AddRefed<nsIInputStream> aIn,
|
2002-10-09 11:03:15 +04:00
|
|
|
nsIStreamListener* aListener,
|
|
|
|
nsIChannel* aChannel)
|
|
|
|
{
|
2018-05-30 22:15:35 +03:00
|
|
|
nsCOMPtr<nsIInputStream> in = std::move(aIn);
|
2017-10-19 12:39:30 +03:00
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
// Set up buffering stream
|
2006-06-16 00:30:44 +04:00
|
|
|
nsresult rv;
|
2002-10-09 11:03:15 +04:00
|
|
|
nsCOMPtr<nsIInputStream> bufferedStream;
|
2017-10-19 12:39:30 +03:00
|
|
|
if (!NS_InputStreamIsBuffered(in)) {
|
2012-10-22 21:51:07 +04:00
|
|
|
int64_t chunkSize;
|
2008-12-18 04:27:43 +03:00
|
|
|
rv = aChannel->GetContentLength(&chunkSize);
|
2013-07-31 01:38:26 +04:00
|
|
|
if (NS_FAILED(rv) || chunkSize < 1) {
|
2008-12-18 04:27:43 +03:00
|
|
|
chunkSize = 4096;
|
|
|
|
}
|
2013-01-15 16:22:03 +04:00
|
|
|
chunkSize = std::min(int64_t(UINT16_MAX), chunkSize);
|
2008-12-18 04:27:43 +03:00
|
|
|
|
2017-10-19 12:39:30 +03:00
|
|
|
rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
|
|
|
|
in.forget(), chunkSize);
|
2006-06-16 00:30:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-10-19 12:39:30 +03:00
|
|
|
in = bufferedStream;
|
2006-06-16 00:30:44 +04:00
|
|
|
}
|
2002-10-09 11:03:15 +04:00
|
|
|
|
|
|
|
// Load
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = aListener->OnStartRequest(aChannel, nullptr);
|
2011-05-19 05:22:59 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t sourceOffset = 0;
|
2011-05-19 05:22:59 +04:00
|
|
|
while (1) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t readCount = 0;
|
2017-10-19 12:39:30 +03:00
|
|
|
rv = in->Available(&readCount);
|
2011-05-19 05:22:59 +04:00
|
|
|
if (NS_FAILED(rv) || !readCount) {
|
|
|
|
if (rv == NS_BASE_STREAM_CLOSED) {
|
|
|
|
// End of file, but not an error
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
break;
|
2007-05-08 02:11:53 +04:00
|
|
|
}
|
2002-10-09 11:03:15 +04:00
|
|
|
|
2012-09-28 10:57:33 +04:00
|
|
|
if (readCount > UINT32_MAX)
|
|
|
|
readCount = UINT32_MAX;
|
2012-08-11 06:44:11 +04:00
|
|
|
|
2017-10-19 12:39:30 +03:00
|
|
|
rv = aListener->OnDataAvailable(aChannel, nullptr, in,
|
2013-01-15 16:22:03 +04:00
|
|
|
(uint32_t)std::min(sourceOffset, (uint64_t)UINT32_MAX),
|
2012-08-22 19:56:38 +04:00
|
|
|
(uint32_t)readCount);
|
2011-05-19 05:22:59 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sourceOffset += readCount;
|
2002-10-09 11:03:15 +04:00
|
|
|
}
|
2011-05-19 05:22:59 +04:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aChannel->Cancel(rv);
|
2002-10-09 11:03:15 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
aListener->OnStopRequest(aChannel, nullptr, rv);
|
2011-05-19 05:22:59 +04:00
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
return rv;
|
|
|
|
}
|