Thanks a lot for starting this conversation!
On 2013-08-12 9:25 PM,
nsm.n...@gmail.com wrote:
> Hi everyone,
>
> (Background: [1], [2], [3])
> (Tracking bug:
https://bugzil.la/903441)
>
> Here are my thoughts after experimenting with SharedWorker code and writing the first bits of the event page code. Feedback is appreciated before I proceed with more work. What I've got now is on the bug. Just a note, SharedWorker hasn't landed yet.
>
> The core idea is to have a worker like thing, that can run a script in a separate thread, but unlike SharedWorkers, the lifetime of the script is not bound to the lifetime of windows that hold a reference to it.
>
> In addition, it should be possible to start this script on its own, from chrome code, on the basis of certain information supplied by another WebAPI, or from the manifest in case of apps.
>
> Event Pages or Background Service?
> ----------------------------------
> The reason I ask is Event pages are something that are short lived. But the moment such a page is allowed to have MessagePorts to user visible web pages, or can be created by content code, they'll be long running. Should this be allowed or should we enforce a distinction and require that developers use SharedWorkers for the later case?
I think we should try to make the lifetime of the page controllable by
the UA if possible. In other words, the event page should expect to get
killed by the UA at any time. We can do that by breaking the
MessagePort references to the event page held by normal content pages
when the event page goes away. I think it would be a very bad idea to
make those references strong, since that would mean that if the author
forgets to release those references when they no longer need the event
page, we may render ourselves unable to kill the event page.
> In addition, if NavigationController intends to use these, they may or may not be long running depending on what is requested for download (a video file for example).
For NavigationController, the controller should assume that it will get
killed after handling every single request. In fact I'm planning to add
that as a debugging option to catch content which has assumptions about
its lifetime.
> I see no technical reason not to allow long running pages, I just want to clear the nomenclature.
If we leave the lifetime management of the event pages to the UA, we can
make intelligent choices on when to kill the event page based on things
like whether there are MessagePorts accessing it, whether it belongs to
a foreground/background app, whether we're low on system resources, etc.
Therefore, event pages may or may not be long running, I don't see why
we should clarify it further.
> A copy of my local notes:
> -------------------------
>
> A Event Page:
> - Can run with no user visible normal HTML pages open.
> - Can run with zero MessagePorts to the above pages.
> - Runs in the same process as the application (on B2G)
One thing that is not clear to me is the origin/process mapping. How do
you plan to handle the case where two processes render same origin
content, and they want to access a shared event page? Note that this
could happen both in Firefox OS and on desktop Firefox with e10s.
> - Separate thread. It *is* a Worker as far as implementation goes, so it inherits all those properties.
> - Should be able to query user agent for currently user-visible same-origin pages that are open.
> - Should receive events when user-visible same-origin pages open or close, with MessagePorts to them (SharedWorker onconnect, perhaps supplemented with ondisconnect?)
> - Should be able to *launch* a new tab/app (This will need to be done right, and require UX support, and possibly another permission)
> - Should be able to be started by the platform
> - Should be able to receive system messages
Another issue, did we decide that we want event pages to run in a worker
context, as opposed to a regular `window' context?
> Event Pages are killed/unloaded when they've been idle (no incoming events) for a small interval (of course, there should be no windows holding references to it.) So XHR and timers will hold pages alive, as will other async APIs that get ported to workers. An event page may also call close() on itself (from the Worker spec).
This doesn't seem like what we want. What if the event page creates a
timer but never destroys it? The way this paragraph is phrased it would
seem like we could never kill such a page.
> In addition, an event page may be immediately unloaded/suspended if:
> * Low memory and it is not part of the foreground app.
> * Process priority is lowered by scheduler
> These two are likely to apply to B2G only, but will require thought about how the process priority is affected (Prior art [4]).
Agreed, however I think we should hide these heuristics under the "UA
gets the say on the lifetime" rule.
> Based on the current SharedWorker spec and patch [5], much of the common ground is implemented, the difference is:
> * Event Page lifecycle is not bound strongly to windows, while SharedWorker's is.
> * An Event Page, unlike workers, is *not suspended/resumed* based on all refering windows being suspended/resumed. That is, event page timers will not stop even if all DOM windows that hold a reference to it are suspended, while SharedWorker's will be.
I wanted to ask clarification on this second point, but that sort of
depends on your answer to the timer issue I raised above. :-)
Cheers,
Ehsan
> _______________________________________________
> dev-webapi mailing list
>
dev-w...@lists.mozilla.org
>
https://lists.mozilla.org/listinfo/dev-webapi
>