Bug 1273725 - Don't show 'No supported source' message in video controls if there's no sources. r?jaws draft
authorChris Pearce <cpearce@mozilla.com>
Tue, 12 Jul 2016 16:19:03 +1200
changeset 386845 1e8c30862bba5c02f97c232e8f02d77687ac4f4f
parent 386693 94c926911767cbaf285badaccc65b0365ae5bae0
child 387326 506a1c92e83e179dd56242c89a704aef569c8187
push id22823
push usercpearce@mozilla.com
push dateTue, 12 Jul 2016 21:46:48 +0000
reviewersjaws
bugs1273725
milestone50.0a1
Bug 1273725 - Don't show 'No supported source' message in video controls if there's no sources. r?jaws We're flashing a warning message "NO video with supported format and MIME type found." when we're loading a YouTube page in Fennec. This is because YouTube are calling load() on a video element with no src attribute or source children in a click handler in order to defeat the "requires user interaction to play" restrictions on mobile Chrome and Safari in that video element. We're showing the warning message to help developers diagnose why loads are unintentionally failing. However, the behaviour that YouTube are doing is intentional, and YouTube are likely to not be the only ones doing this. So we should change our video controls to not display the warning message in this case. We should be compatible with other browsers. We'll still log a debug message to the browser console as to why the load is failing, to help developers who hit this unintentionally. MozReview-Commit-ID: IpugbMOloJt
toolkit/content/widgets/videocontrols.xml
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -654,17 +654,41 @@
                     }
 
                     delete this.controlListeners;
 
                     this.log("--- videocontrols terminated ---");
                 },
 
                 hasError : function () {
-                    return (this.video.error != null || this.video.networkState == this.video.NETWORK_NO_SOURCE);
+                    // We either have an explicit error, or the resource selection
+                    // algorithm is running and we've tried to load something and failed.
+                    // Note: we don't consider the case where we've tried to load but
+                    // there's no sources to load as an error condition, as sites may
+                    // do this intentionally to work around requires-user-interaction to
+                    // play restrictions, and we don't want to display a debug message
+                    // if that's the case.
+                    return this.video.error != null ||
+                          (this.video.networkState == this.video.NETWORK_NO_SOURCE &&
+                           this.hasSources());
+                },
+
+                hasSources : function() {
+                    if (this.video.hasAttribute('src') &&
+                        this.video.getAttribute('src') !== "") {
+                        return true;
+                    }
+                    for (var child = this.video.firstChild;
+                         child !== null;
+                         child = child.nextElementSibling) {
+                        if (child instanceof HTMLSourceElement) {
+                            return true;
+                        }
+                    }
+                    return false;
                 },
 
                 updateErrorText : function () {
                     let error;
                     let v = this.video;
                     // It is possible to have both v.networkState == NETWORK_NO_SOURCE
                     // as well as v.error being non-null. In this case, we will show
                     // the v.error.code instead of the v.networkState error.