Bug 1079554 - Ignore most UITour messages from pages that aren't visible. r=Unfocused, a=sledru
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 21 Jan 2015 21:05:05 -0800
changeset 243002 e35e98044772
parent 243001 0411d20465b4
child 243003 0d51214654ad
push id4358
push userryanvm@gmail.com
push date2015-01-22 19:57 +0000
treeherdermozilla-beta@62f7b8ea571f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused, sledru
bugs1079554
milestone36.0
Bug 1079554 - Ignore most UITour messages from pages that aren't visible. r=Unfocused, a=sledru
browser/base/content/content-UITour.js
browser/modules/UITour.jsm
--- a/browser/base/content/content-UITour.js
+++ b/browser/base/content/content-UITour.js
@@ -8,17 +8,21 @@ let UITourListener = {
     if (!Services.prefs.getBoolPref("browser.uitour.enabled")) {
       return;
     }
     if (!this.ensureTrustedOrigin()) {
       return;
     }
     addMessageListener("UITour:SendPageCallback", this);
     addMessageListener("UITour:SendPageNotification", this);
-    sendAsyncMessage("UITour:onPageEvent", {detail: event.detail, type: event.type});
+    sendAsyncMessage("UITour:onPageEvent", {
+      detail: event.detail,
+      type: event.type,
+      pageVisibilityState: content.document.visibilityState,
+    });
   },
 
   isTestingOrigin: function(aURI) {
     if (Services.prefs.getPrefType(PREF_TEST_WHITELIST) != Services.prefs.PREF_STRING) {
       return false;
     }
 
     // Add any testing origins (comma-seperated) to the whitelist for the session.
--- a/browser/modules/UITour.jsm
+++ b/browser/modules/UITour.jsm
@@ -24,16 +24,25 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
   "resource:///modules/BrowserUITelemetry.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Metrics",
   "resource://gre/modules/Metrics.jsm");
 
 // See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
 const PREF_LOG_LEVEL      = "browser.uitour.loglevel";
 const PREF_SEENPAGEIDS    = "browser.uitour.seenPageIDs";
+
+const BACKGROUND_PAGE_ACTIONS_ALLOWED = new Set([
+  "getConfiguration",
+  "getTreatmentTag",
+  "ping",
+  "registerPageID",
+  "setConfiguration",
+  "setTreatmentTag",
+]);
 const MAX_BUTTONS         = 4;
 
 const BUCKET_NAME         = "UITour";
 const BUCKET_TIMESTEPS    = [
   1 * 60 * 1000, // Until 1 minute after tab is closed/inactive.
   3 * 60 * 1000, // Until 3 minutes after tab is closed/inactive.
   10 * 60 * 1000, // Until 10 minutes after tab is closed/inactive.
   60 * 60 * 1000, // Until 1 hour after tab is closed/inactive.
@@ -327,17 +336,17 @@ this.UITour = {
 
   onPageEvent: function(aMessage, aEvent) {
     let contentDocument = null;
     let browser = aMessage.target;
     let window = browser.ownerDocument.defaultView;
     let tab = window.gBrowser.getTabForBrowser(browser);
     let messageManager = browser.messageManager;
 
-    log.debug("onPageEvent:", aEvent.detail);
+    log.debug("onPageEvent:", aEvent.detail, aMessage);
 
     if (typeof aEvent.detail != "object") {
       log.warn("Malformed event - detail not an object");
       return false;
     }
 
     let action = aEvent.detail.action;
     if (typeof action != "string" || !action) {
@@ -346,16 +355,23 @@ this.UITour = {
     }
 
     let data = aEvent.detail.data;
     if (typeof data != "object") {
       log.warn("Malformed event - data not an object");
       return false;
     }
 
+    if ((aEvent.pageVisibilityState == "hidden" ||
+         aEvent.pageVisibilityState == "unloaded") &&
+        !BACKGROUND_PAGE_ACTIONS_ALLOWED.has(action)) {
+      log.warn("Ignoring disallowed action from a hidden page:", action);
+      return false;
+    }
+
     // Do this before bailing if there's no tab, so later we can pick up the pieces:
     window.gBrowser.tabContainer.addEventListener("TabSelect", this);
 
     if (!window.gMultiProcessBrowser) { // Non-e10s. See bug 1089000.
       contentDocument = browser.contentWindow.document;
       if (!tab) {
         // This should only happen while detaching a tab:
         if (this._detachingTab) {