diff --git a/browser/installer/unix/packages-static b/browser/installer/unix/packages-static index 19aad40731b..4001674b913 100644 --- a/browser/installer/unix/packages-static +++ b/browser/installer/unix/packages-static @@ -243,7 +243,6 @@ bin/components/nsDefaultCLH.js bin/components/nsContentPrefService.js bin/components/nsContentDispatchChooser.js bin/components/nsHandlerService.js -bin/components/nsScriptableIO.js bin/components/nsWebHandlerApp.js bin/components/libdbusservice.so diff --git a/browser/installer/windows/packages-static b/browser/installer/windows/packages-static index d9edee3286b..b4762722795 100644 --- a/browser/installer/windows/packages-static +++ b/browser/installer/windows/packages-static @@ -240,7 +240,6 @@ bin\components\nsDefaultCLH.js bin\components\nsContentPrefService.js bin\components\nsContentDispatchChooser.js bin\components\nsHandlerService.js -bin\components\nsScriptableIO.js bin\components\nsWebHandlerApp.js ; Modules diff --git a/netwerk/base/public/Makefile.in b/netwerk/base/public/Makefile.in index e4912f8ed16..7ec08571567 100644 --- a/netwerk/base/public/Makefile.in +++ b/netwerk/base/public/Makefile.in @@ -126,7 +126,6 @@ XPIDLSRCS = \ nsIChannelEventSink.idl \ nsINetUtil.idl \ nsIProxiedChannel.idl \ - nsIScriptableIO.idl \ nsIRandomGenerator.idl \ $(NULL) diff --git a/netwerk/base/public/nsIScriptableIO.idl b/netwerk/base/public/nsIScriptableIO.idl deleted file mode 100644 index 6a1c4c95004..00000000000 --- a/netwerk/base/public/nsIScriptableIO.idl +++ /dev/null @@ -1,244 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Scriptable IO. - * - * The Initial Developer of the Original Code is Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2007 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Neil Deakin (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -interface nsIVariant; -interface nsIFile; -interface nsIInputStream; -interface nsIOutputStream; -interface nsIUnicharInputStream; -interface nsIUnicharOutputStream; -interface nsIURI; - -/** - * A singleton object which contains a number of methods for creating files, - * streams and uris. - * - * This interface is intended to be used only from script. - */ -[scriptable, uuid(E54798D5-7693-43F9-9BB6-F21E434DD3FC)] -interface nsIScriptableIO : nsISupports -{ - /** - * Retrieves a reference to a file or directory on disk, which may or may - * not exist. If the file exists, it may be opened for reading by passing - * the file as the base to newInputStream. If it doesn't exist, it may be - * created by opening an output stream and writing to it. - * - * Files are identified by the filename argument. The file is found relative - * to a well known directory identified by the location argument. This - * location is a string key which identifies common directories typically - * found on a system. For instance, using the location key 'Desk' will - * retrieve files in the desktop folder, and the location key 'TmpD' will - * retrieve files in the system's temporary directory. - * - * A complete list of location keys may be found at - * http://developer.mozilla.org/en/docs/IO_Guide/Directory_Keys - * - * The filename is always a file within the directory identified by the - * location key and this does not include a path. To retrieve - * subdirectories, retrieve a file and then use the file's append method - * to navigate into further subdirectories. This allows platform independent - * paths to be constructed. - * - * The filename may be a null string to retrieve a reference to the - * location directory itself. - * - * @param aLocation location key of well-known directory - * @param aFileName filename to locate within this directory, may be null - * @returns a file object - * @throws NS_ERROR_INVALID_ARG when aLocation is null - */ - nsIFile getFile(in AString aLocation, in AString aFileName); - - /** - * Retrieves a reference to a file given a absolute file path. - * - * Use this method only when absolutely necessary. In most cases, getFile - * should be used instead, as file paths are not portable across different - * platforms and systems so this method should be avoided if possible. - * Instead, the getFile method should be used and a path constructed from - * it. - * - * The filepath should be an absolute path or the value of the - * persistentDescriptor of a file. - * - * @param aFilePath path to the file - * @returns a file object - * @throws NS_ERROR_INVALID_ARG when aFilePath is null - */ - nsIFile getFileWithPath(in AString aFilePath); - - /** - * Creates a URI object which implements nsIURI. The url argument may either - * be a string or a file. - * - * @param aUri the url to create - * @returns a new nsIURI object - * @throws NS_ERROR_INVALID_ARG when aUri is null - */ - nsIURI newURI(in nsIVariant aUri); - - /** - * Retrieves a stream which may be read from. - * - * The base argument may be one of a number of different types of objects - * which may be read from: - * nsIFile - an object returned from the getFile or getFileWithPath - * methods, or any object which implements the nsIFile - * interface. - * nsITransport - a transport object such as a socket. - * nsIInputStream - a stream returned by a previous call to this method or - * any other object which implements the nsIInputStream - * interface. - * string - a string - * - * The mode may be any number of space separated strings which control - * the manner is which the stream is created. If no strings apply, use - * a null string. Possible values are: - * text - read unicode converted text. The default character set is UTF-8. - * To read text in a different character set, set the aCharSet - * argument to the desired character set. - * buffered - a stream which uses a buffer to hold a block of the next - * part of the data to read. This mode would normally be used - * as a wrapper for other streams. The size of the buffer - * defaults to 1024 bytes, however the size may be changed by - * specifying the aBufferSize argument. If the text mode is - * used, the stream is always buffered. - * block - when reading from a transport such as a socket, an attempt to - * read from the stream while there is no data available will wait - * until data is available before returning. Without this mode, - * the stream will throw an exception if there is no data - * available. - * deleteonclose - the file is automatically deleted when the stream is - * closed. This might be used for temporary files. - * closeoneof - the file is automatically closed when the end of the file - * is reached. - * reopenonrewind - used in conjuction with the seek mode, the file will - * be reopened when a seek to the beginning of the file - * is done. - * multi - a stream which is used to concatenate the input from multiple - * streams together as if it was one long continuous stream. The - * returned stream implements the nsIMultiplexInputStream - * interface. This mode may only be used if the text or buffered - * modes are not used. - * - * If the mode is a null string, then no special type of reading is - * performed. In this case, the data from the stream is not interpreted in - * any way. - * - * @param aBase the base object to read from - * @param aMode flags controlling the reading - * @param aCharSet the character set to use when parsing text streams - * @param aReplaceChar the replacement character for unknown characters - * @param aBufferSize the size of buffer to use for buffered streams - * @returns a new input stream - * @throws NS_ERROR_INVALID_ARG when aBase is null - */ - nsISupports newInputStream(in nsIVariant aBase, - in AString aMode, - [optional] in AString aCharSet, - [optional] in AString aReplaceChar, - [optional] in unsigned long aBufferSize); - - /** - * Retrieves a stream which may be written to. - * - * The base argument may be one of a number of different types of objects - * which may be written to: - * nsIFile - an object returned from the getFile or getFileWithPath - * methods, or any object which implements the nsIFile - * interface. - * nsITransport - a transport object such as a socket. - * nsIOutputStream - a stream returned by a previous call to this method - * or any other object which implements the - * nsIOutputStream interface. - * string - a string - * - * The mode may be any number of space separated strings which control - * the manner is which the stream is created. If no strings apply, use - * a null string. Possible values are: - * text - write unicode converted text. The default character set is - * UTF-8. To write text in a different character set, set the - * aCharSet argument to the desired character set. - * buffered - a stream which buffers the data being written, which would - * normally be used as a wrapper for other streams. The size of - * the buffer defaults to 1024 bytes, however the size may be - * changed by specifying the aBufferSize argument. If the text - * mode is used, the stream is always buffered. - * append - when writing to files, append to the end of the file instead - * of overwriting. If used in conjuction with the create mode, an - * existing file may be opened for appending, or a new file - * created. - * nocreate - when writing to files, and the file does not yet exist, - * don't create a new file. If this mode is not used, a - * new file will be created if it doesn't exist. - * notruncate - when writing to an existing file, overwrite the existing - * content. If this mode is not used, the file will be - * truncated to 0 length. - * syncsave - if used, then writing methods do not return until the - * data is properly saved. - * block - when writing to a transport such as a socket, an attempt - * to write to the stream will not return until all of the - * data has been written. This may cause a delay if the - * socket's underlying buffer is full. If this mode is not used, - * then an exception will be thrown if the buffer is full. - * - * If the mode is a null string, then no special type of writing is - * performed. In this case, the data being written to the stream is not - * interpreted in any way. - * - * The permissions may be set if a file is created. Typically, an octal - * value is used, for example: 0775. The default value when calling - * newOutputStream is 0664. - * - * @param aBase the base object to write to - * @param aMode flags controlling the writing - * @param aCharSet the character set to use when writing text streams - * @param aReplaceChar the replacement character for unknown characters - * @param aBufferSize the size of buffer to use for buffered streams - * @param aPermissions permissions of a file if one is created. - * @returns a new output stream - * @throws NS_ERROR_INVALID_ARG when aBase is null - */ - nsISupports newOutputStream(in nsIVariant aBase, - in AString aMode, - [optional] in AString aCharSet, - [optional] in AString aReplaceChar, - [optional] in unsigned long aBufferSize, - [optional] in unsigned long aPermissions); -}; diff --git a/netwerk/base/src/Makefile.in b/netwerk/base/src/Makefile.in index 94dc772e32d..14d0fa89dda 100644 --- a/netwerk/base/src/Makefile.in +++ b/netwerk/base/src/Makefile.in @@ -114,7 +114,6 @@ endif EXTRA_COMPONENTS = \ $(srcdir)/nsProxyAutoConfig.js \ - $(srcdir)/nsScriptableIO.js \ $(NULL) # we don't want the shared lib, but we want to force the creation of a diff --git a/netwerk/base/src/nsScriptableIO.js b/netwerk/base/src/nsScriptableIO.js deleted file mode 100644 index 90c094d869f..00000000000 --- a/netwerk/base/src/nsScriptableIO.js +++ /dev/null @@ -1,377 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Scriptable IO. - * - * The Initial Developer of the Original Code is Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2007 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Neil Deakin (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const SCRIPTABLEIO_CLASS_ID = Components.ID("1EDB3B94-0E2E-419A-8C2B-D9E232D41086"); -const SCRIPTABLEIO_CLASS_NAME = "Scriptable IO"; -const SCRIPTABLEIO_CONTRACT_ID = "@mozilla.org/io/scriptable-io;1"; - -const DEFAULT_BUFFER_SIZE = 1024; -const DEFAULT_PERMISSIONS = 0644; - -const Cc = Components.classes; -const Ci = Components.interfaces; - -var gScriptableIO = null; - -// when using the directory service, map some extra keys that are -// easier to understand for common directories -var mappedDirKeys = { - Application: "resource:app", - Working: "CurWorkD", - Profile: "ProfD", - Desktop: "Desk", - Components: "ComsD", - Temp: "TmpD" -}; - -function ScriptableIO() { -} - -ScriptableIO.prototype = -{ - _wrapBaseWithInputStream : function ScriptableIO_wrapBaseWithInputStream - (base, modes, permissions) - { - var stream; - if (base instanceof Ci.nsIFile) { - var behaviour = 0; - if (modes["deleteonclose"]) - behaviour |= Ci.nsIFileInputStream.DELETE_ON_CLOSE; - if (modes["closeoneof"]) - behaviour |= Ci.nsIFileInputStream.CLOSE_ON_EOF; - if (modes["reopenonrewind"]) - behaviour |= Ci.nsIFileInputStream.REOPEN_ON_REWIND; - - stream = Cc["@mozilla.org/network/file-input-stream;1"]. - createInstance(Ci.nsIFileInputStream); - stream.init(base, 1, permissions, behaviour); - } - else if (base instanceof Ci.nsITransport) { - var flags = modes["block"] ? Ci.nsITransport.OPEN_BLOCKING : 0; - stream = base.openInputStream(flags, buffersize, 0); - } - else if (base instanceof Ci.nsIInputStream) { - stream = base; - } - else if (typeof base == "string") { - stream = Cc["@mozilla.org/io/string-input-stream;1"]. - createInstance(Ci.nsIStringInputStream); - stream.setData(base, base.length); - } - if (!stream) - throw "Cannot create input stream from base"; - - return stream; - }, - - _wrapBaseWithOutputStream : function ScriptableIO_wrapBaseWithOutputStream - (base, modes, permissions) - { - var stream; - if (base instanceof Ci.nsIFile) { - stream = Cc["@mozilla.org/network/file-output-stream;1"]. - createInstance(Ci.nsIFileOutputStream); - - // default for writing is 'write create truncate' - var modeFlags = 42; - if (modes["nocreate"]) - modeFlags ^= 8; - if (modes["append"]) - modeFlags |= 16; - if (modes["notruncate"]) - modeFlags ^= 32; - if (modes["syncsave"]) - modeFlags |= 64; - - stream.init(base, modeFlags, permissions, 0); - } - else if (base instanceof Ci.nsITransport) { - var flags = modes["block"] ? Ci.nsITransport.OPEN_BLOCKING : 0; - stream = base.openOutputStream(flags, buffersize, 0); - } - else if (base instanceof Ci.nsIInputStream) { - stream = base; - } - if (!stream) - throw "Cannot create output stream from base"; - - return stream; - }, - - _openForReading : function ScriptableIO_openForReading - (base, modes, buffersize, charset, replchar) - { - var stream = base; - var charstream = null; - if (modes["text"]) { - if (!charset) - charset = "UTF-8"; - if (!replchar) - replchar = Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER; - - charstream = Cc["@mozilla.org/intl/converter-input-stream;1"]. - createInstance(Ci.nsIConverterInputStream); - charstream.init(base, charset, buffersize, replchar); - } - else if (modes["buffered"]) { - stream = Cc["@mozilla.org/network/buffered-input-stream;1"]. - createInstance(Ci.nsIBufferedInputStream); - stream.init(base, buffersize); - } - else if (modes["multi"]) { - stream = Cc["@mozilla.org/io/multiplex-input-stream;1"]. - createInstance(Ci.nsIMultiplexInputStream); - stream.appendStream(base); - } - - // wrap the stream in a scriptable stream - var sstream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(); - sstream.initWithStreams(stream, charstream); - return sstream; - }, - - _openForWriting : function ScriptableIO_openForWriting - (base, modes, buffersize, charset, replchar) - { - var stream = base; - var charstream = null; - if (modes["text"]) { - if (!charset) - charset = "UTF-8"; - if (!replchar) - replchar = Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER; - - charstream = Cc["@mozilla.org/intl/converter-output-stream;1"]. - createInstance(Ci.nsIConverterOutputStream); - charstream.init(base, charset, buffersize, replchar); - } - else if (modes["buffered"]) { - stream = Cc["@mozilla.org/network/buffered-output-stream;1"]. - createInstance(Ci.nsIBufferedOutputStream); - stream.init(base, buffersize); - } - - // wrap the stream in a scriptable stream - var sstream = Cc["@mozilla.org/scriptableoutputstream;1"].createInstance(); - sstream.initWithStreams(stream, charstream); - return sstream; - }, - - getFile : function ScriptableIO_getFile(location, file) - { - if (!location) - throw Components.results.NS_ERROR_INVALID_ARG; - - if (location in mappedDirKeys) - location = mappedDirKeys[location]; - - var ds = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties); - var fl = ds.get(location, Ci.nsILocalFile); - if (file) - fl.append(file); - return fl; - }, - - getFileWithPath : function ScriptableIO_getFileWithPath(filepath) - { - if (!filepath) - throw Components.results.NS_ERROR_INVALID_ARG; - - // XXXndeakin not sure if setting persistentDescriptor is best here, but - // it's more useful than initWithPath, for instance, for preferences - var fl = Cc["@mozilla.org/file/local;1"].createInstance(); - fl.persistentDescriptor = filepath; - return fl; - }, - - newURI : function ScriptableIO_newURI(uri) - { - if (!uri) - throw Components.results.NS_ERROR_INVALID_ARG; - - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - if (uri instanceof Ci.nsIFile) - return ios.newFileURI(uri); - return ios.newURI(uri, "", null); - }, - - newInputStream : function ScriptableIO_newInputStream - (base, mode, charset, replchar, buffersize) - { - return this._newStream(base, mode, charset, replchar, buffersize, - DEFAULT_PERMISSIONS, false); - }, - - newOutputStream : function ScriptableIO_newOutputStream - (base, mode, charset, replchar, buffersize, permissions) - { - return this._newStream(base, mode, charset, replchar, buffersize, - permissions, true); - }, - - _newStream : function ScriptableIO_newStream - (base, mode, charset, replchar, buffersize, permissions, iswrite) - { - if (!base) - throw Components.results.NS_ERROR_INVALID_ARG; - - var modes = {}; - var modeArr = mode.split(/\s+/); - for (var m = 0; m < modeArr.length; m++) { - modes[modeArr[m]] = true; - } - - if (!buffersize) - buffersize = DEFAULT_BUFFER_SIZE; - - var stream; - if (iswrite) { - base = this._wrapBaseWithOutputStream(base, modes, permissions); - stream = this._openForWriting(base, modes, buffersize, charset, replchar); - } - else { - base = this._wrapBaseWithInputStream(base, modes, permissions); - stream = this._openForReading(base, modes, buffersize, charset, replchar); - } - - if (!stream) - throw "Cannot create stream from base"; - - return stream; - }, - - // nsIClassInfo - classDescription : "IO", - classID : SCRIPTABLEIO_CLASS_ID, - contractID : SCRIPTABLEIO_CONTRACT_ID, - flags : Ci.nsIClassInfo.SINGLETON, - implementationLanguage : Ci.nsIProgrammingLanguage.JAVASCRIPT, - - getInterfaces : function ScriptableIO_getInterfaces(aCount) { - var interfaces = [Ci.nsIScriptableIO, Ci.nsIClassInfo]; - aCount.value = interfaces.length; - return interfaces; - }, - - getHelperForLanguage : function ScriptableIO_getHelperForLanguage(aCount) { - return null; - }, - - QueryInterface: function ScriptableIO_QueryInterface(aIID) { - if (aIID.equals(Ci.nsIScriptableIO) || - aIID.equals(Ci.nsIClassInfo) || - aIID.equals(Ci.nsISupports)) - return this; - throw Components.results.NS_ERROR_NO_INTERFACE; - } -} - -var ScriptableIOFactory = { - QueryInterface: function ScriptableIOFactory_QueryInterface(iid) - { - if (iid.equals(Ci.nsIFactory) || - iid.equals(Ci.nsISupports)) - return this; - throw Cr.NS_ERROR_NO_INTERFACE; - }, - - createInstance: function ScriptableIOFactory_createInstance(aOuter, aIID) - { - if (aOuter != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - if (gScriptableIO == null) - gScriptableIO = new ScriptableIO(); - - return gScriptableIO.QueryInterface(aIID); - } -}; - -var ScriptableIOModule = { - QueryInterface: function ScriptableIOModule_QueryInterface(iid) { - if (iid.equals(Ci.nsIModule) || - iid.equals(Ci.nsISupports)) - return this; - throw Cr.NS_ERROR_NO_INTERFACE; - }, - - registerSelf: function ScriptableIOModule_registerSelf(aCompMgr, aFileSpec, aLocation, aType) - { - aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar); - aCompMgr.registerFactoryLocation(SCRIPTABLEIO_CLASS_ID, - SCRIPTABLEIO_CLASS_NAME, - SCRIPTABLEIO_CONTRACT_ID, - aFileSpec, aLocation, aType); - - var categoryManager = Cc["@mozilla.org/categorymanager;1"]. - getService(Ci.nsICategoryManager); - - categoryManager.addCategoryEntry("JavaScript global privileged property", "IO", - SCRIPTABLEIO_CONTRACT_ID, true, true); - }, - - unregisterSelf: function ScriptableIOModule_unregisterSelf(aCompMgr, aLocation, aType) - { - aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar); - aCompMgr.unregisterFactoryLocation(SCRIPTABLEIO_CLASS_ID, aLocation); - - var categoryManager = Cc["@mozilla.org/categorymanager;1"]. - getService(Ci.nsICategoryManager); - categoryManager.deleteCategoryEntry("JavaScript global privileged property", - SCRIPTABLEIO_CONTRACT_ID, true); - }, - - getClassObject: function ScriptableIOModule_getClassObject(aCompMgr, aCID, aIID) - { - if (!aIID.equals(Ci.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - if (aCID.equals(SCRIPTABLEIO_CLASS_ID)) - return ScriptableIOFactory; - - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - canUnload: function ScriptableIOModule_canUnload(aCompMgr) - { - gScriptableIO = null; - return true; - } -}; - -function NSGetModule(aCompMgr, aFileSpec) { return ScriptableIOModule; } diff --git a/netwerk/test/Makefile.in b/netwerk/test/Makefile.in index 4bed252e4a4..f19e5dfc592 100644 --- a/netwerk/test/Makefile.in +++ b/netwerk/test/Makefile.in @@ -46,7 +46,6 @@ include $(DEPTH)/config/autoconf.mk MODULE = test_necko DIRS = \ - chrome \ httpserver \ $(NULL) diff --git a/netwerk/test/chrome/Makefile.in b/netwerk/test/chrome/Makefile.in deleted file mode 100644 index 256fd75edaa..00000000000 --- a/netwerk/test/chrome/Makefile.in +++ /dev/null @@ -1,51 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Mozilla Foundation. -# Portions created by the Initial Developer are Copyright (C) 2007 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = network/test/chrome - -include $(DEPTH)/config/autoconf.mk -include $(topsrcdir)/config/rules.mk - -_TEST_FILES = test_scriptableio.xul \ - $(NULL) - -libs:: $(_TEST_FILES) - $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir) diff --git a/netwerk/test/chrome/test_scriptableio.xul b/netwerk/test/chrome/test_scriptableio.xul deleted file mode 100644 index cd7e4a36d12..00000000000 --- a/netwerk/test/chrome/test_scriptableio.xul +++ /dev/null @@ -1,470 +0,0 @@ - - - - - - - - - diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index bde618808c9..de773b861bd 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -51,7 +51,6 @@ #include "nsIProperties.h" #include "nsPersistentProperties.h" #include "nsScriptableInputStream.h" -#include "nsScriptableOutputStream.h" #include "nsBinaryStream.h" #include "nsStorageStream.h" #include "nsPipe.h" @@ -245,9 +244,6 @@ NS_DECL_CLASSINFO(nsThreadManager) NS_GENERIC_FACTORY_CONSTRUCTOR(nsThreadPool) NS_DECL_CLASSINFO(nsThreadPool) -NS_DECL_CLASSINFO(nsScriptableInputStream) -NS_DECL_CLASSINFO(nsScriptableOutputStream) - static NS_METHOD nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer, const nsIID& aIID, @@ -355,10 +351,7 @@ static const nsModuleComponentInfo components[] = { COMPONENT(ERRORSERVICE, nsErrorService::Create), COMPONENT(BYTEBUFFER, ByteBufferImpl::Create), - COMPONENT_CI(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create, - nsScriptableInputStream), - COMPONENT_CI(SCRIPTABLEOUTPUTSTREAM, nsScriptableOutputStream::Create, - nsScriptableOutputStream), + COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create), COMPONENT(BINARYINPUTSTREAM, nsBinaryInputStreamConstructor), COMPONENT(BINARYOUTPUTSTREAM, nsBinaryOutputStreamConstructor), COMPONENT(STORAGESTREAM, nsStorageStreamConstructor), diff --git a/xpcom/io/Makefile.in b/xpcom/io/Makefile.in index 20812e6de01..875da21f87f 100644 --- a/xpcom/io/Makefile.in +++ b/xpcom/io/Makefile.in @@ -73,7 +73,6 @@ CPPSRCS = \ nsPipe3.cpp \ nsStreamUtils.cpp \ nsScriptableInputStream.cpp \ - nsScriptableOutputStream.cpp \ nsSegmentedBuffer.cpp \ SpecialSystemDirectory.cpp \ nsStorageStream.cpp \ @@ -174,7 +173,6 @@ SDK_XPIDLSRCS = \ nsIInputStream.idl \ nsIOutputStream.idl \ nsIScriptableInputStream.idl \ - nsIScriptableStreams.idl \ $(NULL) SDK_HEADERS = \ diff --git a/xpcom/io/nsLocalFileOS2.cpp b/xpcom/io/nsLocalFileOS2.cpp index afba5f6e382..e6d29bb7700 100644 --- a/xpcom/io/nsLocalFileOS2.cpp +++ b/xpcom/io/nsLocalFileOS2.cpp @@ -51,7 +51,6 @@ #include "nsISimpleEnumerator.h" #include "nsIDirectoryEnumerator.h" #include "nsIComponentManager.h" -#include "nsIProgrammingLanguage.h" #include "prtypes.h" #include "prio.h" @@ -616,22 +615,11 @@ nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* // nsLocalFile::nsISupports //----------------------------------------------------------------------------- -NS_IMPL_THREADSAFE_ADDREF(nsLocalFile) -NS_IMPL_THREADSAFE_RELEASE(nsLocalFile) -NS_IMPL_QUERY_INTERFACE5_CI(nsLocalFile, - nsILocalFile, - nsIFile, - nsILocalFileOS2, - nsIHashable, - nsIClassInfo) -NS_IMPL_CI_INTERFACE_GETTER4(nsLocalFile, - nsILocalFile, - nsIFile, - nsILocalFileOS2, - nsIHashable) - -NS_DECL_CLASSINFO(nsLocalFile) -NS_IMPL_THREADSAFE_CI(nsLocalFile) +NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile, + nsILocalFile, + nsIFile, + nsILocalFileOS2, + nsIHashable) //----------------------------------------------------------------------------- diff --git a/xpcom/io/nsLocalFileOS2.h b/xpcom/io/nsLocalFileOS2.h index a93dc206d8f..a39390377bb 100644 --- a/xpcom/io/nsLocalFileOS2.h +++ b/xpcom/io/nsLocalFileOS2.h @@ -73,9 +73,7 @@ class TypeEaEnumerator; class NS_COM nsLocalFile : public nsILocalFileOS2, - public nsIHashable, - public nsIClassInfo - + public nsIHashable { public: NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID) @@ -99,9 +97,6 @@ public: // nsIHashable interface NS_DECL_NSIHASHABLE - // nsIClassInfo interface - NS_DECL_NSICLASSINFO - public: static void GlobalInit(); static void GlobalShutdown(); diff --git a/xpcom/io/nsLocalFileOSX.cpp b/xpcom/io/nsLocalFileOSX.cpp index b4744a95cff..e57268b9864 100644 --- a/xpcom/io/nsLocalFileOSX.cpp +++ b/xpcom/io/nsLocalFileOSX.cpp @@ -48,8 +48,6 @@ #include "nsISimpleEnumerator.h" #include "nsITimelineService.h" #include "nsVoidArray.h" -#include "nsIClassInfoImpl.h" -#include "nsIProgrammingLanguage.h" #include "plbase64.h" #include "prmem.h" @@ -347,23 +345,12 @@ nsLocalFile::~nsLocalFile() #pragma mark - #pragma mark [nsISupports] -NS_IMPL_THREADSAFE_ADDREF(nsLocalFile) -NS_IMPL_THREADSAFE_RELEASE(nsLocalFile) -NS_IMPL_QUERY_INTERFACE5_CI(nsLocalFile, - nsILocalFileMac, - nsILocalFile, - nsIFile, - nsIHashable, - nsIClassInfo) -NS_IMPL_CI_INTERFACE_GETTER4(nsLocalFile, - nsILocalFileMac, - nsILocalFile, - nsIFile, - nsIHashable) - -NS_DECL_CLASSINFO(nsLocalFile) -NS_IMPL_THREADSAFE_CI(nsLocalFile) - +NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile, + nsILocalFileMac, + nsILocalFile, + nsIFile, + nsIHashable) + NS_METHOD nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) { NS_ENSURE_ARG_POINTER(aInstancePtr); diff --git a/xpcom/io/nsLocalFileOSX.h b/xpcom/io/nsLocalFileOSX.h index cea10712d6c..bba0550755f 100644 --- a/xpcom/io/nsLocalFileOSX.h +++ b/xpcom/io/nsLocalFileOSX.h @@ -58,8 +58,7 @@ class nsDirEnumerator; //***************************************************************************** class NS_COM nsLocalFile : public nsILocalFileMac, - public nsIHashable, - public nsIClassInfo + public nsIHashable { friend class nsDirEnumerator; @@ -75,7 +74,6 @@ public: NS_DECL_NSILOCALFILE NS_DECL_NSILOCALFILEMAC NS_DECL_NSIHASHABLE - NS_DECL_NSICLASSINFO public: diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index f1ec275e50f..99f52a665f5 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -81,7 +81,6 @@ #include "nsIDirectoryEnumerator.h" #include "nsISimpleEnumerator.h" #include "nsITimelineService.h" -#include "nsIProgrammingLanguage.h" #ifdef MOZ_WIDGET_GTK2 #include "nsIGnomeVFSService.h" @@ -258,20 +257,10 @@ nsLocalFile::nsLocalFile(const nsLocalFile& other) { } -NS_IMPL_THREADSAFE_ADDREF(nsLocalFile) -NS_IMPL_THREADSAFE_RELEASE(nsLocalFile) -NS_IMPL_QUERY_INTERFACE4_CI(nsLocalFile, - nsILocalFile, - nsIFile, - nsIHashable, - nsIClassInfo) -NS_IMPL_CI_INTERFACE_GETTER3(nsLocalFile, - nsILocalFile, - nsIFile, - nsIHashable) - -NS_DECL_CLASSINFO(nsLocalFile) -NS_IMPL_THREADSAFE_CI(nsLocalFile) +NS_IMPL_THREADSAFE_ISUPPORTS3(nsLocalFile, + nsIFile, + nsILocalFile, + nsIHashable) nsresult nsLocalFile::nsLocalFileConstructor(nsISupports *outer, diff --git a/xpcom/io/nsLocalFileUnix.h b/xpcom/io/nsLocalFileUnix.h index 53cf945036c..9203b332176 100644 --- a/xpcom/io/nsLocalFileUnix.h +++ b/xpcom/io/nsLocalFileUnix.h @@ -83,8 +83,7 @@ #endif class NS_COM nsLocalFile : public nsILocalFile, - public nsIHashable, - public nsIClassInfo + public nsIHashable { public: NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID) @@ -105,9 +104,6 @@ public: // nsIHashable NS_DECL_NSIHASHABLE - // nsIClassInfo - NS_DECL_NSICLASSINFO - public: static void GlobalInit(); static void GlobalShutdown(); diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index 3edc82754d2..8446ef300d8 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -47,7 +47,6 @@ #include "nsLocalFile.h" #include "nsIDirectoryEnumerator.h" #include "nsNativeCharsetUtils.h" -#include "nsIProgrammingLanguage.h" #include "nsISimpleEnumerator.h" #include "nsIComponentManager.h" @@ -747,22 +746,11 @@ nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* // nsLocalFile::nsISupports //----------------------------------------------------------------------------- -NS_IMPL_THREADSAFE_ADDREF(nsLocalFile) -NS_IMPL_THREADSAFE_RELEASE(nsLocalFile) -NS_IMPL_QUERY_INTERFACE5_CI(nsLocalFile, - nsILocalFile, - nsIFile, - nsILocalFileWin, - nsIHashable, - nsIClassInfo) -NS_IMPL_CI_INTERFACE_GETTER4(nsLocalFile, - nsILocalFile, - nsIFile, - nsILocalFileWin, - nsIHashable) - -NS_DECL_CLASSINFO(nsLocalFile) -NS_IMPL_THREADSAFE_CI(nsLocalFile) +NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile, + nsILocalFile, + nsIFile, + nsILocalFileWin, + nsIHashable) //----------------------------------------------------------------------------- diff --git a/xpcom/io/nsLocalFileWin.h b/xpcom/io/nsLocalFileWin.h index ab22c2d1484..9a347d83605 100644 --- a/xpcom/io/nsLocalFileWin.h +++ b/xpcom/io/nsLocalFileWin.h @@ -64,8 +64,7 @@ DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0); #include class nsLocalFile : public nsILocalFileWin, - public nsIHashable, - public nsIClassInfo + public nsIHashable { public: NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID) @@ -89,9 +88,6 @@ public: // nsIHashable interface NS_DECL_NSIHASHABLE - // nsIClassInfo interface - NS_DECL_NSICLASSINFO - public: static void GlobalInit(); static void GlobalShutdown(); diff --git a/xpcom/io/nsScriptableInputStream.cpp b/xpcom/io/nsScriptableInputStream.cpp index 548aaa04500..5458b1b77d8 100644 --- a/xpcom/io/nsScriptableInputStream.cpp +++ b/xpcom/io/nsScriptableInputStream.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -36,335 +36,67 @@ * ***** END LICENSE BLOCK ***** */ #include "nsScriptableInputStream.h" -#include "nsIProgrammingLanguage.h" -#include "nsAutoPtr.h" #include "nsMemory.h" -#include "nsString.h" -#include "nsIUnicharLineInputStream.h" -#include "nsIClassInfoImpl.h" -// needed for NS_SWAP macros -#include "nsIStreamBufferAccess.h" - -NS_IMPL_THREADSAFE_ADDREF(nsScriptableInputStream) -NS_IMPL_THREADSAFE_RELEASE(nsScriptableInputStream) -NS_IMPL_QUERY_INTERFACE5_CI(nsScriptableInputStream, - nsIInputStream, - nsIScriptableInputStream, - nsIScriptableIOInputStream, - nsISeekableStream, - nsIMultiplexInputStream) -NS_IMPL_CI_INTERFACE_GETTER5(nsScriptableInputStream, - nsIInputStream, - nsIScriptableInputStream, - nsIScriptableIOInputStream, - nsISeekableStream, - nsIMultiplexInputStream) +NS_IMPL_ISUPPORTS1(nsScriptableInputStream, nsIScriptableInputStream) // nsIBaseStream methods NS_IMETHODIMP -nsScriptableInputStream::Close(void) -{ - if (mUnicharInputStream) - return mUnicharInputStream->Close(); - - if (mInputStream) +nsScriptableInputStream::Close(void) { + if (!mInputStream) return NS_ERROR_NOT_INITIALIZED; return mInputStream->Close(); - - return NS_ERROR_NOT_INITIALIZED; -} - -NS_IMETHODIMP -nsScriptableInputStream::InitWithStreams(nsIInputStream *aInputStream, - nsIUnicharInputStream *aCharStream) -{ - NS_ENSURE_ARG(aInputStream); - mInputStream = aInputStream; - mUnicharInputStream = aCharStream; - return NS_OK; } // nsIScriptableInputStream methods NS_IMETHODIMP -nsScriptableInputStream::Init(nsIInputStream *aInputStream) -{ - NS_ENSURE_ARG(aInputStream); - mInputStream = aInputStream; - mUnicharInputStream = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsScriptableInputStream::Available(PRUint32 *aIsAvailable) -{ - NS_ENSURE_TRUE(mInputStream, NS_ERROR_NOT_INITIALIZED); - - nsresult rv = mInputStream->Available(aIsAvailable); - NS_ENSURE_SUCCESS(rv, rv); - - // if there is no data left in the stream, check if the character stream - // has more text available. This is needed because the unichar stream - // will read a buffer from the input stream, leaving it with no remaining - // data, yet there is still text to read - if (!*aIsAvailable && mUnicharInputStream) - *aIsAvailable = mUnicharInputStreamHasMore; - - return NS_OK; -} - -NS_IMETHODIMP -nsScriptableInputStream::Read(PRUint32 aCount, char **_retval) -{ - nsresult rv = NS_OK; - PRUint32 count = 0; - char *buffer = nsnull; - - NS_ENSURE_TRUE(mInputStream, NS_ERROR_NOT_INITIALIZED); - - rv = mInputStream->Available(&count); - if (NS_FAILED(rv)) - return rv; - - count = PR_MIN(count, aCount); - buffer = (char*)NS_Alloc(count+1); // make room for '\0' - NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY); - - PRUint32 amtRead = 0; - rv = mInputStream->Read(buffer, count, &amtRead); - if (NS_FAILED(rv)) { - NS_Free(buffer); - return rv; - } - - buffer[amtRead] = '\0'; - *_retval = buffer; - return NS_OK; -} - -// nsIInputStream methods - -NS_IMETHODIMP -nsScriptableInputStream::IsNonBlocking(PRBool *aIsNonBlocking) -{ - NS_ENSURE_TRUE(mInputStream, NS_ERROR_NOT_INITIALIZED); - return mInputStream->IsNonBlocking(aIsNonBlocking); -} - -NS_IMETHODIMP -nsScriptableInputStream::Read(char* aData, - PRUint32 aCount, - PRUint32 *aReadCount) -{ - if (mUnicharInputStream) { - // XXXndeakin implement this +nsScriptableInputStream::Init(nsIInputStream *aInputStream) { + if (!aInputStream) return NS_ERROR_NULL_POINTER; + mInputStream = aInputStream; return NS_OK; - } - - if (mInputStream) - return mInputStream->Read(aData, aCount, aReadCount); - - return NS_ERROR_NOT_INITIALIZED; } NS_IMETHODIMP -nsScriptableInputStream::ReadSegments(nsWriteSegmentFun aFn, - void* aClosure, - PRUint32 aCount, - PRUint32 *aReadCount) -{ - NS_ENSURE_TRUE(mInputStream, NS_ERROR_NOT_INITIALIZED); - return mInputStream->ReadSegments(aFn, aClosure, aCount, aReadCount); +nsScriptableInputStream::Available(PRUint32 *_retval) { + if (!mInputStream) return NS_ERROR_NOT_INITIALIZED; + return mInputStream->Available(_retval); } NS_IMETHODIMP -nsScriptableInputStream::ReadString(PRUint32 aCount, nsAString& aString) -{ - if (mUnicharInputStream) { - PRUint32 readCount; - nsresult rv = mUnicharInputStream->ReadString(aCount, aString, &readCount); - NS_ENSURE_SUCCESS(rv, rv); +nsScriptableInputStream::Read(PRUint32 aCount, char **_retval) { + nsresult rv = NS_OK; + PRUint32 count = 0; + char *buffer = nsnull; - // If less characters are read than requested, then assume that the end - // of the file has been reached. - // XXXndeakin or it could be because the buffer is full - mUnicharInputStreamHasMore = (aCount == readCount); + if (!mInputStream) return NS_ERROR_NOT_INITIALIZED; + + rv = mInputStream->Available(&count); + if (NS_FAILED(rv)) return rv; + + count = PR_MIN(count, aCount); + buffer = (char*)nsMemory::Alloc(count+1); // make room for '\0' + if (!buffer) return NS_ERROR_OUT_OF_MEMORY; + + PRUint32 amtRead = 0; + rv = mInputStream->Read(buffer, count, &amtRead); + if (NS_FAILED(rv)) { + nsMemory::Free(buffer); + return rv; + } + + buffer[amtRead] = '\0'; + *_retval = buffer; return NS_OK; - } - - // just call Read and convert to UTF-16 - nsXPIDLCString cstr; - nsresult rv = Read(aCount, getter_Copies(cstr)); - NS_ENSURE_SUCCESS(rv, rv); - aString.Assign(NS_ConvertASCIItoUTF16(cstr)); - return NS_OK; -} - -NS_IMETHODIMP -nsScriptableInputStream::ReadLine(nsAString& aLine) -{ - nsCOMPtr cstream = do_QueryInterface(mUnicharInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - - return cstream->ReadLine(aLine, &mUnicharInputStreamHasMore); -} - -NS_IMETHODIMP -nsScriptableInputStream::ReadBoolean(PRBool* aBoolean) -{ - PRUint8 byteResult; - nsresult rv = Read8(&byteResult); - *aBoolean = !!byteResult; - return rv; -} - -NS_IMETHODIMP -nsScriptableInputStream::Read8(PRUint8* aVal) -{ - return ReadFully(sizeof *aVal, reinterpret_cast(aVal)); -} - -NS_IMETHODIMP -nsScriptableInputStream::Read16(PRUint16* aVal) -{ - nsresult rv = ReadFully(sizeof *aVal, reinterpret_cast(aVal)); - NS_ENSURE_SUCCESS(rv, rv); - *aVal = NS_SWAP16(*aVal); - return NS_OK; -} - -NS_IMETHODIMP -nsScriptableInputStream::Read32(PRUint32* aVal) -{ - nsresult rv = ReadFully(sizeof *aVal, reinterpret_cast(aVal)); - NS_ENSURE_SUCCESS(rv, rv); - *aVal = NS_SWAP32(*aVal); - return NS_OK; -} - -NS_IMETHODIMP -nsScriptableInputStream::ReadFloat(float* aFloat) -{ - NS_ASSERTION(sizeof(float) == sizeof (PRUint32), - "False assumption about sizeof(float)"); - return Read32(reinterpret_cast(aFloat)); -} - -NS_IMETHODIMP -nsScriptableInputStream::ReadDouble(double* aDouble) -{ - NS_ASSERTION(sizeof(double) == sizeof(PRUint64), - "False assumption about sizeof(double)"); - - nsresult rv = ReadFully(sizeof(double), reinterpret_cast(aDouble)); - - NS_ENSURE_SUCCESS(rv, rv); - PRUint64 i = NS_SWAP64(*reinterpret_cast(aDouble)); - *aDouble = *reinterpret_cast(&i); - return NS_OK; -} - -NS_IMETHODIMP -nsScriptableInputStream::ReadByteArray(PRUint32 aCount, PRUint8 **aBytes) -{ - char* s = reinterpret_cast(NS_Alloc(aCount)); - NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY); - - PRUint32 bytesRead; - nsresult rv = mInputStream->Read(s, aCount, &bytesRead); - if (NS_FAILED(rv)) { - NS_Free(s); - return rv; - } - if (bytesRead != aCount) { - NS_Free(s); - return NS_ERROR_FAILURE; - } - - *aBytes = (PRUint8 *)s; - return NS_OK; -} - -nsresult -nsScriptableInputStream::ReadFully(PRUint32 aCount, char* aBuf) -{ - PRUint32 bytesRead; - nsresult rv = Read(aBuf, aCount, &bytesRead); - NS_ENSURE_SUCCESS(rv, rv); - return (bytesRead != aCount) ? NS_ERROR_FAILURE : NS_OK; -} - -// nsISeekableStream -NS_IMETHODIMP -nsScriptableInputStream::Seek(PRInt32 aWhence, PRInt64 aOffset) -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->Seek(aWhence, aOffset); -} - -NS_IMETHODIMP -nsScriptableInputStream::Tell(PRInt64* aOffset) -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->Tell(aOffset); -} - -NS_IMETHODIMP -nsScriptableInputStream::SetEOF() -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->SetEOF(); -} - -// nsIMultiplexInputStream -NS_IMETHODIMP -nsScriptableInputStream::GetCount(PRUint32* aCount) -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->GetCount(aCount); -} - -NS_IMETHODIMP -nsScriptableInputStream::GetStream(PRUint32 aIndex, nsIInputStream** aStream) -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->GetStream(aIndex, aStream); -} - -NS_IMETHODIMP -nsScriptableInputStream::AppendStream(nsIInputStream* aStream) -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->AppendStream(aStream); -} - -NS_IMETHODIMP -nsScriptableInputStream::InsertStream(nsIInputStream* aStream, PRUint32 aIndex) -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->InsertStream(aStream, aIndex); -} - -NS_IMETHODIMP -nsScriptableInputStream::RemoveStream(PRUint32 aIndex) -{ - nsCOMPtr cstream = do_QueryInterface(mInputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->RemoveStream(aIndex); } NS_METHOD -nsScriptableInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - if (aOuter) return NS_ERROR_NO_AGGREGATION; +nsScriptableInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { + if (aOuter) return NS_ERROR_NO_AGGREGATION; - nsRefPtr sis = new nsScriptableInputStream(); - NS_ENSURE_TRUE(sis, NS_ERROR_OUT_OF_MEMORY); - return sis->QueryInterface(aIID, aResult); + nsScriptableInputStream *sis = new nsScriptableInputStream(); + if (!sis) return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(sis); + nsresult rv = sis->QueryInterface(aIID, aResult); + NS_RELEASE(sis); + return rv; } diff --git a/xpcom/io/nsScriptableInputStream.h b/xpcom/io/nsScriptableInputStream.h index c880f126ae6..76f3b19978e 100644 --- a/xpcom/io/nsScriptableInputStream.h +++ b/xpcom/io/nsScriptableInputStream.h @@ -39,11 +39,7 @@ #define ___nsscriptableinputstream___h_ #include "nsIScriptableInputStream.h" -#include "nsIScriptableStreams.h" #include "nsIInputStream.h" -#include "nsISeekableStream.h" -#include "nsIMultiplexInputStream.h" -#include "nsIUnicharInputStream.h" #include "nsCOMPtr.h" #define NS_SCRIPTABLEINPUTSTREAM_CID \ @@ -52,41 +48,16 @@ #define NS_SCRIPTABLEINPUTSTREAM_CONTRACTID "@mozilla.org/scriptableinputstream;1" #define NS_SCRIPTABLEINPUTSTREAM_CLASSNAME "Scriptable Input Stream" -class nsScriptableInputStream : public nsIScriptableInputStream, - public nsIScriptableIOInputStream, - public nsISeekableStream, - public nsIMultiplexInputStream -{ +class nsScriptableInputStream : public nsIScriptableInputStream { public: // nsISupports methods NS_DECL_ISUPPORTS - // nsIScriptableIOInputStream methods - NS_DECL_NSISCRIPTABLEIOINPUTSTREAM - - // nsISeekableStream methods - NS_DECL_NSISEEKABLESTREAM - - // nsIMultiplexInputStream methods - NS_DECL_NSIMULTIPLEXINPUTSTREAM - - // nsIInputStream and nsIScriptableInputStream methods - NS_IMETHOD Available(PRUint32 *aAvailable); - NS_IMETHOD Close(); - NS_IMETHOD IsNonBlocking(PRBool *aIsNonBlocking); - NS_IMETHOD Read(char* aData, - PRUint32 aCount, - PRUint32 *aReadCount); - NS_IMETHOD ReadSegments(nsWriteSegmentFun aFn, - void* aClosure, - PRUint32 aCount, - PRUint32 *aReadCount); - NS_IMETHOD Init(nsIInputStream* aInputStream); - NS_IMETHOD Read(PRUint32 aCount, char** aData); + // nsIScriptableInputStream methods + NS_DECL_NSISCRIPTABLEINPUTSTREAM // nsScriptableInputStream methods - nsScriptableInputStream() : - mUnicharInputStreamHasMore(PR_TRUE) {} + nsScriptableInputStream() {} static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); @@ -94,11 +65,7 @@ public: private: ~nsScriptableInputStream() {} - nsresult ReadFully(PRUint32 aCount, char* aBuf); - - PRBool mUnicharInputStreamHasMore; nsCOMPtr mInputStream; - nsCOMPtr mUnicharInputStream; }; #endif // ___nsscriptableinputstream___h_ diff --git a/xpcom/io/nsScriptableOutputStream.cpp b/xpcom/io/nsScriptableOutputStream.cpp deleted file mode 100644 index 5881a1c18f4..00000000000 --- a/xpcom/io/nsScriptableOutputStream.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScriptableOutputStream.h" -#include "nsIProgrammingLanguage.h" -#include "nsAutoPtr.h" -#include "nsMemory.h" -#include "nsString.h" -#include "nsIClassInfoImpl.h" - -// needed for NS_SWAP macros -#include "nsIStreamBufferAccess.h" - -NS_IMPL_THREADSAFE_ADDREF(nsScriptableOutputStream) -NS_IMPL_THREADSAFE_RELEASE(nsScriptableOutputStream) -NS_IMPL_QUERY_INTERFACE3_CI(nsScriptableOutputStream, - nsIOutputStream, - nsIScriptableIOOutputStream, - nsISeekableStream) -NS_IMPL_CI_INTERFACE_GETTER3(nsScriptableOutputStream, - nsIOutputStream, - nsIScriptableIOOutputStream, - nsISeekableStream) - -// nsIBaseStream methods -NS_IMETHODIMP -nsScriptableOutputStream::Close(void) -{ - if (mUnicharOutputStream) - return mUnicharOutputStream->Close(); - - if (mOutputStream) - return mOutputStream->Close(); - - return NS_ERROR_NOT_INITIALIZED; -} - -NS_IMETHODIMP -nsScriptableOutputStream::Flush(void) -{ - if (mUnicharOutputStream) - return mUnicharOutputStream->Flush(); - - if (mOutputStream) - return mOutputStream->Flush(); - - return NS_ERROR_NOT_INITIALIZED; -} - -// nsIScriptableIOOutputStream methods - -NS_IMETHODIMP -nsScriptableOutputStream::InitWithStreams(nsIOutputStream* aOutputStream, - nsIUnicharOutputStream *aCharStream) -{ - NS_ENSURE_ARG(aOutputStream); - - mOutputStream = aOutputStream; - mUnicharOutputStream = aCharStream; - return NS_OK; -} - -// nsIOutputStream methods - -NS_IMETHODIMP -nsScriptableOutputStream::IsNonBlocking(PRBool *aIsNonBlocking) -{ - if (mOutputStream) - return mOutputStream->IsNonBlocking(aIsNonBlocking); - - if (mUnicharOutputStream) { - *aIsNonBlocking = PR_FALSE; - return NS_OK; - } - - return NS_ERROR_NOT_INITIALIZED; -} - -NS_IMETHODIMP -nsScriptableOutputStream::Write(const char* aBuffer, PRUint32 aCount, PRUint32 *aWriteCount) -{ - if (mUnicharOutputStream) { - nsAutoString str(NS_ConvertASCIItoUTF16(aBuffer, aCount)); - PRBool ok; - mUnicharOutputStream->WriteString(str, &ok); - *aWriteCount = ok ? aCount : 0; - return NS_OK; - } - - if (mOutputStream) - return mOutputStream->Write(aBuffer, aCount, aWriteCount); - - return NS_ERROR_NOT_INITIALIZED; -} - -NS_IMETHODIMP -nsScriptableOutputStream::WriteFrom(nsIInputStream *aStream, PRUint32 aCount, PRUint32 *aWriteCount) -{ - if (mOutputStream) - return mOutputStream->WriteFrom(aStream, aCount, aWriteCount); - - return NS_ERROR_NOT_INITIALIZED; -} - -NS_IMETHODIMP -nsScriptableOutputStream::WriteSegments(nsReadSegmentFun aFn, - void* aClosure, - PRUint32 aCount, - PRUint32 *aReadCount) -{ - NS_ENSURE_TRUE(mOutputStream, NS_ERROR_NOT_INITIALIZED); - return mOutputStream->WriteSegments(aFn, aClosure, aCount, aReadCount); -} - -NS_IMETHODIMP -nsScriptableOutputStream::WriteString(const nsAString& aString, PRBool *aOK) -{ - if (mUnicharOutputStream) - return mUnicharOutputStream->WriteString(aString, aOK); - - if (!mOutputStream) - return NS_ERROR_NOT_INITIALIZED; - - // just convert to ASCII and call Write - nsCAutoString cstr = NS_LossyConvertUTF16toASCII(aString); - PRUint32 count; - nsresult rv = mOutputStream->Write(cstr.get(), (PRUint32)cstr.Length(), &count); - NS_ENSURE_SUCCESS(rv, rv); - *aOK = (count == cstr.Length()); - return NS_OK; -} - -NS_IMETHODIMP -nsScriptableOutputStream::WriteBoolean(PRBool aBoolean) -{ - return Write8(aBoolean); -} - -NS_IMETHODIMP -nsScriptableOutputStream::Write8(PRUint8 aByte) -{ - return WriteFully((const char *)&aByte, sizeof aByte); -} - -NS_IMETHODIMP -nsScriptableOutputStream::Write16(PRUint16 a16) -{ - a16 = NS_SWAP16(a16); - return WriteFully((const char *)&a16, sizeof a16); -} - -NS_IMETHODIMP -nsScriptableOutputStream::Write32(PRUint32 a32) -{ - a32 = NS_SWAP32(a32); - return WriteFully((const char *)&a32, sizeof a32); -} - -NS_IMETHODIMP -nsScriptableOutputStream::WriteFloat(float aFloat) -{ - NS_ASSERTION(sizeof(float) == sizeof (PRUint32), - "False assumption about sizeof(float)"); - return Write32(*reinterpret_cast(&aFloat)); -} - -NS_IMETHODIMP -nsScriptableOutputStream::WriteDouble(double aDouble) -{ - NS_ASSERTION(sizeof(double) == sizeof(PRUint64), - "False assumption about sizeof(double)"); - - PRUint64 val = NS_SWAP64(*reinterpret_cast(&aDouble)); - return WriteFully(reinterpret_cast(&val), sizeof val); -} - -NS_IMETHODIMP -nsScriptableOutputStream::WriteByteArray(PRUint8 *aBytes, PRUint32 aCount) -{ - return WriteFully((char *)aBytes, aCount); -} - -nsresult -nsScriptableOutputStream::WriteFully(const char *aBuf, PRUint32 aCount) -{ - NS_ENSURE_TRUE(mOutputStream, NS_ERROR_NOT_INITIALIZED); - - PRUint32 bytesWritten; - nsresult rv = mOutputStream->Write(aBuf, aCount, &bytesWritten); - NS_ENSURE_SUCCESS(rv, rv); - return (bytesWritten != aCount) ? NS_ERROR_FAILURE : NS_OK; -} - -// nsISeekableStream -NS_IMETHODIMP -nsScriptableOutputStream::Seek(PRInt32 aWhence, PRInt64 aOffset) -{ - nsCOMPtr cstream = do_QueryInterface(mOutputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->Seek(aWhence, aOffset); -} - -NS_IMETHODIMP -nsScriptableOutputStream::Tell(PRInt64* aOffset) -{ - nsCOMPtr cstream = do_QueryInterface(mOutputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->Tell(aOffset); -} - -NS_IMETHODIMP -nsScriptableOutputStream::SetEOF() -{ - nsCOMPtr cstream = do_QueryInterface(mOutputStream); - NS_ENSURE_TRUE(cstream, NS_ERROR_NOT_AVAILABLE); - return cstream->SetEOF(); -} - -NS_METHOD -nsScriptableOutputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - if (aOuter) return NS_ERROR_NO_AGGREGATION; - - nsRefPtr sos = new nsScriptableOutputStream(); - NS_ENSURE_TRUE(sos, NS_ERROR_OUT_OF_MEMORY); - return sos->QueryInterface(aIID, aResult); -} diff --git a/xpcom/io/nsScriptableOutputStream.h b/xpcom/io/nsScriptableOutputStream.h deleted file mode 100644 index 8fd02757638..00000000000 --- a/xpcom/io/nsScriptableOutputStream.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef ___nsscriptableoutputstream___h_ -#define ___nsscriptableoutputstream___h_ - -#include "nsIScriptableStreams.h" -#include "nsIOutputStream.h" -#include "nsISeekableStream.h" -#include "nsIUnicharOutputStream.h" -#include "nsCOMPtr.h" - -#define NS_SCRIPTABLEOUTPUTSTREAM_CID \ -{ 0xaea1cfe2, 0xf727, 0x4b94, { 0x93, 0xff, 0x41, 0x8d, 0x96, 0x87, 0x94, 0xd1 } } - -#define NS_SCRIPTABLEOUTPUTSTREAM_CONTRACTID "@mozilla.org/scriptableoutputstream;1" -#define NS_SCRIPTABLEOUTPUTSTREAM_CLASSNAME "Scriptable Output Stream" - -class nsScriptableOutputStream : public nsIScriptableIOOutputStream, - public nsISeekableStream, - public nsIOutputStream -{ -public: - // nsISupports methods - NS_DECL_ISUPPORTS - - // nsIOutputStream methods - NS_DECL_NSIOUTPUTSTREAM - - // nsIScriptableIOOutputStream methods - NS_DECL_NSISCRIPTABLEIOOUTPUTSTREAM - - // nsISeekableStream methods - NS_DECL_NSISEEKABLESTREAM - - // nsScriptableOutputStream methods - nsScriptableOutputStream() {} - - static NS_METHOD - Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - -private: - ~nsScriptableOutputStream() {} - - nsresult WriteFully(const char *aBuf, PRUint32 aCount); - - nsCOMPtr mOutputStream; - nsCOMPtr mUnicharOutputStream; -}; - -#endif // ___nsscriptableoutputstream___h_