Closed Bug 1419463 Opened 7 years ago Closed 6 years ago

standalone apps don't seem to focus when service workers call client.focus()

Categories

(Firefox for Android Graveyard :: Web Apps (PWAs), enhancement, P2)

enhancement

Tracking

(firefox60 fixed)

RESOLVED FIXED
Firefox 60
Tracking Status
firefox60 --- fixed

People

(Reporter: bkelly, Assigned: droeh)

Details

Attachments

(1 file)

There is a DOM API which allows service workers to focus an existing window/tab.  This works by dispatching a chrome event "DOMWindowFocus".

Does this work with standalone sites installed to the homescreen in fennec?

I've noticed a couple times I clicked a telegram push notification that did nothing while I had the standalone telegram site open.  Normally it will focus the tab if it exists or open a new window.

Here is the code in fennec that taps into the DOMWindowFocus event:

https://searchfox.org/mozilla-central/source/mobile/android/chrome/content/browser.js#4311
Flags: needinfo?(snorp)
I'm sure we don't handle this right in the standalone scenario. Dylan, we'll need to have some GV API for this, probably in the ContentDelegate. onFocusRequested() maybe? This would cause us to send an intent if we are backgrounded.
Assignee: nobody → droeh
Flags: needinfo?(snorp) → needinfo?(droeh)
Priority: -- → P2
This adds onFocusRequest to ContentListener, listens for "DOMWindowFocus" in GeckoViewContent.js, and calls onFocusRequest when it is received. Also implements onFocusRequest for both PWAs and custom tabs.
Flags: needinfo?(droeh)
Attachment #8944454 - Flags: review?(snorp)
Comment on attachment 8944454 [details] [diff] [review]
Add onFocusRequest to ContentListener

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

I have questions.

::: mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java
@@ +1196,4 @@
>          void onTitleChange(GeckoSession session, String title);
>  
>          /**
> +        * A page has called WindowClient.focus

Probably not good to reference WindowClient here since it doesn't really mean anything in GeckoView.

One question I have is whether or not this would be called if someone just does window.focus() in a normal page. Would we want to ignore those? Are they guarded by user activity in Gecko?
(In reply to James Willcox (:snorp) (jwillcox@mozilla.com) from comment #3)
> Probably not good to reference WindowClient here since it doesn't really
> mean anything in GeckoView.

Right, I was a little bit hesitant as to how to clearly explain when this gets called. Should I go with something a bit more like "A service worker has requested focus for this page"?

> One question I have is whether or not this would be called if someone just
> does window.focus() in a normal page. Would we want to ignore those? Are
> they guarded by user activity in Gecko?

It doesn't look to me like it would get called in that case; the "DOMWindowFocus" event is fired by nsContentUtils::DispatchFocusChromeEvent(), which is only called by nsDocShell::InternalLoad(), WaitForLoad() in ClientOpenWindowUtils.cpp, and ClientSource::Focus().
Attachment #8944454 - Flags: review?(snorp) → review+
Pushed by droeh@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/2d34b2165a74
Add onFocusRequest to ContentListener API. r=snorp
https://hg.mozilla.org/mozilla-central/rev/2d34b2165a74
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 60
Is it possible to add a test for this?
Flags: needinfo?(droeh)
(In reply to Ben Kelly [:bkelly] from comment #7)
> Is it possible to add a test for this?

I think the best approach would be to add a test for the GeckoView functionality here; we should be making a major push to add a lot of GV testing soon.
Flags: needinfo?(droeh)
This still doesn't work 100%. See Bug 1435083
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: