Bug 975144 - Adding rtcIdentityProvider to sandbox global scope, r=gabor
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -25,21 +25,21 @@
#include "nsXMLHttpRequest.h"
#include "WrapperFactory.h"
#include "xpcprivate.h"
#include "XPCWrapper.h"
#include "XrayWrapper.h"
#include "Crypto.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/BlobBinding.h"
-#include "mozilla/dom/CryptoBinding.h"
#include "mozilla/dom/CSSBinding.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/FileBinding.h"
#include "mozilla/dom/PromiseBinding.h"
+#include "mozilla/dom/RTCIdentityProviderRegistrar.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/TextDecoderBinding.h"
#include "mozilla/dom/TextEncoderBinding.h"
#include "mozilla/dom/URLBinding.h"
#include "mozilla/dom/URLSearchParamsBinding.h"
using namespace mozilla;
using namespace JS;
@@ -224,21 +224,35 @@ SandboxCreateCrypto(JSContext *cx, JS::H
{
MOZ_ASSERT(JS_IsGlobalObject(obj));
nsIGlobalObject* native = xpc::NativeGlobal(obj);
MOZ_ASSERT(native);
dom::Crypto* crypto = new dom::Crypto();
crypto->Init(native);
- JS::RootedObject wrapped(cx, dom::CryptoBinding::Wrap(cx, crypto));
+ JS::RootedObject wrapped(cx, crypto->WrapObject(cx));
return JS_DefineProperty(cx, obj, "crypto", wrapped, JSPROP_ENUMERATE);
}
static bool
+SandboxCreateRTCIdentityProvider(JSContext *cx, JS::HandleObject obj)
+{
+ MOZ_ASSERT(JS_IsGlobalObject(obj));
+
+ nsCOMPtr<nsIGlobalObject> nativeGlobal = xpc::NativeGlobal(obj);
+ MOZ_ASSERT(nativeGlobal);
+
+ dom::RTCIdentityProviderRegistrar* registrar =
+ new dom::RTCIdentityProviderRegistrar(nativeGlobal);
+ JS::RootedObject wrapped(cx, registrar->WrapObject(cx));
+ return JS_DefineProperty(cx, obj, "rtcIdentityProvider", wrapped, JSPROP_ENUMERATE);
+}
+
+static bool
SandboxIsProxy(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() < 1) {
JS_ReportError(cx, "Function requires at least 1 argument");
return false;
}
if (!args[0].isObject()) {
@@ -797,16 +811,18 @@ xpc::GlobalProperties::Parse(JSContext *
} else if (!strcmp(name.ptr(), "btoa")) {
btoa = true;
} else if (!strcmp(name.ptr(), "Blob")) {
Blob = true;
} else if (!strcmp(name.ptr(), "File")) {
File = true;
} else if (!strcmp(name.ptr(), "crypto")) {
crypto = true;
+ } else if (!strcmp(name.ptr(), "rtcIdentityProvider")) {
+ rtcIdentityProvider = true;
} else {
JS_ReportError(cx, "Unknown property name: %s", name.ptr());
return false;
}
}
return true;
}
@@ -854,16 +870,19 @@ xpc::GlobalProperties::Define(JSContext
if (File &&
!dom::FileBinding::GetConstructorObject(cx, obj))
return false;
if (crypto && !SandboxCreateCrypto(cx, obj))
return false;
+ if (rtcIdentityProvider && !SandboxCreateRTCIdentityProvider(cx, obj))
+ return false;
+
return true;
}
nsresult
xpc::CreateSandboxObject(JSContext *cx, MutableHandleValue vp, nsISupports *prinOrSop,
SandboxOptions& options)
{
// Create the sandbox global object
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -3365,16 +3365,17 @@ struct GlobalProperties {
bool TextEncoder : 1;
bool URL : 1;
bool URLSearchParams : 1;
bool atob : 1;
bool btoa : 1;
bool Blob : 1;
bool File : 1;
bool crypto : 1;
+ bool rtcIdentityProvider : 1;
};
// Infallible.
already_AddRefed<nsIXPCComponents_utils_Sandbox>
NewSandboxConstructor();
// Returns true if class of 'obj' is SandboxClass.
bool