diff --git a/mobile/android/base/tests/testVideoDiscovery.js b/mobile/android/base/tests/testVideoDiscovery.js index 398d5daad9df..0b158d6b70d2 100644 --- a/mobile/android/base/tests/testVideoDiscovery.js +++ b/mobile/android/base/tests/testVideoDiscovery.js @@ -83,18 +83,24 @@ function execute_video_test(test) { let element = browser.contentDocument.getElementById(test.id); if (element) { let [x, y] = middle(element); - let video = chromeWin.CastingApps.getVideo(element, x, y); - if (video) { - let matchPoster = (test.poster == video.poster); - let matchSource = (test.source == video.source); - ok(matchPoster && matchSource && test.pass, test.text); - } else { - ok(!test.pass, test.text); - } + do_test_pending(); + do_print("Starting to getVideo"); + chromeWin.CastingApps.getVideo(element, x, y, (video) => { + do_print("got a Video"); + if (video) { + let matchPoster = (test.poster == video.poster); + let matchSource = (test.source == video.source); + ok(matchPoster && matchSource && test.pass, test.text); + } else { + ok(!test.pass, test.text); + } + do_test_finished(); + run_next_test(); + }); } else { ok(false, "test element not found: [" + test.id + "]"); + run_next_test(); } - run_next_test(); } let videoTest; diff --git a/mobile/android/chrome/content/CastingApps.js b/mobile/android/chrome/content/CastingApps.js index 369a49c59d48..8a1d6ef6870b 100644 --- a/mobile/android/chrome/content/CastingApps.js +++ b/mobile/android/chrome/content/CastingApps.js @@ -246,12 +246,12 @@ var CastingApps = { return; } - if (!this.getVideo(video, 0, 0)) { - return; - } - - // Let the binding know casting is allowed - this._sendEventToVideo(video, { allow: true }); + this.getVideo(video, 0, 0, (aBundle) => { + // Let the binding know casting is allowed + if (aBundle) { + this._sendEventToVideo(aBundle.element, { allow: true }); + } + }); }, handleVideoBindingCast: function handleVideoBindingCast(aTab, aEvent) { @@ -274,43 +274,77 @@ var CastingApps = { return Services.io.newURI(aURL, aOriginCharset, aBaseURI); }, - getVideo: function(aElement, aX, aY) { + allowableExtension: function(aURI, aExtensions) { + return (aURI instanceof Ci.nsIURL) && aExtensions.indexOf(aURI.fileExtension) != -1; + }, + + allowableMimeType: function(aType, aTypes) { + return aTypes.indexOf(aType) != -1; + }, + + // This method will look at the aElement (or try to find a video at aX, aY) that has + // a castable source. If found, aCallback will be called with a JSON meta bundle. If + // no castable source was found, aCallback is called with null. + getVideo: function(aElement, aX, aY, aCallback) { let extensions = SimpleServiceDiscovery.getSupportedExtensions(); let types = SimpleServiceDiscovery.getSupportedMimeTypes(); - // Fast path: Is the given element a video element - let video = this._getVideo(aElement, types, extensions); - if (video) { - return video; + // Fast path: Is the given element a video element? + if (aElement instanceof HTMLVideoElement) { + // If we found a video element, no need to look further, even if no + // castable video source is found. + this._getVideo(aElement, types, extensions, aCallback); + return; } + // Maybe this is an overlay, with the video element under it. + // Use the (x, y) location to guess at a