-
Notifications
You must be signed in to change notification settings - Fork 263
JEP HTMLView
HTMLView is meant to be an Abstraction class from which UI classes can all sub-class.
Many SDK modules provide UI real estate which can be filled with HTML content, such as widget
, panel
, sidebar
, toolbar
, and addon-page
. In the past one would typically need to use a content script in order to pass messages between the HTML content and the add-on. Since the requirement of a content script
means the developer must use a new file or create a string with code in it..
With HTMLView
s a developer will be able to communicate back to the add-on via an addon
global provided to it, bypassing the need for any content script and standardizing some common events these UI modules have in common.
Since each implementation of an HTMLView
will involve using windows which will be available at different points in time.
- options
- url
- on/off/once
- attach
- show/hide
lib/main.js
const { HTMLView } = require('sdk/ui/html-view');
let view = HTMLView({ url: require('self').data.url('index.html') });
view.on('attach', function(worker) {
worker.port.on('message', function(msg) {
console.log(msg) // logs hi world!
})
worker.postMessage('hi ')
})
data/index.html
worker.onMessage(function(msg) {
worker.port.emit('message', msg + 'world!')
});
-
content/worker
: the content worker will be used to create theaddon
global and the enable the message passing. - Some window will need to be provided in order to load the url provided to the constructor.
sdk/page-mod
sdk/content/worker
sdk/panel