2

Salve! When I try Mozilla's Validator on my addon, it get the following error related to my treatment of clipboard usage:

nsITransferable has been changed in Gecko 16.

Warning: The nsITransferable interface has changed to better support Private Browsing Mode. After instantiating the object, you should call the init function on it before any other functions are called. See https://developer.mozilla.org/en-US/docs/Using_the_Clipboard for more information.

var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if ('init' in trans){ trans.init(null);};

I can't understand this.

Here is my code - I am clearly calling trans.init:

var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
if (!clip) return "";

var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if ('init' in trans){ trans.init(null);};  //<--IT DOESN'T LIKE THIS
if (!trans) return false;
trans.addDataFlavor("text/unicode");

I've also tried the Transferable function from Mozilla's example here, but get the same non-validation report.

One of the Mozilla AMO editors told me to write exactly this, and it still doesn't validate.

I've also tried, simply:

var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
trans.init(null);   //<---LOOK HERE
if (!trans) return false;
trans.addDataFlavor("text/unicode");

The Validator does not report any errors - just this warning. Everything works properly. Mozilla updated their Gecko engine, and they want devlopers to match up to the new standard.

In my usage, we want to be able to use the contents of the clipboard that was probably gotten from outside the application, too, so we do want to call the init function with null instead of window.

Any advice would be wonderful!

bgmCoder
  • 6,205
  • 8
  • 58
  • 105
  • Getting data from clipboard is not affected by the privacy status of Firefox. – paa Jan 27 '13 at 17:09
  • Okay, so, uh, well, I'm not sure how that is helpful, but, thanks, I guess. – bgmCoder Jan 27 '13 at 21:11
  • You wrote that your code reads the clipboard contents. Then passing a loading context, instead of null, to the init function will keep the validator happy without hindering your access to clipboard. – paa Jan 27 '13 at 22:27
  • @paa Thanks, but I've tried `if ('init' in trans){ trans.init(window);};` but I still get the validation error. – bgmCoder Jan 28 '13 at 00:40

1 Answers1

2

trans.init(null) is valid in some circumstances, such as yours. It can also cause privacy leaks if used in the wrong circumstances, so the validator flags all uses of it as potentially requiring changing. Therefore, it is a warning that you can ignore in this case.

Josh Matthews
  • 12,816
  • 7
  • 36
  • 39
  • Thank you very much. One of the AMO Editors told me I could wrap it in a try - catch sequence and ignore it, too, but he never told me why I could ignore it. – bgmCoder Feb 14 '13 at 16:08