Bug 1083425 - WebSocket should remove its nsIRequest from the docShell when disconnected. r=smaug, a=lsblakk
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 17 Oct 2014 08:12:26 +0100
changeset 223521 f84bc950b7b9fc34ca02856cdf9fbf99ad058146
parent 223520 7675ce645b757974447a11a95edb68112615586a
child 223522 0f206c761e1c67f011ec3cb675e796507e6d58a9
push id5
push usergszorc@mozilla.com
push dateWed, 29 Oct 2014 02:51:31 +0000
reviewerssmaug, lsblakk
bugs1083425
milestone35.0a2
Bug 1083425 - WebSocket should remove its nsIRequest from the docShell when disconnected. r=smaug, a=lsblakk
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,