Bug 1200969 - Fix timing issue in PresentationRequestUIGlue. r=fabrice
authorSean Lin <selin@mozilla.com>
Thu, 03 Sep 2015 10:04:59 +0800
changeset 290213 c2ea7d896aeec3336c3cdbaf9f03b5786a228183
parent 290212 fc5121d149c6d8cdf4f384634e658065d20a0cca
child 290214 7b1ba1e20dd9c55cfc80cc1c553cafa90ce0b8f9
push id5107
push userjbruaroey@mozilla.com
push dateThu, 03 Sep 2015 23:22:31 +0000
reviewersfabrice
bugs1200969
milestone43.0a1
Bug 1200969 - Fix timing issue in PresentationRequestUIGlue. r=fabrice
b2g/components/PresentationRequestUIGlue.js
b2g/components/test/mochitest/presentation_ui_glue_handler_chrome.js
--- a/b2g/components/PresentationRequestUIGlue.js
+++ b/b2g/components/PresentationRequestUIGlue.js
@@ -1,14 +1,18 @@
 /* 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"
 
+function debug(aMsg) {
+  //dump("-*- PresentationRequestUIGlue: " + aMsg + "\n");
+}
+
 const { interfaces: Ci, utils: Cu, classes: Cc } = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
                                   "resource://gre/modules/SystemAppProxy.jsm");
 
@@ -25,37 +29,38 @@ function PresentationRequestUIGlue() {
   // Listen to the result for the opened iframe from front-end.
   SystemAppProxy.addEventListener("mozPresentationContentEvent", aEvent => {
     let detail = aEvent.detail;
 
     if (detail.type != "presentation-receiver-launched") {
       return;
     }
 
-    let sessionId = detail.sessionId;
+    let sessionId = detail.id;
     let resolver = this._resolvers[sessionId];
     if (!resolver) {
+      debug("No correspondent resolver for session ID: " + sessionId);
       return;
     }
 
     delete this._resolvers[sessionId];
     resolver(detail.frame);
   });
 }
 
 PresentationRequestUIGlue.prototype = {
 
   sendRequest: function(aUrl, aSessionId) {
-    SystemAppProxy._sendCustomEvent("mozPresentationChromeEvent",
-                                    { type: "presentation-launch-receiver",
-                                      url: aUrl,
-                                      id: aSessionId });
-
     return new Promise(function(aResolve, aReject) {
       this._resolvers[aSessionId] = aResolve;
+
+      SystemAppProxy._sendCustomEvent("mozPresentationChromeEvent",
+                                      { type: "presentation-launch-receiver",
+                                        url: aUrl,
+                                        id: aSessionId });
     }.bind(this));
   },
 
   classID: Components.ID("{ccc8a839-0b64-422b-8a60-fb2af0e376d0}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationRequestUIGlue])
 };
 
--- a/b2g/components/test/mochitest/presentation_ui_glue_handler_chrome.js
+++ b/b2g/components/test/mochitest/presentation_ui_glue_handler_chrome.js
@@ -23,13 +23,13 @@ addMessageListener('trigger-ui-glue', fu
   promise.then(function(aFrame){
     sendAsyncMessage('iframe-resolved', aFrame);
   });
 });
 
 addMessageListener('trigger-presentation-content-event', function(aData) {
   var detail = {
     type: 'presentation-receiver-launched',
-    sessionId: aData.sessionId,
+    id: aData.sessionId,
     frame: aData.frame
   };
   SystemAppProxy._sendCustomEvent('mozPresentationContentEvent', detail);
 });