Bug 545119, use link drop service for tabbrowser dataTransfer for search engine dialog and remove browser dependency on nsDragAndDrop.js, r=gavin

This commit is contained in:
Neil Deakin 2010-05-26 11:28:25 -04:00
parent 5e74cd74e2
commit e5bcae8d66
5 changed files with 33 additions and 75 deletions

View File

@ -2728,9 +2728,11 @@ function FillInHTMLTooltip(tipElement)
}
var browserDragAndDrop = {
canDropLink: function (aEvent) Services.droppedLinkHandler.canDropLink(aEvent, true),
dragOver: function (aEvent, statusString)
{
if (Services.droppedLinkHandler.canDropLink(aEvent, true)) {
if (this.canDropLink(aEvent)) {
aEvent.preventDefault();
if (statusString) {
@ -2872,8 +2874,6 @@ var newWindowButtonObserver = {
}
var DownloadsButtonDNDObserver = {
/////////////////////////////////////////////////////////////////////////////
// nsDragAndDrop
onDragOver: function (aEvent)
{
var statusTextFld = document.getElementById("statusbar-display");

View File

@ -102,10 +102,6 @@
<script type="application/javascript" src="chrome://browser/content/places/editBookmarkOverlay.js"/>
<!-- This is still used for dragDropSecurityCheck and transferUtils. Since we
rely on the new Drag and Drop API these dependencies should be removed. -->
<script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
# All sets except for popupsets (commands, keys, stringbundles and broadcasters) *must* go into the
# browser-sets.inc file for sharing with hiddenWindow.xul.
#include browser-sets.inc

View File

@ -2152,17 +2152,6 @@
onget="return this.mCurrentBrowser.securityUI;"
readonly="true"/>
<method name="dragDropSecurityCheck">
<parameter name="aEvent"/>
<parameter name="aDragSession"/>
<parameter name="aUri"/>
<body>
<![CDATA[
nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, aUri);
]]>
</body>
</method>
<method name="_handleKeyEvent">
<parameter name="aEvent"/>
<body><![CDATA[
@ -2512,10 +2501,6 @@
<field name="_dragOverDelay">350</field>
<field name="_dragTime">0</field>
<field name="_supportedLinkDropTypes"><![CDATA[
["text/x-moz-url", "text/uri-list", "text/plain", "application/x-moz-file"]
]]></field>
<field name="_container" readonly="true"><![CDATA[
this.parentNode && this.parentNode.localName == "toolbar" ? this.parentNode : this;
]]></field>
@ -2709,11 +2694,9 @@
}
}
for (let i = 0; i < this._supportedLinkDropTypes.length; i++) {
if (types.contains(this._supportedLinkDropTypes[i])) {
// Here we need to to do this manually
return dt.effectAllowed = dt.dropEffect = "link";
}
if (browserDragAndDrop.canDropLink(event)) {
// Here we need to do this manually
return dt.effectAllowed = dt.dropEffect = "link";
}
return dt.effectAllowed = "none";
]]></body>
@ -2961,20 +2944,7 @@
// it triggers will correctly update our URL bar.
this.tabbrowser.selectedTab = newTab;
} else {
let url;
for (let i = 0; i < this._supportedLinkDropTypes.length; i++) {
let dataType = this._supportedLinkDropTypes[i];
// uri-list: for now, support dropping of the first URL
// only
let isURLList = dataType == "text/uri-list";
let urlData = isURLList ?
dt.mozGetDataAt("URL", 0) : dt.mozGetDataAt(dataType, 0);
if (urlData) {
url = transferUtils.retrieveURLFromData(urlData, isURLList ? "text/plain" : dataType);
break;
}
}
NS_ASSERT(url, "In the drop event, at least one mime-type should match our supported types");
let url = browserDragAndDrop.drop(event, { });
// valid urls don't contain spaces ' '; if we have a space it isn't a valid url.
// Also disallow dropping javascript: or data: urls--bail out
@ -2982,13 +2952,6 @@
/^\s*(javascript|data):/.test(url))
return;
// XXXmano: temporary fix until dragDropSecurityCheck make the
// drag-session an optional paramter
let dragService = Cc["@mozilla.org/widget/dragservice;1"].
getService(Ci.nsIDragService);
let dragSession = dragService.getCurrentSession();
nsDragAndDrop.dragDropSecurityCheck(event, dragSession, url);
let bgLoad = Services.prefs.getBoolPref("browser.tabs.loadInBackground");
if (event.shiftKey)

View File

@ -1,5 +1,7 @@
function test()
{
waitForExplicitFinish();
// ---- Test dragging the proxy icon ---
var value = content.location.href;
var urlString = value + "\n" + content.document.title;
@ -24,4 +26,22 @@ function test()
// Now, the identity information panel is opened by the proxy icon click.
// We need to close it for next tests.
EventUtils.synthesizeKey("VK_ESCAPE", {}, window);
// now test dragging onto a tab
var tab1 = gBrowser.addTab();
var browser1 = gBrowser.getBrowserForTab(tab1);
var tab2 = gBrowser.addTab();
var browser2 = gBrowser.getBrowserForTab(tab2);
gBrowser.selectedTab = tab1;
browser2.addEventListener("load", function () {
is(browser2.contentWindow.location, "http://mochi.test:8888/", "drop on tab");
gBrowser.removeCurrentTab();
gBrowser.removeCurrentTab();
finish();
}, true);
EventUtils.synthesizeDrop(tab2, [[{type: "text/uri-list", data: "http://mochi.test:8888/"}]], "copy", window);
}

View File

@ -465,29 +465,8 @@ EngineView.prototype = {
this.tree.ensureRowIsVisible(index);
},
getSourceIndexFromDrag: function () {
var dragService = Cc["@mozilla.org/widget/dragservice;1"].
getService().QueryInterface(Ci.nsIDragService);
var dragSession = dragService.getCurrentSession();
var transfer = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
transfer.addDataFlavor(ENGINE_FLAVOR);
dragSession.getData(transfer, 0);
var dataObj = {};
var len = {};
var sourceIndex = -1;
try {
transfer.getAnyTransferData({}, dataObj, len);
} catch (ex) {}
if (dataObj.value) {
sourceIndex = dataObj.value.QueryInterface(Ci.nsISupportsString).data;
sourceIndex = parseInt(sourceIndex.substring(0, len.value));
}
return sourceIndex;
getSourceIndexFromDrag: function (dataTransfer) {
return parseInt(dataTransfer.getData(ENGINE_FLAVOR));
},
// nsITreeView
@ -513,15 +492,15 @@ EngineView.prototype = {
this.tree = tree;
},
canDrop: function(targetIndex, orientation) {
var sourceIndex = this.getSourceIndexFromDrag();
canDrop: function(targetIndex, orientation, dataTransfer) {
var sourceIndex = this.getSourceIndexFromDrag(dataTransfer);
return (sourceIndex != -1 &&
sourceIndex != targetIndex &&
sourceIndex != (targetIndex + orientation));
},
drop: function(dropIndex, orientation) {
var sourceIndex = this.getSourceIndexFromDrag();
drop: function(dropIndex, orientation, dataTransfer) {
var sourceIndex = this.getSourceIndexFromDrag(dataTransfer);
var sourceEngine = this._engineStore.engines[sourceIndex];
if (dropIndex > sourceIndex) {