зеркало из https://github.com/mozilla/gecko-dev.git
merge b2g-inbound to mozilla-central
This commit is contained in:
Коммит
2490b7a836
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"revision": "1f7e70f3ad1c7a79dc03410d774e32a07093da3f",
|
||||
"revision": "207a81a6816b8627674a956b521772de2ac6b572",
|
||||
"repo_path": "/integration/gaia-central"
|
||||
}
|
||||
|
|
|
@ -248,6 +248,7 @@ BluetoothAdapter::SetPropertyByValue(const BluetoothNamedValue& aValue)
|
|||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
NS_ENSURE_TRUE_VOID(sc);
|
||||
|
||||
AutoPushJSContext cx(sc->GetNativeContext());
|
||||
JS::Rooted<JSObject*> uuids(cx);
|
||||
|
@ -263,6 +264,7 @@ BluetoothAdapter::SetPropertyByValue(const BluetoothNamedValue& aValue)
|
|||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
NS_ENSURE_TRUE_VOID(sc);
|
||||
|
||||
AutoPushJSContext cx(sc->GetNativeContext());
|
||||
JS::Rooted<JSObject*> deviceAddresses(cx);
|
||||
|
|
|
@ -125,6 +125,7 @@ BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue)
|
|||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
NS_ENSURE_TRUE_VOID(sc);
|
||||
|
||||
AutoPushJSContext cx(sc->GetNativeContext());
|
||||
|
||||
|
@ -140,6 +141,7 @@ BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue)
|
|||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
NS_ENSURE_TRUE_VOID(sc);
|
||||
|
||||
AutoPushJSContext cx(sc->GetNativeContext());
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "base/basictypes.h"
|
||||
#include "BluetoothOppManager.h"
|
||||
|
||||
#include "BluetoothProfileController.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothSocket.h"
|
||||
#include "BluetoothUtils.h"
|
||||
|
@ -189,7 +188,6 @@ BluetoothOppManager::BluetoothOppManager() : mConnected(false)
|
|||
, mSentFileLength(0)
|
||||
, mWaitingToSendPutFinal(false)
|
||||
, mCurrentBlobIndex(-1)
|
||||
, mController(nullptr)
|
||||
{
|
||||
mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
}
|
||||
|
@ -278,48 +276,6 @@ BluetoothOppManager::ConnectInternal(const nsAString& aDeviceAddress)
|
|||
new BluetoothSocket(this, BluetoothSocketType::RFCOMM, true, true);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::Connect(const nsAString& aDeviceAddress,
|
||||
BluetoothProfileController* aController)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aController && !mController);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs || sInShutdown) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSocket) {
|
||||
if (mConnectedDeviceAddress == aDeviceAddress) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
} else {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_REACHED_CONNECTION_LIMIT));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
mController = aController;
|
||||
OnConnect(EmptyString());
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::Disconnect(BluetoothProfileController* aController)
|
||||
{
|
||||
if (!mSocket) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!mController);
|
||||
|
||||
mController = aController;
|
||||
mSocket->Disconnect();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::HandleShutdown()
|
||||
{
|
||||
|
@ -1582,37 +1538,27 @@ BluetoothOppManager::AcquireSdcardMountLock()
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::Connect(const nsAString& aDeviceAddress,
|
||||
BluetoothProfileController* aController)
|
||||
{
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::Disconnect(BluetoothProfileController* aController)
|
||||
{
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::OnConnect(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!aErrorStr.IsEmpty()) {
|
||||
mSocket = nullptr;
|
||||
Listen();
|
||||
}
|
||||
|
||||
/**
|
||||
* On the one hand, notify the controller that we've done for outbound
|
||||
* connections. On the other hand, we do nothing for inbound connections.
|
||||
*/
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnConnect(aErrorStr);
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/**
|
||||
* On the one hand, notify the controller that we've done for outbound
|
||||
* connections. On the other hand, we do nothing for inbound connections.
|
||||
*/
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnDisconnect(aErrorStr);
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
|
|
@ -82,17 +82,6 @@ public:
|
|||
aName.AssignLiteral("OPP");
|
||||
}
|
||||
|
||||
/*
|
||||
* If an application wants to send a file, first, it needs to
|
||||
* call Connect() to create a valid RFCOMM connection. After
|
||||
* that, call SendFile()/StopSendingFile() to control file-sharing
|
||||
* process. During the file transfering process, the application
|
||||
* will receive several system messages which contain the processed
|
||||
* percentage of file. At the end, the application will get another
|
||||
* system message indicating that the process is complete, then it can
|
||||
* either call Disconnect() to close RFCOMM connection or start another
|
||||
* file-sending thread via calling SendFile() again.
|
||||
*/
|
||||
virtual void Connect(const nsAString& aDeviceAddress,
|
||||
BluetoothProfileController* aController) MOZ_OVERRIDE;
|
||||
virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE;
|
||||
|
@ -222,7 +211,6 @@ private:
|
|||
nsCOMPtr<nsIOutputStream> mOutputStream;
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
nsCOMPtr<nsIVolumeMountLock> mMountLock;
|
||||
nsRefPtr<BluetoothProfileController> mController;
|
||||
nsRefPtr<DeviceStorageFile> mDsFile;
|
||||
|
||||
// If a connection has been established, mSocket will be the socket
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "BluetoothA2dpManager.h"
|
||||
#include "BluetoothHfpManager.h"
|
||||
#include "BluetoothHidManager.h"
|
||||
#include "BluetoothOppManager.h"
|
||||
|
||||
#include "BluetoothUtils.h"
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
|
@ -80,9 +79,6 @@ BluetoothProfileController::AddProfileWithServiceClass(
|
|||
case BluetoothServiceClass::A2DP:
|
||||
profile = BluetoothA2dpManager::Get();
|
||||
break;
|
||||
case BluetoothServiceClass::OBJECT_PUSH:
|
||||
profile = BluetoothOppManager::Get();
|
||||
break;
|
||||
case BluetoothServiceClass::HID:
|
||||
profile = BluetoothHidManager::Get();
|
||||
break;
|
||||
|
@ -132,7 +128,6 @@ BluetoothProfileController::SetupProfiles(bool aAssignServiceClass)
|
|||
// For a disconnect request, all connected profiles are put into array.
|
||||
if (!mConnect) {
|
||||
AddProfile(BluetoothHidManager::Get(), true);
|
||||
AddProfile(BluetoothOppManager::Get(), true);
|
||||
AddProfile(BluetoothA2dpManager::Get(), true);
|
||||
AddProfile(BluetoothHfpManager::Get(), true);
|
||||
return;
|
||||
|
@ -143,17 +138,13 @@ BluetoothProfileController::SetupProfiles(bool aAssignServiceClass)
|
|||
* all of them sequencely.
|
||||
*/
|
||||
bool hasAudio = HAS_AUDIO(mTarget.cod);
|
||||
bool hasObjectTransfer = HAS_OBJECT_TRANSFER(mTarget.cod);
|
||||
bool hasRendering = HAS_RENDERING(mTarget.cod);
|
||||
bool isPeripheral = IS_PERIPHERAL(mTarget.cod);
|
||||
|
||||
NS_ENSURE_TRUE_VOID(hasAudio || hasObjectTransfer ||
|
||||
hasRendering || isPeripheral);
|
||||
NS_ENSURE_TRUE_VOID(hasAudio || hasRendering || isPeripheral);
|
||||
|
||||
/**
|
||||
* Connect to HFP/HSP first. Then, connect A2DP if Rendering bit is set.
|
||||
* It's almost impossible to send file to a remote device which is an Audio
|
||||
* device or a Rendering device, so we won't connect OPP in that case.
|
||||
*/
|
||||
if (hasAudio) {
|
||||
AddProfile(BluetoothHfpManager::Get());
|
||||
|
@ -161,9 +152,6 @@ BluetoothProfileController::SetupProfiles(bool aAssignServiceClass)
|
|||
if (hasRendering) {
|
||||
AddProfile(BluetoothA2dpManager::Get());
|
||||
}
|
||||
if (hasObjectTransfer && !hasAudio && !hasRendering) {
|
||||
AddProfile(BluetoothOppManager::Get());
|
||||
}
|
||||
if (isPeripheral) {
|
||||
AddProfile(BluetoothHidManager::Get());
|
||||
}
|
||||
|
|
|
@ -37,9 +37,6 @@ BEGIN_BLUETOOTH_NAMESPACE
|
|||
// Bit 21: Major service class = 0x100, Audio
|
||||
#define HAS_AUDIO(cod) (cod & 0x200000)
|
||||
|
||||
// Bit 20: Major service class = 0x80, Object Transfer
|
||||
#define HAS_OBJECT_TRANSFER(cod) (cod & 0x100000)
|
||||
|
||||
// Bit 18: Major service class = 0x20, Rendering
|
||||
#define HAS_RENDERING(cod) (cod & 0x40000)
|
||||
|
||||
|
|
|
@ -1009,19 +1009,21 @@ var steps = [
|
|||
next();
|
||||
},
|
||||
function() {
|
||||
ok(true, "Undefined strings should be treated as null");
|
||||
ok(true, "Undefined properties of fields should be treated correctly");
|
||||
var c = new mozContact({
|
||||
adr: [{value: undefined}],
|
||||
adr: [{streetAddress: undefined}],
|
||||
email: [{value: undefined}],
|
||||
url: [{value: undefined}],
|
||||
impp: [{value: undefined}],
|
||||
tel: [{value: undefined}],
|
||||
});
|
||||
is(c.adr[0].type, null, "adr is null");
|
||||
is(c.email[0].type, null, "email is null");
|
||||
is(c.url[0].type, null, "url is null");
|
||||
is(c.impp[0].type, null, "impp is null");
|
||||
is(c.tel[0].type, null, "tel is null");
|
||||
ise(c.adr[0].streetAddress, null, "adr.streetAddress is null");
|
||||
ise(c.adr[0].locality, null, "adr.locality is null");
|
||||
ise(c.adr[0].pref, null, "adr.pref is null");
|
||||
ise(c.email[0].value, null, "email.value is null");
|
||||
ise(c.url[0].value, null, "url.value is null");
|
||||
ise(c.impp[0].value, null, "impp.value is null");
|
||||
ise(c.tel[0].value, null, "tel.value is null");
|
||||
next();
|
||||
},
|
||||
function() {
|
||||
|
|
|
@ -310,7 +310,7 @@ interface nsIDOMMozIccManager : nsIDOMEventTarget
|
|||
* 'pukRequired', 'personalizationInProgress', 'networkLocked',
|
||||
* 'corporateLocked', 'serviceProviderLocked', 'networkPukRequired',
|
||||
* 'corporatePukRequired', 'serviceProviderPukRequired',
|
||||
* 'personalizationReady', 'ready'.
|
||||
* 'personalizationReady', 'ready', 'permanentBlocked'.
|
||||
*/
|
||||
readonly attribute DOMString cardState;
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
if (expect) {
|
||||
func(evt.command, expect);
|
||||
} else {
|
||||
func(evt.command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect);
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testDisplayText(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -96,40 +91,4 @@ let tests = [
|
|||
timeInterval: 0x0A}}},
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testGetInKey(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -107,40 +102,4 @@ let tests = [
|
|||
timeInterval: 0x0A}}},
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testGetInput(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -174,40 +169,4 @@ let tests = [
|
|||
maxLength: 10}},
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testLaunchBrowser(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -251,40 +246,4 @@ let tests = [
|
|||
text: "ル"}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testPollOff(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -23,40 +18,4 @@ let tests = [
|
|||
commandQualifier: 0x00}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testLocalInfoLocation(cmd) {
|
||||
log("STK CMD " + JSON.stringify(cmd));
|
||||
|
@ -109,39 +104,4 @@ let tests = [
|
|||
func: testTimerManagementGetCurrentValue},
|
||||
];
|
||||
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(cmd, func) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(cmd, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let cmd = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(cmd, test.func)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testRefresh(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -27,40 +22,4 @@ let tests = [
|
|||
commandQualifier: 0x04}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSelectItem(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -312,40 +307,4 @@ let tests = [
|
|||
items: [{identifier: 1, text: "82ル1"}, {identifier: 2, text: "82ル2"}, {identifier: 3, text: "82ル3"}]}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSendDTMF(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -192,40 +187,4 @@ let tests = [
|
|||
text: "ル"}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSendSMS(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -242,40 +237,4 @@ let tests = [
|
|||
title: "82ル2"}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSendSS(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -202,40 +197,4 @@ let tests = [
|
|||
title: "ル"}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSendUSSD(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -207,40 +202,4 @@ let tests = [
|
|||
title: "ル"}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSetupCall(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -346,40 +341,4 @@ let tests = [
|
|||
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSetupEventList(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -52,40 +47,4 @@ let tests = [
|
|||
eventList: [7]}}
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSetupIdleModeText(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -195,40 +190,4 @@ let tests = [
|
|||
text: "80ル0"}},
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 30000;
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
|
||||
let icc = navigator.mozIccManager;
|
||||
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
||||
MARIONETTE_HEAD_JS = "stk_helper.js";
|
||||
|
||||
function testSetupMenu(command, expect) {
|
||||
log("STK CMD " + JSON.stringify(command));
|
||||
|
@ -234,40 +229,4 @@ let tests = [
|
|||
|
||||
];
|
||||
|
||||
// TODO - Bug 843455: Import scripts for marionette tests.
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
function sendStkPduToEmulator(command, func, expect) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
runEmulatorCmd(command, function (result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
is(result[0], "OK");
|
||||
});
|
||||
|
||||
icc.onstkcommand = function (evt) {
|
||||
func(evt.command, expect);
|
||||
}
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
let test = tests.pop();
|
||||
if (!test) {
|
||||
cleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = "stk pdu " + test.command;
|
||||
sendStkPduToEmulator(command, test.func, test.expect)
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
|
||||
runNextTest();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
if CONFIG['MOZ_WEBRTC']:
|
||||
DIRS += ['bridge']
|
||||
|
||||
TEST_DIRS += ['tests/mochitest']
|
||||
TEST_DIRS += ['tests/mochitest', 'tests/ipc']
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIDOMMediaStream.idl',
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
# 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/.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
[DEFAULT]
|
||||
|
||||
[test_ipc.html]
|
|
@ -0,0 +1,7 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
MOCHITEST_MANIFESTS += ['mochitest.ini']
|
|
@ -0,0 +1,175 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for OOP PeerConncection</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// This isn't a single test. It runs the entirety of the PeerConnection
|
||||
// tests. Each of those has a normal timeout handler, so there's no point in
|
||||
// having a timeout here. I'm setting this really high just to avoid getting
|
||||
// killed.
|
||||
SimpleTest.requestLongerTimeout(100);
|
||||
|
||||
// Disable crash observers as it breaks later tests.
|
||||
function iframeScriptFirst() {
|
||||
SpecialPowers.prototype.registerProcessCrashObservers = function() { };
|
||||
SpecialPowers.prototype.unregisterProcessCrashObservers = function() { };
|
||||
|
||||
content.wrappedJSObject.RunSet.reloadAndRunAll({
|
||||
preventDefault: function() { },
|
||||
__exposedProps__: { preventDefault: 'r' }
|
||||
});
|
||||
}
|
||||
|
||||
function iframeScriptSecond() {
|
||||
let TestRunner = content.wrappedJSObject.TestRunner;
|
||||
|
||||
let oldComplete = TestRunner.onComplete;
|
||||
|
||||
TestRunner.onComplete = function() {
|
||||
TestRunner.onComplete = oldComplete;
|
||||
|
||||
sendAsyncMessage("test:PeerConnection:ipcTestComplete", {
|
||||
result: JSON.stringify(TestRunner._failedTests)
|
||||
});
|
||||
|
||||
if (oldComplete) {
|
||||
oldComplete();
|
||||
}
|
||||
};
|
||||
|
||||
let oldLog = TestRunner.log;
|
||||
TestRunner.log = function(msg) {
|
||||
sendAsyncMessage("test:PeerConnection:ipcTestMessage", { msg: msg });
|
||||
}
|
||||
}
|
||||
|
||||
let regex = /^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL|TEST-DEBUG-INFO) \| ([^\|]+) \|(.*)/;
|
||||
|
||||
function onTestMessage(data) {
|
||||
let message = SpecialPowers.wrap(data).json.msg;
|
||||
let match = regex.exec(message);
|
||||
if (match) {
|
||||
let state = match[1];
|
||||
let details = match[2] + " | " + match[3];
|
||||
|
||||
switch (state) {
|
||||
case "TEST-PASS":
|
||||
case "TEST-KNOWN-FAIL":
|
||||
ok(true, details);
|
||||
break;
|
||||
|
||||
case "TEST-UNEXPECTED-FAIL":
|
||||
case "TEST-UNEXPECTED-PASS":
|
||||
ok(false, details);
|
||||
break;
|
||||
|
||||
case "TEST-DEBUG-INFO":
|
||||
default:
|
||||
info(details);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onTestComplete() {
|
||||
let comp = SpecialPowers.wrap(SpecialPowers.Components);
|
||||
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
|
||||
let spObserver = comp.classes["@mozilla.org/special-powers-observer;1"]
|
||||
.getService(comp.interfaces.nsIMessageListener);
|
||||
|
||||
mm.removeMessageListener("SPPrefService", spObserver);
|
||||
mm.removeMessageListener("SPProcessCrashService", spObserver);
|
||||
mm.removeMessageListener("SPPingService", spObserver);
|
||||
mm.removeMessageListener("SpecialPowers.Quit", spObserver);
|
||||
mm.removeMessageListener("SPPermissionManager", spObserver);
|
||||
|
||||
mm.removeMessageListener("test:PeerConnection:ipcTestMessage", onTestMessage);
|
||||
mm.removeMessageListener("test:PeerConnection:ipcTestComplete", onTestComplete);
|
||||
|
||||
SimpleTest.executeSoon(function () { SimpleTest.finish(); });
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
let iframe = document.createElement("iframe");
|
||||
SpecialPowers.wrap(iframe).mozbrowser = true;
|
||||
iframe.id = "iframe";
|
||||
iframe.style.width = "100%";
|
||||
iframe.style.height = "1000px";
|
||||
|
||||
function iframeLoadSecond() {
|
||||
ok(true, "Got second iframe load event.");
|
||||
iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond);
|
||||
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
|
||||
mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();",
|
||||
false);
|
||||
}
|
||||
|
||||
function iframeLoadFirst() {
|
||||
ok(true, "Got first iframe load event.");
|
||||
iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst);
|
||||
iframe.addEventListener("mozbrowserloadend", iframeLoadSecond);
|
||||
|
||||
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
|
||||
|
||||
let comp = SpecialPowers.wrap(SpecialPowers.Components);
|
||||
|
||||
let spObserver =
|
||||
comp.classes["@mozilla.org/special-powers-observer;1"]
|
||||
.getService(comp.interfaces.nsIMessageListener);
|
||||
|
||||
mm.addMessageListener("SPPrefService", spObserver);
|
||||
mm.addMessageListener("SPProcessCrashService", spObserver);
|
||||
mm.addMessageListener("SPPingService", spObserver);
|
||||
mm.addMessageListener("SpecialPowers.Quit", spObserver);
|
||||
mm.addMessageListener("SPPermissionManager", spObserver);
|
||||
|
||||
mm.addMessageListener("test:PeerConnection:ipcTestMessage", onTestMessage);
|
||||
mm.addMessageListener("test:PeerConnection:ipcTestComplete", onTestComplete);
|
||||
|
||||
let specialPowersBase = "chrome://specialpowers/content/";
|
||||
mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false);
|
||||
mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false);
|
||||
mm.loadFrameScript(specialPowersBase + "specialpowers.js", false);
|
||||
|
||||
mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();", false);
|
||||
}
|
||||
|
||||
iframe.addEventListener("mozbrowserloadend", iframeLoadFirst);
|
||||
|
||||
// Strip this filename and one directory level and then add "/mochitest".
|
||||
let href = window.location.href;
|
||||
href = href.substring(0, href.lastIndexOf('/'));
|
||||
href = href.substring(0, href.lastIndexOf('/'));
|
||||
iframe.src = href + "/mochitest?consoleLevel=INFO";
|
||||
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
addEventListener("load", function() {
|
||||
|
||||
SpecialPowers.addPermission("browser", true, document);
|
||||
SpecialPowers.pushPrefEnv({
|
||||
"set": [
|
||||
["media.peerconnection.ipc.enabled", true],
|
||||
|
||||
// TODO: remove this as part of bug 820712
|
||||
["network.disable.ipc.security", true],
|
||||
|
||||
["dom.ipc.browser_frames.oop_by_default", true],
|
||||
["dom.mozBrowserFramesEnabled", true],
|
||||
["browser.pagethumbnails.capturing_disabled", true]
|
||||
]
|
||||
}, runTests);
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -13,6 +13,7 @@ XPIDL_SOURCES += [
|
|||
'nsITCPServerSocketParent.idl',
|
||||
'nsITCPSocketChild.idl',
|
||||
'nsITCPSocketParent.idl',
|
||||
'nsIUDPSocketChild.idl',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_RIL']:
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* 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/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsINetAddr.idl"
|
||||
|
||||
interface nsIUDPSocketInternal;
|
||||
|
||||
%{ C++
|
||||
#include "mozilla/net/DNS.h"
|
||||
%}
|
||||
native NetAddr(mozilla::net::NetAddr);
|
||||
[ptr] native NetAddrPtr(mozilla::net::NetAddr);
|
||||
|
||||
[scriptable, uuid(B47E5A0F-D384-48EF-8885-4259793D9CF0)]
|
||||
interface nsIUDPSocketChild : nsISupports
|
||||
{
|
||||
readonly attribute unsigned short localPort;
|
||||
readonly attribute AUTF8String localAddress;
|
||||
// Tell the chrome process to bind the UDP socket to a given local host and port
|
||||
void bind(in nsIUDPSocketInternal socket, in AUTF8String host, in unsigned short port);
|
||||
|
||||
// Tell the chrome process to perform equivalent operations to all following methods
|
||||
void send(in AUTF8String host, in unsigned short port,
|
||||
[const, array, size_is(byteLength)] in uint8_t bytes,
|
||||
in unsigned long byteLength);
|
||||
// Send without DNS query
|
||||
void sendWithAddr(in nsINetAddr addr,
|
||||
[const, array, size_is(byteLength)] in uint8_t bytes,
|
||||
in unsigned long byteLength);
|
||||
[noscript] void sendWithAddress([const] in NetAddrPtr addr,
|
||||
[const, array, size_is(byteLength)] in uint8_t bytes,
|
||||
in unsigned long byteLength);
|
||||
void close();
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal interface for callback from chrome process
|
||||
*/
|
||||
[scriptable, uuid(1E27E9B3-C1C8-4B05-A415-1A2C1A641C60)]
|
||||
interface nsIUDPSocketInternal : nsISupports
|
||||
{
|
||||
void callListenerError(in AUTF8String type, in AUTF8String message, in AUTF8String filename,
|
||||
in uint32_t lineNumber, in uint32_t columnNumber);
|
||||
void callListenerReceivedData(in AUTF8String type, in AUTF8String host, in unsigned short port,
|
||||
[array, size_is(dataLength)] in uint8_t data,
|
||||
in unsigned long dataLength);
|
||||
void callListenerVoid(in AUTF8String type);
|
||||
void callListenerSent(in AUTF8String type, in nsresult status);
|
||||
void updateReadyState(in AUTF8String readyState);
|
||||
};
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et tw=80 ft=cpp : */
|
||||
|
||||
/* 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/. */
|
||||
|
||||
include protocol PNecko;
|
||||
|
||||
include "mozilla/net/NeckoMessageUtils.h";
|
||||
include "mozilla/net/DNS.h";
|
||||
include "prio.h";
|
||||
|
||||
using mozilla::net::NetAddr from "mozilla/net/DNS.h";
|
||||
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
|
||||
|
||||
struct UDPError {
|
||||
nsCString message;
|
||||
nsCString filename;
|
||||
uint32_t lineNumber;
|
||||
uint32_t columnNumber;
|
||||
};
|
||||
|
||||
struct UDPMessage {
|
||||
nsCString fromAddr;
|
||||
uint16_t port;
|
||||
uint8_t[] data;
|
||||
};
|
||||
|
||||
struct UDPAddressInfo {
|
||||
nsCString local;
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
struct UDPSendResult {
|
||||
nsresult value;
|
||||
};
|
||||
|
||||
union UDPCallbackData {
|
||||
void_t;
|
||||
UDPMessage;
|
||||
UDPAddressInfo;
|
||||
UDPSendResult;
|
||||
UDPError;
|
||||
};
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
protocol PUDPSocket
|
||||
{
|
||||
manager PNecko;
|
||||
|
||||
parent:
|
||||
Data(uint8_t[] data, nsCString remoteAddress, uint16_t port);
|
||||
DataWithAddress(uint8_t[] data, NetAddr addr);
|
||||
Close();
|
||||
RequestDelete();
|
||||
|
||||
child:
|
||||
Callback(nsCString type, UDPCallbackData data, nsCString aState);
|
||||
__delete__();
|
||||
};
|
||||
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
/* 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/. */
|
||||
|
||||
#include "UDPSocketChild.h"
|
||||
#include "mozilla/net/NeckoChild.h"
|
||||
|
||||
using mozilla::net::gNeckoChild;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_ISUPPORTS1(UDPSocketChildBase, nsIUDPSocketChild)
|
||||
|
||||
UDPSocketChildBase::UDPSocketChildBase()
|
||||
: mIPCOpen(false)
|
||||
{
|
||||
}
|
||||
|
||||
UDPSocketChildBase::~UDPSocketChildBase()
|
||||
{
|
||||
}
|
||||
void
|
||||
UDPSocketChildBase::ReleaseIPDLReference()
|
||||
{
|
||||
MOZ_ASSERT(mIPCOpen);
|
||||
mIPCOpen = false;
|
||||
this->Release();
|
||||
}
|
||||
|
||||
void
|
||||
UDPSocketChildBase::AddIPDLReference()
|
||||
{
|
||||
MOZ_ASSERT(!mIPCOpen);
|
||||
mIPCOpen = true;
|
||||
this->AddRef();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) UDPSocketChild::Release(void)
|
||||
{
|
||||
nsrefcnt refcnt = UDPSocketChildBase::Release();
|
||||
if (refcnt == 1 && mIPCOpen) {
|
||||
PUDPSocketChild::SendRequestDelete();
|
||||
return 1;
|
||||
}
|
||||
return refcnt;
|
||||
}
|
||||
|
||||
UDPSocketChild::UDPSocketChild()
|
||||
:mLocalPort(0)
|
||||
{
|
||||
}
|
||||
|
||||
UDPSocketChild::~UDPSocketChild()
|
||||
{
|
||||
}
|
||||
|
||||
// nsIUDPSocketChild Methods
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::Bind(nsIUDPSocketInternal *aSocket,
|
||||
const nsACString& aHost,
|
||||
uint16_t aPort)
|
||||
{
|
||||
NS_ENSURE_ARG(aSocket);
|
||||
|
||||
mSocket = aSocket;
|
||||
AddIPDLReference();
|
||||
|
||||
gNeckoChild->SendPUDPSocketConstructor(this, nsCString(aHost), aPort);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::Close()
|
||||
{
|
||||
SendClose();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::Send(const nsACString& aHost,
|
||||
uint16_t aPort,
|
||||
const uint8_t *aData,
|
||||
uint32_t aByteLength)
|
||||
{
|
||||
NS_ENSURE_ARG(aData);
|
||||
|
||||
FallibleTArray<uint8_t> fallibleArray;
|
||||
if (!fallibleArray.InsertElementsAt(0, aData, aByteLength)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
InfallibleTArray<uint8_t> array;
|
||||
array.SwapElements(fallibleArray);
|
||||
SendData(array, nsCString(aHost), aPort);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::SendWithAddr(nsINetAddr *aAddr,
|
||||
const uint8_t *aData,
|
||||
uint32_t aByteLength)
|
||||
{
|
||||
NS_ENSURE_ARG(aAddr);
|
||||
NS_ENSURE_ARG(aData);
|
||||
|
||||
NetAddr addr;
|
||||
aAddr->GetNetAddr(&addr);
|
||||
|
||||
return SendWithAddress(&addr, aData, aByteLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::SendWithAddress(const NetAddr *aAddr,
|
||||
const uint8_t *aData,
|
||||
uint32_t aByteLength)
|
||||
{
|
||||
NS_ENSURE_ARG(aAddr);
|
||||
NS_ENSURE_ARG(aData);
|
||||
|
||||
FallibleTArray<uint8_t> fallibleArray;
|
||||
if (!fallibleArray.InsertElementsAt(0, aData, aByteLength)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
InfallibleTArray<uint8_t> array;
|
||||
array.SwapElements(fallibleArray);
|
||||
SendDataWithAddress(array, *aAddr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::GetLocalPort(uint16_t *aLocalPort)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLocalPort);
|
||||
|
||||
*aLocalPort = mLocalPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::GetLocalAddress(nsACString &aLocalAddress)
|
||||
{
|
||||
aLocalAddress = mLocalAddress;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// PUDPSocketChild Methods
|
||||
bool
|
||||
UDPSocketChild::RecvCallback(const nsCString &aType,
|
||||
const UDPCallbackData &aData,
|
||||
const nsCString &aState)
|
||||
{
|
||||
if (NS_FAILED(mSocket->UpdateReadyState(aState)))
|
||||
NS_ERROR("Shouldn't fail!");
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (aData.type() == UDPCallbackData::Tvoid_t) {
|
||||
rv = mSocket->CallListenerVoid(aType);
|
||||
} else if (aData.type() == UDPCallbackData::TUDPError) {
|
||||
const UDPError& err(aData.get_UDPError());
|
||||
rv = mSocket->CallListenerError(aType, err.message(), err.filename(),
|
||||
err.lineNumber(), err.columnNumber());
|
||||
} else if (aData.type() == UDPCallbackData::TUDPMessage) {
|
||||
const UDPMessage& message(aData.get_UDPMessage());
|
||||
InfallibleTArray<uint8_t> data(message.data());
|
||||
rv = mSocket->CallListenerReceivedData(aType, message.fromAddr(), message.port(),
|
||||
data.Elements(), data.Length());
|
||||
} else if (aData.type() == UDPCallbackData::TUDPAddressInfo) {
|
||||
//update local address and port.
|
||||
const UDPAddressInfo& addressInfo(aData.get_UDPAddressInfo());
|
||||
mLocalAddress = addressInfo.local();
|
||||
mLocalPort = addressInfo.port();
|
||||
rv = mSocket->CallListenerVoid(aType);
|
||||
} else if (aData.type() == UDPCallbackData::TUDPSendResult) {
|
||||
const UDPSendResult& returnValue(aData.get_UDPSendResult());
|
||||
rv = mSocket->CallListenerSent(aType, returnValue.value());
|
||||
} else {
|
||||
MOZ_ASSERT("Invalid callback type!");
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,54 @@
|
|||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_UDPSocketChild_h__
|
||||
#define mozilla_dom_UDPSocketChild_h__
|
||||
|
||||
#include "mozilla/net/PUDPSocketChild.h"
|
||||
#include "nsIUDPSocketChild.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define UDPSOCKETCHILD_CID \
|
||||
{0xb47e5a0f, 0xd384, 0x48ef, { 0x88, 0x85, 0x42, 0x59, 0x79, 0x3d, 0x9c, 0xf0 }}
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class UDPSocketChildBase : public nsIUDPSocketChild {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
void AddIPDLReference();
|
||||
void ReleaseIPDLReference();
|
||||
|
||||
protected:
|
||||
UDPSocketChildBase();
|
||||
virtual ~UDPSocketChildBase();
|
||||
nsCOMPtr<nsIUDPSocketInternal> mSocket;
|
||||
bool mIPCOpen;
|
||||
};
|
||||
|
||||
class UDPSocketChild : public mozilla::net::PUDPSocketChild
|
||||
, public UDPSocketChildBase
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIUDPSOCKETCHILD
|
||||
NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE;
|
||||
|
||||
UDPSocketChild();
|
||||
virtual ~UDPSocketChild();
|
||||
|
||||
virtual bool RecvCallback(const nsCString& aType,
|
||||
const UDPCallbackData& aData,
|
||||
const nsCString& aState) MOZ_OVERRIDE;
|
||||
private:
|
||||
uint16_t mLocalPort;
|
||||
nsCString mLocalAddress;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // !defined(mozilla_dom_UDPSocketChild_h__)
|
|
@ -0,0 +1,239 @@
|
|||
/* 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/. */
|
||||
|
||||
#include "UDPSocketParent.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIUDPSocket.h"
|
||||
#include "nsINetAddr.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
static void
|
||||
FireInternalError(mozilla::net::PUDPSocketParent *aActor, uint32_t aLineNo)
|
||||
{
|
||||
mozilla::unused <<
|
||||
aActor->SendCallback(NS_LITERAL_CSTRING("onerror"),
|
||||
UDPError(NS_LITERAL_CSTRING("Internal error"),
|
||||
NS_LITERAL_CSTRING(__FILE__), aLineNo, 0),
|
||||
NS_LITERAL_CSTRING("connecting"));
|
||||
}
|
||||
|
||||
static nsresult
|
||||
ConvertNetAddrToString(mozilla::net::NetAddr &netAddr, nsACString *address, uint16_t *port)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(address);
|
||||
NS_ENSURE_ARG_POINTER(port);
|
||||
|
||||
*port = 0;
|
||||
uint32_t bufSize = 0;
|
||||
|
||||
switch(netAddr.raw.family) {
|
||||
case AF_INET:
|
||||
*port = PR_ntohs(netAddr.inet.port);
|
||||
bufSize = mozilla::net::kIPv4CStrBufSize;
|
||||
break;
|
||||
case AF_INET6:
|
||||
*port = PR_ntohs(netAddr.inet6.port);
|
||||
bufSize = mozilla::net::kIPv6CStrBufSize;
|
||||
break;
|
||||
default:
|
||||
//impossible
|
||||
MOZ_ASSERT("Unexpected address family");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
address->SetCapacity(bufSize);
|
||||
NetAddrToString(&netAddr, address->BeginWriting(), bufSize);
|
||||
address->SetLength(strlen(address->BeginReading()));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(UDPSocketParent, nsIUDPSocketListener)
|
||||
|
||||
UDPSocketParent::~UDPSocketParent()
|
||||
{
|
||||
}
|
||||
|
||||
// PUDPSocketParent methods
|
||||
|
||||
bool
|
||||
UDPSocketParent::Init(const nsCString &aHost, const uint16_t aPort)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIUDPSocket> sock =
|
||||
do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
FireInternalError(this, __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aHost.IsEmpty()) {
|
||||
rv = sock->Init(aPort, false);
|
||||
} else {
|
||||
PRNetAddr prAddr;
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, aPort, &prAddr);
|
||||
PRStatus status = PR_StringToNetAddr(aHost.BeginReading(), &prAddr);
|
||||
if (status != PR_SUCCESS) {
|
||||
FireInternalError(this, __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
mozilla::net::NetAddr addr;
|
||||
PRNetAddrToNetAddr(&prAddr, &addr);
|
||||
rv = sock->InitWithAddress(&addr);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
FireInternalError(this, __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
mSocket = sock;
|
||||
|
||||
net::NetAddr localAddr;
|
||||
mSocket->GetAddress(&localAddr);
|
||||
|
||||
uint16_t port;
|
||||
nsCString addr;
|
||||
rv = ConvertNetAddrToString(localAddr, &addr, &port);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
FireInternalError(this, __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
// register listener
|
||||
mSocket->AsyncListen(this);
|
||||
mozilla::unused <<
|
||||
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onopen"),
|
||||
UDPAddressInfo(addr, port),
|
||||
NS_LITERAL_CSTRING("connected"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
UDPSocketParent::RecvData(const InfallibleTArray<uint8_t> &aData,
|
||||
const nsCString& aRemoteAddress,
|
||||
const uint16_t& aPort)
|
||||
{
|
||||
NS_ENSURE_TRUE(mSocket, true);
|
||||
uint32_t count;
|
||||
nsresult rv = mSocket->Send(aRemoteAddress,
|
||||
aPort, aData.Elements(),
|
||||
aData.Length(), &count);
|
||||
mozilla::unused <<
|
||||
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onsent"),
|
||||
UDPSendResult(rv),
|
||||
NS_LITERAL_CSTRING("connected"));
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
NS_ENSURE_TRUE(count > 0, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
UDPSocketParent::RecvDataWithAddress(const InfallibleTArray<uint8_t>& aData,
|
||||
const mozilla::net::NetAddr& aAddr)
|
||||
{
|
||||
NS_ENSURE_TRUE(mSocket, true);
|
||||
uint32_t count;
|
||||
nsresult rv = mSocket->SendWithAddress(&aAddr, aData.Elements(),
|
||||
aData.Length(), &count);
|
||||
mozilla::unused <<
|
||||
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onsent"),
|
||||
UDPSendResult(rv),
|
||||
NS_LITERAL_CSTRING("connected"));
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
NS_ENSURE_TRUE(count > 0, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
UDPSocketParent::RecvClose()
|
||||
{
|
||||
NS_ENSURE_TRUE(mSocket, true);
|
||||
nsresult rv = mSocket->Close();
|
||||
mSocket = nullptr;
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
UDPSocketParent::RecvRequestDelete()
|
||||
{
|
||||
mozilla::unused << Send__delete__(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
UDPSocketParent::ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
MOZ_ASSERT(mIPCOpen);
|
||||
mIPCOpen = false;
|
||||
if (mSocket) {
|
||||
mSocket->Close();
|
||||
}
|
||||
mSocket = nullptr;
|
||||
}
|
||||
|
||||
// nsIUDPSocketListener
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketParent::OnPacketReceived(nsIUDPSocket* aSocket, nsIUDPMessage* aMessage)
|
||||
{
|
||||
// receiving packet from remote host, forward the message content to child process
|
||||
if (!mIPCOpen) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint16_t port;
|
||||
nsCString ip;
|
||||
nsCOMPtr<nsINetAddr> fromAddr;
|
||||
aMessage->GetFromAddr(getter_AddRefs(fromAddr));
|
||||
fromAddr->GetPort(&port);
|
||||
fromAddr->GetAddress(ip);
|
||||
|
||||
nsCString data;
|
||||
aMessage->GetData(data);
|
||||
|
||||
const char* buffer = data.get();
|
||||
uint32_t len = data.Length();
|
||||
|
||||
FallibleTArray<uint8_t> fallibleArray;
|
||||
if (!fallibleArray.InsertElementsAt(0, buffer, len)) {
|
||||
FireInternalError(this, __LINE__);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
InfallibleTArray<uint8_t> infallibleArray;
|
||||
infallibleArray.SwapElements(fallibleArray);
|
||||
|
||||
// compose callback
|
||||
mozilla::unused <<
|
||||
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("ondata"),
|
||||
UDPMessage(ip, port, infallibleArray),
|
||||
NS_LITERAL_CSTRING("connected"));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketParent::OnStopListening(nsIUDPSocket* aSocket, nsresult aStatus)
|
||||
{
|
||||
// underlying socket is dead, send state update to child process
|
||||
if (mIPCOpen) {
|
||||
mozilla::unused <<
|
||||
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onclose"),
|
||||
mozilla::void_t(),
|
||||
NS_LITERAL_CSTRING("closed"));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,45 @@
|
|||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_UDPSocketParent_h__
|
||||
#define mozilla_dom_UDPSocketParent_h__
|
||||
|
||||
#include "mozilla/net/PUDPSocketParent.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIUDPSocket.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class UDPSocketParent : public mozilla::net::PUDPSocketParent
|
||||
, public nsIUDPSocketListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSOCKETLISTENER
|
||||
|
||||
UDPSocketParent() : mIPCOpen(true) {}
|
||||
virtual ~UDPSocketParent();
|
||||
|
||||
bool Init(const nsCString& aHost, const uint16_t aPort);
|
||||
|
||||
virtual bool RecvClose() MOZ_OVERRIDE;
|
||||
virtual bool RecvData(const InfallibleTArray<uint8_t>& aData,
|
||||
const nsCString& aRemoteAddress,
|
||||
const uint16_t& aPort) MOZ_OVERRIDE;
|
||||
virtual bool RecvDataWithAddress( const InfallibleTArray<uint8_t>& data,
|
||||
const mozilla::net::NetAddr& addr);
|
||||
virtual bool RecvRequestDelete() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
|
||||
|
||||
bool mIPCOpen;
|
||||
nsCOMPtr<nsIUDPSocket> mSocket;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // !defined(mozilla_dom_UDPSocketParent_h__)
|
|
@ -11,6 +11,8 @@ EXPORTS.mozilla.dom.network += [
|
|||
'TCPSocketChild.h',
|
||||
'TCPSocketParent.h',
|
||||
'Types.h',
|
||||
'UDPSocketChild.h',
|
||||
'UDPSocketParent.h',
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
|
@ -19,6 +21,8 @@ SOURCES += [
|
|||
'TCPServerSocketParent.cpp',
|
||||
'TCPSocketChild.cpp',
|
||||
'TCPSocketParent.cpp',
|
||||
'UDPSocketChild.cpp',
|
||||
'UDPSocketParent.cpp',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_RIL']:
|
||||
|
@ -56,6 +60,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
|||
IPDL_SOURCES += [
|
||||
'PTCPServerSocket.ipdl',
|
||||
'PTCPSocket.ipdl',
|
||||
'PUDPSocket.ipdl',
|
||||
]
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref('media.peerconnection.ipc.enabled', true);
|
||||
run_test_in_child("/udpsocket_child.js", function() {
|
||||
Services.prefs.clearUserPref('media.peerconnection.ipc.enabled');
|
||||
do_test_finished();
|
||||
});
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
/* -*- Mode: Java; 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/. */
|
||||
'use strict';
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
|
||||
const SERVER_PORT = 12345;
|
||||
const DATA_ARRAY = [0, 255, 254, 0, 1, 2, 3, 0, 255, 255, 254, 0];
|
||||
|
||||
function UDPSocketInternalImpl() {
|
||||
}
|
||||
|
||||
UDPSocketInternalImpl.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUDPSocketInternal]),
|
||||
callListenerError: function(type, message, filename, lineNumber, columnNumber) {
|
||||
if (this.onerror) {
|
||||
this.onerror();
|
||||
} else {
|
||||
do_throw('Received unexpected error: ' + message + ' at ' + filename +
|
||||
':' + lineNumber + ':' + columnNumber);
|
||||
}
|
||||
},
|
||||
callListenerReceivedData: function(type, host, port, data, dataLength) {
|
||||
do_print('*** recv data(' + dataLength + ')=' + data.join() + '\n');
|
||||
if (this.ondata) {
|
||||
try {
|
||||
this.ondata(data, dataLength);
|
||||
} catch(ex) {
|
||||
if (ex === Cr.NS_ERROR_ABORT)
|
||||
throw ex;
|
||||
do_print('Caught exception: ' + ex + '\n' + ex.stack);
|
||||
do_throw('test is broken; bad ondata handler; see above');
|
||||
}
|
||||
} else {
|
||||
do_throw('Received ' + dataLength + ' bytes of unexpected data!');
|
||||
}
|
||||
},
|
||||
callListenerVoid: function(type) {
|
||||
switch (type) {
|
||||
case 'onopen':
|
||||
if (this.onopen) {
|
||||
this.onopen();
|
||||
}
|
||||
break;
|
||||
case 'onclose':
|
||||
if (this.onclose) {
|
||||
this.onclose();
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
callListenerSent: function(type, value) {
|
||||
if (value != Cr.NS_OK) {
|
||||
do_throw('Previous send was failed with cause: ' + value);
|
||||
}
|
||||
},
|
||||
updateReadyState: function(readyState) {
|
||||
do_print('*** current state: ' + readyState + '\n');
|
||||
},
|
||||
onopen: function() {},
|
||||
onclose: function() {},
|
||||
};
|
||||
|
||||
function makeSuccessCase(name) {
|
||||
return function() {
|
||||
do_print('got expected: ' + name);
|
||||
run_next_test();
|
||||
};
|
||||
}
|
||||
|
||||
function makeJointSuccess(names) {
|
||||
let funcs = {}, successCount = 0;
|
||||
names.forEach(function(name) {
|
||||
funcs[name] = function() {
|
||||
do_print('got excepted: ' + name);
|
||||
if (++successCount === names.length)
|
||||
run_next_test();
|
||||
};
|
||||
});
|
||||
return funcs;
|
||||
}
|
||||
|
||||
function makeExpectedData(expectedData, callback) {
|
||||
return function(receivedData, receivedDataLength) {
|
||||
if (receivedDataLength != expectedData.length) {
|
||||
do_throw('Received data size mismatched, expected ' + expectedData.length +
|
||||
' but got ' + receivedDataLength);
|
||||
}
|
||||
for (let i = 0; i < receivedDataLength; i++) {
|
||||
if (receivedData[i] != expectedData[i]) {
|
||||
do_throw('Received mismatched data at position ' + i);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback();
|
||||
} else {
|
||||
run_next_test();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function makeFailureCase(name) {
|
||||
return function() {
|
||||
let argstr;
|
||||
if (arguments.length) {
|
||||
argstr = '(args: ' +
|
||||
Array.map(arguments, function(x) {return x.data + ""; }).join(" ") + ')';
|
||||
} else {
|
||||
argstr = '(no arguments)';
|
||||
}
|
||||
do_throw('got unexpected: ' + name + ' ' + argstr);
|
||||
};
|
||||
}
|
||||
|
||||
function createSocketChild() {
|
||||
return Cc['@mozilla.org/udp-socket-child;1']
|
||||
.createInstance(Ci.nsIUDPSocketChild);
|
||||
}
|
||||
|
||||
var UDPSocket = createSocketChild();
|
||||
var callback = new UDPSocketInternalImpl();
|
||||
|
||||
function connectSock() {
|
||||
UDPSocket.bind(callback, '127.0.0.1', SERVER_PORT);
|
||||
callback.onopen = makeSuccessCase('open');
|
||||
}
|
||||
|
||||
function sendData() {
|
||||
UDPSocket.send('127.0.0.1', SERVER_PORT, DATA_ARRAY, DATA_ARRAY.length);
|
||||
callback.ondata = makeExpectedData(DATA_ARRAY);
|
||||
}
|
||||
|
||||
function clientClose() {
|
||||
UDPSocket.close();
|
||||
callback.ondata = makeFailureCase('data');
|
||||
callback.onclose = makeSuccessCase('close');
|
||||
}
|
||||
|
||||
function connectError() {
|
||||
UDPSocket = createSocketChild();
|
||||
UDPSocket.bind(callback, 'some non-IP string', SERVER_PORT);
|
||||
callback.onerror = makeSuccessCase('error');
|
||||
callback.onopen = makeFailureCase('open');
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
UDPSocket = null;
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_test(connectSock);
|
||||
add_test(sendData);
|
||||
add_test(clientClose);
|
||||
add_test(connectError);
|
||||
add_test(cleanup);
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
[DEFAULT]
|
||||
head =
|
||||
tail =
|
||||
support-files =
|
||||
udpsocket_child.js
|
||||
|
||||
[test_tcpsocket_ipc.js]
|
||||
[test_tcpserversocket_ipc.js]
|
||||
[test_udpsocket_ipc.js]
|
||||
run-sequentially = Uses hardcoded port, bug 903830.
|
||||
|
|
|
@ -1434,7 +1434,7 @@ this.PushService = {
|
|||
return;
|
||||
}
|
||||
|
||||
this._udpServer = Cc["@mozilla.org/network/server-socket-udp;1"]
|
||||
this._udpServer = Cc["@mozilla.org/network/socket-udp;1"]
|
||||
.createInstance(Ci.nsIUDPServerSocket);
|
||||
this._udpServer.init(-1, false);
|
||||
this._udpServer.asyncListen(this);
|
||||
|
|
|
@ -479,12 +479,6 @@ AudioManager::SetPhoneState(int32_t aState)
|
|||
obs->NotifyObservers(nullptr, "phone-state-changed", state.get());
|
||||
}
|
||||
|
||||
// follow the switch audio path logic for android, Bug 897364
|
||||
int usage;
|
||||
GetForceForUse(nsIAudioManager::USE_COMMUNICATION, &usage);
|
||||
if (aState == PHONE_STATE_NORMAL && usage == nsIAudioManager::FORCE_BT_SCO) {
|
||||
SetForceForUse(nsIAudioManager::USE_COMMUNICATION, nsIAudioManager::FORCE_NONE);
|
||||
}
|
||||
#if ANDROID_VERSION < 17
|
||||
if (AudioSystem::setPhoneState(aState)) {
|
||||
#else
|
||||
|
|
|
@ -2389,6 +2389,7 @@ this.GECKO_CARDSTATE_CORPORATE_PUK_REQUIRED = "corporatePukRequired";
|
|||
this.GECKO_CARDSTATE_SERVICE_PROVIDER_PUK_REQUIRED = "serviceProviderPukRequired";
|
||||
this.GECKO_CARDSTATE_SIM_PUK_REQUIRED = "simPersonalizationPukRequired";
|
||||
this.GECKO_CARDSTATE_READY = "ready";
|
||||
this.GECKO_CARDSTATE_PERMANENT_BLOCKED = "permanentBlocked";
|
||||
|
||||
this.GECKO_CARDLOCK_PIN = "pin";
|
||||
this.GECKO_CARDLOCK_PIN2 = "pin2";
|
||||
|
|
|
@ -3013,6 +3013,12 @@ let RIL = {
|
|||
newCardState = GECKO_CARDSTATE_UNKNOWN;
|
||||
}
|
||||
|
||||
let pin1State = app.pin1_replaced ? iccStatus.universalPINState :
|
||||
app.pin1;
|
||||
if (pin1State === CARD_PINSTATE_ENABLED_PERM_BLOCKED) {
|
||||
newCardState = GECKO_CARDSTATE_PERMANENT_BLOCKED;
|
||||
}
|
||||
|
||||
if (this.cardState == newCardState) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1701,6 +1701,41 @@ add_test(function test_card_app_state() {
|
|||
run_next_test();
|
||||
});
|
||||
|
||||
/**
|
||||
* Verify permanent blocked for ICC.
|
||||
*/
|
||||
add_test(function test_icc_permanent_blocked() {
|
||||
let worker = newUint8Worker();
|
||||
let ril = worker.RIL;
|
||||
|
||||
function testPermanentBlocked(pin1_replaced, universalPINState, pin1) {
|
||||
let iccStatus = {
|
||||
gsmUmtsSubscriptionAppIndex: 0,
|
||||
universalPINState: universalPINState,
|
||||
apps: [
|
||||
{
|
||||
pin1_replaced: pin1_replaced,
|
||||
pin1: pin1
|
||||
}]
|
||||
};
|
||||
|
||||
ril._processICCStatus(iccStatus);
|
||||
do_check_eq(ril.cardState, GECKO_CARDSTATE_PERMANENT_BLOCKED);
|
||||
}
|
||||
|
||||
testPermanentBlocked(1,
|
||||
CARD_PINSTATE_ENABLED_PERM_BLOCKED,
|
||||
CARD_PINSTATE_UNKNOWN);
|
||||
testPermanentBlocked(1,
|
||||
CARD_PINSTATE_ENABLED_PERM_BLOCKED,
|
||||
CARD_PINSTATE_ENABLED_PERM_BLOCKED);
|
||||
testPermanentBlocked(0,
|
||||
CARD_PINSTATE_UNKNOWN,
|
||||
CARD_PINSTATE_ENABLED_PERM_BLOCKED);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
/**
|
||||
* Verify iccSetCardLock - Facility Lock.
|
||||
*/
|
||||
|
|
|
@ -7,21 +7,21 @@
|
|||
[ChromeOnly, Constructor, JSImplementation="@mozilla.org/contactAddress;1"]
|
||||
interface ContactAddress {
|
||||
attribute object? type; // DOMString[]
|
||||
[TreatUndefinedAs=Null] attribute DOMString? streetAddress;
|
||||
[TreatUndefinedAs=Null] attribute DOMString? locality;
|
||||
[TreatUndefinedAs=Null] attribute DOMString? region;
|
||||
[TreatUndefinedAs=Null] attribute DOMString? postalCode;
|
||||
[TreatUndefinedAs=Null] attribute DOMString? countryName;
|
||||
attribute DOMString? streetAddress;
|
||||
attribute DOMString? locality;
|
||||
attribute DOMString? region;
|
||||
attribute DOMString? postalCode;
|
||||
attribute DOMString? countryName;
|
||||
attribute boolean? pref;
|
||||
|
||||
[ChromeOnly]
|
||||
void initialize(optional sequence<DOMString>? type,
|
||||
optional DOMString streetAddress,
|
||||
optional DOMString locality,
|
||||
optional DOMString region,
|
||||
optional DOMString postalCode,
|
||||
optional DOMString countryName,
|
||||
optional boolean pref);
|
||||
optional DOMString? streetAddress,
|
||||
optional DOMString? locality,
|
||||
optional DOMString? region,
|
||||
optional DOMString? postalCode,
|
||||
optional DOMString? countryName,
|
||||
optional boolean? pref);
|
||||
|
||||
object toJSON();
|
||||
};
|
||||
|
@ -40,13 +40,13 @@ dictionary ContactAddressInit {
|
|||
[ChromeOnly, Constructor, JSImplementation="@mozilla.org/contactField;1"]
|
||||
interface ContactField {
|
||||
attribute object? type; // DOMString[]
|
||||
[TreatUndefinedAs=Null] attribute DOMString? value;
|
||||
attribute DOMString? value;
|
||||
attribute boolean? pref;
|
||||
|
||||
[ChromeOnly]
|
||||
void initialize(optional sequence<DOMString>? type,
|
||||
optional DOMString value,
|
||||
optional boolean pref);
|
||||
optional DOMString? value,
|
||||
optional boolean? pref);
|
||||
|
||||
object toJSON();
|
||||
};
|
||||
|
@ -60,13 +60,13 @@ dictionary ContactFieldInit {
|
|||
|
||||
[ChromeOnly, Constructor, JSImplementation="@mozilla.org/contactTelField;1"]
|
||||
interface ContactTelField : ContactField {
|
||||
[TreatUndefinedAs=Null] attribute DOMString? carrier;
|
||||
attribute DOMString? carrier;
|
||||
|
||||
[ChromeOnly]
|
||||
void initialize(optional sequence<DOMString>? type,
|
||||
optional DOMString value,
|
||||
optional DOMString? value,
|
||||
optional DOMString? carrier,
|
||||
optional boolean pref);
|
||||
optional boolean? pref);
|
||||
|
||||
object toJSON();
|
||||
};
|
||||
|
@ -117,8 +117,8 @@ interface mozContact {
|
|||
attribute Date? bday;
|
||||
attribute Date? anniversary;
|
||||
|
||||
[TreatUndefinedAs=Null] attribute DOMString? sex;
|
||||
[TreatUndefinedAs=Null] attribute DOMString? genderIdentity;
|
||||
attribute DOMString? sex;
|
||||
attribute DOMString? genderIdentity;
|
||||
|
||||
attribute object? photo;
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@
|
|||
#include "mozilla/dom/network/TCPSocketChild.h"
|
||||
#include "mozilla/dom/network/TCPSocketParent.h"
|
||||
#include "mozilla/dom/network/TCPServerSocketChild.h"
|
||||
#include "mozilla/dom/network/UDPSocketChild.h"
|
||||
#include "mozilla/dom/quota/QuotaManager.h"
|
||||
#include "mozilla/OSFileConstants.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
@ -251,6 +252,7 @@ using mozilla::dom::quota::QuotaManager;
|
|||
using mozilla::dom::TCPSocketChild;
|
||||
using mozilla::dom::TCPSocketParent;
|
||||
using mozilla::dom::TCPServerSocketChild;
|
||||
using mozilla::dom::UDPSocketChild;
|
||||
using mozilla::dom::time::TimeService;
|
||||
using mozilla::net::StreamingProtocolControllerService;
|
||||
|
||||
|
@ -646,6 +648,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(OSFileConstantsService)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(TCPSocketChild)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(TCPSocketParent)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(TCPServerSocketChild)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(UDPSocketChild)
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
#include "nsAccessibilityService.h"
|
||||
|
@ -808,6 +811,7 @@ NS_DEFINE_NAMED_CID(NS_ALARMHALSERVICE_CID);
|
|||
NS_DEFINE_NAMED_CID(TCPSOCKETCHILD_CID);
|
||||
NS_DEFINE_NAMED_CID(TCPSOCKETPARENT_CID);
|
||||
NS_DEFINE_NAMED_CID(TCPSERVERSOCKETCHILD_CID);
|
||||
NS_DEFINE_NAMED_CID(UDPSOCKETCHILD_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_TIMESERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_MEDIASTREAMCONTROLLERSERVICE_CID);
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
|
@ -1098,6 +1102,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
|
|||
{ &kTCPSOCKETCHILD_CID, false, nullptr, TCPSocketChildConstructor },
|
||||
{ &kTCPSOCKETPARENT_CID, false, nullptr, TCPSocketParentConstructor },
|
||||
{ &kTCPSERVERSOCKETCHILD_CID, false, nullptr, TCPServerSocketChildConstructor },
|
||||
{ &kUDPSOCKETCHILD_CID, false, nullptr, UDPSocketChildConstructor },
|
||||
{ &kNS_TIMESERVICE_CID, false, nullptr, nsITimeServiceConstructor },
|
||||
{ &kNS_MEDIASTREAMCONTROLLERSERVICE_CID, false, nullptr, nsIStreamingProtocolControllerServiceConstructor },
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
|
@ -1255,6 +1260,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
|||
{ "@mozilla.org/tcp-socket-child;1", &kTCPSOCKETCHILD_CID },
|
||||
{ "@mozilla.org/tcp-socket-parent;1", &kTCPSOCKETPARENT_CID },
|
||||
{ "@mozilla.org/tcp-server-socket-child;1", &kTCPSERVERSOCKETCHILD_CID },
|
||||
{ "@mozilla.org/udp-socket-child;1", &kUDPSOCKETCHILD_CID },
|
||||
{ TIMESERVICE_CONTRACTID, &kNS_TIMESERVICE_CID },
|
||||
{ MEDIASTREAMCONTROLLERSERVICE_CONTRACTID, &kNS_MEDIASTREAMCONTROLLERSERVICE_CID },
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
|
|
|
@ -102,7 +102,9 @@ nrappkit copyright:
|
|||
#include "nsNetCID.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "runnable_utils.h"
|
||||
|
||||
extern "C" {
|
||||
|
@ -116,6 +118,63 @@ extern "C" {
|
|||
// Implement the nsISupports ref counting
|
||||
namespace mozilla {
|
||||
|
||||
// NrSocketBase implementation
|
||||
// async_event APIs
|
||||
int NrSocketBase::async_wait(int how, NR_async_cb cb, void *cb_arg,
|
||||
char *function, int line) {
|
||||
uint16_t flag;
|
||||
|
||||
switch (how) {
|
||||
case NR_ASYNC_WAIT_READ:
|
||||
flag = PR_POLL_READ;
|
||||
break;
|
||||
case NR_ASYNC_WAIT_WRITE:
|
||||
flag = PR_POLL_WRITE;
|
||||
break;
|
||||
default:
|
||||
return R_BAD_ARGS;
|
||||
}
|
||||
|
||||
cbs_[how] = cb;
|
||||
cb_args_[how] = cb_arg;
|
||||
poll_flags_ |= flag;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NrSocketBase::cancel(int how) {
|
||||
uint16_t flag;
|
||||
|
||||
switch (how) {
|
||||
case NR_ASYNC_WAIT_READ:
|
||||
flag = PR_POLL_READ;
|
||||
break;
|
||||
case NR_ASYNC_WAIT_WRITE:
|
||||
flag = PR_POLL_WRITE;
|
||||
break;
|
||||
default:
|
||||
return R_BAD_ARGS;
|
||||
}
|
||||
|
||||
poll_flags_ &= ~flag;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NrSocketBase::fire_callback(int how) {
|
||||
// This can't happen unless we are armed because we only set
|
||||
// the flags if we are armed
|
||||
MOZ_ASSERT(cbs_[how]);
|
||||
|
||||
// Now cancel so that we need to be re-armed. Note that
|
||||
// the re-arming probably happens in the callback we are
|
||||
// about to fire.
|
||||
cancel(how);
|
||||
|
||||
cbs_[how](this, how, cb_args_[how]);
|
||||
}
|
||||
|
||||
// NrSocket implementation
|
||||
NS_IMPL_ISUPPORTS0(NrSocket)
|
||||
|
||||
|
||||
|
@ -139,56 +198,23 @@ void NrSocket::IsLocal(bool *aIsLocal) {
|
|||
// async_event APIs
|
||||
int NrSocket::async_wait(int how, NR_async_cb cb, void *cb_arg,
|
||||
char *function, int line) {
|
||||
uint16_t flag;
|
||||
int r = NrSocketBase::async_wait(how, cb, cb_arg, function, line);
|
||||
|
||||
switch (how) {
|
||||
case NR_ASYNC_WAIT_READ:
|
||||
flag = PR_POLL_READ;
|
||||
break;
|
||||
case NR_ASYNC_WAIT_WRITE:
|
||||
flag = PR_POLL_WRITE;
|
||||
break;
|
||||
default:
|
||||
return R_BAD_ARGS;
|
||||
if (!r) {
|
||||
mPollFlags = poll_flags();
|
||||
}
|
||||
|
||||
cbs_[how] = cb;
|
||||
cb_args_[how] = cb_arg;
|
||||
mPollFlags |= flag;
|
||||
|
||||
return 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int NrSocket::cancel(int how) {
|
||||
uint16_t flag;
|
||||
int r = NrSocketBase::cancel(how);
|
||||
|
||||
switch (how) {
|
||||
case NR_ASYNC_WAIT_READ:
|
||||
flag = PR_POLL_READ;
|
||||
break;
|
||||
case NR_ASYNC_WAIT_WRITE:
|
||||
flag = PR_POLL_WRITE;
|
||||
break;
|
||||
default:
|
||||
return R_BAD_ARGS;
|
||||
if (!r) {
|
||||
mPollFlags = poll_flags();
|
||||
}
|
||||
|
||||
mPollFlags &= ~flag;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NrSocket::fire_callback(int how) {
|
||||
// This can't happen unless we are armed because we only set
|
||||
// the flags if we are armed
|
||||
MOZ_ASSERT(cbs_[how]);
|
||||
|
||||
// Now cancel so that we need to be re-armed. Note that
|
||||
// the re-arming probably happens in the callback we are
|
||||
// about to fire.
|
||||
cancel(how);
|
||||
|
||||
cbs_[how](this, how, cb_args_[how]);
|
||||
return r;
|
||||
}
|
||||
|
||||
// Helper functions for addresses
|
||||
|
@ -240,6 +266,54 @@ static int nr_transport_addr_to_praddr(nr_transport_addr *addr,
|
|||
return(_status);
|
||||
}
|
||||
|
||||
//XXX schien@mozilla.com: copy from PRNetAddrToNetAddr,
|
||||
// should be removed after fix the link error in signaling_unittests
|
||||
static int praddr_to_netaddr(const PRNetAddr *prAddr, net::NetAddr *addr)
|
||||
{
|
||||
int _status;
|
||||
|
||||
switch (prAddr->raw.family) {
|
||||
case PR_AF_INET:
|
||||
addr->inet.family = AF_INET;
|
||||
addr->inet.port = prAddr->inet.port;
|
||||
addr->inet.ip = prAddr->inet.ip;
|
||||
break;
|
||||
case PR_AF_INET6:
|
||||
addr->inet6.family = AF_INET6;
|
||||
addr->inet6.port = prAddr->ipv6.port;
|
||||
addr->inet6.flowinfo = prAddr->ipv6.flowinfo;
|
||||
memcpy(&addr->inet6.ip, &prAddr->ipv6.ip, sizeof(addr->inet6.ip.u8));
|
||||
addr->inet6.scope_id = prAddr->ipv6.scope_id;
|
||||
break;
|
||||
default:
|
||||
MOZ_ASSERT(false);
|
||||
ABORT(R_BAD_ARGS);
|
||||
}
|
||||
|
||||
_status = 0;
|
||||
abort:
|
||||
return(_status);
|
||||
}
|
||||
|
||||
static int nr_transport_addr_to_netaddr(nr_transport_addr *addr,
|
||||
net::NetAddr *naddr)
|
||||
{
|
||||
int r, _status;
|
||||
PRNetAddr praddr;
|
||||
|
||||
if((r = nr_transport_addr_to_praddr(addr, &praddr))) {
|
||||
ABORT(r);
|
||||
}
|
||||
|
||||
if((r = praddr_to_netaddr(&praddr, naddr))) {
|
||||
ABORT(r);
|
||||
}
|
||||
|
||||
_status = 0;
|
||||
abort:
|
||||
return(_status);
|
||||
}
|
||||
|
||||
int nr_netaddr_to_transport_addr(const net::NetAddr *netaddr,
|
||||
nr_transport_addr *addr)
|
||||
{
|
||||
|
@ -299,6 +373,32 @@ int nr_praddr_to_transport_addr(const PRNetAddr *praddr,
|
|||
return(_status);
|
||||
}
|
||||
|
||||
/*
|
||||
* nr_transport_addr_get_addrstring_and_port
|
||||
* convert nr_transport_addr to IP address string and port number
|
||||
*/
|
||||
int nr_transport_addr_get_addrstring_and_port(nr_transport_addr *addr,
|
||||
nsACString *host, int32_t *port) {
|
||||
int r, _status;
|
||||
char addr_string[64];
|
||||
|
||||
// We cannot directly use |nr_transport_addr.as_string| because it contains
|
||||
// more than ip address, therefore, we need to explicity convert it
|
||||
// from |nr_transport_addr_get_addrstring|.
|
||||
if ((r=nr_transport_addr_get_addrstring(addr, addr_string, sizeof(addr_string)))) {
|
||||
ABORT(r);
|
||||
}
|
||||
|
||||
if ((r=nr_transport_addr_get_port(addr, port))) {
|
||||
ABORT(r);
|
||||
}
|
||||
|
||||
*host = addr_string;
|
||||
|
||||
_status=0;
|
||||
abort:
|
||||
return(_status);
|
||||
}
|
||||
|
||||
// nr_socket APIs (as member functions)
|
||||
int NrSocket::create(nr_transport_addr *addr) {
|
||||
|
@ -394,7 +494,7 @@ int NrSocket::sendto(const void *msg, size_t len,
|
|||
if (PR_GetError() == PR_WOULD_BLOCK_ERROR)
|
||||
ABORT(R_WOULDBLOCK);
|
||||
|
||||
r_log_e(LOG_GENERIC, LOG_INFO, "Error in sendto %s", to->as_string);
|
||||
r_log(LOG_GENERIC, LOG_INFO, "Error in sendto %s", to->as_string);
|
||||
ABORT(R_IO_ERROR);
|
||||
}
|
||||
|
||||
|
@ -413,7 +513,7 @@ int NrSocket::recvfrom(void * buf, size_t maxlen,
|
|||
|
||||
status = PR_RecvFrom(fd_, buf, maxlen, flags, &nfrom, PR_INTERVAL_NO_WAIT);
|
||||
if (status <= 0) {
|
||||
r_log_e(LOG_GENERIC,LOG_ERR,"Error in recvfrom");
|
||||
r_log(LOG_GENERIC,LOG_ERR,"Error in recvfrom");
|
||||
ABORT(R_IO_ERROR);
|
||||
}
|
||||
*len=status;
|
||||
|
@ -438,6 +538,383 @@ void NrSocket::close() {
|
|||
ASSERT_ON_THREAD(ststhread_);
|
||||
mCondition = NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
// NrSocketIpc Implementation
|
||||
NS_IMPL_ISUPPORTS1(NrSocketIpc, nsIUDPSocketInternal)
|
||||
|
||||
NrSocketIpc::NrSocketIpc(const nsCOMPtr<nsIEventTarget> &main_thread)
|
||||
: err_(false),
|
||||
state_(NR_INIT),
|
||||
main_thread_(main_thread),
|
||||
monitor_("NrSocketIpc") {
|
||||
}
|
||||
|
||||
// IUDPSocketInternal interfaces
|
||||
// callback while error happened in UDP socket operation
|
||||
NS_IMETHODIMP NrSocketIpc::CallListenerError(const nsACString &type,
|
||||
const nsACString &message,
|
||||
const nsACString &filename,
|
||||
uint32_t line_number,
|
||||
uint32_t column_number) {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
MOZ_ASSERT(type.EqualsLiteral("onerror"));
|
||||
|
||||
r_log(LOG_GENERIC, LOG_ERR, "UDP socket error:%s at %s:%d:%d",
|
||||
message.BeginReading(), filename.BeginReading(),
|
||||
line_number, column_number);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
err_ = true;
|
||||
monitor_.NotifyAll();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// callback while receiving UDP packet
|
||||
NS_IMETHODIMP NrSocketIpc::CallListenerReceivedData(const nsACString &type,
|
||||
const nsACString &host,
|
||||
uint16_t port, uint8_t *data,
|
||||
uint32_t data_length) {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
MOZ_ASSERT(type.EqualsLiteral("ondata"));
|
||||
|
||||
PRNetAddr addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
if (PR_SUCCESS != PR_StringToNetAddr(host.BeginReading(), &addr)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to convert remote host to PRNetAddr");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Use PR_IpAddrNull to avoid address being reset to 0.
|
||||
if (PR_SUCCESS != PR_SetNetAddr(PR_IpAddrNull, addr.raw.family, port, &addr)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to set port in PRNetAddr");
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsAutoPtr<DataBuffer> buf(new DataBuffer(data, data_length));
|
||||
RefPtr<nr_udp_message> msg(new nr_udp_message(addr, buf));
|
||||
|
||||
RUN_ON_THREAD(sts_thread_,
|
||||
mozilla::WrapRunnable(nsRefPtr<NrSocketIpc>(this),
|
||||
&NrSocketIpc::recv_callback_s,
|
||||
msg),
|
||||
NS_DISPATCH_NORMAL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// callback while UDP socket is opened or closed
|
||||
NS_IMETHODIMP NrSocketIpc::CallListenerVoid(const nsACString &type) {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
if (type.EqualsLiteral("onopen")) {
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
uint16_t port;
|
||||
if (NS_FAILED(socket_child_->GetLocalPort(&port))) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to get local port");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoCString address;
|
||||
if(NS_FAILED(socket_child_->GetLocalAddress(address))) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to get local address");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRNetAddr praddr;
|
||||
if (PR_SUCCESS != PR_InitializeNetAddr(PR_IpAddrAny, port, &praddr)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to set port in PRNetAddr");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (PR_SUCCESS != PR_StringToNetAddr(address.BeginReading(), &praddr)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to convert local host to PRNetAddr");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nr_transport_addr expected_addr;
|
||||
if(nr_transport_addr_copy(&expected_addr, &my_addr_)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to copy my_addr_");
|
||||
}
|
||||
|
||||
if (nr_praddr_to_transport_addr(&praddr, &my_addr_, 1)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to copy local host to my_addr_");
|
||||
}
|
||||
|
||||
if (nr_transport_addr_cmp(&expected_addr, &my_addr_,
|
||||
NR_TRANSPORT_ADDR_CMP_MODE_ADDR)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Address of opened socket is not expected");
|
||||
}
|
||||
|
||||
mon.NotifyAll();
|
||||
} else if (type.EqualsLiteral("onclose")) {
|
||||
// Already handled in UpdateReadyState, nothing to do here
|
||||
} else {
|
||||
MOZ_ASSERT(false, "Received unexpected event");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// callback while UDP packet is sent
|
||||
NS_IMETHODIMP NrSocketIpc::CallListenerSent(const nsACString &type,
|
||||
nsresult result) {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
MOZ_ASSERT(type.EqualsLiteral("onsent"));
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
err_ = true;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// callback for state update after every socket operation
|
||||
NS_IMETHODIMP NrSocketIpc::UpdateReadyState(const nsACString &readyState) {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
if (readyState.EqualsLiteral("closed")) {
|
||||
MOZ_ASSERT(state_ == NR_CONNECTED || state_ == NR_CLOSING);
|
||||
state_ = NR_CLOSED;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nr_socket public APIs
|
||||
int NrSocketIpc::create(nr_transport_addr *addr) {
|
||||
ASSERT_ON_THREAD(sts_thread_);
|
||||
|
||||
int r, _status;
|
||||
nsresult rv;
|
||||
int32_t port;
|
||||
nsCString host;
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
if (state_ != NR_INIT) {
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
|
||||
sts_thread_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
MOZ_ASSERT(false, "Failed to get STS thread");
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
|
||||
if ((r=nr_transport_addr_get_addrstring_and_port(addr, &host, &port))) {
|
||||
ABORT(r);
|
||||
}
|
||||
|
||||
// wildcard address will be resolved at NrSocketIpc::CallListenerVoid
|
||||
if ((r=nr_transport_addr_copy(&my_addr_, addr))) {
|
||||
ABORT(r);
|
||||
}
|
||||
|
||||
state_ = NR_CONNECTING;
|
||||
|
||||
RUN_ON_THREAD(main_thread_,
|
||||
mozilla::WrapRunnable(nsRefPtr<NrSocketIpc>(this),
|
||||
&NrSocketIpc::create_m,
|
||||
host, static_cast<uint16_t>(port)),
|
||||
NS_DISPATCH_NORMAL);
|
||||
|
||||
// Wait until socket creation complete.
|
||||
mon.Wait();
|
||||
|
||||
if (err_) {
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
|
||||
state_ = NR_CONNECTED;
|
||||
|
||||
_status = 0;
|
||||
abort:
|
||||
return(_status);
|
||||
}
|
||||
|
||||
int NrSocketIpc::sendto(const void *msg, size_t len, int flags,
|
||||
nr_transport_addr *to) {
|
||||
ASSERT_ON_THREAD(sts_thread_);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
//If send err happened before, simply return the error.
|
||||
if (err_) {
|
||||
return R_IO_ERROR;
|
||||
}
|
||||
|
||||
if (!socket_child_) {
|
||||
return R_EOD;
|
||||
}
|
||||
|
||||
if (state_ != NR_CONNECTED) {
|
||||
return R_INTERNAL;
|
||||
}
|
||||
|
||||
int r;
|
||||
net::NetAddr addr;
|
||||
if ((r=nr_transport_addr_to_netaddr(to, &addr))) {
|
||||
return r;
|
||||
}
|
||||
|
||||
nsAutoPtr<DataBuffer> buf(new DataBuffer(static_cast<const uint8_t*>(msg), len));
|
||||
|
||||
RUN_ON_THREAD(main_thread_,
|
||||
mozilla::WrapRunnable(nsRefPtr<NrSocketIpc>(this),
|
||||
&NrSocketIpc::sendto_m,
|
||||
addr, buf),
|
||||
NS_DISPATCH_NORMAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NrSocketIpc::close() {
|
||||
ASSERT_ON_THREAD(sts_thread_);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
state_ = NR_CLOSING;
|
||||
|
||||
RUN_ON_THREAD(main_thread_,
|
||||
mozilla::WrapRunnable(nsRefPtr<NrSocketIpc>(this),
|
||||
&NrSocketIpc::close_m),
|
||||
NS_DISPATCH_NORMAL);
|
||||
|
||||
//remove all enqueued messages
|
||||
std::queue<RefPtr<nr_udp_message> > empty;
|
||||
std::swap(received_msgs_, empty);
|
||||
}
|
||||
|
||||
int NrSocketIpc::recvfrom(void *buf, size_t maxlen, size_t *len, int flags,
|
||||
nr_transport_addr *from) {
|
||||
ASSERT_ON_THREAD(sts_thread_);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
int r, _status;
|
||||
uint32_t consumed_len;
|
||||
|
||||
*len = 0;
|
||||
|
||||
if (state_ != NR_CONNECTED) {
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
|
||||
if (received_msgs_.empty()) {
|
||||
ABORT(R_WOULDBLOCK);
|
||||
}
|
||||
|
||||
{
|
||||
RefPtr<nr_udp_message> msg(received_msgs_.front());
|
||||
|
||||
received_msgs_.pop();
|
||||
|
||||
if ((r=nr_praddr_to_transport_addr(&msg->from, from, 0))) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Get bogus address for received UDP packet");
|
||||
ABORT(r);
|
||||
}
|
||||
|
||||
consumed_len = std::min(maxlen, msg->data->len());
|
||||
if (consumed_len < msg->data->len()) {
|
||||
r_log(LOG_GENERIC, LOG_DEBUG, "Partial received UDP packet will be discard");
|
||||
}
|
||||
|
||||
memcpy(buf, msg->data->data(), consumed_len);
|
||||
*len = consumed_len;
|
||||
}
|
||||
|
||||
_status = 0;
|
||||
abort:
|
||||
return(_status);
|
||||
}
|
||||
|
||||
int NrSocketIpc::getaddr(nr_transport_addr *addrp) {
|
||||
ASSERT_ON_THREAD(sts_thread_);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
if (state_ != NR_CONNECTED) {
|
||||
return R_INTERNAL;
|
||||
}
|
||||
|
||||
return nr_transport_addr_copy(addrp, &my_addr_);
|
||||
}
|
||||
|
||||
// Main thread executors
|
||||
void NrSocketIpc::create_m(const nsACString &host, const uint16_t port) {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
nsresult rv;
|
||||
socket_child_ = do_CreateInstance("@mozilla.org/udp-socket-child;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to create UDPSocketChild");
|
||||
}
|
||||
|
||||
if (NS_FAILED(socket_child_->Bind(this, host, port))) {
|
||||
err_ = true;
|
||||
MOZ_ASSERT(false, "Failed to create UDP socket");
|
||||
}
|
||||
}
|
||||
|
||||
void NrSocketIpc::sendto_m(const net::NetAddr &addr, nsAutoPtr<DataBuffer> buf) {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
|
||||
MOZ_ASSERT(socket_child_);
|
||||
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
|
||||
if (NS_FAILED(socket_child_->SendWithAddress(&addr,
|
||||
buf->data(),
|
||||
buf->len()))) {
|
||||
err_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void NrSocketIpc::close_m() {
|
||||
ASSERT_ON_THREAD(main_thread_);
|
||||
|
||||
if (socket_child_) {
|
||||
socket_child_->Close();
|
||||
socket_child_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NrSocketIpc::recv_callback_s(RefPtr<nr_udp_message> msg) {
|
||||
ASSERT_ON_THREAD(sts_thread_);
|
||||
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(monitor_);
|
||||
if (state_ != NR_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//enqueue received message
|
||||
received_msgs_.push(msg);
|
||||
|
||||
if ((poll_flags() & PR_POLL_READ)) {
|
||||
fire_callback(NR_ASYNC_WAIT_READ);
|
||||
}
|
||||
}
|
||||
|
||||
} // close namespace
|
||||
|
||||
|
||||
|
@ -462,9 +939,18 @@ static nr_socket_vtbl nr_socket_local_vtbl={
|
|||
nr_socket_local_close
|
||||
};
|
||||
|
||||
|
||||
int nr_socket_local_create(nr_transport_addr *addr, nr_socket **sockp) {
|
||||
NrSocket * sock = new NrSocket();
|
||||
NrSocketBase *sock = nullptr;
|
||||
|
||||
// create IPC bridge for content process
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
sock = new NrSocket();
|
||||
} else {
|
||||
nsCOMPtr<nsIThread> main_thread;
|
||||
NS_GetMainThread(getter_AddRefs(main_thread));
|
||||
sock = new NrSocketIpc(main_thread.get());
|
||||
}
|
||||
|
||||
int r, _status;
|
||||
|
||||
r = sock->create(addr);
|
||||
|
@ -492,7 +978,7 @@ static int nr_socket_local_destroy(void **objp) {
|
|||
if(!objp || !*objp)
|
||||
return 0;
|
||||
|
||||
NrSocket *sock = static_cast<NrSocket *>(*objp);
|
||||
NrSocketBase *sock = static_cast<NrSocketBase *>(*objp);
|
||||
*objp=0;
|
||||
|
||||
sock->close(); // Signal STS that we want not to listen
|
||||
|
@ -503,7 +989,7 @@ static int nr_socket_local_destroy(void **objp) {
|
|||
|
||||
static int nr_socket_local_sendto(void *obj,const void *msg, size_t len,
|
||||
int flags, nr_transport_addr *addr) {
|
||||
NrSocket *sock = static_cast<NrSocket *>(obj);
|
||||
NrSocketBase *sock = static_cast<NrSocketBase *>(obj);
|
||||
|
||||
return sock->sendto(msg, len, flags, addr);
|
||||
}
|
||||
|
@ -511,13 +997,13 @@ static int nr_socket_local_sendto(void *obj,const void *msg, size_t len,
|
|||
static int nr_socket_local_recvfrom(void *obj,void * restrict buf,
|
||||
size_t maxlen, size_t *len, int flags,
|
||||
nr_transport_addr *addr) {
|
||||
NrSocket *sock = static_cast<NrSocket *>(obj);
|
||||
NrSocketBase *sock = static_cast<NrSocketBase *>(obj);
|
||||
|
||||
return sock->recvfrom(buf, maxlen, len, flags, addr);
|
||||
}
|
||||
|
||||
static int nr_socket_local_getfd(void *obj, NR_SOCKET *fd) {
|
||||
NrSocket *sock = static_cast<NrSocket *>(obj);
|
||||
NrSocketBase *sock = static_cast<NrSocketBase *>(obj);
|
||||
|
||||
*fd = sock;
|
||||
|
||||
|
@ -525,14 +1011,14 @@ static int nr_socket_local_getfd(void *obj, NR_SOCKET *fd) {
|
|||
}
|
||||
|
||||
static int nr_socket_local_getaddr(void *obj, nr_transport_addr *addrp) {
|
||||
NrSocket *sock = static_cast<NrSocket *>(obj);
|
||||
NrSocketBase *sock = static_cast<NrSocketBase *>(obj);
|
||||
|
||||
return sock->getaddr(addrp);
|
||||
}
|
||||
|
||||
|
||||
static int nr_socket_local_close(void *obj) {
|
||||
NrSocket *sock = static_cast<NrSocket *>(obj);
|
||||
NrSocketBase *sock = static_cast<NrSocketBase *>(obj);
|
||||
|
||||
sock->close();
|
||||
|
||||
|
@ -542,13 +1028,13 @@ static int nr_socket_local_close(void *obj) {
|
|||
// Implement async api
|
||||
int NR_async_wait(NR_SOCKET sock, int how, NR_async_cb cb,void *cb_arg,
|
||||
char *function,int line) {
|
||||
NrSocket *s = static_cast<NrSocket *>(sock);
|
||||
NrSocketBase *s = static_cast<NrSocketBase *>(sock);
|
||||
|
||||
return s->async_wait(how, cb, cb_arg, function, line);
|
||||
}
|
||||
|
||||
int NR_async_cancel(NR_SOCKET sock,int how) {
|
||||
NrSocket *s = static_cast<NrSocket *>(sock);
|
||||
NrSocketBase *s = static_cast<NrSocketBase *>(sock);
|
||||
|
||||
return s->cancel(how);
|
||||
}
|
||||
|
|
|
@ -46,18 +46,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef nr_socket_prsock__
|
||||
#define nr_socket_prsock__
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#include "nspr.h"
|
||||
#include "prio.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsASocketHandler.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsIUDPSocketChild.h"
|
||||
|
||||
#include "databuffer.h"
|
||||
#include "m_cpp_utils.h"
|
||||
#include "mozilla/ReentrantMonitor.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -65,13 +70,52 @@ namespace net {
|
|||
union NetAddr;
|
||||
}
|
||||
|
||||
class NrSocket : public nsASocketHandler {
|
||||
class NrSocketBase {
|
||||
public:
|
||||
NrSocket() : fd_(nullptr) {
|
||||
memset(&my_addr_, 0, sizeof(my_addr_));
|
||||
NrSocketBase() : poll_flags_(0) {
|
||||
memset(cbs_, 0, sizeof(cbs_));
|
||||
memset(cb_args_, 0, sizeof(cb_args_));
|
||||
memset(&my_addr_, 0, sizeof(my_addr_));
|
||||
}
|
||||
virtual ~NrSocketBase() {}
|
||||
|
||||
// the nr_socket APIs
|
||||
virtual int create(nr_transport_addr *addr) = 0;
|
||||
virtual int sendto(const void *msg, size_t len,
|
||||
int flags, nr_transport_addr *to) = 0;
|
||||
virtual int recvfrom(void * buf, size_t maxlen,
|
||||
size_t *len, int flags,
|
||||
nr_transport_addr *from) = 0;
|
||||
virtual int getaddr(nr_transport_addr *addrp) = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
// Implementations of the async_event APIs
|
||||
virtual int async_wait(int how, NR_async_cb cb, void *cb_arg,
|
||||
char *function, int line);
|
||||
virtual int cancel(int how);
|
||||
|
||||
// nsISupport reference counted interface
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) = 0;
|
||||
|
||||
uint32_t poll_flags() {
|
||||
return poll_flags_;
|
||||
}
|
||||
|
||||
protected:
|
||||
void fire_callback(int how);
|
||||
nr_transport_addr my_addr_;
|
||||
|
||||
private:
|
||||
NR_async_cb cbs_[NR_ASYNC_WAIT_WRITE + 1];
|
||||
void *cb_args_[NR_ASYNC_WAIT_WRITE + 1];
|
||||
uint32_t poll_flags_;
|
||||
};
|
||||
|
||||
class NrSocket : public NrSocketBase,
|
||||
public nsASocketHandler {
|
||||
public:
|
||||
NrSocket() : fd_(nullptr) {}
|
||||
virtual ~NrSocket() {
|
||||
PR_Close(fd_);
|
||||
}
|
||||
|
@ -87,36 +131,95 @@ public:
|
|||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
// Implementations of the async_event APIs
|
||||
int async_wait(int how, NR_async_cb cb, void *cb_arg,
|
||||
char *function, int line);
|
||||
int cancel(int how);
|
||||
virtual int async_wait(int how, NR_async_cb cb, void *cb_arg,
|
||||
char *function, int line);
|
||||
virtual int cancel(int how);
|
||||
|
||||
|
||||
// Implementations of the nr_socket APIs
|
||||
int create(nr_transport_addr *addr); // (really init, but it's called create)
|
||||
int sendto(const void *msg, size_t len,
|
||||
int flags, nr_transport_addr *to);
|
||||
int recvfrom(void * buf, size_t maxlen,
|
||||
size_t *len, int flags,
|
||||
nr_transport_addr *from);
|
||||
int getaddr(nr_transport_addr *addrp);
|
||||
void close();
|
||||
virtual int create(nr_transport_addr *addr); // (really init, but it's called create)
|
||||
virtual int sendto(const void *msg, size_t len,
|
||||
int flags, nr_transport_addr *to);
|
||||
virtual int recvfrom(void * buf, size_t maxlen,
|
||||
size_t *len, int flags,
|
||||
nr_transport_addr *from);
|
||||
virtual int getaddr(nr_transport_addr *addrp);
|
||||
virtual void close();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_ASSIGN(NrSocket);
|
||||
|
||||
void fire_callback(int how);
|
||||
|
||||
PRFileDesc *fd_;
|
||||
nr_transport_addr my_addr_;
|
||||
NR_async_cb cbs_[NR_ASYNC_WAIT_WRITE + 1];
|
||||
void *cb_args_[NR_ASYNC_WAIT_WRITE + 1];
|
||||
nsCOMPtr<nsIEventTarget> ststhread_;
|
||||
};
|
||||
|
||||
struct nr_udp_message {
|
||||
nr_udp_message(const PRNetAddr &from, nsAutoPtr<DataBuffer> &data)
|
||||
: from(from), data(data) {
|
||||
}
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nr_udp_message);
|
||||
|
||||
PRNetAddr from;
|
||||
nsAutoPtr<DataBuffer> data;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_ASSIGN(nr_udp_message);
|
||||
};
|
||||
|
||||
class NrSocketIpc : public NrSocketBase,
|
||||
public nsIUDPSocketInternal {
|
||||
public:
|
||||
|
||||
enum NrSocketIpcState {
|
||||
NR_INIT,
|
||||
NR_CONNECTING,
|
||||
NR_CONNECTED,
|
||||
NR_CLOSING,
|
||||
NR_CLOSED,
|
||||
};
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSOCKETINTERNAL
|
||||
|
||||
NrSocketIpc(const nsCOMPtr<nsIEventTarget> &main_thread);
|
||||
virtual ~NrSocketIpc() {};
|
||||
|
||||
// Implementations of the NrSocketBase APIs
|
||||
virtual int create(nr_transport_addr *addr);
|
||||
virtual int sendto(const void *msg, size_t len,
|
||||
int flags, nr_transport_addr *to);
|
||||
virtual int recvfrom(void * buf, size_t maxlen,
|
||||
size_t *len, int flags,
|
||||
nr_transport_addr *from);
|
||||
virtual int getaddr(nr_transport_addr *addrp);
|
||||
virtual void close();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_ASSIGN(NrSocketIpc);
|
||||
|
||||
// Main thread executors of the NrSocketBase APIs
|
||||
void create_m(const nsACString &host, const uint16_t port);
|
||||
void sendto_m(const net::NetAddr &addr, nsAutoPtr<DataBuffer> buf);
|
||||
void close_m();
|
||||
// STS thread executor
|
||||
void recv_callback_s(RefPtr<nr_udp_message> msg);
|
||||
|
||||
bool err_;
|
||||
NrSocketIpcState state_;
|
||||
std::queue<RefPtr<nr_udp_message> > received_msgs_;
|
||||
|
||||
nsCOMPtr<nsIUDPSocketChild> socket_child_;
|
||||
nsCOMPtr<nsIEventTarget> sts_thread_;
|
||||
const nsCOMPtr<nsIEventTarget> main_thread_;
|
||||
ReentrantMonitor monitor_;
|
||||
};
|
||||
|
||||
int nr_netaddr_to_transport_addr(const net::NetAddr *netaddr,
|
||||
nr_transport_addr *addr);
|
||||
int nr_praddr_to_transport_addr(const PRNetAddr *praddr,
|
||||
nr_transport_addr *addr, int keep);
|
||||
int nr_transport_addr_get_addrstring_and_port(nr_transport_addr *addr,
|
||||
nsACString *host, int32_t *port);
|
||||
} // close namespace
|
||||
#endif
|
||||
|
|
|
@ -106,7 +106,7 @@ XPIDL_SOURCES += [
|
|||
'nsITimedChannel.idl',
|
||||
'nsITraceableChannel.idl',
|
||||
'nsITransport.idl',
|
||||
'nsIUDPServerSocket.idl',
|
||||
'nsIUDPSocket.idl',
|
||||
'nsIUnicharStreamLoader.idl',
|
||||
'nsIUploadChannel.idl',
|
||||
'nsIUploadChannel2.idl',
|
||||
|
|
|
@ -6,13 +6,18 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{ C++
|
||||
#include "mozilla/net/DNS.h"
|
||||
%}
|
||||
native NetAddr(mozilla::net::NetAddr);
|
||||
|
||||
/**
|
||||
* nsINetAddr
|
||||
*
|
||||
* This interface represents a native NetAddr struct in a readonly
|
||||
* interface.
|
||||
*/
|
||||
[scriptable, uuid(4f7c40b0-fc7d-42a4-a642-1b2a703c10f6)]
|
||||
[scriptable, uuid(652B9EC5-D159-45D7-9127-50BB559486CD)]
|
||||
interface nsINetAddr : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -71,4 +76,9 @@ interface nsINetAddr : nsISupports
|
|||
const unsigned long FAMILY_INET = 1;
|
||||
const unsigned long FAMILY_INET6 = 2;
|
||||
const unsigned long FAMILY_LOCAL = 3;
|
||||
|
||||
/**
|
||||
* @return the underlying NetAddr struct.
|
||||
*/
|
||||
[noscript] NetAddr getNetAddr();
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsINetAddr;
|
||||
interface nsIUDPServerSocketListener;
|
||||
interface nsIUDPSocketListener;
|
||||
interface nsIUDPMessage;
|
||||
interface nsISocketTransport;
|
||||
interface nsIOutputStream;
|
||||
|
@ -22,23 +22,23 @@ native NetAddr(mozilla::net::NetAddr);
|
|||
[ptr] native NetAddrPtr(mozilla::net::NetAddr);
|
||||
|
||||
/**
|
||||
* nsIUDPServerSocket
|
||||
* nsIUDPSocket
|
||||
*
|
||||
* An interface to a server socket that can accept incoming connections.
|
||||
* An interface to a UDP socket that can accept incoming connections.
|
||||
*/
|
||||
[scriptable, uuid(c2a38bd0-024b-4ae8-bcb2-20d766b54389)]
|
||||
interface nsIUDPServerSocket : nsISupports
|
||||
[scriptable, uuid(6EFE692D-F0B0-4A9E-9E63-837C7452446D)]
|
||||
interface nsIUDPSocket : nsISupports
|
||||
{
|
||||
/**
|
||||
* init
|
||||
*
|
||||
* This method initializes a server socket.
|
||||
* This method initializes a UDP socket.
|
||||
*
|
||||
* @param aPort
|
||||
* The port of the server socket. Pass -1 to indicate no preference,
|
||||
* The port of the UDP socket. Pass -1 to indicate no preference,
|
||||
* and a port will be selected automatically.
|
||||
* @param aLoopbackOnly
|
||||
* If true, the server socket will only respond to connections on the
|
||||
* If true, the UDP socket will only respond to connections on the
|
||||
* local loopback interface. Otherwise, it will accept connections
|
||||
* from any interface. To specify a particular network interface,
|
||||
* use initWithAddress.
|
||||
|
@ -48,20 +48,20 @@ interface nsIUDPServerSocket : nsISupports
|
|||
/**
|
||||
* initWithAddress
|
||||
*
|
||||
* This method initializes a server socket, and binds it to a particular
|
||||
* This method initializes a UDP socket, and binds it to a particular
|
||||
* local address (and hence a particular local network interface).
|
||||
*
|
||||
* @param aAddr
|
||||
* The address to which this server socket should be bound.
|
||||
* The address to which this UDP socket should be bound.
|
||||
*/
|
||||
[noscript] void initWithAddress([const] in NetAddrPtr aAddr);
|
||||
|
||||
/**
|
||||
* close
|
||||
*
|
||||
* This method closes a server socket. This does not affect already
|
||||
* This method closes a UDP socket. This does not affect already
|
||||
* connected client sockets (i.e., the nsISocketTransport instances
|
||||
* created from this server socket). This will cause the onStopListening
|
||||
* created from this UDP socket). This will cause the onStopListening
|
||||
* event to asynchronously fire with a status of NS_BINDING_ABORTED.
|
||||
*/
|
||||
void close();
|
||||
|
@ -69,7 +69,7 @@ interface nsIUDPServerSocket : nsISupports
|
|||
/**
|
||||
* asyncListen
|
||||
*
|
||||
* This method puts the server socket in the listening state. It will
|
||||
* This method puts the UDP socket in the listening state. It will
|
||||
* asynchronously listen for and accept client connections. The listener
|
||||
* will be notified once for each client connection that is accepted. The
|
||||
* listener's onSocketAccepted method will be called on the same thread
|
||||
|
@ -81,65 +81,109 @@ interface nsIUDPServerSocket : nsISupports
|
|||
* @param aListener
|
||||
* The listener to be notified when client connections are accepted.
|
||||
*/
|
||||
void asyncListen(in nsIUDPServerSocketListener aListener);
|
||||
void asyncListen(in nsIUDPSocketListener aListener);
|
||||
|
||||
/**
|
||||
* Returns the port of this server socket.
|
||||
* Returns the port of this UDP socket.
|
||||
*/
|
||||
readonly attribute long port;
|
||||
|
||||
/**
|
||||
* Returns the address to which this server socket is bound. Since a
|
||||
* server socket may be bound to multiple network devices, this address
|
||||
* Returns the address to which this UDP socket is bound. Since a
|
||||
* UDP socket may be bound to multiple network devices, this address
|
||||
* may not necessarily be specific to a single network device. In the
|
||||
* case of an IP socket, the IP address field would be zerod out to
|
||||
* indicate a server socket bound to all network devices. Therefore,
|
||||
* indicate a UDP socket bound to all network devices. Therefore,
|
||||
* this method cannot be used to determine the IP address of the local
|
||||
* system. See nsIDNSService::myHostName if this is what you need.
|
||||
*/
|
||||
[noscript] NetAddr getAddress();
|
||||
|
||||
/**
|
||||
* send
|
||||
*
|
||||
* Send out the datagram to specified remote host and port.
|
||||
* DNS lookup will be triggered.
|
||||
*
|
||||
* @param host The remote host name.
|
||||
* @param port The remote port.
|
||||
* @param data The buffer containing the data to be written.
|
||||
* @param dataLength The maximum number of bytes to be written.
|
||||
* @return number of bytes written. (0 or dataLength)
|
||||
*/
|
||||
unsigned long send(in AUTF8String host, in unsigned short port,
|
||||
[const, array, size_is(dataLength)]in uint8_t data,
|
||||
in unsigned long dataLength);
|
||||
|
||||
/**
|
||||
* sendWithAddr
|
||||
*
|
||||
* Send out the datagram to specified remote host and port.
|
||||
*
|
||||
* @param addr The remote host address.
|
||||
* @param data The buffer containing the data to be written.
|
||||
* @param dataLength The maximum number of bytes to be written.
|
||||
* @return number of bytes written. (0 or dataLength)
|
||||
*/
|
||||
unsigned long sendWithAddr(in nsINetAddr addr,
|
||||
[const, array, size_is(dataLength)]in uint8_t data,
|
||||
in unsigned long dataLength);
|
||||
|
||||
/**
|
||||
* sendWithAddress
|
||||
*
|
||||
* Send out the datagram to specified remote address and port.
|
||||
*
|
||||
* @param addr The remote host address.
|
||||
* @param data The buffer containing the data to be written.
|
||||
* @param dataLength The maximum number of bytes to be written.
|
||||
* @return number of bytes written. (0 or dataLength)
|
||||
*/
|
||||
[noscript] unsigned long sendWithAddress([const] in NetAddrPtr addr,
|
||||
[const, array, size_is(dataLength)]in uint8_t data,
|
||||
in unsigned long dataLength);
|
||||
};
|
||||
|
||||
/**
|
||||
* nsIUDPServerSocketListener
|
||||
* nsIUDPSocketListener
|
||||
*
|
||||
* This interface is notified whenever a server socket accepts a new connection.
|
||||
* This interface is notified whenever a UDP socket accepts a new connection.
|
||||
* The transport is in the connected state, and read/write streams can be opened
|
||||
* using the normal nsITransport API. The address of the client can be found by
|
||||
* calling the nsISocketTransport::GetAddress method or by inspecting
|
||||
* nsISocketTransport::GetHost, which returns a string representation of the
|
||||
* client's IP address (NOTE: this may be an IPv4 or IPv6 string literal).
|
||||
*/
|
||||
[scriptable, uuid(0500a336-29b2-4df1-9103-911f8ee0a569)]
|
||||
interface nsIUDPServerSocketListener : nsISupports
|
||||
[scriptable, uuid(2E4B5DD3-7358-4281-B81F-10C62EF39CB5)]
|
||||
interface nsIUDPSocketListener : nsISupports
|
||||
{
|
||||
/**
|
||||
* onPacketReceived
|
||||
*
|
||||
* This method is called when a client sends an UDP packet.
|
||||
*
|
||||
* @param aServ
|
||||
* The server socket.
|
||||
* @param aSocket
|
||||
* The UDP socket.
|
||||
* @param aMessage
|
||||
* The message.
|
||||
*/
|
||||
void onPacketReceived(in nsIUDPServerSocket aServ,
|
||||
void onPacketReceived(in nsIUDPSocket aSocket,
|
||||
in nsIUDPMessage aMessage);
|
||||
|
||||
/**
|
||||
* onStopListening
|
||||
*
|
||||
* This method is called when the listening socket stops for some reason.
|
||||
* The server socket is effectively dead after this notification.
|
||||
* The UDP socket is effectively dead after this notification.
|
||||
*
|
||||
* @param aServ
|
||||
* The server socket.
|
||||
* @param aSocket
|
||||
* The UDP socket.
|
||||
* @param aStatus
|
||||
* The reason why the server socket stopped listening. If the
|
||||
* server socket was manually closed, then this value will be
|
||||
* The reason why the UDP socket stopped listening. If the
|
||||
* UDP socket was manually closed, then this value will be
|
||||
* NS_BINDING_ABORTED.
|
||||
*/
|
||||
void onStopListening(in nsIUDPServerSocket aServ, in nsresult aStatus);
|
||||
void onStopListening(in nsIUDPSocket aSocket, in nsresult aStatus);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -147,7 +191,7 @@ interface nsIUDPServerSocketListener : nsISupports
|
|||
*
|
||||
* This interface is used to encapsulate an incomming UDP message
|
||||
*/
|
||||
[scriptable, uuid(1587698a-60b6-4a8d-9df9-708cd793e24b)]
|
||||
[scriptable, uuid(333D5D69-8117-4AA6-9E16-2DD4FD6AEBA6)]
|
||||
interface nsIUDPMessage : nsISupports
|
||||
{
|
||||
/**
|
|
@ -66,7 +66,7 @@ SOURCES += [
|
|||
'nsSyncStreamListener.cpp',
|
||||
'nsTemporaryFileInputStream.cpp',
|
||||
'nsTransportUtils.cpp',
|
||||
'nsUDPServerSocket.cpp',
|
||||
'nsUDPSocket.cpp',
|
||||
'nsUnicharStreamLoader.cpp',
|
||||
'nsURIChecker.cpp',
|
||||
'nsURLHelper.cpp',
|
||||
|
|
|
@ -151,3 +151,8 @@ NS_IMETHODIMP nsNetAddr::GetIsV4Mapped(bool *aIsV4Mapped)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNetAddr::GetNetAddr(NetAddr *aResult) {
|
||||
memcpy(aResult, &mAddr, sizeof(mAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsSocketTransport2.h"
|
||||
#include "nsUDPServerSocket.h"
|
||||
#include "nsUDPSocket.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsError.h"
|
||||
|
@ -19,6 +19,9 @@
|
|||
#include "nsIPipe.h"
|
||||
#include "prerror.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsIDNSRecord.h"
|
||||
#include "nsIDNSService.h"
|
||||
#include "nsICancelable.h"
|
||||
|
||||
using namespace mozilla::net;
|
||||
using namespace mozilla;
|
||||
|
@ -27,10 +30,10 @@ static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef void (nsUDPServerSocket:: *nsUDPServerSocketFunc)(void);
|
||||
typedef void (nsUDPSocket:: *nsUDPSocketFunc)(void);
|
||||
|
||||
static nsresult
|
||||
PostEvent(nsUDPServerSocket *s, nsUDPServerSocketFunc func)
|
||||
PostEvent(nsUDPSocket *s, nsUDPSocketFunc func)
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> ev = NS_NewRunnableMethod(s, func);
|
||||
|
||||
|
@ -40,15 +43,32 @@ PostEvent(nsUDPServerSocket *s, nsUDPServerSocketFunc func)
|
|||
return gSocketTransportService->Dispatch(ev, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
static nsresult
|
||||
ResolveHost(const nsACString &host, nsIDNSListener *listener)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDNSService> dns =
|
||||
do_GetService("@mozilla.org/network/dns-service;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICancelable> tmpOutstanding;
|
||||
return dns->AsyncResolve(host, 0, listener, nullptr,
|
||||
getter_AddRefs(tmpOutstanding));
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsUPDOutputStream impl
|
||||
// nsUDPOutputStream impl
|
||||
//-----------------------------------------------------------------------------
|
||||
NS_IMPL_ISUPPORTS1(nsUDPOutputStream, nsIOutputStream)
|
||||
|
||||
nsUDPOutputStream::nsUDPOutputStream(nsUDPServerSocket* aServer,
|
||||
nsUDPOutputStream::nsUDPOutputStream(nsUDPSocket* aSocket,
|
||||
PRFileDesc* aFD,
|
||||
PRNetAddr& aPrClientAddr)
|
||||
: mServer(aServer)
|
||||
: mSocket(aSocket)
|
||||
, mFD(aFD)
|
||||
, mPrClientAddr(aPrClientAddr)
|
||||
, mIsClosed(false)
|
||||
|
@ -90,7 +110,7 @@ NS_IMETHODIMP nsUDPOutputStream::Write(const char * aBuf, uint32_t aCount, uint3
|
|||
|
||||
*_retval = count;
|
||||
|
||||
mServer->AddOutputBytes(count);
|
||||
mSocket->AddOutputBytes(count);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -115,7 +135,7 @@ NS_IMETHODIMP nsUDPOutputStream::IsNonBlocking(bool *_retval)
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsUPDMessage impl
|
||||
// nsUDPMessage impl
|
||||
//-----------------------------------------------------------------------------
|
||||
NS_IMPL_ISUPPORTS1(nsUDPMessage, nsIUDPMessage)
|
||||
|
||||
|
@ -162,11 +182,11 @@ NS_IMETHODIMP nsUDPMessage::GetOutputStream(nsIOutputStream * *aOutputStream)
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsServerSocket
|
||||
// nsUDPSocket
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
nsUDPServerSocket::nsUDPServerSocket()
|
||||
: mLock("nsUDPServerSocket.mLock")
|
||||
nsUDPSocket::nsUDPSocket()
|
||||
: mLock("nsUDPSocket.mLock")
|
||||
, mFD(nullptr)
|
||||
, mAttached(false)
|
||||
, mByteReadCount(0)
|
||||
|
@ -183,26 +203,26 @@ nsUDPServerSocket::nsUDPServerSocket()
|
|||
}
|
||||
|
||||
mSts = gSocketTransportService;
|
||||
MOZ_COUNT_CTOR(nsUDPServerSocket);
|
||||
MOZ_COUNT_CTOR(nsUDPSocket);
|
||||
}
|
||||
|
||||
nsUDPServerSocket::~nsUDPServerSocket()
|
||||
nsUDPSocket::~nsUDPSocket()
|
||||
{
|
||||
Close(); // just in case :)
|
||||
|
||||
MOZ_COUNT_DTOR(nsUDPServerSocket);
|
||||
MOZ_COUNT_DTOR(nsUDPSocket);
|
||||
}
|
||||
|
||||
void
|
||||
nsUDPServerSocket::AddOutputBytes(uint64_t aBytes)
|
||||
nsUDPSocket::AddOutputBytes(uint64_t aBytes)
|
||||
{
|
||||
mByteWriteCount += aBytes;
|
||||
}
|
||||
|
||||
void
|
||||
nsUDPServerSocket::OnMsgClose()
|
||||
nsUDPSocket::OnMsgClose()
|
||||
{
|
||||
SOCKET_LOG(("nsServerSocket::OnMsgClose [this=%p]\n", this));
|
||||
SOCKET_LOG(("nsUDPSocket::OnMsgClose [this=%p]\n", this));
|
||||
|
||||
if (NS_FAILED(mCondition))
|
||||
return;
|
||||
|
@ -218,9 +238,9 @@ nsUDPServerSocket::OnMsgClose()
|
|||
}
|
||||
|
||||
void
|
||||
nsUDPServerSocket::OnMsgAttach()
|
||||
nsUDPSocket::OnMsgAttach()
|
||||
{
|
||||
SOCKET_LOG(("nsServerSocket::OnMsgAttach [this=%p]\n", this));
|
||||
SOCKET_LOG(("nsUDPSocket::OnMsgAttach [this=%p]\n", this));
|
||||
|
||||
if (NS_FAILED(mCondition))
|
||||
return;
|
||||
|
@ -236,7 +256,7 @@ nsUDPServerSocket::OnMsgAttach()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsUDPServerSocket::TryAttach()
|
||||
nsUDPSocket::TryAttach()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -258,7 +278,7 @@ nsUDPServerSocket::TryAttach()
|
|||
if (!gSocketTransportService->CanAttachSocket())
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> event =
|
||||
NS_NewRunnableMethod(this, &nsUDPServerSocket::OnMsgAttach);
|
||||
NS_NewRunnableMethod(this, &nsUDPSocket::OnMsgAttach);
|
||||
|
||||
nsresult rv = gSocketTransportService->NotifyWhenCanAttachSocket(event);
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -282,11 +302,11 @@ nsUDPServerSocket::TryAttach()
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsServerSocket::nsASocketHandler
|
||||
// nsUDPSocket::nsASocketHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
nsUDPServerSocket::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
|
||||
nsUDPSocket::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
|
||||
{
|
||||
NS_ASSERTION(NS_SUCCEEDED(mCondition), "oops");
|
||||
NS_ASSERTION(mFD == fd, "wrong file descriptor");
|
||||
|
@ -343,7 +363,7 @@ nsUDPServerSocket::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
|
|||
}
|
||||
|
||||
void
|
||||
nsUDPServerSocket::OnSocketDetached(PRFileDesc *fd)
|
||||
nsUDPSocket::OnSocketDetached(PRFileDesc *fd)
|
||||
{
|
||||
// force a failure condition if none set; maybe the STS is shutting down :-/
|
||||
if (NS_SUCCEEDED(mCondition))
|
||||
|
@ -359,7 +379,7 @@ nsUDPServerSocket::OnSocketDetached(PRFileDesc *fd)
|
|||
if (mListener)
|
||||
{
|
||||
// need to atomically clear mListener. see our Close() method.
|
||||
nsCOMPtr<nsIUDPServerSocketListener> listener;
|
||||
nsCOMPtr<nsIUDPSocketListener> listener;
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
mListener.swap(listener);
|
||||
|
@ -373,25 +393,25 @@ nsUDPServerSocket::OnSocketDetached(PRFileDesc *fd)
|
|||
}
|
||||
|
||||
void
|
||||
nsUDPServerSocket::IsLocal(bool *aIsLocal)
|
||||
nsUDPSocket::IsLocal(bool *aIsLocal)
|
||||
{
|
||||
// If bound to loopback, this server socket only accepts local connections.
|
||||
// If bound to loopback, this UDP socket only accepts local connections.
|
||||
*aIsLocal = mAddr.raw.family == nsINetAddr::FAMILY_LOCAL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsServerSocket::nsISupports
|
||||
// nsSocket::nsISupports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsUDPServerSocket, nsIUDPServerSocket)
|
||||
NS_IMPL_ISUPPORTS1(nsUDPSocket, nsIUDPSocket)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsServerSocket::nsIServerSocket
|
||||
// nsSocket::nsISocket
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPServerSocket::Init(int32_t aPort, bool aLoopbackOnly)
|
||||
nsUDPSocket::Init(int32_t aPort, bool aLoopbackOnly)
|
||||
{
|
||||
NetAddr addr;
|
||||
|
||||
|
@ -410,7 +430,7 @@ nsUDPServerSocket::Init(int32_t aPort, bool aLoopbackOnly)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPServerSocket::InitWithAddress(const NetAddr *aAddr)
|
||||
nsUDPSocket::InitWithAddress(const NetAddr *aAddr)
|
||||
{
|
||||
NS_ENSURE_TRUE(mFD == nullptr, NS_ERROR_ALREADY_INITIALIZED);
|
||||
|
||||
|
@ -421,7 +441,7 @@ nsUDPServerSocket::InitWithAddress(const NetAddr *aAddr)
|
|||
mFD = PR_OpenUDPSocket(aAddr->raw.family);
|
||||
if (!mFD)
|
||||
{
|
||||
NS_WARNING("unable to create server socket");
|
||||
NS_WARNING("unable to create UDP socket");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -436,6 +456,7 @@ nsUDPServerSocket::InitWithAddress(const NetAddr *aAddr)
|
|||
PR_SetSocketOption(mFD, &opt);
|
||||
|
||||
PRNetAddr addr;
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, 0, &addr);
|
||||
NetAddrToPRNetAddr(aAddr, &addr);
|
||||
|
||||
if (PR_Bind(mFD, &addr) != PR_SUCCESS)
|
||||
|
@ -467,7 +488,7 @@ fail:
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPServerSocket::Close()
|
||||
nsUDPSocket::Close()
|
||||
{
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
@ -483,11 +504,11 @@ nsUDPServerSocket::Close()
|
|||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return PostEvent(this, &nsUDPServerSocket::OnMsgClose);
|
||||
return PostEvent(this, &nsUDPSocket::OnMsgClose);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPServerSocket::GetPort(int32_t *aResult)
|
||||
nsUDPSocket::GetPort(int32_t *aResult)
|
||||
{
|
||||
// no need to enter the lock here
|
||||
uint16_t port;
|
||||
|
@ -503,7 +524,7 @@ nsUDPServerSocket::GetPort(int32_t *aResult)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPServerSocket::GetAddress(NetAddr *aResult)
|
||||
nsUDPSocket::GetAddress(NetAddr *aResult)
|
||||
{
|
||||
// no need to enter the lock here
|
||||
memcpy(aResult, &mAddr, sizeof(mAddr));
|
||||
|
@ -512,107 +533,260 @@ nsUDPServerSocket::GetAddress(NetAddr *aResult)
|
|||
|
||||
namespace {
|
||||
|
||||
class ServerSocketListenerProxy MOZ_FINAL : public nsIUDPServerSocketListener
|
||||
class SocketListenerProxy MOZ_FINAL : public nsIUDPSocketListener
|
||||
{
|
||||
public:
|
||||
ServerSocketListenerProxy(nsIUDPServerSocketListener* aListener)
|
||||
: mListener(new nsMainThreadPtrHolder<nsIUDPServerSocketListener>(aListener))
|
||||
SocketListenerProxy(nsIUDPSocketListener* aListener)
|
||||
: mListener(new nsMainThreadPtrHolder<nsIUDPSocketListener>(aListener))
|
||||
, mTargetThread(do_GetCurrentThread())
|
||||
{ }
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSERVERSOCKETLISTENER
|
||||
NS_DECL_NSIUDPSOCKETLISTENER
|
||||
|
||||
class OnPacketReceivedRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
OnPacketReceivedRunnable(const nsMainThreadPtrHandle<nsIUDPServerSocketListener>& aListener,
|
||||
nsIUDPServerSocket* aServ,
|
||||
nsIUDPMessage* aMessage)
|
||||
OnPacketReceivedRunnable(const nsMainThreadPtrHandle<nsIUDPSocketListener>& aListener,
|
||||
nsIUDPSocket* aSocket,
|
||||
nsIUDPMessage* aMessage)
|
||||
: mListener(aListener)
|
||||
, mServ(aServ)
|
||||
, mSocket(aSocket)
|
||||
, mMessage(aMessage)
|
||||
{ }
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
private:
|
||||
nsMainThreadPtrHandle<nsIUDPServerSocketListener> mListener;
|
||||
nsCOMPtr<nsIUDPServerSocket> mServ;
|
||||
nsMainThreadPtrHandle<nsIUDPSocketListener> mListener;
|
||||
nsCOMPtr<nsIUDPSocket> mSocket;
|
||||
nsCOMPtr<nsIUDPMessage> mMessage;
|
||||
};
|
||||
|
||||
class OnStopListeningRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
OnStopListeningRunnable(const nsMainThreadPtrHandle<nsIUDPServerSocketListener>& aListener,
|
||||
nsIUDPServerSocket* aServ,
|
||||
OnStopListeningRunnable(const nsMainThreadPtrHandle<nsIUDPSocketListener>& aListener,
|
||||
nsIUDPSocket* aSocket,
|
||||
nsresult aStatus)
|
||||
: mListener(aListener)
|
||||
, mServ(aServ)
|
||||
, mSocket(aSocket)
|
||||
, mStatus(aStatus)
|
||||
{ }
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
private:
|
||||
nsMainThreadPtrHandle<nsIUDPServerSocketListener> mListener;
|
||||
nsCOMPtr<nsIUDPServerSocket> mServ;
|
||||
nsMainThreadPtrHandle<nsIUDPSocketListener> mListener;
|
||||
nsCOMPtr<nsIUDPSocket> mSocket;
|
||||
nsresult mStatus;
|
||||
};
|
||||
|
||||
private:
|
||||
nsMainThreadPtrHandle<nsIUDPServerSocketListener> mListener;
|
||||
nsMainThreadPtrHandle<nsIUDPSocketListener> mListener;
|
||||
nsCOMPtr<nsIEventTarget> mTargetThread;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(ServerSocketListenerProxy,
|
||||
nsIUDPServerSocketListener)
|
||||
NS_IMPL_ISUPPORTS1(SocketListenerProxy,
|
||||
nsIUDPSocketListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServerSocketListenerProxy::OnPacketReceived(nsIUDPServerSocket* aServ,
|
||||
nsIUDPMessage* aMessage)
|
||||
SocketListenerProxy::OnPacketReceived(nsIUDPSocket* aSocket,
|
||||
nsIUDPMessage* aMessage)
|
||||
{
|
||||
nsRefPtr<OnPacketReceivedRunnable> r =
|
||||
new OnPacketReceivedRunnable(mListener, aServ, aMessage);
|
||||
new OnPacketReceivedRunnable(mListener, aSocket, aMessage);
|
||||
return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServerSocketListenerProxy::OnStopListening(nsIUDPServerSocket* aServ,
|
||||
nsresult aStatus)
|
||||
SocketListenerProxy::OnStopListening(nsIUDPSocket* aSocket,
|
||||
nsresult aStatus)
|
||||
{
|
||||
nsRefPtr<OnStopListeningRunnable> r =
|
||||
new OnStopListeningRunnable(mListener, aServ, aStatus);
|
||||
new OnStopListeningRunnable(mListener, aSocket, aStatus);
|
||||
return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServerSocketListenerProxy::OnPacketReceivedRunnable::Run()
|
||||
SocketListenerProxy::OnPacketReceivedRunnable::Run()
|
||||
{
|
||||
mListener->OnPacketReceived(mServ, mMessage);
|
||||
mListener->OnPacketReceived(mSocket, mMessage);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServerSocketListenerProxy::OnStopListeningRunnable::Run()
|
||||
SocketListenerProxy::OnStopListeningRunnable::Run()
|
||||
{
|
||||
mListener->OnStopListening(mServ, mStatus);
|
||||
mListener->OnStopListening(mSocket, mStatus);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class PendingSend : public nsIDNSListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIDNSLISTENER
|
||||
|
||||
PendingSend(nsUDPSocket *aSocket, uint16_t aPort,
|
||||
FallibleTArray<uint8_t> &aData)
|
||||
: mSocket(aSocket)
|
||||
, mPort(aPort)
|
||||
{
|
||||
mData.SwapElements(aData);
|
||||
}
|
||||
|
||||
virtual ~PendingSend() {}
|
||||
|
||||
private:
|
||||
nsRefPtr<nsUDPSocket> mSocket;
|
||||
uint16_t mPort;
|
||||
FallibleTArray<uint8_t> mData;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(PendingSend, nsIDNSListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
PendingSend::OnLookupComplete(nsICancelable *request,
|
||||
nsIDNSRecord *rec,
|
||||
nsresult status)
|
||||
{
|
||||
if (NS_FAILED(status)) {
|
||||
NS_WARNING("Failed to send UDP packet due to DNS lookup failure");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NetAddr addr;
|
||||
if (NS_SUCCEEDED(rec->GetNextAddr(mPort, &addr))) {
|
||||
uint32_t count;
|
||||
nsresult rv = mSocket->SendWithAddress(&addr, mData.Elements(),
|
||||
mData.Length(), &count);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class SendRequestRunnable: public nsRunnable {
|
||||
public:
|
||||
SendRequestRunnable(nsUDPSocket *aSocket,
|
||||
const NetAddr &aAddr,
|
||||
FallibleTArray<uint8_t> &aData)
|
||||
: mSocket(aSocket)
|
||||
, mAddr(aAddr)
|
||||
, mData(aData)
|
||||
{ }
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
private:
|
||||
nsRefPtr<nsUDPSocket> mSocket;
|
||||
const NetAddr mAddr;
|
||||
FallibleTArray<uint8_t> mData;
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
SendRequestRunnable::Run()
|
||||
{
|
||||
uint32_t count;
|
||||
mSocket->SendWithAddress(&mAddr, mData.Elements(),
|
||||
mData.Length(), &count);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPServerSocket::AsyncListen(nsIUDPServerSocketListener *aListener)
|
||||
nsUDPSocket::AsyncListen(nsIUDPSocketListener *aListener)
|
||||
{
|
||||
// ensuring mFD implies ensuring mLock
|
||||
NS_ENSURE_TRUE(mFD, NS_ERROR_NOT_INITIALIZED);
|
||||
NS_ENSURE_TRUE(mListener == nullptr, NS_ERROR_IN_PROGRESS);
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
mListener = new ServerSocketListenerProxy(aListener);
|
||||
mListener = new SocketListenerProxy(aListener);
|
||||
mListenerTarget = NS_GetCurrentThread();
|
||||
}
|
||||
return PostEvent(this, &nsUDPServerSocket::OnMsgAttach);
|
||||
return PostEvent(this, &nsUDPSocket::OnMsgAttach);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPSocket::Send(const nsACString &aHost, uint16_t aPort,
|
||||
const uint8_t *aData, uint32_t aDataLength,
|
||||
uint32_t *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(aData);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
*_retval = 0;
|
||||
|
||||
FallibleTArray<uint8_t> fallibleArray;
|
||||
if (!fallibleArray.InsertElementsAt(0, aData, aDataLength)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDNSListener> listener = new PendingSend(this, aPort, fallibleArray);
|
||||
|
||||
nsresult rv = ResolveHost(aHost, listener);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*_retval = aDataLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPSocket::SendWithAddr(nsINetAddr *aAddr, const uint8_t *aData,
|
||||
uint32_t aDataLength, uint32_t *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(aAddr);
|
||||
NS_ENSURE_ARG(aData);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
NetAddr netAddr;
|
||||
aAddr->GetNetAddr(&netAddr);
|
||||
return SendWithAddress(&netAddr, aData, aDataLength, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPSocket::SendWithAddress(const NetAddr *aAddr, const uint8_t *aData,
|
||||
uint32_t aDataLength, uint32_t *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(aAddr);
|
||||
NS_ENSURE_ARG(aData);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
*_retval = 0;
|
||||
|
||||
PRNetAddr prAddr;
|
||||
NetAddrToPRNetAddr(aAddr, &prAddr);
|
||||
|
||||
bool onSTSThread = false;
|
||||
mSts->IsOnCurrentThread(&onSTSThread);
|
||||
|
||||
if (onSTSThread) {
|
||||
MutexAutoLock lock(mLock);
|
||||
if (!mFD) {
|
||||
// socket is not initialized or has been closed
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
int32_t count = PR_SendTo(mFD, aData, sizeof(uint8_t) *aDataLength,
|
||||
0, &prAddr, PR_INTERVAL_NO_WAIT);
|
||||
if (count < 0) {
|
||||
PRErrorCode code = PR_GetError();
|
||||
return ErrorAccordingToNSPR(code);
|
||||
}
|
||||
this->AddOutputBytes(count);
|
||||
*_retval = count;
|
||||
} else {
|
||||
FallibleTArray<uint8_t> fallibleArray;
|
||||
if (!fallibleArray.InsertElementsAt(0, aData, aDataLength)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv = mSts->Dispatch(new SendRequestRunnable(this, *aAddr, fallibleArray),
|
||||
NS_DISPATCH_NORMAL);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
*_retval = aDataLength;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
|
@ -3,22 +3,22 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef nsUDPServerSocket_h__
|
||||
#define nsUDPServerSocket_h__
|
||||
#ifndef nsUDPSocket_h__
|
||||
#define nsUDPSocket_h__
|
||||
|
||||
#include "nsIUDPServerSocket.h"
|
||||
#include "nsIUDPSocket.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class nsUDPServerSocket : public nsASocketHandler
|
||||
, public nsIUDPServerSocket
|
||||
class nsUDPSocket : public nsASocketHandler
|
||||
, public nsIUDPSocket
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSERVERSOCKET
|
||||
NS_DECL_NSIUDPSOCKET
|
||||
|
||||
// nsASocketHandler methods:
|
||||
virtual void OnSocketReady(PRFileDesc* fd, int16_t outFlags);
|
||||
|
@ -30,10 +30,10 @@ public:
|
|||
|
||||
void AddOutputBytes(uint64_t aBytes);
|
||||
|
||||
nsUDPServerSocket();
|
||||
nsUDPSocket();
|
||||
|
||||
// This must be public to support older compilers (xlC_r on AIX)
|
||||
virtual ~nsUDPServerSocket();
|
||||
virtual ~nsUDPSocket();
|
||||
|
||||
private:
|
||||
void OnMsgClose();
|
||||
|
@ -47,7 +47,7 @@ private:
|
|||
mozilla::Mutex mLock;
|
||||
PRFileDesc *mFD;
|
||||
mozilla::net::NetAddr mAddr;
|
||||
nsCOMPtr<nsIUDPServerSocketListener> mListener;
|
||||
nsCOMPtr<nsIUDPSocketListener> mListener;
|
||||
nsCOMPtr<nsIEventTarget> mListenerTarget;
|
||||
bool mAttached;
|
||||
nsRefPtr<nsSocketTransportService> mSts;
|
||||
|
@ -85,16 +85,16 @@ public:
|
|||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIOUTPUTSTREAM
|
||||
|
||||
nsUDPOutputStream(nsUDPServerSocket* aServer,
|
||||
nsUDPOutputStream(nsUDPSocket* aSocket,
|
||||
PRFileDesc* aFD,
|
||||
PRNetAddr& aPrClientAddr);
|
||||
virtual ~nsUDPOutputStream();
|
||||
|
||||
private:
|
||||
nsRefPtr<nsUDPServerSocket> mServer;
|
||||
nsRefPtr<nsUDPSocket> mSocket;
|
||||
PRFileDesc *mFD;
|
||||
PRNetAddr mPrClientAddr;
|
||||
bool mIsClosed;
|
||||
};
|
||||
|
||||
#endif // nsUDPServerSocket_h__
|
||||
#endif // nsUDPSocket_h__
|
|
@ -335,10 +335,10 @@
|
|||
{0xab, 0x1d, 0x5e, 0x68, 0xa9, 0xf4, 0x5f, 0x08} \
|
||||
}
|
||||
|
||||
// component implementing nsIUDPServerSocket
|
||||
#define NS_UDPSERVERSOCKET_CONTRACTID \
|
||||
"@mozilla.org/network/server-socket-udp;1"
|
||||
#define NS_UDPSERVERSOCKET_CID \
|
||||
// component implementing nsIUDPSocket
|
||||
#define NS_UDPSOCKET_CONTRACTID \
|
||||
"@mozilla.org/network/udp-socket;1"
|
||||
#define NS_UDPSOCKET_CID \
|
||||
{ /* c9f74572-7b8e-4fec-bb4a-03c0d3021bd6 */ \
|
||||
0xc9f74572, \
|
||||
0x7b8e, \
|
||||
|
|
|
@ -73,8 +73,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSocketTransportService, Init)
|
|||
#include "nsServerSocket.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsServerSocket)
|
||||
|
||||
#include "nsUDPServerSocket.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUDPServerSocket)
|
||||
#include "nsUDPSocket.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUDPSocket)
|
||||
|
||||
#include "nsUDPSocketProvider.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUDPSocketProvider)
|
||||
|
@ -682,7 +682,7 @@ NS_DEFINE_NAMED_CID(NS_IOSERVICE_CID);
|
|||
NS_DEFINE_NAMED_CID(NS_STREAMTRANSPORTSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_SERVERSOCKET_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_UDPSERVERSOCKET_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_UDPSOCKET_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_SOCKETPROVIDERSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DNSSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_IDNSERVICE_CID);
|
||||
|
@ -820,7 +820,7 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
|
|||
{ &kNS_STREAMTRANSPORTSERVICE_CID, false, nullptr, nsStreamTransportServiceConstructor },
|
||||
{ &kNS_SOCKETTRANSPORTSERVICE_CID, false, nullptr, nsSocketTransportServiceConstructor },
|
||||
{ &kNS_SERVERSOCKET_CID, false, nullptr, nsServerSocketConstructor },
|
||||
{ &kNS_UDPSERVERSOCKET_CID, false, nullptr, nsUDPServerSocketConstructor },
|
||||
{ &kNS_UDPSOCKET_CID, false, nullptr, nsUDPSocketConstructor },
|
||||
{ &kNS_SOCKETPROVIDERSERVICE_CID, false, nullptr, nsSocketProviderService::Create },
|
||||
{ &kNS_DNSSERVICE_CID, false, nullptr, nsDNSServiceConstructor },
|
||||
{ &kNS_IDNSERVICE_CID, false, nullptr, nsIDNServiceConstructor },
|
||||
|
@ -965,7 +965,7 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
|
|||
{ NS_STREAMTRANSPORTSERVICE_CONTRACTID, &kNS_STREAMTRANSPORTSERVICE_CID },
|
||||
{ NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &kNS_SOCKETTRANSPORTSERVICE_CID },
|
||||
{ NS_SERVERSOCKET_CONTRACTID, &kNS_SERVERSOCKET_CID },
|
||||
{ NS_UDPSERVERSOCKET_CONTRACTID, &kNS_UDPSERVERSOCKET_CID },
|
||||
{ NS_UDPSOCKET_CONTRACTID, &kNS_UDPSOCKET_CID },
|
||||
{ NS_SOCKETPROVIDERSERVICE_CONTRACTID, &kNS_SOCKETPROVIDERSERVICE_CID },
|
||||
{ NS_DNSSERVICE_CONTRACTID, &kNS_DNSSERVICE_CID },
|
||||
{ NS_IDNSERVICE_CONTRACTID, &kNS_IDNSERVICE_CID },
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
/* vim: set sw=2 ts=8 et tw=80 : */
|
||||
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
|
@ -16,6 +16,7 @@
|
|||
#include "mozilla/net/RemoteOpenFileChild.h"
|
||||
#include "mozilla/dom/network/TCPSocketChild.h"
|
||||
#include "mozilla/dom/network/TCPServerSocketChild.h"
|
||||
#include "mozilla/dom/network/UDPSocketChild.h"
|
||||
#ifdef MOZ_RTSP
|
||||
#include "mozilla/net/RtspControllerChild.h"
|
||||
#endif
|
||||
|
@ -23,6 +24,7 @@
|
|||
|
||||
using mozilla::dom::TCPSocketChild;
|
||||
using mozilla::dom::TCPServerSocketChild;
|
||||
using mozilla::dom::UDPSocketChild;
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
@ -209,6 +211,23 @@ NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child)
|
|||
return true;
|
||||
}
|
||||
|
||||
PUDPSocketChild*
|
||||
NeckoChild::AllocPUDPSocketChild(const nsCString& aHost,
|
||||
const uint16_t& aPort)
|
||||
{
|
||||
NS_NOTREACHED("AllocPUDPSocket should not be called");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild* child)
|
||||
{
|
||||
|
||||
UDPSocketChild* p = static_cast<UDPSocketChild*>(child);
|
||||
p->ReleaseIPDLReference();
|
||||
return true;
|
||||
}
|
||||
|
||||
PRemoteOpenFileChild*
|
||||
NeckoChild::AllocPRemoteOpenFileChild(const URIParams&, const OptionalURIParams&)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,9 @@ protected:
|
|||
const uint16_t& aBacklog,
|
||||
const nsString& aBinaryType);
|
||||
virtual bool DeallocPTCPServerSocketChild(PTCPServerSocketChild*);
|
||||
virtual PUDPSocketChild* AllocPUDPSocketChild(const nsCString& aHost,
|
||||
const uint16_t& aPort);
|
||||
virtual bool DeallocPUDPSocketChild(PUDPSocketChild*);
|
||||
virtual PRemoteOpenFileChild* AllocPRemoteOpenFileChild(const URIParams&,
|
||||
const OptionalURIParams&);
|
||||
virtual bool DeallocPRemoteOpenFileChild(PRemoteOpenFileChild*);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "mozilla/dom/TabParent.h"
|
||||
#include "mozilla/dom/network/TCPSocketParent.h"
|
||||
#include "mozilla/dom/network/TCPServerSocketParent.h"
|
||||
#include "mozilla/dom/network/UDPSocketParent.h"
|
||||
#include "mozilla/ipc/URIUtils.h"
|
||||
#include "mozilla/LoadContext.h"
|
||||
#include "mozilla/AppProcessChecker.h"
|
||||
|
@ -36,6 +37,8 @@ using mozilla::net::PTCPSocketParent;
|
|||
using mozilla::dom::TCPSocketParent;
|
||||
using mozilla::net::PTCPServerSocketParent;
|
||||
using mozilla::dom::TCPServerSocketParent;
|
||||
using mozilla::net::PUDPSocketParent;
|
||||
using mozilla::dom::UDPSocketParent;
|
||||
using IPC::SerializedLoadContext;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -373,6 +376,37 @@ NeckoParent::DeallocPTCPServerSocketParent(PTCPServerSocketParent* actor)
|
|||
return true;
|
||||
}
|
||||
|
||||
PUDPSocketParent*
|
||||
NeckoParent::AllocPUDPSocketParent(const nsCString& aHost,
|
||||
const uint16_t& aPort)
|
||||
{
|
||||
bool enabled = Preferences::GetBool("media.peerconnection.ipc.enabled", false);
|
||||
if (!enabled) {
|
||||
NS_WARNING("Not support UDP socket in content process, aborting subprocess");
|
||||
return nullptr;
|
||||
}
|
||||
UDPSocketParent* p = new UDPSocketParent();
|
||||
p->AddRef();
|
||||
return p;
|
||||
|
||||
}
|
||||
|
||||
bool
|
||||
NeckoParent::RecvPUDPSocketConstructor(PUDPSocketParent* aActor,
|
||||
const nsCString& aHost,
|
||||
const uint16_t& aPort)
|
||||
{
|
||||
return static_cast<UDPSocketParent*>(aActor)->Init(aHost, aPort);
|
||||
}
|
||||
|
||||
bool
|
||||
NeckoParent::DeallocPUDPSocketParent(PUDPSocketParent* actor)
|
||||
{
|
||||
UDPSocketParent* p = static_cast<UDPSocketParent*>(actor);
|
||||
p->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
PRemoteOpenFileParent*
|
||||
NeckoParent::AllocPRemoteOpenFileParent(const URIParams& aURI,
|
||||
const OptionalURIParams& aAppURI)
|
||||
|
|
|
@ -116,6 +116,12 @@ protected:
|
|||
const uint16_t& aBacklog,
|
||||
const nsString& aBinaryType);
|
||||
virtual bool DeallocPTCPServerSocketParent(PTCPServerSocketParent*);
|
||||
virtual PUDPSocketParent* AllocPUDPSocketParent(const nsCString& aHost,
|
||||
const uint16_t& aPort);
|
||||
virtual bool RecvPUDPSocketConstructor(PUDPSocketParent*,
|
||||
const nsCString& aHost,
|
||||
const uint16_t& aPort);
|
||||
virtual bool DeallocPUDPSocketParent(PUDPSocketParent*);
|
||||
virtual bool RecvHTMLDNSPrefetch(const nsString& hostname,
|
||||
const uint16_t& flags);
|
||||
virtual bool RecvCancelHTMLDNSPrefetch(const nsString& hostname,
|
||||
|
|
|
@ -14,6 +14,7 @@ include protocol PFTPChannel;
|
|||
include protocol PWebSocket;
|
||||
include protocol PTCPSocket;
|
||||
include protocol PTCPServerSocket;
|
||||
include protocol PUDPSocket;
|
||||
include protocol PRemoteOpenFile;
|
||||
include protocol PBlob; //FIXME: bug #792908
|
||||
|
||||
|
@ -39,6 +40,7 @@ sync protocol PNecko
|
|||
manages PWebSocket;
|
||||
manages PTCPSocket;
|
||||
manages PTCPServerSocket;
|
||||
manages PUDPSocket;
|
||||
manages PRemoteOpenFile;
|
||||
manages PRtspController;
|
||||
|
||||
|
@ -55,6 +57,8 @@ parent:
|
|||
|
||||
PWebSocket(PBrowser browser, SerializedLoadContext loadContext);
|
||||
PTCPServerSocket(uint16_t localPort, uint16_t backlog, nsString binaryType);
|
||||
PUDPSocket(nsCString host, uint16_t port);
|
||||
|
||||
PRemoteOpenFile(URIParams fileuri, OptionalURIParams appuri);
|
||||
|
||||
HTMLDNSPrefetch(nsString hostname, uint16_t flags);
|
||||
|
|
|
@ -0,0 +1,268 @@
|
|||
/* 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/. */
|
||||
|
||||
#include "TestCommon.h"
|
||||
#include "TestHarness.h"
|
||||
#include "nsIUDPSocket.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsINetAddr.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
#include "prerror.h"
|
||||
|
||||
#define REQUEST 0x68656c6f
|
||||
#define RESPONSE 0x6f6c6568
|
||||
|
||||
#define EXPECT_SUCCESS(rv, ...) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (NS_FAILED(rv)) { \
|
||||
fail(__VA_ARGS__); \
|
||||
return false; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
|
||||
#define EXPECT_FAILURE(rv, ...) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (NS_SUCCEEDED(rv)) { \
|
||||
fail(__VA_ARGS__); \
|
||||
return false; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define REQUIRE_EQUAL(a, b, ...) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (a != b) { \
|
||||
fail(__VA_ARGS__); \
|
||||
return false; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
enum TestPhase {
|
||||
TEST_OUTPUT_STREAM,
|
||||
TEST_SEND_API,
|
||||
TEST_NONE
|
||||
};
|
||||
|
||||
static TestPhase phase = TEST_NONE;
|
||||
|
||||
static bool CheckMessageContent(nsIUDPMessage *aMessage, uint32_t aExpectedContent)
|
||||
{
|
||||
nsCString data;
|
||||
aMessage->GetData(data);
|
||||
|
||||
const char* buffer = data.get();
|
||||
uint32_t len = data.Length();
|
||||
|
||||
uint32_t input = 0;
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
input += buffer[i] << (8 * i);
|
||||
}
|
||||
|
||||
if (len != sizeof(uint32_t) || input != aExpectedContent)
|
||||
{
|
||||
fail("Request 0x%x received, expected 0x%x", input, aExpectedContent);
|
||||
return false;
|
||||
} else {
|
||||
passed("Request 0x%x received as expected", input);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* UDPClientListener: listens for incomming UDP packets
|
||||
*/
|
||||
class UDPClientListener : public nsIUDPSocketListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSOCKETLISTENER
|
||||
virtual ~UDPClientListener();
|
||||
nsresult mResult;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(UDPClientListener, nsIUDPSocketListener)
|
||||
|
||||
UDPClientListener::~UDPClientListener()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPClientListener::OnPacketReceived(nsIUDPSocket* socket, nsIUDPMessage* message)
|
||||
{
|
||||
mResult = NS_OK;
|
||||
|
||||
uint16_t port;
|
||||
nsCString ip;
|
||||
nsCOMPtr<nsINetAddr> fromAddr;
|
||||
message->GetFromAddr(getter_AddRefs(fromAddr));
|
||||
fromAddr->GetPort(&port);
|
||||
fromAddr->GetAddress(ip);
|
||||
passed("Packet received on client from %s:%d", ip.get(), port);
|
||||
|
||||
if (TEST_SEND_API == phase && CheckMessageContent(message, REQUEST)) {
|
||||
uint32_t count;
|
||||
const uint32_t data = RESPONSE;
|
||||
printf("*** Attempting to write response 0x%x to server by SendWithAddr...\n", RESPONSE);
|
||||
mResult = socket->SendWithAddr(fromAddr, (const uint8_t*)&data,
|
||||
sizeof(uint32_t), &count);
|
||||
if (mResult == NS_OK && count == sizeof(uint32_t)) {
|
||||
passed("Response written");
|
||||
} else {
|
||||
fail("Response written");
|
||||
}
|
||||
} else if (TEST_OUTPUT_STREAM != phase || !CheckMessageContent(message, RESPONSE)) {
|
||||
mResult = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Notify thread
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPClientListener::OnStopListening(nsIUDPSocket*, nsresult)
|
||||
{
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* UDPServerListener: listens for incomming UDP packets
|
||||
*/
|
||||
class UDPServerListener : public nsIUDPSocketListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSOCKETLISTENER
|
||||
|
||||
virtual ~UDPServerListener();
|
||||
|
||||
nsresult mResult;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(UDPServerListener, nsIUDPSocketListener)
|
||||
|
||||
UDPServerListener::~UDPServerListener()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPServerListener::OnPacketReceived(nsIUDPSocket* socket, nsIUDPMessage* message)
|
||||
{
|
||||
mResult = NS_OK;
|
||||
|
||||
uint16_t port;
|
||||
nsCString ip;
|
||||
nsCOMPtr<nsINetAddr> fromAddr;
|
||||
message->GetFromAddr(getter_AddRefs(fromAddr));
|
||||
fromAddr->GetPort(&port);
|
||||
fromAddr->GetAddress(ip);
|
||||
passed("Packet received on server from %s:%d", ip.get(), port);
|
||||
|
||||
if (TEST_OUTPUT_STREAM == phase && CheckMessageContent(message, REQUEST))
|
||||
{
|
||||
nsCOMPtr<nsIOutputStream> outstream;
|
||||
message->GetOutputStream(getter_AddRefs(outstream));
|
||||
|
||||
uint32_t count;
|
||||
const uint32_t data = RESPONSE;
|
||||
printf("*** Attempting to write response 0x%x to client by OutputStream...\n", RESPONSE);
|
||||
mResult = outstream->Write((const char*)&data, sizeof(uint32_t), &count);
|
||||
|
||||
if (mResult == NS_OK && count == sizeof(uint32_t)) {
|
||||
passed("Response written");
|
||||
} else {
|
||||
fail("Response written");
|
||||
}
|
||||
} else if (TEST_SEND_API != phase || !CheckMessageContent(message, RESPONSE)) {
|
||||
mResult = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPServerListener::OnStopListening(nsIUDPSocket*, nsresult)
|
||||
{
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**** Main ****/
|
||||
int
|
||||
main(int32_t argc, char *argv[])
|
||||
{
|
||||
nsresult rv;
|
||||
ScopedXPCOM xpcom("UDP ServerSocket");
|
||||
if (xpcom.failed())
|
||||
return -1;
|
||||
|
||||
// Create UDPSocket
|
||||
nsCOMPtr<nsIUDPSocket> server, client;
|
||||
server = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
client = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
|
||||
// Create UDPServerListener to process UDP packets
|
||||
nsCOMPtr<UDPServerListener> serverListener = new UDPServerListener();
|
||||
|
||||
// Bind server socket to 127.0.0.1
|
||||
rv = server->Init(0, true);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
int32_t serverPort;
|
||||
server->GetPort(&serverPort);
|
||||
server->AsyncListen(serverListener);
|
||||
|
||||
// Bind clinet on arbitrary port
|
||||
nsCOMPtr<UDPClientListener> clientListener = new UDPClientListener();
|
||||
client->Init(0, true);
|
||||
client->AsyncListen(clientListener);
|
||||
|
||||
// Write data to server
|
||||
uint32_t count;
|
||||
const uint32_t data = REQUEST;
|
||||
|
||||
phase = TEST_OUTPUT_STREAM;
|
||||
rv = client->Send(NS_LITERAL_CSTRING("127.0.0.1"), serverPort, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Request written by Send");
|
||||
|
||||
// Wait for server
|
||||
PumpEvents();
|
||||
NS_ENSURE_SUCCESS(serverListener->mResult, -1);
|
||||
|
||||
// Read response from server
|
||||
NS_ENSURE_SUCCESS(clientListener->mResult, -1);
|
||||
|
||||
mozilla::net::NetAddr clientAddr;
|
||||
rv = client->GetAddress(&clientAddr);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
|
||||
phase = TEST_SEND_API;
|
||||
rv = server->SendWithAddress(&clientAddr, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Request written by SendWithAddress");
|
||||
|
||||
// Wait for server
|
||||
PumpEvents();
|
||||
NS_ENSURE_SUCCESS(serverListener->mResult, -1);
|
||||
|
||||
// Read response from server
|
||||
NS_ENSURE_SUCCESS(clientListener->mResult, -1);
|
||||
|
||||
// Close server
|
||||
printf("*** Attempting to close server ...\n");
|
||||
server->Close();
|
||||
client->Close();
|
||||
PumpEvents();
|
||||
passed("Server closed");
|
||||
|
||||
return 0; // failure is a non-zero return
|
||||
}
|
|
@ -53,6 +53,6 @@ SOURCES += [
|
|||
|
||||
CPP_UNIT_TESTS += [
|
||||
'TestSTSParser.cpp',
|
||||
'TestUDPServerSocket.cpp',
|
||||
'TestUDPSocket.cpp',
|
||||
]
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@
|
|||
"dom/network/tests/test_network_basics.html": "",
|
||||
"dom/permission/tests/test_permission_basics.html": "",
|
||||
"dom/mobilemessage/tests/test_sms_basics.html": "Bug 909036",
|
||||
"dom/media/tests/ipc/test_ipc.html":"bug 910661",
|
||||
"dom/tests/mochitest/ajax/jquery/test_jQuery.html": "bug 775227",
|
||||
"dom/tests/mochitest/ajax/offline/test_simpleManifest.html": "TIMED_OUT",
|
||||
"dom/tests/mochitest/ajax/offline/test_updatingManifest.html": "TIMED_OUT",
|
||||
|
|
|
@ -320,6 +320,7 @@
|
|||
"dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html":"",
|
||||
"dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html":"",
|
||||
"dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"",
|
||||
"dom/media/tests/ipc/test_ipc.html":"nested ipc not working",
|
||||
|
||||
"dom/network/tests/test_networkstats_basics.html":"Will be fixed in bug 858005",
|
||||
"dom/permission/tests/test_permission_basics.html":"Bug 907770",
|
||||
|
|
|
@ -325,6 +325,7 @@
|
|||
"dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html":"",
|
||||
"dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html":"",
|
||||
"dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"",
|
||||
"dom/media/tests/ipc/test_ipc.html":"nested ipc not working",
|
||||
|
||||
"dom/network/tests/test_networkstats_basics.html":"Will be fixed in bug 858005",
|
||||
"dom/permission/tests/test_permission_basics.html":"https not working, bug 907770",
|
||||
|
|
Загрузка…
Ссылка в новой задаче