插件与 Firefox 48 的兼容性

Addons Compatibility with Firefox 48

我有一个插件可以正常工作直到 FF 47.I 知道使用 e10s FF 48,它有一些兼容性问题。这里是我认为受浏览器的新多进程模型影响的代码行的简要列表:

1.let { Cc, Ci } = require('chrome'); 

2.const { Cu } = require("chrome");

3.require("sdk/tabs").on("ready",logURL);

4.Cu.import("resource://gre/modules/FileUtils.jsm"); 

5.const {TextDecoder, TextEncoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {}); 

6. file = FileUtils.getFile("Home", [".cp.txt"]); //reopen the file just saved 

7. var txt = ""; 
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream); 
var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream); 
fstream.init(file, -1, 0, 0); cstream.init(fstream, "UTF-8", 0, 0); let str = {}; 
let read = 0; 
do { 
read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value 
txt += str.value; 
} while (read != 0); 
cstream.close(); // this closes fstream // use 0x02 | 0x10 to open file for appending. // save the domain option in file 
foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0); 
converter.init(foStream, "UTF-8", 0, 0); 
var sEP = txt + '\n' + 'h' + '\n'; // encrypt new path converter.writeString(sEP); converter.close(); // this closes foStream 
console.log('saved h'); }

首先,我需要知道,如果所有这些元素在新 FF 中都存在问题(我很确定 6 和 7 不兼容——XUL 和 XPCOM 已经过时并且在同一个线程上工作——,但对于其他行不太确定),最后是否有 48 版本的代理构造以解决相同的问题(input/output 等等)。特别是,附加组件必须使用选项卡机制(用于读取选项卡的 URL)。谢谢您的帮助。

None 这些问题都是e10s相关的,都是es6和xpcom的问题。

如果你在框架脚本中使用它,那么它是一个 e10s 问题,但是我避免在框架脚本中使用 xpcom,尝试使用从框架脚本到 bootstrap 的消息传递,例如 - https://github.com/Noitidart/CommPlayground

回复 1 和 2:如果您没有在 require 编辑的脚本中使用 Cu Ciletconst 就可以了。

回复 7:不要这样做,它很快就会被弃用,并且不是主要 ui 友好的。它可以锁定它。使用 OS.File.

回复 4 和 6:我建议做 Services.dirsvc.get('Home', Ci.nsIFile).path;。这是 XPCOM,但它使用的是通用的 Services.jsm 模块,该模块不太可能被弃用。此外,Services.dirsvc.get 缓存文件,因此它比 FileUtils 快得多。但是,理想情况下,您应该使用导入 osfile.jsm 时出现的 OS.Path.joinOS.Constants.Path。所以你会做 OS.Path.join(OS.Constants.Path.homeDir, '.cp.txt') - 尽量避免使用 XPCOM。

回复 3:没问题。