diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index 30438fbf07d9..b60b60d22bd7 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -36,11 +36,6 @@ #include "MultipartBlobImpl.h" #include "nsQueryObject.h" -#ifdef MOZ_WEBRTC -# include "mozilla/dom/RTCCertificate.h" -# include "mozilla/dom/RTCCertificateBinding.h" -#endif - using namespace mozilla::ipc; namespace mozilla { @@ -123,7 +118,7 @@ void AssertTagValues() { SCTAG_DOM_SYSTEM_PRINCIPAL == 0xffff800c && SCTAG_DOM_CONTENT_PRINCIPAL == 0xffff800d && SCTAG_DOM_DOMQUAD == 0xffff800e && - SCTAG_DOM_RTC_CERTIFICATE == 0xffff800f && + SCTAG_DOM_RTCCERTIFICATE == 0xffff800f && SCTAG_DOM_DOMRECT == 0xffff8010 && SCTAG_DOM_DOMRECTREADONLY == 0xffff8011 && SCTAG_DOM_EXPANDED_PRINCIPAL == 0xffff8012 && @@ -370,31 +365,6 @@ JSObject* StructuredCloneHolder::ReadFullySerializableObjects( return result.toObjectOrNull(); } -#ifdef MOZ_WEBRTC - if (aTag == SCTAG_DOM_RTC_CERTIFICATE) { - if (!NS_IsMainThread()) { - return nullptr; - } - - nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx); - if (!global) { - return nullptr; - } - - // Prevent the return value from being trashed by a GC during ~nsRefPtr. - JS::Rooted result(aCx); - { - RefPtr cert = new RTCCertificate(global); - if (!cert->ReadStructuredClone(aReader)) { - result = nullptr; - } else { - result = cert->WrapObject(aCx, nullptr); - } - } - return result; - } -#endif - if (aTag == SCTAG_DOM_STRUCTURED_CLONE_TESTER) { return StructuredCloneTester::ReadStructuredClone(aCx, aReader); } @@ -422,18 +392,6 @@ bool StructuredCloneHolder::WriteFullySerializableObjects( return domClass->mSerializer(aCx, aWriter, obj); } -#ifdef MOZ_WEBRTC - { - // Handle WebRTC Certificate cloning - RTCCertificate* cert = nullptr; - if (NS_SUCCEEDED(UNWRAP_OBJECT(RTCCertificate, &obj, cert))) { - MOZ_ASSERT(NS_IsMainThread()); - return JS_WriteUint32Pair(aWriter, SCTAG_DOM_RTC_CERTIFICATE, 0) && - cert->WriteStructuredClone(aWriter); - } - } -#endif - // StructuredCloneTester - testing only { StructuredCloneTester* sct = nullptr; diff --git a/dom/base/StructuredCloneTags.h b/dom/base/StructuredCloneTags.h index 703142399ae9..9b45e32d6a38 100644 --- a/dom/base/StructuredCloneTags.h +++ b/dom/base/StructuredCloneTags.h @@ -69,7 +69,7 @@ enum StructuredCloneTags { // IMPORTANT: Don't change the order of these enum values. You could break // IDB. - SCTAG_DOM_RTC_CERTIFICATE, + SCTAG_DOM_RTCCERTIFICATE, // IMPORTANT: Don't change the order of these enum values. You could break // IDB. diff --git a/dom/media/webrtc/RTCCertificate.cpp b/dom/media/webrtc/RTCCertificate.cpp index 0338cc823de6..375985db1b92 100644 --- a/dom/media/webrtc/RTCCertificate.cpp +++ b/dom/media/webrtc/RTCCertificate.cpp @@ -327,7 +327,7 @@ bool RTCCertificate::WriteCertificate(JSStructuredCloneWriter* aWriter) const { } bool RTCCertificate::WriteStructuredClone( - JSStructuredCloneWriter* aWriter) const { + JSContext* aCx, JSStructuredCloneWriter* aWriter) const { if (!mPrivateKey || !mCertificate) { return false; } @@ -364,21 +364,33 @@ bool RTCCertificate::ReadCertificate(JSStructuredCloneReader* aReader) { return !!mCertificate; } -bool RTCCertificate::ReadStructuredClone(JSStructuredCloneReader* aReader) { +// static +already_AddRefed RTCCertificate::ReadStructuredClone( + JSContext* aCx, nsIGlobalObject* aGlobal, + JSStructuredCloneReader* aReader) { + if (!NS_IsMainThread()) { + // These objects are mainthread-only. + return nullptr; + } uint32_t version, authType; if (!JS_ReadUint32Pair(aReader, &version, &authType) || version != RTCCERTIFICATE_SC_VERSION) { - return false; + return nullptr; } - mAuthType = static_cast(authType); + RefPtr cert = new RTCCertificate(aGlobal); + cert->mAuthType = static_cast(authType); uint32_t high, low; if (!JS_ReadUint32Pair(aReader, &high, &low)) { - return false; + return nullptr; } - mExpires = static_cast(high) << 32 | low; + cert->mExpires = static_cast(high) << 32 | low; - return ReadPrivateKey(aReader) && ReadCertificate(aReader); + if (!cert->ReadPrivateKey(aReader) || !cert->ReadCertificate(aReader)) { + return nullptr; + } + + return cert.forget(); } } // namespace dom diff --git a/dom/media/webrtc/RTCCertificate.h b/dom/media/webrtc/RTCCertificate.h index 053f5ab982a4..822fdd1f5453 100644 --- a/dom/media/webrtc/RTCCertificate.h +++ b/dom/media/webrtc/RTCCertificate.h @@ -56,8 +56,11 @@ class RTCCertificate final : public nsISupports, public nsWrapperCache { const UniqueCERTCertificate& Certificate() const { return mCertificate; } // Structured clone methods - bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const; - bool ReadStructuredClone(JSStructuredCloneReader* aReader); + bool WriteStructuredClone(JSContext* aCx, + JSStructuredCloneWriter* aWriter) const; + static already_AddRefed ReadStructuredClone( + JSContext* aCx, nsIGlobalObject* aGlobal, + JSStructuredCloneReader* aReader); private: ~RTCCertificate() {} diff --git a/dom/webidl/RTCCertificate.webidl b/dom/webidl/RTCCertificate.webidl index 405859518517..81c3fd41fcce 100644 --- a/dom/webidl/RTCCertificate.webidl +++ b/dom/webidl/RTCCertificate.webidl @@ -11,7 +11,7 @@ dictionary RTCCertificateExpiration { DOMTimeStamp expires; }; -[Pref="media.peerconnection.enabled"] +[Pref="media.peerconnection.enabled", Serializable] interface RTCCertificate { readonly attribute DOMTimeStamp expires; };