зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1000676 - Part 1: Add aboutDevices.* files. r=mfinkle
This commit is contained in:
Родитель
d1d48c29e1
Коммит
37bce631c2
|
@ -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);
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" [
|
||||
<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
|
||||
%brandDTD;
|
||||
<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
|
||||
%globalDTD;
|
||||
<!ENTITY % aboutDTD SYSTEM "chrome://browser/locale/aboutDevices.dtd" >
|
||||
%aboutDTD;
|
||||
]>
|
||||
|
||||
<!-- 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/. -->
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>&aboutDevices.title;</title>
|
||||
<meta name="viewport" content="width=device-width; user-scalable=0" />
|
||||
<link rel="icon" type="image/png" sizes="64x64" href="chrome://branding/content/favicon64.png" />
|
||||
<link rel="stylesheet" href="chrome://browser/skin/aboutBase.css" type="text/css"/>
|
||||
<link rel="stylesheet" href="chrome://browser/skin/aboutDevices.css" type="text/css"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>&aboutDevices.header;</h1>
|
||||
|
||||
<ul id="devices-list"></ul>
|
||||
|
||||
<button id="refresh">&aboutDevices.refresh;</button>
|
||||
|
||||
<script type="text/javascript;version=1.8" src="chrome://browser/content/aboutDevices.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,7 @@
|
|||
<!-- 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/. -->
|
||||
|
||||
<!ENTITY aboutDevices.title "Devices">
|
||||
<!ENTITY aboutDevices.header "Your devices">
|
||||
<!ENTITY aboutDevices.refresh "Refresh">
|
|
@ -0,0 +1,8 @@
|
|||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
Загрузка…
Ссылка в новой задаче