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:
Shelley Vohr 2019-02-14 09:03:28 -08:00 committed by GitHub
parent 6e7dca9082
commit de27911661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 40 deletions

View file

@ -1300,11 +1300,17 @@ std::string WebContents::GetUserAgent() {
return web_contents()->GetUserAgentOverride();
}
bool WebContents::SavePage(const base::FilePath& full_file_path,
const content::SavePageType& save_type,
const SavePageHandler::SavePageCallback& callback) {
auto* handler = new SavePageHandler(web_contents(), callback);
return handler->Handle(full_file_path, save_type);
v8::Local<v8::Promise> WebContents::SavePage(
const base::FilePath& full_file_path,
const content::SavePageType& save_type) {
scoped_refptr<util::Promise> promise = new util::Promise(isolate());
auto* handler = new SavePageHandler(web_contents(), promise);
const bool saveStarted = handler->Handle(full_file_path, save_type);
if (!saveStarted)
promise->RejectWithErrorMessage("Failed to save the page");
return promise->GetHandle();
}
void WebContents::OpenDevTools(mate::Arguments* args) {