Bug 858828 - Avoid missing URI host member when special-casing user agent string for Youtube domains. r=mfinkle a=akeybl
authorNick Alexander <nalexander@mozilla.com>
Fri, 24 May 2013 13:51:25 -0700
changeset 137675 e9871a4f9b070bb52bc0261b9e5b24cc77c63766
parent 137674 dfdffee03d15ef63b1249443dfd93dc7d1c71a51
child 137676 2d8ccf3ca4bd4f1676dc229f1f482cccaee98ca2
push id2491
push usernalexander@mozilla.com
push dateFri, 24 May 2013 20:51:44 +0000
treeherdermozilla-beta@e9871a4f9b07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, akeybl
bugs858828
milestone22.0
Bug 858828 - Avoid missing URI host member when special-casing user agent string for Youtube domains. r=mfinkle a=akeybl
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -2087,17 +2087,17 @@ var LightWeightThemeWebInstaller = {
 
   _getThemeFromNode: function (node) {
     return this._manager.parseTheme(node.getAttribute("data-browsertheme"), node.baseURI);
   }
 };
 
 var UserAgent = {
   DESKTOP_UA: null,
-  YOUTUBE_DOMAIN: /\.?youtube\.com$/,
+  YOUTUBE_DOMAIN: /(^|\.)youtube\.com$/,
 
   init: function ua_init() {
     Services.obs.addObserver(this, "DesktopMode:Change", false);
     UserAgentOverrides.init();
     UserAgentOverrides.addComplexOverride(this.onRequest.bind(this));
 
     // See https://developer.mozilla.org/en/Gecko_user_agent_string_reference
     this.DESKTOP_UA = Cc["@mozilla.org/network/protocol;1?name=http"]
@@ -2125,20 +2125,23 @@ var UserAgent = {
   getUserAgentForWindow: function ua_getUserAgentForWindow(aWindow, defaultUA) {
     let tab = BrowserApp.getTabForWindow(aWindow.top);
     if (tab)
       return this.getUserAgentForUriAndTab(tab.browser.currentURI, tab, defaultUA);
     return defaultUA;
   },
 
   getUserAgentForUriAndTab: function ua_getUserAgentForUriAndTab(aUri, aTab, defaultUA) {
-    if (this.YOUTUBE_DOMAIN.test(aUri.host)) {
-      // Send the phone UA to youtube if this is a tablet
-      if (defaultUA.indexOf("Android; Mobile;") === -1)
-        return defaultUA.replace("Android;", "Android; Mobile;");
+    // Not all schemes have a host member.
+    if (aUri.schemeIs("http") || aUri.schemeIs("https")) {
+      if (this.YOUTUBE_DOMAIN.test(aUri.host)) {
+        // Send the phone UA to Youtube if this is a tablet.
+        if (defaultUA.indexOf("Android; Mobile;") === -1)
+          return defaultUA.replace("Android;", "Android; Mobile;");
+      }
     }
 
     // Send desktop UA if "Request Desktop Site" is enabled
     if (aTab.desktopMode)
       return this.DESKTOP_UA;
 
     return defaultUA;
   },