On Wed, Dec 23, 2015 at 4:37 AM, Marcello Stanisci <
marcello.stani...@inria.fr> wrote:

> Hi list,
>
> Would it be possible to emulate what the 'backgroud' page does
> in the context of a "normal" Firefox extension by using Web workers?
>
> In detail, WebExtensions dictates that each extension has a background
> thread which runs independently of its foreground counterpart, and that
> they notify each other by sending messages.
>

There are a couple different contexts in which WebExtensions run code:
1. background page
2. popups for things like browser actions and page actions
3. content scripts

#1 and #2 run on the same thread; they can access each other's global
variables directly via functions like getBackgroundPage and getViews. #3
potentially runs in a different process from #1 and #2, so it's a bit
different.


> Web workers are quite the same thing: independent threads which can
> send/receive messages to/from their creators.
>
> So it seems "natural" to have a Web worker active for the extension's
> lifetime which behaves the same way a WebExtension's background script
> does.
>

You could create a Web worker in a WebExtension. But it would be different
from a background page. For one thing, a background page has a normal DOM
even though it's not displayed. So it has access to the full set of DOM
APIs rather than the restricted set available to workers.


> Which kind of problems may arise in implementing the WebExtension's
> semantics in a traditional Firefox extension?
>

Everything WebExtensions do is available to legacy extensions. Our
implementation of WebExtensions is entirely JS code using XPCOM. If you're
interested in how background pages are created, you might look at the
createWindowlessBrowser API:
https://dxr.mozilla.org/mozilla-central/source/xpfe/appshell/nsIAppShellService.idl#56


> Is there any exmple to look at which already does that?
>

You can look at our implementation of background pages:
https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ext-backgroundPage.js#22

I'm not sure if this answers your question. I hope it helps.

-Bill


>
> Thanks
> Marcello
> _______________________________________________
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to