Bug 822551 - Initialize the user agent overrides in content process frames. r=dao,vingtetun
authorJosh Matthews <josh@joshmatthews.net>
Mon, 07 Jan 2013 17:47:01 +0100
changeset 123497 3966def5b2198f40b5e7bb632e983762de369e9d
parent 123496 e4550612487b478ddbf68077e885621bd4aaf91f
child 123498 a2c05e82dd8980bf973030f755c32b0563851f40
push id3129
push userakeybl@mozilla.com
push dateMon, 07 Jan 2013 22:54:45 +0000
treeherdermozilla-aurora@090bc89ff6b4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, vingtetun
bugs822551
milestone20.0a1
Bug 822551 - Initialize the user agent overrides in content process frames. r=dao,vingtetun
b2g/chrome/content/UAO_child.js
b2g/chrome/jar.mn
b2g/components/ProcessGlobal.js
netwerk/protocol/http/UserAgentOverrides.jsm
new file mode 100644
--- /dev/null
+++ b/b2g/chrome/content/UAO_child.js
@@ -0,0 +1,2 @@
+Components.utils.import('resource://gre/modules/UserAgentOverrides.jsm');
+UserAgentOverrides.init();
--- a/b2g/chrome/jar.mn
+++ b/b2g/chrome/jar.mn
@@ -19,16 +19,18 @@ chrome.jar:
   content/runapp.js                     (content/runapp.js)
 #endif
   content/content.css                   (content/content.css)
   content/touchcontrols.css             (content/touchcontrols.css)
 
   content/payment.js                    (content/payment.js)
   content/identity.js                   (content/identity.js)
 
+  content/UAO_child.js                 (content/UAO_child.js)
+
 % override chrome://global/content/netError.xhtml chrome://browser/content/netError.xhtml
 % override chrome://global/skin/netError.css chrome://browser/content/netError.css
 % override chrome://global/skin/media/videocontrols.css chrome://browser/content/touchcontrols.css
 
   content/netError.xhtml                (content/netError.xhtml)
   content/netError.css                  (content/netError.css)
   content/images/errorpage-larry-black.png (content/images/errorpage-larry-black.png)
   content/images/errorpage-larry-white.png (content/images/errorpage-larry-white.png)
--- a/b2g/components/ProcessGlobal.js
+++ b/b2g/components/ProcessGlobal.js
@@ -38,26 +38,38 @@ ProcessGlobal.prototype = {
   classID: Components.ID('{1a94c87a-5ece-4d11-91e1-d29c29f21b28}'),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
 
   observe: function pg_observe(subject, topic, data) {
     switch (topic) {
     case 'app-startup': {
       Services.obs.addObserver(this, 'console-api-log-event', false);
+      Services.obs.addObserver(this, 'remote-browser-frame-shown', false);
       break;
     }
     case 'console-api-log-event': {
       // Pipe `console` log messages to the nsIConsoleService which
       // writes them to logcat on Gonk.
       let message = subject.wrappedJSObject;
       let prefix = ('Content JS ' + message.level.toUpperCase() +
                     ' at ' + message.filename + ':' + message.lineNumber +
                     ' in ' + (message.functionName || 'anonymous') + ': ');
       Services.console.logStringMessage(prefix + Array.join(message.arguments,
                                                             ' '));
       break;
     }
+    case 'remote-browser-frame-shown': {
+      let frameLoader = subject.QueryInterface(Ci.nsIFrameLoader);
+      let mm = frameLoader.messageManager;
+
+      const kFrameScript = "chrome://browser/content/UAO_child.js";
+      try {
+        mm.loadFrameScript(kFrameScript, true);
+      } catch (e) {
+        dump('Error loading ' + kFrameScript + ' as frame script: ' + e + '\n');
+      }
+    }
     }
   },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ProcessGlobal]);
--- a/netwerk/protocol/http/UserAgentOverrides.jsm
+++ b/netwerk/protocol/http/UserAgentOverrides.jsm
@@ -22,26 +22,30 @@ var gInitialized = false;
 var gOverrideFunctions = [
   function (aHttpChannel) UserAgentOverrides.getOverrideForURI(aHttpChannel.URI)
 ];
 
 this.UserAgentOverrides = {
   init: function uao_init() {
     if (gInitialized)
       return;
-    gInitialized = true;
 
     gPrefBranch = Services.prefs.getBranch("general.useragent.override.");
     gPrefBranch.addObserver("", buildOverrides, false);
 
     Services.prefs.addObserver(PREF_OVERRIDES_ENABLED, buildOverrides, false);
 
-    Services.obs.addObserver(HTTP_on_modify_request, "http-on-modify-request", false);
+    try {
+      Services.obs.addObserver(HTTP_on_modify_request, "http-on-modify-request", false);
+    } catch (x) {
+      // The http-on-modify-request notification is disallowed in content processes.
+    }
 
     buildOverrides();
+    gInitialized = true;
   },
 
   addComplexOverride: function uao_addComplexOverride(callback) {
     gOverrideFunctions.push(callback);
   },
 
   getOverrideForURI: function uao_getOverrideForURI(aURI) {
     if (!gInitialized)