From e8cd4c9338efc9764d54092e3fc3b48dfc322b32 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Fri, 27 Jul 2018 16:44:28 +0200 Subject: [PATCH] Use Services.io to access IOService --- chrome/content/zotero/xpcom/file.js | 4 +--- chrome/content/zotero/xpcom/http.js | 7 ++----- chrome/content/zotero/xpcom/utilities.js | 6 ++---- chrome/content/zotero/xpcom/zotero.js | 8 ++------ 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 513a4580b3..be7301bc38 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -59,9 +59,7 @@ Zotero.File = new function(){ this.pathToFileURI = function (path) { var file = new FileUtils.File(path); - var ios = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - return ios.newFileURI(file).spec; + return Services.io.newFileURI(file).spec; } diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js index 6b7591947b..21a143e325 100644 --- a/chrome/content/zotero/xpcom/http.js +++ b/chrome/content/zotero/xpcom/http.js @@ -833,8 +833,7 @@ Zotero.HTTP = new function() { * @type Boolean */ this.browserIsOffline = function() { - return Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService).offline; + return Services.io.offline; } @@ -1064,10 +1063,8 @@ Zotero.HTTP = new function() { if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_INSECURE) == Ci.nsIWebProgressListener.STATE_IS_INSECURE) { let url = channel.name; - let ios = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); try { - var uri = ios.newURI(url, null, null); + var uri = Services.io.newURI(url, null, null); var host = uri.host; } catch (e) { diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 2f38954747..d82c445fa7 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -267,10 +267,8 @@ Zotero.Utilities = { url = url.trim(); if (!url) return false; - var ios = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); try { - return ios.newURI(url, null, null).spec; // Valid URI if succeeds + return Services.io.newURI(url, null, null).spec; // Valid URI if succeeds } catch (e) { if (e instanceof Components.Exception && e.result == Components.results.NS_ERROR_MALFORMED_URI @@ -278,7 +276,7 @@ Zotero.Utilities = { if (tryHttp && /\w\.\w/.test(url)) { // Assume it's a URL missing "http://" part try { - return ios.newURI('http://' + url, null, null).spec; + return Services.io.newURI('http://' + url, null, null).spec; } catch (e) {} } diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index d549701034..ca31cf1cd9 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -768,9 +768,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); } // Load More Info page else if (index == 2) { - let io = Components.classes['@mozilla.org/network/io-service;1'] - .getService(Components.interfaces.nsIIOService); - let uri = io.newURI(kbURL, null, null); + let uri = Services.io.newURI(kbURL, null, null); let handler = Components.classes['@mozilla.org/uriloader/external-protocol-service;1'] .getService(Components.interfaces.nsIExternalProtocolService) .getProtocolHandlerInfo('http'); @@ -1167,9 +1165,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); } try { - var io = Components.classes['@mozilla.org/network/io-service;1'] - .getService(Components.interfaces.nsIIOService); - var uri = io.newURI(url, null, null); + var uri = Services.io.newURI(url, null, null); var handler = Components.classes['@mozilla.org/uriloader/external-protocol-service;1'] .getService(Components.interfaces.nsIExternalProtocolService) .getProtocolHandlerInfo('http');