Bug 1463753 - [DragAndDrop] Update mTarget(Wayland)DragContext unconditionally and check its validity after that, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Thu, 24 May 2018 11:51:17 +0200
changeset 799221 336173e762381d600eb270d4f5881ed013d0285e
parent 799120 47e81ea1ef10189ef210867934bf36e14cf223dc
push id110978
push userstransky@redhat.com
push dateThu, 24 May 2018 10:20:05 +0000
reviewersjhorak
bugs1463753
milestone62.0a1
Bug 1463753 - [DragAndDrop] Update mTarget(Wayland)DragContext unconditionally and check its validity after that, r?jhorak MozReview-Commit-ID: KiNaPDDVvLu
widget/gtk/nsDragService.cpp
--- a/widget/gtk/nsDragService.cpp
+++ b/widget/gtk/nsDragService.cpp
@@ -1043,21 +1043,21 @@ nsDragService::IsDataFlavorSupported(con
     }
 
     // check the target context vs. this flavor, one at a time
     GList *tmp = nullptr;
     if (mTargetDragContext) {
         tmp = gdk_drag_context_list_targets(mTargetDragContext);
     }
 #ifdef MOZ_WAYLAND
-    else {
+    else if (mTargetWaylandDragContext) {
         tmp = mTargetWaylandDragContext->GetTargets();
     }
+    GList *tmp_head = tmp;
 #endif
-    GList *tmp_head = tmp;
 
     for (; tmp; tmp = tmp->next) {
         /* Bug 331198 */
         GdkAtom atom = GDK_POINTER_TO_ATOM(tmp->data);
         gchar *name = nullptr;
         name = gdk_atom_name(atom);
         MOZ_LOG(sDragLm, LogLevel::Debug,
                ("checking %s against %s\n", name, aDataFlavor));
@@ -1095,21 +1095,23 @@ nsDragService::IsDataFlavorSupported(con
             MOZ_LOG(sDragLm, LogLevel::Debug,
                    ("good! ( it's text plain and we're checking \
                    against text/unicode or application/x-moz-file)\n"));
             *_retval = true;
         }
         g_free(name);
     }
 
+#ifdef MOZ_WAYLAND
     // mTargetWaylandDragContext->GetTargets allocates the list
     // so we need to free it here.
-    if (!mTargetDragContext) {
+    if (!mTargetDragContext && tmp_head) {
         g_list_free(tmp_head);
     }
+#endif
 
     return NS_OK;
 }
 
 void
 nsDragService::ReplyToDragMotion(GdkDragContext* aDragContext)
 {
     MOZ_LOG(sDragLm, LogLevel::Debug,
@@ -2007,23 +2009,19 @@ nsDragService::RunScheduledTask()
     // This may be the start of a destination drag session.
     StartDragSession();
 
     // mTargetWidget may be nullptr if the window has been destroyed.
     // (The leave event is not scheduled if a drop task is still scheduled.)
     // We still reply appropriately to indicate that the drop will or didn't
     // succeeed.
     mTargetWidget = mTargetWindow->GetMozContainerWidget();
-    if (mTargetDragContext) {
-        mTargetDragContext.steal(mPendingDragContext);
-    }
+    mTargetDragContext.steal(mPendingDragContext);
 #ifdef MOZ_WAYLAND
-    else {
-        mTargetWaylandDragContext = mPendingWaylandDragContext.forget();
-    }
+    mTargetWaylandDragContext = mPendingWaylandDragContext.forget();
 #endif
     mTargetTime = mPendingTime;
 
     // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#drag-and-drop-processing-model
     // (as at 27 December 2010) indicates that a "drop" event should only be
     // fired (at the current target element) if the current drag operation is
     // not none.  The current drag operation will only be set to a non-none
     // value during a "dragover" event.
@@ -2056,17 +2054,17 @@ nsDragService::RunScheduledTask()
 #endif
           } else {
               // Reply to tell the source whether we can drop and what
               // action would be taken.
               if (mTargetDragContext) {
                   ReplyToDragMotion(mTargetDragContext);
               }
 #ifdef MOZ_WAYLAND
-              else {
+              else if (mTargetWaylandDragContext) {
                   ReplyToDragMotion(mTargetWaylandDragContext);
               }
 #endif
           }
         }
     }
 
     if (task == eDragTaskDrop) {
@@ -2123,17 +2121,17 @@ nsDragService::UpdateDragAction()
 
     // default is to do nothing
     int action = nsIDragService::DRAGDROP_ACTION_NONE;
     GdkDragAction gdkAction = GDK_ACTION_DEFAULT;
     if (mTargetDragContext) {
         gdkAction = gdk_drag_context_get_actions(mTargetDragContext);
     }
 #ifdef MOZ_WAYLAND
-    else {
+    else if (mTargetWaylandDragContext) {
         // We got the selected D&D action from compositor on Wayland.
         gdkAction = mTargetWaylandDragContext->GetSelectedDragAction();
     }
 #endif
 
     // set the default just in case nothing matches below
     if (gdkAction & GDK_ACTION_DEFAULT)
         action = nsIDragService::DRAGDROP_ACTION_MOVE;