Revision 46:f16f6e0e5b69 src/pithos/content/connection.js

b/src/pithos/content/connection.js
1
// The Pithos File Manager Firefox Extension is funded by GRNET S.A.
2
// (http://www.grnet.gr)
3
//
4
// Copyright (c) 2009, Christos KK Loverdos, Vassilios Karakoidas.
5
// All rights reserved.
6
//
7
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are
9
// met:
10
//
11
//   - Redistributions of source code must retain the above copyright
12
//     notice, this list of conditions and the following disclaimer.
13
//   - Redistributions in binary form must reproduce the above
14
//     copyright notice, this list of conditions and the following
15
//     disclaimer in the documentation and/or other materials provided
16
//     with the distribution.
17
//   - Neither the name of GRNET S.A. nor the names of its contributors
18
//     may be used to endorse or promote products derived from this
19
//     software without specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32

  
1 33
connection_obj = null;
2 34

  
3 35
function ConnectionObject() {
......
46 78
	}
47 79
	
48 80
	this.create_request_get = function(rest_req) {
49
		if ( isRemoteDirectory(rest_req) ) {
81
		if ( vfs.isRemoteResource(rest_req) ) {
50 82
			var gmtstring = (new Date()).toGMTString();
51 83
			var sign_url = rest_req.replace(this.rest_url, "");
52 84
			var hash = sign(this.token, sign_url, gmtstring, "GET");
......
76 108
        return req;
77 109
    }
78 110

  
111
	this.rest_request_get_inline_async = function(rest_req) {
112
        var url = this.create_request_get(rest_req);
113
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
114
        var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
115
        req.open("GET", url, true);
116

  
117
		req.onload = this.onLoadDefault;
118
		req.onprogress = this.onProgressDefault;
119
		req.onerror = this.onErrorDefault;
120

  
121
        req.overrideMimeType('text/plain; charset=x-user-defined');
122
        req.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
123
        req.send(null);
124

  
125
        return req;		
126
	}
127

  
128
    this.rest_request_put_upload_async = function(source, rest_req, data, mime) {
129
        var url = rest_req;
130
        var sign_url = rest_req.replace(current.rest_url, '');
131
        var gmtstring = (new Date()).toGMTString();
132

  
133
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
134
        var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
135
        try {
136
            file.initWithPath(source);
137
        } catch(error) {
138
            alert(error);
139
            return null;
140
        }
141
        
142
        var stream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
143
        stream.init(file, 0x04 | 0x08, 0644, 0x04); // file is an nsIFile instance  
144

  
145
        var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
146
        req.open("PUT", url, true);
147

  
148
		req.onload = this.onLoadDefault;
149
		req.onprogress = this.onProgressDefault;
150
		req.onerror = this.onErrorDefault;
151

  
152
        req.setRequestHeader('Authorization', current.username + " " + sign(current.token, sign_url, gmtstring, "PUT"));
153
        req.setRequestHeader('X-GSS-Date', gmtstring);
154

  
155
        req.setRequestHeader("Content-type", mime + "; charset=utf-8");
156
        //req.setRequestHeader("Content-length", data.length);
157
        req.send(stream);
158

  
159
        return req;
160
    }
161

  
79 162
    this.rest_request_put_upload = function(source, rest_req, data, mime) {
80 163
        var url = rest_req;
81 164
        var sign_url = rest_req.replace(current.rest_url, '');
......
105 188

  
106 189
        return req;
107 190
    }
191

  
192
	this.rest_request_post_async = function(rest_req, params, data) {
193
		return rest_request_generic(rest_req, params, "POST", data, true, this.onLoadDefault, this.onProgressDefault, this.onErrorDefault);
194
	}
195
	
196
	this.rest_request_put_async = function(rest_req, params, data) {
197
		return rest_request_generic(rest_req, params, "PUT", data, true, this.onLoadDefault, this.onProgressDefault, this.onErrorDefault);
198
	}
108 199
	
109 200
	this.rest_request_head = function(rest_req, params) {
110 201
		return rest_request_generic(rest_req, params, "HEAD", null, false, null, null, null);

Also available in: Unified diff