From bc63d7486c2344cc0d4696cf8b490ad7a5ec7398 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 3 Nov 2014 12:39:00 +0100 Subject: [PATCH] Bug 1092447 - Ignore non top-level documents when enabling/disabling Report Site Menu. r=margaret --- .../android/chrome/content/WebcompatReporter.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mobile/android/chrome/content/WebcompatReporter.js b/mobile/android/chrome/content/WebcompatReporter.js index e0e5a87dc7c..3ca8449a5af 100644 --- a/mobile/android/chrome/content/WebcompatReporter.js +++ b/mobile/android/chrome/content/WebcompatReporter.js @@ -13,12 +13,15 @@ var WebcompatReporter = { menuItemEnabled: null, init: function() { Services.obs.addObserver(this, "DesktopMode:Change", false); - Services.obs.addObserver(this, "content-page-shown", false); + Services.obs.addObserver(this, "chrome-document-global-created", false); + Services.obs.addObserver(this, "content-document-global-created", false); this.addMenuItem(); }, uninit: function() { Services.obs.removeObserver(this, "DesktopMode:Change"); + Services.obs.removeObserver(this, "chrome-document-global-created"); + Services.obs.removeObserver(this, "content-document-global-created"); if (this.menuItem) { NativeWindow.menu.remove(this.menuItem); @@ -27,8 +30,15 @@ var WebcompatReporter = { }, observe: function(subject, topic, data) { - if (topic === "content-page-shown") { - let currentURI = subject.documentURI; + if (topic == "content-document-global-created" || topic == "chrome-document-global-created") { + let win = subject; + let currentURI = win.document.documentURI; + + // Ignore non top-level documents + if (currentURI !== win.top.location.href) { + return; + } + if (!this.menuItemEnabled && this.isReportableUrl(currentURI)) { NativeWindow.menu.update(this.menuItem, {enabled: true}); this.menuItemEnabled = true;