From 73d069ddedd6f15a3dd596bf25383d34b0a9a788 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Fri, 23 May 2014 11:43:39 -0700 Subject: [PATCH] Bug 1009327 - Add "manual connect" to Android about:devices page. r=mfinkle --- mobile/android/chrome/content/aboutDevices.js | 45 +++++++++++++++++++ .../android/chrome/content/aboutDevices.xhtml | 14 ++++++ .../locales/en-US/chrome/aboutDevices.dtd | 7 +++ 3 files changed, 66 insertions(+) diff --git a/mobile/android/chrome/content/aboutDevices.js b/mobile/android/chrome/content/aboutDevices.js index 0f702d5a0f7e..7d4875740a82 100644 --- a/mobile/android/chrome/content/aboutDevices.js +++ b/mobile/android/chrome/content/aboutDevices.js @@ -36,6 +36,11 @@ var Devices = { this.updateDeviceList(); }, false); + let manual = document.getElementById("connect"); + manual.addEventListener("click", (evt) => { + this.connectManually(evt); + }, false); + this._savedSearchInterval = SimpleServiceDiscovery.search(SEARCH_INTERVAL_IN_MILLISECONDS); this.updateDeviceList(); @@ -87,6 +92,46 @@ var Devices = { this.updateDeviceList(); } }, + + _fixedTargetForType: function(type, ip) { + let fixedTarget = {}; + if (type == "roku") { + fixedTarget.target = "roku:ecp"; + fixedTarget.location = "http://" + ip + ":8060"; + } else if (type == "chromecast") { + fixedTarget.target = "urn:dial-multiscreen-org:service:dial:1"; + fixedTarget.location = "http://" + ip + ":8008"; + } + return fixedTarget; + }, + + connectManually: function(evt) { + // Since there is no form submit event, this is not validated. However, + // after we process this event, the element's validation state is updated. + let ip = document.getElementById("ip"); + if (!ip.checkValidity()) { + dump("Manually entered IP address is not valid!"); + return; + } + + let fixedTargets = []; + try { + fixedTargets = JSON.parse(Services.prefs.getCharPref("browser.casting.fixedTargets")); + } catch (e) {} + + let type = document.getElementById("type").value; + let fixedTarget = this._fixedTargetForType(type, ip.value); + + // Early abort if we're already looking for this target. + if (fixedTargets.indexOf(fixedTarget) > -1) + return; + + fixedTargets.push(fixedTarget); + Services.prefs.setCharPref("browser.casting.fixedTargets", JSON.stringify(fixedTargets)); + + // The backend does not yet listen for pref changes, so we trigger a scan. + this.updateDeviceList(); + }, }; window.addEventListener("load", Devices.init.bind(Devices), false); diff --git a/mobile/android/chrome/content/aboutDevices.xhtml b/mobile/android/chrome/content/aboutDevices.xhtml index 29c9a8df760f..bb24118a8026 100644 --- a/mobile/android/chrome/content/aboutDevices.xhtml +++ b/mobile/android/chrome/content/aboutDevices.xhtml @@ -30,6 +30,20 @@ +

&aboutDevices.addDeviceHeader;

+ +
+ + + + +
+ diff --git a/mobile/android/locales/en-US/chrome/aboutDevices.dtd b/mobile/android/locales/en-US/chrome/aboutDevices.dtd index ba80000e3b10..45d00393e7e6 100644 --- a/mobile/android/locales/en-US/chrome/aboutDevices.dtd +++ b/mobile/android/locales/en-US/chrome/aboutDevices.dtd @@ -5,3 +5,10 @@ + + + + + +