Bug 1517074 - [Linux/Gtk] Enable native (xdg-desktop based) file dialog on KDE only due to Gtk+ regression, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Fri, 11 Jan 2019 11:21:27 +0000
changeset 453453 c8604d1a709caa37700cf712cbd4be848f62c6c0
parent 453452 fc6fa6ebad8670134a9fca57ec7d7f1c9b60f4d1
child 453454 fa4d4678a56854c7edf887747d25546d0f6929a9
push id35357
push usernerli@mozilla.com
push dateFri, 11 Jan 2019 21:54:07 +0000
treeherdermozilla-central@0ce024c91511 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1517074
milestone66.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 1517074 - [Linux/Gtk] Enable native (xdg-desktop based) file dialog on KDE only due to Gtk+ regression, r=jhorak Also add widget.allow-gtk-native-file-chooser preference value to force enable on all systems. Differential Revision: https://phabricator.services.mozilla.com/D16184
widget/gtk/nsFilePicker.cpp
widget/gtk/nsFilePicker.h
--- a/widget/gtk/nsFilePicker.cpp
+++ b/widget/gtk/nsFilePicker.cpp
@@ -157,16 +157,18 @@ nsFilePicker::nsFilePicker()
     : mSelectedType(0),
       mRunning(false),
       mAllowURLs(false)
 #ifdef MOZ_WIDGET_GTK
       ,
       mFileChooserDelegate(nullptr)
 #endif
 {
+  nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
+  giovfs->ShouldUseFlatpakPortal(&mUseNativeFileChooser);
 }
 
 nsFilePicker::~nsFilePicker() {}
 
 void ReadMultipleFiles(gpointer filename, gpointer array) {
   nsCOMPtr<nsIFile> localfile;
   nsresult rv =
       NS_NewNativeLocalFile(nsDependentCString(static_cast<char *>(filename)),
@@ -570,26 +572,25 @@ void nsFilePicker::Done(void *file_choos
     mCallback = nullptr;
   } else {
     mResult = result;
   }
   NS_RELEASE_THIS();
 }
 
 // All below functions available as of GTK 3.20+
-
 void *nsFilePicker::GtkFileChooserNew(const gchar *title, GtkWindow *parent,
                                       GtkFileChooserAction action,
                                       const gchar *accept_label) {
   static auto sGtkFileChooserNativeNewPtr =
       (void *(*)(const gchar *, GtkWindow *, GtkFileChooserAction,
                  const gchar *,
                  const gchar *))dlsym(RTLD_DEFAULT,
                                       "gtk_file_chooser_native_new");
-  if (sGtkFileChooserNativeNewPtr != nullptr) {
+  if (mUseNativeFileChooser && sGtkFileChooserNativeNewPtr != nullptr) {
     return (*sGtkFileChooserNativeNewPtr)(title, parent, action, accept_label,
                                           nullptr);
   }
   if (accept_label == nullptr) {
     accept_label = (action == GTK_FILE_CHOOSER_ACTION_SAVE) ? GTK_STOCK_SAVE
                                                             : GTK_STOCK_OPEN;
   }
   GtkWidget *file_chooser = gtk_file_chooser_dialog_new(
@@ -598,40 +599,40 @@ void *nsFilePicker::GtkFileChooserNew(co
   gtk_dialog_set_alternative_button_order(
       GTK_DIALOG(file_chooser), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1);
   return file_chooser;
 }
 
 void nsFilePicker::GtkFileChooserShow(void *file_chooser) {
   static auto sGtkNativeDialogShowPtr =
       (void (*)(void *))dlsym(RTLD_DEFAULT, "gtk_native_dialog_show");
-  if (sGtkNativeDialogShowPtr != nullptr) {
+  if (mUseNativeFileChooser && sGtkNativeDialogShowPtr != nullptr) {
     (*sGtkNativeDialogShowPtr)(file_chooser);
   } else {
     g_signal_connect(file_chooser, "destroy", G_CALLBACK(OnDestroy), this);
     gtk_widget_show(GTK_WIDGET(file_chooser));
   }
 }
 
 void nsFilePicker::GtkFileChooserDestroy(void *file_chooser) {
   static auto sGtkNativeDialogDestroyPtr =
       (void (*)(void *))dlsym(RTLD_DEFAULT, "gtk_native_dialog_destroy");
-  if (sGtkNativeDialogDestroyPtr != nullptr) {
+  if (mUseNativeFileChooser && sGtkNativeDialogDestroyPtr != nullptr) {
     (*sGtkNativeDialogDestroyPtr)(file_chooser);
   } else {
     gtk_widget_destroy(GTK_WIDGET(file_chooser));
   }
 }
 
 void nsFilePicker::GtkFileChooserSetModal(void *file_chooser,
                                           GtkWindow *parent_widget,
                                           gboolean modal) {
   static auto sGtkNativeDialogSetModalPtr = (void (*)(void *, gboolean))dlsym(
       RTLD_DEFAULT, "gtk_native_dialog_set_modal");
-  if (sGtkNativeDialogSetModalPtr != nullptr) {
+  if (mUseNativeFileChooser && sGtkNativeDialogSetModalPtr != nullptr) {
     (*sGtkNativeDialogSetModalPtr)(file_chooser, modal);
   } else {
     GtkWindow *window = GTK_WINDOW(file_chooser);
     gtk_window_set_modal(window, modal);
     if (parent_widget != nullptr) {
       gtk_window_set_destroy_with_parent(window, modal);
     }
   }
--- a/widget/gtk/nsFilePicker.h
+++ b/widget/gtk/nsFilePicker.h
@@ -78,11 +78,12 @@ class nsFilePicker : public nsBaseFilePi
   void GtkFileChooserShow(void *file_chooser);
   void GtkFileChooserDestroy(void *file_chooser);
   void GtkFileChooserSetModal(void *file_chooser, GtkWindow *parent_widget,
                               gboolean modal);
 
 #ifdef MOZ_WIDGET_GTK
   GtkFileChooserWidget *mFileChooserDelegate;
 #endif
+  bool mUseNativeFileChooser;
 };
 
 #endif