зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1218029 - Adds IncrementalStreamLoader interface stubs. r=djvj
--HG-- extra : commitid : J0UubFG9gvz
This commit is contained in:
Родитель
a9a0ca3af0
Коммит
66199890c4
|
@ -157,10 +157,10 @@ nsScriptLoader::~nsScriptLoader()
|
|||
// subtree in the meantime and therefore aren't actually going away.
|
||||
for (uint32_t j = 0; j < mPendingChildLoaders.Length(); ++j) {
|
||||
mPendingChildLoaders[j]->RemoveExecuteBlocker();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsScriptLoader, nsIStreamLoaderObserver)
|
||||
NS_IMPL_ISUPPORTS(nsScriptLoader, nsIIncrementalStreamLoaderObserver)
|
||||
|
||||
// Helper method for checking if the script element is an event-handler
|
||||
// This means that it has both a for-attribute and a event-attribute.
|
||||
|
@ -269,7 +269,7 @@ nsScriptLoader::ShouldLoadScript(nsIDocument* aDocument,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class ContextMediator : public nsIStreamLoaderObserver
|
||||
class ContextMediator : public nsIIncrementalStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
explicit ContextMediator(nsScriptLoader *aScriptLoader, nsISupports *aContext)
|
||||
|
@ -277,7 +277,7 @@ public:
|
|||
, mContext(aContext) {}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
|
||||
|
||||
private:
|
||||
virtual ~ContextMediator() {}
|
||||
|
@ -285,10 +285,10 @@ private:
|
|||
nsCOMPtr<nsISupports> mContext;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ContextMediator, nsIStreamLoaderObserver)
|
||||
NS_IMPL_ISUPPORTS(ContextMediator, nsIIncrementalStreamLoaderObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContextMediator::OnStreamComplete(nsIStreamLoader* aLoader,
|
||||
ContextMediator::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
nsISupports* aContext,
|
||||
nsresult aStatus,
|
||||
uint32_t aStringLen,
|
||||
|
@ -385,8 +385,8 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
|
|||
|
||||
RefPtr<ContextMediator> mediator = new ContextMediator(this, aRequest);
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), mediator);
|
||||
nsCOMPtr<nsIIncrementalStreamLoader> loader;
|
||||
rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), mediator);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return channel->AsyncOpen2(loader);
|
||||
|
@ -1439,7 +1439,7 @@ nsScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
|
||||
nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
nsISupports* aContext,
|
||||
nsresult aStatus,
|
||||
uint32_t aStringLen,
|
||||
|
@ -1535,7 +1535,7 @@ nsScriptLoader::NumberOfProcessors()
|
|||
|
||||
nsresult
|
||||
nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest,
|
||||
nsIStreamLoader* aLoader,
|
||||
nsIIncrementalStreamLoader* aLoader,
|
||||
nsresult aStatus,
|
||||
uint32_t aStringLen,
|
||||
const uint8_t* aString)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsIIncrementalStreamLoader.h"
|
||||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/dom/SRIMetadata.h"
|
||||
#include "mozilla/LinkedList.h"
|
||||
|
@ -195,7 +195,7 @@ public:
|
|||
// Script loader implementation
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
class nsScriptLoader final : public nsIStreamLoaderObserver
|
||||
class nsScriptLoader final : public nsIIncrementalStreamLoaderObserver
|
||||
{
|
||||
class MOZ_STACK_CLASS AutoCurrentScriptUpdater
|
||||
{
|
||||
|
@ -223,7 +223,7 @@ public:
|
|||
explicit nsScriptLoader(nsIDocument* aDocument);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
|
||||
|
||||
/**
|
||||
* The loader maintains a weak reference to the document with
|
||||
|
@ -489,7 +489,7 @@ private:
|
|||
|
||||
uint32_t NumberOfProcessors();
|
||||
nsresult PrepareLoadedRequest(nsScriptLoadRequest* aRequest,
|
||||
nsIStreamLoader* aLoader,
|
||||
nsIIncrementalStreamLoader* aLoader,
|
||||
nsresult aStatus,
|
||||
uint32_t aStringLen,
|
||||
const uint8_t* aString);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsIIncrementalStreamLoader.h"
|
||||
#include "nsIUnicharStreamLoader.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -317,7 +317,7 @@ SRICheck::VerifyIntegrity(const SRIMetadata& aMetadata,
|
|||
|
||||
/* static */ nsresult
|
||||
SRICheck::VerifyIntegrity(const SRIMetadata& aMetadata,
|
||||
nsIStreamLoader* aLoader,
|
||||
nsIIncrementalStreamLoader* aLoader,
|
||||
const CORSMode aCORSMode,
|
||||
uint32_t aStringLen,
|
||||
const uint8_t* aString,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "SRIMetadata.h"
|
||||
|
||||
class nsIDocument;
|
||||
class nsIStreamLoader;
|
||||
class nsIIncrementalStreamLoader;
|
||||
class nsIUnicharStreamLoader;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
* must prevent the resource from loading.
|
||||
*/
|
||||
static nsresult VerifyIntegrity(const SRIMetadata& aMetadata,
|
||||
nsIStreamLoader* aLoader,
|
||||
nsIIncrementalStreamLoader* aLoader,
|
||||
const CORSMode aCORSMode,
|
||||
uint32_t aStringLen,
|
||||
const uint8_t* aString,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "nsIXULDocument.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
#include "nsIXULStore.h"
|
||||
|
||||
|
|
|
@ -239,11 +239,11 @@ EvalScript(JSContext* cx,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class AsyncScriptLoader : public nsIStreamLoaderObserver
|
||||
class AsyncScriptLoader : public nsIIncrementalStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AsyncScriptLoader)
|
||||
|
||||
|
@ -277,7 +277,7 @@ private:
|
|||
NS_IMPL_CYCLE_COLLECTION_CLASS(AsyncScriptLoader)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AsyncScriptLoader)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIStreamLoaderObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIIncrementalStreamLoaderObserver)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AsyncScriptLoader)
|
||||
|
@ -326,7 +326,7 @@ class MOZ_STACK_CLASS AutoRejectPromise
|
|||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
AsyncScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
|
||||
AsyncScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
nsISupports* aContext,
|
||||
nsresult aStatus,
|
||||
uint32_t aLength,
|
||||
|
@ -431,8 +431,8 @@ mozJSSubScriptLoader::ReadScriptAsync(nsIURI* uri, JSObject* targetObjArg,
|
|||
cache,
|
||||
promise);
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), loadObserver);
|
||||
nsCOMPtr<nsIIncrementalStreamLoader> loader;
|
||||
rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), loadObserver);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIStreamListener> listener = loader.get();
|
||||
|
@ -673,11 +673,11 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url,
|
|||
* Let us compile scripts from a URI off the main thread.
|
||||
*/
|
||||
|
||||
class ScriptPrecompiler : public nsIStreamLoaderObserver
|
||||
class ScriptPrecompiler : public nsIIncrementalStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
|
||||
|
||||
ScriptPrecompiler(nsIObserver* aObserver,
|
||||
nsIPrincipal* aPrincipal,
|
||||
|
@ -709,7 +709,7 @@ private:
|
|||
size_t mScriptLength;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ScriptPrecompiler, nsIStreamLoaderObserver);
|
||||
NS_IMPL_ISUPPORTS(ScriptPrecompiler, nsIIncrementalStreamLoaderObserver);
|
||||
|
||||
class NotifyPrecompilationCompleteRunnable : public nsRunnable
|
||||
{
|
||||
|
@ -770,7 +770,7 @@ NotifyPrecompilationCompleteRunnable::Run(void)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ScriptPrecompiler::OnStreamComplete(nsIStreamLoader* aLoader,
|
||||
ScriptPrecompiler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
nsISupports* aContext,
|
||||
nsresult aStatus,
|
||||
uint32_t aLength,
|
||||
|
@ -876,8 +876,8 @@ mozJSSubScriptLoader::PrecompileScript(nsIURI* aURI,
|
|||
RefPtr<ScriptPrecompiler> loadObserver =
|
||||
new ScriptPrecompiler(aObserver, aPrincipal, channel);
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), loadObserver);
|
||||
nsCOMPtr<nsIIncrementalStreamLoader> loader;
|
||||
rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), loadObserver);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIStreamListener> listener = loader.get();
|
||||
|
|
|
@ -48,6 +48,7 @@ XPIDL_SOURCES += [
|
|||
'nsIForcePendingChannel.idl',
|
||||
'nsIHttpPushListener.idl',
|
||||
'nsIIncrementalDownload.idl',
|
||||
'nsIIncrementalStreamLoader.idl',
|
||||
'nsIInputStreamChannel.idl',
|
||||
'nsIInputStreamPump.idl',
|
||||
'nsIIOService.idl',
|
||||
|
@ -212,6 +213,7 @@ UNIFIED_SOURCES += [
|
|||
'nsDownloader.cpp',
|
||||
'nsFileStreams.cpp',
|
||||
'nsIncrementalDownload.cpp',
|
||||
'nsIncrementalStreamLoader.cpp',
|
||||
'nsInputStreamChannel.cpp',
|
||||
'nsInputStreamPump.cpp',
|
||||
'nsIOService.cpp',
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 "nsIStreamListener.idl"
|
||||
|
||||
interface nsIRequest;
|
||||
interface nsIIncrementalStreamLoader;
|
||||
|
||||
[scriptable, uuid(2143eaad-674e-4613-87f8-359d4c40f590)]
|
||||
interface nsIIncrementalStreamLoaderObserver : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called when the entire stream has been loaded.
|
||||
*
|
||||
* @param loader the stream loader that loaded the stream.
|
||||
* @param ctxt the context parameter of the underlying channel
|
||||
* @param status the status of the underlying channel
|
||||
* @param resultLength the length of the data loaded
|
||||
* @param result the data
|
||||
*
|
||||
* This method will always be called asynchronously by the
|
||||
* nsIIncrementalStreamLoader involved, on the thread that called the
|
||||
* loader's init() method.
|
||||
*
|
||||
* If the observer wants to take over responsibility for the
|
||||
* data buffer (result), it returns NS_SUCCESS_ADOPTED_DATA
|
||||
* in place of NS_OK as its success code. The loader will then
|
||||
* "forget" about the data and not free() it after
|
||||
* onStreamComplete() returns; observer must call free()
|
||||
* when the data is no longer required.
|
||||
*/
|
||||
void onStreamComplete(in nsIIncrementalStreamLoader loader,
|
||||
in nsISupports ctxt,
|
||||
in nsresult status,
|
||||
in unsigned long resultLength,
|
||||
[const,array,size_is(resultLength)] in octet result);
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronously loads a channel into a memory buffer.
|
||||
*
|
||||
* To use this interface, first call init() with a nsIIncrementalStreamLoaderObserver
|
||||
* that will be notified when the data has been loaded. Then call asyncOpen()
|
||||
* on the channel with the nsIIncrementalStreamLoader as the listener. The context
|
||||
* argument in the asyncOpen() call will be passed to the onStreamComplete()
|
||||
* callback.
|
||||
*
|
||||
* XXX define behaviour for sizes >4 GB
|
||||
*/
|
||||
[scriptable, uuid(a023b060-ba23-431a-b449-2dd63e220554)]
|
||||
interface nsIIncrementalStreamLoader : nsIStreamListener
|
||||
{
|
||||
/**
|
||||
* Initialize this stream loader, and start loading the data.
|
||||
*
|
||||
* @param aObserver
|
||||
* An observer that will be notified when the data is complete.
|
||||
*/
|
||||
void init(in nsIIncrementalStreamLoaderObserver aObserver);
|
||||
|
||||
/**
|
||||
* Gets the number of bytes read so far.
|
||||
*/
|
||||
readonly attribute unsigned long numBytesRead;
|
||||
|
||||
/**
|
||||
* Gets the request that loaded this file.
|
||||
* null after the request has finished loading.
|
||||
*/
|
||||
readonly attribute nsIRequest request;
|
||||
};
|
|
@ -0,0 +1,153 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 "nsIncrementalStreamLoader.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsError.h"
|
||||
#include "GeckoProfiler.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
nsIncrementalStreamLoader::nsIncrementalStreamLoader()
|
||||
: mData()
|
||||
{
|
||||
}
|
||||
|
||||
nsIncrementalStreamLoader::~nsIncrementalStreamLoader()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIncrementalStreamLoader::Init(nsIIncrementalStreamLoaderObserver* observer)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(observer);
|
||||
mObserver = observer;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsIncrementalStreamLoader::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsIncrementalStreamLoader* it = new nsIncrementalStreamLoader();
|
||||
if (it == nullptr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(it);
|
||||
nsresult rv = it->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(it);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsIncrementalStreamLoader, nsIIncrementalStreamLoader,
|
||||
nsIRequestObserver, nsIStreamListener,
|
||||
nsIThreadRetargetableStreamListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIncrementalStreamLoader::GetNumBytesRead(uint32_t* aNumBytes)
|
||||
{
|
||||
*aNumBytes = mData.length();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIRequest request; */
|
||||
NS_IMETHODIMP
|
||||
nsIncrementalStreamLoader::GetRequest(nsIRequest **aRequest)
|
||||
{
|
||||
NS_IF_ADDREF(*aRequest = mRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIncrementalStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
|
||||
{
|
||||
nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
|
||||
if (chan) {
|
||||
int64_t contentLength = -1;
|
||||
chan->GetContentLength(&contentLength);
|
||||
if (contentLength >= 0) {
|
||||
if (uint64_t(contentLength) > std::numeric_limits<size_t>::max()) {
|
||||
// Too big to fit into size_t, so let's bail.
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
// preallocate buffer
|
||||
if (!mData.initCapacity(contentLength)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
mContext = ctxt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIncrementalStreamLoader::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||
nsresult aStatus)
|
||||
{
|
||||
PROFILER_LABEL("nsIncrementalStreamLoader", "OnStopRequest",
|
||||
js::ProfileEntry::Category::NETWORK);
|
||||
|
||||
if (mObserver) {
|
||||
// provide nsIIncrementalStreamLoader::request during call to OnStreamComplete
|
||||
mRequest = request;
|
||||
size_t length = mData.length();
|
||||
uint8_t* elems = mData.extractRawBuffer();
|
||||
nsresult rv = mObserver->OnStreamComplete(this, mContext, aStatus,
|
||||
length, elems);
|
||||
if (rv != NS_SUCCESS_ADOPTED_DATA) {
|
||||
// The observer didn't take ownership of the extracted data buffer, so
|
||||
// put it back into mData.
|
||||
mData.replaceRawBuffer(elems, length);
|
||||
}
|
||||
// done.. cleanup
|
||||
ReleaseData();
|
||||
mRequest = 0;
|
||||
mObserver = 0;
|
||||
mContext = 0;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsIncrementalStreamLoader::WriteSegmentFun(nsIInputStream *inStr,
|
||||
void *closure,
|
||||
const char *fromSegment,
|
||||
uint32_t toOffset,
|
||||
uint32_t count,
|
||||
uint32_t *writeCount)
|
||||
{
|
||||
nsIncrementalStreamLoader *self = (nsIncrementalStreamLoader *) closure;
|
||||
|
||||
if (!self->mData.append(fromSegment, count)) {
|
||||
self->mData.clearAndFree();
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
*writeCount = count;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIncrementalStreamLoader::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
|
||||
nsIInputStream *inStr,
|
||||
uint64_t sourceOffset, uint32_t count)
|
||||
{
|
||||
uint32_t countRead;
|
||||
return inStr->ReadSegments(WriteSegmentFun, this, count, &countRead);
|
||||
}
|
||||
|
||||
void
|
||||
nsIncrementalStreamLoader::ReleaseData()
|
||||
{
|
||||
mData.clearAndFree();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIncrementalStreamLoader::CheckListenerChain()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 nsIncrementalStreamLoader_h__
|
||||
#define nsIncrementalStreamLoader_h__
|
||||
|
||||
#include "nsIThreadRetargetableStreamListener.h"
|
||||
#include "nsIIncrementalStreamLoader.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Vector.h"
|
||||
|
||||
class nsIRequest;
|
||||
|
||||
class nsIncrementalStreamLoader final : public nsIIncrementalStreamLoader
|
||||
, public nsIThreadRetargetableStreamListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIINCREMENTALSTREAMLOADER
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
||||
|
||||
nsIncrementalStreamLoader();
|
||||
|
||||
static nsresult
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
protected:
|
||||
~nsIncrementalStreamLoader();
|
||||
|
||||
static NS_METHOD WriteSegmentFun(nsIInputStream *, void *, const char *,
|
||||
uint32_t, uint32_t, uint32_t *);
|
||||
|
||||
// Utility method to free mData, if present, and update other state to
|
||||
// reflect that no data has been allocated.
|
||||
void ReleaseData();
|
||||
|
||||
nsCOMPtr<nsIIncrementalStreamLoaderObserver> mObserver;
|
||||
nsCOMPtr<nsISupports> mContext; // the observer's context
|
||||
nsCOMPtr<nsIRequest> mRequest;
|
||||
|
||||
// Buffer to accumulate incoming data. We preallocate if contentSize is
|
||||
// available.
|
||||
mozilla::Vector<uint8_t, 0> mData;
|
||||
};
|
||||
|
||||
#endif // nsIncrementalStreamLoader_h__
|
|
@ -45,6 +45,7 @@
|
|||
#include "nsISocketProviderService.h"
|
||||
#include "nsIStandardURL.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsIIncrementalStreamLoader.h"
|
||||
#include "nsIStreamTransportService.h"
|
||||
#include "nsStringStream.h"
|
||||
#include "nsISyncStreamListener.h"
|
||||
|
@ -580,6 +581,23 @@ NS_NewDownloader(nsIStreamListener **result,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewIncrementalStreamLoader(nsIIncrementalStreamLoader **result,
|
||||
nsIIncrementalStreamLoaderObserver *observer)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIIncrementalStreamLoader> loader =
|
||||
do_CreateInstance(NS_INCREMENTALSTREAMLOADER_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = loader->Init(observer);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*result = nullptr;
|
||||
loader.swap(*result);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewStreamLoaderInternal(nsIStreamLoader **outStream,
|
||||
nsIURI *aUri,
|
||||
|
|
|
@ -42,6 +42,8 @@ class nsIRequestObserver;
|
|||
class nsIStreamListener;
|
||||
class nsIStreamLoader;
|
||||
class nsIStreamLoaderObserver;
|
||||
class nsIIncrementalStreamLoader;
|
||||
class nsIIncrementalStreamLoaderObserver;
|
||||
class nsIUnicharStreamLoader;
|
||||
class nsIUnicharStreamLoaderObserver;
|
||||
|
||||
|
@ -369,6 +371,9 @@ nsresult NS_NewStreamLoader(nsIStreamLoader **result,
|
|||
nsIStreamLoaderObserver *observer,
|
||||
nsIRequestObserver *requestObserver = nullptr);
|
||||
|
||||
nsresult NS_NewIncrementalStreamLoader(nsIIncrementalStreamLoader **result,
|
||||
nsIIncrementalStreamLoaderObserver *observer);
|
||||
|
||||
nsresult NS_NewStreamLoaderInternal(nsIStreamLoader **outStream,
|
||||
nsIURI *aUri,
|
||||
nsIStreamLoaderObserver *aObserver,
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIStandardURL.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsIIncrementalStreamLoader.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIURIWithPrincipal.h"
|
||||
#include "nsIWritablePropertyBag2.h"
|
||||
|
|
|
@ -226,6 +226,18 @@
|
|||
{ 0xa1, 0xa5, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } \
|
||||
}
|
||||
|
||||
// component implementing nsIStreamLoader.
|
||||
#define NS_INCREMENTALSTREAMLOADER_CONTRACTID \
|
||||
"@mozilla.org/network/incremental-stream-loader;1"
|
||||
#define NS_INCREMENTALSTREAMLOADER_CID \
|
||||
{ /* 5d6352a3-b9c3-4fa3-87aa-b2a3c6e5a501 */ \
|
||||
0x5d6352a3, \
|
||||
0xb9c3, \
|
||||
0x4fa3, \
|
||||
{0x87, 0xaa, 0xb2, 0xa3, 0xc6, 0xe5, 0xa5, 0x01} \
|
||||
}
|
||||
|
||||
|
||||
// component implementing nsIUnicharStreamLoader.
|
||||
#define NS_UNICHARSTREAMLOADER_CONTRACTID \
|
||||
"@mozilla.org/network/unichar-stream-loader;1"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "nsSimpleNestedURI.h"
|
||||
#include "nsLoadGroup.h"
|
||||
#include "nsStreamLoader.h"
|
||||
#include "nsIncrementalStreamLoader.h"
|
||||
#include "nsUnicharStreamLoader.h"
|
||||
#include "nsFileStreams.h"
|
||||
#include "nsBufferedStreams.h"
|
||||
|
@ -707,6 +708,7 @@ NS_DEFINE_NAMED_CID(NS_ASYNCSTREAMCOPIER_CID);
|
|||
NS_DEFINE_NAMED_CID(NS_INPUTSTREAMPUMP_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_INPUTSTREAMCHANNEL_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_STREAMLOADER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_INCREMENTALSTREAMLOADER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_UNICHARSTREAMLOADER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DOWNLOADER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_BACKGROUNDFILESAVEROUTPUTSTREAM_CID);
|
||||
|
@ -854,6 +856,7 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
|
|||
{ &kNS_INPUTSTREAMPUMP_CID, false, nullptr, nsInputStreamPumpConstructor },
|
||||
{ &kNS_INPUTSTREAMCHANNEL_CID, false, nullptr, nsInputStreamChannelConstructor },
|
||||
{ &kNS_STREAMLOADER_CID, false, nullptr, nsStreamLoader::Create },
|
||||
{ &kNS_INCREMENTALSTREAMLOADER_CID, false, nullptr, nsIncrementalStreamLoader::Create },
|
||||
{ &kNS_UNICHARSTREAMLOADER_CID, false, nullptr, nsUnicharStreamLoader::Create },
|
||||
{ &kNS_DOWNLOADER_CID, false, nullptr, nsDownloaderConstructor },
|
||||
{ &kNS_BACKGROUNDFILESAVEROUTPUTSTREAM_CID, false, nullptr,
|
||||
|
@ -1007,6 +1010,7 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
|
|||
{ NS_INPUTSTREAMPUMP_CONTRACTID, &kNS_INPUTSTREAMPUMP_CID },
|
||||
{ NS_INPUTSTREAMCHANNEL_CONTRACTID, &kNS_INPUTSTREAMCHANNEL_CID },
|
||||
{ NS_STREAMLOADER_CONTRACTID, &kNS_STREAMLOADER_CID },
|
||||
{ NS_INCREMENTALSTREAMLOADER_CONTRACTID, &kNS_INCREMENTALSTREAMLOADER_CID },
|
||||
{ NS_UNICHARSTREAMLOADER_CONTRACTID, &kNS_UNICHARSTREAMLOADER_CID },
|
||||
{ NS_DOWNLOADER_CONTRACTID, &kNS_DOWNLOADER_CID },
|
||||
{ NS_BACKGROUNDFILESAVEROUTPUTSTREAM_CONTRACTID, &kNS_BACKGROUNDFILESAVEROUTPUTSTREAM_CID },
|
||||
|
|
Загрузка…
Ссылка в новой задаче