void ProgressTracker::Notify(imgRequestProxy* proxy) { MOZ_ASSERT(NS_IsMainThread(), "imgRequestProxy is not threadsafe"); #ifdef PR_LOGGING if (mImage && mImage->GetURI()) { nsRefPtr<ImageURL> uri(mImage->GetURI()); nsAutoCString spec; uri->GetSpec(spec); LOG_FUNC_WITH_PARAM(GetImgLog(), "ProgressTracker::Notify async", "uri", spec.get()); } else { LOG_FUNC_WITH_PARAM(GetImgLog(), "ProgressTracker::Notify async", "uri", "<unknown>"); } #endif proxy->SetNotificationsDeferred(true); // If we have an existing runnable that we can use, we just append this proxy // to its list of proxies to be notified. This ensures we don't unnecessarily // delay onload. AsyncNotifyRunnable* runnable = static_cast<AsyncNotifyRunnable*>(mRunnable.get()); if (runnable) { runnable->AddProxy(proxy); } else { mRunnable = new AsyncNotifyRunnable(this, proxy); NS_DispatchToCurrentThread(mRunnable); } }
void ProgressTracker::Notify(IProgressObserver* aObserver) { MOZ_ASSERT(NS_IsMainThread()); if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) { nsRefPtr<Image> image = GetImage(); if (image && image->GetURI()) { nsRefPtr<ImageURL> uri(image->GetURI()); nsAutoCString spec; uri->GetSpec(spec); LOG_FUNC_WITH_PARAM(GetImgLog(), "ProgressTracker::Notify async", "uri", spec.get()); } else { LOG_FUNC_WITH_PARAM(GetImgLog(), "ProgressTracker::Notify async", "uri", "<unknown>"); } } aObserver->SetNotificationsDeferred(true); // If we have an existing runnable that we can use, we just append this // observer to its list of observers to be notified. This ensures we don't // unnecessarily delay onload. AsyncNotifyRunnable* runnable = static_cast<AsyncNotifyRunnable*>(mRunnable.get()); if (runnable) { runnable->AddObserver(aObserver); } else { mRunnable = new AsyncNotifyRunnable(this, aObserver); NS_DispatchToCurrentThread(mRunnable); } }
imgRequest::~imgRequest() { if (mKeyURI) { nsCAutoString spec; mKeyURI->GetSpec(spec); LOG_FUNC_WITH_PARAM(gImgLog, "imgRequest::~imgRequest()", "keyuri", spec.get()); } else LOG_FUNC(gImgLog, "imgRequest::~imgRequest()"); }
void imgRequestProxy::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { #ifdef PR_LOGGING nsCAutoString name; GetName(name); LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStartRequest", "name", name.get()); #endif if (mListener) { // Hold a ref to the listener while we call it, just in case. nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener); mListener->OnStartRequest(this); } }
void imgRequestProxy::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { #ifdef PR_LOGGING nsCAutoString name; GetName(name); LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStartRequest", "name", name.get()); #endif // Notify even if mCanceled, since OnStartRequest is guaranteed by the // nsIStreamListener contract so it makes sense to do the same here. if (mListener) { // Hold a ref to the listener while we call it, just in case. nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener); mListener->OnStartRequest(this); } }
void ProgressTracker::NotifyCurrentState(imgRequestProxy* proxy) { MOZ_ASSERT(NS_IsMainThread(), "imgRequestProxy is not threadsafe"); #ifdef PR_LOGGING nsRefPtr<ImageURL> uri; proxy->GetURI(getter_AddRefs(uri)); nsAutoCString spec; uri->GetSpec(spec); LOG_FUNC_WITH_PARAM(GetImgLog(), "ProgressTracker::NotifyCurrentState", "uri", spec.get()); #endif proxy->SetNotificationsDeferred(true); nsCOMPtr<nsIRunnable> ev = new AsyncNotifyCurrentStateRunnable(this, proxy); NS_DispatchToCurrentThread(ev); }
void imgRequestProxy::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult statusCode, PRBool lastPart) { #ifdef PR_LOGGING nsCAutoString name; GetName(name); LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStopRequest", "name", name.get()); #endif // There's all sorts of stuff here that could kill us (the OnStopRequest call // on the listener, the removal from the loadgroup, the release of the // listener, etc). Don't let them do it. nsCOMPtr<imgIRequest> kungFuDeathGrip(this); if (mListener) { // Hold a ref to the listener while we call it, just in case. nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener); mListener->OnStopRequest(this, lastPart); } // If we're expecting more data from a multipart channel, re-add ourself // to the loadgroup so that the document doesn't lose track of the load. // If the request is already a background request and there's more data // coming, we can just leave the request in the loadgroup as-is. if (lastPart || (mLoadFlags & nsIRequest::LOAD_BACKGROUND) == 0) { RemoveFromLoadGroup(lastPart); // More data is coming, so change the request to be a background request // and put it back in the loadgroup. if (!lastPart) { mLoadFlags |= nsIRequest::LOAD_BACKGROUND; AddToLoadGroup(); } } if (mListenerIsStrongRef) { NS_PRECONDITION(mListener, "How did that happen?"); // Drop our strong ref to the listener now that we're done with // everything. Note that this can cancel us and other fun things // like that. Don't add anything in this method after this point. imgIDecoderObserver* obs = mListener; mListenerIsStrongRef = PR_FALSE; NS_RELEASE(obs); } }
void ProgressTracker::NotifyCurrentState(IProgressObserver* aObserver) { MOZ_ASSERT(NS_IsMainThread()); if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) { nsRefPtr<Image> image = GetImage(); nsAutoCString spec; if (image && image->GetURI()) { image->GetURI()->GetSpec(spec); } LOG_FUNC_WITH_PARAM(GetImgLog(), "ProgressTracker::NotifyCurrentState", "uri", spec.get()); } aObserver->SetNotificationsDeferred(true); nsCOMPtr<nsIRunnable> ev = new AsyncNotifyCurrentStateRunnable(this, aObserver); NS_DispatchToCurrentThread(ev); }
void imgRequest::SetIsInCache(PRBool incache) { LOG_FUNC_WITH_PARAM(gImgLog, "imgRequest::SetIsCacheable", "incache", incache); mIsInCache = incache; }