Bug 835712 - Use more webidl for safer JS traversal. r=bz, r=jesup

This commit is contained in:
Jan-Ivar Bruaroey 2013-02-13 14:26:30 -05:00
Родитель 92a410c896
Коммит ff4a56c545
6 изменённых файлов: 35 добавлений и 34 удалений

Просмотреть файл

@ -10,7 +10,7 @@
interface DummyInterface {
readonly attribute OnErrorEventHandlerNonNull onErrorEventHandler;
FilePropertyBag fileBag();
RTCIceServer rtcIceServer();
RTCConfiguration rtcConfiguration();
CFStateChangeEventDict cfstateChangeEvent();
USSDReceivedEventDict ussdReceivedEvent();
};

Просмотреть файл

@ -0,0 +1,14 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
dictionary RTCIceServer {
DOMString url;
DOMString? credential = null;
};
dictionary RTCConfiguration {
sequence<RTCIceServer> iceServers;
};

Просмотреть файл

@ -124,7 +124,7 @@ webidl_files = \
ProcessingInstruction.webidl \
Rect.webidl \
RGBColor.webidl \
RTCIceServer.webidl \
RTCConfiguration.webidl \
Screen.webidl \
SVGAElement.webidl \
SVGAltGlyphElement.webidl \

Просмотреть файл

@ -43,7 +43,7 @@
#include "nsURLHelper.h"
#include "nsNetUtil.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/RTCIceServerBinding.h"
#include "mozilla/dom/RTCConfigurationBinding.h"
#include "MediaStreamList.h"
#include "nsIScriptGlobalObject.h"
#include "jsapi.h"
@ -347,43 +347,30 @@ Warn(JSContext* aCx, const nsCString& aMsg) {
* { url:"turn:user@turn.example.org", credential:"mypass"} ] }
*
* This function converts an already-validated jsval that looks like the above
* into an RTCConfiguration object.
* into an IceConfiguration object.
*/
nsresult
PeerConnectionImpl::ConvertRTCConfiguration(const JS::Value& aSrc,
RTCConfiguration *aDst,
IceConfiguration *aDst,
JSContext* aCx)
{
#ifdef MOZILLA_INTERNAL_API
if (!aSrc.isObject()) {
return NS_ERROR_FAILURE;
}
JSObject& config = aSrc.toObject();
JSAutoCompartment ac(aCx, &config);
JS::Value jsServers;
if (!(JS_GetProperty(aCx, &config, "iceServers", &jsServers) && jsServers.isObject())) {
JSAutoCompartment ac(aCx, &aSrc.toObject());
RTCConfiguration config;
if (!(config.Init(aCx, nullptr, aSrc) && config.mIceServers.WasPassed())) {
return NS_ERROR_FAILURE;
}
JSObject& servers = jsServers.toObject();
uint32_t len;
if (!(IsArrayLike(aCx, &servers) && JS_GetArrayLength(aCx, &servers, &len))) {
return NS_ERROR_FAILURE;
}
for (uint32_t i = 0; i < len; i++) {
nsresult rv;
// XXXbz once this moves to WebIDL, remove the RTCIceServer hack
// in DummyBinding.webidl.
RTCIceServer server;
{
JS::Value v;
if (!(JS_GetElement(aCx, &servers, i, &v) && server.Init(aCx, nullptr, v))) {
return NS_ERROR_FAILURE;
}
}
for (uint32_t i = 0; i < config.mIceServers.Value().Length(); i++) {
// XXXbz once this moves to WebIDL, remove RTCConfiguration in DummyBinding.webidl.
RTCIceServer& server = config.mIceServers.Value()[i];
if (!server.mUrl.WasPassed()) {
return NS_ERROR_FAILURE;
}
nsRefPtr<nsIURI> url;
nsresult rv;
rv = NS_NewURI(getter_AddRefs(url), server.mUrl.Value());
NS_ENSURE_SUCCESS(rv, rv);
bool isStun = false, isStuns = false, isTurn = false, isTurns = false;
@ -450,7 +437,7 @@ PeerConnectionImpl::Initialize(IPeerConnectionObserver* aObserver,
nsresult
PeerConnectionImpl::Initialize(IPeerConnectionObserver* aObserver,
nsIDOMWindow* aWindow,
const RTCConfiguration* aConfiguration,
const IceConfiguration* aConfiguration,
const JS::Value* aRTCConfiguration,
nsIThread* aThread,
JSContext* aCx)
@ -500,7 +487,7 @@ PeerConnectionImpl::Initialize(IPeerConnectionObserver* aObserver,
// Initialize the media object.
if (aRTCConfiguration) {
RTCConfiguration ic;
IceConfiguration ic;
res = ConvertRTCConfiguration(*aRTCConfiguration, &ic, aCx);
NS_ENSURE_SUCCESS(res, res);
res = mMedia->Init(ic.getServers());

Просмотреть файл

@ -65,7 +65,7 @@ private:
constraints_map mConstraints;
};
class RTCConfiguration
class IceConfiguration
{
public:
bool addServer(const std::string& addr, uint16_t port)
@ -141,7 +141,7 @@ public:
static PeerConnectionImpl* CreatePeerConnection();
static nsresult ConvertRTCConfiguration(const JS::Value& aSrc,
RTCConfiguration *aDst, JSContext* aCx);
IceConfiguration *aDst, JSContext* aCx);
static nsresult ConvertConstraints(
const JS::Value& aConstraints, MediaConstraints* aObj, JSContext* aCx);
static nsresult MakeMediaStream(nsIDOMWindow* aWindow,
@ -209,10 +209,10 @@ public:
return mWindow;
}
// Initialize PeerConnection from an RTCConfiguration object.
// Initialize PeerConnection from an IceConfiguration object.
nsresult Initialize(IPeerConnectionObserver* aObserver,
nsIDOMWindow* aWindow,
const RTCConfiguration& aConfiguration,
const IceConfiguration& aConfiguration,
nsIThread* aThread) {
return Initialize(aObserver, aWindow, &aConfiguration, nullptr, aThread, nullptr);
}
@ -227,7 +227,7 @@ private:
PeerConnectionImpl& operator=(PeerConnectionImpl);
nsresult Initialize(IPeerConnectionObserver* aObserver,
nsIDOMWindow* aWindow,
const RTCConfiguration* aConfiguration,
const IceConfiguration* aConfiguration,
const JS::Value* aRTCConfiguration,
nsIThread* aThread,
JSContext* aCx);

Просмотреть файл

@ -534,7 +534,7 @@ class SignalingAgent {
pObserver = new TestObserver(pc);
ASSERT_TRUE(pObserver);
sipcc::RTCConfiguration cfg;
sipcc::IceConfiguration cfg;
cfg.addServer("23.21.150.121", 3478);
ASSERT_EQ(pc->Initialize(pObserver, nullptr, cfg, thread), NS_OK);
@ -562,7 +562,7 @@ class SignalingAgent {
if (!pObserver)
return false;
sipcc::RTCConfiguration cfg;
sipcc::IceConfiguration cfg;
cfg.addServer("23.21.150.121", 3478);
if (NS_FAILED(pc->Initialize(pObserver, nullptr, cfg, thread)))
return false;