Closed Bug 1648024 Opened 4 years ago Closed 4 years ago

[Firefox] Needs permission to own MPRIS bus names, not just talk to them

Categories

(Core :: Widget: Gtk, defect, P3)

77 Branch
defect

Tracking

()

RESOLVED FIXED
82 Branch
Tracking Status
firefox82 --- fixed

People

(Reporter: will, Assigned: pobega)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15 Epiphany/605.1.15

Steps to reproduce:

  1. In about:config, set media.hardwaremediakeys.enabled = true
  2. Browsed to YouTube and started playing a video

Actual results:

No media playback indicator appeared in the GNOME Shell notification menu.

This is because the Firefox flatpak only has permission to talk to the name org.mpris.MediaPlayer2.org.mozilla.firefox. This is not correct:

  • As described in the MPRIS specification[1] and implemented in Firefox[2], Firefox needs to own a name in the MPRIS namespace, not talk to one.
  • That's not the name Firefox uses. It defines DBUS_MRPIS_SERVICE_NAME (sic, should be MPRIS) as "org.mpris.MediaPlayer2.firefox" [3] and then (following guidance in the MPRIS specification for apps which can have multiple running instances) appends ".instance$PID" to that name[4]

[1] https://specifications.freedesktop.org/mpris-spec/latest/#Bus-Name-Policy
[2] https://github.com/mozilla/gecko-dev/blob/34eac0d840a849f88ae09b17e2c599114a74b859/widget/gtk/MPRISServiceHandler.cpp#L423-L427
[3]
[4] https://github.com/mozilla/gecko-dev/blob/34eac0d840a849f88ae09b17e2c599114a74b859/widget/gtk/MPRISServiceHandler.cpp#L421

Expected results:

Based on reading https://docs.google.com/document/d/1c4FivJpvAjjw9Uw-jn7X1UjGOoWkANXOulNyqDWs83w/ I expected that the playing media would be shown by GNOME Shell, thanks to Firefox implementing the MPRIS specification.

If I launch Firefox with:

$ flatpak run --own-name=org.mpris.MediaPlayer2.firefox.'*' org.mozilla.firefox

Then indeed I can see the playing media in the GNOME notifications menu, and control it with the media keys on my keyboard.

Oh – in a Flatpak context a PID is not a suitable key to unique-ify between different instances of Firefox. If you start a second Firefox with a different profile, it will be in a separate PID namespace, so both are likely to believe themselves to be PID 3. A better choice (which is also suitable in the non-Flatpak case) is to use something derived from the D-Bus connection's unique name.

These are defined in https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus. The specification is a little wooly on the details but in practice they have the form ":I.J" for two integers I and J; adjusting for characters which are legal in D-Bus names, perhaps org.mpris.MediaPlayer2.firefox.instance_I_J would be a good option.

Priority: -- → P3
Assignee: nobody → pobega

Once this gets merged to central, it will naturally ride the 82 train.
I'll let the Sherriffs close the bug.

Pushed by mtabara@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7696ef3fe20d
take ownership of correct mpris bus name for flatpak r=mtabara DONTBUILD
Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch

The concern with PIDs being non-unique still holds, though.
In it's current form, the PIDs would clash resulting the second instance to be unable to own the bus, hence not registering MPRIS.

No longer blocks: 1665211
Blocks: 1861627
No longer blocks: 1861627
You need to log in before you can comment on or make changes to this bug.