@@ -16,11 +16,6 @@ const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
16
16
17
17
Cu . import ( "resource://gre/modules/Services.jsm" ) ;
18
18
Cu . import ( "resource://gre/modules/XPCOMUtils.jsm" ) ;
19
- XPCOMUtils . defineLazyGetter ( this , "convert" , function ( ) {
20
- var obj = new Object ;
21
- Cu . import ( "resource://liberator/template.js" , obj ) ;
22
- return obj . convert ;
23
- } ) ;
24
19
25
20
const NS_BINDING_ABORTED = 0x804b0002 ;
26
21
const nsIProtocolHandler = Ci . nsIProtocolHandler ;
@@ -51,17 +46,6 @@ function redirect(to, orig) {
51
46
let html = '<html><head><meta http-equiv="Refresh" content="' + ( "0;" + to ) . replace ( / " / g, """ ) + '"/></head></html>' ;
52
47
return makeChannel ( dataURL ( 'text/html' , html ) , ioService . newURI ( to , null , null ) ) ;
53
48
}
54
- XPCOMUtils . defineLazyGetter ( this , "cache" , function ( ) {
55
- var dir = Cc [ "@mozilla.org/file/directory_service;1" ] . getService ( Ci . nsIProperties ) . get ( "ProfD" , Ci . nsIFile ) ;
56
- dir . append ( "liberatorCache" ) ;
57
- if ( ! dir . exists ( ) ) {
58
- dir . create ( dir . DIRECTORY_TYPE , - 1 ) ;
59
- }
60
- return dir ;
61
- } ) ;
62
- XPCOMUtils . defineLazyGetter ( this , "version" , function ( ) {
63
- return Services . appinfo . version ;
64
- } ) ;
65
49
66
50
function ChromeData ( ) { }
67
51
ChromeData . prototype = {
@@ -148,110 +132,11 @@ Liberator.prototype = {
148
132
. QueryInterface ( Ci . nsIURI ) ;
149
133
uri . init ( uri . URLTYPE_STANDARD , this . defaultPort , spec , charset , baseURI ) ;
150
134
151
- if ( uri . host !== "template" ) return uri ;
152
-
153
- try {
154
- spec = uri . spec ;
155
- //uri.init(uri.URLTYPE_STANDARD, this.defaultPort, uri.path.substr(1), charset, null);
156
- // xxx:
157
- uri = ioService . newURI ( uri . path . replace ( new RegExp ( "^/+" ) , "" ) , charset , null ) ;
158
- // recursible when override
159
- while ( uri . scheme === "chrome" ) {
160
- uri = Cc [ "@mozilla.org/chrome/chrome-registry;1" ]
161
- . getService ( Ci . nsIChromeRegistry )
162
- . convertChromeURL ( uri ) ;
163
- }
164
-
165
- var nest = Cc [ "@mozilla.org/network/util;1" ] . getService ( Ci . nsINetUtil ) . newSimpleNestedURI ( uri ) ;
166
- nest . spec = spec ;
167
- } catch ( ex ) { Cu . reportError ( ex ) ; }
168
- return nest ;
135
+ return uri ;
169
136
} ,
170
137
171
138
newChannel : function ( uri ) {
172
139
try {
173
- if ( ( uri instanceof Ci . nsINestedURI ) ) {
174
- var m = ( new RegExp ( "^/{2,}([^/]+)/([^?]+)" ) ) . exec ( uri . path ) ;
175
- if ( m ) {
176
- var host = m [ 1 ] ;
177
- var path = m [ 2 ] ;
178
-
179
- switch ( host ) {
180
- case "template" :
181
- try {
182
- var nest = ioService . newURI ( path , uri . charset , null ) ;
183
- var channel = ioService . newChannelFromURI ( nest ) ;
184
-
185
- // xxx: support template
186
- if ( 0 ) return channel ;
187
-
188
- // xxx: NG: Firefox 16, 17
189
- // NG: Cu.import
190
- if ( parseFloat ( version ) < 17 ) {
191
- var stream = Cc [ "@mozilla.org/scriptableinputstream;1" ]
192
- . createInstance ( Ci . nsIScriptableInputStream ) ;
193
- var cstream = channel . open ( ) ;
194
- stream . init ( cstream ) ;
195
- var text = stream . read ( - 1 ) ;
196
- stream . close ( ) ;
197
- cstream . close ( ) ;
198
-
199
- stream = Cc [ "@mozilla.org/io/string-input-stream;1" ] . createInstance ( Ci . nsIStringInputStream ) ;
200
- stream . setData ( convert ( text ) , - 1 ) ;
201
- var channel = Cc [ "@mozilla.org/network/input-stream-channel;1" ]
202
- . createInstance ( Ci . nsIInputStreamChannel ) ;
203
- channel . contentStream = stream ;
204
- channel . QueryInterface ( Ci . nsIChannel ) ;
205
- channel . setURI ( uri ) ;
206
- return channel ;
207
- }
208
-
209
- var innerURI = uri . innerURI ;
210
- var temp = cache . clone ( ) ;
211
- var path = nest . spec . replace ( / [: \/ ] / g, "_" ) ;
212
- var lastModifiedTime ;
213
- if ( innerURI . scheme === "resource" ) {
214
- innerURI = Cc [ "@mozilla.org/network/protocol;1?name=resource" ]
215
- . getService ( Ci . nsIResProtocolHandler ) . resolveURI ( innerURI ) ;
216
- innerURI = ioService . newURI ( innerURI , null , null ) ;
217
- }
218
- if ( innerURI . scheme === "jar" ) {
219
- innerURI = innerURI . QueryInterface ( Ci . nsIJARURI ) . JARFile ;
220
- }
221
- if ( innerURI . scheme === "file" ) {
222
- lastModifiedTime = innerURI . QueryInterface ( Ci . nsIFileURL ) . file . lastModifiedTime ;
223
- } else {
224
- Cu . reportError ( "do not support:" + innerURI . spec ) ;
225
- }
226
-
227
- temp . append ( path ) ;
228
- if ( ! temp . exists ( )
229
- || temp . lastModifiedTime !== lastModifiedTime ) {
230
-
231
- var stream = Cc [ "@mozilla.org/scriptableinputstream;1" ]
232
- . createInstance ( Ci . nsIScriptableInputStream ) ;
233
- var cstream = channel . open ( ) ;
234
- stream . init ( cstream ) ;
235
- var text = stream . read ( - 1 ) ;
236
- stream . close ( ) ;
237
- cstream . close ( ) ;
238
-
239
- text = convert ( text ) ;
240
-
241
- var stream = Cc [ "@mozilla.org/network/file-output-stream;1" ] . createInstance ( Ci . nsIFileOutputStream ) ;
242
- Services . console . logStringMessage ( "create:" + temp . leafName ) ;
243
- stream . init ( temp , 0x2 | 0x8 | 0x20 , 0644 , 0 ) ;
244
- stream . write ( text , text . length ) ;
245
- stream . close ( ) ;
246
- temp . lastModifiedTime = lastModifiedTime ;
247
- } else { Services . console . logStringMessage ( "use cache:" + uri . spec ) ; }
248
- return ioService . newChannelFromURI ( ioService . newFileURI ( temp ) ) ;
249
- } catch ( ex ) { Cu . reportError ( ex ) ; }
250
- }
251
- }
252
- return fakeChannel ( uri ) ;
253
- }
254
-
255
140
let url ;
256
141
switch ( uri . host ) {
257
142
case "help" :
0 commit comments