Skip to content

Commit

Permalink
Bug 725804 - Don't add active network requests (XHR, WebSocket, Event…
Browse files Browse the repository at this point in the history
…Source) to CC graph, r=mccr8,jduell,jst
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Feb 16, 2012
1 parent d73d2f0 commit 9de96b4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
17 changes: 15 additions & 2 deletions content/base/src/nsEventSource.cpp
Expand Up @@ -89,6 +89,7 @@ nsEventSource::nsEventSource() :
mErrorLoadOnRedirect(false),
mGoingToDispatchAllMessages(false),
mWithCredentials(false),
mWaitingForOnStopRequest(false),
mLastConvertionResult(NS_OK),
mReadyState(nsIEventSource::CONNECTING),
mScriptLine(0),
Expand All @@ -108,13 +109,19 @@ nsEventSource::~nsEventSource()
NS_IMPL_CYCLE_COLLECTION_CLASS(nsEventSource)

NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsEventSource)
if (tmp->IsBlack()) {
bool isBlack = tmp->IsBlack();
if (isBlack || tmp->mWaitingForOnStopRequest) {
if (tmp->mListenerManager) {
tmp->mListenerManager->UnmarkGrayJSListeners();
NS_UNMARK_LISTENER_WRAPPER(Open)
NS_UNMARK_LISTENER_WRAPPER(Message)
NS_UNMARK_LISTENER_WRAPPER(Error)
}
if (!isBlack) {
xpc_UnmarkGrayObject(tmp->PreservingWrapper() ?
tmp->GetWrapperPreserveColor() :
tmp->GetExpandoObjectPreserveColor());
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
Expand Down Expand Up @@ -599,6 +606,8 @@ nsEventSource::OnStopRequest(nsIRequest *aRequest,
nsISupports *aContext,
nsresult aStatusCode)
{
mWaitingForOnStopRequest = false;

if (mReadyState == nsIEventSource::CLOSED) {
return NS_ERROR_ABORT;
}
Expand Down Expand Up @@ -949,7 +958,11 @@ nsEventSource::InitChannelAndRequestEventSource()
NS_ENSURE_SUCCESS(rv, rv);

// Start reading from the channel
return mHttpChannel->AsyncOpen(listener, nsnull);
rv = mHttpChannel->AsyncOpen(listener, nsnull);
if (NS_SUCCEEDED(rv)) {
mWaitingForOnStopRequest = true;
}
return rv;
}

void
Expand Down
1 change: 1 addition & 0 deletions content/base/src/nsEventSource.h
Expand Up @@ -216,6 +216,7 @@ friend class AsyncVerifyRedirectCallbackFwr;
bool mErrorLoadOnRedirect;
bool mGoingToDispatchAllMessages;
bool mWithCredentials;
bool mWaitingForOnStopRequest;

// used while reading the input streams
nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
Expand Down
8 changes: 7 additions & 1 deletion content/base/src/nsWebSocket.cpp
Expand Up @@ -439,14 +439,20 @@ nsWebSocket::~nsWebSocket()
NS_IMPL_CYCLE_COLLECTION_CLASS(nsWebSocket)

NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsWebSocket)
if (tmp->IsBlack()) {
bool isBlack = tmp->IsBlack();
if (isBlack|| tmp->mKeepingAlive) {
if (tmp->mListenerManager) {
tmp->mListenerManager->UnmarkGrayJSListeners();
NS_UNMARK_LISTENER_WRAPPER(Open)
NS_UNMARK_LISTENER_WRAPPER(Error)
NS_UNMARK_LISTENER_WRAPPER(Message)
NS_UNMARK_LISTENER_WRAPPER(Close)
}
if (!isBlack) {
xpc_UnmarkGrayObject(tmp->PreservingWrapper() ?
tmp->GetWrapperPreserveColor() :
tmp->GetExpandoObjectPreserveColor());
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
Expand Down
17 changes: 14 additions & 3 deletions content/base/src/nsXMLHttpRequest.cpp
Expand Up @@ -445,8 +445,8 @@ nsXMLHttpRequest::nsXMLHttpRequest()
mProgressSinceLastProgressEvent(false),
mUploadProgress(0), mUploadProgressMax(0),
mRequestSentTime(0), mTimeoutMilliseconds(0),
mErrorLoad(false), mProgressTimerIsActive(false),
mProgressEventWasDelayed(false),
mErrorLoad(false), mWaitingForOnStopRequest(false),
mProgressTimerIsActive(false), mProgressEventWasDelayed(false),
mIsHtml(false),
mWarnAboutMultipartHtml(false),
mWarnAboutSyncHtml(false),
Expand Down Expand Up @@ -602,7 +602,8 @@ nsXMLHttpRequest::SetRequestObserver(nsIRequestObserver* aObserver)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLHttpRequest)

NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsXMLHttpRequest)
if (tmp->IsBlack()) {
bool isBlack = tmp->IsBlack();
if (isBlack || tmp->mWaitingForOnStopRequest) {
if (tmp->mListenerManager) {
tmp->mListenerManager->UnmarkGrayJSListeners();
NS_UNMARK_LISTENER_WRAPPER(Load)
Expand All @@ -614,6 +615,11 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsXMLHttpRequest)
NS_UNMARK_LISTENER_WRAPPER(UploadProgress)
NS_UNMARK_LISTENER_WRAPPER(Readystatechange)
}
if (!isBlack) {
xpc_UnmarkGrayObject(tmp->PreservingWrapper() ?
tmp->GetWrapperPreserveColor() :
tmp->GetExpandoObjectPreserveColor());
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
Expand Down Expand Up @@ -2140,6 +2146,8 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
return NS_OK;
}

mWaitingForOnStopRequest = false;

nsresult rv = NS_OK;

// If we're loading a multipart stream of XML documents, we'll get
Expand Down Expand Up @@ -2774,6 +2782,9 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
return rv;
}

// Either AsyncOpen was called, or CORS will open the channel later.
mWaitingForOnStopRequest = true;

// If we're synchronous, spin an event loop here and wait
if (!(mState & XML_HTTP_REQUEST_ASYNC)) {
mState |= XML_HTTP_REQUEST_SYNCLOOPING;
Expand Down
2 changes: 1 addition & 1 deletion content/base/src/nsXMLHttpRequest.h
Expand Up @@ -365,7 +365,7 @@ class nsXMLHttpRequest : public nsXHREventTarget,
void HandleTimeoutCallback();

bool mErrorLoad;

bool mWaitingForOnStopRequest;
bool mProgressTimerIsActive;
bool mProgressEventWasDelayed;
bool mIsHtml;
Expand Down

0 comments on commit 9de96b4

Please sign in to comment.