Bug 1083425 - WebSocket should remove its nsIRequest from the docShell when disconnected, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 17 Oct 2014 08:12:26 +0100
changeset 210850 4a51a12d8ed350f77aa062d055c03a84158d06c6
parent 210849 03f1d37d1fb17f746a1711ea455eaccb18fb9304
child 210851 76899623e9f4a21a61bdfd1740acc38b7698e336
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs1083425
milestone36.0a1
Bug 1083425 - WebSocket should remove its nsIRequest from the docShell when disconnected, r=smaug
content/base/src/WebSocket.cpp
--- 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,