chore: make util::Promise a move-only type (#17071)

This commit is contained in:
Cheng Zhao 2019-02-21 12:32:44 +00:00 committed by GitHub
parent a40d826b11
commit 32a4de4a68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 325 additions and 260 deletions

View file

@ -241,12 +241,11 @@ namespace api {
namespace {
// Called when CapturePage is done.
void OnCapturePageDone(scoped_refptr<util::Promise> promise,
const SkBitmap& bitmap) {
void OnCapturePageDone(util::Promise promise, const SkBitmap& bitmap) {
// Hack to enable transparency in captured image
// TODO(nitsakh) Remove hack once fixed in chromium
const_cast<SkBitmap&>(bitmap).setAlphaType(kPremul_SkAlphaType);
promise->Resolve(gfx::Image::CreateFrom1xBitmap(bitmap));
promise.Resolve(gfx::Image::CreateFrom1xBitmap(bitmap));
}
} // namespace
@ -1302,14 +1301,12 @@ std::string WebContents::GetUserAgent() {
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);
util::Promise promise(isolate());
v8::Local<v8::Promise> ret = promise.GetHandle();
const bool saveStarted = handler->Handle(full_file_path, save_type);
if (!saveStarted)
promise->RejectWithErrorMessage("Failed to save the page");
return promise->GetHandle();
auto* handler = new SavePageHandler(web_contents(), std::move(promise));
handler->Handle(full_file_path, save_type);
return ret;
}
void WebContents::OpenDevTools(mate::Arguments* args) {
@ -1506,10 +1503,11 @@ std::vector<printing::PrinterBasicInfo> WebContents::GetPrinterList() {
v8::Local<v8::Promise> WebContents::PrintToPDF(
const base::DictionaryValue& settings) {
scoped_refptr<util::Promise> promise = new util::Promise(isolate());
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
PrintPreviewMessageHandler::FromWebContents(web_contents())
->PrintToPDF(settings, promise);
return promise->GetHandle();
->PrintToPDF(settings, std::move(promise));
return handle;
}
#endif
@ -1780,15 +1778,16 @@ void WebContents::StartDrag(const mate::Dictionary& item,
v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* args) {
gfx::Rect rect;
scoped_refptr<util::Promise> promise = new util::Promise(isolate());
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
// get rect arguments if they exist
args->GetNext(&rect);
auto* const view = web_contents()->GetRenderWidgetHostView();
if (!view) {
promise->Resolve(gfx::Image());
return promise->GetHandle();
promise.Resolve(gfx::Image());
return handle;
}
// Capture full page if user doesn't specify a |rect|.
@ -1807,8 +1806,8 @@ v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* args) {
bitmap_size = gfx::ScaleToCeiledSize(view_size, scale);
view->CopyFromSurface(gfx::Rect(rect.origin(), view_size), bitmap_size,
base::BindOnce(&OnCapturePageDone, promise));
return promise->GetHandle();
base::BindOnce(&OnCapturePageDone, std::move(promise)));
return handle;
}
void WebContents::OnCursorChange(const content::WebCursor& cursor) {