зеркало из https://github.com/mozilla/gecko-dev.git
Bug 92737 - Part 2: Open multiple tabs when multiple items are dropped on non-remote content area. r=Gijs
This commit is contained in:
Родитель
2bd5613240
Коммит
9867f060f7
|
@ -3395,8 +3395,8 @@ var browserDragAndDrop = {
|
|||
}
|
||||
},
|
||||
|
||||
drop: function (aEvent, aName, aDisallowInherit) {
|
||||
return Services.droppedLinkHandler.dropLink(aEvent, aName, aDisallowInherit);
|
||||
dropLinks: function (aEvent, aDisallowInherit) {
|
||||
return Services.droppedLinkHandler.dropLinks(aEvent, aDisallowInherit);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -5638,14 +5638,43 @@ function stripUnsafeProtocolOnPaste(pasteData) {
|
|||
return pasteData.replace(/^(?:\s*javascript:)+/i, "");
|
||||
}
|
||||
|
||||
function handleDroppedLink(event, url, name)
|
||||
// handleDroppedLink has the following 2 overloads:
|
||||
// handleDroppedLink(event, url, name)
|
||||
// handleDroppedLink(event, links)
|
||||
function handleDroppedLink(event, urlOrLinks, name)
|
||||
{
|
||||
let links;
|
||||
if (Array.isArray(urlOrLinks)) {
|
||||
links = urlOrLinks;
|
||||
} else {
|
||||
links = [{ url: urlOrLinks, name, type: "" }];
|
||||
}
|
||||
|
||||
let lastLocationChange = gBrowser.selectedBrowser.lastLocationChange;
|
||||
|
||||
getShortcutOrURIAndPostData(url).then(data => {
|
||||
if (data.url &&
|
||||
lastLocationChange == gBrowser.selectedBrowser.lastLocationChange)
|
||||
loadURI(data.url, null, data.postData, false);
|
||||
let userContextId = gBrowser.selectedBrowser.getAttribute("usercontextid");
|
||||
|
||||
let inBackground = Services.prefs.getBoolPref("browser.tabs.loadInBackground");
|
||||
if (event.shiftKey)
|
||||
inBackground = !inBackground;
|
||||
|
||||
Task.spawn(function*() {
|
||||
let urls = [];
|
||||
let postDatas = [];
|
||||
for (let link of links) {
|
||||
let data = yield getShortcutOrURIAndPostData(link.url);
|
||||
urls.push(data.url);
|
||||
postDatas.push(data.postData);
|
||||
}
|
||||
if (lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) {
|
||||
gBrowser.loadTabs(urls, {
|
||||
inBackground,
|
||||
replace: true,
|
||||
allowThirdPartyFixup: false,
|
||||
postDatas,
|
||||
userContextId,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Keep the event from being handled by the dragDrop listeners
|
||||
|
|
|
@ -1551,6 +1551,24 @@
|
|||
<parameter name="aLoadInBackground"/>
|
||||
<parameter name="aReplace"/>
|
||||
<body><![CDATA[
|
||||
let aAllowThirdPartyFixup;
|
||||
let aTargetTab;
|
||||
let aNewIndex = -1;
|
||||
let aPostDatas = [];
|
||||
let aUserContextId;
|
||||
if (arguments.length == 2 &&
|
||||
typeof arguments[1] == "object") {
|
||||
let params = arguments[1];
|
||||
aLoadInBackground = params.inBackground;
|
||||
aReplace = params.replace;
|
||||
aAllowThirdPartyFixup = params.allowThirdPartyFixup;
|
||||
aTargetTab = params.targetTab;
|
||||
aNewIndex = typeof params.newIndex === "number" ?
|
||||
params.newIndex : aNewIndex;
|
||||
aPostDatas = params.postDatas || aPostDatas;
|
||||
aUserContextId = params.userContextId;
|
||||
}
|
||||
|
||||
if (!aURIs.length)
|
||||
return;
|
||||
|
||||
|
@ -1568,22 +1586,53 @@
|
|||
var multiple = aURIs.length > 1;
|
||||
var owner = multiple || aLoadInBackground ? null : this.selectedTab;
|
||||
var firstTabAdded = null;
|
||||
var targetTabIndex = -1;
|
||||
|
||||
if (aReplace) {
|
||||
let browser;
|
||||
if (aTargetTab) {
|
||||
browser = this.getBrowserForTab(aTargetTab);
|
||||
targetTabIndex = aTargetTab._tPos;
|
||||
} else {
|
||||
browser = this.mCurrentBrowser;
|
||||
targetTabIndex = this.tabContainer.selectedIndex;
|
||||
}
|
||||
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
if (aAllowThirdPartyFixup) {
|
||||
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
|
||||
}
|
||||
try {
|
||||
this.loadURI(aURIs[0], null, null);
|
||||
browser.loadURIWithFlags(aURIs[0], {
|
||||
flags, postData: aPostDatas[0]
|
||||
});
|
||||
} catch (e) {
|
||||
// Ignore failure in case a URI is wrong, so we can continue
|
||||
// opening the next ones.
|
||||
}
|
||||
} else {
|
||||
firstTabAdded = this.addTab(aURIs[0], {
|
||||
ownerTab: owner,
|
||||
skipAnimation: multiple,
|
||||
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
||||
postData: aPostDatas[0],
|
||||
userContextId: aUserContextId
|
||||
});
|
||||
if (aNewIndex !== -1) {
|
||||
this.moveTabTo(firstTabAdded, aNewIndex);
|
||||
targetTabIndex = firstTabAdded._tPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
firstTabAdded = this.addTab(aURIs[0], {ownerTab: owner, skipAnimation: multiple});
|
||||
|
||||
var tabNum = this.tabContainer.selectedIndex;
|
||||
let tabNum = targetTabIndex;
|
||||
for (let i = 1; i < aURIs.length; ++i) {
|
||||
let tab = this.addTab(aURIs[i], {skipAnimation: true});
|
||||
if (aReplace)
|
||||
let tab = this.addTab(aURIs[i], {
|
||||
skipAnimation: true,
|
||||
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
||||
postData: aPostDatas[i],
|
||||
userContextId: aUserContextId
|
||||
});
|
||||
if (targetTabIndex !== -1)
|
||||
this.moveTabTo(tab, ++tabNum);
|
||||
}
|
||||
|
||||
|
@ -2111,12 +2160,12 @@
|
|||
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_MIXED_CONTENT;
|
||||
try {
|
||||
b.loadURIWithFlags(aURI, {
|
||||
flags: flags,
|
||||
referrerURI: aNoReferrer ? null: aReferrerURI,
|
||||
referrerPolicy: aReferrerPolicy,
|
||||
charset: aCharset,
|
||||
postData: aPostData,
|
||||
});
|
||||
flags,
|
||||
referrerURI: aNoReferrer ? null: aReferrerURI,
|
||||
referrerPolicy: aReferrerPolicy,
|
||||
charset: aCharset,
|
||||
postData: aPostData,
|
||||
});
|
||||
} catch (ex) {
|
||||
Cu.reportError(ex);
|
||||
}
|
||||
|
@ -5678,30 +5727,28 @@
|
|||
<parameter name="event"/>
|
||||
<body><![CDATA[
|
||||
var dt = event.dataTransfer;
|
||||
// Disallow dropping multiple items
|
||||
if (dt.mozItemCount > 1)
|
||||
return "none";
|
||||
if (dt.mozItemCount == 1) {
|
||||
var types = dt.mozTypesAt(0);
|
||||
// tabs are always added as the first type
|
||||
if (types[0] == TAB_DROP_TYPE) {
|
||||
let sourceNode = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
|
||||
if (sourceNode instanceof XULElement &&
|
||||
sourceNode.localName == "tab" &&
|
||||
sourceNode.ownerDocument.defaultView instanceof ChromeWindow &&
|
||||
sourceNode.ownerDocument.documentElement.getAttribute("windowtype") == "navigator:browser" &&
|
||||
sourceNode.ownerDocument.defaultView.gBrowser.tabContainer == sourceNode.parentNode) {
|
||||
// Do not allow transfering a private tab to a non-private window
|
||||
// and vice versa.
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window) !=
|
||||
PrivateBrowsingUtils.isWindowPrivate(sourceNode.ownerDocument.defaultView))
|
||||
return "none";
|
||||
|
||||
var types = dt.mozTypesAt(0);
|
||||
// tabs are always added as the first type
|
||||
if (types[0] == TAB_DROP_TYPE) {
|
||||
let sourceNode = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
|
||||
if (sourceNode instanceof XULElement &&
|
||||
sourceNode.localName == "tab" &&
|
||||
sourceNode.ownerDocument.defaultView instanceof ChromeWindow &&
|
||||
sourceNode.ownerDocument.documentElement.getAttribute("windowtype") == "navigator:browser" &&
|
||||
sourceNode.ownerDocument.defaultView.gBrowser.tabContainer == sourceNode.parentNode) {
|
||||
// Do not allow transfering a private tab to a non-private window
|
||||
// and vice versa.
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window) !=
|
||||
PrivateBrowsingUtils.isWindowPrivate(sourceNode.ownerDocument.defaultView))
|
||||
return "none";
|
||||
if (window.gMultiProcessBrowser !=
|
||||
sourceNode.ownerDocument.defaultView.gMultiProcessBrowser)
|
||||
return "none";
|
||||
|
||||
if (window.gMultiProcessBrowser !=
|
||||
sourceNode.ownerDocument.defaultView.gMultiProcessBrowser)
|
||||
return "none";
|
||||
|
||||
return dt.dropEffect == "copy" ? "copy" : "move";
|
||||
return dt.dropEffect == "copy" ? "copy" : "move";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1440,13 +1440,13 @@
|
|||
getService(Components.interfaces.nsIDroppedLinkHandler);
|
||||
try {
|
||||
// Pass true to prevent the dropping of javascript:/data: URIs
|
||||
var uri = linkHandler.dropLink(event, name, true);
|
||||
var links = linkHandler.dropLinks(event, true);
|
||||
} catch (ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (uri) {
|
||||
this.droppedLinkHandler(event, uri, name.value);
|
||||
if (links.length) {
|
||||
this.droppedLinkHandler(event, links);
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
|
|
Загрузка…
Ссылка в новой задаче