const SERVICE_NAME = "Yoono Web API";
const SERVICE_CID = Components.ID("{51b3c79b-aa74-4785-917d-c1f8a47e5210}");
const SERVICE_CTRID = "@yoono.com/webapi;1";

const CC = Components.classes;
const CI = Components.interfaces;

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

//class constructor
function YoonoWebAPI() {
  Components.utils.import("resource://yoono/yoonoService.js");
  Components.utils.import("resource://yoono/yoonoYEXTIF.js");
  
  this.version = YOONO_YEXTIF.methods.getVersion(); // this works in desktop version too
  this._devicevm = YOONO_YEXTIF.methods.partnerPresent('deviceVM');
  this.brand = "yoono";
  if(this._devicevm) {
    this.brand = "devicevm";
  }
}

// class definition
YoonoWebAPI.prototype = {
  classDescription: SERVICE_NAME,
  classID: SERVICE_CID,
  contractID: SERVICE_CTRID,

  _xpcom_categories: [{
    category: "JavaScript global property",
    entry: "yoonoapi",
    value: SERVICE_CTRID
  }],

  QueryInterface: XPCOMUtils.generateQI([CI.nsISecurityCheckedComponent,
                                         CI.yoonoIWebAPI,
                                         CI.nsIClassInfo]),

  // nsIClassInfo

  getInterfaces: function(aCount) {
    var result = [CI.nsISecurityCheckedComponent,
                  CI.yoonoIWebAPI,
                  CI.nsIClassInfo];
    aCount.value = result.length;
    return result;
  },

  getHelperForLanguage: function(aLanguage) {
    return null;
  },

  // nsISecurityCheckedComponent

  canCreateWrapper: function(aIID) {
    return "AllAccess";
  },

  canCallMethod: function(aIID, methodName) {
    return "NoAccess";
  },

  canGetProperty: function(aIID, propertyName) {
    switch (propertyName) {
      case "version":
      case "brand":
        return "AllAccess";
    }
    return "NoAccess";
  },

  canSetProperty: function(aIID, propertyName) {
    return "NoAccess";
  }
};

/**
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
*/
if (XPCOMUtils.generateNSGetFactory)
    var NSGetFactory = XPCOMUtils.generateNSGetFactory([YoonoWebAPI]);
else
    var NSGetModule = XPCOMUtils.generateNSGetModule([YoonoWebAPI]);
