ChromeWorker 编辑
Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
Summary
If you're developing privileged code, and would like to create a worker that can use js-ctypes to perform calls to native code, you can do so by using ChromeWorker
instead of the standard Worker
object. It works exactly like a standard Worker
, except that it has access to js-ctypes via a global ctypes
object available in the global scope of the worker. Examples of ChromeWorker's using js-ctypes are availabe on Github and are linked to from the See Also section below. To use a postMessage with callback version of ChromeWorker that features promises, see PromiseWorker.
Addons must use absolute URLs to load their workers, and those URLs have to be using a chrome://
or resource://
protocol (file://
is not accepted). Addons that wish to use file://
URLs must first register a resource replacement path, using code like this:
var fileuri = Services.io.newFileURI(file);
Services.io.getProtocolHandler('resource').
QueryInterface(Ci.nsIResProtocolHandler).
setSubstitution('my-cool-addon', fileuri);
var worker = new Worker('resource://my-cool-addon/worker.js');
More references:
- You can use
ChromeWorker
from JavaScript code modules. See Using workers in JavaScript code modules for details. - You can use ChromeWorker modules in ChromeWorkers.
- See Using web workers for examples and details.
See Also
- Using web workers
- Using workers in JavaScript code modules
Worker
SharedWorker
- Web Workers specification
WorkerGlobalScope
- GitHub :: ChromeWorker - A fully working demo addon using js-ctypes from a chrome worker. Uses WinAPI example.
- PromiseWorker
- GitHub :: PromiseWorker - Shows how to uses promises as an twist on postMessage feature of ChromeWorker
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论