diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index bc29f554e683..f6556682e4e3 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,15 +15,15 @@ - + - + - + @@ -134,7 +134,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index 293143a8403e..e3b020cbcc25 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,13 +19,13 @@ - - + + - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index adea45f3db44..14474d5a1338 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,10 +17,10 @@ - - + + - + @@ -135,7 +135,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index caf871c07842..08888d41f52a 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,15 +15,15 @@ - + - + - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index 27360dd2a953..4827166ff056 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,15 +15,15 @@ - + - + - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index 293143a8403e..e3b020cbcc25 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,13 +19,13 @@ - - + + - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 31edb485e14c..aff534fa3f39 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,15 +15,15 @@ - + - + - + @@ -125,7 +125,7 @@ - + @@ -146,7 +146,7 @@ - + diff --git a/b2g/config/flame/sources.xml b/b2g/config/flame/sources.xml index 5d81e7052983..bcb761159cfa 100644 --- a/b2g/config/flame/sources.xml +++ b/b2g/config/flame/sources.xml @@ -17,10 +17,10 @@ - - + + - + @@ -145,7 +145,7 @@ - + diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 8b45c417b7d9..1092f5cdac36 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "10dcd335d588997fc12845e9197de89228664f95", + "git_revision": "1b2f0a20ff4ada05b7d1f84a393bf15bda0e8406", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "f378c0a3ef97b44ddb7f71a7a65faddc391c4e0e", + "revision": "2545ffc0126d415f296eb375afd68bc4f6224030", "repo_path": "integration/gaia-central" } diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index 76d263dc296f..02c6310d3c1e 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,10 +17,10 @@ - - + + - + @@ -130,7 +130,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index 9d6745f0e1cf..ae8bf2db50eb 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,15 +15,15 @@ - + - + - + @@ -157,5 +157,5 @@ - + diff --git a/dom/camera/DOMCameraControl.cpp b/dom/camera/DOMCameraControl.cpp old mode 100644 new mode 100755 index e5ed9cc947a6..21f7c78f4586 --- a/dom/camera/DOMCameraControl.cpp +++ b/dom/camera/DOMCameraControl.cpp @@ -306,6 +306,8 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId, nsDOMCameraControl::~nsDOMCameraControl() { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); + /*invoke DOMMdediastream destroy*/ + Destroy(); } JSObject* diff --git a/dom/icc/Icc.cpp b/dom/icc/Icc.cpp index 93a7d01c7abd..dc3d6fa38b75 100644 --- a/dom/icc/Icc.cpp +++ b/dom/icc/Icc.cpp @@ -70,6 +70,10 @@ Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo) } } +Icc::~Icc() +{ +} + void Icc::Shutdown() { diff --git a/dom/icc/Icc.h b/dom/icc/Icc.h index 957d43966318..d34066899560 100644 --- a/dom/icc/Icc.h +++ b/dom/icc/Icc.h @@ -111,7 +111,7 @@ public: IMPL_EVENT_HANDLER(stksessionend) private: - ~Icc() {} + ~Icc(); bool mLive; uint32_t mClientId; diff --git a/dom/nfc/gonk/Nfc.js b/dom/nfc/gonk/Nfc.js index 036597327817..c8f9f6e432b9 100644 --- a/dom/nfc/gonk/Nfc.js +++ b/dom/nfc/gonk/Nfc.js @@ -498,17 +498,6 @@ let SessionHelper = { }; function Nfc() { - debug("Starting Nfc Service"); - - let nfcService = Cc["@mozilla.org/nfc/service;1"].getService(Ci.nsINfcService); - if (!nfcService) { - debug("No nfc service component available!"); - return; - } - - nfcService.start(this); - this.nfcService = nfcService; - gMessageManager.init(this); this.targetsByRequestId = {}; @@ -529,6 +518,39 @@ Nfc.prototype = { targetsByRequestId: null, + // temporary variables while NFC initialization is pending + pendingNfcService: null, + pendingMessageQueue: [], + + /** + * Start NFC service + */ + startNfcService: function startNfcService() { + debug("Starting Nfc Service"); + + let nfcService = + Cc["@mozilla.org/nfc/service;1"].getService(Ci.nsINfcService); + if (!nfcService) { + debug("No nfc service component available!"); + return false; + } + + nfcService.start(this); + this.pendingNfcService = nfcService; + + return true; + }, + + /** + * Shutdown NFC service + */ + shutdownNfcService : function shutdownNfcService() { + debug("Shutting down Nfc Service"); + + this.nfcService.shutdown(); + this.nfcService = null; + }, + /** * Send arbitrary message to Nfc service. * @@ -573,27 +595,23 @@ Nfc.prototype = { }, /** - * Send Error response to content. This is used only - * in case of discovering an error in message received from - * content process. + * Send Error response to content process. * * @param message * An nsIMessageListener's message parameter. + * @param errorMsg + * A string with an error message. */ - sendNfcErrorResponse: function sendNfcErrorResponse(message, errorCode) { + sendNfcErrorResponse: function sendNfcErrorResponse(message, errorMsg) { if (!message.target) { return; } let nfcMsgType = message.name + "Response"; - message.data.errorMsg = this.getErrorMessage(errorCode); + message.data.errorMsg = errorMsg; message.target.sendAsyncMessage(nfcMsgType, message.data); }, - getErrorMessage: function getErrorMessage(errorCode) { - return NFC.NFC_ERROR_MSG[errorCode]; - }, - /** * Process the incoming message from the NFC Service. */ @@ -604,7 +622,14 @@ Nfc.prototype = { message.type = message.rspType || message.ntfType; switch (message.type) { case NfcNotificationType.INITIALIZED: - // Do nothing. + this.nfcService = this.pendingNfcService; + // Send messages that have been queued up during initialization + // TODO: Bug 1141007: send error responses if the message + // indicates an error during initialization. + while (this.pendingMessageQueue.length) { + this.receiveMessage(this.pendingMessageQueue.shift()); + } + this.pendingNfcService = null; break; case NfcNotificationType.TECH_DISCOVERED: // Update the upper layers with a session token (alias) @@ -648,6 +673,9 @@ Nfc.prototype = { this.rfState = message.rfState; gMessageManager.onRFStateChanged(this.rfState); } + if (this.rfState == NFC.NFC_RF_STATE_IDLE) { + this.shutdownNfcService(); + } break; case NfcResponseType.READ_NDEF_RSP: // Fall through. case NfcResponseType.WRITE_NDEF_RSP: @@ -685,7 +713,8 @@ Nfc.prototype = { * Process a message from the gMessageManager. */ receiveMessage: function receiveMessage(message) { - // Return early if we don't need the NFC Service. + // Return early if we don't need the NFC Service. We won't start + // the NFC daemon here. switch (message.name) { case "NFC:QueryInfo": return {rfState: this.rfState}; @@ -693,6 +722,24 @@ Nfc.prototype = { break; } + // Start NFC Service if necessary. Messages are held in a + // queue while initialization is being performed. + if (!this.nfcService) { + if ((message.name == "NFC:ChangeRFState") && + (message.data.rfState != "idle") && + !this.pendingNfcService) { + this.startNfcService(); // error handled in next branch + } + if (this.pendingNfcService) { + this.pendingMessageQueue.push(message); + } else { + this.sendNfcErrorResponse(message, "NotInitialize"); + } + return; + } + + // NFC Service is running and we have a message for it. This + // is the case during normal operation. if (message.name != "NFC:ChangeRFState") { // Update the current sessionId before sending to the NFC service. message.data.sessionId = SessionHelper.getId(message.data.sessionToken); @@ -738,8 +785,14 @@ Nfc.prototype = { }, shutdown: function shutdown() { - this.nfcService.shutdown(); - this.nfcService = null; + // We shutdown before initialization has been completed. The + // pending messages will receive an error response. + while (this.pendingMessageQueue.length) { + this.sendNfcErrorResponse(this.pendingMessageQueue.shift(), "NotInitialize"); + } + if (this.nfcService) { + this.shutdownNfcService(); + } } }; diff --git a/dom/nfc/gonk/NfcService.cpp b/dom/nfc/gonk/NfcService.cpp index c539f38c8ce2..4d894740f7f3 100644 --- a/dom/nfc/gonk/NfcService.cpp +++ b/dom/nfc/gonk/NfcService.cpp @@ -4,11 +4,13 @@ #include "NfcService.h" #include +#include #include "mozilla/ModuleUtils.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/dom/NfcOptionsBinding.h" #include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/RootedDictionary.h" +#include "mozilla/unused.h" #include "nsAutoPtr.h" #include "nsString.h" #include "nsXULAppAPI.h" @@ -264,7 +266,6 @@ private: }; NfcService::NfcService() - : mConsumer(new NfcConsumer(this)) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!gNfcService); @@ -296,20 +297,42 @@ NfcService::FactoryCreate() NS_IMETHODIMP NfcService::Start(nsINfcGonkEventListener* aListener) { + static const char BASE_SOCKET_NAME[] = "nfcd"; + MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aListener); MOZ_ASSERT(!mThread); + MOZ_ASSERT(!mListenSocket); + + // If we could not cleanup properly before and an old + // instance of the daemon is still running, we kill it + // here. + unused << NS_WARN_IF(property_set("ctl.stop", "nfcd") < 0); + + mListener = aListener; + mHandler = new NfcMessageHandler(); + mConsumer = new NfcConsumer(this); + + mListenSocketName = BASE_SOCKET_NAME; + + mListenSocket = new NfcListenSocket(this); + + bool success = mListenSocket->Listen(new NfcConnector(), mConsumer); + if (!success) { + mConsumer = nullptr; + return NS_ERROR_FAILURE; + } nsresult rv = NS_NewNamedThread("NfcThread", getter_AddRefs(mThread)); if (NS_FAILED(rv)) { NS_WARNING("Can't create Nfc worker thread."); - Shutdown(); + mListenSocket->Close(); + mListenSocket = nullptr; + mConsumer->Shutdown(); + mConsumer = nullptr; return NS_ERROR_FAILURE; } - mListener = aListener; - mHandler = new NfcMessageHandler(); - return NS_OK; } @@ -323,7 +346,11 @@ NfcService::Shutdown() mThread = nullptr; } + mListenSocket->Close(); + mListenSocket = nullptr; + mConsumer->Shutdown(); + mConsumer = nullptr; return NS_OK; } @@ -370,6 +397,40 @@ NfcService::ReceiveSocketData(nsAutoPtr& aData) mThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL); } +void +NfcService::OnConnectSuccess(enum SocketType aSocketType) +{ + MOZ_ASSERT(NS_IsMainThread()); + + switch (aSocketType) { + case LISTEN_SOCKET: { + nsCString value("nfcd:-a "); + value.Append(mListenSocketName); + if (NS_WARN_IF(property_set("ctl.start", value.get()) < 0)) { + OnConnectError(STREAM_SOCKET); + } + } + break; + case STREAM_SOCKET: + /* nothing to do */ + break; + } +} + +void +NfcService::OnConnectError(enum SocketType aSocketType) +{ + MOZ_ASSERT(NS_IsMainThread()); + + Shutdown(); +} + +void +NfcService::OnDisconnect(enum SocketType aSocketType) +{ + MOZ_ASSERT(NS_IsMainThread()); +} + NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(NfcService, NfcService::FactoryCreate) diff --git a/dom/nfc/gonk/NfcService.h b/dom/nfc/gonk/NfcService.h index 71e359aefc4c..ba140633a055 100644 --- a/dom/nfc/gonk/NfcService.h +++ b/dom/nfc/gonk/NfcService.h @@ -29,8 +29,12 @@ public: void DispatchNfcEvent(const mozilla::dom::NfcEventOptions& aOptions); - virtual void - ReceiveSocketData(nsAutoPtr& aData) MOZ_OVERRIDE; + virtual void ReceiveSocketData( + nsAutoPtr& aData) MOZ_OVERRIDE; + + virtual void OnConnectSuccess(enum SocketType aSocketType) MOZ_OVERRIDE; + virtual void OnConnectError(enum SocketType aSocketType) MOZ_OVERRIDE; + virtual void OnDisconnect(enum SocketType aSocketType) MOZ_OVERRIDE; nsCOMPtr GetThread() { return mThread; @@ -42,8 +46,10 @@ private: nsCOMPtr mThread; nsCOMPtr mListener; + nsRefPtr mListenSocket; nsRefPtr mConsumer; nsAutoPtr mHandler; + nsCString mListenSocketName; }; } // namespace mozilla diff --git a/ipc/nfc/Nfc.cpp b/ipc/nfc/Nfc.cpp index 62b96d5ab564..3d032021768c 100644 --- a/ipc/nfc/Nfc.cpp +++ b/ipc/nfc/Nfc.cpp @@ -22,19 +22,12 @@ #include "jsfriendapi.h" #include "mozilla/ArrayUtils.h" -#include "mozilla/ipc/UnixSocketConnector.h" #include "nsThreadUtils.h" // For NS_IsMainThread. using namespace mozilla::ipc; namespace { -static const char NFC_SOCKET_NAME[] = "/dev/socket/nfcd"; - -// Network port to connect to for adb forwarded sockets when doing -// desktop development. -static const uint32_t NFC_TEST_PORT = 6400; - class SendNfcSocketDataTask MOZ_FINAL : public nsRunnable { public: @@ -62,37 +55,21 @@ private: nsAutoPtr mRawData; }; -class NfcConnector MOZ_FINAL : public mozilla::ipc::UnixSocketConnector -{ -public: - NfcConnector() - { } +} // anonymous namespace - int Create() MOZ_OVERRIDE; - bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) MOZ_OVERRIDE; - bool SetUp(int aFd) MOZ_OVERRIDE; - bool SetUpListenSocket(int aFd) MOZ_OVERRIDE; - void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) MOZ_OVERRIDE; -}; +namespace mozilla { +namespace ipc { + +// +// NfcConnector +// int NfcConnector::Create() { MOZ_ASSERT(!NS_IsMainThread()); - int fd = -1; - -#if defined(MOZ_WIDGET_GONK) - fd = socket(AF_LOCAL, SOCK_STREAM, 0); -#else - // If we can't hit a local loopback, fail later in connect. - fd = socket(AF_INET, SOCK_STREAM, 0); -#endif - + int fd = socket(AF_LOCAL, SOCK_STREAM, 0); if (fd < 0) { NS_WARNING("Could not open nfc socket!"); return -1; @@ -110,34 +87,23 @@ NfcConnector::CreateAddr(bool aIsServer, sockaddr_any& aAddr, const char* aAddress) { - // We never open nfc socket as server. - MOZ_ASSERT(!aIsServer); - uint32_t af; -#if defined(MOZ_WIDGET_GONK) - af = AF_LOCAL; -#else - af = AF_INET; -#endif - switch (af) { - case AF_LOCAL: - aAddr.un.sun_family = af; - if(strlen(aAddress) > sizeof(aAddr.un.sun_path)) { - NS_WARNING("Address too long for socket struct!"); - return false; - } - strcpy((char*)&aAddr.un.sun_path, aAddress); - aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1; - break; - case AF_INET: - aAddr.in.sin_family = af; - aAddr.in.sin_port = htons(NFC_TEST_PORT); - aAddr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - aAddrSize = sizeof(sockaddr_in); - break; - default: - NS_WARNING("Socket type not handled by connector!"); + static const size_t sNameOffset = 1; + + nsDependentCString socketName("nfcd"); + + size_t namesiz = socketName.Length() + 1; /* include trailing '\0' */ + + if ((sNameOffset + namesiz) > sizeof(aAddr.un.sun_path)) { + NS_WARNING("Address too long for socket struct!"); return false; } + + memset(aAddr.un.sun_path, '\0', sNameOffset); // abstract socket + memcpy(aAddr.un.sun_path + sNameOffset, socketName.get(), namesiz); + aAddr.un.sun_family = AF_UNIX; + + aAddrSize = offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; + return true; } @@ -162,26 +128,51 @@ NfcConnector::GetSocketAddr(const sockaddr_any& aAddr, MOZ_CRASH("This should never be called!"); } -} // anonymous namespace +// +// NfcListenSocket +// -namespace mozilla { -namespace ipc { +NfcListenSocket::NfcListenSocket(NfcSocketListener* aListener) + : mListener(aListener) +{ } + +void +NfcListenSocket::OnConnectSuccess() +{ + if (mListener) { + mListener->OnConnectSuccess(NfcSocketListener::LISTEN_SOCKET); + } +} + +void +NfcListenSocket::OnConnectError() +{ + if (mListener) { + mListener->OnConnectError(NfcSocketListener::LISTEN_SOCKET); + } +} + +void +NfcListenSocket::OnDisconnect() +{ + if (mListener) { + mListener->OnDisconnect(NfcSocketListener::LISTEN_SOCKET); + } +} + +// +// NfcConsumer +// NfcConsumer::NfcConsumer(NfcSocketListener* aListener) : mListener(aListener) - , mShutdown(false) -{ - mAddress = NFC_SOCKET_NAME; - - Connect(new NfcConnector(), mAddress.get()); -} +{ } void NfcConsumer::Shutdown() { MOZ_ASSERT(NS_IsMainThread()); - mShutdown = true; Close(); } @@ -209,23 +200,31 @@ NfcConsumer::ReceiveSocketData(nsAutoPtr& aData) void NfcConsumer::OnConnectSuccess() { - // Nothing to do here. CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); + + if (mListener) { + mListener->OnConnectSuccess(NfcSocketListener::STREAM_SOCKET); + } + // Nothing to do here. } void NfcConsumer::OnConnectError() { CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); - Close(); + + if (mListener) { + mListener->OnConnectError(NfcSocketListener::STREAM_SOCKET); + } } void NfcConsumer::OnDisconnect() { CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); - if (!mShutdown) { - Connect(new NfcConnector(), mAddress.get(), GetSuggestedConnectDelayMs()); + + if (mListener) { + mListener->OnDisconnect(NfcSocketListener::STREAM_SOCKET); } } diff --git a/ipc/nfc/Nfc.h b/ipc/nfc/Nfc.h index 8f0b9683fb5d..d45de8bb3790 100644 --- a/ipc/nfc/Nfc.h +++ b/ipc/nfc/Nfc.h @@ -9,7 +9,9 @@ #ifndef mozilla_ipc_Nfc_h #define mozilla_ipc_Nfc_h 1 +#include #include +#include namespace mozilla { namespace ipc { @@ -17,7 +19,46 @@ namespace ipc { class NfcSocketListener { public: + enum SocketType { + LISTEN_SOCKET, + STREAM_SOCKET + }; + virtual void ReceiveSocketData(nsAutoPtr& aData) = 0; + + virtual void OnConnectSuccess(enum SocketType aSocketType) = 0; + virtual void OnConnectError(enum SocketType aSocketType) = 0; + virtual void OnDisconnect(enum SocketType aSocketType) = 0; +}; + +class NfcListenSocket MOZ_FINAL : public mozilla::ipc::ListenSocket +{ +public: + NfcListenSocket(NfcSocketListener* aListener); + + void OnConnectSuccess() MOZ_OVERRIDE; + void OnConnectError() MOZ_OVERRIDE; + void OnDisconnect() MOZ_OVERRIDE; + +private: + NfcSocketListener* mListener; +}; + +class NfcConnector MOZ_FINAL : public mozilla::ipc::UnixSocketConnector +{ +public: + NfcConnector() + { } + + int Create() MOZ_OVERRIDE; + bool CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + sockaddr_any& aAddr, + const char* aAddress) MOZ_OVERRIDE; + bool SetUp(int aFd) MOZ_OVERRIDE; + bool SetUpListenSocket(int aFd) MOZ_OVERRIDE; + void GetSocketAddr(const sockaddr_any& aAddr, + nsAString& aAddrStr) MOZ_OVERRIDE; }; class NfcConsumer MOZ_FINAL : public mozilla::ipc::StreamSocket @@ -40,8 +81,6 @@ private: private: NfcSocketListener* mListener; - nsCString mAddress; - bool mShutdown; }; } // namespace ipc