-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcae35a
commit a51d1f6
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
files/zh-cn/mozilla/add-ons/webextensions/api/pkcs11/installmodule/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
title: pkcs11.installModule() | ||
slug: Mozilla/Add-ons/WebExtensions/API/pkcs11/installModule | ||
l10n: | ||
sourceCommit: 43e3ff826b7b755b05986c99ada75635c01c187c | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
安装指定的 PKCS #11 模块,使其对 Firefox 可用。 | ||
|
||
这是一个异步函数,返回 [`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise)。 | ||
|
||
## 语法 | ||
|
||
```js-nolint | ||
let installing = browser.pkcs11.installModule( | ||
name, // 字符串 | ||
flags // 整型 | ||
) | ||
``` | ||
|
||
### 参数 | ||
|
||
- `name` | ||
- : `string`,要安装的模块名称。这需要与模块的 [PKCS #11 清单](/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#pkcs_11_清单)中的 `name` 属性相匹配。 | ||
- `flags` {{optional_inline}} | ||
- : `integer`,传递给模块的标志位。 | ||
|
||
### 返回值 | ||
|
||
当模块安装完成后,会返回一个没有参数兑现的 [`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise)。 | ||
|
||
若无法找到模块或发生其他错误,该 Promise 将被拒绝并返回一个错误消息。 | ||
|
||
## 浏览器兼容性 | ||
|
||
{{Compat}} | ||
|
||
## 示例 | ||
|
||
安装一个模块并列出其插槽及其包含的令牌: | ||
|
||
```js | ||
function onInstalled() { | ||
return browser.pkcs11.getModuleSlots("my_module"); | ||
} | ||
|
||
function onGotSlots(slots) { | ||
for (const slot of slots) { | ||
console.log(`插槽:${slot.name}`); | ||
if (slot.token) { | ||
console.log(`包含令牌:${slot.token.name}`); | ||
} else { | ||
console.log("为空"); | ||
} | ||
} | ||
} | ||
|
||
browser.pkcs11.installModule("my_module").then(onInstalled).then(onGotSlots); | ||
``` | ||
|
||
{{WebExtExamples}} |