Commit 5ab94864 authored by Marc Streckfuss's avatar Marc Streckfuss
Browse files

Bug 1615375 - MPRIS: Dynamically determine the User-Agent Vendor and Name to...

Bug 1615375 - MPRIS: Dynamically determine the User-Agent Vendor and Name to support Re-Branding. r=alwu

Differential Revision: https://phabricator.services.mozilla.com/D62940

--HG--
extra : moz-landing-system : lando
parent d5589171
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include "mozilla/dom/MediaControlUtils.h"
#include "mozilla/Maybe.h"
#include "mozilla/Sprintf.h"
#include "nsIXULAppInfo.h"

// avoid redefined macro in unified build
#undef LOG
@@ -420,6 +421,8 @@ bool MPRISServiceHandler::Open() {
  MOZ_ASSERT(NS_IsMainThread());
  GError* error = nullptr;
  gchar serviceName[256];

  InitIdentity();
  SprintfLiteral(serviceName, DBUS_MRPIS_SERVICE_NAME ".instance%d", getpid());
  mOwnerId =
      g_bus_own_name(G_BUS_TYPE_SESSION, serviceName,
@@ -470,7 +473,26 @@ bool MPRISServiceHandler::IsOpened() const { return mInitialized; }

bool MPRISServiceHandler::HasTrackList() { return false; }

const char* MPRISServiceHandler::Identity() { return "Mozilla Firefox"; }
void MPRISServiceHandler::InitIdentity() {
  nsresult rv;
  nsAutoCString appName;
  nsCOMPtr<nsIXULAppInfo> appInfo =
      do_GetService("@mozilla.org/xre/app-info;1", &rv);

  MOZ_ASSERT(NS_SUCCEEDED(rv));
  rv = appInfo->GetVendor(mIdentity);
  MOZ_ASSERT(NS_SUCCEEDED(rv));
  rv = appInfo->GetName(appName);
  MOZ_ASSERT(NS_SUCCEEDED(rv));

  mIdentity.Append(' ');
  mIdentity.Append(appName);
}

const char* MPRISServiceHandler::Identity() const {
  MOZ_ASSERT(mInitialized);
  return mIdentity.get();
}

GVariant* MPRISServiceHandler::SupportedUriSchemes() {
  GVariantBuilder builder;
+6 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include <gio/gio.h>
#include "mozilla/dom/MediaControlKeysEvent.h"
#include "mozilla/Attributes.h"
#include "nsString.h"

#define DBUS_MRPIS_SERVICE_NAME "org.mpris.MediaPlayer2.firefox"
#define DBUS_MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
@@ -75,7 +76,7 @@ class MPRISServiceHandler final : public dom::MediaControlKeysEventSource {
  bool CanSetFullscreen();
#endif
  bool HasTrackList();
  const char* Identity();
  const char* Identity() const;
#ifdef MPRIS_DESKTOP_ENTRY
  const char* DesktopEntry();
#endif
@@ -140,6 +141,10 @@ class MPRISServiceHandler final : public dom::MediaControlKeysEventSource {
  GDBusNodeInfo* mIntrospectionData = nullptr;
  GDBusConnection* mConnection = nullptr;
  bool mInitialized = false;
  nsAutoCString mIdentity;

  // Queries nsAppInfo to get the branded browser name and vendor
  void InitIdentity();

  // non-public API, called from events
  void OnNameAcquired(GDBusConnection* aConnection, const gchar* aName);