Make callback aligns node.js style.

This commit is contained in:
Haojian Wu 2015-06-10 20:07:14 +08:00
parent 93243ef223
commit ccbe554ec0
2 changed files with 8 additions and 3 deletions

View file

@ -52,7 +52,9 @@ class WebContents : public mate::EventEmitter,
public content::WebContentsObserver,
public content::GpuDataManagerObserver {
public:
typedef base::Callback<void(v8::Local<v8::Value>)> PrintToPDFCallback;
// For node.js callback function type: function(error, buffer)
typedef base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>
PrintToPDFCallback;
// Create from an existing WebContents.
static mate::Handle<WebContents> CreateFrom(

View file

@ -130,9 +130,12 @@ void PrintPreviewMessageHandler::RunPrintToPDFCallback(
v8::Local<v8::Value> buffer = node::Buffer::Use(
const_cast<char*>(reinterpret_cast<const char*>(data->front())),
data->size());
print_to_pdf_callback_map_[request_id].Run(buffer);
print_to_pdf_callback_map_[request_id].Run(v8::Null(isolate), buffer);
} else {
print_to_pdf_callback_map_[request_id].Run(v8::Null(isolate));
v8::Local<v8::String> error_message = v8::String::NewFromUtf8(isolate,
"Fail to generate PDF");
print_to_pdf_callback_map_[request_id].Run(
v8::Exception::Error(error_message), v8::Null(isolate));
}
print_to_pdf_callback_map_.erase(request_id);
}