XPCOM Component attributes

This is a multi-part message in MIME format.
--------------010503070502060802010207
Content-Type: text/plain; charset=windows-1251; format=flowed
Content-Transfer-Encoding: 7bit

Hi mozilla developers!

I have created Firefox extension in javascript that makes global object 
called jsPrintSetup which is accessible from client's javascript.

All methods call works fine but when add attribute 'ATest' to my object 
and try to access it from client javascript (for example 
alert(jsPrintSetup.ATest);) firefox reports error:
Permission denied to get property Object.ATest
If I add line 
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
before access property of object all works.

Can I workaround this and ignore need from enabling UniversalXPConnect 
from client javascript?

Thank you in advance.


Regards,

Dimitar

PS: I have attached my idl and implementation file.

--------------010503070502060802010207
Content-Type: application/x-javascript;
 name="jsPrintSetup.js"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="jsPrintSetup.js"

//
//  jsPrintSetup 
//  	 Global object extending printing features from client-side JavaScript
//
//  Revision: 
//     $Id$ 
//
//  Copyright(c) 2009 EDA Ltd.
//

const kMODULE_NAME = "jsPrintSetup";
const kMODULE_CONTRACTID = "@edabg.com/jsprintsetup;1";
const kMODULE_CID = Components.ID("ec8030f7-c20a-464f-9b0e-13a3a9e97384");
const kMODULE_INTERFACE = Components.interfaces.jsPrintSetup;

function jsPrintSetup() { 
	this.printSettingsInterface = Components.interfaces.nsIPrintSettings;

	this.printSettingsService = 
		Components.classes["@mozilla.org/gfx/printsettings-service;1"]
				.getService(Components.interfaces.nsIPrintSettingsService);
//	this.printSettingsService = 
//		Components.classes["@mozilla.org/gfx/printsettings-service;1"]
//			.createInstance(Components.interfaces.nsIPrintSettingsService);

	this.printSettings = this.printSettingsService.newPrintSettings;
//		this.printSettingsService.globalPrintSettings
//			.QueryInterface(Components.interfaces.nsIPrintSettings);

	this.getPrintersList();                  
	this.setPrinter('');

	this.globalPaperSizeUnit = this.printSettingsService.globalPrintSettings.paperSizeUnit;
	this.paperSizeUnit = Components.interfaces.nsIPrintSettings.kPaperSizeMillimeters;
	
	this.globalPrintSettings = this.printSettingsService.globalPrintSettings.clone();
	 
	this.prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); 
}


jsPrintSetup.prototype = {
	mTest : 'ala bala',
// Alert and logging methods
	alert: function(msg){
		var promptService = 
			Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
				.getService(Components.interfaces.nsIPromptService);
		promptService.alert(null, "JS Print Setup",msg);	
	},

	log: function (msg) {
	  var consoleService = 
	    Components.classes["@mozilla.org/consoleservice;1"].
	               getService(Components.interfaces.nsIConsoleService);
	  consoleService.logStringMessage(msg);
	},

// Common private methods	
	getWindow: function () {
		var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
									.getService(Components.interfaces.nsIWindowMediator);
		return wm.getMostRecentWindow('navigator:browser');
	},
	
  getWebBrowserPrint: function (aWindow)
  {
    var contentWindow = aWindow || this.getWindow().content;
//		this.alert(contentWindow.frames.length);
//		if (contentWindow.frames.length)
//			contentWindow = contentWindow.frames[0]; 
    return contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                        .getInterface(Components.interfaces.nsIWebBrowserPrint);
  },	
	
/*
  getWebBrowserPrint: function ()
  {
//    var contentWindow = aWindow || window.content;
		var contentWindow = this.getWindow().content;
    	return contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                        .getInterface(Components.interfaces.nsIWebBrowserPrint);
  },
*/

// Common converting private methods 
	adjustValue : function (value, unitFrom, unitTo) {
		if (unitFrom != unitTo) {
			// Different Paper Size Units 
			if (unitTo == Components.interfaces.nsIPrintSettings.kPaperSizeInches)
				// value is in mm -> convert to inches
				return value / 25.4;
			else
				// value is in inches -> convert to mm
				return value * 25.4;
		} else
			return value;
	},
	
	// gets printer setting value and adjust it depending of units
	getValue : function (value) {
		// Here must be this.printSettings.paperSizeUnit, but actualy don't work properly
		// to work well we are using this.globalPrintSettings.paperSizeUnit
		return this.adjustValue(value, this.globalPrintSettings.paperSizeUnit, this.paperSizeUnit);
	},

	// sets printer setting value and adjust it depending of units
	setValue : function (value) {
		// Here must be this.printSettings.paperSizeUnit, but actualy don't work properly
		// to work well we are using this.globalPrintSettings.paperSizeUnit
		return this.adjustValue(value, this.paperSizeUnit, this.globalPrintSettings.paperSizeUnit);
	},

	// gets global printer setting value and adjust it depending of units
	getGlobalValue : function (value) {
		return this.adjustValue(value, this.globalPrintSettings.paperSizeUnit, this.paperSizeUnit);
	},

	// sets global printer setting value and adjust it depending of units
	setGlobalValue : function (value) {
		return this.adjustValue(value, this.paperSizeUnit, this.globalPrintSettings.paperSizeUnit);
	},

	// converts string to boolean
	toBool: function (value){
		return ((value == "true") || (value == "1")? true:false);
	},

	// convert scaling from percent to actual unit using from mozilla
	scalingConvert: function (scaling){
		if (scaling < 10.0) {
			scaling = 10.0;
		}
		if (scaling > 500.0) {
			scaling = 500.0;
		}
		scaling /= 100.0;
		
		return scaling;
	},
	
	// attribute manipulation methods
	get ATest() {return this.mTest; /*return this.printSettings.showPrintProgress;*/},
	set ATest(aTest) {return this.mTest = aTest;/*eturn this.printSettings.showPrintProgress = aShow;*/},
	
	// sets printer name and read its settings, if 	
	setPrinter: function(printerName){
		if (printerName) {
			// check if printer exist
			for (var i = 0, p_exist = false; (i < this.printerList.length) && !p_exist; i++)
				if (this.printerList[i] == printerName) p_exist = 1;
			if (!p_exist) {
				this.alert('Error: Printer \''+printerName+'\' doesn\'t exist!');
				return;
			}
		}
		this.printerName = (printerName? printerName:this.printSettingsService.defaultPrinterName);
		this.printSettings.printerName = this.printerName;
		// This is part from mozilla toolkit printUtils.js
		// First get any defaults from the printer 		
		this.printSettingsService.initPrintSettingsFromPrinter(this.printSettings.printerName, this.printSettings);
		// now augment them with any values from last time
		this.printSettingsService.initPrintSettingsFromPrefs(this.printSettings, true, this.printSettingsInterface.kInitSaveAll);

	/*	if (this.printSettingsService.defaultPrinterName != this.printerName)
			this.printSettingsService.defaultPrinterName = this.printerName;*/
	},
	
	// get current printer name 
	getPrinter: function(){
		return this.printerName;
	},
	
	// get list of available printers
	getPrintersList: function(){
		var printerEnumerator =
			Components.classes["@mozilla.org/gfx/printerenumerator;1"]
				.getService(Components.interfaces.nsIPrinterEnumerator)
				.printerNameList;
		this.printerList = new Array();
		var i = 0;
		while(printerEnumerator.hasMore())
			this.printerList[i++] = printerEnumerator.getNext();
		return this.printerList;	
	},

	//set current printer options
	setOption: function(option,value){
		switch(option){
			case 'orientation':
				this.printSettings.orientation = value;
				break;
			case 'marginTop':
				this.printSettings.marginTop = this.setValue(value);
				break;
			case 'marginLeft':
				this.printSettings.marginLeft = this.setValue(value);
				break;
			case 'marginRight':
				this.printSettings.marginRight = this.setValue(value);
				break;
			case 'marginBottom':
				this.printSettings.marginBottom = this.setValue(value);
				break;
			case 'shrinkToFit':
				this.printSettings.shrinkToFit = this.toBool(value);
				break;
			case 'paperData':
				this.printSettings.paperData = value;				
				break;				
			case 'numCopies':
				this.printSettings.numCopies = value;
				break;				
			case 'outputFormat':
				this.printSettings.outputFormat = value;				
				break;				
			case 'paperHeight':
				this.printSettings.paperHeight = value;				
				break;				
			case 'paperName':
				this.printSettings.paperName = value;				
				break;				
			case 'paperSizeType':
				this.printSettings.paperSizeType = value;				
				break;
			case 'paperSizeUnit':
				this.alert("The property paperSizeUnit is readonly!");
//				this.printSettings.paperSizeUnit = value;				
				break;			
			case 'paperWidth':
				this.printSettings.paperWidth = value;				
				break;								
			case 'scaling':
				this.printSettings.scaling = this.scalingConvert(value);
				break;
			case 'footerStrCenter':
				this.printSettings.footerStrCenter = value;
				break;
			case 'footerStrLeft':
				this.printSettings.footerStrLeft = value;
				break;
			case 'footerStrRight':
				this.printSettings.footerStrRight = value;
				break;
			case 'headerStrCenter':
				this.printSettings.headerStrCenter = value;
				break;
			case 'headerStrLeft':
				this.printSettings.headerStrLeft = value;
				break;
			case 'headerStrRight':
				this.printSettings.headerStrRight = value;
				break;
		}	 
		
	},

	// set global print options
	setGlobalOption: function(option,value){
		switch(option){
			case 'orientation':
				this.globalPrintSettings.orientation = value;
				break;
			case 'marginTop':
				this.globalPrintSettings.marginTop = this.setValue(value);
				break;
			case 'marginLeft':
				this.globalPrintSettings.marginLeft = this.setValue(value);
				break;
			case 'marginRight':
				this.globalPrintSettings.marginRight = this.setValue(value);
				break;
			case 'marginBottom':
				this.globalPrintSettings.marginBottom = this.setValue(value);
				break;
			case 'shrinkToFit':
				this.globalPrintSettings.shrinkToFit = this.toBool(value);
				break;
			case 'paperData':
				this.globalPrintSettings.paperData = value;				
				break;				
			case 'numCopies':
				this.globalPrintSettings.numCopies = value;
				break;				
			case 'outputFormat':
				this.globalPrintSettings.outputFormat = value;				
				break;				
			case 'paperHeight':
				this.globalPrintSettings.paperHeight = value;				
				break;				
			case 'paperName':
				this.globalPrintSettings.paperName = value;				
				break;				
			case 'paperSizeType':
				this.globalPrintSettings.paperSizeType = value;				
				break;
			case 'paperSizeUnit':
				this.alert("The Global property paperSizeUnit is readonly!");			
//				this.globalPrintSettings.paperSizeUnit = value;				
				break;				
			case 'paperWidth':
				this.globalPrintSettings.paperWidth = value;				
				break;								
			case 'scaling':
				this.globalPrintSettings.scaling = this.scalingConvert(value);
				break;
			case 'footerStrCenter':
				this.globalPrintSettings.footerStrCenter = value;
				break;
			case 'footerStrLeft':
				this.globalPrintSettings.footerStrLeft = value;
				break;
			case 'footerStrRight':
				this.globalPrintSettings.footerStrRight = value;
				break;
			case 'headerStrCenter':
				this.globalPrintSettings.headerStrCenter = value;
				break;
			case 'headerStrLeft':
				this.globalPrintSettings.headerStrLeft = value;
				break;
			case 'headerStrRight':
				this.globalPrintSettings.headerStrRight = value;
				break;
		}	 

	},	

	// get current printer options
 	getOption: function(option){
		this.prefSatus = null;	
		switch(option){
			case 'orientation':
				this.prefSatus = this.printSettings.orientation;
				break;
			case 'marginTop':
				this.prefSatus = this.getValue(this.printSettings.marginTop);
				break;
			case 'marginLeft':
				this.prefSatus = this.getValue(this.printSettings.marginLeft);
				break;
			case 'marginRight':
				this.prefSatus = this.getValue(this.printSettings.marginRight);
				break;
			case 'marginBottom':
				this.prefSatus = this.getValue(this.printSettings.marginBottom);
				break;
			case 'shrinkToFit':
				this.prefSatus = this.printSettings.shrinkToFit;
				break;
			case 'paperData':
				this.prefSatus = this.printSettings.paperData;				
				break;				
			case 'numCopies':
				this.prefSatus = this.printSettings.numCopies;				
				break;				
			case 'outputFormat':
				this.prefSatus = this.printSettings.outputFormat;				
				break;				
			case 'paperHeight':
				this.prefSatus = this.printSettings.paperHeight;				
				break;				
			case 'paperName':
				this.prefSatus = this.printSettings.paperName;				
				break;				
			case 'paperSizeType':
				this.prefSatus = this.printSettings.paperSizeType;				
				break;
			case 'paperSizeUnit':
				this.prefSatus = this.printSettings.paperSizeUnit;				
				break;				
			case 'paperWidth':
				this.prefSatus = this.printSettings.paperWidth;				
				break;												
			case 'scaling':
				this.prefSatus = this.printSettings.scaling;				
				break;			
			case 'footerStrCenter':
				this.prefSatus = this.printSettings.footerStrCenter;
				break;
			case 'footerStrLeft':
				this.prefSatus = this.printSettings.footerStrLeft;
				break;
			case 'footerStrRight':
				this.prefSatus = this.printSettings.footerStrRight;
				break;
			case 'headerStrCenter':
				this.prefSatus = this.printSettings.headerStrCenter;
				break;
			case 'headerStrLeft':
				this.prefSatus = this.printSettings.headerStrLeft;
				break;
			case 'headerStrRight':
				this.prefSatus = this.printSettings.headerStrRight;
				break;
			case 'pinterName':
				this.prefSatus = this.printSettings.printerName;
				break;
		}	 
		return this.prefSatus;
	},

	// get  global print options
 	getGlobalOption: function(option){
		this.prefSatus = null;	
		switch(option){
			case 'orientation':
				this.prefSatus = this.globalPrintSettings.orientation;
				break;
			case 'marginTop':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginTop);
				break;
			case 'marginLeft':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginLeft);
				break;
			case 'marginRight':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginRight);
				break;
			case 'marginBottom':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginBottom);
				break;
			case 'shrinkToFit':
				this.prefSatus = this.globalPrintSettings.shrinkToFit;
				break;
			case 'paperData':
				this.prefSatus = this.globalPrintSettings.paperData;				
				break;				
			case 'numCopies':
				this.prefSatus = this.globalPrintSettings.numCopies;				
				break;				
			case 'outputFormat':
				this.prefSatus = this.globalPrintSettings.outputFormat;				
				break;				
			case 'paperHeight':
				this.prefSatus = this.globalPrintSettings.paperHeight;				
				break;				
			case 'paperName':
				this.prefSatus = this.globalPrintSettings.paperName;				
				break;				
			case 'paperSizeType':
				this.prefSatus = this.globalPrintSettings.paperSizeType;				
				break;
			case 'paperSizeUnit':
				this.prefSatus = this.globalPrintSettings.paperSizeUnit;				
				break;				
			case 'paperWidth':
				this.prefSatus = this.globalPrintSettings.paperWidth;				
				break;												
			case 'scaling':
				this.prefSatus = this.globalPrintSettings.scaling;				
				break;			
			case 'footerStrCenter':
				this.prefSatus = this.globalPrintSettings.footerStrCenter;
				break;
			case 'footerStrLeft':
				this.prefSatus = this.globalPrintSettings.footerStrLeft;
				break;
			case 'footerStrRight':
				this.prefSatus = this.globalPrintSettings.footerStrRight;
				break;
			case 'headerStrCenter':
				this.prefSatus = this.globalPrintSettings.headerStrCenter;
				break;
			case 'headerStrLeft':
				this.prefSatus = this.globalPrintSettings.headerStrLeft;
				break;
			case 'headerStrRight':
				this.prefSatus = this.globalPrintSettings.headerStrRight;
				break;
			case 'pinterName':
				this.prefSatus = this.globalPrintSettings.printerName;
				break;
		}	 
		return this.prefSatus;

	},
//		
// All print configuration options can be found at
// http://kb.mozillazine.org/About:config_entries#Print..2A
//
	// set flag to display print progress true/false 	
	setShowPrintProgress: function (flag){
		this.prefManager.setBoolPref("print.show_print_progress", flag);
	},

	// get flag to display print progress
	getShowPrintProgress: function () {
		return this.prefManager.getBoolPref("print.print.show_print_progress");		
	},

	// set flag for silents print process (don't display print dialog)
	setSilentPrint: function (flag) {
		this.prefManager.setBoolPref("print.always_print_silent", flag);	
	},
	
	// get flag for silents print process (don't display print dialog)
	getSilentPrint: function (){
		return this.prefManager.getBoolPref("print.always_print_silent");	
	},
	
	//save  current printer settings to preferences
	saveOptions: function(flags){
      this.printSettingsService.savePrintSettingsToPrefs(this.printSettings, true, flags);
	},

	// save global print settings to preferences
	saveGlobalOptions: function(flags){
      this.printSettingsService.savePrintSettingsToPrefs(this.globalPrintSettings, true, flags);
	},
	
	// call print with current printer
	print: function() {
		var webBrowserPrint = this.getWebBrowserPrint(null);				
		webBrowserPrint.print(this.printSettings, null); //this.printSettings, null
	},

	printWindow: function(aWindow) {
		var webBrowserPrint = this.getWebBrowserPrint(aWindow);				
		webBrowserPrint.print(this.printSettings, null); //this.printSettings, null
	},

	printPreview: function() {
		this.alert("This version don't implement method printPreview! ");
	},
	 
	// refreshresh printer options
	refreshOptions: function(){
//		this.printSettings = this.printSettingsService.globalPrintSettings
//		.QueryInterface(Components.interfaces.nsIPrintSettings);
//		this.printSettings.printerName = this.printerName;

		// This is part from mozilla toolkit printUtils.js
		// First get any defaults from the printer 		
		this.printSettingsService.initPrintSettingsFromPrinter(this.printSettings.printerName, this.printSettings);
		// now augment them with any values from last time
		this.printSettingsService.initPrintSettingsFromPrefs(this.printSettings, true, this.printSettingsInterface.kInitSaveAll);	
	},

// Interface supporting methods	
  // nsISupports
  QueryInterface: function(iid) {
    if (!iid.equals(kMODULE_INTERFACE) &&
        !iid.equals(Components.interfaces.nsIClassInfo) &&
        !iid.equals(Components.interfaces.nsISupports)) {
      throw Components.results.NS_ERROR_NO_INTERFACE;
    }
    return this;
  },

  // nsIClassInfo
  flags: Components.interfaces.nsIClassInfo.DOM_OBJECT,

  // nsIClassInfo
  classDescription: kMODULE_NAME,

  // nsIClassInfo
  getInterfaces: function(count) {
    var interfaceList = [kMODULE_INTERFACE, Components.interfaces.nsIClassInfo];
    count.value = interfaceList.length;
    return interfaceList;
  },

  // nsIClassInfo
  getHelperForLanguage: function(count) { return null; }
};

// the end jsPrintSetup.property
var jsPrintSetupFactory = {};

jsPrintSetupFactory.createInstance = function (outer, iid) {
  if (outer !== null) {
    throw Components.results.NS_ERROR_NO_AGGREGATION;
  }
  if (!iid.equals(kMODULE_INTERFACE) &&
      !iid.equals(Components.interfaces.nsIClassInfo) &&
      !iid.equals(Components.interfaces.nsISupports)) {
    throw Components.results.NS_ERROR_NO_INTERFACE;
  }

  return new jsPrintSetup();
};

var jsPrintSetupModule = {};

jsPrintSetupModule.registerSelf = function (compMgr, fileSpec, location, type) {
  compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  compMgr.registerFactoryLocation(kMODULE_CID,
                                  kMODULE_NAME,
                                  kMODULE_CONTRACTID,
                                  fileSpec, 
                                  location, 
                                  type);

  var catman = Components.classes["@mozilla.org/categorymanager;1"].
                          getService(Components.interfaces.nsICategoryManager);
  catman.addCategoryEntry("JavaScript global property",
                          "jsPrintSetup",
                          kMODULE_CONTRACTID,
                          true,
                          true);
};

jsPrintSetupModule.getClassObject = function (compMgr, cid, iid) {
  if (!cid.equals(kMODULE_CID)) {
    throw Components.results.NS_ERROR_NO_INTERFACE;
  }
  if (!iid.equals(Components.interfaces.nsIFactory)) {
    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  }
  return jsPrintSetupFactory;
};

jsPrintSetupModule.canUnload = function (compMgr) {
  return true;
};

function NSGetModule(compMgr, fileSpec) {
  return jsPrintSetupModule;
}

--------------010503070502060802010207
Content-Type: text/plain;
 name="jsPrintSetup.idl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="jsPrintSetup.idl"

//
//  jsPrintSetup interface 
//  	 Global object extending printing features from client-side JavaScript
//
//  Revision: 
//     $Id$ 
//
//  Copyright(c) 2009 EDA Ltd.
//

#include "nsISupports.idl"
#include "nsIDOMHTMLDocument.idl"
#include "nsIPrintSettings.idl"
// #include "nsIDOMWindow.idl"

interface nsIObserver;

[scriptable, uuid(ec8030f7-c20a-464f-9b0e-13a3a9e97384)]
interface jsPrintSetup : nsISupports
{
	// Save Options Constants	
	const unsigned long kSaveOddEvenPages = nsIPrintSettings::kInitSaveOddEvenPages; 
	const unsigned long kSaveHeaderLeft = nsIPrintSettings::kInitSaveHeaderLeft;
	const unsigned long kSaveHeaderCenter = nsIPrintSettings::kInitSaveHeaderCenter;
	const unsigned long kSaveHeaderRight = nsIPrintSettings::kInitSaveHeaderRight;
	const unsigned long kSaveFooterLeft = nsIPrintSettings::kInitSaveFooterLeft;
	const unsigned long kSaveFooterCenter = nsIPrintSettings::kInitSaveFooterCenter;
	const unsigned long kSaveFooterRight = nsIPrintSettings::kInitSaveFooterRight;
	const unsigned long kSaveBGImages = nsIPrintSettings::kInitSaveBGImages;
	const unsigned long kSavePaperSize = nsIPrintSettings::kInitSavePaperSize;
	const unsigned long kSavePaperData = nsIPrintSettings::kInitSavePaperData;
	const unsigned long kSavePaperSizeNativeData = nsIPrintSettings:: kPaperSizeNativeData;
	const unsigned long kSavePaperWidth = nsIPrintSettings::kInitSaveUnwriteableMargins;
	const unsigned long kSavePaperHeight = nsIPrintSettings::kInitSaveEdges;
	const unsigned long kSaveInColor = nsIPrintSettings::kInitSaveInColor;
	const unsigned long kSaveOrientation = nsIPrintSettings::kInitSaveOrientation;
	const unsigned long kSavePrinterName = nsIPrintSettings::kInitSavePrinterName;
	const unsigned long kSavePageDelay = nsIPrintSettings::kInitSavePageDelay;
	const unsigned long kSaveMargins = nsIPrintSettings::kInitSaveMargins;
	const unsigned long kSaveShrinkToFit = nsIPrintSettings::kInitSaveShrinkToFit;
	const unsigned long kSaveResolutionName = nsIPrintSettings::kInitSaveResolutionName;
	
	const unsigned long  kSaveScaling = nsIPrintSettings:: kInitSaveScaling;

	// Page Size Unit Constants 
	const short kPaperSizeInches      = nsIPrintSettings::kPaperSizeInches;
	const short kPaperSizeMillimeters = nsIPrintSettings::kPaperSizeMillimeters;

	// Page Orientation Constants
	const short kPortraitOrientation  = nsIPrintSettings::kPortraitOrientation;
	const short kLandscapeOrientation = nsIPrintSettings::kLandscapeOrientation;

	// Print Range Enums 
	const long kRangeAllPages           = nsIPrintSettings::kRangeAllPages;
	const long kRangeSpecifiedPageRange = nsIPrintSettings::kRangeSpecifiedPageRange;
	const long kRangeSelection          = nsIPrintSettings::kRangeSelection;
	const long kRangeFocusFrame         = nsIPrintSettings::kRangeFocusFrame;

	// Shorthand Combined Saving Constants
	const unsigned long kSaveHeader = 
										  kSaveHeaderLeft | kSaveHeaderCenter | kSaveHeaderRight | 
										  kSaveFooterLeft | kSaveFooterCenter | kSaveFooterRight;
	const unsigned long kSaveMarginsAndOrientation = 
												kSaveOrientation | kSaveMargins;
	const unsigned long kSaveMarginsAndHeader =
											kSaveHeader | kSaveMarginsAndOrientation;
	const unsigned long kSaveAll = 
									  	kSaveOddEvenPages 
										| kSaveHeaderLeft |kSaveHeaderCenter | kSaveHeaderRight  
										| kSaveFooterLeft | kSaveFooterCenter | kSaveFooterRight 
										| kSaveBGImages 
										| kSavePaperSize | kSavePaperData | kSavePaperSizeNativeData 
										| kSavePaperWidth | kSavePaperHeight | kSaveInColor 
										| kSaveOrientation |	kSavePrinterName | kSavePageDelay 
										| kSaveMargins |	kSaveShrinkToFit | kSaveScaling 
										| kSaveResolutionName;

	attribute string ATest;										 
	   
	void setOption( in string option, in wstring value);
	void setGlobalOption( in string option, in wstring value);
	wstring getOption( in wstring option);
	wstring getGlobalOption( in wstring option);
	void saveOptions( in long option_set);
	void saveGlobalOptions( in long option_set);
	void refreshOptions();
	wstring getPrintersList();
	void setPrinter(in wstring printerName);
	wstring getPrinter();
	void setShowPrintProgress( in boolean flag);
	boolean getShowPrintProgress();
	void setSilentPrint( in boolean flag);
	boolean getSilentPrint();	
	void print();
	void printWindow(in nsIDOMWindow aWindow);
	void printPreview(); // not implemented yet
};

--------------010503070502060802010207--
0
Dimitar
6/10/2009 12:53:19 PM
mozilla.dev.tech.xpcom 1345 articles. 0 followers. Post Follow

7 Replies
1338 Views

Similar Articles

[PageSpeed] 7

Dimitar Angelov wrote:
> Hi mozilla developers!
> 
> I have created Firefox extension in javascript that makes global object 
> called jsPrintSetup which is accessible from client's javascript.
> 
> All methods call works fine but when add attribute 'ATest' to my object 
> and try to access it from client javascript (for example 
> alert(jsPrintSetup.ATest);) firefox reports error:
> Permission denied to get property Object.ATest
> If I add line 
> netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
> before access property of object all works.
> 
> Can I workaround this and ignore need from enabling UniversalXPConnect 
> from client javascript?
> 
> Thank you in advance.
> 
> 
> Regards,
> 
> Dimitar
> 
> PS: I have attached my idl and implementation file.
Did you rebuild xpt file?
What about to use ACString and AString instead of string and wstring?

PM-
0
Pavol
6/10/2009 2:19:32 PM
Pavol Misik wrote:
> Dimitar Angelov wrote:
>> Hi mozilla developers!
>>
>> I have created Firefox extension in javascript that makes global 
>> object called jsPrintSetup which is accessible from client's javascript.
>>
>> All methods call works fine but when add attribute 'ATest' to my 
>> object and try to access it from client javascript (for example 
>> alert(jsPrintSetup.ATest);) firefox reports error:
>> Permission denied to get property Object.ATest
>> If I add line 
>> netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
>> before access property of object all works.
>>
>> Can I workaround this and ignore need from enabling UniversalXPConnect 
>> from client javascript?
>>
>> Thank you in advance.
>>
>>
>> Regards,
>>
>> Dimitar
>>
>> PS: I have attached my idl and implementation file.
> Did you rebuild xpt file?
> What about to use ACString and AString instead of string and wstring?
I have changed to
	attribute ACString ATest;
rebuild xpt reinstall extension
	attribute AString ATest;				
rebuild xpt reinstall extension
but result is the same:
"Permission denied to get property Object.ATest"

Regards,

Dimitar
0
Dimitar
6/11/2009 6:29:08 AM
Dimitar Angelov wrote:
> I have changed to
>     attribute ACString ATest;
> rebuild xpt reinstall extension
>     attribute AString ATest;               
> rebuild xpt reinstall extension
> but result is the same:
> "Permission denied to get property Object.ATest"
> 
> Regards,
> 
> Dimitar

Isn't there problem with a first capital letter ATest.

Try to declare it as
attribute AString aTest


https://developer.mozilla.org/en/IDL_interface_rules
PM-

0
Pavol
6/11/2009 10:24:54 AM
On 10/06/2009 13:53, Dimitar Angelov wrote:
> Hi mozilla developers!
>
> I have created Firefox extension in javascript that makes global object
> called jsPrintSetup which is accessible from client's javascript.
>
> All methods call works fine but when add attribute 'ATest' to my object
> and try to access it from client javascript (for example
> alert(jsPrintSetup.ATest);) firefox reports error:
> Permission denied to get property Object.ATest
> If I add line
> netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
> before access property of object all works.
>
> Can I workaround this and ignore need from enabling UniversalXPConnect
> from client javascript?
>
> Thank you in advance.
>
>
> Regards,
>
> Dimitar
>
> PS: I have attached my idl and implementation file.

You haven't implemented nsISecurityCheckedComponent correctly.

http://weblogs.mozillazine.org/weirdal/archives/017211.html

0
Dave
6/11/2009 10:38:26 AM
Pavol Misik wrote:
> Dimitar Angelov wrote:
>> I have changed to
>>     attribute ACString ATest;
>> rebuild xpt reinstall extension
>>     attribute AString ATest;               rebuild xpt reinstall 
>> extension
>> but result is the same:
>> "Permission denied to get property Object.ATest"
>>
>> Regards,
>>
>> Dimitar
> 
> Isn't there problem with a first capital letter ATest.
> 
> Try to declare it as
> attribute AString aTest
> 
> 
> https://developer.mozilla.org/en/IDL_interface_rules
> PM-
> 
I have changed declaration with:
	attribute AString myAttrTest;						

Recompile, Reinstall but again get's error:				

Permission denied to get property Object.myAttrTest
[Break on this error] alert(jsPrintSetup.myAttrTest);

uncaught exception: [Exception... "'[JavaScript Error: "Permission 
denied to get property Object.myAttrTest" {file: 
"file:///d:/temp/New4.html" line: 16}]' when calling method: 
[jsPrintSetup::myAttrTest]" nsresult: "0x80570021 
(NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)" location: "JS frame :: 
file:///d:/temp/New4.html :: test1 :: line 16" data: yes]


Regards,

Dimitar
0
Dimitar
6/11/2009 12:11:07 PM
Dave Townsend wrote:
> On 10/06/2009 13:53, Dimitar Angelov wrote:
>> Hi mozilla developers!
>>
>> I have created Firefox extension in javascript that makes global object
>> called jsPrintSetup which is accessible from client's javascript.
>>
>> All methods call works fine but when add attribute 'ATest' to my object
>> and try to access it from client javascript (for example
>> alert(jsPrintSetup.ATest);) firefox reports error:
>> Permission denied to get property Object.ATest
>> If I add line
>> netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
>> before access property of object all works.
>>
>> Can I workaround this and ignore need from enabling UniversalXPConnect
>> from client javascript?
>>
>> Thank you in advance.
>>
>>
>> Regards,
>>
>> Dimitar
>>
>> PS: I have attached my idl and implementation file.
> 
> You haven't implemented nsISecurityCheckedComponent correctly.
> 
> http://weblogs.mozillazine.org/weirdal/archives/017211.html
> 

Thank you it is correctly! This is perfect article.
I have not implemented nsISecurityCheckedComponent interface generally. :-(

I've tried to implement but have a trouble, i do something wrong but 
can't found what.
Implementations of my methods canCreateWrapper, canCallMethod, 
canGetProperty and canSetProperty are never called.

I have attached my idl and js file if you can point me error I will be 
thankful.

Thank you again.

Regards,

Dimitar
0
Dimitar
6/12/2009 6:41:45 AM
This is a multi-part message in MIME format.
--------------070708050101070206010502
Content-Type: text/plain; charset=windows-1251; format=flowed
Content-Transfer-Encoding: 7bit

Sorry!
I forgot the files! :-(

--------------070708050101070206010502
Content-Type: application/x-javascript;
 name="jsPrintSetup.js"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="jsPrintSetup.js"

//
//  jsPrintSetup 
//  	 Global object extending printing features from client-side JavaScript
//
//  Revision: 
//     $Id$ 
//
//  Copyright(c) 2009 EDA Ltd.
//

const kMODULE_NAME = "jsPrintSetup";
const kMODULE_CONTRACTID = "@edabg.com/jsprintsetup;1";
const kMODULE_CID = Components.ID("ec8030f7-c20a-464f-9b0e-13a3a9e97384");
const kMODULE_INTERFACE = Components.interfaces.jsPrintSetup;

function jsPrintSetup() { 
	this.printSettingsInterface = Components.interfaces.nsIPrintSettings;

	this.printSettingsService = 
		Components.classes["@mozilla.org/gfx/printsettings-service;1"]
				.getService(Components.interfaces.nsIPrintSettingsService);
//	this.printSettingsService = 
//		Components.classes["@mozilla.org/gfx/printsettings-service;1"]
//			.createInstance(Components.interfaces.nsIPrintSettingsService);

	this.printSettings = this.printSettingsService.newPrintSettings;
//		this.printSettingsService.globalPrintSettings
//			.QueryInterface(Components.interfaces.nsIPrintSettings);

	this.getPrintersList();                  
	this.setPrinter('');

	this.globalPaperSizeUnit = this.printSettingsService.globalPrintSettings.paperSizeUnit;
	this.paperSizeUnit = Components.interfaces.nsIPrintSettings.kPaperSizeMillimeters;
	
	this.globalPrintSettings = this.printSettingsService.globalPrintSettings.clone();
	 
	this.prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); 
}


jsPrintSetup.prototype = {
	mTest : 'ala bala',
// Alert and logging methods
	alert: function(msg){
		var promptService = 
			Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
				.getService(Components.interfaces.nsIPromptService);
		promptService.alert(null, "JS Print Setup",msg);	
	},

	log: function (msg) {
	  var consoleService = 
	    Components.classes["@mozilla.org/consoleservice;1"].
	               getService(Components.interfaces.nsIConsoleService);
	  consoleService.logStringMessage(msg);
	},

// Common private methods	
	getWindow: function () {
		var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
									.getService(Components.interfaces.nsIWindowMediator);
		return wm.getMostRecentWindow('navigator:browser');
	},
	
  getWebBrowserPrint: function (aWindow)
  {
    var contentWindow = aWindow || this.getWindow().content;
//		this.alert(contentWindow.frames.length);
//		if (contentWindow.frames.length)
//			contentWindow = contentWindow.frames[0]; 
    return contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                        .getInterface(Components.interfaces.nsIWebBrowserPrint);
  },	
	
/*
  getWebBrowserPrint: function ()
  {
//    var contentWindow = aWindow || window.content;
		var contentWindow = this.getWindow().content;
    	return contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                        .getInterface(Components.interfaces.nsIWebBrowserPrint);
  },
*/

// Common converting private methods 
	adjustValue : function (value, unitFrom, unitTo) {
		if (unitFrom != unitTo) {
			// Different Paper Size Units 
			if (unitTo == Components.interfaces.nsIPrintSettings.kPaperSizeInches)
				// value is in mm -> convert to inches
				return value / 25.4;
			else
				// value is in inches -> convert to mm
				return value * 25.4;
		} else
			return value;
	},
	
	// gets printer setting value and adjust it depending of units
	getValue : function (value) {
		// Here must be this.printSettings.paperSizeUnit, but actualy don't work properly
		// to work well we are using this.globalPrintSettings.paperSizeUnit
		return this.adjustValue(value, this.globalPrintSettings.paperSizeUnit, this.paperSizeUnit);
	},

	// sets printer setting value and adjust it depending of units
	setValue : function (value) {
		// Here must be this.printSettings.paperSizeUnit, but actualy don't work properly
		// to work well we are using this.globalPrintSettings.paperSizeUnit
		return this.adjustValue(value, this.paperSizeUnit, this.globalPrintSettings.paperSizeUnit);
	},

	// gets global printer setting value and adjust it depending of units
	getGlobalValue : function (value) {
		return this.adjustValue(value, this.globalPrintSettings.paperSizeUnit, this.paperSizeUnit);
	},

	// sets global printer setting value and adjust it depending of units
	setGlobalValue : function (value) {
		return this.adjustValue(value, this.paperSizeUnit, this.globalPrintSettings.paperSizeUnit);
	},

	// converts string to boolean
	toBool: function (value){
		return ((value == "true") || (value == "1")? true:false);
	},

	// convert scaling from percent to actual unit using from mozilla
	scalingConvert: function (scaling){
		if (scaling < 10.0) {
			scaling = 10.0;
		}
		if (scaling > 500.0) {
			scaling = 500.0;
		}
		scaling /= 100.0;
		
		return scaling;
	},
	
	// attribute manipulation methods
	get myAttrTest() {return this.mTest; /*return this.printSettings.showPrintProgress;*/},
	set myAttrTest(aTest) {return this.mTest = aTest;/*eturn this.printSettings.showPrintProgress = aShow;*/},
	
	// sets printer name and read its settings, if 	
	setPrinter: function(printerName){
		if (printerName) {
			// check if printer exist
			for (var i = 0, p_exist = false; (i < this.printerList.length) && !p_exist; i++)
				if (this.printerList[i] == printerName) p_exist = 1;
			if (!p_exist) {
				this.alert('Error: Printer \''+printerName+'\' doesn\'t exist!');
				return;
			}
		}
		this.printerName = (printerName? printerName:this.printSettingsService.defaultPrinterName);
		this.printSettings.printerName = this.printerName;
		// This is part from mozilla toolkit printUtils.js
		// First get any defaults from the printer 		
		this.printSettingsService.initPrintSettingsFromPrinter(this.printSettings.printerName, this.printSettings);
		// now augment them with any values from last time
		this.printSettingsService.initPrintSettingsFromPrefs(this.printSettings, true, this.printSettingsInterface.kInitSaveAll);

	/*	if (this.printSettingsService.defaultPrinterName != this.printerName)
			this.printSettingsService.defaultPrinterName = this.printerName;*/
	},
	
	// get current printer name 
	getPrinter: function(){
		return this.printerName;
	},
	
	// get list of available printers
	getPrintersList: function(){
		var printerEnumerator =
			Components.classes["@mozilla.org/gfx/printerenumerator;1"]
				.getService(Components.interfaces.nsIPrinterEnumerator)
				.printerNameList;
		this.printerList = new Array();
		var i = 0;
		while(printerEnumerator.hasMore())
			this.printerList[i++] = printerEnumerator.getNext();
		return this.printerList;	
	},

	//set current printer options
	setOption: function(option,value){
		switch(option){
			case 'orientation':
				this.printSettings.orientation = value;
				break;
			case 'marginTop':
				this.printSettings.marginTop = this.setValue(value);
				break;
			case 'marginLeft':
				this.printSettings.marginLeft = this.setValue(value);
				break;
			case 'marginRight':
				this.printSettings.marginRight = this.setValue(value);
				break;
			case 'marginBottom':
				this.printSettings.marginBottom = this.setValue(value);
				break;
			case 'shrinkToFit':
				this.printSettings.shrinkToFit = this.toBool(value);
				break;
			case 'paperData':
				this.printSettings.paperData = value;				
				break;				
			case 'numCopies':
				this.printSettings.numCopies = value;
				break;				
			case 'outputFormat':
				this.printSettings.outputFormat = value;				
				break;				
			case 'paperHeight':
				this.printSettings.paperHeight = value;				
				break;				
			case 'paperName':
				this.printSettings.paperName = value;				
				break;				
			case 'paperSizeType':
				this.printSettings.paperSizeType = value;				
				break;
			case 'paperSizeUnit':
				this.alert("The property paperSizeUnit is readonly!");
//				this.printSettings.paperSizeUnit = value;				
				break;			
			case 'paperWidth':
				this.printSettings.paperWidth = value;				
				break;								
			case 'scaling':
				this.printSettings.scaling = this.scalingConvert(value);
				break;
			case 'footerStrCenter':
				this.printSettings.footerStrCenter = value;
				break;
			case 'footerStrLeft':
				this.printSettings.footerStrLeft = value;
				break;
			case 'footerStrRight':
				this.printSettings.footerStrRight = value;
				break;
			case 'headerStrCenter':
				this.printSettings.headerStrCenter = value;
				break;
			case 'headerStrLeft':
				this.printSettings.headerStrLeft = value;
				break;
			case 'headerStrRight':
				this.printSettings.headerStrRight = value;
				break;
		}	 
		
	},

	// set global print options
	setGlobalOption: function(option,value){
		switch(option){
			case 'orientation':
				this.globalPrintSettings.orientation = value;
				break;
			case 'marginTop':
				this.globalPrintSettings.marginTop = this.setValue(value);
				break;
			case 'marginLeft':
				this.globalPrintSettings.marginLeft = this.setValue(value);
				break;
			case 'marginRight':
				this.globalPrintSettings.marginRight = this.setValue(value);
				break;
			case 'marginBottom':
				this.globalPrintSettings.marginBottom = this.setValue(value);
				break;
			case 'shrinkToFit':
				this.globalPrintSettings.shrinkToFit = this.toBool(value);
				break;
			case 'paperData':
				this.globalPrintSettings.paperData = value;				
				break;				
			case 'numCopies':
				this.globalPrintSettings.numCopies = value;
				break;				
			case 'outputFormat':
				this.globalPrintSettings.outputFormat = value;				
				break;				
			case 'paperHeight':
				this.globalPrintSettings.paperHeight = value;				
				break;				
			case 'paperName':
				this.globalPrintSettings.paperName = value;				
				break;				
			case 'paperSizeType':
				this.globalPrintSettings.paperSizeType = value;				
				break;
			case 'paperSizeUnit':
				this.alert("The Global property paperSizeUnit is readonly!");			
//				this.globalPrintSettings.paperSizeUnit = value;				
				break;				
			case 'paperWidth':
				this.globalPrintSettings.paperWidth = value;				
				break;								
			case 'scaling':
				this.globalPrintSettings.scaling = this.scalingConvert(value);
				break;
			case 'footerStrCenter':
				this.globalPrintSettings.footerStrCenter = value;
				break;
			case 'footerStrLeft':
				this.globalPrintSettings.footerStrLeft = value;
				break;
			case 'footerStrRight':
				this.globalPrintSettings.footerStrRight = value;
				break;
			case 'headerStrCenter':
				this.globalPrintSettings.headerStrCenter = value;
				break;
			case 'headerStrLeft':
				this.globalPrintSettings.headerStrLeft = value;
				break;
			case 'headerStrRight':
				this.globalPrintSettings.headerStrRight = value;
				break;
		}	 

	},	

	// get current printer options
 	getOption: function(option){
		this.prefSatus = null;	
		switch(option){
			case 'orientation':
				this.prefSatus = this.printSettings.orientation;
				break;
			case 'marginTop':
				this.prefSatus = this.getValue(this.printSettings.marginTop);
				break;
			case 'marginLeft':
				this.prefSatus = this.getValue(this.printSettings.marginLeft);
				break;
			case 'marginRight':
				this.prefSatus = this.getValue(this.printSettings.marginRight);
				break;
			case 'marginBottom':
				this.prefSatus = this.getValue(this.printSettings.marginBottom);
				break;
			case 'shrinkToFit':
				this.prefSatus = this.printSettings.shrinkToFit;
				break;
			case 'paperData':
				this.prefSatus = this.printSettings.paperData;				
				break;				
			case 'numCopies':
				this.prefSatus = this.printSettings.numCopies;				
				break;				
			case 'outputFormat':
				this.prefSatus = this.printSettings.outputFormat;				
				break;				
			case 'paperHeight':
				this.prefSatus = this.printSettings.paperHeight;				
				break;				
			case 'paperName':
				this.prefSatus = this.printSettings.paperName;				
				break;				
			case 'paperSizeType':
				this.prefSatus = this.printSettings.paperSizeType;				
				break;
			case 'paperSizeUnit':
				this.prefSatus = this.printSettings.paperSizeUnit;				
				break;				
			case 'paperWidth':
				this.prefSatus = this.printSettings.paperWidth;				
				break;												
			case 'scaling':
				this.prefSatus = this.printSettings.scaling;				
				break;			
			case 'footerStrCenter':
				this.prefSatus = this.printSettings.footerStrCenter;
				break;
			case 'footerStrLeft':
				this.prefSatus = this.printSettings.footerStrLeft;
				break;
			case 'footerStrRight':
				this.prefSatus = this.printSettings.footerStrRight;
				break;
			case 'headerStrCenter':
				this.prefSatus = this.printSettings.headerStrCenter;
				break;
			case 'headerStrLeft':
				this.prefSatus = this.printSettings.headerStrLeft;
				break;
			case 'headerStrRight':
				this.prefSatus = this.printSettings.headerStrRight;
				break;
			case 'pinterName':
				this.prefSatus = this.printSettings.printerName;
				break;
		}	 
		return this.prefSatus;
	},

	// get  global print options
 	getGlobalOption: function(option){
		this.prefSatus = null;	
		switch(option){
			case 'orientation':
				this.prefSatus = this.globalPrintSettings.orientation;
				break;
			case 'marginTop':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginTop);
				break;
			case 'marginLeft':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginLeft);
				break;
			case 'marginRight':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginRight);
				break;
			case 'marginBottom':
				this.prefSatus = this.getValue(this.globalPrintSettings.marginBottom);
				break;
			case 'shrinkToFit':
				this.prefSatus = this.globalPrintSettings.shrinkToFit;
				break;
			case 'paperData':
				this.prefSatus = this.globalPrintSettings.paperData;				
				break;				
			case 'numCopies':
				this.prefSatus = this.globalPrintSettings.numCopies;				
				break;				
			case 'outputFormat':
				this.prefSatus = this.globalPrintSettings.outputFormat;				
				break;				
			case 'paperHeight':
				this.prefSatus = this.globalPrintSettings.paperHeight;				
				break;				
			case 'paperName':
				this.prefSatus = this.globalPrintSettings.paperName;				
				break;				
			case 'paperSizeType':
				this.prefSatus = this.globalPrintSettings.paperSizeType;				
				break;
			case 'paperSizeUnit':
				this.prefSatus = this.globalPrintSettings.paperSizeUnit;				
				break;				
			case 'paperWidth':
				this.prefSatus = this.globalPrintSettings.paperWidth;				
				break;												
			case 'scaling':
				this.prefSatus = this.globalPrintSettings.scaling;				
				break;			
			case 'footerStrCenter':
				this.prefSatus = this.globalPrintSettings.footerStrCenter;
				break;
			case 'footerStrLeft':
				this.prefSatus = this.globalPrintSettings.footerStrLeft;
				break;
			case 'footerStrRight':
				this.prefSatus = this.globalPrintSettings.footerStrRight;
				break;
			case 'headerStrCenter':
				this.prefSatus = this.globalPrintSettings.headerStrCenter;
				break;
			case 'headerStrLeft':
				this.prefSatus = this.globalPrintSettings.headerStrLeft;
				break;
			case 'headerStrRight':
				this.prefSatus = this.globalPrintSettings.headerStrRight;
				break;
			case 'pinterName':
				this.prefSatus = this.globalPrintSettings.printerName;
				break;
		}	 
		return this.prefSatus;

	},
//		
// All print configuration options can be found at
// http://kb.mozillazine.org/About:config_entries#Print..2A
//
	// set flag to display print progress true/false 	
	setShowPrintProgress: function (flag){
		this.prefManager.setBoolPref("print.show_print_progress", flag);
	},

	// get flag to display print progress
	getShowPrintProgress: function () {
		return this.prefManager.getBoolPref("print.print.show_print_progress");		
	},

	// set flag for silents print process (don't display print dialog)
	setSilentPrint: function (flag) {
		this.prefManager.setBoolPref("print.always_print_silent", flag);	
	},
	
	// get flag for silents print process (don't display print dialog)
	getSilentPrint: function (){
		return this.prefManager.getBoolPref("print.always_print_silent");	
	},
	
	//save  current printer settings to preferences
	saveOptions: function(flags){
      this.printSettingsService.savePrintSettingsToPrefs(this.printSettings, true, flags);
	},

	// save global print settings to preferences
	saveGlobalOptions: function(flags){
      this.printSettingsService.savePrintSettingsToPrefs(this.globalPrintSettings, true, flags);
	},
	
	// call print with current printer
	print: function() {
		var webBrowserPrint = this.getWebBrowserPrint(null);				
		webBrowserPrint.print(this.printSettings, null); //this.printSettings, null
	},

	printWindow: function(aWindow) {
		var webBrowserPrint = this.getWebBrowserPrint(aWindow);				
		webBrowserPrint.print(this.printSettings, null); //this.printSettings, null
	},

	printPreview: function() {
		this.alert("This version don't implement method printPreview! ");
	},
	 
	// refreshresh printer options
	refreshOptions: function(){
//		this.printSettings = this.printSettingsService.globalPrintSettings
//		.QueryInterface(Components.interfaces.nsIPrintSettings);
//		this.printSettings.printerName = this.printerName;

		// This is part from mozilla toolkit printUtils.js
		// First get any defaults from the printer 		
		this.printSettingsService.initPrintSettingsFromPrinter(this.printSettings.printerName, this.printSettings);
		// now augment them with any values from last time
		this.printSettingsService.initPrintSettingsFromPrefs(this.printSettings, true, this.printSettingsInterface.kInitSaveAll);	
	},

// Interface supporting methods	
	// nsISupports
	QueryInterface: function(iid) {
//		this.alert(iid.equals(Components.interfaces.nsISecurityCheckedComponent));
		if (iid.equals(kMODULE_INTERFACE)) this.alert(kMODULE_INTERFACE);
		else if (iid.equals(Components.interfaces.nsIClassInfo)) this.alert(Components.interfaces.nsIClassInfo);
		else if (iid.equals(Components.interfaces.nsISupports)) this.alert(Components.interfaces.nsISupports);
		else if (iid.equals(Components.interfaces.nsISecurityCheckedComponent)) this.alert(Components.interfaces.nsISecurityCheckedComponent);
		else this.alert('unknown:'+iid);
		if (!iid.equals(kMODULE_INTERFACE) &&
			!iid.equals(Components.interfaces.nsIClassInfo) &&
			!iid.equals(Components.interfaces.nsISupports) &&
			!iid.equals(Components.interfaces.nsISecurityCheckedComponent)
			) {
			throw Components.results.NS_ERROR_NO_INTERFACE;
		}
		return this;
	},

	// nsIClassInfo
	flags: Components.interfaces.nsIClassInfo.DOM_OBJECT,

	implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,

	classDescription: kMODULE_NAME,

	getInterfaces: function(aCount) {
		var aResult = [
		 	kMODULE_INTERFACE
			, Components.interfaces.nsISecurityCheckedComponent
			, Components.interfaces.nsIClassInfo
		];
		this.alert('get interfaces:'+aResult);
		aCount.value = aResult.length;
		return aResult;
	},

	getHelperForLanguage: function(count) { return null; },
  
	// nsISecurityCheckedComponent
	// Implementation of this interface was suggested from Dave Townsend
	// to see http://weblogs.mozillazine.org/weirdal/archives/017211.html
	canCreateWrapper : function canCreateWrapper(aIID) {
		this.alert('canCreateWrapper:'+aIID);
		return "AllAccess";
	},
	canCallMethod: function canCallMethod(aIID, methodName) {
		this.alert('canGetProperty:'+aIID+':'+propertyName);
		return "AllAccess";
	},
	canGetProperty: function canGetProperty(aIID, propertyName) {
		this.alert('canGetProperty:'+aIID+':'+propertyName);
		return "AllAccess";
/*		
		switch (propertyName) {
			case "property 1":
			case "property 2":
				return "AllAccess";
		}
		return "NoAccess";
*/		
	},
	canSetProperty: function canSetProperty(aIID, propertyName) {
		this.alert('canSetProperty:'+aIID+':'+propertyName);
		return "AllAccess";
/*	
		if (propertyName == "property 1") {
			return "AllAccess";
		}
		return "NoAccess";
*/		
	},
};

// the end jsPrintSetup.property
var jsPrintSetupFactory = {};

jsPrintSetupFactory.createInstance = function (outer, iid) {
	var ps  = 
			Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
				.getService(Components.interfaces.nsIPromptService);
	if (iid.equals(kMODULE_INTERFACE)) ps.alert(null, "JS Print Setup",'aa:'+kMODULE_INTERFACE);
	else if (iid.equals(Components.interfaces.nsIClassInfo)) ps.alert(null, "JS Print Setup",'aa:'+Components.interfaces.nsIClassInfo);
	else if (iid.equals(Components.interfaces.nsISupports)) ps.alert(null, "JS Print Setup",'aa:'+Components.interfaces.nsISupports);
	else if (iid.equals(Components.interfaces.nsISecurityCheckedComponent)) ps.alert(null, "JS Print Setup",'aa:'+Components.interfaces.nsISecurityCheckedComponent);
	else ps.alert(null, "JS Print Setup",'aa:unknown:'+iid);
  if (outer !== null) {
    throw Components.results.NS_ERROR_NO_AGGREGATION;
  }
  if (!iid.equals(kMODULE_INTERFACE) &&
      !iid.equals(Components.interfaces.nsIClassInfo) && 
      !iid.equals(Components.interfaces.nsISupports) &&
      !iid.equals(Components.interfaces.nsISecurityCheckedComponent)
		) {
    throw Components.results.NS_ERROR_NO_INTERFACE;
  }

  return new jsPrintSetup();
};

var jsPrintSetupModule = {};

jsPrintSetupModule.registerSelf = function (compMgr, fileSpec, location, type) {
  compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  compMgr.registerFactoryLocation(kMODULE_CID,
                                  kMODULE_NAME,
                                  kMODULE_CONTRACTID,
                                  fileSpec, 
                                  location, 
                                  type);

  var catman = Components.classes["@mozilla.org/categorymanager;1"].
                          getService(Components.interfaces.nsICategoryManager);
  catman.addCategoryEntry("JavaScript global property",
                          "jsPrintSetup",
                          kMODULE_CONTRACTID,
                          true,
                          true);
};

jsPrintSetupModule.getClassObject = function (compMgr, cid, iid) {
  if (!cid.equals(kMODULE_CID)) {
    throw Components.results.NS_ERROR_NO_INTERFACE;
  }
  if (!iid.equals(Components.interfaces.nsIFactory)) {
    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  }
  return jsPrintSetupFactory;
};

jsPrintSetupModule.canUnload = function (compMgr) {
  return true;
};

function NSGetModule(compMgr, fileSpec) {
  return jsPrintSetupModule;
}

--------------070708050101070206010502
Content-Type: text/plain;
 name="jsPrintSetup.idl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="jsPrintSetup.idl"

//
//  jsPrintSetup interface 
//  	 Global object extending printing features from client-side JavaScript
//
//  Revision: 
//     $Id$ 
//
//  Copyright(c) 2009 EDA Ltd.
//

#include "nsISupports.idl"
//#include "nsIDOMHTMLDocument.idl"
#include "nsIPrintSettings.idl"
#include "nsIDOMWindow.idl"
//#include "nsISecurityCheckedComponent.idl"

interface nsIObserver;
interface nsIClassInfo;
interface nsISecurityCheckedComponent;

[scriptable, uuid(ec8030f7-c20a-464f-9b0e-13a3a9e97384)]
interface jsPrintSetup : nsISupports
{
	// Save Options Constants	
	const unsigned long kSaveOddEvenPages = nsIPrintSettings::kInitSaveOddEvenPages; 
	const unsigned long kSaveHeaderLeft = nsIPrintSettings::kInitSaveHeaderLeft;
	const unsigned long kSaveHeaderCenter = nsIPrintSettings::kInitSaveHeaderCenter;
	const unsigned long kSaveHeaderRight = nsIPrintSettings::kInitSaveHeaderRight;
	const unsigned long kSaveFooterLeft = nsIPrintSettings::kInitSaveFooterLeft;
	const unsigned long kSaveFooterCenter = nsIPrintSettings::kInitSaveFooterCenter;
	const unsigned long kSaveFooterRight = nsIPrintSettings::kInitSaveFooterRight;
	const unsigned long kSaveBGImages = nsIPrintSettings::kInitSaveBGImages;
	const unsigned long kSavePaperSize = nsIPrintSettings::kInitSavePaperSize;
	const unsigned long kSavePaperData = nsIPrintSettings::kInitSavePaperData;
	const unsigned long kSavePaperSizeNativeData = nsIPrintSettings:: kPaperSizeNativeData;
	const unsigned long kSavePaperWidth = nsIPrintSettings::kInitSaveUnwriteableMargins;
	const unsigned long kSavePaperHeight = nsIPrintSettings::kInitSaveEdges;
	const unsigned long kSaveInColor = nsIPrintSettings::kInitSaveInColor;
	const unsigned long kSaveOrientation = nsIPrintSettings::kInitSaveOrientation;
	const unsigned long kSavePrinterName = nsIPrintSettings::kInitSavePrinterName;
	const unsigned long kSavePageDelay = nsIPrintSettings::kInitSavePageDelay;
	const unsigned long kSaveMargins = nsIPrintSettings::kInitSaveMargins;
	const unsigned long kSaveShrinkToFit = nsIPrintSettings::kInitSaveShrinkToFit;
	const unsigned long kSaveResolutionName = nsIPrintSettings::kInitSaveResolutionName;
	
	const unsigned long  kSaveScaling = nsIPrintSettings:: kInitSaveScaling;

	// Page Size Unit Constants 
	const short kPaperSizeInches      = nsIPrintSettings::kPaperSizeInches;
	const short kPaperSizeMillimeters = nsIPrintSettings::kPaperSizeMillimeters;

	// Page Orientation Constants
	const short kPortraitOrientation  = nsIPrintSettings::kPortraitOrientation;
	const short kLandscapeOrientation = nsIPrintSettings::kLandscapeOrientation;

	// Print Range Enums 
	const long kRangeAllPages           = nsIPrintSettings::kRangeAllPages;
	const long kRangeSpecifiedPageRange = nsIPrintSettings::kRangeSpecifiedPageRange;
	const long kRangeSelection          = nsIPrintSettings::kRangeSelection;
	const long kRangeFocusFrame         = nsIPrintSettings::kRangeFocusFrame;

	// Shorthand Combined Saving Constants
	const unsigned long kSaveHeader = 
										  kSaveHeaderLeft | kSaveHeaderCenter | kSaveHeaderRight | 
										  kSaveFooterLeft | kSaveFooterCenter | kSaveFooterRight;
	const unsigned long kSaveMarginsAndOrientation = 
												kSaveOrientation | kSaveMargins;
	const unsigned long kSaveMarginsAndHeader =
											kSaveHeader | kSaveMarginsAndOrientation;
	const unsigned long kSaveAll = 
									  	kSaveOddEvenPages 
										| kSaveHeaderLeft |kSaveHeaderCenter | kSaveHeaderRight  
										| kSaveFooterLeft | kSaveFooterCenter | kSaveFooterRight 
										| kSaveBGImages 
										| kSavePaperSize | kSavePaperData | kSavePaperSizeNativeData 
										| kSavePaperWidth | kSavePaperHeight | kSaveInColor 
										| kSaveOrientation |	kSavePrinterName | kSavePageDelay 
										| kSaveMargins |	kSaveShrinkToFit | kSaveScaling 
										| kSaveResolutionName;

	attribute AString myAttrTest;										 
	   
	void setOption( in string option, in wstring value);
	void setGlobalOption( in string option, in wstring value);
	wstring getOption( in wstring option);
	wstring getGlobalOption( in wstring option);
	void saveOptions( in long option_set);
	void saveGlobalOptions( in long option_set);
	void refreshOptions();
	wstring getPrintersList();
	void setPrinter(in wstring printerName);
	wstring getPrinter();
	void setShowPrintProgress( in boolean flag);
	boolean getShowPrintProgress();
	void setSilentPrint( in boolean flag);
	boolean getSilentPrint();	
	void print();
	void printWindow(in nsIDOMWindow aWindow);
	void printPreview(); // not implemented yet
};

--------------070708050101070206010502--
0
Dimitar
6/12/2009 6:43:03 AM
Reply:

Similar Artilces:

How to Instantiate JavaScript XPCOM Component from C++ XPCOM Component
Hi Could you please help me " Instantiate JavaScript XPCOM Component from C++ XPCOM Component/ C++ Code" I have tried one same code given below. HellowWorld.js ------------------------------------ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); function HelloWorld() { } HelloWorld.prototype = { classDescription: "My Hello World Javascript XPCOM Component", classID: Components.ID("{1b635320-30a8-11e3-aa6e-0800200c9a66}"), contractID: "@keynote.com/firefox/helloworld;1", QueryInt...

accessing fields/methods in one JS XPCOM component from another JS XPCOM component
Hello All, Is it illegal to access a method in one javascript XPCOM component from another javascript xpcom component? Do I need to explicitly define an IDL? Thanks for any pointers. Regards, am -- ps: (long) detailed context: I followed: a) "Share global data in Firefox through javascript implemented XPCOM" -- http://tinyurl.com/35dszj b) "passing/getting data from/to custom xpcom service" -- http://tinyurl.com/3ex225 and c) created the JS XPCOM components using http://ted.mielczarek.org/code/mozilla/jscomponentwiz/ (removed the singl...

Purpose of dev-tech-xpcom
What's the purpose of this list? I used to think it was about XPCOM itself, basically for questions about the code in xpcom/**. However, that doesn't seem to be how everyone else uses it. In fact, it seems to be about all coding questions that are somewhat Firefox- or XULRunner-related. Basically what the platform or extension lists are supposed to be. Should we, therefore, delete this list/newsgroup? As it is used, it is redundant. -christian -- All the world's a stage, And all the men and women merely players: They have their exits and their entrances...

XPCOM that use another XPCOM
Hi all, I have the following problem: I want to create a standalone application that uses an XPCOM module "A" written in C++ (a library). I want to create plugins for this application (.xpi package) that install another XPCOM module "B" that use the A XPCom library. I think I doesn't need to cross the interface and to write javascript code. How can I do this in a cross-platform manner? Does mozilla support the dynamic linking? Does it exist some pages of documentation about it? Thank you for your help, Lorenzo On 23 Mar, 14:48, Lorenzo <nos...@pl...

XPCOM
Hi, I'm trying to build mozzilla in order to see a good example application of XPCOM. I read somewhere (http://www.ibm.com/ developerworks/webservices/library/co-xpcom3.html) that this was a good way to get a working version. However, that website seemed to be out of date. I would like to get some sort of "hello world" type of application of XPCOM on which I could conduct further experiements. Any suggestions about how I should get started? In trying to build an example app., I've been trying to build firefox following the directions at http://develope...

XPCOM
Name: Jonny tango Email: jonnytangoattescodotnet Product: Firefox Summary: XPCOM Comments: have you fixed XPCOM problem with this update? Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 ...

xpcom
Hi, I posted this earlier and got no answers. Anyone care to drop a couple of lines on the subject? Hi, I have just started reading the documentation. I am just wondering about xpcom. Is it just a historical thing? i.e., if one is to write a new portable app, given how close java is performing compared to the native binary wouldn't it make sense to do it in java for simplicity and elegance? Surely modularization can be achieved in java or for that matter c#. Microsoft seems to be moving away from COM into managed code. Any thoughts? Thanks, Moheb moheb missaghi w...

XPCOM
Running Mozilla 1.1 and all is basically well, except for the occasional hang on shutdown. I get a message that XPCOM is not responding etc....I know it plays a part in Mozilla, but what does it do? I'd like to fix this, although its not a major issue. Thanks, XPCOM is a lightweight cross platform COM work-alike. It provides interfaces, factories, reference counting, QueryInterface based 'casting', auto pointers, and various other useful stuff. It is the foundation for modularity in mozilla You can get the source code here: http://lxr.mozilla.org/mozilla/source/xpco...

xpcom
since xulplanet is no more, i miss the reference of the xpcom mail. didn't find it at mozdev neither. jef peeraer ...

XPCOM
Hi, I'm trying to build mozzilla in order to see a good example application of XPCOM. I read somewhere (http://www.ibm.com/ developerworks/webservices/library/co-xpcom3.html) that this was a good way to get a working version. However, that website seemed to be out of date. I would like to get some sort of "hello world" type of application of XPCOM on which I could conduct further experiements. Any suggestions about how I should get started? In trying to build an example app., I've been trying to build firefox following the directions at http://developer....

XPCOM
I keep finding links for NS_StringToUTF16, NS_StringGetMutableData ? do such a functions exits ? Also found this http://developer.mozilla.org/en/docs/nsCStringEncoding but don't know where it should go Regards pete Pete Morgan wrote: > NS_StringToUTF16, NS_StringGetMutableData > > ? do such a functions exits ? NS_StringGetMutableData exists. NS_StringToUTF16 doesn't (the NS_String* functions all refer to strings that are in the UTF-16 encoding already), but NS_CStringToUTF16 does. > Also found this > http://developer.mozilla.org/en/doc...

XPCOM how to integrate a XPCOM of thunderbird in firefox
Hello everybody! Well I have a question about the XPCOM. I want to developp a toolbar for firefox, which notify the arrival of new messages in my webmail account. This Webmail is a imap server. So to do that, i tried to download for mozilla source to get the composants wich allow to connect with imap protocol. When i downloaded it, i compiled all sources. Finally, i have many files : *.idl, *.h, *.xpt, so now i want to integrate them to firefox to use it. And i don't know how to do that? to be more precise i don't know what is the best solution to do this application .....

XPCOM component deploying
I'm interesting of is there a way to deploy a component in different directory of "\components" subdirectory in Gecko client application ? -- View this message in context: http://www.nabble.com/XPCOM-component-deploying-tf1991846.html#a5466215 Sent from the Mozilla - XPCOM forum at Nabble.com. ...

How-to register xpcom components?
Good day,everyone. Now, I'm trying to register xpcom components via regxpcom.exe in the sdk. All of my components are placed in the components folder. I copy the regxpcom.exe to xulrunner's folder* C:\xulrunner *then *cd* to * C:\xulrunner\componets* and execute *..\regxpcom*. I found the compreg.datand xpti.dat with CID and interface placed correctly in the components folder. But I can't get the component by *Components.classes[cid]* in the chrome which is all OK in the xpcshell. Anyone knows why and how to fix it? -- >: ~ ...

Web resources about - XPCOM Component attributes - mozilla.dev.tech.xpcom

Attribute - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Template:Attributes of God - Wikipedia, the free encyclopedia
Language: English Română Home Random Template:Attributes of God Part of a series on the Attributes of God Aseity Eternity Graciousness Holiness ...

Six Attributes Of The Perfect Facebook Page Administrator
So, here’s the thing: In many ways, hiring a Facebook page administrator is akin to hiring a poster child for your brand. This trusted manager ...

PANDA: Pose Aligned Networks for Deep Attribute Modeling - Facebook
We propose a method for inferring human attributes (such as gender, hair style, clothes style, expression, action) from images of people under ...

Facebook announces data partnerships to help advertisers target users by offline purchases and attributes ...
... will anonymously match data from consumer loyalty programs with user profiles in order to target ads by offline purchase habits and other attributes. ...

New Study Attributes Rapid Ageing Mainly To Environment Factors
New study explains why some people age faster than others.

Should I use the nofollow attribute on internal links? - YouTube
Regarding "nofollow" on internal links: Does it hurt? Does it help? I read different comments from Matt on this matter over time. What's the ...

Justin Trudeau attributes abortion stance to father's example
Liberal Leader Justin Trudeau says he is following an example set by his famous father when it comes to his position on election candidates and ...

Obama attributes western U.S. wildfires to climate change
... that has burned nearly 400 square miles in the north-central part of Washington state, along with blazes in other Western areas, can be attributed ...

Fifty Shades Of Grey Baby Births: Windsor Hospital Sees Spike In Births, Attribute Book
A significant spike in baby births at a hospital in Windsor, Ontario, has been attributed to the book Fifty Shades of Grey, which has become ...

Resources last updated: 12/23/2015 5:28:21 AM