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 117926 3966def5b2198f40b5e7bb632e983762de369e9d
parent 117925 e4550612487b478ddbf68077e885621bd4aaf91f
child 117927 a2c05e82dd8980bf973030f755c32b0563851f40
push id24134
push userjosh@joshmatthews.net
push dateMon, 07 Jan 2013 16:48:50 +0000
treeherdermozilla-central@3966def5b219 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, vingtetun
bugs822551
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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)