CopyCutPaste.js
Summary
Allows Mozile to do some basic Copy&Paste operations. Requires above-normal privileges and will not work in server-seide version without setting the pref "signed.applets.codebase_principal_support" to "true" using the "about:config" GUI in Firefox. Doing this has serious security implications and should only be done in a controlled environment.
Version: 0.0.1
Author: David Palm
var f = new Array();
f["File"] = "CopyCutPaste/CopyCutPaste.js";
f["Function"] = "";
mozile.debug(f,0,"CutCopyPaste.js:: LOADED");
Mozile.prototype.clipboard = "";
Mozile.prototype.doCopy = function(){
var f = new Array();
f["File"] = "CopyCutPaste/CopyCutPaste.js";
f["Function"] = "Mozile.doCopy()";
this.debug(f,0,"START");
var copyStr = this.getSelection().toString();
if(!mozile.extension && (!this.moduleList["CopyCutPaste"]["requestPermissions"] || this.moduleList["CopyCutPaste"]["requestPermissions"]!="true") ) {
this.clipboard = copyStr;
}
else {
try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite ");}
catch(e){
this.debug(f,3,"Universal Connect non concesso"+e);
return false;
}
const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
if(gClipboardHelper) {
gClipboardHelper.copyString(copyStr);
}
else {
this.clipboard = copyStr;
}
}
return copyStr;
}
Mozile.prototype.doCut = function(){
var f = new Array();
f["File"] = "CopyCutPaste/CopyCutPaste.js";
f["Function"] = "Mozile.doCut()";
this.debug(f,0,"START");
var copyStr = this.doCopy() ;
if(copyStr){
this.getSelection().deleteContents();
return copyStr;
}
else{
this.debug(f,0,"Cut command failed. Maybe a problem in doCopy()?");
return false;
}
}
Mozile.prototype.doPaste = function(){
var f = new Array();
f["File"] = "CopyCutPaste/CopyCutPaste.js";
f["Function"] = "Mozile.doPaste()";
this.debug(f,0,"START");
if(!mozile.extension && (!this.moduleList["CopyCutPaste"]["requestPermissions"] || this.moduleList["CopyCutPaste"]["requestPermissions"]!="true") ) {
if(this.clipboard) this.insertString(this.clipboard);
return this.clipboard;
}
try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite ");}
catch(e){
this.debug(f,3,"Universal Connect non concesso"+e);
return false;
}
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return false;
this.debug(f,0,"Got clipboard: "+clip);
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
this.debug(f,0,"Got transferable: "+trans);
trans.addDataFlavor("text/unicode");
this.debug(f,0,"Added data flavour (text/unicode)")
clip.getData(trans,clip.kGlobalClipboard);
this.debug(f,0,"Copied clipboard data into clip var")
var str = new Object();
var strLength = new Object();
trans.getTransferData("text/unicode",str,strLength);
this.debug(f,0,"Got data. Converting to js string...")
if(str)
str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
else{
this.debug(f,0,"str is false, so I could not QueryInterface the str var's value");
return false;
}
if (str)
pasteText = str.data.substring(0,strLength.value / 2);
else{
this.debug(f,0,"str is false, so I could not grab the js string from clipboard");
return false;
}
this.debug(f,0,"Js string to be pasted: "+pasteText)
this.insertString(pasteText)
return pasteText;
}
var mozileCopy = mozile.rootCommandList.createCommand("MozileCommand: id=Mozile-Copy, label=Copy, tooltip='Copy selection', accelerator='Command-C', image='"+mozile.root+"images/copy.png'");
mozileCopy.command = function() {
var f = new Array();
f["File"] = "CopyCutPaste/CopyCutPaste.js";
f["Function"] = "mozileCopy.command";
this.debug(f,0,"START");
mozile.doCopy();
}
var mozileCut = mozile.rootCommandList.createCommand("MozileCommand: id=Mozile-Cut, label=Cut, tooltip='Cut selection', accelerator='Command-X', image='"+mozile.root+"images/cut.png'");
mozileCut.command = function() {
var f = new Array();
f["File"] = "CopyCutPaste/CopyCutPaste.js";
f["Function"] = "mozileCut.command";
this.debug(f,0,"START");
mozile.doCut();
}
var mozilePaste = mozile.rootCommandList.createCommand("MozileCommand: id=Mozile-Paste, label=Paste, tooltip='Paste selection', accelerator='Command-V', image='"+mozile.root+"images/paste.png'");
mozilePaste.command = function() {
var f = new Array();
f["File"] = "CopyCutPaste/CopyCutPaste.js";
f["Function"] = "mozilePaste.command";
this.debug(f,0,"START");
mozile.doPaste();
}
mozile.registerModule("CopyCutPaste","0.0.1");
Documentation generated by
JSDoc on Thu Feb 2 14:36:27 2006