From 82e3ed418c5eb849d024a87f67c5924129578291 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 9 Jan 2013 11:28:35 -0800 Subject: [PATCH] Bug 827608 - Use html context menus for about:apps. r=mfinkle --- mobile/android/chrome/content/aboutApps.js | 71 +++++++++++-------- mobile/android/chrome/content/aboutApps.xhtml | 6 ++ .../locales/en-US/chrome/aboutApps.dtd | 2 + .../locales/en-US/chrome/aboutApps.properties | 6 -- mobile/android/locales/jar.mn | 1 - 5 files changed, 49 insertions(+), 37 deletions(-) delete mode 100644 mobile/android/locales/en-US/chrome/aboutApps.properties diff --git a/mobile/android/chrome/content/aboutApps.js b/mobile/android/chrome/content/aboutApps.js index 605fdb4e58d..2affceb9517 100644 --- a/mobile/android/chrome/content/aboutApps.js +++ b/mobile/android/chrome/content/aboutApps.js @@ -37,6 +37,45 @@ function openLink(aElement) { } catch (ex) {} } +var ContextMenus = { + target: null, + + init: function() { + document.addEventListener("contextmenu", ContextMenus, false); + }, + + handleEvent: function(event) { + // store the target of context menu events so that we know which app to act on + this.target = event.target; + while (!this.target.hasAttribute("contextmenu")) { + this.target = this.target.parentNode; + } + }, + + addToHomescreen: function() { + let manifest = this.target.manifest; + let origin = Services.io.newURI(this.target.app.origin, null, null); + gChromeWin.WebappsUI.createShortcut(manifest.name, manifest.fullLaunchPath(), gChromeWin.WebappsUI.getBiggestIcon(manifest.icons, origin), "webapp"); + this.target = null; + }, + + uninstall: function() { + this.target.app.uninstall(); + + let manifest = this.target.manifest; + gChromeWin.sendMessageToJava({ + gecko: { + type: "Shortcut:Remove", + title: manifest.name, + url: manifest.fullLaunchPath(), + origin: this.target.app.origin, + shortcutType: "webapp" + } + }); + this.target = null; + } +} + function onLoad(aEvent) { try { let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter); @@ -49,36 +88,7 @@ function onLoad(aEvent) { navigator.mozApps.mgmt.onuninstall = onUninstall; updateList(); - let contextmenus = gChromeWin.NativeWindow.contextmenus; - AppsUI.shortcut = contextmenus.add(gStrings.GetStringFromName("appsContext.shortcut"), contextmenus.SelectorContext("div[mozApp]"), - function(aTarget) { - let manifest = aTarget.manifest; - let origin = Services.io.newURI(aTarget.app.origin, null, null); - gChromeWin.WebappsUI.createShortcut(manifest.name, manifest.fullLaunchPath(), gChromeWin.WebappsUI.getBiggestIcon(manifest.icons, origin), "webapp"); - }); - AppsUI.uninstall = contextmenus.add(gStrings.GetStringFromName("appsContext.uninstall"), contextmenus.SelectorContext("div[mozApp]"), - function(aTarget) { - aTarget.app.uninstall(); - - let manifest = aTarget.manifest; - gChromeWin.sendMessageToJava({ - gecko: { - type: "Shortcut:Remove", - title: manifest.name, - url: manifest.fullLaunchPath(), - origin: aTarget.app.origin, - shortcutType: "webapp" - } - }); - }); -} - -function onUnload(aEvent) { - let contextmenus = gChromeWin.NativeWindow.contextmenus; - if (AppsUI.shortcut) - contextmenus.remove(AppsUI.shortcut); - if (AppsUI.uninstall) - contextmenus.remove(AppsUI.uninstall); + ContextMenus.init(); } function updateList() { @@ -102,6 +112,7 @@ function addApplication(aApp) { let container = document.createElement("div"); container.className = "app"; + container.setAttribute("contextmenu", "appmenu"); container.setAttribute("id", "app-" + aApp.origin); container.setAttribute("mozApp", aApp.origin); container.setAttribute("title", manifest.name); diff --git a/mobile/android/chrome/content/aboutApps.xhtml b/mobile/android/chrome/content/aboutApps.xhtml index 7ac8f54a05d..f5f4f502ed8 100644 --- a/mobile/android/chrome/content/aboutApps.xhtml +++ b/mobile/android/chrome/content/aboutApps.xhtml @@ -27,6 +27,12 @@ + + + + + +
&aboutApps.header;
diff --git a/mobile/android/locales/en-US/chrome/aboutApps.dtd b/mobile/android/locales/en-US/chrome/aboutApps.dtd index e044d7033d2..f5d09a6b93c 100644 --- a/mobile/android/locales/en-US/chrome/aboutApps.dtd +++ b/mobile/android/locales/en-US/chrome/aboutApps.dtd @@ -11,3 +11,5 @@ + + diff --git a/mobile/android/locales/en-US/chrome/aboutApps.properties b/mobile/android/locales/en-US/chrome/aboutApps.properties deleted file mode 100644 index 147fe12f9ca..00000000000 --- a/mobile/android/locales/en-US/chrome/aboutApps.properties +++ /dev/null @@ -1,6 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -appsContext.uninstall=Uninstall -appsContext.shortcut=Add to Home Screen diff --git a/mobile/android/locales/jar.mn b/mobile/android/locales/jar.mn index f6543f76864..ef18ee3fa0e 100644 --- a/mobile/android/locales/jar.mn +++ b/mobile/android/locales/jar.mn @@ -10,7 +10,6 @@ locale/@AB_CD@/browser/aboutAddons.dtd (%chrome/aboutAddons.dtd) locale/@AB_CD@/browser/aboutAddons.properties (%chrome/aboutAddons.properties) locale/@AB_CD@/browser/aboutApps.dtd (%chrome/aboutApps.dtd) - locale/@AB_CD@/browser/aboutApps.properties (%chrome/aboutApps.properties) locale/@AB_CD@/browser/aboutCertError.dtd (%chrome/aboutCertError.dtd) locale/@AB_CD@/browser/aboutDownloads.dtd (%chrome/aboutDownloads.dtd) locale/@AB_CD@/browser/aboutDownloads.properties (%chrome/aboutDownloads.properties)