Bug 1083425 - WebSocket should remove its nsIRequest from the docShell when disconnected, r=smaug
--- a/content/base/src/WebSocket.cpp
+++ b/content/base/src/WebSocket.cpp
@@ -188,16 +188,18 @@ public:
// These attributes are used for error reporting.
nsCString mScriptFile;
uint32_t mScriptLine;
uint64_t mInnerWindowID;
WorkerPrivate* mWorkerPrivate;
nsAutoPtr<WorkerFeature> mWorkerFeature;
+ nsWeakPtr mWeakLoadGroup;
+
private:
~WebSocketImpl()
{
// If we threw during Init we never called disconnect
if (!mDisconnected) {
Disconnect();
}
}
@@ -523,18 +525,17 @@ WebSocketImpl::Disconnect()
return NS_OK;
}
void
WebSocketImpl::DisconnectInternal()
{
AssertIsOnMainThread();
- nsCOMPtr<nsILoadGroup> loadGroup;
- GetLoadGroup(getter_AddRefs(loadGroup));
+ nsCOMPtr<nsILoadGroup> loadGroup = do_QueryReferent(mWeakLoadGroup);
if (loadGroup) {
loadGroup->RemoveRequest(this, nullptr, NS_OK);
}
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
os->RemoveObserver(this, DOM_WINDOW_FROZEN_TOPIC);
@@ -1385,16 +1386,18 @@ WebSocketImpl::InitializeConnection()
// provide the http stack the loadgroup info too
nsCOMPtr<nsILoadGroup> loadGroup;
rv = GetLoadGroup(getter_AddRefs(loadGroup));
if (loadGroup) {
rv = wsChannel->SetLoadGroup(loadGroup);
NS_ENSURE_SUCCESS(rv, rv);
rv = loadGroup->AddRequest(this, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
+
+ mWeakLoadGroup = do_GetWeakReference(loadGroup);
}
// manually adding loadinfo to the channel since it
// was not set during channel creation.
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mOriginDocument);
nsCOMPtr<nsILoadInfo> loadInfo =
new LoadInfo(mPrincipal,
doc,