截至 Firefox 32 ,为你的加载项存储数据的地方应该是: [profile ] / extension-data / [add-on ID] 。这是通过错误915838 - 为附件提供一个标准目录来存储数据,设置。有一个后续错误,错误952304 - (JSONStore)JSON存储API的插件用于存储数据和设置,这应该提供一个API以方便访问。
对于Addon-SDK,您可以获取插件ID(你可以在 package.json 中定义):
let self = require(sdk / self ); 让addonID = self.id;对于XUL和重新启动的扩展,您应该能够获得您的插件的ID在 install.rdf 文件中):
Components.utils.import(resource:/ /gre/modules/Services.jsm); 让addonID = Services.appInfo.ID然后您可以执行以下操作来生成该目录中的文件的URI:
userProfileDirectoryPath = Components.classes [@ mozilla/file/directory_service;1 ] .getService(Components.interfaces.nsIProperties) .get(ProfD,Components.interfaces.nsIFile).path, $ b $ / ** *在首选项 *目录下为扩展名的数据目录中的文件名生成URI。 * / 函数generateURIForFileInPrefExtensionDataDirectory(fileName){ //考虑路径分隔符依赖于操作系统 let toReturn =file://+ userProfileDirectoryPath.replace(/ \\\/G,/); return toReturn +/ extension-data /+ addonID +/+ fileName; $ b对象 myExtension.addonData 是我存储的 Bootstrap数据的副本提供给 bootstrap.js 。
I am working on a Firefox add-on which among other stuff generates thumbnails of websites for use by the add-on. So far I've been storing them by their image data URL using simple-storage. Two problems with this: the storage space is limited and sending very long strings around doesn't seem optimal(I assume the browser has optimized ways of loading image files, but maybe not data URLs). I think it shouldn't be a problem to save the files to disk, the question is where though. I googled quite a bit and could not find anything. Is there a natural place for this? Are there any restrictions?
解决方案As of Firefox 32, the place to store data for your add-on is supposed to be: [profile]/extension-data/[add-on ID]. This was established by the resolution of "Bug 915838 - Provide add-ons a standard directory to store data, settings". There is a follow-on bug, "Bug 952304 - (JSONStore) JSON storage API for addons to use in storing data and settings" which is supposed to provide an API for easy access.
For the Addon-SDK, you can obtain the addon ID (which you define in package.json) with:
let self = require("sdk/self"); let addonID = self.id;For XUL and restartless extensions, you should be able to get the ID of your addon (which you define in the install.rdf file) with:
Components.utils.import("resource://gre/modules/Services.jsm"); let addonID = Services.appInfo.IDYou can then do the following to generate a URI for a file in that directory:
userProfileDirectoryPath = Components.classes["@mozilla/file/directory_service;1"] .getService( Components.interfaces.nsIProperties) .get("ProfD", Components.interfaces.nsIFile).path, /** * Generate URI for a filename in the extension's data directory under the preferences * directory. */ function generateURIForFileInPrefExtensionDataDirectory (fileName) { //Account for the path separator being OS dependent let toReturn = "file://" + userProfileDirectoryPath.replace(/\\/g,"/"); return toReturn +"/extension-data/" + addonID + "/" + fileName; } }The object myExtension.addonData is a copy that I store of the Bootstrap data provided to entry points in bootstrap.js.
更多推荐
在哪里保存Firefox插件的文件?
发布评论