feat: promisify webContents.savePage() (#16742)
* feat: promisify webContents.savePage() * no need to make compatible w callbacks, we're breaking it * fix promise resolve type * address feedback from review * fix promise return text * update smoke test
This commit is contained in:
parent
6e7dca9082
commit
de27911661
9 changed files with 35 additions and 40 deletions
|
@ -16,8 +16,8 @@ namespace atom {
|
|||
namespace api {
|
||||
|
||||
SavePageHandler::SavePageHandler(content::WebContents* web_contents,
|
||||
const SavePageCallback& callback)
|
||||
: web_contents_(web_contents), callback_(callback) {}
|
||||
scoped_refptr<atom::util::Promise> promise)
|
||||
: web_contents_(web_contents), promise_(promise) {}
|
||||
|
||||
SavePageHandler::~SavePageHandler() {}
|
||||
|
||||
|
@ -50,16 +50,10 @@ bool SavePageHandler::Handle(const base::FilePath& full_path,
|
|||
|
||||
void SavePageHandler::OnDownloadUpdated(download::DownloadItem* item) {
|
||||
if (item->IsDone()) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
if (item->GetState() == download::DownloadItem::COMPLETE) {
|
||||
callback_.Run(v8::Null(isolate));
|
||||
} else {
|
||||
v8::Local<v8::String> error_message =
|
||||
v8::String::NewFromUtf8(isolate, "Fail to save page");
|
||||
callback_.Run(v8::Exception::Error(error_message));
|
||||
}
|
||||
if (item->GetState() == download::DownloadItem::COMPLETE)
|
||||
promise_->Resolve();
|
||||
else
|
||||
promise_->RejectWithErrorMessage("Failed to save the page.");
|
||||
Destroy(item);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue