From 116c1bd804855dd979b37a4ca930be2e403cd2e6 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 19 Jun 2014 05:19:56 +0800 Subject: [PATCH] Bug 1025000 - move runtime details and permissions table inside webide. r=jryans --- browser/devtools/webide/content/addons.js | 8 +- browser/devtools/webide/content/addons.xhtml | 2 +- browser/devtools/webide/content/jar.mn | 4 + .../webide/content/permissionstable.js | 75 +++++++++++ .../webide/content/permissionstable.xhtml | 35 +++++ .../devtools/webide/content/runtimedetails.js | 56 ++++++++ .../webide/content/runtimedetails.xhtml | 28 ++++ browser/devtools/webide/content/webide.js | 88 +----------- browser/devtools/webide/content/webide.xul | 2 + .../devtools/webide/locales/en-US/webide.dtd | 13 +- browser/devtools/webide/modules/runtimes.js | 1 - browser/devtools/webide/test/chrome.ini | 1 + browser/devtools/webide/test/head.js | 15 +++ .../devtools/webide/test/test_deviceinfo.html | 126 ++++++++++++++++++ browser/devtools/webide/themes/jar.mn | 1 + browser/devtools/webide/themes/tabledoc.css | 54 ++++++++ 16 files changed, 417 insertions(+), 92 deletions(-) create mode 100644 browser/devtools/webide/content/permissionstable.js create mode 100644 browser/devtools/webide/content/permissionstable.xhtml create mode 100644 browser/devtools/webide/content/runtimedetails.js create mode 100644 browser/devtools/webide/content/runtimedetails.xhtml create mode 100644 browser/devtools/webide/test/test_deviceinfo.html create mode 100644 browser/devtools/webide/themes/tabledoc.css diff --git a/browser/devtools/webide/content/addons.js b/browser/devtools/webide/content/addons.js index bad430e5e830..7da12b3cf2fd 100644 --- a/browser/devtools/webide/content/addons.js +++ b/browser/devtools/webide/content/addons.js @@ -13,15 +13,17 @@ window.addEventListener("load", function onLoad() { document.querySelector("#aboutaddons").onclick = function() { window.parent.UI.openInBrowser("about:addons"); } - document.querySelector("#close").onclick = function() { - window.parent.UI.closeLastDeckPanel(); - } + document.querySelector("#close").onclick = CloseUI; GetAvailableAddons().then(BuildUI, (e) => { console.error(e); window.alert(Strings.formatStringFromName("error_cantFetchAddonsJSON", [e], 1)); }); }, true); +function CloseUI() { + window.parent.UI.openProject(); +} + function BuildUI(addons) { BuildItem(addons.adb, true /* is adb */); for (let addon of addons.simulators) { diff --git a/browser/devtools/webide/content/addons.xhtml b/browser/devtools/webide/content/addons.xhtml index 3f2e3978e6b7..12ed00988c0d 100644 --- a/browser/devtools/webide/content/addons.xhtml +++ b/browser/devtools/webide/content/addons.xhtml @@ -19,7 +19,7 @@
&addons_aboutaddons; - &addons_close; + &deck_close;

&addons_title;

diff --git a/browser/devtools/webide/content/jar.mn b/browser/devtools/webide/content/jar.mn index 03118a80615e..1e17d4f3df9d 100644 --- a/browser/devtools/webide/content/jar.mn +++ b/browser/devtools/webide/content/jar.mn @@ -13,6 +13,10 @@ webide.jar: content/cli.js (cli.js) content/addons.js (addons.js) content/addons.xhtml (addons.xhtml) + content/permissionstable.js (permissionstable.js) + content/permissionstable.xhtml (permissionstable.xhtml) + content/runtimedetails.js (runtimedetails.js) + content/runtimedetails.xhtml (runtimedetails.xhtml) # Temporarily include locales in content, until we're ready # to localize webide diff --git a/browser/devtools/webide/content/permissionstable.js b/browser/devtools/webide/content/permissionstable.js new file mode 100644 index 000000000000..6dc356bfeeb6 --- /dev/null +++ b/browser/devtools/webide/content/permissionstable.js @@ -0,0 +1,75 @@ +/* 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/. */ + +const Cu = Components.utils; +const {Services} = Cu.import("resource://gre/modules/Services.jsm"); +const {require} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools; +const {AppManager} = require("devtools/webide/app-manager"); +const {Connection} = require("devtools/client/connection-manager"); + +window.addEventListener("load", function onLoad() { + window.removeEventListener("load", onLoad); + document.querySelector("#close").onclick = CloseUI; + AppManager.on("app-manager-update", OnAppManagerUpdate); + BuildUI(); +}, true); + +window.addEventListener("unload", function onUnload() { + window.removeEventListener("unload", onUnload); + AppManager.off("app-manager-update", OnAppManagerUpdate); +}); + +function CloseUI() { + window.parent.UI.openProject(); +} + +function OnAppManagerUpdate(event, what) { + if (what == "connection" || what == "list-tabs-response") { + BuildUI(); + } +} + +let getRawPermissionsTablePromise; // Used by tests +function BuildUI() { + let table = document.querySelector("table"); + let lines = table.querySelectorAll(".line"); + for (let line of lines) { + line.remove(); + } + + if (AppManager.connection && + AppManager.connection.status == Connection.Status.CONNECTED && + AppManager.deviceFront) { + getRawPermissionsTablePromise = AppManager.deviceFront.getRawPermissionsTable(); + getRawPermissionsTablePromise.then(json => { + let permissionsTable = json.rawPermissionsTable; + for (let name in permissionsTable) { + let tr = document.createElement("tr"); + tr.className = "line"; + let td = document.createElement("td"); + td.textContent = name; + tr.appendChild(td); + for (let type of ["app","privileged","certified"]) { + let td = document.createElement("td"); + if (permissionsTable[name][type] == json.ALLOW_ACTION) { + td.textContent = "✓"; + td.className = "permallow"; + } + if (permissionsTable[name][type] == json.PROMPT_ACTION) { + td.textContent = "!"; + td.className = "permprompt"; + } + if (permissionsTable[name][type] == json.DENY_ACTION) { + td.textContent = "✕"; + td.className = "permdeny" + } + tr.appendChild(td); + } + table.appendChild(tr); + } + }); + } else { + CloseUI(); + } +} diff --git a/browser/devtools/webide/content/permissionstable.xhtml b/browser/devtools/webide/content/permissionstable.xhtml new file mode 100644 index 000000000000..17dffd1b9e36 --- /dev/null +++ b/browser/devtools/webide/content/permissionstable.xhtml @@ -0,0 +1,35 @@ + + + + + + %webideDTD; +]> + + + + + + + + + +
+ &deck_close; +
+ +

&permissionstable_title;

+ + + + + + + + +
&permissionstable_name_header;type:webtype:privilegedtype:certified
+ + diff --git a/browser/devtools/webide/content/runtimedetails.js b/browser/devtools/webide/content/runtimedetails.js new file mode 100644 index 000000000000..8de2196dada2 --- /dev/null +++ b/browser/devtools/webide/content/runtimedetails.js @@ -0,0 +1,56 @@ +/* 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/. */ + +const Cu = Components.utils; +const {Services} = Cu.import("resource://gre/modules/Services.jsm"); +const {require} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools; +const {AppManager} = require("devtools/webide/app-manager"); +const {Connection} = require("devtools/client/connection-manager"); + +window.addEventListener("load", function onLoad() { + window.removeEventListener("load", onLoad); + document.querySelector("#close").onclick = CloseUI; + AppManager.on("app-manager-update", OnAppManagerUpdate); + BuildUI(); +}, true); + +window.addEventListener("unload", function onUnload() { + window.removeEventListener("unload", onUnload); + AppManager.off("app-manager-update", OnAppManagerUpdate); +}); + +function CloseUI() { + window.parent.UI.openProject(); +} + +function OnAppManagerUpdate(event, what) { + if (what == "connection" || what == "list-tabs-response") { + BuildUI(); + } +} + +let getDescriptionPromise; // Used by tests +function BuildUI() { + let table = document.querySelector("table"); + table.innerHTML = ""; + if (AppManager.connection && + AppManager.connection.status == Connection.Status.CONNECTED && + AppManager.deviceFront) { + getDescriptionPromise = AppManager.deviceFront.getDescription(); + getDescriptionPromise.then(json => { + for (let name in json) { + let tr = document.createElement("tr"); + let td = document.createElement("td"); + td.textContent = name; + tr.appendChild(td); + td = document.createElement("td"); + td.textContent = json[name]; + tr.appendChild(td); + table.appendChild(tr); + } + }); + } else { + CloseUI(); + } +} diff --git a/browser/devtools/webide/content/runtimedetails.xhtml b/browser/devtools/webide/content/runtimedetails.xhtml new file mode 100644 index 000000000000..6d1f5d6dec1f --- /dev/null +++ b/browser/devtools/webide/content/runtimedetails.xhtml @@ -0,0 +1,28 @@ + + + + + + %webideDTD; +]> + + + + + + + + + +
+ &deck_close; +
+ +

&runtimedetails_title;

+ +
+ + diff --git a/browser/devtools/webide/content/webide.js b/browser/devtools/webide/content/webide.js index b142efebac5b..631247872805 100644 --- a/browser/devtools/webide/content/webide.js +++ b/browser/devtools/webide/content/webide.js @@ -399,8 +399,6 @@ let UI = { /********** DECK **********/ - _lastSelectedPanels: [], - resetFocus: function() { document.commandDispatcher.focusedElement = document.documentElement; }, @@ -410,24 +408,12 @@ let UI = { this.resetFocus(); let deck = document.querySelector("#deck"); let panel = deck.querySelector("#deck-panel-" + id); - this._lastSelectedPanels.push(deck.selectedIndex); deck.selectedPanel = panel; }, - closeLastDeckPanel: function() { - this.resetFocus(); - let deck = document.querySelector("#deck"); - if (this._lastSelectedPanels.length > 0) { - deck.selectedIndex = this._lastSelectedPanels.pop(); - } else { - this.resetDeck(); - } - }, - resetDeck: function() { this.resetFocus(); let deck = document.querySelector("#deck"); - this._lastSelectedPanels = []; deck.selectedPanel = null; }, @@ -794,81 +780,11 @@ let Cmds = { }, showPermissionsTable: function() { - return UI.busyUntil(AppManager.deviceFront.getRawPermissionsTable().then(json => { - let styleContent = ""; - styleContent += "body {background:white; font-family: monospace}"; - styleContent += "table {border-collapse: collapse}"; - styleContent += "th, td {padding: 5px; border: 1px solid #EEE}"; - styleContent += "th {min-width: 130px}"; - styleContent += "td {text-align: center}"; - styleContent += "th:first-of-type, td:first-of-type {text-align:left}"; - styleContent += ".permallow {color:rgb(152, 207, 57)}"; - styleContent += ".permprompt {color:rgb(0,158,237)}"; - styleContent += ".permdeny {color:rgb(204,73,8)}"; - let style = document.createElementNS(HTML, "style"); - style.textContent = styleContent; - let table = document.createElementNS(HTML, "table"); - table.innerHTML = "Nametype:webtype:privilegedtype:certified"; - let permissionsTable = json.rawPermissionsTable; - for (let name in permissionsTable) { - let tr = document.createElementNS(HTML, "tr"); - let td = document.createElementNS(HTML, "td"); - td.textContent = name; - tr.appendChild(td); - for (let type of ["app","privileged","certified"]) { - let td = document.createElementNS(HTML, "td"); - if (permissionsTable[name][type] == json.ALLOW_ACTION) { - td.textContent = "✓"; - td.className = "permallow"; - } - if (permissionsTable[name][type] == json.PROMPT_ACTION) { - td.textContent = "!"; - td.className = "permprompt"; - } - if (permissionsTable[name][type] == json.DENY_ACTION) { - td.textContent = "✕"; - td.className = "permdeny" - } - tr.appendChild(td); - } - table.appendChild(tr); - } - let body = document.createElementNS(HTML, "body"); - body.appendChild(style); - body.appendChild(table); - let url = "data:text/html;charset=utf-8,"; - url += encodeURIComponent(body.outerHTML); - UI.openInBrowser(url); - }), "showing permission table"); + UI.selectDeckPanel("permissionstable"); }, showRuntimeDetails: function() { - return UI.busyUntil(AppManager.deviceFront.getDescription().then(json => { - let styleContent = ""; - styleContent += "body {background:white; font-family: monospace}"; - styleContent += "table {border-collapse: collapse}"; - styleContent += "th, td {padding: 5px; border: 1px solid #EEE}"; - let style = document.createElementNS(HTML, "style"); - style.textContent = styleContent; - let table = document.createElementNS(HTML, "table"); - for (let name in json) { - let tr = document.createElementNS(HTML, "tr"); - let td = document.createElementNS(HTML, "td"); - td.textContent = name; - tr.appendChild(td); - td = document.createElementNS(HTML, "td"); - td.textContent = json[name]; - tr.appendChild(td); - table.appendChild(tr); - } - let body = document.createElementNS(HTML, "body"); - body.appendChild(style); - body.appendChild(table); - let url = "data:text/html;charset=utf-8,"; - url += encodeURIComponent(body.outerHTML); - UI.openInBrowser(url); - }), "showing runtime details"); - + UI.selectDeckPanel("runtimedetails"); }, play: function() { diff --git a/browser/devtools/webide/content/webide.xul b/browser/devtools/webide/content/webide.xul index 920af47faf4f..3a77c8eb22eb 100644 --- a/browser/devtools/webide/content/webide.xul +++ b/browser/devtools/webide/content/webide.xul @@ -162,6 +162,8 @@