// BEGIN FLOCK GPL
//
// Copyright Flock Inc. 2005-2009
// http://flock.com
//
// This file may be used under the terms of the
// GNU General Public License Version 2 or later (the "GPL"),
// http://www.gnu.org/licenses/gpl.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// END FLOCK GPL

const CC = Components.classes;
const CI = Components.interfaces;
const CU = Components.utils;
const CR = Components.results;

CU.import("resource:///modules/FlockXPCOMUtils.jsm");

const FM_CONTRACTID = "@flock.com/webpageapi;1";
const FM_CLASSID    = Components.ID("{e1a06c44-26a1-4765-93e4-6ec07f4c8af6}");
const FM_CLASSNAME  = "Flock Webpage API";

const MODULE_NAME = "Webpage API";

/*************************************************************************
 * Component: flockWebpageAPI
 *************************************************************************/

function flockWebpageAPI() {
  this.media = CC["@flock.com/media-webpageapi;1"]
               .getService(CI.flockIMediaWebpageAPI);
  this.people = CC["@flock.com/people-webpageapi;1"]
                .getService(CI.flockIPeopleWebpageAPI);

}

/*************************************************************************
 * flockWebpageAPI: XPCOM Component Creation
 *************************************************************************/

flockWebpageAPI.prototype = new FlockXPCOMUtils.genericComponent(
  FM_CLASSNAME,
  FM_CLASSID,
  FM_CONTRACTID,
  flockWebpageAPI,
  CI.nsIClassInfo.SINGLETON,
  [
    CI.flockIWebpageAPI,
    CI.nsISecurityCheckedComponent
  ]
);

flockWebpageAPI.prototype._xpcom_categories = [
  {
    category: "JavaScript global property",
    entry: "flock",
    value: FM_CONTRACTID
  }
];

/*************************************************************************
 * flockWebpageAPI: flockIWebpageAPI implementation
 *************************************************************************/

// attribute media: set in the constructor
// attribute people: set in the constructor

/*************************************************************************
 * flockWebpageAPI: nsISecurityChecked implementation
 *************************************************************************/

flockWebpageAPI.prototype.canCreateWrapper =
function canCreateWrapper(aIID) {
  return "AllAccess";
}

flockWebpageAPI.prototype.canCallMethod =
function canCallMethod(aIID, methodName) {
  return "NoAccess";
}

flockWebpageAPI.prototype.canGetProperty =
function canGetProperty(aIID, propertyName) {
  switch (propertyName) {
    case "media":
    case "people":
      return "AllAccess";
  }

  return "NoAccess";
}

flockWebpageAPI.prototype.canSetProperty =
function canSetProperty(aIID, propertyName) {
  return "NoAccess";
}

/*************************************************************************
 * XPCOM Support - Module Construction
 *************************************************************************/

// Create array of components.
var componentsArray = [flockWebpageAPI];

// Generate a module for XPCOM to find.
var NSGetModule = FlockXPCOMUtils.generateNSGetModule(MODULE_NAME,
                                                      componentsArray);
