root/branches/uploadr/3.2/MacUploadr.app/Contents/Resources/components/clh.js

Revision 641, 3.7 kB (checked in by jdecq, 5 months ago)

new temporary build, additional command line handler modification to retrieve frob, GM version matching site...

Line 
1 /*
2  * Flickr Uploadr
3  *
4  * Copyright (c) 2007-2009 Yahoo! Inc.  All rights reserved.  This library is
5  * free software; you can redistribute it and/or modify it under the terms of
6  * the GNU General Public License (GPL), version 2 only.  This library is
7  * distributed WITHOUT ANY WARRANTY, whether express or implied. See the GNU
8  * GPL for more details (http://www.gnu.org/licenses/gpl.html)
9  */
10
11 const Cc = Components.classes;
12 const Ci = Components.interfaces;
13
14 const clh_contractID =
15         "@mozilla.org/commandlinehandler/general-startup;1?type=flcmdline";
16 const clh_CID = Components.ID("{3e984f42-a822-11dc-8314-0800200c9a66}");
17 const clh_category = "m-flcmdline";
18
19 const myAppHandler = {
20
21         QueryInterface : function(iid){
22                 if (iid.equals(Ci.nsICommandLineHandler) || iid.equals(Ci.nsIFactory) ||
23                         iid.equals(Ci.nsISupports) || iid.equals(Ci.flICLH)) {
24                         return this;
25                 }
26                 throw Components.results.NS_ERROR_NO_INTERFACE;
27         },
28
29         handle : function(cl){
30                 var start = 0;
31
32                 if (1 == cl.state){ // STATE_REMOTE_AUTO
33                         // calh: i needed this in my test app, since arg 0 was the
34                         // application.ini file (wtf?)
35                         // don't seem to need it for uploadr though...
36                         //start = 1;
37                 }
38
39                 var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
40                         .getService(Ci.nsIWindowMediator);
41                 var win = wm.getMostRecentWindow('app');
42
43                 var ii = cl.length;
44                 var send_queue = [];
45                 for (var i = start; i < ii; ++i) {
46                         var arg = cl.getArgument(i);
47                         Cc["@mozilla.org/consoleservice;1"]
48                                 .getService(Ci.nsIConsoleService)
49                                 .logStringMessage(new Date().toUTCString() + ': ' + arg);
50                         if ('-' == arg.substr(0,1)) continue;
51
52                         // Either queue it for immediate sending or queue it for later
53                         if (win) {
54                                 send_queue.push(arg);
55                         } else {
56                                 this.local_queue.push(arg);
57                         }
58
59                 }
60
61                 // If we found a window, we need to send the queue
62                 if (0 < send_queue.length) {
63                         win.clh(true, send_queue.join('|||||'));
64                 }
65
66                 if (1 == cl.state) { // STATE_REMOTE_AUTO
67                         cl.preventDefault = true;
68                 }
69         },
70
71         local_queue : [],
72
73         getQueue : function(){
74                 var q = this.local_queue.join('|||||');
75                 this.local_queue = [];
76                 return q;
77         },
78
79         helpInfo : "\n",
80
81         createInstance : function(outer, iid){
82                 if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
83                 return this.QueryInterface(iid);
84         },
85
86         lockFactory : function(lock){
87                 /* no-op */
88         }
89 };
90
91 const myAppHandlerModule = {
92
93         QueryInterface : function(iid){
94                 if (iid.equals(Ci.nsIModule) || iid.equals(Ci.nsISupports)) {
95                         return this;
96                 }
97                 throw Components.results.NS_ERROR_NO_INTERFACE;
98         },
99
100         getClassObject : function(compMgr, cid, iid){
101                 if (cid.equals(clh_CID)) return myAppHandler.QueryInterface(iid);
102                 throw Components.results.NS_ERROR_NOT_REGISTERED;
103         },
104
105         registerSelf : function(compMgr, fileSpec, location, type){
106                 compMgr.QueryInterface(Ci.nsIComponentRegistrar);
107                 compMgr.registerFactoryLocation(clh_CID,
108                                     "myAppHandler",
109                                     clh_contractID,
110                                     fileSpec,
111                                     location,
112                                     type);
113
114                 var catMan = Cc["@mozilla.org/categorymanager;1"]
115                         .getService(Ci.nsICategoryManager);
116                 catMan.addCategoryEntry("command-line-handler",
117                             clh_category,
118                             clh_contractID, true, true);
119         },
120
121         unregisterSelf : function(compMgr, location, type){
122                 compMgr.QueryInterface(Ci.nsIComponentRegistrar);
123                 compMgr.unregisterFactoryLocation(clh_CID, location);
124                 var catMan = Cc["@mozilla.org/categorymanager;1"]
125                         .getService(Ci.nsICategoryManager);
126                 catMan.deleteCategoryEntry("command-line-handler", clh_category);
127         },
128
129         canUnload : function(compMgr){
130                 return true;
131         }
132 };
133
134 function NSGetModule(comMgr, fileSpec){
135         return myAppHandlerModule;
136 }
Note: See TracBrowser for help on using the browser.