Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Web activity] Please don't do postError when page visibility is changed.

10 views
Skip to first unread message

Alive Kuo

unread,
Jun 18, 2013, 8:15:10 AM6/18/13
to dev-...@lists.mozilla.org, Fabrice Desré
Hi,

We're working on a small fix on web activity.

TL; DR: Please don't use the page visibility pattern for the case inline activity is closed/killed when bug 853759 is landed.
Like this:

/* Don't need to do this!! */
64 // When the app is being closed or killed, we will cancel the pending
65 // request.
66 document.addEventListener('mozvisibilitychange', function visibility(e) {
67 if (!document.mozHidden || !activityRequest)
68 return;
69
70 activityRequest.postError('canceled');
71 activityRequest = null;
72 });



The story begins from Bug 846262 - [OPEN_][camera]camera can not use when do some operations in contacts.(617002041478) (https://bugzilla.mozilla.org/show_bug.cgi?id=846262) - and we find that several apps, running as inline activity, are canceling(call activity.postError) the activity request when they observe visibilitychange event.
I see some comments are above these codes: 'Cancel the activity when app is closed/killed.'
However, use 'visibilitychange' event is not a good idea for this purpose!
It results that we, in system app, could not put correct visibility on inline activities when there're multiple inline activities. (See https://bugzilla.mozilla.org/show_bug.cgi?id=846850#c8 for detail.)

Use case:
Dialer=>Open a 'new Contact' activity to Contact, Contact=>open a 'pick photo' activity to Camera.

The visible state should be:
(A)

----TOP----
Camera(activity) visible=true
Contact(activity) visible=false
Dialer(app) visible=false
----BOTTOM----

But now it's

(B)
----TOP----
Camera(activity) visible=true
Contact(activity) visible=true
Dialer(app) visible=false
----BOTTOM----


Because contact needs to do postError() to let the Dialer knows it's removed by some reason(by system app in case another app is opened now).
And the only way to know it's close is mozvisibilitychange event or window.onunload

If I correct the visible state to (A) without doing anything to Contact app,
when camera is triggered by activity request from contact:

(C)
----TOP----
Contact(activity) visible=true => click add a photo to trigger another activity
Dialer(app) visible=false
----BOTTOM----

(D)

----TOP----
Camera(activity) visible=true
Contact(activity) visible=true------>false by system app------>knows visibilitychange---->close itself by postError----> implictly remove itself------> the activity chain is broken.
Dialer(app) visible=false
----BOTTOM----

Therefore we have Bug 846850 - [Unagi][Camera][Activity][Contacts] App doesn't get 'mozvisibilitychange' event when running as an activity (https://bugzilla.mozilla.org/show_bug.cgi?id=846850) and Bug 880588 - [System] inline activities are removed when locked (https://bugzilla.mozilla.org/show_bug.cgi?id=880588)

After discussion, we would do postError for the app when it's removed in gecko, at Bug 853759 - [activities] fire postError when unloading the app before we have fired anything(https://bugzilla.mozilla.org/show_bug.cgi?id=853759).

So you don't need to do it when your app, running as inline activity, is closed/remove/crashed. Please don't use the page visibility pattern for this purpose from now on.
I will remove all these kind of codes in my patch for bug 880588.

Thanks :fabrice for gecko part support!
--
Alive C. Kuo, Front-end Eng., Mozilla Corp. (Taiwan, Taipei)







0 new messages