123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846 |
- /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
- /* 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 "mozilla/DebugOnly.h"
- #include "nsLoadGroup.h"
- #include "nsArrayEnumerator.h"
- #include "nsCOMArray.h"
- #include "nsCOMPtr.h"
- #include "mozilla/Logging.h"
- #include "nsString.h"
- #include "nsTArray.h"
- #include "nsITimedChannel.h"
- #include "nsIInterfaceRequestor.h"
- #include "nsIRequestObserver.h"
- #include "nsIRequestContext.h"
- #include "CacheObserver.h"
- #include "MainThreadUtils.h"
- #include "mozilla/net/NeckoChild.h"
- namespace mozilla {
- namespace net {
- //
- // Log module for nsILoadGroup logging...
- //
- // To enable logging (see prlog.h for full details):
- //
- // set MOZ_LOG=LoadGroup:5
- // set MOZ_LOG_FILE=network.log
- //
- // This enables LogLevel::Debug level information and places all output in
- // the file network.log.
- //
- static LazyLogModule gLoadGroupLog("LoadGroup");
- #undef LOG
- #define LOG(args) MOZ_LOG(gLoadGroupLog, mozilla::LogLevel::Debug, args)
- ////////////////////////////////////////////////////////////////////////////////
- class RequestMapEntry : public PLDHashEntryHdr
- {
- public:
- explicit RequestMapEntry(nsIRequest *aRequest) :
- mKey(aRequest)
- {
- }
- nsCOMPtr<nsIRequest> mKey;
- };
- static bool
- RequestHashMatchEntry(const PLDHashEntryHdr *entry, const void *key)
- {
- const RequestMapEntry *e =
- static_cast<const RequestMapEntry *>(entry);
- const nsIRequest *request = static_cast<const nsIRequest *>(key);
- return e->mKey == request;
- }
- static void
- RequestHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
- {
- RequestMapEntry *e = static_cast<RequestMapEntry *>(entry);
- // An entry is being cleared, let the entry do its own cleanup.
- e->~RequestMapEntry();
- }
- static void
- RequestHashInitEntry(PLDHashEntryHdr *entry, const void *key)
- {
- const nsIRequest *const_request = static_cast<const nsIRequest *>(key);
- nsIRequest *request = const_cast<nsIRequest *>(const_request);
- // Initialize the entry with placement new
- new (entry) RequestMapEntry(request);
- }
- static const PLDHashTableOps sRequestHashOps =
- {
- PLDHashTable::HashVoidPtrKeyStub,
- RequestHashMatchEntry,
- PLDHashTable::MoveEntryStub,
- RequestHashClearEntry,
- RequestHashInitEntry
- };
- static void
- RescheduleRequest(nsIRequest *aRequest, int32_t delta)
- {
- nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(aRequest);
- if (p)
- p->AdjustPriority(delta);
- }
- nsLoadGroup::nsLoadGroup(nsISupports* outer)
- : mForegroundCount(0)
- , mLoadFlags(LOAD_NORMAL)
- , mDefaultLoadFlags(0)
- , mRequests(&sRequestHashOps, sizeof(RequestMapEntry))
- , mStatus(NS_OK)
- , mPriority(PRIORITY_NORMAL)
- , mIsCanceling(false)
- , mDefaultLoadIsTimed(false)
- , mTimedRequests(0)
- , mCachedRequests(0)
- , mTimedNonCachedRequestsUntilOnEndPageLoad(0)
- {
- NS_INIT_AGGREGATED(outer);
- LOG(("LOADGROUP [%x]: Created.\n", this));
- }
- nsLoadGroup::~nsLoadGroup()
- {
- DebugOnly<nsresult> rv = Cancel(NS_BINDING_ABORTED);
- NS_ASSERTION(NS_SUCCEEDED(rv), "Cancel failed");
- mDefaultLoadRequest = nullptr;
- if (mRequestContext) {
- nsID rcid;
- mRequestContext->GetID(&rcid);
- if (IsNeckoChild() && gNeckoChild) {
- char rcid_str[NSID_LENGTH];
- rcid.ToProvidedString(rcid_str);
- nsCString rcid_nscs;
- rcid_nscs.AssignASCII(rcid_str);
- gNeckoChild->SendRemoveRequestContext(rcid_nscs);
- } else {
- mRequestContextService->RemoveRequestContext(rcid);
- }
- }
- LOG(("LOADGROUP [%x]: Destroyed.\n", this));
- }
- ////////////////////////////////////////////////////////////////////////////////
- // nsISupports methods:
- NS_IMPL_AGGREGATED(nsLoadGroup)
- NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsLoadGroup)
- NS_INTERFACE_MAP_ENTRY(nsILoadGroup)
- NS_INTERFACE_MAP_ENTRY(nsPILoadGroupInternal)
- NS_INTERFACE_MAP_ENTRY(nsILoadGroupChild)
- NS_INTERFACE_MAP_ENTRY(nsIRequest)
- NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
- NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
- NS_INTERFACE_MAP_END
- ////////////////////////////////////////////////////////////////////////////////
- // nsIRequest methods:
- NS_IMETHODIMP
- nsLoadGroup::GetName(nsACString &result)
- {
- // XXX is this the right "name" for a load group?
- if (!mDefaultLoadRequest) {
- result.Truncate();
- return NS_OK;
- }
- return mDefaultLoadRequest->GetName(result);
- }
- NS_IMETHODIMP
- nsLoadGroup::IsPending(bool *aResult)
- {
- *aResult = (mForegroundCount > 0) ? true : false;
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetStatus(nsresult *status)
- {
- if (NS_SUCCEEDED(mStatus) && mDefaultLoadRequest)
- return mDefaultLoadRequest->GetStatus(status);
- *status = mStatus;
- return NS_OK;
- }
- static bool
- AppendRequestsToArray(PLDHashTable* aTable, nsTArray<nsIRequest*> *aArray)
- {
- for (auto iter = aTable->Iter(); !iter.Done(); iter.Next()) {
- auto e = static_cast<RequestMapEntry*>(iter.Get());
- nsIRequest *request = e->mKey;
- NS_ASSERTION(request, "What? Null key in PLDHashTable entry?");
- bool ok = !!aArray->AppendElement(request);
- if (!ok) {
- break;
- }
- NS_ADDREF(request);
- }
- if (aArray->Length() != aTable->EntryCount()) {
- for (uint32_t i = 0, len = aArray->Length(); i < len; ++i) {
- NS_RELEASE((*aArray)[i]);
- }
- return false;
- }
- return true;
- }
- NS_IMETHODIMP
- nsLoadGroup::Cancel(nsresult status)
- {
- MOZ_ASSERT(NS_IsMainThread());
- NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
- nsresult rv;
- uint32_t count = mRequests.EntryCount();
- AutoTArray<nsIRequest*, 8> requests;
- if (!AppendRequestsToArray(&mRequests, &requests)) {
- return NS_ERROR_OUT_OF_MEMORY;
- }
- // set the load group status to our cancel status while we cancel
- // all our requests...once the cancel is done, we'll reset it...
- //
- mStatus = status;
- // Set the flag indicating that the loadgroup is being canceled... This
- // prevents any new channels from being added during the operation.
- //
- mIsCanceling = true;
- nsresult firstError = NS_OK;
- while (count > 0) {
- nsIRequest* request = requests.ElementAt(--count);
- NS_ASSERTION(request, "NULL request found in list.");
- if (!mRequests.Search(request)) {
- // |request| was removed already
- NS_RELEASE(request);
- continue;
- }
- if (MOZ_LOG_TEST(gLoadGroupLog, LogLevel::Debug)) {
- nsAutoCString nameStr;
- request->GetName(nameStr);
- LOG(("LOADGROUP [%x]: Canceling request %x %s.\n",
- this, request, nameStr.get()));
- }
- //
- // Remove the request from the load group... This may cause
- // the OnStopRequest notification to fire...
- //
- // XXX: What should the context be?
- //
- (void)RemoveRequest(request, nullptr, status);
- // Cancel the request...
- rv = request->Cancel(status);
- // Remember the first failure and return it...
- if (NS_FAILED(rv) && NS_SUCCEEDED(firstError))
- firstError = rv;
- NS_RELEASE(request);
- }
- #if defined(DEBUG)
- NS_ASSERTION(mRequests.EntryCount() == 0, "Request list is not empty.");
- NS_ASSERTION(mForegroundCount == 0, "Foreground URLs are active.");
- #endif
- mStatus = NS_OK;
- mIsCanceling = false;
- return firstError;
- }
- NS_IMETHODIMP
- nsLoadGroup::Suspend()
- {
- nsresult rv, firstError;
- uint32_t count = mRequests.EntryCount();
- AutoTArray<nsIRequest*, 8> requests;
- if (!AppendRequestsToArray(&mRequests, &requests)) {
- return NS_ERROR_OUT_OF_MEMORY;
- }
- firstError = NS_OK;
- //
- // Operate the elements from back to front so that if items get
- // get removed from the list it won't affect our iteration
- //
- while (count > 0) {
- nsIRequest* request = requests.ElementAt(--count);
- NS_ASSERTION(request, "NULL request found in list.");
- if (!request)
- continue;
- if (MOZ_LOG_TEST(gLoadGroupLog, LogLevel::Debug)) {
- nsAutoCString nameStr;
- request->GetName(nameStr);
- LOG(("LOADGROUP [%x]: Suspending request %x %s.\n",
- this, request, nameStr.get()));
- }
- // Suspend the request...
- rv = request->Suspend();
- // Remember the first failure and return it...
- if (NS_FAILED(rv) && NS_SUCCEEDED(firstError))
- firstError = rv;
- NS_RELEASE(request);
- }
- return firstError;
- }
- NS_IMETHODIMP
- nsLoadGroup::Resume()
- {
- nsresult rv, firstError;
- uint32_t count = mRequests.EntryCount();
- AutoTArray<nsIRequest*, 8> requests;
- if (!AppendRequestsToArray(&mRequests, &requests)) {
- return NS_ERROR_OUT_OF_MEMORY;
- }
- firstError = NS_OK;
- //
- // Operate the elements from back to front so that if items get
- // get removed from the list it won't affect our iteration
- //
- while (count > 0) {
- nsIRequest* request = requests.ElementAt(--count);
- NS_ASSERTION(request, "NULL request found in list.");
- if (!request)
- continue;
- if (MOZ_LOG_TEST(gLoadGroupLog, LogLevel::Debug)) {
- nsAutoCString nameStr;
- request->GetName(nameStr);
- LOG(("LOADGROUP [%x]: Resuming request %x %s.\n",
- this, request, nameStr.get()));
- }
- // Resume the request...
- rv = request->Resume();
- // Remember the first failure and return it...
- if (NS_FAILED(rv) && NS_SUCCEEDED(firstError))
- firstError = rv;
- NS_RELEASE(request);
- }
- return firstError;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetLoadFlags(uint32_t *aLoadFlags)
- {
- *aLoadFlags = mLoadFlags;
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::SetLoadFlags(uint32_t aLoadFlags)
- {
- mLoadFlags = aLoadFlags;
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetLoadGroup(nsILoadGroup **loadGroup)
- {
- *loadGroup = mLoadGroup;
- NS_IF_ADDREF(*loadGroup);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::SetLoadGroup(nsILoadGroup *loadGroup)
- {
- mLoadGroup = loadGroup;
- return NS_OK;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // nsILoadGroup methods:
- NS_IMETHODIMP
- nsLoadGroup::GetDefaultLoadRequest(nsIRequest * *aRequest)
- {
- *aRequest = mDefaultLoadRequest;
- NS_IF_ADDREF(*aRequest);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::SetDefaultLoadRequest(nsIRequest *aRequest)
- {
- mDefaultLoadRequest = aRequest;
- // Inherit the group load flags from the default load request
- if (mDefaultLoadRequest) {
- mDefaultLoadRequest->GetLoadFlags(&mLoadFlags);
- //
- // Mask off any bits that are not part of the nsIRequest flags.
- // in particular, nsIChannel::LOAD_DOCUMENT_URI...
- //
- mLoadFlags &= nsIRequest::LOAD_REQUESTMASK;
- nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(aRequest);
- mDefaultLoadIsTimed = timedChannel != nullptr;
- if (mDefaultLoadIsTimed) {
- timedChannel->SetTimingEnabled(true);
- }
- }
- // Else, do not change the group's load flags (see bug 95981)
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt)
- {
- nsresult rv;
- if (MOZ_LOG_TEST(gLoadGroupLog, LogLevel::Debug)) {
- nsAutoCString nameStr;
- request->GetName(nameStr);
- LOG(("LOADGROUP [%x]: Adding request %x %s (count=%d).\n",
- this, request, nameStr.get(), mRequests.EntryCount()));
- }
- NS_ASSERTION(!mRequests.Search(request),
- "Entry added to loadgroup twice, don't do that");
- //
- // Do not add the channel, if the loadgroup is being canceled...
- //
- if (mIsCanceling) {
- LOG(("LOADGROUP [%x]: AddChannel() ABORTED because LoadGroup is"
- " being canceled!!\n", this));
- return NS_BINDING_ABORTED;
- }
- nsLoadFlags flags;
- // if the request is the default load request or if the default load
- // request is null, then the load group should inherit its load flags from
- // the request, but also we need to enforce defaultLoadFlags.
- if (mDefaultLoadRequest == request || !mDefaultLoadRequest) {
- rv = MergeDefaultLoadFlags(request, flags);
- } else {
- rv = MergeLoadFlags(request, flags);
- }
- if (NS_FAILED(rv)) return rv;
- //
- // Add the request to the list of active requests...
- //
- auto entry =
- static_cast<RequestMapEntry*>(mRequests.Add(request, fallible));
- if (!entry) {
- return NS_ERROR_OUT_OF_MEMORY;
- }
- if (mPriority != 0)
- RescheduleRequest(request, mPriority);
- nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(request);
- if (timedChannel)
- timedChannel->SetTimingEnabled(true);
- if (!(flags & nsIRequest::LOAD_BACKGROUND)) {
- // Update the count of foreground URIs..
- mForegroundCount += 1;
- //
- // Fire the OnStartRequest notification out to the observer...
- //
- // If the notification fails then DO NOT add the request to
- // the load group.
- //
- nsCOMPtr<nsIRequestObserver> observer = do_QueryReferent(mObserver);
- if (observer) {
- LOG(("LOADGROUP [%x]: Firing OnStartRequest for request %x."
- "(foreground count=%d).\n", this, request, mForegroundCount));
- rv = observer->OnStartRequest(request, ctxt);
- if (NS_FAILED(rv)) {
- LOG(("LOADGROUP [%x]: OnStartRequest for request %x FAILED.\n",
- this, request));
- //
- // The URI load has been canceled by the observer. Clean up
- // the damage...
- //
- mRequests.Remove(request);
- rv = NS_OK;
- mForegroundCount -= 1;
- }
- }
- // Ensure that we're part of our loadgroup while pending
- if (mForegroundCount == 1 && mLoadGroup) {
- mLoadGroup->AddRequest(this, nullptr);
- }
- }
- return rv;
- }
- NS_IMETHODIMP
- nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt,
- nsresult aStatus)
- {
- NS_ENSURE_ARG_POINTER(request);
- nsresult rv;
- if (MOZ_LOG_TEST(gLoadGroupLog, LogLevel::Debug)) {
- nsAutoCString nameStr;
- request->GetName(nameStr);
- LOG(("LOADGROUP [%x]: Removing request %x %s status %x (count=%d).\n",
- this, request, nameStr.get(), aStatus, mRequests.EntryCount() - 1));
- }
- // Make sure we have a owning reference to the request we're about
- // to remove.
- nsCOMPtr<nsIRequest> kungFuDeathGrip(request);
- //
- // Remove the request from the group. If this fails, it means that
- // the request was *not* in the group so do not update the foreground
- // count or it will get messed up...
- //
- auto entry = static_cast<RequestMapEntry*>(mRequests.Search(request));
- if (!entry) {
- LOG(("LOADGROUP [%x]: Unable to remove request %x. Not in group!\n",
- this, request));
- return NS_ERROR_FAILURE;
- }
- mRequests.RemoveEntry(entry);
- // Undo any group priority delta...
- if (mPriority != 0)
- RescheduleRequest(request, -mPriority);
- nsLoadFlags flags;
- rv = request->GetLoadFlags(&flags);
- if (NS_FAILED(rv)) return rv;
- if (!(flags & nsIRequest::LOAD_BACKGROUND)) {
- NS_ASSERTION(mForegroundCount > 0, "ForegroundCount messed up");
- mForegroundCount -= 1;
- // Fire the OnStopRequest out to the observer...
- nsCOMPtr<nsIRequestObserver> observer = do_QueryReferent(mObserver);
- if (observer) {
- LOG(("LOADGROUP [%x]: Firing OnStopRequest for request %x."
- "(foreground count=%d).\n", this, request, mForegroundCount));
- rv = observer->OnStopRequest(request, ctxt, aStatus);
- if (NS_FAILED(rv)) {
- LOG(("LOADGROUP [%x]: OnStopRequest for request %x FAILED.\n",
- this, request));
- }
- }
- // If that was the last request -> remove ourselves from loadgroup
- if (mForegroundCount == 0 && mLoadGroup) {
- mLoadGroup->RemoveRequest(this, nullptr, aStatus);
- }
- }
- return rv;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetRequests(nsISimpleEnumerator * *aRequests)
- {
- nsCOMArray<nsIRequest> requests;
- requests.SetCapacity(mRequests.EntryCount());
- for (auto iter = mRequests.Iter(); !iter.Done(); iter.Next()) {
- auto e = static_cast<RequestMapEntry*>(iter.Get());
- requests.AppendObject(e->mKey);
- }
- return NS_NewArrayEnumerator(aRequests, requests);
- }
- NS_IMETHODIMP
- nsLoadGroup::SetGroupObserver(nsIRequestObserver* aObserver)
- {
- mObserver = do_GetWeakReference(aObserver);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetGroupObserver(nsIRequestObserver* *aResult)
- {
- nsCOMPtr<nsIRequestObserver> observer = do_QueryReferent(mObserver);
- *aResult = observer;
- NS_IF_ADDREF(*aResult);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetActiveCount(uint32_t* aResult)
- {
- *aResult = mForegroundCount;
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
- {
- NS_ENSURE_ARG_POINTER(aCallbacks);
- *aCallbacks = mCallbacks;
- NS_IF_ADDREF(*aCallbacks);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
- {
- mCallbacks = aCallbacks;
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetRequestContextID(nsID *aRCID)
- {
- if (!mRequestContext) {
- return NS_ERROR_NOT_AVAILABLE;
- }
- return mRequestContext->GetID(aRCID);
- }
- ////////////////////////////////////////////////////////////////////////////////
- // nsILoadGroupChild methods:
- NS_IMETHODIMP
- nsLoadGroup::GetParentLoadGroup(nsILoadGroup * *aParentLoadGroup)
- {
- *aParentLoadGroup = nullptr;
- nsCOMPtr<nsILoadGroup> parent = do_QueryReferent(mParentLoadGroup);
- if (!parent)
- return NS_OK;
- parent.forget(aParentLoadGroup);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::SetParentLoadGroup(nsILoadGroup *aParentLoadGroup)
- {
- mParentLoadGroup = do_GetWeakReference(aParentLoadGroup);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetChildLoadGroup(nsILoadGroup * *aChildLoadGroup)
- {
- NS_ADDREF(*aChildLoadGroup = this);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetRootLoadGroup(nsILoadGroup * *aRootLoadGroup)
- {
- // first recursively try the root load group of our parent
- nsCOMPtr<nsILoadGroupChild> ancestor = do_QueryReferent(mParentLoadGroup);
- if (ancestor)
- return ancestor->GetRootLoadGroup(aRootLoadGroup);
- // next recursively try the root load group of our own load grop
- ancestor = do_QueryInterface(mLoadGroup);
- if (ancestor)
- return ancestor->GetRootLoadGroup(aRootLoadGroup);
- // finally just return this
- NS_ADDREF(*aRootLoadGroup = this);
- return NS_OK;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // nsPILoadGroupInternal methods:
- NS_IMETHODIMP
- nsLoadGroup::OnEndPageLoad(nsIChannel *aDefaultChannel)
- {
- // for the moment, nothing to do here.
- return NS_OK;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // nsISupportsPriority methods:
- NS_IMETHODIMP
- nsLoadGroup::GetPriority(int32_t *aValue)
- {
- *aValue = mPriority;
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::SetPriority(int32_t aValue)
- {
- return AdjustPriority(aValue - mPriority);
- }
- NS_IMETHODIMP
- nsLoadGroup::AdjustPriority(int32_t aDelta)
- {
- // Update the priority for each request that supports nsISupportsPriority
- if (aDelta != 0) {
- mPriority += aDelta;
- for (auto iter = mRequests.Iter(); !iter.Done(); iter.Next()) {
- auto e = static_cast<RequestMapEntry*>(iter.Get());
- RescheduleRequest(e->mKey, aDelta);
- }
- }
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::GetDefaultLoadFlags(uint32_t *aFlags)
- {
- *aFlags = mDefaultLoadFlags;
- return NS_OK;
- }
- NS_IMETHODIMP
- nsLoadGroup::SetDefaultLoadFlags(uint32_t aFlags)
- {
- mDefaultLoadFlags = aFlags;
- return NS_OK;
- }
- ////////////////////////////////////////////////////////////////////////////////
- nsresult nsLoadGroup::MergeLoadFlags(nsIRequest *aRequest,
- nsLoadFlags& outFlags)
- {
- nsresult rv;
- nsLoadFlags flags, oldFlags;
- rv = aRequest->GetLoadFlags(&flags);
- if (NS_FAILED(rv)) {
- return rv;
- }
- oldFlags = flags;
- // Inherit the following bits...
- flags |= (mLoadFlags & (LOAD_BACKGROUND |
- LOAD_BYPASS_CACHE |
- LOAD_FROM_CACHE |
- VALIDATE_ALWAYS |
- VALIDATE_ONCE_PER_SESSION |
- VALIDATE_NEVER));
- // ... and force the default flags.
- flags |= mDefaultLoadFlags;
- if (flags != oldFlags) {
- rv = aRequest->SetLoadFlags(flags);
- }
- outFlags = flags;
- return rv;
- }
- nsresult nsLoadGroup::MergeDefaultLoadFlags(nsIRequest *aRequest,
- nsLoadFlags& outFlags)
- {
- nsresult rv;
- nsLoadFlags flags, oldFlags;
- rv = aRequest->GetLoadFlags(&flags);
- if (NS_FAILED(rv)) {
- return rv;
- }
- oldFlags = flags;
- // ... and force the default flags.
- flags |= mDefaultLoadFlags;
- if (flags != oldFlags) {
- rv = aRequest->SetLoadFlags(flags);
- }
- outFlags = flags;
- return rv;
- }
- nsresult nsLoadGroup::Init()
- {
- mRequestContextService = do_GetService("@mozilla.org/network/request-context-service;1");
- if (mRequestContextService) {
- nsID requestContextID;
- if (NS_SUCCEEDED(mRequestContextService->NewRequestContextID(&requestContextID))) {
- mRequestContextService->GetRequestContext(requestContextID,
- getter_AddRefs(mRequestContext));
- }
- }
- return NS_OK;
- }
- } // namespace net
- } // namespace mozilla
- #undef LOG
|