bug 766914 - Unable to play videos on mobile YouTube; redirection loop on 'Play' r=blassey a=blassey 14_0_Beta FENNEC_14_0b8_BUILD2 FENNEC_14_0b8_BUILD3
authorMark Finkle <mfinkle@mozilla.com>
Thu, 21 Jun 2012 13:49:48 -0400
branch14_0_Beta
changeset 96134 f54b2bbd3baf1dd1ecc0fc476047404b1ea77b1e
parent 96133 4ea5dbbba3d0710925cba250cd05e9f844971425
child 96141 36d87a1cfab325e6a52657c2b4cf2499bfe5b0f0
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersblassey, blassey
bugs766914
milestone14.0
bug 766914 - Unable to play videos on mobile YouTube; redirection loop on 'Play' r=blassey a=blassey
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -230,16 +230,17 @@ var BrowserApp = {
     ConsoleAPI.init();
     ClipboardHelper.init();
     PermissionsHelper.init();
     CharacterEncoding.init();
     SearchEngines.init();
     ActivityObserver.init();
     WebappsUI.init();
     RemoteDebugger.init();
+    UserAgent.init();
 
     // Init LoginManager
     Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
     // Init FormHistory
     Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
 
     let loadParams = {};
     let url = "about:home";
@@ -429,16 +430,17 @@ var BrowserApp = {
     IndexedDB.uninit();
     ViewportHandler.uninit();
     XPInstallObserver.uninit();
     ConsoleAPI.uninit();
     CharacterEncoding.uninit();
     SearchEngines.uninit();
     WebappsUI.uninit();
     RemoteDebugger.uninit();
+    UserAgent.uninit();
   },
 
   // This function returns false during periods where the browser displayed document is
   // different from the browser content document, so user actions and some kinds of viewport
   // updates should be ignored. This period starts when we start loading a new page or
   // switch tabs, and ends when the new browser content document has been drawn and handed
   // off to the compositor.
   isBrowserContentDocumentDisplayed: function() {
@@ -1427,16 +1429,66 @@ var NativeWindow = {
       }
 
       return this.makeURLAbsolute(aLink.baseURI, href);
     }
   }
 };
 
 
+var UserAgent = {
+  init: function ua_init() {
+    Services.obs.addObserver(this, "http-on-modify-request", false);
+  },
+
+  uninit: function ua_uninit() {
+    Services.obs.removeObserver(this, "http-on-modify-request");
+  },
+
+  getRequestLoadContext: function ua_getRequestLoadContext(aRequest) {
+    if (aRequest && aRequest.notificationCallbacks) {
+      try {
+        return aRequest.notificationCallbacks.getInterface(Ci.nsILoadContext);
+      } catch (ex) { }
+    }
+
+    if (aRequest && aRequest.loadGroup && aRequest.loadGroup.notificationCallbacks) {
+      try {
+        return aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
+      } catch (ex) { }
+    }
+
+    return null;
+  },
+
+  getWindowForRequest: function ua_getWindowForRequest(aRequest) {
+    let loadContext = this.getRequestLoadContext(aRequest);
+    if (loadContext)
+      return loadContext.associatedWindow;
+    return null;
+  },
+
+  observe: function ua_observe(aSubject, aTopic, aData) {
+    if (!(aSubject instanceof Ci.nsIHttpChannel))
+      return;
+
+    let channel = aSubject.QueryInterface(Ci.nsIHttpChannel);
+    let channelWindow = this.getWindowForRequest(channel);
+    if (BrowserApp.getBrowserForWindow(channelWindow)) {
+      if (channel.URI.host.indexOf("youtube") != -1) {
+        let ua = Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).userAgent;
+#expand let version = "__MOZ_APP_VERSION__";
+        ua += " Fennec/" + version;
+        channel.setRequestHeader("User-Agent", ua, false);
+      }
+    }
+  }
+};
+
+
 function nsBrowserAccess() {
 }
 
 nsBrowserAccess.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserDOMWindow]),
 
   _getBrowser: function _getBrowser(aURI, aOpener, aWhere, aContext) {
     let isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
@@ -2506,39 +2558,16 @@ Tab.prototype = {
 
     if (md && md.minZoom)
       zoom = Math.max(zoom, md.minZoom);
     if (md && md.maxZoom)
       zoom = Math.min(zoom, md.maxZoom);
     return zoom;
   },
 
-  getRequestLoadContext: function(aRequest) {
-    if (aRequest && aRequest.notificationCallbacks) {
-      try {
-        return aRequest.notificationCallbacks.getInterface(Ci.nsILoadContext);
-      } catch (ex) { }
-    }
-
-    if (aRequest && aRequest.loadGroup && aRequest.loadGroup.notificationCallbacks) {
-      try {
-        return aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
-      } catch (ex) { }
-    }
-
-    return null;
-  },
-
-  getWindowForRequest: function(aRequest) {
-    let loadContext = this.getRequestLoadContext(aRequest);
-    if (loadContext)
-      return loadContext.associatedWindow;
-    return null;
-  },
-
   observe: function(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "before-first-paint":
         // Is it on the top level?
         let contentDocument = aSubject;
         if (contentDocument == this.browser.contentDocument) {
           // reset CSS viewport and zoom to default on new page, and then calculate
           // them properly using the actual metadata from the page. note that the