Bug 1172159 - [NFC] Introduce getFocusTabId function. r=allstars.chh, a=jocheng
authorKrzysztof Mioduszewski <kmioduszewski@gmail.com>
Wed, 17 Jun 2015 10:25:00 -0400
changeset 238647 14a1a46b54ab902504e5f8613fce8a4eed5eaa33
parent 238646 05fb211d4c6c60fba3964517f2218166a71f84a4
child 238648 3732db0c615dcb83b2683e56a5fae8dca57b6eb1
push id703
push userryanvm@gmail.com
push dateThu, 18 Jun 2015 20:21:07 +0000
treeherdermozilla-b2g37_v2_2@14a1a46b54ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars.chh, jocheng
bugs1172159
milestone37.0
Bug 1172159 - [NFC] Introduce getFocusTabId function. r=allstars.chh, a=jocheng
dom/nfc/gonk/Nfc.js
--- a/dom/nfc/gonk/Nfc.js
+++ b/dom/nfc/gonk/Nfc.js
@@ -165,38 +165,36 @@ XPCOMUtils.defineLazyGetter(this, "gMess
       Object.keys(this.peerTargets).forEach((appId) => {
         if (this.peerTargets[appId] === target) {
           delete this.peerTargets[appId];
         }
       });
     },
 
     notifyFocusApp: function notifyFocusApp(options) {
-      let target, tabId;
-      if (this.eventListeners[this.focusApp]) {
-        target = this.eventListeners[this.focusApp];
-        tabId = this.focusApp;
-      } else {
-        target = this.eventListeners[NFC.SYSTEM_APP_ID];
-        tabId = NFC.SYSTEM_APP_ID;
-      }
+      let tabId = this.getFocusTabId();
       options.tabId = tabId;
 
-      this.notifyDOMEvent(target, options);
+      this.notifyDOMEvent(this.eventListeners[tabId], options);
     },
 
     notifyDOMEvent: function notifyDOMEvent(target, options) {
       if (!target) {
         dump("invalid target");
         return;
       }
 
       target.sendAsyncMessage("NFC:DOMEvent", options);
     },
 
+    getFocusTabId: function getFocusTabId() {
+      return this.eventListeners[this.focusApp] ? this.focusApp
+                                                : NFC.SYSTEM_APP_ID;
+    },
+
     setFocusApp: function setFocusApp(id, isFocus) {
       // if calling setNFCFocus(true) on the browser-element which is already
       // focused, or calling setNFCFocus(false) on the browser-element which has
       // lost focus already, ignore.
       if (isFocus == (id == this.focusApp)) {
         return;
       }
 
@@ -245,23 +243,22 @@ XPCOMUtils.defineLazyGetter(this, "gMess
       }
       // Notify the content process immediately of the status
       message.target.sendAsyncMessage(message.name + "Response", respMsg);
     },
 
     notifyUserAcceptedP2P: function notifyUserAcceptedP2P(appId) {
       let target = this.peerTargets[appId];
       let sessionToken = SessionHelper.getCurrentP2PToken();
-      let isValid = (sessionToken != null) && (target != null);
-      if (!isValid) {
+      if (!sessionToken || !target) {
         debug("Peer already lost or " + appId + " is not a registered PeerReadytarget");
         return;
       }
 
-      this.notifyDOMEvent(target, {tabId: this.focusApp,
+      this.notifyDOMEvent(target, {tabId: this.getFocusTabId(),
                                    event: NFC.PEER_EVENT_READY,
                                    sessionToken: sessionToken});
     },
 
     callDefaultFoundHandler: function callDefaultFoundHandler(message) {
       let sysMsg = new NfcTechDiscoveredSysMsg(message.sessionToken,
                                                message.isP2P,
                                                message.records || null);