Bug 1517074 - [Linux/Gtk] Enable native (xdg-desktop based) file dialog on KDE only due to Gtk+ regression. r=jhorak, a=RyanVM
authorMartin Stransky <stransky@redhat.com>
Fri, 11 Jan 2019 11:21:27 +0000
changeset 506686 25ba8700fe94
parent 506685 aa0bf52184e6
child 506687 1ee1bd77fa1c
push id10511
push userryanvm@gmail.com
push dateMon, 14 Jan 2019 14:27:14 +0000
treeherdermozilla-beta@7448d41d4fdc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak, RyanVM
bugs1517074
milestone65.0
Bug 1517074 - [Linux/Gtk] Enable native (xdg-desktop based) file dialog on KDE only due to Gtk+ regression. r=jhorak, a=RyanVM 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