/* ***** 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 Open Web Apps.
 *
 * The Initial Developer of the Original Code is
 * Mozilla Corporation
 * Portions created by the Initial Developer are Copyright (C) 2011
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Fabrice Desré <fabrice@mozilla.com>
 *
 * 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 ***** */

// IDL for https://developer.mozilla.org/en/OpenWebApps/The_JavaScript_API

#include "nsISupports.idl"

[scriptable, uuid(3b937eb5-679b-41e9-aefa-543849fa61dd)]
interface nsIOpenWebappsApplication : nsISupports {
    attribute jsval manifest;
    attribute DOMString origin;
    attribute jsval install_data;
    attribute DOMString install_origin;
    attribute unsigned long install_time;
};

[scriptable, function, uuid(fa3ac1bb-ad7d-44d7-8585-9ecdf3782d65)]
interface nsIOpenWebappsSuccessInstalled : nsISupports {
    void handle(in nsIOpenWebappsApplication application);
};

[scriptable, function, uuid(a8a83f45-4cbe-4806-b867-017554e30bd4)]
interface nsIOpenWebappsSuccessList : nsISupports {
    void handle([array, size_is(count)] in nsIOpenWebappsApplication apps,
                in unsigned long count);
};

[scriptable, function, uuid(75e44e3f-ccda-4497-af68-8abd3f5e1d7b)]
interface nsIOpenWebappsError : nsISupports {
    attribute DOMString code;
    attribute DOMString message;
};

[scriptable, function, uuid(8b29495e-a5e4-4e76-9af8-0f6fe97b8959)]
interface nsIOpenWebappsErrorCB : nsISupports {
    void handle(in nsIOpenWebappsError error);
};

[scriptable, function, uuid(b86669ab-6a36-4ceb-a4bf-a980dd496144)]
interface nsIOpenWebappsSuccessEmpty : nsISupports {
    void handle();
};

[scriptable, function, uuid(a458afcf-eee9-42fb-bd90-75d5e41c0d9e)]
interface nsIOpenWebappsChangeCallback : nsISupports {
    // what is either "add" when new apps are added to the repository, or
    // "remove" when they are deleted.
    void update(in DOMString what, [array, size_is(count)] in nsIOpenWebappsApplication apps,
		in unsigned long count);
};

[scriptable, uuid(f3ec76a6-abca-4d90-b8c9-e221033068ef)]
interface nsIOpenWebappsMgmt : nsISupports {
    void launch(in DOMString origin,
                [optional] in nsIOpenWebappsSuccessEmpty onsuccess,
                [optional] in nsIOpenWebappsErrorCB onerror);
    
    void list(in nsIOpenWebappsSuccessList onsuccess,
              [optional] in nsIOpenWebappsErrorCB onerror);
    
    void uninstall(in DOMString origin,
                   in nsIOpenWebappsSuccessEmpty onsuccess,
                   [optional] in nsIOpenWebappsErrorCB onerror);

    long watchUpdates(in nsIOpenWebappsChangeCallback callback);

    void clearWatch(in long watchId);
};

[scriptable, uuid(cecd9de7-ea4e-45fd-8a01-a5861d9109ab)]
interface nsIOpenWebapps : nsISupports {
    void install(in DOMString manifestURI,
                 [optional] in jsval install_data,
                 [optional] in nsIOpenWebappsSuccessEmpty onsuccess,
                 [optional] in nsIOpenWebappsErrorCB onerror);
    
    void amInstalled(in nsIOpenWebappsSuccessInstalled onsuccess,
                     [optional] in nsIOpenWebappsErrorCB onerror);
    
    void getInstalledBy(in nsIOpenWebappsSuccessList onsuccess,
                        [optional] in nsIOpenWebappsErrorCB onerror);
    
    readonly attribute nsIOpenWebappsMgmt mgmt;
};
