Backed out changeset 8ed536957a4b (bug 1490186) for FilePicker.cpp build bustages CLOSED TREE
authorCiure Andrei <aciure@mozilla.com>
Thu, 11 Oct 2018 07:23:28 +0300
changeset 440673 04186081b9031399b1198284f57672aa2eee8229
parent 440672 8ed536957a4bfadb1b651af81ccff887ada217ee
child 440674 55fe54a19a99c26af25556f0d3fb3e81f6233c4c
push id34829
push useraiakab@mozilla.com
push dateThu, 11 Oct 2018 09:59:57 +0000
treeherdermozilla-central@ddcd7cc2f3cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1490186
milestone64.0a1
backs out8ed536957a4bfadb1b651af81ccff887ada217ee
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
Backed out changeset 8ed536957a4b (bug 1490186) for FilePicker.cpp build bustages CLOSED TREE
widget/gtk/nsFilePicker.cpp
widget/gtk/nsFilePicker.h
--- a/widget/gtk/nsFilePicker.cpp
+++ b/widget/gtk/nsFilePicker.cpp
@@ -192,17 +192,17 @@ ReadMultipleFiles(gpointer filename, gpo
     nsCOMArray<nsIFile>& files = *static_cast<nsCOMArray<nsIFile>*>(array);
     files.AppendObject(localfile);
   }
 
   g_free(filename);
 }
 
 void
-nsFilePicker::ReadValuesFromFileChooser(void *file_chooser)
+nsFilePicker::ReadValuesFromFileChooser(GtkWidget *file_chooser)
 {
   mFiles.Clear();
 
   if (mMode == nsIFilePicker::modeOpenMultiple) {
     mFileURL.Truncate();
 
     GSList *list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(file_chooser));
     g_slist_foreach(list, ReadMultipleFiles, static_cast<gpointer>(&mFiles));
@@ -384,36 +384,49 @@ nsFilePicker::Open(nsIFilePickerShownCal
 
   GtkFileChooserAction action = GetGtkFileChooserAction(mMode);
 
   const gchar* accept_button;
   NS_ConvertUTF16toUTF8 buttonLabel(mOkButtonLabel);
   if (!mOkButtonLabel.IsEmpty()) {
     accept_button = buttonLabel.get();
   } else {
-    accept_button = nullptr;
+    accept_button = (action == GTK_FILE_CHOOSER_ACTION_SAVE) ?
+                    GTK_STOCK_SAVE : GTK_STOCK_OPEN;
   }
 
-  void *file_chooser = GtkFileChooserNew(title.get(), parent_widget, action, accept_button);
+  GtkWidget *file_chooser =
+      gtk_file_chooser_dialog_new(title.get(), parent_widget, action,
+                                  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                  accept_button, GTK_RESPONSE_ACCEPT,
+                                  nullptr);
+  gtk_dialog_set_alternative_button_order(GTK_DIALOG(file_chooser),
+                                          GTK_RESPONSE_ACCEPT,
+                                          GTK_RESPONSE_CANCEL,
+                                          -1);
 
   // If we have --enable-proxy-bypass-protection, then don't allow
   // remote URLs to be used.
 #ifndef MOZ_PROXY_BYPASS_PROTECTION
   if (mAllowURLs) {
     gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_chooser), FALSE);
   }
 #endif
 
   if (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SAVE) {
     GtkWidget *img_preview = gtk_image_new();
     gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file_chooser), img_preview);
     g_signal_connect(file_chooser, "update-preview", G_CALLBACK(UpdateFilePreviewWidget), img_preview);
   }
 
-  GtkFileChooserSetModal(file_chooser, parent_widget, TRUE);
+  GtkWindow *window = GTK_WINDOW(file_chooser);
+  gtk_window_set_modal(window, TRUE);
+  if (parent_widget) {
+    gtk_window_set_destroy_with_parent(window, TRUE);
+  }
 
   NS_ConvertUTF16toUTF8 defaultName(mDefault);
   switch (mMode) {
     case nsIFilePicker::modeOpenMultiple:
       gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(file_chooser), TRUE);
       break;
     case nsIFilePicker::modeSave:
       gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(file_chooser),
@@ -441,41 +454,36 @@ nsFilePicker::Open(nsIFilePickerShownCal
       defaultPath->GetNativePath(directory);
 
 #ifdef MOZ_WIDGET_GTK
       // Workaround for problematic refcounting in GTK3 before 3.16.
       // We need to keep a reference to the dialog's internal delegate.
       // Otherwise, if our dialog gets destroyed, we'll lose the dialog's
       // delegate by the time this gets processed in the event loop.
       // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1166741
-      if (GTK_IS_DIALOG(file_chooser)) {
-        GtkDialog *dialog = GTK_DIALOG(file_chooser);
-        GtkContainer *area = GTK_CONTAINER(gtk_dialog_get_content_area(dialog));
-        gtk_container_forall(area, [](GtkWidget *widget,
-                                      gpointer data) {
-            if (GTK_IS_FILE_CHOOSER_WIDGET(widget)) {
-              auto result = static_cast<GtkFileChooserWidget**>(data);
-              *result = GTK_FILE_CHOOSER_WIDGET(widget);
-            }
-        }, &mFileChooserDelegate);
+      GtkDialog *dialog = GTK_DIALOG(file_chooser);
+      GtkContainer *area = GTK_CONTAINER(gtk_dialog_get_content_area(dialog));
+      gtk_container_forall(area, [](GtkWidget *widget,
+                                    gpointer data) {
+          if (GTK_IS_FILE_CHOOSER_WIDGET(widget)) {
+            auto result = static_cast<GtkFileChooserWidget**>(data);
+            *result = GTK_FILE_CHOOSER_WIDGET(widget);
+          }
+      }, &mFileChooserDelegate);
 
-        if (mFileChooserDelegate != nullptr) {
-          g_object_ref(mFileChooserDelegate);
-        }
-      }
+      if (mFileChooserDelegate)
+        g_object_ref(mFileChooserDelegate);
 #endif
 
       gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser),
                                           directory.get());
     }
   }
 
-  if (GTK_IS_DIALOG(file_chooser)) {
-    gtk_dialog_set_default_response(GTK_DIALOG(file_chooser), GTK_RESPONSE_ACCEPT);
-  }
+  gtk_dialog_set_default_response(GTK_DIALOG(file_chooser), GTK_RESPONSE_ACCEPT);
 
   int32_t count = mFilters.Length();
   for (int32_t i = 0; i < count; ++i) {
     // This is fun... the GTK file picker does not accept a list of filters
     // so we need to split out each string, and add it manually.
 
     char **patterns = g_strsplit(mFilters[i].get(), ";", -1);
     if (!patterns) {
@@ -509,38 +517,39 @@ nsFilePicker::Open(nsIFilePickerShownCal
   }
 
   gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(file_chooser), TRUE);
 
   mRunning = true;
   mCallback = aCallback;
   NS_ADDREF_THIS();
   g_signal_connect(file_chooser, "response", G_CALLBACK(OnResponse), this);
-  GtkFileChooserShow(file_chooser);
+  g_signal_connect(file_chooser, "destroy", G_CALLBACK(OnDestroy), this);
+  gtk_widget_show(file_chooser);
 
   return NS_OK;
 }
 
 /* static */ void
-nsFilePicker::OnResponse(void* file_chooser, gint response_id,
+nsFilePicker::OnResponse(GtkWidget* file_chooser, gint response_id,
                          gpointer user_data)
 {
   static_cast<nsFilePicker*>(user_data)->
     Done(file_chooser, response_id);
 }
 
 /* static */ void
 nsFilePicker::OnDestroy(GtkWidget* file_chooser, gpointer user_data)
 {
   static_cast<nsFilePicker*>(user_data)->
     Done(file_chooser, GTK_RESPONSE_CANCEL);
 }
 
 void
-nsFilePicker::Done(void* file_chooser, gint response)
+nsFilePicker::Done(GtkWidget* file_chooser, gint response)
 {
   mRunning = false;
 
   int16_t result;
   switch (response) {
     case GTK_RESPONSE_OK:
     case GTK_RESPONSE_ACCEPT:
     ReadValuesFromFileChooser(file_chooser);
@@ -574,17 +583,17 @@ nsFilePicker::Done(void* file_chooser, g
                                        FuncToGpointer(OnDestroy), this);
 
   // When response_id is GTK_RESPONSE_DELETE_EVENT or when called from
   // OnDestroy, the widget would be destroyed anyway but it is fine if
   // gtk_widget_destroy is called more than once.  gtk_widget_destroy has
   // requests that any remaining references be released, but the reference
   // count will not be decremented again if GtkWindow's reference has already
   // been released.
-  GtkFileChooserDestroy(file_chooser);
+  gtk_widget_destroy(file_chooser);
 
 #ifdef MOZ_WIDGET_GTK
       if (mFileChooserDelegate) {
         // Properly deref our acquired reference. We call this after
         // gtk_widget_destroy() to try and ensure that pending file info
         // queries caused by updating the current folder have been cancelled.
         // However, we do not know for certain when the callback will run after
         // cancelled.
@@ -599,78 +608,8 @@ nsFilePicker::Done(void* file_chooser, g
   if (mCallback) {
     mCallback->Done(result);
     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 = (GtkFileChooserNative * (*)(
-        const gchar *, GtkWindow *,
-        GtkFileChooserAction,
-        const gchar *, const gchar *))
-      dlsym(RTLD_DEFAULT, "gtk_file_chooser_native_new");
-  if (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(title, parent, action,
-      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-      accept_label, GTK_RESPONSE_ACCEPT, nullptr);
-  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) {
-    (*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) {
-    (*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) {
-    (*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
@@ -43,22 +43,22 @@ public:
                           const nsAString& aTitle) override;
 
   static void Shutdown();
 
 protected:
   virtual ~nsFilePicker();
 
   nsresult Show(int16_t *aReturn) override;
-  void ReadValuesFromFileChooser(void *file_chooser);
+  void ReadValuesFromFileChooser(GtkWidget *file_chooser);
 
-  static void OnResponse(void* file_chooser, gint response_id,
+  static void OnResponse(GtkWidget* dialog, gint response_id,
                          gpointer user_data);
-  static void OnDestroy(GtkWidget* file_chooser, gpointer user_data);
-  void Done(void* file_chooser, gint response_id);
+  static void OnDestroy(GtkWidget* dialog, gpointer user_data);
+  void Done(GtkWidget* dialog, gint response_id);
 
   nsCOMPtr<nsIWidget>    mParentWidget;
   nsCOMPtr<nsIFilePickerShownCallback> mCallback;
   nsCOMArray<nsIFile> mFiles;
 
   int16_t   mSelectedType;
   int16_t   mResult;
   bool      mRunning;
@@ -69,23 +69,14 @@ protected:
   nsString  mDefaultExtension;
 
   nsTArray<nsCString> mFilters;
   nsTArray<nsCString> mFilterNames;
 
 private:
   static nsIFile *mPrevDisplayDirectory;
 
-  void *GtkFileChooserNew(
-          const gchar *title, GtkWindow *parent,
-          GtkFileChooserAction action,
-          const gchar *accept_label);
-  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
 };
 
 #endif