case REQUEST_STRING_JOB:
return static_cast<URLRequestStringJob*>(real_job_.get())->
ReadRawData(buf, buf_size, bytes_read);
+ case REQUEST_FILE_JOB:
+ return static_cast<net::URLRequestFileJob*>(real_job_.get())->
+ ReadRawData(buf, buf_size, bytes_read);
default:
return net::URLRequestJob::ReadRawData(buf, buf_size, bytes_read);
}
charset,
data));
return;
+ } else if (name == "RequestFileJob") {
+ base::FilePath path = base::FilePath::FromUTF8Unsafe(
+ *v8::String::Utf8Value(obj->Get(v8::String::New("path"))));
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&AdapterRequestJob::CreateFileJobAndStart,
+ weak_factory_.GetWeakPtr(),
+ path));
+ return;
}
}
real_job_->Start();
}
+ void CreateFileJobAndStart(const base::FilePath& path) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+
+ type_ = REQUEST_FILE_JOB;
+ real_job_ = new net::URLRequestFileJob(request(), network_delegate(), path);
+ real_job_->Start();
+ }
+
scoped_refptr<net::URLRequestJob> real_job_;
// Type of the delegated url request job.
@mimeType = mimeType ? 'text/plain'
@charset = charset ? 'UTF-8'
@data = String data
+
+module.exports.RequestFileJob =
+class RequestFileJob
+ constructor: (@path) ->
it 'calls the callback when scheme is visited', (done) ->
protocol.registerProtocol 'test2', (url) ->
assert.equal url, 'test2://test2'
+ protocol.unregisterProtocol 'test2'
done()
$.get 'test2://test2', ->
- protocol.unregisterProtocol 'test2'
describe 'protocol.unregisterProtocol', ->
it 'throws error when scheme does not exist', ->
done()
error: (xhr, errorType, error) ->
assert false, 'Got error: ' + errorType + ' ' + error
+
+ it 'returns RequestFileJob should send file', (done) ->
+ $.ajax
+ url: 'atom-file-job://' + __filename
+ success: (data) ->
+ console.log data
+ done()
+ error: (xhr, errorType, error) ->
+ assert false, 'Got error: ' + errorType + ' ' + error
protocol.registerProtocol('atom-string-job', function(url) {
return new protocol.RequestStringJob({mimeType: 'text/html', data: url});
});
+
+ protocol.registerProtocol('atom-file-job', function(url) {
+ return new protocol.RequestFileJob(url.substr(16));
+ });
});
app.on('finish-launching', function() {