diff --git a/dom/websocket/WebSocket.cpp b/dom/websocket/WebSocket.cpp index 5d4963ec208c..68a444825ec3 100644 --- a/dom/websocket/WebSocket.cpp +++ b/dom/websocket/WebSocket.cpp @@ -954,6 +954,30 @@ WebSocket::WrapObject(JSContext* cx, JS::Handle aGivenProto) return WebSocketBinding::Wrap(cx, this, aGivenProto); } +void +WebSocket::BindToOwner(nsIGlobalObject* aNew) +{ + auto scopeExit = MakeScopeExit([&] { + DOMEventTargetHelper::BindToOwner(aNew); + }); + + // If we're disconnected, then there is no state to update. + if (!mImpl || mImpl->mDisconnectingOrDisconnected) { + return; + } + + // Update state on the old window. + if (GetOwner()) { + GetOwner()->UpdateWebSocketCount(-1); + } + + // Update state on the new window + nsCOMPtr newWindow = do_QueryInterface(aNew); + if (newWindow) { + newWindow->UpdateWebSocketCount(1); + } +} + //--------------------------------------------------------------------------- // WebIDL //--------------------------------------------------------------------------- diff --git a/dom/websocket/WebSocket.h b/dom/websocket/WebSocket.h index 0369893cc5c4..4dbaabd5fdbb 100644 --- a/dom/websocket/WebSocket.h +++ b/dom/websocket/WebSocket.h @@ -65,6 +65,9 @@ public: virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + // DOMEventTargetHelper + void BindToOwner(nsIGlobalObject* aNew) override; + public: // static helpers: // Determine if preferences allow WebSocket