Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const Cc = Components.classes; |
michael@0 | 8 | const Ci = Components.interfaces; |
michael@0 | 9 | const Cu = Components.utils; |
michael@0 | 10 | |
michael@0 | 11 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 12 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | XPCOMUtils.defineLazyServiceGetter(this, "cpmm", |
michael@0 | 15 | "@mozilla.org/childprocessmessagemanager;1", |
michael@0 | 16 | "nsISyncMessageSender"); |
michael@0 | 17 | |
michael@0 | 18 | function debug(aMsg) { |
michael@0 | 19 | //dump("-- ActivityWrapper.js " + Date.now() + " : " + aMsg + "\n"); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | /** |
michael@0 | 23 | * nsISystemMessagesWrapper implementation. Will return a |
michael@0 | 24 | * nsIDOMMozActivityRequestHandler |
michael@0 | 25 | */ |
michael@0 | 26 | function ActivityWrapper() { |
michael@0 | 27 | debug("ActivityWrapper"); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | ActivityWrapper.prototype = { |
michael@0 | 31 | wrapMessage: function wrapMessage(aMessage, aWindow) { |
michael@0 | 32 | debug("Wrapping " + JSON.stringify(aMessage)); |
michael@0 | 33 | |
michael@0 | 34 | // This message is useful to communicate that the activity message has been |
michael@0 | 35 | // properly received by the app. If the app will be killed, the |
michael@0 | 36 | // ActivitiesService will be able to fire an error and complete the |
michael@0 | 37 | // Activity workflow. |
michael@0 | 38 | cpmm.sendAsyncMessage("Activity:Ready", { id: aMessage.id }); |
michael@0 | 39 | |
michael@0 | 40 | let handler = new aWindow.ActivityRequestHandler(aMessage.id, aMessage.payload); |
michael@0 | 41 | |
michael@0 | 42 | // When the activity window is closed, fire an error to notify the activity |
michael@0 | 43 | // caller of the situation. |
michael@0 | 44 | // We don't need to check whether the activity itself already sent |
michael@0 | 45 | // back something since ActivitiesService.jsm takes care of that. |
michael@0 | 46 | let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 47 | .getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 48 | let innerWindowID = util.currentInnerWindowID; |
michael@0 | 49 | |
michael@0 | 50 | let observer = { |
michael@0 | 51 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 52 | |
michael@0 | 53 | switch (aTopic) { |
michael@0 | 54 | case 'inner-window-destroyed': |
michael@0 | 55 | let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data; |
michael@0 | 56 | if (wId == innerWindowID) { |
michael@0 | 57 | debug("Closing activity window " + innerWindowID); |
michael@0 | 58 | Services.obs.removeObserver(observer, "inner-window-destroyed"); |
michael@0 | 59 | cpmm.sendAsyncMessage("Activity:PostError", |
michael@0 | 60 | { id: aMessage.id, |
michael@0 | 61 | error: "ActivityCanceled" |
michael@0 | 62 | }); |
michael@0 | 63 | } |
michael@0 | 64 | break; |
michael@0 | 65 | case 'activity-error': |
michael@0 | 66 | case 'activity-success': |
michael@0 | 67 | if (aData !== aMessage.id) { |
michael@0 | 68 | return; |
michael@0 | 69 | } |
michael@0 | 70 | Services.obs.removeObserver(observer, "activity-error"); |
michael@0 | 71 | Services.obs.removeObserver(observer, "activity-success"); |
michael@0 | 72 | let docshell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 73 | .getInterface(Ci.nsIWebNavigation); |
michael@0 | 74 | Services.obs.notifyObservers(docshell, "activity-done", aTopic); |
michael@0 | 75 | break; |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | Services.obs.addObserver(observer, "activity-error", false); |
michael@0 | 81 | Services.obs.addObserver(observer, "activity-success", false); |
michael@0 | 82 | Services.obs.addObserver(observer, "inner-window-destroyed", false); |
michael@0 | 83 | return handler; |
michael@0 | 84 | }, |
michael@0 | 85 | |
michael@0 | 86 | classID: Components.ID("{5430d6f9-32d6-4924-ba39-6b6d1b093cd6}"), |
michael@0 | 87 | QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper]) |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityWrapper]); |
michael@0 | 91 |