Bug 774362 - Switch to new drag and drop api for go and search buttons r=neil
authorIan Neal <iann_cvs@blueyonder.co.uk>
Tue, 31 Jul 2012 23:45:08 +0100
changeset 13178 54f3c239ef7a0a35f74c69012d5a254227a30ba2
parent 13177 ca8eda5e95fdf0499b6d8acbc8dea49c288bd39f
child 13179 112daf200c72444c046e1a0b5659c77baf9ae9e8
push idunknown
push userunknown
push dateunknown
reviewersneil
bugs774362
Bug 774362 - Switch to new drag and drop api for go and search buttons r=neil
suite/browser/navigator.xul
suite/browser/navigatorDD.js
--- a/suite/browser/navigator.xul
+++ b/suite/browser/navigator.xul
@@ -311,32 +311,30 @@
                    title="&goButton.label;">
         <button id="go-button"
                 class="button-toolbar chromeclass-location"
                 label="&goButton.label;"
                 tooltiptext="&goButton.tooltip;"
                 default="true"
                 oncommand="handleURLBarCommand('none', event);"
                 onclick="checkForMiddleClick(this, event);"
-                ondragover="nsDragAndDrop.dragOver(event, goButtonObserver);"
-                ondragdrop="nsDragAndDrop.drop(event, goButtonObserver);"
-                ondragexit="nsDragAndDrop.dragExit(event, goButtonObserver);"/>
+                ondragover="goButtonObserver.onDragOver(event);"
+                ondragdrop="goButtonObserver.onDrop(event);"/>
       </toolbaritem>
 
       <toolbaritem id="search-button-container"
                    class="nav-bar-class"
                    title="&searchButton.label;">
         <button id="search-button"
                 class="button-toolbar chromeclass-location"
                 label="&searchButton.label;"
                 tooltiptext="&searchButton.tooltip;"
                 oncommand="BrowserSearch.loadSearch(QualifySearchTerm());"
-                ondragover="nsDragAndDrop.dragOver(event, searchButtonObserver);"
-                ondragdrop="nsDragAndDrop.drop(event, searchButtonObserver);"
-                ondragexit="nsDragAndDrop.dragExit(event, searchButtonObserver);"/>
+                ondragover="searchButtonObserver.onDragOver(event);"
+                ondragdrop="searchButtonObserver.onDrop(event);"/>
       </toolbaritem>
 
       <toolbaritem id="search-container" title="&searchItem.title;"
                    align="center" class="chromeclass-toolbar-additional nav-bar-class"
                    flex="1" persist="width" removable="true">
         <searchbar id="searchbar" flex="1"/>
       </toolbaritem>
 
--- a/suite/browser/navigatorDD.js
+++ b/suite/browser/navigatorDD.js
@@ -127,74 +127,31 @@ function openHomeDialog(aURL)
                                 (Services.prompt.BUTTON_TITLE_CANCEL *
                                  Services.prompt.BUTTON_POS_1),
                                 okButton, null, null, null,
                                 {value: false}) == 0)
     SetStringPref("browser.startup.homepage", aURL);
 }
 
 var goButtonObserver = {
-  onDragOver: function(aEvent, aFlavour, aDragSession)
-    {
-      aEvent.target.setAttribute("dragover", "true");
-      return true;
-    },
-  onDragExit: function (aEvent, aDragSession)
-    {
-      aEvent.target.removeAttribute("dragover");
-    },
-  onDrop: function (aEvent, aXferData, aDragSession)
-    {
-      var xferData = aXferData.data.split("\n");
-      var draggedText = xferData[0] || xferData[1];
-      nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, draggedText);
+  onDragOver: DragLinkOver,
 
-      var uri;
-      try {
-        uri = makeURI(draggedText);
-      } catch (ex) { }
-      if (uri) {
-        // we have a valid url, so do a security check for javascript.
-        const nsIScriptSecMan = Components.interfaces.nsIScriptSecurityManager;
-        urlSecurityCheck(uri, content.document.nodePrincipal,
-                         nsIScriptSecMan.DISALLOW_SCRIPT_OR_DATA);
-      }
-
-      var postData = {};
-      var url = getShortcutOrURI(draggedText, postData);
+  onDrop: function (aEvent)
+  {
+    var url = Services.droppedLinkHandler.dropLink(aEvent, {});
+    var postData = {};
+    url = getShortcutOrURI(url, postData);
+    if (url)
       loadURI(url, null, postData.value, true);
-    },
-  getSupportedFlavours: function ()
-    {
-      var flavourSet = new FlavourSet();
-      flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
-      flavourSet.appendFlavour("text/x-moz-url");
-      flavourSet.appendFlavour("text/unicode");
-      return flavourSet;
-    }
-}
+  }
+};
 
 var searchButtonObserver = {
-  onDragOver: function(aEvent, aFlavour, aDragSession)
-    {
-      aEvent.target.setAttribute("dragover", "true");
-      return true;
-    },
-  onDragExit: function (aEvent, aDragSession)
-    {
-      aEvent.target.removeAttribute("dragover");
-    },
-  onDrop: function (aEvent, aXferData, aDragSession)
-    {
-      var xferData = aXferData.data.split("\n");
-      var uri = xferData[1] ? xferData[1] : xferData[0];
-      if (uri)
-        BrowserSearch.loadSearch(uri);
-    },
-  getSupportedFlavours: function ()
-    {
-      var flavourSet = new FlavourSet();
-      flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
-      flavourSet.appendFlavour("text/x-moz-url");
-      flavourSet.appendFlavour("text/unicode");
-      return flavourSet;
-    }
-}
+  onDragOver: DragLinkOver,
+
+  onDrop: function (aEvent)
+  {
+    var name = {};
+    var url = Services.droppedLinkHandler.dropLink(aEvent, name);
+    if (url)
+      BrowserSearch.loadSearch(name.value || url);
+  }
+};