mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1350254 part 10. Switch RTCCertificate to [Serializable]. r=baku
Differential Revision: https://phabricator.services.mozilla.com/D35724 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ee45c802a7
commit
2a6bd5b432
@ -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<JSObject*> result(aCx);
|
||||
{
|
||||
RefPtr<RTCCertificate> 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;
|
||||
|
@ -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.
|
||||
|
@ -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> 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<SSLKEAType>(authType);
|
||||
RefPtr<RTCCertificate> cert = new RTCCertificate(aGlobal);
|
||||
cert->mAuthType = static_cast<SSLKEAType>(authType);
|
||||
|
||||
uint32_t high, low;
|
||||
if (!JS_ReadUint32Pair(aReader, &high, &low)) {
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
mExpires = static_cast<PRTime>(high) << 32 | low;
|
||||
cert->mExpires = static_cast<PRTime>(high) << 32 | low;
|
||||
|
||||
return ReadPrivateKey(aReader) && ReadCertificate(aReader);
|
||||
if (!cert->ReadPrivateKey(aReader) || !cert->ReadCertificate(aReader)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return cert.forget();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
@ -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<RTCCertificate> ReadStructuredClone(
|
||||
JSContext* aCx, nsIGlobalObject* aGlobal,
|
||||
JSStructuredCloneReader* aReader);
|
||||
|
||||
private:
|
||||
~RTCCertificate() {}
|
||||
|
@ -11,7 +11,7 @@ dictionary RTCCertificateExpiration {
|
||||
DOMTimeStamp expires;
|
||||
};
|
||||
|
||||
[Pref="media.peerconnection.enabled"]
|
||||
[Pref="media.peerconnection.enabled", Serializable]
|
||||
interface RTCCertificate {
|
||||
readonly attribute DOMTimeStamp expires;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user