78aec85
diff -up firefox-52.0/modules/libpref/init/all.js.1158076 firefox-52.0/modules/libpref/init/all.js
78aec85
--- firefox-52.0/modules/libpref/init/all.js.1158076	2017-03-22 10:05:22.318067553 +0100
78aec85
+++ firefox-52.0/modules/libpref/init/all.js	2017-03-22 10:07:15.360555913 +0100
78aec85
@@ -4646,6 +4646,7 @@ pref("gfx.apitrace.enabled",false);
78aec85
 pref("gfx.content.use-native-pushlayer", true);
78aec85
 #ifdef MOZ_WIDGET_GTK
78aec85
 pref("gfx.xrender.enabled",false);
78aec85
+pref("widget.allow-gtk-dark-theme", false);
78aec85
 #endif
78aec85
 #endif
78aec85
 
78aec85
diff -up firefox-52.0/widget/gtk/mozgtk/mozgtk.c.1158076 firefox-52.0/widget/gtk/mozgtk/mozgtk.c
78aec85
--- firefox-52.0/widget/gtk/mozgtk/mozgtk.c.1158076	2017-03-22 10:05:22.313067576 +0100
78aec85
+++ firefox-52.0/widget/gtk/mozgtk/mozgtk.c	2017-03-22 10:08:34.122199432 +0100
78aec85
@@ -522,6 +522,7 @@ STUB(gdk_x11_display_get_type)
78aec85
 STUB(gtk_box_new)
78aec85
 STUB(gtk_cairo_should_draw_window)
78aec85
 STUB(gtk_cairo_transform_to_window)
78aec85
+STUB(gtk_css_provider_get_named)
78aec85
 STUB(gtk_combo_box_text_append)
78aec85
 STUB(gtk_drag_set_icon_surface)
78aec85
 STUB(gtk_get_major_version)
78aec85
@@ -548,6 +549,7 @@ STUB(gtk_scale_new)
78aec85
 STUB(gtk_scrollbar_new)
78aec85
 STUB(gtk_style_context_add_class)
78aec85
 STUB(gtk_style_context_add_region)
78aec85
+STUB(gtk_style_context_add_provider_for_screen)
78aec85
 STUB(gtk_style_context_get)
78aec85
 STUB(gtk_style_context_get_background_color)
78aec85
 STUB(gtk_style_context_get_border)
78aec85
@@ -573,6 +575,7 @@ STUB(gtk_style_context_set_path)
78aec85
 STUB(gtk_style_context_set_parent)
78aec85
 STUB(gtk_style_context_set_state)
78aec85
 STUB(gtk_style_properties_lookup_property)
78aec85
+STUB(gtk_style_provider_get_type)
78aec85
 STUB(gtk_tree_view_column_get_button)
78aec85
 STUB(gtk_widget_get_preferred_size)
78aec85
 STUB(gtk_widget_get_state_flags)
78aec85
diff -up firefox-52.0/widget/gtk/nsLookAndFeel.cpp.1158076 firefox-52.0/widget/gtk/nsLookAndFeel.cpp
78aec85
--- firefox-52.0/widget/gtk/nsLookAndFeel.cpp.1158076	2017-03-22 10:05:22.314067571 +0100
78aec85
+++ firefox-52.0/widget/gtk/nsLookAndFeel.cpp	2017-03-22 10:07:56.914367838 +0100
78aec85
@@ -50,9 +50,9 @@ nsLookAndFeel::nsLookAndFeel()
78aec85
       mStyle(nullptr),
78aec85
 #endif
78aec85
       mDefaultFontCached(false), mButtonFontCached(false),
78aec85
-      mFieldFontCached(false), mMenuFontCached(false)
78aec85
+      mFieldFontCached(false), mMenuFontCached(false),
78aec85
+      mInitialized(false)
78aec85
 {
78aec85
-    Init();    
78aec85
 }
78aec85
 
78aec85
 nsLookAndFeel::~nsLookAndFeel()
78aec85
@@ -224,6 +224,8 @@ GetBorderColors(GtkStyleContext* aContex
78aec85
 nsresult
78aec85
 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
78aec85
 {
78aec85
+    EnsureInit();
78aec85
+
78aec85
 #if (MOZ_WIDGET_GTK == 3)
78aec85
     GdkRGBA gdk_color;
78aec85
 #endif
78aec85
@@ -675,6 +677,8 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
78aec85
         return res;
78aec85
     res = NS_OK;
78aec85
 
78aec85
+    // We use delayed initialization by EnsureInit() here
78aec85
+    // to ensure mozilla::Preferences is available (see Bug 1158076).
78aec85
     switch (aID) {
78aec85
     case eIntID_CaretBlinkTime:
78aec85
         {
78aec85
@@ -837,6 +841,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
78aec85
         aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
78aec85
         break;
78aec85
     case eIntID_MenuBarDrag:
78aec85
+        EnsureInit();
78aec85
         aResult = sMenuSupportsDrag;
78aec85
         break;
78aec85
     case eIntID_ScrollbarButtonAutoRepeatBehavior:
78aec85
@@ -877,6 +882,7 @@ nsLookAndFeel::GetFloatImpl(FloatID aID,
78aec85
         aResult = 1.0f;
78aec85
         break;
78aec85
     case eFloatID_CaretAspectRatio:
78aec85
+        EnsureInit();
78aec85
         aResult = sCaretRatio;
78aec85
         break;
78aec85
     default:
78aec85
@@ -1057,11 +1063,15 @@ nsLookAndFeel::GetFontImpl(FontID aID, n
78aec85
 }
78aec85
 
78aec85
 void
78aec85
-nsLookAndFeel::Init()
78aec85
+nsLookAndFeel::EnsureInit()
78aec85
 {
78aec85
     GdkColor colorValue;
78aec85
     GdkColor *colorValuePtr;
78aec85
 
78aec85
+    if (mInitialized)
78aec85
+        return;
78aec85
+    mInitialized = true;
78aec85
+
78aec85
 #if (MOZ_WIDGET_GTK == 2)
78aec85
     NS_ASSERTION(!mStyle, "already initialized");
78aec85
     // GtkInvisibles come with a refcount that is not floating
78aec85
@@ -1133,17 +1143,40 @@ nsLookAndFeel::Init()
78aec85
     // ask Gtk to create it explicitly. Otherwise we may end up
78aec85
     // with wrong color theme, see Bug 972382
78aec85
     GtkSettings *settings = gtk_settings_get_for_screen(gdk_screen_get_default());
78aec85
+    bool e10sActive = mozilla::BrowserTabsRemoteAutostart();
78aec85
+
78aec85
+    if (!e10sActive || XRE_IsContentProcess()) {
78aec85
+        // Disable dark theme in processes with web content because it
78aec85
+        // interacts poorly with widget styling (see bug 1216658).
78aec85
+        // To avoid triggering reload of theme settings unnecessarily, only set the
78aec85
+        // setting when necessary.
78aec85
+        const gchar* dark_setting = "gtk-application-prefer-dark-theme";
78aec85
+        gboolean dark;
78aec85
+        g_object_get(settings, dark_setting, &dark, nullptr);
78aec85
+
78aec85
+        bool allowDarkEnv = PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME") != nullptr;
78aec85
+        bool allowDarkPref =
78aec85
+            mozilla::Preferences::GetBool("widget.allow-gtk-dark-theme", false);
78aec85
 
78aec85
-    // Disable dark theme because it interacts poorly with widget styling in
78aec85
-    // web content (see bug 1216658).
78aec85
-    // To avoid triggering reload of theme settings unnecessarily, only set the
78aec85
-    // setting when necessary.
78aec85
-    const gchar* dark_setting = "gtk-application-prefer-dark-theme";
78aec85
-    gboolean dark;
78aec85
-    g_object_get(settings, dark_setting, &dark, nullptr);
78aec85
+        if (dark && !allowDarkEnv && !allowDarkPref) {
78aec85
+            g_object_set(settings, dark_setting, FALSE, nullptr);
78aec85
+        }
78aec85
 
78aec85
-    if (dark && !PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME")) {
78aec85
-        g_object_set(settings, dark_setting, FALSE, nullptr);
78aec85
+        // Allow Gtk+ theme override for web content only.
78aec85
+        if (e10sActive) {
78aec85
+            auto contentThemeName =
78aec85
+                mozilla::Preferences::GetCString("widget.content-gtk-theme");
78aec85
+            if (!contentThemeName.IsEmpty()) {
78aec85
+                // TODO: It should be enough to change theme by "gtk-theme-name"
78aec85
+                // settings but that does not have any effect here. Maybe we
78aec85
+                // call it too late?
78aec85
+                GtkCssProvider *styleProvider =
78aec85
+                    gtk_css_provider_get_named(contentThemeName, NULL);
78aec85
+                gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
78aec85
+                    GTK_STYLE_PROVIDER(styleProvider),
78aec85
+                    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
78aec85
+            }
78aec85
+        }
78aec85
     }
78aec85
 
78aec85
     // Scrollbar colors
78aec85
@@ -1439,6 +1472,7 @@ nsLookAndFeel::Init()
78aec85
 char16_t
78aec85
 nsLookAndFeel::GetPasswordCharacterImpl()
78aec85
 {
78aec85
+    EnsureInit();
78aec85
     return sInvisibleCharacter;
78aec85
 }
78aec85
 
78aec85
@@ -1457,7 +1491,7 @@ nsLookAndFeel::RefreshImpl()
78aec85
     mStyle = nullptr;
78aec85
 #endif
78aec85
 
78aec85
-    Init();
78aec85
+    mInitialized = false;
78aec85
 }
78aec85
 
78aec85
 bool
78aec85
diff -up firefox-52.0/widget/gtk/nsLookAndFeel.h.1158076 firefox-52.0/widget/gtk/nsLookAndFeel.h
78aec85
--- firefox-52.0/widget/gtk/nsLookAndFeel.h.1158076	2016-05-12 19:13:34.000000000 +0200
78aec85
+++ firefox-52.0/widget/gtk/nsLookAndFeel.h	2017-03-22 10:06:36.461731972 +0100
78aec85
@@ -84,8 +84,9 @@ protected:
78aec85
     char16_t sInvisibleCharacter;
78aec85
     float   sCaretRatio;
78aec85
     bool    sMenuSupportsDrag;
78aec85
+    bool    mInitialized;
78aec85
 
78aec85
-    void Init();
78aec85
+    void EnsureInit();
78aec85
 };
78aec85
 
78aec85
 #endif