NS_IMETHODIMP nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt) { nsresult rv; #if defined(PR_LOGGING) { nsCAutoString nameStr; request->GetName(nameStr); LOG(("LOADGROUP [%x]: Adding request %x %s (count=%d).\n", this, request, nameStr.get(), mRequests.entryCount)); } #endif /* PR_LOGGING */ #ifdef DEBUG { RequestMapEntry *entry = static_cast<RequestMapEntry *> (PL_DHashTableOperate(&mRequests, request, PL_DHASH_LOOKUP)); NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(entry), "Entry added to loadgroup twice, don't do that"); } #endif // // Do not add the channel, if the loadgroup is being canceled... // if (mIsCanceling) { #if defined(PR_LOGGING) LOG(("LOADGROUP [%x]: AddChannel() ABORTED because LoadGroup is" " being canceled!!\n", this)); #endif /* PR_LOGGING */ 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. if (mDefaultLoadRequest == request || !mDefaultLoadRequest) rv = request->GetLoadFlags(&flags); else rv = MergeLoadFlags(request, flags); if (NS_FAILED(rv)) return rv; // // Add the request to the list of active requests... // RequestMapEntry *entry = static_cast<RequestMapEntry *> (PL_DHashTableOperate(&mRequests, request, PL_DHASH_ADD)); if (!entry) { return NS_ERROR_OUT_OF_MEMORY; } if (mPriority != 0) RescheduleRequest(request, mPriority); 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... // PL_DHashTableOperate(&mRequests, request, PL_DHASH_REMOVE); rv = NS_OK; mForegroundCount -= 1; } } // Ensure that we're part of our loadgroup while pending if (mForegroundCount == 1 && mLoadGroup) { mLoadGroup->AddRequest(this, nsnull); } } return rv; }
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; }