救命!当我尝试 Mozilla 的 Validator 时在我的插件上,它出现以下与我对剪贴板使用的处理相关的错误:
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 theinit
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);};
我无法理解这个。
这是我的代码 - 我显然正在调用 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");
我还尝试了 Mozilla example here 的 Transferable
功能,但得到相同的非验证报告。
一位 Mozilla AMO 编辑告诉我要这样写,但它仍然无法验证。
我也尝试过,简单地说:
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");
验证器不会报告任何错误 - 仅报告此警告。一切正常。 Mozilla 更新了他们的 Gecko 引擎,他们希望开发者能够符合新标准。
在我的使用中,我们也希望能够使用可能从应用程序外部获取的剪贴板内容,因此我们确实希望使用 null
来调用 init 函数,而不是窗口
。
任何建议都会很棒!
最佳答案
trans.init(null)
在某些情况下有效,例如您的情况。如果在错误的情况下使用,它还可能导致隐私泄露,因此验证器会将其所有使用标记为可能需要更改。因此,在这种情况下,您可以忽略该警告。
关于firefox-addon - 为什么此剪贴板代码无法通过 Mozilla 验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14533593/