/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.0 (the "NPL"); you may not use this file except in
 * compliance with the NPL.  You may obtain a copy of the NPL at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the NPL is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
 * for the specific language governing rights and limitations under the
 * NPL.
 *
 * The Initial Developer of this code under the NPL is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 * Reserved.
 */

#include "nsIRequest.idl"

interface nsIChannel;
interface nsISimpleEnumerator;
interface nsIStreamObserver;
interface nsIStreamListener;
interface nsIInputStream;


[scriptable, uuid(60fdf550-5392-11d3-9a97-0080c7cb1080)]
interface nsILoadGroupListenerFactory : nsISupports
{
	nsIStreamListener CreateLoadGroupListener(in nsIStreamListener alistener);
};


/**
 * A load group maintains a collection of active URL requests. 
 */
[scriptable, uuid(19845248-29ab-11d3-8cce-0060b0fc14a3)]
interface nsILoadGroup : nsIRequest
{
    void Init(in nsIStreamObserver observer,
              in nsILoadGroup parent);

    /**
     * Accesses the default load attributes for the group, returned as
     * a flag word. Setting the default load attributes will cause them
     * to be applied to each new channel inserted into the group.
     */
    attribute unsigned long DefaultLoadAttributes;

	/**
	 * Accesses the default load channel for the group.  Each time a number
	 * of channels are added to a group, the DefaultLoadChannel may be set
	 * to indicate that all of the channels are related to a particular URL.
	 */
	attribute nsIChannel DefaultLoadChannel;

    /**
     * Adds a new channel to the group. This will cause the default load
     * attributes to be applied to that channel. If the channel added is 
     * the first channel in the group, the group's observer's OnStartRequest
     * method is called.
     */
    void AddChannel(in nsIChannel channel,
                    in nsISupports ctxt);

    /**
     * Removes a channel from the group. If the channel removed is 
     * the last channel in the group, the group's observer's OnStopRequest
     * method is called.
     */
    void RemoveChannel(in nsIChannel channel, 
                       in nsISupports ctxt,
                       in nsresult status,
                       in wstring errorMsg);

    /**
     * Returns the channels contained directly in this group.
     * Enumerator element type: nsIChannel.
     */
    readonly attribute nsISimpleEnumerator Channels;

    /**
     * Adds a new sub-group to the group.
     */
    void AddSubGroup(in nsILoadGroup group);

    /**
     * Removes a sub-group from the group.
     */
    void RemoveSubGroup(in nsILoadGroup group);

    /**
     * Returns the sub-groups of a group.
     * Enumerator element type: nsILoadGroup.
     */
    readonly attribute nsISimpleEnumerator SubGroups;

	attribute nsILoadGroupListenerFactory GroupListenerFactory;
};

%{C++

#define NS_LOADGROUP_CID                             \
{ /* e1c61582-2a84-11d3-8cce-0060b0fc14a3 */         \
    0xe1c61582,                                      \
    0x2a84,                                          \
    0x11d3,                                          \
    {0x8c, 0xce, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
}                                                    \

%}
