QueryInterface(cinsIFileURL)什么都不返回 - Firefox扩展

时间:2016-05-10 07:41:11

标签: firefox firefox-addon firefox-addon-sdk

我正在关注一些使用js-ctypes在firefox扩展中加载dll的示例。它的工作原理除以下代码外:

var self = require("sdk/self");
var {Cc, Ci, Cu} = require('chrome');
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://gre/modules/Services.jsm");
const ResProtocolHandler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
var data = self.data;
var dataUrl = data.url("MyBin.dll");
var file = Services.io.newURI(dataUrl, null, null);
console.log(file);
file = ResProtocolHandler.resolveURI(file);
console.log(file);
file = Services.io.newURI(file, null, null);
console.log(file);
file = file.QueryInterface(Ci.nsIFileURL);
console.log(file);

我得到的如下:

console.log: smartt: {"spec":"resource://smartt/data/MyBin.dll","prePath":"resource://smartt","scheme":"resource","userPass":"","username":"","password":"","hostPort":"smartt","host":"smartt","port":-1,"path":"/data/MyBin.dll","asciiSpec":"resource://smartt/data/MyBin.dll","asciiHostPort":"smartt","asciiHost":"smartt","originCharset":"UTF-8","ref":"","specIgnoringRef":"resource://smartt/data/MyBin.dll","hasRef":false}
console.log: smartt: file:///C:/Users/dipto/AppData/Local/Temp/417dcdc0-7016-4975-8344-4c43fe7cc83c/extensions/@smartt/data/MyBin.dll
console.log: smartt: {"spec":"file:///C:/Users/dipto/AppData/Local/Temp/417dcdc0-7016-4975-8344-4c43fe7cc83c/extensions/@smartt/data/MyBin.dll","prePath":"file://","scheme":"file","userPass":"","username":"","password":"","hostPort":"","host":"","port":-1,"path":"/C:/Users/dipto/AppData/Local/Temp/417dcdc0-7016-4975-8344-4c43fe7cc83c/extensions/@smartt/data/MyBin.dll","asciiSpec":"file:///C:/Users/dipto/AppData/Local/Temp/417dcdc0-7016-4975-8344-4c43fe7cc83c/extensions/@smartt/data/MyBin.dll","asciiHostPort":"","asciiHost":"","originCharset":"UTF-8","ref":"","specIgnoringRef":"file:///C:/Users/dipto/AppData/Local/Temp/417dcdc0-7016-4975-8344-4c43fe7cc83c/extensions/@smartt/data/MyBin.dll","hasRef":false}
console.log: smartt: {spec:..,prePath:..,scheme:..,userPass:..,username:..,password:..,hostPort:..,host:..,port:..,path:..,equals:..,schemeIs:..,clone:..,resolve:..,asciiSpec:..,asciiHostPort:..,asciiHost:..,originCharset:..,ref:..,equalsExceptRef:..,cloneIgnoringRef:..,specIgnoringRef:..,hasRef:..,filePath:..,query:..,directory:..,fileName:..,fileBaseName:..,fileExtension:..,getCommonBaseSpec:..,getRelativeSpec:..,file:.., }

如您所见,最后一个输出为空。我期待一个文件网址。我的目标是获取资源文件的本地文件路径。

有人请告诉我我做错了什么吗?我错过了一些非常愚蠢的东西吗?

0 个答案:

没有答案