From 909a1747e25f7d6f19f84d5cadddf6249b0eae9a Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Wed, 4 Jun 2014 15:25:07 -0400 Subject: [PATCH] Bug 1016785 - Add more structured filtering to SSDP r=wesj --- .../android/base/tests/testSimpleDiscovery.js | 9 ++++ mobile/android/chrome/content/CastingApps.js | 22 +++++--- .../modules/SimpleServiceDiscovery.jsm | 52 +++++++++++++++++-- 3 files changed, 74 insertions(+), 9 deletions(-) diff --git a/mobile/android/base/tests/testSimpleDiscovery.js b/mobile/android/base/tests/testSimpleDiscovery.js index 542df9f6acc5..6b6bc2f42e25 100644 --- a/mobile/android/base/tests/testSimpleDiscovery.js +++ b/mobile/android/base/tests/testSimpleDiscovery.js @@ -24,13 +24,22 @@ function discovery_observer(subject, topic, data) { run_next_test(); }; +var testTarget = { + target: "test:service", + factory: function(service) { /* dummy */ } +}; + add_test(function test_default() { do_register_cleanup(function cleanup() { + SimpleServiceDiscovery.unregisterTarget(testTarget); Services.obs.removeObserver(discovery_observer, "ssdp-service-found"); }); Services.obs.addObserver(discovery_observer, "ssdp-service-found", false); + // We need to register a target or processService will ignore us + SimpleServiceDiscovery.registerTarget(testTarget); + // Create a pretend service let service = { location: "http://mochi.test:8888/tests/robocop/simpleservice.xml", diff --git a/mobile/android/chrome/content/CastingApps.js b/mobile/android/chrome/content/CastingApps.js index fb86c5fd1d58..6c1850863fe3 100644 --- a/mobile/android/chrome/content/CastingApps.js +++ b/mobile/android/chrome/content/CastingApps.js @@ -3,6 +3,16 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; +// Define service targets. We should consider moving these to their respective +// JSM files, but we left them here to allow for better lazy JSM loading. +var rokuTarget = { + target: "roku:ecp", + factory: function(aService) { + Cu.import("resource://gre/modules/RokuApp.jsm"); + return new RokuApp(aService); + } +}; + var CastingApps = { _castMenuId: -1, @@ -11,11 +21,8 @@ var CastingApps = { return; } - // Register a service target - SimpleServiceDiscovery.registerTarget("roku:ecp", function(aService) { - Cu.import("resource://gre/modules/RokuApp.jsm"); - return new RokuApp(aService); - }); + // Register targets + SimpleServiceDiscovery.registerTarget(rokuTarget); // Search for devices continuously every 120 seconds SimpleServiceDiscovery.search(120 * 1000); @@ -252,6 +259,10 @@ var CastingApps = { }, _findCastableVideo: function _findCastableVideo(aBrowser) { + if (!aBrowser) { + return null; + } + // Scan for a