[Pkg-mozext-commits] [greasemonkey] 40/62: Only implement newChannelFromURI2 logic once.
David Prévot
taffit at moszumanska.debian.org
Sun Sep 13 22:10:23 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 22b4714ae11ae7a204763a640d29f7707a99c37b
Author: Anthony Lieuallen <arantius at gmail.com>
Date: Mon Aug 24 16:26:52 2015 -0400
Only implement newChannelFromURI2 logic once.
---
modules/remoteScript.js | 9 +--------
modules/scriptProtocol.js | 12 +-----------
modules/util.js | 1 +
modules/util/channelFromUri.js | 21 +++++++++++++++++++++
modules/util/getBinaryContents.js | 19 ++++---------------
modules/util/getContents.js | 18 ++++--------------
6 files changed, 32 insertions(+), 48 deletions(-)
diff --git a/modules/remoteScript.js b/modules/remoteScript.js
index 598d666..8f27c51 100644
--- a/modules/remoteScript.js
+++ b/modules/remoteScript.js
@@ -586,14 +586,7 @@ RemoteScript.prototype._downloadFile = function(
}
}
- var channel = null;
- if (ioService.newChannelFromURI2) {
- channel = ioService.newChannelFromURI2(
- aUri, null, Services.scriptSecurityManager.getSystemPrincipal(),
- null, Ci.nsILoadInfo.SEC_NORMAL, Ci.nsIContentPolicy.TYPE_OTHER);
- } else {
- channel = ioService.newChannelFromURI(aUri);
- }
+ var channel = GM_util.channelFromUri(aUri);
channel.loadFlags |= channel.LOAD_BYPASS_CACHE;
this._channels.push(channel);
var dsl = new DownloadListener(
diff --git a/modules/scriptProtocol.js b/modules/scriptProtocol.js
index 75861ff..d6c7e78 100644
--- a/modules/scriptProtocol.js
+++ b/modules/scriptProtocol.js
@@ -8,8 +8,6 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var schemeName = 'greasemonkey-script';
-var ioService = Cc['@mozilla.org/network/io-service;1']
- .getService(Ci.nsIIOService);
var gHaveDoneInit = false;
@@ -148,15 +146,7 @@ var ScriptProtocol = {
// In parent scope we have the raw script, with file intact.
uri = GM_util.getUriFromFile(resource.file);
}
- var channel = null;
- if (ioService.newChannelFromURI2) {
- channel = ioService.newChannelFromURI2(
- uri, null, Services.scriptSecurityManager.getSystemPrincipal(),
- null, Ci.nsILoadInfo.SEC_NORMAL, Ci.nsIContentPolicy.TYPE_OTHER);
- } else {
- channel = ioService.newChannelFromURI(uri);
- }
- return channel;
+ return GM_util.channelFromUri(uri);
}
}
diff --git a/modules/util.js b/modules/util.js
index 874f3ba..571ad90 100644
--- a/modules/util.js
+++ b/modules/util.js
@@ -24,6 +24,7 @@ var GM_util = {};
// Do not edit below this line. Use `util.sh` to auto-populate.
XPCOMUtils.defineLazyModuleGetter(GM_util, 'alert', 'chrome://greasemonkey-modules/content/util/alert.js');
+XPCOMUtils.defineLazyModuleGetter(GM_util, 'channelFromUri', 'chrome://greasemonkey-modules/content/util/channelFromUri.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'compareFirefoxVersion', 'chrome://greasemonkey-modules/content/util/compareFirefoxVersion.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'emptyEl', 'chrome://greasemonkey-modules/content/util/emptyEl.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'enqueueRemoveFile', 'chrome://greasemonkey-modules/content/util/enqueueRemoveFile.js');
diff --git a/modules/util/channelFromUri.js b/modules/util/channelFromUri.js
new file mode 100644
index 0000000..a045119
--- /dev/null
+++ b/modules/util/channelFromUri.js
@@ -0,0 +1,21 @@
+var EXPORTED_SYMBOLS = ['channelFromUri'];
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+var ioService = Cc['@mozilla.org/network/io-service;1']
+ .getService(Ci.nsIIOService);
+
+
+function channelFromUri(aUri) {
+ if (ioService.newChannelFromURI2) {
+ return ioService.newChannelFromURI2(
+ aUri, null, Services.scriptSecurityManager.getSystemPrincipal(),
+ null, Ci.nsILoadInfo.SEC_NORMAL, Ci.nsIContentPolicy.TYPE_OTHER);
+ } else {
+ return ioService.newChannelFromURI(aUri);
+ }
+}
diff --git a/modules/util/getBinaryContents.js b/modules/util/getBinaryContents.js
index 2c048fe..8ed2661 100644
--- a/modules/util/getBinaryContents.js
+++ b/modules/util/getBinaryContents.js
@@ -1,22 +1,11 @@
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import('chrome://greasemonkey-modules/content/util.js');
-
var EXPORTED_SYMBOLS = ['getBinaryContents'];
-var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
+Components.utils.import('resource://gre/modules/Services.jsm');
+Components.utils.import('chrome://greasemonkey-modules/content/util.js');
+
function getBinaryContents(aFile) {
- var channel = null;
- if (ioService.newChannelFromURI2) {
- channel = ioService.newChannelFromURI2(
- GM_util.getUriFromFile(aFile), null,
- Services.scriptSecurityManager.getSystemPrincipal(), null,
- Components.interfaces.nsILoadInfo.SEC_NORMAL,
- Components.interfaces.nsIContentPolicy.TYPE_OTHER);
- } else {
- channel = ioService.newChannelFromURI(GM_util.getUriFromFile(aFile));
- }
+ var channel = GM_util.channelFromUri(GM_util.getUriFromFile(aFile));
var input = channel.open();
var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]
diff --git a/modules/util/getContents.js b/modules/util/getContents.js
index 29802ba..af89af6 100644
--- a/modules/util/getContents.js
+++ b/modules/util/getContents.js
@@ -1,10 +1,8 @@
+var EXPORTED_SYMBOLS = ['getContents'];
+
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import('chrome://greasemonkey-modules/content/util.js');
-var EXPORTED_SYMBOLS = ['getContents'];
-
-var ioService=Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
var scriptableStream=Components
.classes["@mozilla.org/scriptableinputstream;1"]
.getService(Components.interfaces.nsIScriptableInputStream);
@@ -12,6 +10,7 @@ var unicodeConverter = Components
.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+
function getContents(aFile, aCharset, aFatal) {
if (!aFile.isFile()) {
throw new Error(
@@ -19,16 +18,7 @@ function getContents(aFile, aCharset, aFatal) {
}
unicodeConverter.charset = aCharset || 'UTF-8';
- var channel = null;
- if (ioService.newChannelFromURI2) {
- channel = ioService.newChannelFromURI2(
- GM_util.getUriFromFile(aFile), null,
- Services.scriptSecurityManager.getSystemPrincipal(), null,
- Components.interfaces.nsILoadInfo.SEC_NORMAL,
- Components.interfaces.nsIContentPolicy.TYPE_OTHER);
- } else {
- channel = ioService.newChannelFromURI(GM_util.getUriFromFile(aFile));
- }
+ var channel = GM_util.channelFromUri(GM_util.getUriFromFile(aFile));
try {
var input = channel.open();
} catch (e) {
--
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