// 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/people-webpageapi;1";
const FM_CLASSID    = Components.ID("{8d8420be-35fa-4c5d-8a7a-a940c3dfb26b}");
const FM_CLASSNAME  = "Flock People Webpage API";

const MODULE_NAME = "Media Webpage API";

/*************************************************************************
 * Component: flockPeopleWebpageAPI
 *************************************************************************/

function flockPeopleWebpageAPI() {
}

/*************************************************************************
 * flockPeopleWebpageAPI: XPCOM Component Creation
 *************************************************************************/

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

/*************************************************************************
 * flockPeopleWebpageAPI: private members
 *************************************************************************/

/*************************************************************************
 * flockPeopleWebpageAPI: flockIPeopleWebpageAPI implementation
 *************************************************************************/

flockPeopleWebpageAPI.prototype.open =
function flockPeopleWebpageAPI_open() {
  var wm = CC["@mozilla.org/appshell/window-mediator;1"]
           .getService(CI.nsIWindowMediator);
  var win = wm.getMostRecentWindow("navigator:browser");

  win.toggleSidebarWithMetric("flockPeopleSidebarBroadcaster",
                              "PeopleSidebar-Open",
                              null,
                              "MyWorldPeopleButton",
                              true);
}

/*************************************************************************
 * flockPeopleWebpageAPI: nsISecurityChecked implementation
 *************************************************************************/

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

flockPeopleWebpageAPI.prototype.canCallMethod =
function canCallMethod(aIID, methodName) {
  switch (methodName) {
    case "open":
      return "AllAccess";
  }

  return "NoAccess";
}

flockPeopleWebpageAPI.prototype.canGetProperty =
function canGetProperty(aIID, propertyName) {
  return "NoAccess";
}

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

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

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

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