Bug 1151753 - Set program class name when not using --class command line option. r=karlt
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 25 Oct 2017 15:58:49 +0900
changeset 389804 cd2a5b5cf752194818cee5f96f2ae5cdcbf3d564
parent 389803 1116fde20e3bf588202c5becf5ffb414d33e7ad5
child 389805 a29ab4c986c761f64d5889f715390bd82e9137e7
push id32796
push userapavel@mozilla.com
push dateThu, 02 Nov 2017 13:27:53 +0000
treeherdermozilla-central@083a5838f76a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1151753, 747634
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1151753 - Set program class name when not using --class command line option. r=karlt GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=747634 Before 3.16.3, GDK cannot override classname by --class command line option when program uses gdk_set_program_class(). So if 3.16.3+, we should call gdk_set_program_class() to set program class name of default. MozReview-Commit-ID: KvNc3U6xHr7
widget/WidgetUtils.cpp
widget/WidgetUtils.h
widget/gtk/mozgtk/mozgtk.c
widget/gtk/nsAppShell.cpp
widget/gtk/nsSound.cpp
widget/gtk/nsWindow.cpp
--- a/widget/WidgetUtils.cpp
+++ b/widget/WidgetUtils.cpp
@@ -2,19 +2,21 @@
  * vim: sw=2 ts=8 et :
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #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"
 #endif
 #if MOZ_WIDGET_GTK == 3
 #include "mozilla/WidgetUtilsGtk.h"
 #endif
 
@@ -132,10 +134,31 @@ WidgetUtils::SendBidiKeyboardInfoToConte
 
   nsTArray<dom::ContentParent*> children;
   dom::ContentParent::GetAll(children);
   for (uint32_t i = 0; i < children.Length(); i++) {
     Unused << children[i]->SendBidiKeyboardNotify(rtl, bidiKeyboards);
   }
 }
 
+// static
+void
+WidgetUtils::GetBrandShortName(nsAString& aBrandName)
+{
+    aBrandName.Truncate();
+
+    nsCOMPtr<nsIStringBundleService> bundleService =
+        mozilla::services::GetStringBundleService();
+
+    nsCOMPtr<nsIStringBundle> bundle;
+    if (bundleService) {
+        bundleService->CreateBundle(
+            "chrome://branding/locale/brand.properties",
+            getter_AddRefs(bundle));
+    }
+
+    if (bundle) {
+        bundle->GetStringFromName("brandShortName", aBrandName);
+    }
+}
+
 } // namespace widget
 } // namespace mozilla
--- a/widget/WidgetUtils.h
+++ b/widget/WidgetUtils.h
@@ -86,14 +86,20 @@ public:
   * Does device have touch support
   */
   static uint32_t IsTouchDeviceSupportPresent();
 
   /**
    * Send bidi keyboard information to content process
    */
   static void SendBidiKeyboardInfoToContent();
+
+  /**
+   * Get branchShortName from string bundle
+   */
+  static void GetBrandShortName(nsAString& aBrandName);
+
 };
 
 } // namespace widget
 } // namespace mozilla
 
 #endif // mozilla_WidgetUtils_h
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -66,16 +66,17 @@ STUB(gdk_screen_get_number)
 STUB(gdk_screen_get_resolution)
 STUB(gdk_screen_get_rgba_visual)
 STUB(gdk_screen_get_root_window)
 STUB(gdk_screen_get_system_visual)
 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)
 STUB(gdk_window_add_filter)
 STUB(gdk_window_begin_move_drag)
 STUB(gdk_window_begin_resize_drag)
 STUB(gdk_window_destroy)
 STUB(gdk_window_focus)
--- a/widget/gtk/nsAppShell.cpp
+++ b/widget/gtk/nsAppShell.cpp
@@ -11,16 +11,17 @@
 #include <errno.h>
 #include <gdk/gdk.h>
 #include "nsAppShell.h"
 #include "nsWindow.h"
 #include "mozilla/Logging.h"
 #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
 #include "WakeLockListener.h"
 #endif
 #include "gfxPlatform.h"
 #include "ScreenHelperGTK.h"
 #include "HeadlessScreenHelper.h"
@@ -171,16 +172,28 @@ nsAppShell::Init()
         ScreenManager& screenManager = ScreenManager::GetSingleton();
         if (gfxPlatform::IsHeadless()) {
             screenManager.SetHelper(mozilla::MakeUnique<HeadlessScreenHelper>());
         } else {
             screenManager.SetHelper(mozilla::MakeUnique<ScreenHelperGTK>());
         }
     }
 
+    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.
         // GtkWindow is a static class and so will leak anyway but this ref
         // makes sure it isn't recreated.
         gpointer gtk_plug_class = g_type_class_ref(GTK_TYPE_WINDOW);
         auto check_resize = &GTK_CONTAINER_CLASS(gtk_plug_class)->check_resize;
         sReal_gtk_window_check_resize = *check_resize;
--- a/widget/gtk/nsSound.cpp
+++ b/widget/gtk/nsSound.cpp
@@ -20,17 +20,17 @@
 #include "nsIChannel.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsDirectoryService.h"
 #include "nsDirectoryServiceDefs.h"
 #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"
 #include "mozilla/ClearOnShutdown.h"
 
 #include <stdio.h>
 #include <unistd.h>
 
@@ -120,31 +120,21 @@ ca_context_get_default()
 
         if (sound_theme_name) {
             ca_context_change_props(ctx, "canberra.xdg-theme.name",
                                     sound_theme_name, nullptr);
             g_free(sound_theme_name);
         }
     }
 
-    nsCOMPtr<nsIStringBundleService> bundleService =
-        mozilla::services::GetStringBundleService();
-    if (bundleService) {
-        nsCOMPtr<nsIStringBundle> 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<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
     if (appInfo) {
         nsAutoCString version;
         appInfo->GetVersion(version);
 
         ca_context_change_props(ctx, "application.version", version.get(),
                                 nullptr);
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -12,16 +12,17 @@
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/TextEventDispatcher.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/UniquePtrExtensions.h"
+#include "mozilla/WidgetUtils.h"
 #include <algorithm>
 
 #include "GeckoProfiler.h"
 
 #include "prlink.h"
 #include "nsGTKToolkit.h"
 #include "nsIRollupListener.h"
 #include "nsIDOMNode.h"
@@ -71,17 +72,16 @@
 #endif
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Preferences.h"
 #include "nsIPrefService.h"
 #include "nsIGConfService.h"
 #include "nsIServiceManager.h"
-#include "nsIStringBundle.h"
 #include "nsGfxCIID.h"
 #include "nsGtkUtils.h"
 #include "nsIObserverService.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "nsIIdleServiceInternal.h"
 #include "nsIPropertyBag2.h"
 #include "GLContext.h"
 #include "gfx2DGlue.h"
@@ -171,18 +171,16 @@ static GdkCursor *get_gtk_cursor(nsCurso
 
 static GdkWindow *get_inner_gdk_window (GdkWindow *aWindow,
                                         gint x, gint y,
                                         gint *retx, gint *rety);
 
 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,
                                            GdkEventExpose *event);
 #else
 static gboolean expose_event_cb           (GtkWidget *widget,
                                            cairo_t *rect);
 #endif
@@ -1772,17 +1770,20 @@ nsWindow::SetIcon(const nsAString& aIcon
 {
     if (!mShell)
         return;
 
     nsAutoCString iconName;
 
     if (aIconSpec.EqualsLiteral("default")) {
         nsAutoString brandName;
-        GetBrandName(brandName);
+        WidgetUtils::GetBrandShortName(brandName);
+        if (brandName.IsEmpty()) {
+            brandName.AssignLiteral(u"Mozilla");
+        }
         AppendUTF16toUTF8(brandName, iconName);
         ToLowerCase(iconName);
     } else {
         AppendUTF16toUTF8(aIconSpec, iconName);
     }
 
     nsCOMPtr<nsIFile> iconFile;
     nsAutoCString path;
@@ -3516,35 +3517,16 @@ nsWindow::OnTouchEvent(GdkEventTouch* aE
         *event.mTouches.AppendElement() = touch.forget();
     }
 
     DispatchInputEvent(&event);
     return TRUE;
 }
 #endif
 
-static void
-GetBrandName(nsAString& aBrandName)
-{
-    nsCOMPtr<nsIStringBundleService> bundleService =
-        do_GetService(NS_STRINGBUNDLE_CONTRACTID);
-
-    nsCOMPtr<nsIStringBundle> 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)
 {
     GdkWindowAttr attributes;
     gint          attributes_mask = GDK_WA_VISUAL;
 
     attributes.event_mask = kEvents;