2012-03-29 21:50:48 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
let Ci = Components.interfaces, Cc = Components.classes, Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm")
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-10-02 22:38:03 -07:00
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-03-29 21:50:48 -07:00
|
|
|
|
|
|
|
let gStrings = Services.strings.createBundle("chrome://browser/locale/aboutApps.properties");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(window, "gChromeWin", function()
|
|
|
|
window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
|
|
.rootTreeItem
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
|
|
.QueryInterface(Ci.nsIDOMChromeWindow));
|
|
|
|
|
|
|
|
var AppsUI = {
|
|
|
|
uninstall: null,
|
|
|
|
shortcut: null
|
|
|
|
};
|
|
|
|
|
2012-08-07 09:49:30 -07:00
|
|
|
function openLink(aElement) {
|
|
|
|
try {
|
|
|
|
let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
|
|
|
|
let url = formatter.formatURLPref(aElement.getAttribute("pref"));
|
|
|
|
let BrowserApp = gChromeWin.BrowserApp;
|
|
|
|
BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id });
|
|
|
|
} catch (ex) {}
|
|
|
|
}
|
|
|
|
|
2013-01-09 11:28:35 -08:00
|
|
|
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() {
|
2013-01-11 04:50:50 -08:00
|
|
|
navigator.mozApps.mgmt.uninstall(this.target.app);
|
2013-01-09 11:28:35 -08:00
|
|
|
|
|
|
|
let manifest = this.target.manifest;
|
|
|
|
gChromeWin.sendMessageToJava({
|
2013-02-01 17:36:38 -08:00
|
|
|
type: "Shortcut:Remove",
|
|
|
|
title: manifest.name,
|
|
|
|
url: manifest.fullLaunchPath(),
|
|
|
|
origin: this.target.app.origin,
|
|
|
|
shortcutType: "webapp"
|
2013-01-09 11:28:35 -08:00
|
|
|
});
|
|
|
|
this.target = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 21:50:48 -07:00
|
|
|
function onLoad(aEvent) {
|
|
|
|
try {
|
|
|
|
let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
|
|
|
|
let link = document.getElementById("marketplaceURL");
|
|
|
|
let url = formatter.formatURLPref(link.getAttribute("pref"));
|
|
|
|
link.setAttribute("href", url);
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
navigator.mozApps.mgmt.oninstall = onInstall;
|
|
|
|
navigator.mozApps.mgmt.onuninstall = onUninstall;
|
|
|
|
updateList();
|
|
|
|
|
2013-01-09 11:28:35 -08:00
|
|
|
ContextMenus.init();
|
2012-03-29 21:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateList() {
|
|
|
|
let grid = document.getElementById("appgrid");
|
|
|
|
while (grid.lastChild) {
|
|
|
|
grid.removeChild(grid.lastChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
let request = navigator.mozApps.mgmt.getAll();
|
|
|
|
request.onsuccess = function() {
|
|
|
|
for (let i = 0; i < request.result.length; i++)
|
|
|
|
addApplication(request.result[i]);
|
|
|
|
if (!request.result.length)
|
|
|
|
document.getElementById("noapps").className = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addApplication(aApp) {
|
|
|
|
let list = document.getElementById("appgrid");
|
2012-10-02 22:38:03 -07:00
|
|
|
let manifest = new ManifestHelper(aApp.manifest, aApp.origin);
|
2012-03-29 21:50:48 -07:00
|
|
|
|
|
|
|
let container = document.createElement("div");
|
2013-03-22 16:36:31 -07:00
|
|
|
container.className = "app list-item";
|
2013-01-09 11:28:35 -08:00
|
|
|
container.setAttribute("contextmenu", "appmenu");
|
2012-03-29 21:50:48 -07:00
|
|
|
container.setAttribute("id", "app-" + aApp.origin);
|
|
|
|
container.setAttribute("mozApp", aApp.origin);
|
|
|
|
container.setAttribute("title", manifest.name);
|
|
|
|
|
|
|
|
let img = document.createElement("img");
|
2012-07-09 17:54:40 -07:00
|
|
|
let origin = Services.io.newURI(aApp.origin, null, null);
|
|
|
|
img.src = gChromeWin.WebappsUI.getBiggestIcon(manifest.icons, origin);
|
2012-03-29 21:50:48 -07:00
|
|
|
img.setAttribute("title", manifest.name);
|
|
|
|
|
|
|
|
let title = document.createElement("div");
|
|
|
|
title.appendChild(document.createTextNode(manifest.name));
|
|
|
|
|
|
|
|
container.appendChild(img);
|
|
|
|
container.appendChild(title);
|
|
|
|
list.appendChild(container);
|
|
|
|
|
|
|
|
container.addEventListener("click", function(aEvent) {
|
|
|
|
aApp.launch();
|
|
|
|
}, false);
|
|
|
|
container.app = aApp;
|
|
|
|
container.manifest = manifest;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onInstall(aEvent) {
|
|
|
|
let node = document.getElementById("app-" + aEvent.application.origin);
|
|
|
|
if (node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
addApplication(aEvent.application);
|
|
|
|
document.getElementById("noapps").className = "hidden";
|
|
|
|
}
|
|
|
|
|
|
|
|
function onUninstall(aEvent) {
|
|
|
|
let node = document.getElementById("app-" + aEvent.application.origin);
|
|
|
|
if (node) {
|
|
|
|
let parent = node.parentNode;
|
|
|
|
parent.removeChild(node);
|
|
|
|
if (!parent.firstChild)
|
|
|
|
document.getElementById("noapps").className = "";
|
|
|
|
}
|
|
|
|
}
|