Bug 795158 - Switch to Services.jsm: /editor/ui/: Services.io. r=mconley, r=IanN

This commit is contained in:
Sebastian Hengst 2013-02-05 00:28:55 +01:00
Родитель bf80a3ab89
Коммит 56c20576ac
5 изменённых файлов: 51 добавлений и 111 удалений

Просмотреть файл

@ -748,15 +748,14 @@ function GetSuggestedFileName(aDocumentURLString, aMIMEType)
if (aDocumentURLString && !IsUrlAboutBlank(aDocumentURLString))
{
try {
var ioService = GetIOService();
var docURI = ioService.newURI(aDocumentURLString,
let docURI = Services.io.newURI(aDocumentURLString,
GetCurrentEditor().documentCharacterSet, null);
docURI = docURI.QueryInterface(Components.interfaces.nsIURL);
// grab the file name
var url = validateFileName(decodeURIComponent(docURI.fileBaseName));
let url = validateFileName(decodeURIComponent(docURI.fileBaseName));
if (url)
return url+extension;
return url + extension;
} catch(e) {}
}
@ -805,12 +804,11 @@ function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, aDocumentU
// set the file picker's current directory
// assuming we have information needed (like prior saved location)
try {
var ioService = GetIOService();
var fileHandler = GetFileProtocolHandler();
var isLocalFile = true;
try {
var docURI = ioService.newURI(aDocumentURLString, GetCurrentEditor().documentCharacterSet, null);
let docURI = Services.io.newURI(aDocumentURLString, GetCurrentEditor().documentCharacterSet, null);
isLocalFile = docURI.schemeIs("file");
}
catch (e) {}
@ -1183,7 +1181,7 @@ var gEditorOutputProgressListener =
// Make a new docURI from the "browse location" in case "publish location" was FTP
// We need to set document uri before notifying listeners
var docUrl = GetDocUrlFromPublishData(gPublishData);
SetDocumentURI(GetIOService().newURI(docUrl, editor.documentCharacterSet, null));
SetDocumentURI(Services.io.newURI(docUrl, editor.documentCharacterSet, null));
UpdateWindowTitle();
@ -1684,15 +1682,13 @@ function SaveDocument(aSaveAs, aSaveCopy, aMimeType)
} // mustShowFileDialog
var success = true;
var ioService;
try {
// if somehow we didn't get a local file but we did get a uri,
// attempt to create the localfile if it's a "file" url
var docURI;
if (!tempLocalFile)
{
ioService = GetIOService();
docURI = ioService.newURI(urlstring, editor.documentCharacterSet, null);
docURI = Services.io.newURI(urlstring, editor.documentCharacterSet, null);
if (docURI.schemeIs("file"))
{
@ -1734,8 +1730,7 @@ function SaveDocument(aSaveAs, aSaveCopy, aMimeType)
if (lastSlash != -1)
{
var relatedFilesDirString = urlstring.slice(0, lastSlash + 1); // include last slash
ioService = GetIOService();
relatedFilesDir = ioService.newURI(relatedFilesDirString, editor.documentCharacterSet, null);
relatedFilesDir = Services.io.newURI(relatedFilesDirString, editor.documentCharacterSet, null);
}
}
} catch(e) { relatedFilesDir = null; }
@ -1952,8 +1947,7 @@ function CreateURIFromPublishData(publishData, doDocUri)
else
spec += FormatDirForPublishing(publishData.otherDir);
var ioService = GetIOService();
URI = ioService.newURI(spec, GetCurrentEditor().documentCharacterSet, null);
URI = Services.io.newURI(spec, GetCurrentEditor().documentCharacterSet, null);
if (publishData.username)
URI.username = publishData.username;

Просмотреть файл

@ -118,9 +118,7 @@ function editPage(url, aFileType)
function createURI(urlstring)
{
try {
var ioserv = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return ioserv.newURI(urlstring, null, null);
return Services.io.newURI(urlstring, null, null);
} catch (e) {}
return null;

Просмотреть файл

@ -23,7 +23,6 @@ const kOutputSelectionOnly = Components.interfaces.nsIDocumentEncoder.OutputSele
const kOutputWrap = Components.interfaces.nsIDocumentEncoder.OutputWrap;
var gStringBundle;
var gIOService;
var gFilePickerDirectory;
var gOS = "";
@ -448,21 +447,9 @@ function SetElementEnabled(element, doEnable)
/************* Services / Prefs ***************/
function GetIOService()
{
if (gIOService)
return gIOService;
gIOService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return gIOService;
}
function GetFileProtocolHandler()
{
var ios = GetIOService();
var handler = ios.getProtocolHandler("file");
let handler = Services.io.getProtocolHandler("file");
return handler.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
}
@ -587,10 +574,6 @@ function MakeRelativeUrl(url)
if (docScheme != urlScheme)
return inputUrl;
var IOService = GetIOService();
if (!IOService)
return inputUrl;
// Host must be the same
var docHost = GetHost(docUrl);
var urlHost = GetHost(inputUrl);
@ -600,8 +583,8 @@ function MakeRelativeUrl(url)
// Get just the file path part of the urls
// XXX Should we use GetCurrentEditor().documentCharacterSet for 2nd param ?
var docPath = IOService.newURI(docUrl, GetCurrentEditor().documentCharacterSet, null).path;
var urlPath = IOService.newURI(inputUrl, GetCurrentEditor().documentCharacterSet, null).path;
let docPath = Services.io.newURI(docUrl, GetCurrentEditor().documentCharacterSet, null).path;
let urlPath = Services.io.newURI(inputUrl, GetCurrentEditor().documentCharacterSet, null).path;
// We only return "urlPath", so we can convert
// the entire docPath for case-insensitive comparisons
@ -694,30 +677,26 @@ function MakeRelativeUrl(url)
function MakeAbsoluteUrl(url)
{
var resultUrl = TrimString(url);
let resultUrl = TrimString(url);
if (!resultUrl)
return resultUrl;
// Check if URL is already absolute, i.e., it has a scheme
var urlScheme = GetScheme(resultUrl);
let urlScheme = GetScheme(resultUrl);
if (urlScheme)
return resultUrl;
var docUrl = GetDocumentBaseUrl();
var docScheme = GetScheme(docUrl);
let docUrl = GetDocumentBaseUrl();
let docScheme = GetScheme(docUrl);
// Can't relativize if no doc scheme (page hasn't been saved)
if (!docScheme)
return resultUrl;
var IOService = GetIOService();
if (!IOService)
return resultUrl;
// Make a URI object to use its "resolve" method
var absoluteUrl = resultUrl;
var docUri = IOService.newURI(docUrl, GetCurrentEditor().documentCharacterSet, null);
let absoluteUrl = resultUrl;
let docUri = Services.io.newURI(docUrl, GetCurrentEditor().documentCharacterSet, null);
try {
absoluteUrl = docUri.resolve(resultUrl);
@ -771,14 +750,10 @@ function GetScheme(urlspec)
if (!resultUrl || IsUrlAboutBlank(resultUrl))
return "";
var IOService = GetIOService();
if (!IOService)
return "";
var scheme = "";
try {
// This fails if there's no scheme
scheme = IOService.extractScheme(resultUrl);
scheme = Services.io.extractScheme(resultUrl);
} catch (e) {}
return scheme ? scheme.toLowerCase() : "";
@ -789,13 +764,9 @@ function GetHost(urlspec)
if (!urlspec)
return "";
var IOService = GetIOService();
if (!IOService)
return "";
var host = "";
try {
host = IOService.newURI(urlspec, null, null).host;
host = Services.io.newURI(urlspec, null, null).host;
} catch (e) {}
return host;
@ -806,13 +777,9 @@ function GetUsername(urlspec)
if (!urlspec)
return "";
var IOService = GetIOService();
if (!IOService)
return "";
var username = "";
try {
username = IOService.newURI(urlspec, null, null).username;
username = Services.io.newURI(urlspec, null, null).username;
} catch (e) {}
return username;
@ -823,17 +790,13 @@ function GetFilename(urlspec)
if (!urlspec || IsUrlAboutBlank(urlspec))
return "";
var IOService = GetIOService();
if (!IOService)
return "";
var filename;
try {
var uri = IOService.newURI(urlspec, null, null);
let uri = Services.io.newURI(urlspec, null, null);
if (uri)
{
var url = uri.QueryInterface(Components.interfaces.nsIURL);
let url = uri.QueryInterface(Components.interfaces.nsIURL);
if (url)
filename = url.fileName;
}
@ -861,13 +824,9 @@ function StripUsernamePassword(urlspec, usernameObj, passwordObj)
if (atIndex > 0)
{
try {
var IOService = GetIOService();
if (!IOService)
return urlspec;
var uri = IOService.newURI(urlspec, null, null);
var username = uri.username;
var password = uri.password;
let uri = Services.io.newURI(urlspec, null, null);
let username = uri.username;
let password = uri.password;
if (usernameObj && username)
usernameObj.value = username;
@ -875,7 +834,7 @@ function StripUsernamePassword(urlspec, usernameObj, passwordObj)
passwordObj.value = password;
if (username)
{
var usernameStart = urlspec.indexOf(username);
let usernameStart = urlspec.indexOf(username);
if (usernameStart != -1)
return urlspec.slice(0, usernameStart) + urlspec.slice(atIndex+1);
}
@ -898,18 +857,14 @@ function StripPassword(urlspec, passwordObj)
if (atIndex > 0)
{
try {
var IOService = GetIOService();
if (!IOService)
return urlspec;
var password = IOService.newURI(urlspec, null, null).password;
let password = Services.io.newURI(urlspec, null, null).password;
if (passwordObj && password)
passwordObj.value = password;
if (password)
{
// Find last ":" before "@"
var colon = urlspec.lastIndexOf(":", atIndex);
let colon = urlspec.lastIndexOf(":", atIndex);
if (colon != -1)
{
// Include the "@"
@ -946,8 +901,7 @@ function InsertUsernameIntoUrl(urlspec, username)
return urlspec;
try {
var ioService = GetIOService();
var URI = ioService.newURI(urlspec, GetCurrentEditor().documentCharacterSet, null);
let URI = Services.io.newURI(urlspec, GetCurrentEditor().documentCharacterSet, null);
URI.username = username;
return URI.spec;
} catch (e) {}

Просмотреть файл

@ -879,9 +879,7 @@ function GetUrlForPasswordManager(publishData)
if (!publishData || !publishData.publishUrl)
return false;
var url = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(publishData.publishUrl, null, null);
let url = Services.io.newURI(publishData.publishUrl, null, null);
if (url.scheme == "ftp" && publishData.username)
// Include username in the URL so we can handle multiple users per server

Просмотреть файл

@ -3,11 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
Note: We encourage non-empty alt text for images inserted into a page.
Note: We encourage non-empty alt text for images inserted into a page.
When there's no alt text, we always write 'alt=""' as the attribute, since "alt" is a required attribute.
We allow users to not have alt text by checking a "Don't use alterate text" radio button,
and we don't accept spaces as valid alt text. A space used to be required to avoid the error message
if user didn't enter alt text, but is unnecessary now that we no longer annoy the user
if user didn't enter alt text, but is unnecessary now that we no longer annoy the user
with the error dialog if alt="" is present on an img element.
We trim all spaces at the beginning and end of user's alt text
*/
@ -288,24 +288,20 @@ function LoadPreviewImage()
// Remove the image URL from image cache so it loads fresh
// (if we don't do this, loads after the first will always use image cache
// and we won't see image edit changes or be able to get actual width and height)
var IOService = GetIOService();
if (IOService)
// We must have an absolute URL to preview it or remove it from the cache
imageSrc = MakeAbsoluteUrl(imageSrc);
if (GetScheme(imageSrc))
{
// We must have an absolute URL to preview it or remove it from the cache
imageSrc = MakeAbsoluteUrl(imageSrc);
if (GetScheme(imageSrc))
let uri = Services.io.newURI(imageSrc, null, null);
if (uri)
{
var uri = IOService.newURI(imageSrc, null, null);
if (uri)
{
var imgCacheService = Components.classes["@mozilla.org/image/cache;1"].getService();
var imgCache = imgCacheService.QueryInterface(Components.interfaces.imgICache);
let imgCacheService = Components.classes["@mozilla.org/image/cache;1"].getService();
let imgCache = imgCacheService.QueryInterface(Components.interfaces.imgICache);
// This returns error if image wasn't in the cache; ignore that
imgCache.removeEntry(uri);
}
// This returns error if image wasn't in the cache; ignore that
imgCache.removeEntry(uri);
}
}
} catch(e) {}
@ -315,7 +311,7 @@ function LoadPreviewImage()
if (gDialog.ImageHolder.firstChild)
gDialog.ImageHolder.removeChild(gDialog.ImageHolder.firstChild);
gDialog.PreviewImage = document.createElementNS("http://www.w3.org/1999/xhtml", "html:img");
if (gDialog.PreviewImage)
{
@ -516,12 +512,12 @@ function ValidateImage()
if (!gDialog.actualSizeRadio.selected)
{
// Get user values for width and height
width = ValidateNumber(gDialog.widthInput, gDialog.widthUnitsMenulist, 1, gMaxPixels,
width = ValidateNumber(gDialog.widthInput, gDialog.widthUnitsMenulist, 1, gMaxPixels,
globalElement, "width", false, true);
if (gValidationError)
return false;
height = ValidateNumber(gDialog.heightInput, gDialog.heightUnitsMenulist, 1, gMaxPixels,
height = ValidateNumber(gDialog.heightInput, gDialog.heightUnitsMenulist, 1, gMaxPixels,
globalElement, "height", false, true);
if (gValidationError)
return false;
@ -544,23 +540,23 @@ function ValidateImage()
if (height)
editor.setAttributeOrEquivalent(globalElement, "height", height, true);
else if (srcChanged)
else if (srcChanged)
editor.removeAttributeOrEquivalent(globalElement, "height", true);
// spacing attributes
gValidateTab = gDialog.tabBorder;
ValidateNumber(gDialog.imagelrInput, null, 0, gMaxPixels,
ValidateNumber(gDialog.imagelrInput, null, 0, gMaxPixels,
globalElement, "hspace", false, true, true);
if (gValidationError)
return false;
ValidateNumber(gDialog.imagetbInput, null, 0, gMaxPixels,
ValidateNumber(gDialog.imagetbInput, null, 0, gMaxPixels,
globalElement, "vspace", false, true);
if (gValidationError)
return false;
// note this is deprecated and should be converted to stylesheets
ValidateNumber(gDialog.border, null, 0, gMaxPixels,
ValidateNumber(gDialog.border, null, 0, gMaxPixels,
globalElement, "border", false, true);
if (gValidationError)
return false;