typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
+scoped_refptr<base::RefCountedBytes> BufferToRefCountedBytes(
+ v8::Local<v8::Value> buf) {
+ scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes);
+ auto start = reinterpret_cast<const unsigned char*>(node::Buffer::Data(buf));
+ data->data().assign(start, start + node::Buffer::Length(buf));
+ return data;
+}
+
class CustomProtocolRequestJob : public AdapterRequestJob {
public:
CustomProtocolRequestJob(Protocol* registry,
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&AdapterRequestJob::CreateBufferJobAndStart,
- GetWeakPtr(), mime_type, encoding, buffer->ToObject()));
+ GetWeakPtr(), mime_type, encoding,
+ BufferToRefCountedBytes(buffer)));
return;
} else if (name == "RequestFileJob") {
base::FilePath path;
}
void AdapterRequestJob::CreateErrorJobAndStart(int error_code) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
-
real_job_ = new net::URLRequestErrorJob(
request(), network_delegate(), error_code);
real_job_->Start();
void AdapterRequestJob::CreateStringJobAndStart(const std::string& mime_type,
const std::string& charset,
const std::string& data) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
-
real_job_ = new URLRequestStringJob(
request(), network_delegate(), mime_type, charset, data);
real_job_->Start();
}
-void AdapterRequestJob::CreateBufferJobAndStart(const std::string& mime_type,
- const std::string& charset,
- v8::Local<v8::Object> buffer) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
-
+void AdapterRequestJob::CreateBufferJobAndStart(
+ const std::string& mime_type,
+ const std::string& charset,
+ scoped_refptr<base::RefCountedBytes> data) {
real_job_ = new URLRequestBufferJob(
- request(), network_delegate(), mime_type, charset, buffer);
+ request(), network_delegate(), mime_type, charset, data);
real_job_->Start();
}
void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
real_job_ = asar::CreateJobFromPath(
path,
request(),
}
void AdapterRequestJob::CreateJobFromProtocolHandlerAndStart() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- DCHECK(protocol_handler_);
real_job_ = protocol_handler_->MaybeCreateJob(request(),
network_delegate());
if (!real_job_.get())
#include <string>
+#include "base/memory/ref_counted_memory.h"
#include "base/memory/weak_ptr.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
const std::string& data);
void CreateBufferJobAndStart(const std::string& mime_type,
const std::string& charset,
- v8::Local<v8::Object> buffer);
+ scoped_refptr<base::RefCountedBytes> data);
void CreateFileJobAndStart(const base::FilePath& path);
void CreateJobFromProtocolHandlerAndStart();
namespace atom {
-URLRequestBufferJob::URLRequestBufferJob(net::URLRequest* request,
- net::NetworkDelegate* network_delegate,
- const std::string& mime_type,
- const std::string& charset,
- v8::Local<v8::Object> data)
+URLRequestBufferJob::URLRequestBufferJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate,
+ const std::string& mime_type,
+ const std::string& charset,
+ scoped_refptr<base::RefCountedBytes> data)
: net::URLRequestSimpleJob(request, network_delegate),
mime_type_(mime_type),
charset_(charset),
- buffer_data_(new base::RefCountedBytes()) {
- auto input = reinterpret_cast<const unsigned char*>(node::Buffer::Data(data));
- size_t length = node::Buffer::Length(data);
- buffer_data_->data().assign(input, input + length);
+ buffer_data_(data) {
}
int URLRequestBufferJob::GetRefCountedData(
net::NetworkDelegate* network_delegate,
const std::string& mime_type,
const std::string& charset,
- v8::Local<v8::Object> buffer);
+ scoped_refptr<base::RefCountedBytes> data);
// URLRequestSimpleJob:
int GetRefCountedData(std::string* mime_type,
-Subproject commit 269be869988bda9a7e8ad0ef56af178a741af09c
+Subproject commit 1696237a3f444f0e33a8947749b4d70f6feb511b