mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Merge b2g-inbound to m-c
This commit is contained in:
commit
1a896a9140
@ -1,4 +1,4 @@
|
||||
{
|
||||
"revision": "53c6a2b0bf4c238d39ee0096b79d911aec2de0fc",
|
||||
"revision": "fe012cdbca542f414a72b0cba9cfb50a4aaf62ae",
|
||||
"repo_path": "/integration/gaia-central"
|
||||
}
|
||||
|
@ -31,6 +31,9 @@
|
||||
#ifdef MOZ_B2G_RIL
|
||||
#include "mozilla/ipc/Ril.h"
|
||||
#endif
|
||||
#ifdef MOZ_NFC
|
||||
#include "mozilla/ipc/Nfc.h"
|
||||
#endif
|
||||
#include "mozilla/ipc/KeyStore.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsCxPusher.h"
|
||||
@ -275,6 +278,10 @@ SystemWorkerManager::Shutdown()
|
||||
RilConsumer::Shutdown();
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_NFC
|
||||
NfcConsumer::Shutdown();
|
||||
#endif
|
||||
|
||||
StopNetd();
|
||||
mNetdWorker = nullptr;
|
||||
|
||||
@ -361,6 +368,28 @@ SystemWorkerManager::RegisterRilWorker(unsigned int aClientId,
|
||||
#endif // MOZ_B2G_RIL
|
||||
}
|
||||
|
||||
nsresult
|
||||
SystemWorkerManager::RegisterNfcWorker(const JS::Value& aWorker,
|
||||
JSContext* aCx)
|
||||
{
|
||||
#ifndef MOZ_NFC
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#else
|
||||
NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(aWorker), NS_ERROR_UNEXPECTED);
|
||||
|
||||
JSAutoCompartment ac(aCx, JSVAL_TO_OBJECT(aWorker));
|
||||
|
||||
WorkerCrossThreadDispatcher* wctd =
|
||||
GetWorkerCrossThreadDispatcher(aCx, aWorker);
|
||||
if (!wctd) {
|
||||
NS_WARNING("Failed to GetWorkerCrossThreadDispatcher for nfc");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NfcConsumer::Register(wctd);
|
||||
#endif // MOZ_NFC
|
||||
}
|
||||
|
||||
nsresult
|
||||
SystemWorkerManager::InitNetd(JSContext *cx)
|
||||
{
|
||||
|
@ -7,10 +7,13 @@
|
||||
/**
|
||||
* Information about networks that is exposed to network manager API consumers.
|
||||
*/
|
||||
[scriptable, builtinclass, uuid(02166330-2ff6-4ea5-895a-693c0c2b4c1f)]
|
||||
[scriptable, builtinclass, uuid(a9ea96a0-407d-11e3-aa6e-0800200c9a66)]
|
||||
interface nsISystemWorkerManager : nsISupports
|
||||
{
|
||||
[implicit_jscontext]
|
||||
void registerRilWorker(in unsigned long aClientId,
|
||||
in jsval aWorker);
|
||||
|
||||
[implicit_jscontext]
|
||||
void registerNfcWorker(in jsval aWorker);
|
||||
};
|
||||
|
@ -17,7 +17,10 @@ if CONFIG['MOZ_B2G_RIL']:
|
||||
if CONFIG['MOZ_B2G_BT_BLUEZ']:
|
||||
DIRS += ['dbus']
|
||||
|
||||
if CONFIG['MOZ_B2G_RIL'] or CONFIG['MOZ_B2G_BT'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
||||
if CONFIG['MOZ_NFC']:
|
||||
DIRS += ['nfc']
|
||||
|
||||
if CONFIG['MOZ_B2G_RIL'] or CONFIG['MOZ_B2G_BT'] or CONFIG['MOZ_NFC'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
||||
DIRS += ['unixsocket']
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
||||
|
187
ipc/nfc/Nfc.cpp
187
ipc/nfc/Nfc.cpp
@ -4,10 +4,11 @@
|
||||
* 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 <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
/* Copyright © 2013, Deutsche Telekom, Inc. */
|
||||
|
||||
#include "mozilla/ipc/Nfc.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
@ -21,7 +22,6 @@
|
||||
|
||||
#include "jsfriendapi.h"
|
||||
#include "nsThreadUtils.h" // For NS_IsMainThread.
|
||||
#include "Nfc.h"
|
||||
|
||||
USING_WORKERS_NAMESPACE
|
||||
using namespace mozilla::ipc;
|
||||
@ -32,12 +32,118 @@ const char* NFC_SOCKET_NAME = "/dev/socket/nfcd";
|
||||
|
||||
// Network port to connect to for adb forwarded sockets when doing
|
||||
// desktop development.
|
||||
const uint32_t NFCD_TEST_PORT = 6400;
|
||||
const uint32_t NFC_TEST_PORT = 6400;
|
||||
|
||||
class DispatchNfcEvent : public WorkerTask
|
||||
nsRefPtr<mozilla::ipc::NfcConsumer> sNfcConsumer;
|
||||
|
||||
class ConnectWorkerToNFC : public WorkerTask
|
||||
{
|
||||
public:
|
||||
DispatchNfcEvent(UnixSocketRawData* aMessage)
|
||||
ConnectWorkerToNFC()
|
||||
{ }
|
||||
|
||||
virtual bool RunTask(JSContext* aCx);
|
||||
};
|
||||
|
||||
class SendNfcSocketDataTask : public nsRunnable
|
||||
{
|
||||
public:
|
||||
SendNfcSocketDataTask(UnixSocketRawData* aRawData)
|
||||
: mRawData(aRawData)
|
||||
{ }
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!sNfcConsumer ||
|
||||
sNfcConsumer->GetConnectionStatus() != SOCKET_CONNECTED) {
|
||||
// Probably shuting down.
|
||||
delete mRawData;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
sNfcConsumer->SendSocketData(mRawData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
UnixSocketRawData* mRawData;
|
||||
};
|
||||
|
||||
bool
|
||||
PostToNFC(JSContext* aCx,
|
||||
unsigned aArgc,
|
||||
JS::Value* aArgv)
|
||||
{
|
||||
NS_ASSERTION(!NS_IsMainThread(), "Expecting to be on the worker thread");
|
||||
|
||||
if (aArgc != 1) {
|
||||
JS_ReportError(aCx, "Expecting one argument with the NFC message");
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::Value v = JS_ARGV(aCx, aArgv)[0];
|
||||
|
||||
JSAutoByteString abs;
|
||||
void* data;
|
||||
size_t size;
|
||||
if (JSVAL_IS_STRING(v)) {
|
||||
JSString* str = JSVAL_TO_STRING(v);
|
||||
if (!abs.encodeUtf8(aCx, str)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data = abs.ptr();
|
||||
size = abs.length();
|
||||
} else if (!JSVAL_IS_PRIMITIVE(v)) {
|
||||
JSObject* obj = JSVAL_TO_OBJECT(v);
|
||||
if (!JS_IsTypedArrayObject(obj)) {
|
||||
JS_ReportError(aCx, "Object passed in wasn't a typed array");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t type = JS_GetArrayBufferViewType(obj);
|
||||
if (type != js::ArrayBufferView::TYPE_INT8 &&
|
||||
type != js::ArrayBufferView::TYPE_UINT8 &&
|
||||
type != js::ArrayBufferView::TYPE_UINT8_CLAMPED) {
|
||||
JS_ReportError(aCx, "Typed array data is not octets");
|
||||
return false;
|
||||
}
|
||||
|
||||
size = JS_GetTypedArrayByteLength(obj);
|
||||
data = JS_GetArrayBufferViewData(obj);
|
||||
} else {
|
||||
JS_ReportError(aCx,
|
||||
"Incorrect argument. Expecting a string or a typed array");
|
||||
return false;
|
||||
}
|
||||
|
||||
UnixSocketRawData* raw = new UnixSocketRawData(data, size);
|
||||
|
||||
nsRefPtr<SendNfcSocketDataTask> task =
|
||||
new SendNfcSocketDataTask(raw);
|
||||
NS_DispatchToMainThread(task);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ConnectWorkerToNFC::RunTask(JSContext* aCx)
|
||||
{
|
||||
// Set up the postNFCMessage on the function for worker -> NFC thread
|
||||
// communication.
|
||||
NS_ASSERTION(!NS_IsMainThread(), "Expecting to be on the worker thread");
|
||||
NS_ASSERTION(!JS_IsRunning(aCx), "Are we being called somehow?");
|
||||
JSObject* workerGlobal = JS::CurrentGlobalOrNull(aCx);
|
||||
|
||||
return !!JS_DefineFunction(aCx, workerGlobal,
|
||||
"postNfcMessage", PostToNFC, 1, 0);
|
||||
}
|
||||
|
||||
class DispatchNFCEvent : public WorkerTask
|
||||
{
|
||||
public:
|
||||
DispatchNFCEvent(UnixSocketRawData* aMessage)
|
||||
: mMessage(aMessage)
|
||||
{ }
|
||||
|
||||
@ -48,18 +154,17 @@ private:
|
||||
};
|
||||
|
||||
bool
|
||||
DispatchNfcEvent::RunTask(JSContext *aCx)
|
||||
DispatchNFCEvent::RunTask(JSContext* aCx)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "DispatchNfcEvent on main thread");
|
||||
MOZ_ASSERT(aCx);
|
||||
|
||||
JSObject* obj = JS::CurrentGlobalOrNull(aCx);
|
||||
|
||||
JSObject* array = JS_NewUint8Array(aCx, mMessage->mSize);
|
||||
if (!array) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(JS_GetArrayBufferViewData(array), mMessage->mData, mMessage->mSize);
|
||||
jsval argv[] = { OBJECT_TO_JSVAL(array) };
|
||||
JS::Value argv[] = { OBJECT_TO_JSVAL(array) };
|
||||
return JS_CallFunctionName(aCx, obj, "onNfcMessage", NS_ARRAY_LENGTH(argv),
|
||||
argv, argv);
|
||||
}
|
||||
@ -67,7 +172,9 @@ DispatchNfcEvent::RunTask(JSContext *aCx)
|
||||
class NfcConnector : public mozilla::ipc::UnixSocketConnector
|
||||
{
|
||||
public:
|
||||
NfcConnector() {}
|
||||
NfcConnector()
|
||||
{}
|
||||
|
||||
virtual ~NfcConnector()
|
||||
{}
|
||||
|
||||
@ -97,7 +204,7 @@ NfcConnector::Create()
|
||||
#endif
|
||||
|
||||
if (fd < 0) {
|
||||
NS_WARNING("Could not open Nfc socket!");
|
||||
NS_WARNING("Could not open nfc socket!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -133,7 +240,7 @@ NfcConnector::CreateAddr(bool aIsServer,
|
||||
break;
|
||||
case AF_INET:
|
||||
aAddr.in.sin_family = af;
|
||||
aAddr.in.sin_port = htons(NFCD_TEST_PORT);
|
||||
aAddr.in.sin_port = htons(NFC_TEST_PORT);
|
||||
aAddr.in.sin_addr.s_addr = htons(INADDR_LOOPBACK);
|
||||
aAddrSize = sizeof(sockaddr_in);
|
||||
break;
|
||||
@ -142,7 +249,6 @@ NfcConnector::CreateAddr(bool aIsServer,
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool
|
||||
@ -168,7 +274,6 @@ NfcConnector::GetSocketAddr(const sockaddr_any& aAddr,
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
@ -176,24 +281,46 @@ NfcConsumer::NfcConsumer(WorkerCrossThreadDispatcher* aDispatcher)
|
||||
: mDispatcher(aDispatcher)
|
||||
, mShutdown(false)
|
||||
{
|
||||
ConnectSocket(new NfcConnector(), NFC_SOCKET_NAME);
|
||||
mAddress = NFC_SOCKET_NAME;
|
||||
|
||||
ConnectSocket(new NfcConnector(), mAddress.get());
|
||||
}
|
||||
|
||||
nsresult
|
||||
NfcConsumer::Register(WorkerCrossThreadDispatcher* aDispatcher)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (sNfcConsumer) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsRefPtr<ConnectWorkerToNFC> connection = new ConnectWorkerToNFC();
|
||||
if (!aDispatcher->PostTask(connection)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Now that we're set up, connect ourselves to the NFC thread.
|
||||
sNfcConsumer = new NfcConsumer(aDispatcher);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
NfcConsumer::Shutdown()
|
||||
{
|
||||
mShutdown = true;
|
||||
CloseSocket();
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
sNfcConsumer->mShutdown = true;
|
||||
sNfcConsumer->CloseSocket();
|
||||
sNfcConsumer = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
NfcConsumer::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
#ifdef DEBUG
|
||||
LOG("ReceiveSocketData\n");
|
||||
#endif
|
||||
nsRefPtr<DispatchNfcEvent> dre(new DispatchNfcEvent(aMessage.forget()));
|
||||
|
||||
nsRefPtr<DispatchNFCEvent> dre(new DispatchNFCEvent(aMessage.forget()));
|
||||
mDispatcher->PostTask(dre);
|
||||
}
|
||||
|
||||
@ -201,26 +328,22 @@ void
|
||||
NfcConsumer::OnConnectSuccess()
|
||||
{
|
||||
// Nothing to do here.
|
||||
LOG("Socket open for Nfc\n");
|
||||
LOG("NFC: %s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void
|
||||
NfcConsumer::OnConnectError()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
LOG("%s\n", __FUNCTION__);
|
||||
#endif
|
||||
LOG("NFC: %s\n", __FUNCTION__);
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
void
|
||||
NfcConsumer::OnDisconnect()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
LOG("%s\n", __FUNCTION__);
|
||||
#endif
|
||||
LOG("NFC: %s\n", __FUNCTION__);
|
||||
if (!mShutdown) {
|
||||
ConnectSocket(new NfcConnector(), NFC_SOCKET_NAME, 1000);
|
||||
ConnectSocket(new NfcConnector(), mAddress.get(), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
* 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/. */
|
||||
|
||||
/* Copyright © 2013, Deutsche Telekom, Inc. */
|
||||
|
||||
#ifndef mozilla_ipc_Nfc_h
|
||||
#define mozilla_ipc_Nfc_h 1
|
||||
|
||||
@ -16,10 +18,14 @@ namespace ipc {
|
||||
class NfcConsumer : public mozilla::ipc::UnixSocketConsumer
|
||||
{
|
||||
public:
|
||||
NfcConsumer(mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
|
||||
virtual ~NfcConsumer() { }
|
||||
void Shutdown();
|
||||
|
||||
static nsresult Register(mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
|
||||
static void Shutdown();
|
||||
|
||||
private:
|
||||
NfcConsumer(mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
|
||||
|
||||
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage);
|
||||
|
||||
virtual void OnConnectSuccess();
|
||||
@ -28,6 +34,7 @@ private:
|
||||
|
||||
private:
|
||||
nsRefPtr<mozilla::dom::workers::WorkerCrossThreadDispatcher> mDispatcher;
|
||||
nsCString mAddress;
|
||||
bool mShutdown;
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
# 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/.
|
||||
|
||||
if CONFIG['MOZ_B2G_NFC']:
|
||||
if CONFIG['MOZ_NFC']:
|
||||
MODULE = 'ipc'
|
||||
EXPORTS.mozilla.ipc += [
|
||||
'Nfc.h',
|
||||
|
Loading…
Reference in New Issue
Block a user