[Pkg-mozext-commits] [greasemonkey] 38/55: piggyback script refresh checking on http requests for page/frame loads

David Prévot taffit at moszumanska.debian.org
Thu Oct 29 15:38:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository greasemonkey.

commit 4b240a704b66800fd953ccfa205cf4d9e41a8f4a
Author: The8472 <git at infinite-source.de>
Date:   Thu Sep 24 20:30:09 2015 +0200

    piggyback script refresh checking on http requests for page/frame loads
---
 components/greasemonkey.js |  2 ++
 modules/requestObserver.js | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/components/greasemonkey.js b/components/greasemonkey.js
index 48870ee..9dc0eea 100644
--- a/components/greasemonkey.js
+++ b/components/greasemonkey.js
@@ -98,6 +98,8 @@ function startup(aService) {
       }
   }});
 
+  Cu.import("chrome://greasemonkey-modules/content/requestObserver.js", {});
+
   Services.obs.addObserver(aService, 'quit-application', false);
 
   // Import this once, early, so that enqueued deletes can happen.
diff --git a/modules/requestObserver.js b/modules/requestObserver.js
new file mode 100644
index 0000000..58314b2
--- /dev/null
+++ b/modules/requestObserver.js
@@ -0,0 +1,41 @@
+'use strict';
+
+const EXPORTED_SYMBOLS = [];
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("chrome://greasemonkey-modules/content/util.js");
+Components.utils.import("chrome://greasemonkey-modules/content/prefmanager.js");
+
+const types = Components.interfaces.nsIContentPolicy
+
+function checkScriptRefresh(channel) {
+  // .loadInfo is part of nsiChannel -> implicit QI needed
+  if (!(channel instanceof Components.interfaces.nsIChannel)) return;
+  if (!channel.loadInfo) return;
+
+  var type = channel.loadInfo.contentPolicyType;
+  
+  // only check for updated scripts when tabs/iframes are loaded 
+  if (type != types.TYPE_DOCUMENT && type != types.TYPE_SUBDOCUMENT) return;
+
+  // forward compatibility: https://bugzilla.mozilla.org/show_bug.cgi?id=1124477
+  var browser = channel.loadInfo.topFrameElement;
+
+  if (!browser && channel.notificationCallbacks) {
+    // current API: https://bugzilla.mozilla.org/show_bug.cgi?id=1123008#c7
+    var loadCtx = channel.notificationCallbacks.QueryInterface(
+        Components.interfaces.nsIInterfaceRequestor).getInterface(
+        Components.interfaces.nsILoadContext);
+    browser = loadCtx.topFrameElement;
+  }
+
+  var windowId = channel.loadInfo.innerWindowID;
+
+  GM_util.getService().scriptRefresh(channel.URI.spec, windowId, browser);
+}
+
+Services.obs.addObserver({
+  observe: function(subject, topic, data) {
+    checkScriptRefresh(subject);
+  }
+}, "http-on-modify-request", false);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/greasemonkey.git



More information about the Pkg-mozext-commits mailing list