use base::Owned instead of base::Passed for repeating handler

This commit is contained in:
Jeremy Apthorp 2019-05-03 14:20:43 -07:00 committed by Nitish Sakhawalkar
parent 6c6555c13c
commit 6f0524d87f

View file

@ -457,23 +457,28 @@ void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
using RequestHandler =
base::Callback<void(content::WebContents*, content::PermissionType,
StatusCallback, const base::DictionaryValue&)>;
RequestHandler handler;
if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &handler))) {
auto* permission_manager = static_cast<AtomPermissionManager*>(
browser_context()->GetPermissionControllerDelegate());
if (val->IsNull()) {
permission_manager->SetPermissionRequestHandler(
AtomPermissionManager::RequestHandler());
return;
}
auto handler = std::make_unique<RequestHandler>();
if (!mate::ConvertFromV8(args->isolate(), val, handler.get())) {
args->ThrowError("Must pass null or function");
return;
}
auto* permission_manager = static_cast<AtomPermissionManager*>(
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<v8::Value> val,