1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla XPInstall.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2002
19 * the Initial Developer. All Rights Reserved.
22 * Daniel Veditz <dveditz@netscape.com> (Original Author)
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* implementation of a test XPInstall Dialog Service */
40 // -----------------------------------------------------------------------
41 // Test the XPInstall embedding API's by dropping this component into
42 // the Mozilla components directory and registering it.
44 // Do not export as part of a normal build since this will override the
45 // built-in Mozilla UI we want to use.
46 // -----------------------------------------------------------------------
48 // -----------------------------------------------------------------------
50 // -----------------------------------------------------------------------
51 const XPIDIALOGSERVICE_CONTRACTID =
52 "@mozilla.org/embedui/xpinstall-dialog-service;1";
54 const XPIDIALOGSERVICE_CID =
55 Components.ID("{9A5BEF68-3FDA-4926-9809-87A5A1CC8505}");
57 const XPI_TOPIC = "xpinstall-progress";
59 const CANCEL = "cancel";
62 // -----------------------------------------------------------------------
63 // XPInstall Dialog Service
64 // -----------------------------------------------------------------------
66 function testXPIDialogService() {}
68 testXPIDialogService.prototype =
70 QueryInterface: function( iid )
72 if (iid.equals(Components.interfaces.nsIXPIDialogService) ||
73 iid.equals(Components.interfaces.nsIXPIProgressDialog) ||
74 iid.equals(Components.interfaces.nsISupports))
77 Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
81 confirmInstall: function( parent, packages, count )
83 // stash parent window for use later
84 this.mParent = parent;
86 // quick and dirty data display
87 var str = "num packages: " + count/2 + "\n\n";
88 for ( i = 0; i < count; ++i)
89 str += packages[i++] + ' -- ' + packages[i] + '\n';
91 str += "\nDo you want to install?";
93 return parent.confirm(str);
96 openProgressDialog: function( packages, count, mgr )
98 this.dlg = this.mParent.open();
99 mgr.observe( this, XPI_TOPIC, OPEN );
102 onStateChange: function( index, state, error )
104 dump("---XPIDlg--- State: "+index+', '+state+', '+error+'\n');
107 onProgress: function( index, value, max )
109 dump("---XPIDlg--- "+index+": "+value+' of '+max+'\n');
115 // -----------------------------------------------------------------------
116 // XPInstall Dialog Service Module and Factory
117 // -----------------------------------------------------------------------
119 // --- module entry point ---
120 function NSGetModule(compMgr, fileSpec) { return XPIDlgSvcModule; }
124 var XPIDlgSvcModule =
126 registerSelf: function( compMgr, fileSpec, location, type )
128 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
130 compMgr.registerFactoryLocation(XPIDIALOGSERVICE_CID,
131 'XPInstall Dialog Service test component',
132 XPIDIALOGSERVICE_CONTRACTID, fileSpec,
136 unregisterSelf: function( compMgr, fileSpec, location )
138 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
139 compMgr.unregisterFactoryLocation(XPIDIALOGSERVICE_CID, fileSpec);
142 getClassObject: function( compMgr, cid, iid )
144 if (!cid.equals(XPIDIALOGSERVICE_CID))
145 throw Components.results.NS_ERROR_NO_INTERFACE;
147 if (!iid.equals(Components.interfaces.nsIFactory))
148 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
150 return XPIDlgSvcFactory;
153 canUnload: function( compMgr ) { return true; }
158 var XPIDlgSvcFactory =
160 createInstance: function( outer, iid )
163 throw Components.results.NS_ERROR_NO_AGGREGATION;
165 if (!iid.equals(Components.interfaces.nsIXPIDialogService) &&
166 !iid.equals(Components.interfaces.nsISupports))
167 throw Components.results.NS_ERROR_INVALID_ARG;
169 return new testXPIDialogService();