Skip to content

Commit

Permalink
Making @grant enabled by default, but possible to opt-out of, and rem…
Browse files Browse the repository at this point in the history
…oving the grant sniffing
  • Loading branch information
erikvold committed Apr 30, 2014
1 parent 62103e6 commit 0f767fa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions extension/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<preference id="pref-enabledSchemes-about" name="extensions.scriptish.enabledSchemes.about" type="bool"/>
<preference id="pref-logChrome" name="extensions.scriptish.logChrome" type="bool"/>
<preference id="pref-logToErrorConsole" name="extensions.scriptish.logToErrorConsole" type="bool"/>
<preference id="pref-enableScriptGrantSniffing" name="extensions.scriptish.enableScriptGrantSniffing" type="bool"/>
<preference id="pref-enableScriptGrant" name="extensions.scriptish.enableScriptGrant" type="bool"/>
<preference id="pref-enableInstallDetection" name="extensions.scriptish.enableInstallDetection" type="bool"/>
<preference id="pref-update-requireSecured" name="extensions.scriptish.update.requireSecured" type="bool"/>
<preference id="pref-update-requireBuiltInCerts" name="extensions.scriptish.update.requireBuiltInCerts" type="bool"/>
Expand All @@ -130,7 +130,7 @@
</groupbox>
<groupbox>
<caption label="options.other" localize="label" />
<checkbox preference="pref-enableScriptGrantSniffing" label="options.grant.sniffing" localize="label"/>
<checkbox preference="pref-enableScriptGrant" label="options.grant.enabled" localize="label"/>
<checkbox preference="pref-enableInstallDetection" label="options.enableInstallDetection" localize="label"/>
</groupbox>
</tabpanel>
Expand Down
2 changes: 1 addition & 1 deletion extension/defaults/preferences/scriptish.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pref("extensions.scriptish.enableCopyDownloadURL", false);
pref("extensions.scriptish.enabledNotifications.popup", true);
pref("extensions.scriptish.enabledNotifications.sliding", true);
pref("extensions.scriptish.enableScriptRefreshing", true);
pref("extensions.scriptish.enableScriptGrantSniffing", true);
pref("extensions.scriptish.enableScriptGrant", true);
pref("extensions.scriptish.enableInstallDetection", true);
pref("extensions.scriptish.logChrome", false);
pref("extensions.scriptish.logToErrorConsole", true);
Expand Down
2 changes: 1 addition & 1 deletion extension/locale/en-US/scriptish.properties
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ options.enabledSchemes.unmht=unmht protocol (Mozilla Archive format)
options.excludes.desc=Global excludes will override any script or user specified rules
options.excludes.empty=No global excludes specified
options.excludes.remark=(You may specify one exclude per line)
options.grant.sniffing=Enable @grant sniffing
options.grant.enabled=Enable @grant
options.logChrome=Log non-critical extension messages to the Error Console
options.logging=Logging
options.logToErrorConsole=GM_log uses the Error Console
Expand Down
8 changes: 1 addition & 7 deletions extension/modules/script/script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var EXPORTED_SYMBOLS = ["Script"];

const valueSplitter = /(\S+)(?:\s+([^\r\f\n]+))?/;
const GRANT_REGEX = /(?:unsafeWindow|GM_[a-z]+)/gi;

const Cu = Components.utils;
Cu.import("resource://gre/modules/CertUtils.jsm");
Expand Down Expand Up @@ -921,11 +920,6 @@ Script.parse = function Script_parse(aConfig, aSource, aURI, aUpdateScript, aPri
if (aURI && aPrivate === false)
script._downloadURL = aURI.spec;

// sniff @grant ?
if (Scriptish_prefRoot.getValue("enableScriptGrantSniffing")) {
(aSource.match(GRANT_REGEX) || []).forEach(function(i) script.grant[i] = true);
}

// read one line at a time looking for start meta delimiter or EOF
var lines = aSource.match(metaRegExp);
var i = 0;
Expand Down Expand Up @@ -1066,7 +1060,7 @@ Script.parse = function Script_parse(aConfig, aSource, aURI, aUpdateScript, aPri
continue;
case "grant":
var splitValue = value.split(/[ \t]+/);
splitValue.forEach(function(i) script.grant[i] = true);
splitValue.forEach(i => script.grant[i] = true);
continue;
case "include":
script.addInclude(value);
Expand Down
20 changes: 13 additions & 7 deletions extension/modules/utils/Scriptish_injectScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ const { getInnerId } = jetpack('sdk/window/utils');

const {nsIDOMXPathResult: XPATH_RESULT} = Ci;

let useGrants = Scriptish_prefRoot.getValue("enableScriptGrant");
Scriptish_prefRoot.watch("enableScriptGrant", _ => {
useGrants = Scriptish_prefRoot.getValue("enableScriptGrant");
});

function Scriptish_injectScripts(options) {
var {scripts, url, safeWin} = options;
var chromeWin = Scriptish_getBrowserForContentWindow(safeWin).wrappedJSObject;
const { scripts, url, safeWin } = options;
const chromeWin = Scriptish_getBrowserForContentWindow(safeWin).wrappedJSObject;
if (!chromeWin || !chromeWin.Scriptish_BrowserUI) return;

if (0 >= scripts.length) return;
Expand Down Expand Up @@ -61,7 +66,8 @@ function Scriptish_injectScripts(options) {

Cu.evalInSandbox(GM_updatingEnabled, sandbox);

if (script.grant['GM_xpath']) {
Scriptish_log('granting: ' + Object.keys(script.grant).join(', '))
if (!useGrants || script.grant['GM_xpath']) {
Cu.evalInSandbox(GM_xpath, sandbox);
}

Expand All @@ -74,8 +80,8 @@ function Scriptish_injectScripts(options) {
unsafeWin: unsafeContentWin,
chromeWin: chromeWin
}))) {
for (var funcName in GM_api) {
if (script.grant[funcName]) {
for (let funcName in GM_api) {
if (!useGrants || script.grant[funcName]) {
sandbox[funcName] = GM_api[funcName];
}
else {
Expand All @@ -88,10 +94,10 @@ function Scriptish_injectScripts(options) {
return GM_console(script, safeWin, chromeWin);
});

if (script.grant['GM_log']) {
if (!useGrants || script.grant['GM_log']) {
lazy(sandbox, "GM_log", function() {
if (Scriptish_prefRoot.getValue("logToErrorConsole")) {
var logger = new GM_ScriptLogger(script);
let logger = new GM_ScriptLogger(script);
return function() {
const args = Array.slice(arguments);
logger.log(args.join(" "));
Expand Down

0 comments on commit 0f767fa

Please sign in to comment.