From 37bce631c29c86b3e88dc11aa9a329b69e659dd9 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Mon, 5 May 2014 11:27:56 -0700 Subject: [PATCH] Bug 1000676 - Part 1: Add aboutDevices.* files. r=mfinkle --- mobile/android/chrome/content/aboutDevices.js | 97 +++++++++++++++++++ .../android/chrome/content/aboutDevices.xhtml | 35 +++++++ .../locales/en-US/chrome/aboutDevices.dtd | 7 ++ mobile/android/themes/core/aboutDevices.css | 8 ++ 4 files changed, 147 insertions(+) create mode 100644 mobile/android/chrome/content/aboutDevices.js create mode 100644 mobile/android/chrome/content/aboutDevices.xhtml create mode 100644 mobile/android/locales/en-US/chrome/aboutDevices.dtd create mode 100644 mobile/android/themes/core/aboutDevices.css diff --git a/mobile/android/chrome/content/aboutDevices.js b/mobile/android/chrome/content/aboutDevices.js new file mode 100644 index 000000000000..4e16ea4a1c48 --- /dev/null +++ b/mobile/android/chrome/content/aboutDevices.js @@ -0,0 +1,97 @@ +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- +/* 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/. */ + +"use strict"; + +const { classes: Cc, interfaces: Ci, utils: Cu } = Components; + +Cu.import("resource://gre/modules/Services.jsm"); /*global Services */ +Cu.import("resource://gre/modules/Messaging.jsm"); +Cu.import("resource://gre/modules/SimpleServiceDiscovery.jsm"); /*global SimpleServiceDiscovery */ + +// TODO: Export these from SimpleServiceDiscovery. +const EVENT_SERVICE_FOUND = "ssdp-service-found"; +const EVENT_SERVICE_LOST = "ssdp-service-lost"; + +// We want to keep this page fresh while it is open, so we decrease +// our time between searches when it is opened, and revert to the +// former time between searches when it is closed. +const SEARCH_INTERVAL_IN_MILLISECONDS = 5 * 1000; + +function dump(s) { + Services.console.logStringMessage("aboutDevices :: " + s); +} + +var Devices = { + _savedSearchInterval: -1, + + init: function() { + dump("Initializing."); + Services.obs.addObserver(this, EVENT_SERVICE_FOUND, false); + Services.obs.addObserver(this, EVENT_SERVICE_LOST, false); + + let button = document.getElementById("refresh"); + button.addEventListener("click", () => { + this.updateDeviceList(); + }, false); + + // TODO: Don't break encapsulation here: have search() return the + // old interval. + this._savedSearchInterval = SimpleServiceDiscovery._searchInterval; + SimpleServiceDiscovery.search(SEARCH_INTERVAL_IN_MILLISECONDS); + + this.updateDeviceList(); + }, + + uninit: function() { + dump("Uninitializing."); + Services.obs.removeObserver(this, EVENT_SERVICE_FOUND); + Services.obs.removeObserver(this, EVENT_SERVICE_LOST); + + if (this._savedSearchInterval > 0) { + SimpleServiceDiscovery.search(this._savedSearchInterval); + } + }, + + _createItemForDevice: function(device) { + let item = document.createElement("div"); + + let friendlyName = document.createElement("div"); + friendlyName.classList.add("name"); + friendlyName.textContent = device.friendlyName; + item.appendChild(friendlyName); + + let location = document.createElement("div"); + location.classList.add("location"); + location.textContent = device.location; + item.appendChild(location); + + return item; + }, + + updateDeviceList: function() { + let services = SimpleServiceDiscovery.services; + dump("Updating device list with " + services.length + " services."); + + let list = document.getElementById("devices-list"); + while (list.firstChild) { + list.removeChild(list.firstChild); + } + + for (let service of services) { + let item = this._createItemForDevice(service); + list.appendChild(item); + } + }, + + observe: function(subject, topic, data) { + if (topic == EVENT_SERVICE_FOUND || topic == EVENT_SERVICE_LOST) { + this.updateDeviceList(); + } + }, +}; + +window.addEventListener("load", Devices.init.bind(Devices), false); +window.addEventListener("unload", Devices.uninit.bind(Devices), false); diff --git a/mobile/android/chrome/content/aboutDevices.xhtml b/mobile/android/chrome/content/aboutDevices.xhtml new file mode 100644 index 000000000000..29c9a8df760f --- /dev/null +++ b/mobile/android/chrome/content/aboutDevices.xhtml @@ -0,0 +1,35 @@ + + + +%brandDTD; + +%globalDTD; + +%aboutDTD; +]> + + + + + + &aboutDevices.title; + + + + + + + +

&aboutDevices.header;

+ + + + + + + + diff --git a/mobile/android/locales/en-US/chrome/aboutDevices.dtd b/mobile/android/locales/en-US/chrome/aboutDevices.dtd new file mode 100644 index 000000000000..ba80000e3b10 --- /dev/null +++ b/mobile/android/locales/en-US/chrome/aboutDevices.dtd @@ -0,0 +1,7 @@ + + + + + diff --git a/mobile/android/themes/core/aboutDevices.css b/mobile/android/themes/core/aboutDevices.css new file mode 100644 index 000000000000..74470bafea9a --- /dev/null +++ b/mobile/android/themes/core/aboutDevices.css @@ -0,0 +1,8 @@ +* { + margin: 0; + padding: 0; +} + +html, body { + height: 100%; +}