From fb12d9ccf9fa9859352be9fa4262b248843a6637 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Wed, 16 Jun 2010 19:46:11 -0700 Subject: [PATCH] Bug 565682: Support dropping xpi/jar files on the add-ons manager. r=Unfocused --- .../mozapps/extensions/content/extensions.js | 60 ++++++ .../mozapps/extensions/content/extensions.xul | 5 +- .../extensions/test/browser/Makefile.in | 15 +- .../addons/browser_dragdrop1/install.rdf | 22 +++ .../addons/browser_dragdrop2/install.rdf | 22 +++ .../addons/browser_installssl/install.rdf | 22 +++ .../test/browser/browser_dragdrop.js | 185 ++++++++++++++++++ .../test/browser/browser_installssl.js | 4 +- .../test/browser/browser_installssl.xpi | Bin 449 -> 0 bytes .../test/browser/browser_updatessl.js | 4 +- .../mozapps/extensions/test/browser/head.js | 14 ++ 11 files changed, 347 insertions(+), 6 deletions(-) create mode 100644 toolkit/mozapps/extensions/test/browser/addons/browser_dragdrop1/install.rdf create mode 100644 toolkit/mozapps/extensions/test/browser/addons/browser_dragdrop2/install.rdf create mode 100644 toolkit/mozapps/extensions/test/browser/addons/browser_installssl/install.rdf create mode 100644 toolkit/mozapps/extensions/test/browser/browser_dragdrop.js delete mode 100644 toolkit/mozapps/extensions/test/browser/browser_installssl.xpi diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 4996a17189d..3ecbccabb51 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -1256,3 +1256,63 @@ var gDetailView = { this.updateState(); } }; + + +var gDragDrop = { + onDragOver: function(aEvent) { + var types = aEvent.dataTransfer.types; + if (types.contains("text/uri-list") || + types.contains("text/x-moz-url") || + types.contains("application/x-moz-file")) + aEvent.preventDefault(); + }, + + onDrop: function(aEvent) { + var dataTransfer = aEvent.dataTransfer; + var urls = []; + + // Convert every dropped item into a url + for (var i = 0; i < dataTransfer.mozItemCount; i++) { + var url = dataTransfer.mozGetDataAt("text/uri-list", i); + if (url) { + urls.push(url); + continue; + } + + url = dataTransfer.mozGetDataAt("text/x-moz-url", i); + if (url) { + urls.push(url.split("\n")[0]); + continue; + } + + var file = dataTransfer.mozGetDataAt("application/x-moz-file", i); + if (file) { + urls.push(Services.io.newFileURI(file).spec); + continue; + } + } + + var pos = 0; + var installs = []; + + function buildNextInstall() { + if (pos == urls.length) { + if (installs.length > 0) { + // Display the normal install confirmation for the installs + AddonManager.installAddonsFromWebpage("application/x-xpinstall", this, + null, installs); + } + return; + } + + AddonManager.getInstallForURL(urls[pos++], function(aInstall) { + installs.push(aInstall); + buildNextInstall(); + }, "application/x-xpinstall"); + } + + buildNextInstall(); + + aEvent.preventDefault(); + } +}; diff --git a/toolkit/mozapps/extensions/content/extensions.xul b/toolkit/mozapps/extensions/content/extensions.xul index 75e9a3bf6e2..4fd3f53afe1 100644 --- a/toolkit/mozapps/extensions/content/extensions.xul +++ b/toolkit/mozapps/extensions/content/extensions.xul @@ -46,7 +46,10 @@ ]> + id="addons-page" title="&addons.windowTitle;" + ondragenter="gDragDrop.onDragOver(event)" + ondragover="gDragDrop.onDragOver(event)" + ondrop="gDragDrop.onDrop(event)">