Bug 1463753 - [DragAndDrop] Update mTarget(Wayland)DragContext unconditionally and check its validity after that, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Thu, 24 May 2018 11:51:17 +0200
changeset 419687 172827af80fa02953e0c7723c0dee915c411c286
parent 419686 a5c04fe7278db916b3efd5f06a5f2a9da0d64ad2
child 419688 ffb639607291b4dcf3bce8d7cd78ae18b43a9cf3
push id64384
push userstransky@redhat.com
push dateThu, 24 May 2018 11:07:03 +0000
treeherderautoland@172827af80fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1463753
milestone62.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 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;