/usr/share/xul-ext/greasemonkey/modules/requestObserver.js is in xul-ext-greasemonkey 3.8-1~deb8u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | 'use strict';
var EXPORTED_SYMBOLS = [];
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("chrome://greasemonkey-modules/content/util.js");
Cu.import("chrome://greasemonkey-modules/content/prefmanager.js");
var gDisallowedSchemes = {
'chrome': 1, 'greasemonkey-script': 1, 'view-source': 1};
var gScriptEndingRegexp = new RegExp('\\.user\\.js$');
var gContentTypes = Ci.nsIContentPolicy;
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
function checkScriptRefresh(channel) {
// .loadInfo is part of nsiChannel -> implicit QI needed
if (!(channel instanceof Components.interfaces.nsIChannel)) return;
if (!channel.loadInfo) return;
// See http://bugzil.la/1182571
var type = channel.loadInfo.externalContentPolicyType
? channel.loadInfo.externalContentPolicyType
: channel.loadInfo.contentPolicyType;
// only check for updated scripts when tabs/iframes are loaded
if (type != gContentTypes.TYPE_DOCUMENT
&& type != gContentTypes.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);
}
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
function installObserver(aSubject, aTopic, aData) {
// When observing a new request, inspect it to determine if it should be
// a user script install. If so, abort and restart as an install rather
// than a navigation.
if (!GM_util.getEnabled()) {
return;
}
var channel = aSubject.QueryInterface(Ci.nsIChannel);
if (!channel || !channel.loadInfo) {
return;
}
// See http://bugzil.la/1182571
var type = channel.loadInfo.externalContentPolicyType
|| channel.loadInfo.contentPolicyType;
if (type != gContentTypes.TYPE_DOCUMENT) {
return;
}
if (channel.URI.scheme in gDisallowedSchemes) {
return;
}
try {
var httpChannel = channel.QueryInterface(Ci.nsIHttpChannel);
if ('POST' == httpChannel.requestMethod) {
return;
}
} catch (e) {
// Ignore completely, e.g. file:/// URIs.
}
if (!channel.URI.spec.match(gScriptEndingRegexp)) {
return;
}
// We've done an early return above for all non-user-script navigations. If
// execution has proceeded to this point, we want to cancel the existing
// request (i.e. navigation) and instead start a script installation for
// this same URI.
try {
var request = channel.QueryInterface(Ci.nsIRequest);
request.suspend();
var browser = channel
.QueryInterface(Ci.nsIHttpChannel)
.notificationCallbacks
.getInterface(Ci.nsILoadContext)
.topFrameElement;
GM_util.showInstallDialog(channel.URI.spec, browser, request);
} catch (e) {
dump('Greasemonkey could not do script install!\n'+e+'\n');
// Ignore.
return;
}
}
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
Services.obs.addObserver({
observe: function(aSubject, aTopic, aData) {
try {
installObserver(aSubject, aTopic, aData);
} catch (e) {
dump('Greasemonkey install observer failed:\n' + e + '\n');
}
try {
checkScriptRefresh(aSubject);
} catch (e) {
dump('Greasemonkey refresh observer failed:\n' + e + '\n');
}
}
}, "http-on-modify-request", false);
|