[Pkg-mozext-commits] [requestpolicy] 151/280: eliminate framescript DocManager, which was buggy
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:14 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 5b48125f4894eb2b373ca93891053fd00635c254
Author: Martin Kimmerle <dev at 256k.de>
Date: Sun Jan 18 14:55:22 2015 +0100
eliminate framescript DocManager, which was buggy
`DocManager` was only used in the "DOMContentLoaded" callback.
That callback now notifies the chrome process *synchronously*,
so it's not needed to hold a reference to the document.
In order to let the page load as fast as possible, calling
`indicateBlockedVisibleObjects()` is done async. The indicators
might appear a little later than the page itself.
---
src/content/ui/frame.blocked-content.js | 11 ++--
src/content/ui/frame.doc-manager.js | 100 -----------------------------
src/content/ui/frame.dom-content-loaded.js | 17 +++--
src/content/ui/frame.js | 3 -
src/content/ui/overlay.js | 11 ++--
5 files changed, 23 insertions(+), 119 deletions(-)
diff --git a/src/content/ui/frame.blocked-content.js b/src/content/ui/frame.blocked-content.js
index fed427c..88290e7 100644
--- a/src/content/ui/frame.blocked-content.js
+++ b/src/content/ui/frame.blocked-content.js
@@ -46,12 +46,12 @@ let ManagerForBlockedContent = (function() {
let transparentImageDataUri = "data:image/gif;base64,R0lGODlhAQABAIAAA"
+ "AAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
- let indicateBlockedVisibleObjects = function(message) {
- let {blockedURIs, docID} = message.data;
- let doc = DocManager.getDocument(docID);
- if (!doc) {
+ self.indicateBlockedVisibleObjects = function(doc, blockedURIs) {
+ if (Object.getOwnPropertyNames(blockedURIs).length == 0) {
+ // there are no blocked uris
return;
}
+
let images = doc.getElementsByTagName("img");
// Ideally, want the image to be a broken image so that the alt text
@@ -92,8 +92,5 @@ let ManagerForBlockedContent = (function() {
}
};
- mlManager.addListener("indicateBlockedVisibleObjects",
- indicateBlockedVisibleObjects);
-
return self;
}());
diff --git a/src/content/ui/frame.doc-manager.js b/src/content/ui/frame.doc-manager.js
deleted file mode 100644
index e2c76f4..0000000
--- a/src/content/ui/frame.doc-manager.js
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ***** BEGIN LICENSE BLOCK *****
- *
- * RequestPolicy - A Firefox extension for control over cross-site requests.
- * Copyright (c) 2008 Justin Samuel
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * ***** END LICENSE BLOCK *****
- */
-
-/**
- * This singleton module can be used for having a reference to documents
- * (whether top level or frame documents). This is necessary when chrome code
- * needs to call functions on specific documents.
- *
- */
-let DocManager = (function() {
- let self = {};
-
- let nextDocID = 0;
- let documents = new Map();
-
- // the DocManager is enabled until it is shut down.
- let enabled = true;
-
-
- function cleanUpDoc(docID) {
- let {doc, unloadCallback} = documents.get(docID);
- // clean up listeners
-
- doc.removeEventListener("unload", unloadCallback);
- // no longer remember the document
- documents.delete(docID);
- }
-
- // TODO: Create a `getDocEnv` function. The Environment can then also be
- // used to call `cleanUpDoc`.
- //self.getDocEnv = function(doc) {};
-
-
- self.generateDocID = function(doc) {
- if (!enabled) {
- return null;
- }
-
- let docID = nextDocID++;
-
- let cleanUpThisDoc = cleanUpDoc.bind(this, docID);
-
- // Destructor function:
- // As soon as the document is unloaded, delete the reference.
- // The unload event is called when the document's location changes.
- doc.addEventListener("unload", cleanUpThisDoc);
-
- documents.set(docID, {
- doc: doc,
- unloadCallback: cleanUpThisDoc
- });
-
- return docID;
- };
-
- function cleanUpAllDocs() {
- // call `cleanUpAllDoc` for all docs
- for (let [docID] of documents) {
- // Note to the loop's head:
- // Destructuring assignment (ECMAScript 6) is used, that is, only
- // the "key" of `documents` is used, the "value" is ignored.
- cleanUpDoc(docID);
- }
- }
-
- function shutdownDocManager() {
- enabled = false;
- cleanUpAllDocs();
- }
- FrameScriptEnv.addShutdownFunction(Environment.LEVELS.BACKEND,
- shutdownDocManager);
-
- self.getDocument = function(docID) {
- if (documents.has(docID)) {
- return documents.get(docID).doc;
- }
- return null;
- };
-
- return self;
-}());
diff --git a/src/content/ui/frame.dom-content-loaded.js b/src/content/ui/frame.dom-content-loaded.js
index e57259b..7a230a1 100644
--- a/src/content/ui/frame.dom-content-loaded.js
+++ b/src/content/ui/frame.dom-content-loaded.js
@@ -25,6 +25,7 @@ let ManagerForDOMContentLoaded = (function() {
let self = {};
let {DomainUtil} = ScriptLoader.importModule("lib/utils/domains");
+ let {Utils} = ScriptLoader.importModule("lib/utils");
function htmlAnchorTagClicked(event) {
@@ -58,16 +59,24 @@ let ManagerForDOMContentLoaded = (function() {
// called once.
// <--- the above comment is very old – is it still true that
// onDOMContentLoaded is eventually called multiple times?
- let doc = event.originalTarget;
+ var doc = event.originalTarget;
if (doc.nodeName != "#document") {
// only documents
return;
}
onDocumentLoaded(doc);
- let docID = DocManager.generateDocID(doc);
- mm.sendAsyncMessage(C.MM_PREFIX + "notifyDocumentLoaded",
- {docID: docID, documentURI: doc.documentURI});
+
+ // take only one answer. If there are more answers, they are ignored
+ // ==> there must be only one listener for 'notifyDocumentLoaded'
+ let [answer] = mm.sendSyncMessage(C.MM_PREFIX + "notifyDocumentLoaded",
+ {documentURI: doc.documentURI});
+ var blockedURIs = answer.blockedURIs;
+ // Indicating blocked visible objects isn't an urgent task, so this should
+ // be done async.
+ Utils.runAsync(function() {
+ ManagerForBlockedContent.indicateBlockedVisibleObjects(doc, blockedURIs);
+ });
if (isActiveTopLevelDocument(doc)) {
diff --git a/src/content/ui/frame.js b/src/content/ui/frame.js
index f7520b5..213bea6 100644
--- a/src/content/ui/frame.js
+++ b/src/content/ui/frame.js
@@ -187,9 +187,6 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Services.scriptloader.loadSubScriptWithOptions(
'chrome://requestpolicy/content/ui/frame.dom-content-loaded.js',
{target: FrameScriptScope/*, ignoreCache: true*/});
- Services.scriptloader.loadSubScriptWithOptions(
- 'chrome://requestpolicy/content/ui/frame.doc-manager.js',
- {target: FrameScriptScope/*, ignoreCache: true*/});
}
FrameScriptEnv.addStartupFunction(Environment.LEVELS.BACKEND,
loadSubScripts);
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index e81333e..3b162a4 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -233,18 +233,19 @@ requestpolicy.overlay = (function() {
mlManager.addListener("notifyDocumentLoaded", function(message) {
- let {docID, documentURI} = message.data;
+ let {documentURI} = message.data;
// the <browser> element of the corresponding tab.
let browser = message.target;
+ let blockedURIs = {};
+
if (rpPrefBranch.getBoolPref("indicateBlockedObjects")) {
var indicateBlacklisted = rpPrefBranch
.getBoolPref("indicateBlacklistedObjects");
var rejectedRequests = RequestProcessor._rejectedRequests
.getOriginUri(documentURI);
- let blockedURIs = {};
for (var destBase in rejectedRequests) {
for (var destIdent in rejectedRequests[destBase]) {
for (var destUri in rejectedRequests[destBase][destIdent]) {
@@ -267,9 +268,6 @@ requestpolicy.overlay = (function() {
}
}
}
- message.target.messageManager.sendAsyncMessage(
- C.MM_PREFIX + "indicateBlockedVisibleObjects",
- {blockedURIs: blockedURIs, docID: docID});
}
if ("requestpolicy" in browser &&
@@ -283,6 +281,9 @@ requestpolicy.overlay = (function() {
delete browser.requestpolicy.blockedRedirects[documentURI];
}
+
+ // send the list of blocked URIs back to the frame script
+ return {blockedURIs: blockedURIs};
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list