nsICacheService 在 Firefox 38 中不起作用
nsICacheService doesn't work in Firefox 38
我用
Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
在开发 Firefox 扩展时操作 http 缓存。
但是我升级到Firefox 38 esr后,这个接口在调用它的函数时会报错
[Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsICacheService.visitEntries]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)"
而且我没有发现它在 MDN 中已过时,所以有人知道为什么吗?非常感谢。
我试过这段代码,它抛出:(在浏览器环境的 scratcpad 中复制粘贴 运行 - https://www.youtube.com/watch?v=oo4STWceGTM)
var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
console.log('cacheService:', cacheService);
function CacheVisitor(){}
CacheVisitor.prototype = {
QueryInterface : function(iid)
{
if (iid.equals(Ci.nsICacheVisitor))
return this;
throw Components.results.NS_NOINTERFACE;
},
visitDevice : function(deviceID, deviceInfo)
{
console.log("[visiting device (deviceID = ", deviceID ,", description = ", deviceInfo.description ,")]");
return true;
},
visitEntry : function(deviceID, entryInfo)
{
console.log("[visiting entry (clientID = ", entryInfo.clientID, "key = ", entryInfo.key, ")]");
return true;
}
};
var visitor = new CacheVisitor();
cacheService.visitEntries(visitor); // throws on this line here!!!
它在行 cacheService.visitEntries(visitor); // throws on this line here!!!
上抛出它抛出这个:
/*
Exception: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsICacheService.visitEntries]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: Scratchpad/1 :: <TOP_LEVEL> :: line 27" data: no]
*/
这与您遇到的问题相同。你能验证一下吗,我没有看到你的可重现代码。
http://code.metager.de/source/xref/mozilla/firefox/netwerk/cache/nsICacheService.idl
这看起来像是一个提示
* @throws NS_ERROR_NOT_IMPLEMENTED 当首选使用缓存 v2 时。
https://bugzilla.mozilla.org/show_bug.cgi?id=913807
我认为我们需要做的就是将
这一行中的 1 更改为 2
var cacheService = cc["@mozilla.org/network/cache-service;1"]
.getService(ci.nsICacheService);
我用
Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
在开发 Firefox 扩展时操作 http 缓存。
但是我升级到Firefox 38 esr后,这个接口在调用它的函数时会报错
[Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsICacheService.visitEntries]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)"
而且我没有发现它在 MDN 中已过时,所以有人知道为什么吗?非常感谢。
我试过这段代码,它抛出:(在浏览器环境的 scratcpad 中复制粘贴 运行 - https://www.youtube.com/watch?v=oo4STWceGTM)
var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
console.log('cacheService:', cacheService);
function CacheVisitor(){}
CacheVisitor.prototype = {
QueryInterface : function(iid)
{
if (iid.equals(Ci.nsICacheVisitor))
return this;
throw Components.results.NS_NOINTERFACE;
},
visitDevice : function(deviceID, deviceInfo)
{
console.log("[visiting device (deviceID = ", deviceID ,", description = ", deviceInfo.description ,")]");
return true;
},
visitEntry : function(deviceID, entryInfo)
{
console.log("[visiting entry (clientID = ", entryInfo.clientID, "key = ", entryInfo.key, ")]");
return true;
}
};
var visitor = new CacheVisitor();
cacheService.visitEntries(visitor); // throws on this line here!!!
它在行 cacheService.visitEntries(visitor); // throws on this line here!!!
上抛出它抛出这个:
/*
Exception: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsICacheService.visitEntries]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: Scratchpad/1 :: <TOP_LEVEL> :: line 27" data: no]
*/
这与您遇到的问题相同。你能验证一下吗,我没有看到你的可重现代码。
http://code.metager.de/source/xref/mozilla/firefox/netwerk/cache/nsICacheService.idl
这看起来像是一个提示 * @throws NS_ERROR_NOT_IMPLEMENTED 当首选使用缓存 v2 时。
https://bugzilla.mozilla.org/show_bug.cgi?id=913807
我认为我们需要做的就是将
这一行中的 1 更改为 2var cacheService = cc["@mozilla.org/network/cache-service;1"] .getService(ci.nsICacheService);