nsIInstallLocation 编辑

toolkit/mozapps/extensions/public/nsIExtensionManager.idlScriptable Interface representing a location where extensions, themes and so on are installed. 1.0 66 Introduced Gecko 1.8 Obsolete Gecko 2.0 Inherits from: nsISupports Last changed in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) Note: While this API still works, Firefox 4 no longer extracts XPIs by default, so this will now point to the XPI file instead of to the directory. Any nsIFile operations that assume a directory and plain files will fail in Firefox 4, unless you specify <em:unpack>.

You can get the install location of a particular add-on using nsIExtensionManager interface:

var il = Components.classes["@mozilla.org/extensions/manager;1"]
                   .getService(Components.interfaces.nsIExtensionManager)
                   .getInstallLocation("add-on id")

Method overview

AString getIDForLocation(in nsIFile file);
nsIFile getItemFile(in AString id, in AString path);
nsIFile getItemLocation(in AString id);
nsIFile getStageFile(in AString id);
boolean itemIsManagedIndependently(in AString id);
void removeFile(in nsIFile file);
nsIFile stageFile(in nsIFile file, in AString id);

Attributes

AttributeTypeDescription
canAccessbooleanWhether or not the user can write to the Install Location with the current access privileges. This is different from restricted because it's not whether or not the location *might* be restricted, it's whether or not it actually *is* restricted right now. Read only.
itemLocationsnsIDirectoryEnumerator

An enumeration of nsIFiles for:

  • Locations that contain items
  • Potential dropped-in XPIs
Note: This enumeration resolves Text Links to the directories they refer to. Read only.
locationnsIFile

The file system location where items live. Items can be dropped in at this location. Can be null for Install Locations that don't have a file system presence.

Note: This is a clone of the actual location which the caller can modify freely. Read only.
nameAStringThe string identifier of this Install Location. Read only.
prioritylongThe priority level of this Install Location in loading. Read only.
restrictedbooleanWhether or not this Install Location is on an area of the file system that could be restricted on a restricted-access account, regardless of whether or not the location is restricted with the current user privileges. Read only.

Constants

Constants representing priority of some default Install Locations. You should not use the exact values here, you should offset from these values each time you create a new Install Location. Offsetting can be brittle but you should know what Install Locations are being defined for your own application.

ConstantValueDescription
PRIORITY_APP_PROFILE0 
PRIORITY_APP_SYSTEM_USER10 
PRIORITY_XRE_SYSTEM_USER100 
PRIORITY_APP_SYSTEM_GLOBAL1000 
PRIORITY_XRE_SYSTEM_GLOBAL10000 

Methods

getIDForLocation()

Retrieves the GUID for an item at the specified location.

Note: This function makes no promises about whether or not this path is actually maintained by this Install Location.
AString getIDForLocation(
  in nsIFile file
);
Parameters
file
The location where an item might live.
Return value

The ID for an item that might live at the location specified.

getItemFile()

Gets a nsIFile object for a file within an item's directory structure.

nsIFile getItemFile(
  in AString id,
  in AString path
);
Parameters
id
The GUID of the item.
path
The path to the file beneath an Extension's directory.
Return value

A file object at the requested location. The file does not necessarily have to exist.

getItemLocation()

Gets the directory that contains an item.

nsIFile getItemLocation(
  in AString id
);
Parameters
id
The GUID of the item.
Return value

The location of the item.

getStageFile()

Returns the most recently staged package (for example the last XPI or JAR in a directory) for an item and removes items that do not qualify.

nsIFile getStageFile(
  in AString id
);
Parameters
id
The ID of the staged package.
Return value

An nsIFile if the package exists otherwise null.

itemIsManagedIndependently()

Determines whether or not an item's resources are managed by the Extension System or by some other user or process. For example, items linked to by text links are managed by the user, and items linked to from Registry Install Locations are usually managed by other applications or installers.

boolean itemIsManagedIndependently(
  in AString id
);
Parameters
id
The GUID of the item.
Return value

true if the item's resources are managed independently of the Extension System, false otherwise.

removeFile()

Removes a file from the stage. This cleans up the stage if there is nothing else left after the remove operation.

void removeFile(
  in nsIFile file
);
Parameters
file
The file to remove.

stageFile()

Stages the specified file by copying it to some location from where it can be retrieved later to complete installation.

nsIFile stageFile(
  in nsIFile file,
  in AString id
);
Parameters
file
The file to stage.
id
The GUID of the item the file represents.
Return value

The staged file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:24 次

字数:10826

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文