diff --git a/widget/WidgetUtils.cpp b/widget/WidgetUtils.cpp index 4352f837ca00..345c0772ad62 100644 --- a/widget/WidgetUtils.cpp +++ b/widget/WidgetUtils.cpp @@ -7,9 +7,11 @@ #include "mozilla/WidgetUtils.h" #include "mozilla/dom/ContentParent.h" +#include "mozilla/Services.h" #include "mozilla/Unused.h" #include "nsContentUtils.h" #include "nsIBidiKeyboard.h" +#include "nsIStringBundle.h" #include "nsTArray.h" #ifdef XP_WIN #include "WinUtils.h" @@ -137,5 +139,26 @@ WidgetUtils::SendBidiKeyboardInfoToContent() } } +// static +void +WidgetUtils::GetBrandShortName(nsAString& aBrandName) +{ + aBrandName.Truncate(); + + nsCOMPtr bundleService = + mozilla::services::GetStringBundleService(); + + nsCOMPtr bundle; + if (bundleService) { + bundleService->CreateBundle( + "chrome://branding/locale/brand.properties", + getter_AddRefs(bundle)); + } + + if (bundle) { + bundle->GetStringFromName("brandShortName", aBrandName); + } +} + } // namespace widget } // namespace mozilla diff --git a/widget/WidgetUtils.h b/widget/WidgetUtils.h index c61873e47fa7..142f0cf1683f 100644 --- a/widget/WidgetUtils.h +++ b/widget/WidgetUtils.h @@ -91,6 +91,12 @@ public: * Send bidi keyboard information to content process */ static void SendBidiKeyboardInfoToContent(); + + /** + * Get branchShortName from string bundle + */ + static void GetBrandShortName(nsAString& aBrandName); + }; } // namespace widget diff --git a/widget/gtk/mozgtk/mozgtk.c b/widget/gtk/mozgtk/mozgtk.c index 83a67575e848..aa56782d9545 100644 --- a/widget/gtk/mozgtk/mozgtk.c +++ b/widget/gtk/mozgtk/mozgtk.c @@ -71,6 +71,7 @@ STUB(gdk_screen_get_width) STUB(gdk_screen_height) STUB(gdk_screen_is_composited) STUB(gdk_screen_width) +STUB(gdk_set_program_class) STUB(gdk_unicode_to_keyval) STUB(gdk_visual_get_depth) STUB(gdk_visual_get_system) diff --git a/widget/gtk/nsAppShell.cpp b/widget/gtk/nsAppShell.cpp index 4e341de7b89d..f6cab92f18a4 100644 --- a/widget/gtk/nsAppShell.cpp +++ b/widget/gtk/nsAppShell.cpp @@ -16,6 +16,7 @@ #include "prenv.h" #include "mozilla/HangMonitor.h" #include "mozilla/Unused.h" +#include "mozilla/WidgetUtils.h" #include "GeckoProfiler.h" #include "nsIPowerManagerService.h" #ifdef MOZ_ENABLE_DBUS @@ -176,6 +177,18 @@ nsAppShell::Init() } } + if (gtk_check_version(3, 16, 3) == nullptr) { + // Before 3.16.3, GDK cannot override classname by --class command line + // option when program uses gdk_set_program_class(). + // + // See https://bugzilla.gnome.org/show_bug.cgi?id=747634 + nsAutoString brandName; + mozilla::widget::WidgetUtils::GetBrandShortName(brandName); + if (!brandName.IsEmpty()) { + gdk_set_program_class(NS_ConvertUTF16toUTF8(brandName).get()); + } + } + #if MOZ_WIDGET_GTK == 3 if (!sReal_gtk_window_check_resize && gtk_check_version(3,8,0) != nullptr) { // GTK 3.0 to GTK 3.6. diff --git a/widget/gtk/nsSound.cpp b/widget/gtk/nsSound.cpp index c70921c1c801..85698fd86ded 100644 --- a/widget/gtk/nsSound.cpp +++ b/widget/gtk/nsSound.cpp @@ -25,7 +25,7 @@ #include "mozilla/FileUtils.h" #include "mozilla/Services.h" #include "mozilla/Unused.h" -#include "nsIStringBundle.h" +#include "mozilla/WidgetUtils.h" #include "nsIXULAppInfo.h" #include "nsContentUtils.h" #include "gfxPlatform.h" @@ -125,21 +125,11 @@ ca_context_get_default() } } - nsCOMPtr bundleService = - mozilla::services::GetStringBundleService(); - if (bundleService) { - nsCOMPtr brandingBundle; - bundleService->CreateBundle("chrome://branding/locale/brand.properties", - getter_AddRefs(brandingBundle)); - if (brandingBundle) { - nsAutoString wbrand; - brandingBundle->GetStringFromName("brandShortName", wbrand); - NS_ConvertUTF16toUTF8 brand(wbrand); - - ca_context_change_props(ctx, "application.name", brand.get(), - nullptr); - } - } + nsAutoString wbrand; + WidgetUtils::GetBrandShortName(wbrand); + ca_context_change_props(ctx, "application.name", + NS_ConvertUTF16toUTF8(wbrand).get(), + nullptr); nsCOMPtr appInfo = do_GetService("@mozilla.org/xre/app-info;1"); if (appInfo) { diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index fda1a053df50..8b700c55d0b5 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -17,6 +17,7 @@ #include "mozilla/TimeStamp.h" #include "mozilla/TouchEvents.h" #include "mozilla/UniquePtrExtensions.h" +#include "mozilla/WidgetUtils.h" #include #include "GeckoProfiler.h" @@ -76,7 +77,6 @@ #include "nsIPrefService.h" #include "nsIGConfService.h" #include "nsIServiceManager.h" -#include "nsIStringBundle.h" #include "nsGfxCIID.h" #include "nsGtkUtils.h" #include "nsIObserverService.h" @@ -176,8 +176,6 @@ static GdkWindow *get_inner_gdk_window (GdkWindow *aWindow, static int is_parent_ungrab_enter(GdkEventCrossing *aEvent); static int is_parent_grab_leave(GdkEventCrossing *aEvent); -static void GetBrandName(nsAString& brandName); - /* callbacks from widgets */ #if (MOZ_WIDGET_GTK == 2) static gboolean expose_event_cb (GtkWidget *widget, @@ -1777,7 +1775,10 @@ nsWindow::SetIcon(const nsAString& aIconSpec) if (aIconSpec.EqualsLiteral("default")) { nsAutoString brandName; - GetBrandName(brandName); + WidgetUtils::GetBrandShortName(brandName); + if (brandName.IsEmpty()) { + brandName.AssignLiteral(u"Mozilla"); + } AppendUTF16toUTF8(brandName, iconName); ToLowerCase(iconName); } else { @@ -3521,25 +3522,6 @@ nsWindow::OnTouchEvent(GdkEventTouch* aEvent) } #endif -static void -GetBrandName(nsAString& aBrandName) -{ - nsCOMPtr bundleService = - do_GetService(NS_STRINGBUNDLE_CONTRACTID); - - nsCOMPtr bundle; - if (bundleService) - bundleService->CreateBundle( - "chrome://branding/locale/brand.properties", - getter_AddRefs(bundle)); - - if (bundle) - bundle->GetStringFromName("brandShortName", aBrandName); - - if (aBrandName.IsEmpty()) - aBrandName.AssignLiteral(u"Mozilla"); -} - static GdkWindow * CreateGdkWindow(GdkWindow *parent, GtkWidget *widget) {