Bug 667662 - Switch suite to use Services.io r=neil
--- a/suite/common/bookmarks/bookmarksManager.js
+++ b/suite/common/bookmarks/bookmarksManager.js
@@ -755,19 +755,17 @@ var PlacesOrganizer = {
// Get the place: uri for the query.
// If the advanced query builder is showing, use that.
var options = this.getCurrentOptions();
var queries = this.getCurrentQueries();
var placeSpec = PlacesUtils.history.queriesToQueryString(queries,
queries.length,
options);
- var placeURI = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService)
- .newURI(placeSpec, null, null);
+ var placeURI = Services.io.newURI(placeSpec, null, null);
// Prompt the user for a name for the query.
// XXX - using prompt service for now; will need to make
// a real dialog and localize when we're sure this is the UI we want.
var title = PlacesUIUtils.getString("saveSearch.title");
var inputLabel = PlacesUIUtils.getString("saveSearch.inputLabel");
var defaultText = PlacesUIUtils.getString("saveSearch.inputDefaultText");
--- a/suite/common/contentAreaClick.js
+++ b/suite/common/contentAreaClick.js
@@ -299,18 +299,8 @@
// Remove any expired history items so that we don't let
// this grow without bound.
connection.executeSimpleSQL(
"DELETE FROM urlbarhistory WHERE ROWID NOT IN " +
"(SELECT ROWID FROM urlbarhistory ORDER BY ROWID DESC LIMIT 30)");
connection.commitTransaction();
connection.close();
}
-
- function makeURLAbsolute(base, url)
- {
- // Construct nsIURL.
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var baseURI = ioService.newURI(base, null, null);
-
- return ioService.newURI(baseURI.resolve(url), null, null).spec;
- }
--- a/suite/common/downloads/downloadmanager.js
+++ b/suite/common/downloads/downloadmanager.js
@@ -244,19 +244,17 @@ function openDownload(aDownload)
}
} catch (ex) { }
try {
file.launch();
} catch (ex) {
// If launch fails, try sending it through the system's external
// file: URL handler
- var uri = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService)
- .newFileURI(file);
+ var uri = Services.io.newFileURI(file);
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
.getService(Components.interfaces.nsIExternalProtocolService);
protocolSvc.loadUrl(uri);
}
}
function showDownload(aDownload)
{
@@ -271,19 +269,17 @@ function showDownload(aDownload)
var parent = file.parent.QueryInterface(Components.interfaces.nsILocalFile);
try {
// "Double click" the parent directory to show where the file should be
parent.launch();
} catch (e) {
// If launch also fails (probably because it's not implemented), let the
// OS handler try to open the parent
- var uri = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService)
- .newFileURI(parent);
+ var uri = Services.io.newFileURI(parent);
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
.getService(Components.interfaces.nsIExternalProtocolService);
protocolSvc.loadUrl(uri);
}
}
}
function showProperties(aDownloadID)
--- a/suite/common/history/history.js
+++ b/suite/common/history/history.js
@@ -39,17 +39,16 @@
*
* ***** END LICENSE BLOCK ***** */
var gHistoryTree;
var gLastHostname;
var gLastDomain;
var gSearchBox;
var gPrefService;
-var gIOService;
var gDeleteByHostname;
var gDeleteByDomain;
var gHistoryStatus;
var gHistoryGrouping = "day";
function HistoryCommonInit()
{
gHistoryTree = document.getElementById("historyTree");
@@ -92,20 +91,17 @@ function historyOnSelect()
gLastDomain = null;
var url = null;
var selectedNode = gHistoryTree.selectedNode;
if (selectedNode) {
if (PlacesUtils.nodeIsURI(selectedNode)) {
try {
url = selectedNode.uri;
- if (!gIOService)
- gIOService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- gLastHostname = gIOService.newURI(url, null, null).host;
+ gLastHostname = Services.io.newURI(url, null, null).host;
} catch (e) {}
} else if (PlacesUtils.nodeIsHost(selectedNode)) {
gLastHostname = selectedNode.title;
}
if (gLastHostname) {
try {
gLastDomain = Services.eTLD.getBaseDomainFromHost(gLastHostname);
} catch (e) {}
--- a/suite/common/nsContextMenu.js
+++ b/suite/common/nsContextMenu.js
@@ -516,17 +516,17 @@ nsContextMenu.prototype = {
}
else if ( this.target instanceof HTMLHtmlElement ) {
// pages with multiple <body>s are lame. we'll teach them a lesson.
var bodyElt = this.target.ownerDocument.body;
if (bodyElt) {
var computedURL = this.getComputedURL(bodyElt, "background-image");
if (computedURL) {
this.hasBGImage = true;
- this.bgImageURL = this.makeURLAbsolute(bodyElt.baseURI, computedURL);
+ this.bgImageURL = makeURLAbsolute(bodyElt.baseURI, computedURL);
}
}
}
else if ("HTTPIndex" in content &&
content.HTTPIndex instanceof Components.interfaces.nsIHTTPIndex) {
this.inDirList = true;
// Bubble outward till we get to an element with URL attribute
// (which should be the href).
@@ -626,17 +626,17 @@ nsContextMenu.prototype = {
// Background image? Don't bother if we've already found a
// background image further down the hierarchy. Otherwise,
// we look for the computed background-image style.
if (!this.hasBGImage) {
var bgImgUrl = this.getComputedURL(elem, "background-image");
if (bgImgUrl) {
this.hasBGImage = true;
- this.bgImageURL = this.makeURLAbsolute(elem.baseURI, bgImgUrl);
+ this.bgImageURL = makeURLAbsolute(elem.baseURI, bgImgUrl);
}
}
}
elem = elem.parentNode;
}
},
initPopupURL: function() {
@@ -658,23 +658,17 @@ nsContextMenu.prototype = {
CI.nsIWindowCreator2.PARENT_IS_LOADING_OR_RUNNING_TIMEOUT) {
// do the pref settings allow site-by-site popup management?
const PB = Components.classes["@mozilla.org/preferences-service;1"]
.getService(CI.nsIPrefBranch);
show = !PB.getBoolPref("dom.disable_open_during_load");
}
if (show) {
// initialize popupURL
- const IOS = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(CI.nsIIOService);
- this.popupURL = IOS.newURI(window.content.opener.location.href, null, null);
-
- // but cancel if it's an unsuitable URL
- const PM = Components.classes["@mozilla.org/PopupWindowManager;1"]
- .getService(CI.nsIPopupWindowManager);
+ this.popupURL = Services.io.newURI(window.content.opener.location.href, null, null);
}
} catch(e) {
}
},
// Returns the computed style attribute for the given element.
getComputedStyle: function(aElem, aProp) {
return aElem.ownerDocument
@@ -980,19 +974,17 @@ nsContextMenu.prototype = {
// If we don't have the headers after a short time the user won't have
// received any feedback from the click. That's bad, so we give up
// waiting for the filename.
function timerCallback() {
channel.cancel(NS_ERROR_SAVE_LINK_AS_TIMEOUT);
}
// set up a channel to do the saving
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var channel = ioService.newChannel(linkURL, null, null);
+ var channel = Services.io.newChannel(linkURL, null, null);
channel.notificationCallbacks = new Callbacks();
channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE |
Components.interfaces.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS;
if (channel instanceof Components.interfaces.nsIHttpChannel) {
channel.referrer = doc.documentURIObject;
if (channel instanceof Components.interfaces.nsIHttpChannelInternal)
channel.forceAllowThirdPartyCookie = true;
}
@@ -1202,17 +1194,17 @@ nsContextMenu.prototype = {
text = this.link.getAttribute("alt");
if (!text || !text.match(/\S/)) {
if (this.link.href) {
text = this.link.href;
}
else {
text = getAttributeNS("http://www.w3.org/1999/xlink", "href");
if (text && text.match(/\S/)) {
- text = this.makeURLAbsolute(this.link.baseURI, text);
+ text = makeURLAbsolute(this.link.baseURI, text);
}
}
}
}
}
return text;
},
@@ -1278,26 +1270,16 @@ nsContextMenu.prototype = {
return true;
for (var node = this.target; node; node = node.parentNode)
if (node instanceof Components.interfaces.nsIDOMNSHTMLElement)
return node.isContentEditable;
return false;
},
- // Convert relative URL to absolute, using document's <base>.
- makeURLAbsolute: function(aBase, aUrl) {
- // Construct nsIURL.
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var baseURI = ioService.newURI(aBase, null, null);
-
- return ioService.newURI(baseURI.resolve(aUrl), null, null).spec;
- },
-
toString: function() {
return "contextMenu.target = " + this.target + "\n" +
"contextMenu.onImage = " + this.onImage + "\n" +
"contextMenu.onLink = " + this.onLink + "\n" +
"contextMenu.link = " + this.link + "\n" +
"contextMenu.inFrame = " + this.inFrame + "\n" +
"contextMenu.hasBGImage = " + this.hasBGImage + "\n";
},
--- a/suite/common/pref/pref-applications.js
+++ b/suite/common/pref/pref-applications.js
@@ -65,18 +65,16 @@ const nsIPropertyBag = Components.interf
var handlerSvc = Components.classes["@mozilla.org/uriloader/handler-service;1"]
.getService(Components.interfaces.nsIHandlerService);
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2);
var categoryMgr = Components.classes["@mozilla.org/categorymanager;1"]
.getService(Components.interfaces.nsICategoryManager);
var mimeSvc = Components.classes["@mozilla.org/mime;1"]
.getService(Components.interfaces.nsIMIMEService);
-var ioSvc = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
var converterSvc = Components.classes["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"]
.getService(Components.interfaces.nsIWebContentConverterService);
var shellSvc = null;
if ("@mozilla.org/suite/shell-feed-service;1" in Components.classes)
shellSvc = Components.classes["@mozilla.org/suite/shell-feed-service;1"]
.getService(Components.interfaces.nsIShellService);
const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
@@ -1760,25 +1758,25 @@ var gApplicationsPane = {
return this._getIconURLForWebApp(aHandlerApp.uri)
}
// We know nothing about other kinds of handler apps.
return "";
},
_getIconURLForFile: function(aFile) {
- var fph = ioSvc.getProtocolHandler("file")
- .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
+ var fph = Services.io.getProtocolHandler("file")
+ .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
var urlSpec = fph.getURLSpecFromFile(aFile);
return "moz-icon://" + urlSpec + "?size=16";
},
_getIconURLForWebApp: function(aWebAppURITemplate) {
- var uri = ioSvc.newURI(aWebAppURITemplate, null, null);
+ var uri = Services.io.newURI(aWebAppURITemplate, null, null);
// Unfortunately we need to use favicon.ico here, but we don't know
// about any other possibility to retrieve an icon for the web app/site
// without loading a specific full URL and parsing it for a possible
// shortcut icon.
return /^https?/.test(uri.scheme) ? uri.resolve("/favicon.ico") : "";
},
--- a/suite/common/pref/pref-download.js
+++ b/suite/common/pref/pref-download.js
@@ -41,20 +41,18 @@
const kDesktop = 0;
const kDownloads = 1;
const kUserDir = 2;
var gFPHandler;
function Startup()
{
// Define globals
- gFPHandler = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService)
- .getProtocolHandler("file")
- .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
+ gFPHandler = Services.io.getProtocolHandler("file")
+ .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
SetSoundEnabled(document.getElementById("browser.download.finished_download_sound").value);
// if we don't have the alert service, hide the pref UI for using alerts to
// notify on download completion
// see bug #158711
var downloadDoneNotificationAlertUI = document.getElementById("finishedNotificationAlert");
downloadDoneNotificationAlertUI.hidden = !("@mozilla.org/alerts-service;1" in Components.classes);
--- a/suite/common/sidebar/sidebarOverlay.js
+++ b/suite/common/sidebar/sidebarOverlay.js
@@ -865,20 +865,17 @@ function check_for_missing_panels() {
var currHeader;
var currTab;
for (var i = 2; i < tabs.length; i += 2) {
currHeader = tabs[i];
currTab = new sbPanel(currHeader.getAttribute("id"), currHeader, i);
if (!currTab.is_excluded()) {
if (currHeader.hasAttribute("prereq") && currHeader.getAttribute("prereq") != "") {
var prereq_file = currHeader.getAttribute("prereq");
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var uri = ioService.newURI(prereq_file, null, null);
- var channel = ioService.newChannelFromURI(uri);
+ var channel = Services.io.newChannel(prereq_file, null, null);
try {
channel.open();
}
catch(ex if (ex.result == NS_ERROR_FILE_NOT_FOUND)) {
sidebarObj.datasource.Assert(RDF.GetResource(currHeader.getAttribute("id")),
RDF.GetResource(NC + "exclude"),
RDF.GetLiteral(sidebarObj.component),
true);
@@ -935,18 +932,17 @@ function sidebar_revert_to_default_panel
}
return null;
}
function get_sidebar_datasource_uri() {
try {
var sidebar_file = sidebar_get_panels_file();
- var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
+ var fileHandler = Services.io.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
return fileHandler.getURLSpecFromFile(sidebar_file);
} catch (ex) {
// This should not happen
debug("Error: Unable to load panels file.\n");
}
return null;
}
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -965,16 +965,23 @@ function isElementVisible(aElement)
return false;
// If aElement or a direct or indirect parent is hidden or collapsed,
// height, width or both will be 0.
var bo = aElement.boxObject;
return (bo.height > 0 && bo.width > 0);
}
+function makeURLAbsolute(aBase, aUrl)
+{
+ // Construct nsIURL.
+ return Services.io.newURI(aUrl, null,
+ Services.io.newURI(aBase, null, null)).spec;
+}
+
function openAsExternal(aURL)
{
var loadType = Services.prefs.getIntPref("browser.link.open_external");
var loadInBackground = Services.prefs.getBoolPref("browser.tabs.loadDivertedInBackground");
openNewTabWindowOrExistingWith(loadType, aURL, null, loadInBackground);
}
/**