dom/activities/src/ActivityRequestHandler.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/activities/src/ActivityRequestHandler.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +const Ci = Components.interfaces;
    1.11 +const Cu = Components.utils;
    1.12 +
    1.13 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.14 +Cu.import("resource://gre/modules/Services.jsm");
    1.15 +
    1.16 +XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
    1.17 +                                   "@mozilla.org/childprocessmessagemanager;1",
    1.18 +                                   "nsISyncMessageSender");
    1.19 +
    1.20 +function debug(aMsg) {
    1.21 +  //dump("-- ActivityRequestHandler.js " + Date.now() + " : " + aMsg + "\n");
    1.22 +}
    1.23 +
    1.24 +/**
    1.25 +  * nsIDOMMozActivityRequestHandler implementation.
    1.26 +  */
    1.27 +
    1.28 +function ActivityRequestHandler() {
    1.29 +  debug("ActivityRequestHandler");
    1.30 +
    1.31 +  // When a system message of type 'activity' is emitted, it forces the
    1.32 +  // creation of an ActivityWrapper which in turns replace the default
    1.33 +  // system message callback. The newly created wrapper then create an
    1.34 +  // ActivityRequestHandler object.
    1.35 +}
    1.36 +
    1.37 +ActivityRequestHandler.prototype = {
    1.38 +  init: function arh_init(aWindow) {
    1.39 +    this._window = aWindow;
    1.40 +  },
    1.41 +
    1.42 +  __init: function arh___init(aId, aOptions) {
    1.43 +    this._id = aId;
    1.44 +    this._options = aOptions;
    1.45 +  },
    1.46 +
    1.47 +  get source() {
    1.48 +    // We need to clone this object because the this._options.data has
    1.49 +    // the type any in WebIDL which will cause the binding layer to pass
    1.50 +    // the value which is a COW unmodified to content.
    1.51 +    return Cu.cloneInto(this._options, this._window);
    1.52 +  },
    1.53 +
    1.54 +  postResult: function arh_postResult(aResult) {
    1.55 +    cpmm.sendAsyncMessage("Activity:PostResult", {
    1.56 +      "id": this._id,
    1.57 +      "result": aResult
    1.58 +    });
    1.59 +    Services.obs.notifyObservers(null, "activity-success", this._id);
    1.60 +  },
    1.61 +
    1.62 +  postError: function arh_postError(aError) {
    1.63 +    cpmm.sendAsyncMessage("Activity:PostError", {
    1.64 +      "id": this._id,
    1.65 +      "error": aError
    1.66 +    });
    1.67 +    Services.obs.notifyObservers(null, "activity-error", this._id);
    1.68 +  },
    1.69 +
    1.70 +  classID: Components.ID("{9326952a-dbe3-4d81-a51f-d9c160d96d6b}"),
    1.71 +
    1.72 +  QueryInterface: XPCOMUtils.generateQI([
    1.73 +    Ci.nsIDOMGlobalPropertyInitializer
    1.74 +  ])
    1.75 +}
    1.76 +
    1.77 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityRequestHandler]);

mercurial