Closed Bug 1013671 Opened 10 years ago Closed 10 years ago

Use SystemAppProxy to fire "system-messages-open-app" from SystemMessageInternal.js

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla32

People

(Reporter: airpingu, Assigned: selin)

References

Details

Attachments

(1 file, 2 obsolete files)

Bug 908191 inspires me we should use SystemAppProxy to fire "system-messages-open-app" from SystemMessageInternal.js, instead of calling the notifyObservers() to notify the shell.js.

Fabrice, if my understanding on the SystemAppProxy is correct, that's something we should polish. Right? Also, the shell.js is listening to lots of observer topics for sendCustomEvent too, which are all supposed to be done through the SystemAppProxy in the long-term. Right?

Sean, this might be another good first bug you can support.
Flags: needinfo?(fabrice)
We can do that on b2g, but I'm worried about other runtimes that may want to enable system messages, like Android.

We do all the buffering of messages in shell.js too, I'm not sure yet if we should move that somewhere else.
Flags: needinfo?(fabrice)
(In reply to Fabrice Desré [:fabrice] from comment #1)
> We can do that on b2g, but I'm worried about other runtimes that may want to
> enable system messages, like Android.

But the 'system-messages-open-app' is designed for asking the System App (window_manager) to open other apps, which implies there must be a System App listening to it. We haven't yet considered other paths (like Android) for non-system-app scenarios so I think it's OK to do this for 'system-messages-open-app' specifically.

> 
> We do all the buffering of messages in shell.js too, I'm not sure yet if we
> should move that somewhere else.

If we can use SystemAppProxy to fire "system-messages-open-app", another benefit is we might rely on the SystemAppProxy.setIsReady() to pend the chrome events until the system completely boots up, so that we can remove the ugly 10-sec timer for buffering 'system-messages-open-app' messages in shell.js.
Blocks: 793420
(In reply to Gene Lian [:gene] (needinfo? encouraged) from comment #2)
> (In reply to Fabrice Desré [:fabrice] from comment #1)
> > We can do that on b2g, but I'm worried about other runtimes that may want to
> > enable system messages, like Android.
> 
> But the 'system-messages-open-app' is designed for asking the System App
> (window_manager) to open other apps, which implies there must be a System
> App listening to it. We haven't yet considered other paths (like Android)
> for non-system-app scenarios so I think it's OK to do this for
> 'system-messages-open-app' specifically.

It's designed to ask the "runtime UI" to do something. In b2g case it's the system app. That will be something else in other runtimes. 

What about just moving the observer in SystemAppProxy?

> > 
> > We do all the buffering of messages in shell.js too, I'm not sure yet if we
> > should move that somewhere else.
> 
> If we can use SystemAppProxy to fire "system-messages-open-app", another
> benefit is we might rely on the SystemAppProxy.setIsReady() to pend the
> chrome events until the system completely boots up, so that we can remove
> the ugly 10-sec timer for buffering 'system-messages-open-app' messages in
> shell.js.

Yes, we should do that.
(In reply to Fabrice Desré [:fabrice] from comment #3)
> (In reply to Gene Lian [:gene] (needinfo? encouraged) from comment #2)
> > (In reply to Fabrice Desré [:fabrice] from comment #1)
> > > We can do that on b2g, but I'm worried about other runtimes that may want to
> > > enable system messages, like Android.
> > 
> > But the 'system-messages-open-app' is designed for asking the System App
> > (window_manager) to open other apps, which implies there must be a System
> > App listening to it. We haven't yet considered other paths (like Android)
> > for non-system-app scenarios so I think it's OK to do this for
> > 'system-messages-open-app' specifically.
> 
> It's designed to ask the "runtime UI" to do something. In b2g case it's the
> system app. That will be something else in other runtimes. 
> 
> What about just moving the observer in SystemAppProxy?

Just have a quick discussion on the IRC. It makes sense to us to move the observer topics from shell.js into SystemAppProxy. We need to keep the observer mechanism for now because other platforms (like Android) might also need to listen to those observer topics to launch its own runtime UIs in its own way in the future.
Another alternative is we can follow what we've done for:

  b2g/components/ActivitiesGlue.js
  mobile/android/components/ActivitiesGlue.js

to construct different components but with he same interface, then we can call SystemAppProxy's APIs to dispatch chrome events based on the instance of the b2g-specific component. In this way, we don't need to move the observer topic from shell.js to SystemAppProxy.
... just drop the observer topics instead.
We can do that too, it's just a bit more refactoring.
Assignee: nobody → selin
Attached patch Patch v1 (obsolete) — Splinter Review
The patch also fixes Bug 793420 since the logic relevant to these two bugs is interleaved to some extent.
Attachment #8430491 - Flags: review?(gene.lian)
Attachment #8430491 - Flags: review?(fabrice)
Attached patch Patch v2 (obsolete) — Splinter Review
Further removing variable |timer| from shell.js since we no longer need it.
Attachment #8430491 - Attachment is obsolete: true
Attachment #8430491 - Flags: review?(gene.lian)
Attachment #8430491 - Flags: review?(fabrice)
Attachment #8430494 - Flags: review?(gene.lian)
Attachment #8430494 - Flags: review?(fabrice)
Comment on attachment 8430494 [details] [diff] [review]
Patch v2

Review of attachment 8430494 [details] [diff] [review]:
-----------------------------------------------------------------

::: b2g/components/B2GComponents.manifest
@@ +27,5 @@
>  # InterAppCommUIGlue.js
>  component {879ee66c-e246-11e3-9910-74d02b97e723} InterAppCommUIGlue.js
>  contract @mozilla.org/dom/apps/inter-app-comm-ui-glue;1 {879ee66c-e246-11e3-9910-74d02b97e723}
>  
> +# SystemMessagesUIGlue.js

System message doesn't attempt to launch any "UI" stuff, so SystemMessagesUIGlue might not be a good name.

How about SystemMessagesOpenAppGlue or any others better?

::: b2g/components/SystemAppProxy.jsm
@@ +53,5 @@
>     *     event.details == 'bar'
>     *   });
>     */
> +  _sendCustomEvent: function systemApp_sendCustomEvent(type, details,
> +                                                       noPendingUntilReady) {

Would you add some comments about how to use |noPendingUntilReady|? Also, I think |noPending| is enough because you still need to check the codes to realize the meaning of "UntilReady" anyway, so just let comments cover it.

@@ +58,5 @@
>      let content = this._frame ? this._frame.contentWindow : null;
>  
>      // If the system app isn't ready yet,
>      // queue events until someone calls setIsLoaded
> +    if ((!noPendingUntilReady && !this._isReady) || !content) {

Why it's not:

if (!noPendingUntilReady && (!this._isReady || !content)) {

???

::: b2g/components/SystemMessagesUIGlue.js
@@ +9,5 @@
> +const Cu = Components.utils;
> +
> +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
> +Cu.import("resource://gre/modules/Services.jsm");
> +Cu.import("resource://gre/modules/Promise.jsm");

You don't need Promise.

@@ +15,5 @@
> +XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
> +                                  "resource://gre/modules/SystemAppProxy.jsm");
> +
> +const DEBUG = false;
> +function debug(aMsg) {

You didn't use the debug in this file. Add it to one place at least or just remove the debug function.

@@ +34,5 @@
> +                    onlyShowApp: aOnlyShowApp,
> +                    expectingSystemMessage: true,
> +                    extra: aExtra };
> +
> +    // |SystemAppProxy| will queue non-activity events without actually sending

s/non-activity events/'open-app' events for non-activity system messages/

@@ +35,5 @@
> +                    expectingSystemMessage: true,
> +                    extra: aExtra };
> +
> +    // |SystemAppProxy| will queue non-activity events without actually sending
> +    // them until it's set ready.

s/it's/the system app is/

::: dom/messages/SystemMessageInternal.js
@@ +589,5 @@
> +          ", manifestURL: " + aPage.manifestURL + ", type: " + aPage.type +
> +          ", target: " + JSON.stringify(aMessage.target) +
> +          ", showApp: " + showApp + ", onlyShowApp: " + onlyShowApp +
> +          ", extra: " + JSON.stringify(aExtra));
> +    let glue = Cc["@mozilla.org/dom/messages/system-messages-ui-glue;1"]

Add one blank line above this line.

::: dom/messages/interfaces/nsISystemMessagesUIGlue.idl
@@ +10,5 @@
> +interface nsISystemMessagesUIGlue : nsISupports
> +{
> +    /* Notify the system app to open the target app.
> +     *
> +     * @param pageURL     The URI of the page that will be opened.

s/URI/URL/

URI is actually a special interface (nsIURI), whereas URL represents the string of URI.

@@ +11,5 @@
> +{
> +    /* Notify the system app to open the target app.
> +     *
> +     * @param pageURL     The URI of the page that will be opened.
> +     * @param manifestURL The webapp's manifest URI.

s/URI/URL/

@@ +23,5 @@
> +     */
> +    void openApp(in AString pageURL,
> +                 in AString manifestURL,
> +                 in AString type,
> +                 in jsval target,

I wonder we can have a more explicit interface than jsval for the target.
Attachment #8430494 - Flags: review?(gene.lian) → review-
(In reply to Gene Lian [:gene] (needinfo? encouraged) from comment #10)
> ::: b2g/components/B2GComponents.manifest
> @@ +27,5 @@
> >  # InterAppCommUIGlue.js
> >  component {879ee66c-e246-11e3-9910-74d02b97e723} InterAppCommUIGlue.js
> >  contract @mozilla.org/dom/apps/inter-app-comm-ui-glue;1 {879ee66c-e246-11e3-9910-74d02b97e723}
> >  
> > +# SystemMessagesUIGlue.js
> 
> System message doesn't attempt to launch any "UI" stuff, so
> SystemMessagesUIGlue might not be a good name.
> 
> How about SystemMessagesOpenAppGlue or any others better?
I'm thinking to simply use SystemMessagesGlue with the flexibility to enhace it with some other methods in the future.
> @@ +58,5 @@
> >      let content = this._frame ? this._frame.contentWindow : null;
> >  
> >      // If the system app isn't ready yet,
> >      // queue events until someone calls setIsLoaded
> > +    if ((!noPendingUntilReady && !this._isReady) || !content) {
> 
> Why it's not:
> 
> if (!noPendingUntilReady && (!this._isReady || !content)) {
> 
> ???
Since the next line below this section is

let event = content.document.createEvent('CustomEvent');

To ensure null-safe, I made a compromise to allow pending for the edge case where content hasn't been assigned with anything.

Thoughts?!
Flags: needinfo?(gene.lian)
(In reply to Sean Lin [:seanlin] from comment #11)
> (In reply to Gene Lian [:gene] (needinfo? encouraged) from comment #10)
> > ::: b2g/components/B2GComponents.manifest
> > @@ +27,5 @@
> > >  # InterAppCommUIGlue.js
> > >  component {879ee66c-e246-11e3-9910-74d02b97e723} InterAppCommUIGlue.js
> > >  contract @mozilla.org/dom/apps/inter-app-comm-ui-glue;1 {879ee66c-e246-11e3-9910-74d02b97e723}
> > >  
> > > +# SystemMessagesUIGlue.js
> > 
> > System message doesn't attempt to launch any "UI" stuff, so
> > SystemMessagesUIGlue might not be a good name.
> > 
> > How about SystemMessagesOpenAppGlue or any others better?
> I'm thinking to simply use SystemMessagesGlue with the flexibility to enhace
> it with some other methods in the future.

Yeap, sounds good. Btw, please s/SystemMessagesGlue/SystemMessageGlue. Don't need an extra "s", which is consistent with other system message related file names.

> > @@ +58,5 @@
> > >      let content = this._frame ? this._frame.contentWindow : null;
> > >  
> > >      // If the system app isn't ready yet,
> > >      // queue events until someone calls setIsLoaded
> > > +    if ((!noPendingUntilReady && !this._isReady) || !content) {
> > 
> > Why it's not:
> > 
> > if (!noPendingUntilReady && (!this._isReady || !content)) {
> > 
> > ???
> Since the next line below this section is
> 
> let event = content.document.createEvent('CustomEvent');
> 
> To ensure null-safe, I made a compromise to allow pending for the edge case
> where content hasn't been assigned with anything.
> 
> Thoughts?!

OK, I see. I'd like to have a a minor improvement on this condition:

  if (!content || (!this._isReady && !noPending))

which has a more reasonable order because the flow we expect is:

1. Check if the content window is constructed.
2. If the content window is constructed, check if the system app is ready to receive events.
3. If the system app is not ready to receive events, check if we need to pend the events.
Flags: needinfo?(gene.lian)
Blocks: system-message-api
No longer blocks: 988787
Attachment #8430494 - Flags: review?(fabrice)
Attached patch Patch v3Splinter Review
Updating based on Gene's comments.
Attachment #8430494 - Attachment is obsolete: true
Attachment #8431418 - Flags: review?(gene.lian)
Attachment #8431418 - Flags: review?(fabrice)
Comment on attachment 8431418 [details] [diff] [review]
Patch v3

Review of attachment 8431418 [details] [diff] [review]:
-----------------------------------------------------------------

Sean, I won't have time to review during the next 2 weeks, but I'll do it when I'll be back.
Attachment #8431418 - Flags: review?(gene.lian) → review+
(In reply to < away until June 17 > from comment #14)
> Comment on attachment 8431418 [details] [diff] [review]
> Patch v3
> 
> Review of attachment 8431418 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Sean, I won't have time to review during the next 2 weeks, but I'll do it
> when I'll be back.

Two weeks sounds a too long timeline to wait for when it comes to fixing a bug. I personally think having my review is enough because we used to have a very similar same change for inter-app-comm API UI glue and Fabrice has passed the review for it.

I think we can land this first and needinfo? to Fabrice. If Fabrice wouldn't be satisfied with the changes when he comes back, we can polish it as a follow-up.
Flags: needinfo?(fabrice)
Attachment #8431418 - Flags: review?(fabrice)
The correspondent try run for this patch.
https://tbpl.mozilla.org/?tree=Try&rev=f273d916c71d
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/10869fc4d7e7
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla32
Flags: needinfo?(fabrice)
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: