Issue #999 - Disable native file picker by default.

This commit is contained in:
Ascrod 2019-08-15 06:03:42 -04:00 • committed by Roy Tam
commit 53bfc43dbe
3 changed files with 13 additions and 4 deletions

View file

@ -4020,6 +4020,12 @@ pref("autocomplete.ungrab_during_mode_switch", true);
// toggling to use the XUL filepicker // toggling to use the XUL filepicker
pref("ui.allow_platform_file_picker", true); pref("ui.allow_platform_file_picker", true);
// Allow for using the native GTK file picker. If the application is not run
// with GTK_USE_PORTAL=1 this pref has no effect.
#ifdef MOZ_WIDGET_GTK
pref("widget.allow-gtk-native-file-chooser", false);
#endif
pref("helpers.global_mime_types_file", "/etc/mime.types"); pref("helpers.global_mime_types_file", "/etc/mime.types");
pref("helpers.global_mailcap_file", "/etc/mailcap"); pref("helpers.global_mailcap_file", "/etc/mailcap");
pref("helpers.private_mime_types_file", "~/.mime.types"); pref("helpers.private_mime_types_file", "~/.mime.types");

View file

@ -23,6 +23,7 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "mozcontainer.h" #include "mozcontainer.h"
#include "mozilla/Preferences.h"
#include "nsFilePicker.h" #include "nsFilePicker.h"
@ -175,6 +176,7 @@ nsFilePicker::nsFilePicker()
, mFileChooserDelegate(nullptr) , mFileChooserDelegate(nullptr)
#endif #endif
{ {
mUseNativeFileChooser = Preferences::GetBool("widget.allow-gtk-native-file-chooser", false);
} }
nsFilePicker::~nsFilePicker() nsFilePicker::~nsFilePicker()
@ -613,7 +615,7 @@ nsFilePicker::GtkFileChooserNew(
GtkFileChooserAction, GtkFileChooserAction,
const gchar *, const gchar *)) const gchar *, const gchar *))
dlsym(RTLD_DEFAULT, "gtk_file_chooser_native_new"); dlsym(RTLD_DEFAULT, "gtk_file_chooser_native_new");
if (sGtkFileChooserNativeNewPtr != nullptr) { if (mUseNativeFileChooser && sGtkFileChooserNativeNewPtr != nullptr) {
return (*sGtkFileChooserNativeNewPtr)(title, parent, action, accept_label, nullptr); return (*sGtkFileChooserNativeNewPtr)(title, parent, action, accept_label, nullptr);
} }
if (accept_label == nullptr) { if (accept_label == nullptr) {
@ -633,7 +635,7 @@ nsFilePicker::GtkFileChooserShow(void *file_chooser)
{ {
static auto sGtkNativeDialogShowPtr = (void (*)(void *)) static auto sGtkNativeDialogShowPtr = (void (*)(void *))
dlsym(RTLD_DEFAULT, "gtk_native_dialog_show"); dlsym(RTLD_DEFAULT, "gtk_native_dialog_show");
if (sGtkNativeDialogShowPtr != nullptr) { if (mUseNativeFileChooser && sGtkNativeDialogShowPtr != nullptr) {
(*sGtkNativeDialogShowPtr)(file_chooser); (*sGtkNativeDialogShowPtr)(file_chooser);
} else { } else {
g_signal_connect(file_chooser, "destroy", G_CALLBACK(OnDestroy), this); g_signal_connect(file_chooser, "destroy", G_CALLBACK(OnDestroy), this);
@ -646,7 +648,7 @@ nsFilePicker::GtkFileChooserDestroy(void *file_chooser)
{ {
static auto sGtkNativeDialogDestroyPtr = (void (*)(void *)) static auto sGtkNativeDialogDestroyPtr = (void (*)(void *))
dlsym(RTLD_DEFAULT, "gtk_native_dialog_destroy"); dlsym(RTLD_DEFAULT, "gtk_native_dialog_destroy");
if (sGtkNativeDialogDestroyPtr != nullptr) { if (mUseNativeFileChooser && sGtkNativeDialogDestroyPtr != nullptr) {
(*sGtkNativeDialogDestroyPtr)(file_chooser); (*sGtkNativeDialogDestroyPtr)(file_chooser);
} else { } else {
gtk_widget_destroy(GTK_WIDGET(file_chooser)); gtk_widget_destroy(GTK_WIDGET(file_chooser));
@ -659,7 +661,7 @@ nsFilePicker::GtkFileChooserSetModal(void *file_chooser,
{ {
static auto sGtkNativeDialogSetModalPtr = (void (*)(void *, gboolean)) static auto sGtkNativeDialogSetModalPtr = (void (*)(void *, gboolean))
dlsym(RTLD_DEFAULT, "gtk_native_dialog_set_modal"); dlsym(RTLD_DEFAULT, "gtk_native_dialog_set_modal");
if (sGtkNativeDialogSetModalPtr != nullptr) { if (mUseNativeFileChooser && sGtkNativeDialogSetModalPtr != nullptr) {
(*sGtkNativeDialogSetModalPtr)(file_chooser, modal); (*sGtkNativeDialogSetModalPtr)(file_chooser, modal);
} else { } else {
GtkWindow *window = GTK_WINDOW(file_chooser); GtkWindow *window = GTK_WINDOW(file_chooser);

View file

@ -86,6 +86,7 @@ private:
#if (MOZ_WIDGET_GTK == 3) #if (MOZ_WIDGET_GTK == 3)
GtkFileChooserWidget *mFileChooserDelegate; GtkFileChooserWidget *mFileChooserDelegate;
#endif #endif
bool mUseNativeFileChooser;
}; };
#endif #endif