From 6f0524d87f9add9dbcd47476b3ff77a1f1eeff08 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Fri, 3 May 2019 14:20:43 -0700 Subject: [PATCH] use base::Owned instead of base::Passed for repeating handler --- atom/browser/api/atom_api_session.cc | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 9f94b09e0099..3e7015e05bb4 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -457,23 +457,28 @@ void Session::SetPermissionRequestHandler(v8::Local val, using RequestHandler = base::Callback; - RequestHandler handler; - if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &handler))) { + auto* permission_manager = static_cast( + browser_context()->GetPermissionControllerDelegate()); + if (val->IsNull()) { + permission_manager->SetPermissionRequestHandler( + AtomPermissionManager::RequestHandler()); + return; + } + auto handler = std::make_unique(); + if (!mate::ConvertFromV8(args->isolate(), val, handler.get())) { args->ThrowError("Must pass null or function"); return; } - auto* permission_manager = static_cast( - browser_context()->GetPermissionControllerDelegate()); permission_manager->SetPermissionRequestHandler(base::BindRepeating( - [](const RequestHandler& handler, content::WebContents* web_contents, + [](RequestHandler* handler, content::WebContents* web_contents, content::PermissionType permission_type, AtomPermissionManager::StatusCallback callback, const base::DictionaryValue& details) { - handler.Run(web_contents, permission_type, - base::AdaptCallbackForRepeating(std::move(callback)), - details); + handler->Run(web_contents, permission_type, + base::AdaptCallbackForRepeating(std::move(callback)), + details); }, - base::Passed(std::move(handler)))); + base::Owned(std::move(handler)))); } void Session::SetPermissionCheckHandler(v8::Local val,