chore: update base::Bind in app module (#17925)
* chore: update base::Bind in app module * fix lint
This commit is contained in:
parent
68f448ee73
commit
e7ef374899
4 changed files with 101 additions and 81 deletions
|
@ -24,6 +24,7 @@
|
||||||
#include "atom/common/native_mate_converters/image_converter.h"
|
#include "atom/common/native_mate_converters/image_converter.h"
|
||||||
#include "atom/common/native_mate_converters/net_converter.h"
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
#include "atom/common/native_mate_converters/network_converter.h"
|
#include "atom/common/native_mate_converters/network_converter.h"
|
||||||
|
#include "atom/common/native_mate_converters/once_callback.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
|
@ -426,7 +427,7 @@ int GetPathConstant(const std::string& name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotificationCallbackWrapper(
|
bool NotificationCallbackWrapper(
|
||||||
const base::Callback<
|
const base::RepeatingCallback<
|
||||||
void(const base::CommandLine::StringVector& command_line,
|
void(const base::CommandLine::StringVector& command_line,
|
||||||
const base::FilePath& current_directory)>& callback,
|
const base::FilePath& current_directory)>& callback,
|
||||||
const base::CommandLine::StringVector& cmd,
|
const base::CommandLine::StringVector& cmd,
|
||||||
|
@ -485,7 +486,7 @@ void OnClientCertificateSelected(
|
||||||
if (cert->EqualsExcludingChain((*identities)[i]->certificate())) {
|
if (cert->EqualsExcludingChain((*identities)[i]->certificate())) {
|
||||||
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
||||||
std::move((*identities)[i]),
|
std::move((*identities)[i]),
|
||||||
base::Bind(&GotPrivateKey, delegate, std::move(cert)));
|
base::BindRepeating(&GotPrivateKey, delegate, std::move(cert)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -670,10 +671,11 @@ void App::OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
content::WebContents* web_contents = login_handler->GetWebContents();
|
content::WebContents* web_contents = login_handler->GetWebContents();
|
||||||
if (web_contents) {
|
if (web_contents) {
|
||||||
prevent_default = Emit(
|
prevent_default =
|
||||||
"login", WebContents::FromOrCreate(isolate(), web_contents),
|
Emit("login", WebContents::FromOrCreate(isolate(), web_contents),
|
||||||
request_details, *login_handler->auth_info(),
|
request_details, *login_handler->auth_info(),
|
||||||
base::Bind(&PassLoginInformation, base::RetainedRef(login_handler)));
|
base::BindOnce(&PassLoginInformation,
|
||||||
|
base::RetainedRef(login_handler)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default behavior is to always cancel the auth.
|
// Default behavior is to always cancel the auth.
|
||||||
|
@ -721,7 +723,7 @@ void App::AllowCertificateError(
|
||||||
content::ResourceType resource_type,
|
content::ResourceType resource_type,
|
||||||
bool strict_enforcement,
|
bool strict_enforcement,
|
||||||
bool expired_previous_decision,
|
bool expired_previous_decision,
|
||||||
const base::Callback<void(content::CertificateRequestResultType)>&
|
const base::RepeatingCallback<void(content::CertificateRequestResultType)>&
|
||||||
callback) {
|
callback) {
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
@ -755,8 +757,8 @@ void App::SelectClientCertificate(
|
||||||
Emit("select-client-certificate",
|
Emit("select-client-certificate",
|
||||||
WebContents::FromOrCreate(isolate(), web_contents),
|
WebContents::FromOrCreate(isolate(), web_contents),
|
||||||
cert_request_info->host_and_port.ToString(), std::move(client_certs),
|
cert_request_info->host_and_port.ToString(), std::move(client_certs),
|
||||||
base::Bind(&OnClientCertificateSelected, isolate(), shared_delegate,
|
base::BindOnce(&OnClientCertificateSelected, isolate(),
|
||||||
shared_identities));
|
shared_delegate, shared_identities));
|
||||||
|
|
||||||
// Default to first certificate from the platform store.
|
// Default to first certificate from the platform store.
|
||||||
if (!prevent_default) {
|
if (!prevent_default) {
|
||||||
|
@ -764,7 +766,7 @@ void App::SelectClientCertificate(
|
||||||
(*shared_identities)[0]->certificate();
|
(*shared_identities)[0]->certificate();
|
||||||
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
||||||
std::move((*shared_identities)[0]),
|
std::move((*shared_identities)[0]),
|
||||||
base::Bind(&GotPrivateKey, shared_delegate, std::move(cert)));
|
base::BindRepeating(&GotPrivateKey, shared_delegate, std::move(cert)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -947,10 +949,10 @@ bool App::RequestSingleInstanceLock() {
|
||||||
base::FilePath user_dir;
|
base::FilePath user_dir;
|
||||||
base::PathService::Get(DIR_USER_DATA, &user_dir);
|
base::PathService::Get(DIR_USER_DATA, &user_dir);
|
||||||
|
|
||||||
auto cb = base::Bind(&App::OnSecondInstance, base::Unretained(this));
|
auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this));
|
||||||
|
|
||||||
process_singleton_.reset(new ProcessSingleton(
|
process_singleton_.reset(new ProcessSingleton(
|
||||||
user_dir, base::Bind(NotificationCallbackWrapper, cb)));
|
user_dir, base::BindRepeating(NotificationCallbackWrapper, cb)));
|
||||||
|
|
||||||
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
|
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
|
||||||
case ProcessSingleton::NotifyResult::LOCK_ERROR:
|
case ProcessSingleton::NotifyResult::LOCK_ERROR:
|
||||||
|
@ -1063,8 +1065,9 @@ void App::ImportCertificate(const base::DictionaryValue& options,
|
||||||
base::Value::ToUniquePtrValue(options.Clone()));
|
base::Value::ToUniquePtrValue(options.Clone()));
|
||||||
CertificateManagerModel::Create(
|
CertificateManagerModel::Create(
|
||||||
browser_context.get(),
|
browser_context.get(),
|
||||||
base::Bind(&App::OnCertificateManagerModelCreated,
|
base::BindRepeating(&App::OnCertificateManagerModelCreated,
|
||||||
base::Unretained(this), base::Passed(©), callback));
|
base::Unretained(this), base::Passed(©),
|
||||||
|
callback));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1297,20 +1300,25 @@ v8::Local<v8::Value> App::GetDockAPI(v8::Isolate* isolate) {
|
||||||
auto browser = base::Unretained(Browser::Get());
|
auto browser = base::Unretained(Browser::Get());
|
||||||
mate::Dictionary dock_obj = mate::Dictionary::CreateEmpty(isolate);
|
mate::Dictionary dock_obj = mate::Dictionary::CreateEmpty(isolate);
|
||||||
dock_obj.SetMethod("bounce", &DockBounce);
|
dock_obj.SetMethod("bounce", &DockBounce);
|
||||||
dock_obj.SetMethod("cancelBounce",
|
dock_obj.SetMethod(
|
||||||
base::Bind(&Browser::DockCancelBounce, browser));
|
"cancelBounce",
|
||||||
dock_obj.SetMethod("downloadFinished",
|
base::BindRepeating(&Browser::DockCancelBounce, browser));
|
||||||
base::Bind(&Browser::DockDownloadFinished, browser));
|
dock_obj.SetMethod(
|
||||||
dock_obj.SetMethod("setBadge",
|
"downloadFinished",
|
||||||
base::Bind(&Browser::DockSetBadgeText, browser));
|
base::BindRepeating(&Browser::DockDownloadFinished, browser));
|
||||||
dock_obj.SetMethod("getBadge",
|
dock_obj.SetMethod(
|
||||||
base::Bind(&Browser::DockGetBadgeText, browser));
|
"setBadge", base::BindRepeating(&Browser::DockSetBadgeText, browser));
|
||||||
dock_obj.SetMethod("hide", base::Bind(&Browser::DockHide, browser));
|
dock_obj.SetMethod(
|
||||||
dock_obj.SetMethod("show", base::Bind(&Browser::DockShow, browser));
|
"getBadge", base::BindRepeating(&Browser::DockGetBadgeText, browser));
|
||||||
|
dock_obj.SetMethod("hide",
|
||||||
|
base::BindRepeating(&Browser::DockHide, browser));
|
||||||
|
dock_obj.SetMethod("show",
|
||||||
|
base::BindRepeating(&Browser::DockShow, browser));
|
||||||
dock_obj.SetMethod("isVisible",
|
dock_obj.SetMethod("isVisible",
|
||||||
base::Bind(&Browser::DockIsVisible, browser));
|
base::BindRepeating(&Browser::DockIsVisible, browser));
|
||||||
dock_obj.SetMethod("setMenu", &DockSetMenu);
|
dock_obj.SetMethod("setMenu", &DockSetMenu);
|
||||||
dock_obj.SetMethod("setIcon", base::Bind(&Browser::DockSetIcon, browser));
|
dock_obj.SetMethod("setIcon",
|
||||||
|
base::BindRepeating(&Browser::DockSetIcon, browser));
|
||||||
|
|
||||||
dock_.Reset(isolate, dock_obj.GetHandle());
|
dock_.Reset(isolate, dock_obj.GetHandle());
|
||||||
}
|
}
|
||||||
|
@ -1329,72 +1337,82 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "App"));
|
prototype->SetClassName(mate::StringToV8(isolate, "App"));
|
||||||
auto browser = base::Unretained(Browser::Get());
|
auto browser = base::Unretained(Browser::Get());
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
.SetMethod("quit", base::BindRepeating(&Browser::Quit, browser))
|
||||||
.SetMethod("exit", base::Bind(&Browser::Exit, browser))
|
.SetMethod("exit", base::BindRepeating(&Browser::Exit, browser))
|
||||||
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
|
.SetMethod("focus", base::BindRepeating(&Browser::Focus, browser))
|
||||||
.SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser))
|
.SetMethod("getVersion",
|
||||||
.SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser))
|
base::BindRepeating(&Browser::GetVersion, browser))
|
||||||
.SetMethod("getName", base::Bind(&Browser::GetName, browser))
|
.SetMethod("setVersion",
|
||||||
.SetMethod("setName", base::Bind(&Browser::SetName, browser))
|
base::BindRepeating(&Browser::SetVersion, browser))
|
||||||
.SetMethod("isReady", base::Bind(&Browser::is_ready, browser))
|
.SetMethod("getName", base::BindRepeating(&Browser::GetName, browser))
|
||||||
.SetMethod("whenReady", base::Bind(&Browser::WhenReady, browser))
|
.SetMethod("setName", base::BindRepeating(&Browser::SetName, browser))
|
||||||
|
.SetMethod("isReady", base::BindRepeating(&Browser::is_ready, browser))
|
||||||
|
.SetMethod("whenReady", base::BindRepeating(&Browser::WhenReady, browser))
|
||||||
.SetMethod("addRecentDocument",
|
.SetMethod("addRecentDocument",
|
||||||
base::Bind(&Browser::AddRecentDocument, browser))
|
base::BindRepeating(&Browser::AddRecentDocument, browser))
|
||||||
.SetMethod("clearRecentDocuments",
|
.SetMethod("clearRecentDocuments",
|
||||||
base::Bind(&Browser::ClearRecentDocuments, browser))
|
base::BindRepeating(&Browser::ClearRecentDocuments, browser))
|
||||||
.SetMethod("setAppUserModelId",
|
.SetMethod("setAppUserModelId",
|
||||||
base::Bind(&Browser::SetAppUserModelID, browser))
|
base::Bind(&Browser::SetAppUserModelID, browser))
|
||||||
.SetMethod("isDefaultProtocolClient",
|
.SetMethod(
|
||||||
base::Bind(&Browser::IsDefaultProtocolClient, browser))
|
"isDefaultProtocolClient",
|
||||||
.SetMethod("setAsDefaultProtocolClient",
|
base::BindRepeating(&Browser::IsDefaultProtocolClient, browser))
|
||||||
base::Bind(&Browser::SetAsDefaultProtocolClient, browser))
|
.SetMethod(
|
||||||
.SetMethod("removeAsDefaultProtocolClient",
|
"setAsDefaultProtocolClient",
|
||||||
base::Bind(&Browser::RemoveAsDefaultProtocolClient, browser))
|
base::BindRepeating(&Browser::SetAsDefaultProtocolClient, browser))
|
||||||
.SetMethod("_setBadgeCount", base::Bind(&Browser::SetBadgeCount, browser))
|
.SetMethod(
|
||||||
.SetMethod("_getBadgeCount", base::Bind(&Browser::GetBadgeCount, browser))
|
"removeAsDefaultProtocolClient",
|
||||||
|
base::BindRepeating(&Browser::RemoveAsDefaultProtocolClient, browser))
|
||||||
|
.SetMethod("_setBadgeCount",
|
||||||
|
base::BindRepeating(&Browser::SetBadgeCount, browser))
|
||||||
|
.SetMethod("_getBadgeCount",
|
||||||
|
base::BindRepeating(&Browser::GetBadgeCount, browser))
|
||||||
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
|
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
|
||||||
.SetMethod("setLoginItemSettings",
|
.SetMethod("setLoginItemSettings",
|
||||||
base::Bind(&Browser::SetLoginItemSettings, browser))
|
base::BindRepeating(&Browser::SetLoginItemSettings, browser))
|
||||||
.SetMethod("isEmojiPanelSupported",
|
.SetMethod("isEmojiPanelSupported",
|
||||||
base::Bind(&Browser::IsEmojiPanelSupported, browser))
|
base::BindRepeating(&Browser::IsEmojiPanelSupported, browser))
|
||||||
.SetProperty("badgeCount", base::Bind(&Browser::GetBadgeCount, browser),
|
.SetProperty("badgeCount",
|
||||||
base::Bind(&Browser::SetBadgeCount, browser))
|
base::BindRepeating(&Browser::GetBadgeCount, browser),
|
||||||
|
base::BindRepeating(&Browser::SetBadgeCount, browser))
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
.SetMethod("hide", base::Bind(&Browser::Hide, browser))
|
.SetMethod("hide", base::BindRepeating(&Browser::Hide, browser))
|
||||||
.SetMethod("show", base::Bind(&Browser::Show, browser))
|
.SetMethod("show", base::BindRepeating(&Browser::Show, browser))
|
||||||
.SetMethod("setUserActivity",
|
.SetMethod("setUserActivity",
|
||||||
base::Bind(&Browser::SetUserActivity, browser))
|
base::BindRepeating(&Browser::SetUserActivity, browser))
|
||||||
.SetMethod("getCurrentActivityType",
|
.SetMethod("getCurrentActivityType",
|
||||||
base::Bind(&Browser::GetCurrentActivityType, browser))
|
base::BindRepeating(&Browser::GetCurrentActivityType, browser))
|
||||||
.SetMethod("invalidateCurrentActivity",
|
.SetMethod(
|
||||||
base::Bind(&Browser::InvalidateCurrentActivity, browser))
|
"invalidateCurrentActivity",
|
||||||
|
base::BindRepeating(&Browser::InvalidateCurrentActivity, browser))
|
||||||
.SetMethod("updateCurrentActivity",
|
.SetMethod("updateCurrentActivity",
|
||||||
base::Bind(&Browser::UpdateCurrentActivity, browser))
|
base::BindRepeating(&Browser::UpdateCurrentActivity, browser))
|
||||||
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
|
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
|
||||||
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
||||||
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
||||||
.SetMethod("setAboutPanelOptions",
|
.SetMethod("setAboutPanelOptions",
|
||||||
base::Bind(&Browser::SetAboutPanelOptions, browser))
|
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
|
||||||
.SetMethod("showAboutPanel",
|
.SetMethod("showAboutPanel",
|
||||||
base::Bind(&Browser::ShowAboutPanel, browser))
|
base::BindRepeating(&Browser::ShowAboutPanel, browser))
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_MACOSX) || defined(OS_WIN)
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
||||||
.SetMethod("showEmojiPanel",
|
.SetMethod("showEmojiPanel",
|
||||||
base::Bind(&Browser::ShowEmojiPanel, browser))
|
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
|
||||||
.SetProperty("accessibilitySupportEnabled",
|
.SetProperty("accessibilitySupportEnabled",
|
||||||
&App::IsAccessibilitySupportEnabled,
|
&App::IsAccessibilitySupportEnabled,
|
||||||
&App::SetAccessibilitySupportEnabled)
|
&App::SetAccessibilitySupportEnabled)
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
.SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser))
|
.SetMethod("setUserTasks",
|
||||||
|
base::BindRepeating(&Browser::SetUserTasks, browser))
|
||||||
.SetMethod("getJumpListSettings", &App::GetJumpListSettings)
|
.SetMethod("getJumpListSettings", &App::GetJumpListSettings)
|
||||||
.SetMethod("setJumpList", &App::SetJumpList)
|
.SetMethod("setJumpList", &App::SetJumpList)
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
.SetMethod("isUnityRunning",
|
.SetMethod("isUnityRunning",
|
||||||
base::Bind(&Browser::IsUnityRunning, browser))
|
base::BindRepeating(&Browser::IsUnityRunning, browser))
|
||||||
#endif
|
#endif
|
||||||
.SetMethod("setAppPath", &App::SetAppPath)
|
.SetMethod("setAppPath", &App::SetAppPath)
|
||||||
.SetMethod("getAppPath", &App::GetAppPath)
|
.SetMethod("getAppPath", &App::GetAppPath)
|
||||||
|
|
|
@ -69,7 +69,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
public content::BrowserChildProcessObserver {
|
public content::BrowserChildProcessObserver {
|
||||||
public:
|
public:
|
||||||
using FileIconCallback =
|
using FileIconCallback =
|
||||||
base::Callback<void(v8::Local<v8::Value>, const gfx::Image&)>;
|
base::RepeatingCallback<void(v8::Local<v8::Value>, const gfx::Image&)>;
|
||||||
|
|
||||||
static mate::Handle<App> Create(v8::Isolate* isolate);
|
static mate::Handle<App> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
@ -133,8 +133,8 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
content::ResourceType resource_type,
|
content::ResourceType resource_type,
|
||||||
bool strict_enforcement,
|
bool strict_enforcement,
|
||||||
bool expired_previous_decision,
|
bool expired_previous_decision,
|
||||||
const base::Callback<void(content::CertificateRequestResultType)>&
|
const base::RepeatingCallback<
|
||||||
callback) override;
|
void(content::CertificateRequestResultType)>& callback) override;
|
||||||
void SelectClientCertificate(
|
void SelectClientCertificate(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
net::SSLCertRequestInfo* cert_request_info,
|
net::SSLCertRequestInfo* cert_request_info,
|
||||||
|
|
|
@ -51,25 +51,25 @@ class EventEmitter : public Wrappable<T> {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
bool EmitCustomEvent(const base::StringPiece& name,
|
bool EmitCustomEvent(const base::StringPiece& name,
|
||||||
v8::Local<v8::Object> event,
|
v8::Local<v8::Object> event,
|
||||||
const Args&... args) {
|
Args&&... args) {
|
||||||
return EmitWithEvent(
|
return EmitWithEvent(
|
||||||
name, internal::CreateCustomEvent(isolate(), GetWrapper(), event),
|
name, internal::CreateCustomEvent(isolate(), GetWrapper(), event),
|
||||||
args...);
|
std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.emit(name, new Event(flags), args...);
|
// this.emit(name, new Event(flags), args...);
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
bool EmitWithFlags(const base::StringPiece& name,
|
bool EmitWithFlags(const base::StringPiece& name, int flags, Args&&... args) {
|
||||||
int flags,
|
return EmitCustomEvent(name,
|
||||||
const Args&... args) {
|
internal::CreateEventFromFlags(isolate(), flags),
|
||||||
return EmitCustomEvent(
|
std::forward<Args>(args)...);
|
||||||
name, internal::CreateEventFromFlags(isolate(), flags), args...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.emit(name, new Event(), args...);
|
// this.emit(name, new Event(), args...);
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
bool Emit(const base::StringPiece& name, const Args&... args) {
|
bool Emit(const base::StringPiece& name, Args&&... args) {
|
||||||
return EmitWithSender(name, nullptr, base::nullopt, args...);
|
return EmitWithSender(name, nullptr, base::nullopt,
|
||||||
|
std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.emit(name, new Event(sender, message), args...);
|
// this.emit(name, new Event(sender, message), args...);
|
||||||
|
@ -79,7 +79,7 @@ class EventEmitter : public Wrappable<T> {
|
||||||
content::RenderFrameHost* sender,
|
content::RenderFrameHost* sender,
|
||||||
base::Optional<atom::mojom::ElectronBrowser::MessageSyncCallback>
|
base::Optional<atom::mojom::ElectronBrowser::MessageSyncCallback>
|
||||||
callback,
|
callback,
|
||||||
const Args&... args) {
|
Args&&... args) {
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::Local<v8::Object> wrapper = GetWrapper();
|
v8::Local<v8::Object> wrapper = GetWrapper();
|
||||||
|
@ -88,7 +88,7 @@ class EventEmitter : public Wrappable<T> {
|
||||||
}
|
}
|
||||||
v8::Local<v8::Object> event = internal::CreateJSEvent(
|
v8::Local<v8::Object> event = internal::CreateJSEvent(
|
||||||
isolate(), wrapper, sender, std::move(callback));
|
isolate(), wrapper, sender, std::move(callback));
|
||||||
return EmitWithEvent(name, event, args...);
|
return EmitWithEvent(name, event, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -99,11 +99,12 @@ class EventEmitter : public Wrappable<T> {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
bool EmitWithEvent(const base::StringPiece& name,
|
bool EmitWithEvent(const base::StringPiece& name,
|
||||||
v8::Local<v8::Object> event,
|
v8::Local<v8::Object> event,
|
||||||
const Args&... args) {
|
Args&&... args) {
|
||||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
EmitEvent(isolate(), GetWrapper(), name, event, args...);
|
EmitEvent(isolate(), GetWrapper(), name, event,
|
||||||
|
std::forward<Args>(args)...);
|
||||||
return event->Get(StringToV8(isolate(), "defaultPrevented"))
|
return event->Get(StringToV8(isolate(), "defaultPrevented"))
|
||||||
->BooleanValue(isolate());
|
->BooleanValue(isolate());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#ifndef ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
|
#ifndef ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
|
||||||
#define ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
|
#define ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
|
@ -42,10 +43,10 @@ template <typename StringType, typename... Args>
|
||||||
v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> obj,
|
v8::Local<v8::Object> obj,
|
||||||
const StringType& name,
|
const StringType& name,
|
||||||
const Args&... args) {
|
Args&&... args) {
|
||||||
internal::ValueVector converted_args = {
|
internal::ValueVector converted_args = {
|
||||||
StringToV8(isolate, name),
|
StringToV8(isolate, name),
|
||||||
ConvertToV8(isolate, args)...,
|
ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||||
};
|
};
|
||||||
return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
|
return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
|
||||||
}
|
}
|
||||||
|
@ -55,9 +56,9 @@ template <typename... Args>
|
||||||
v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
|
v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> object,
|
v8::Local<v8::Object> object,
|
||||||
const char* custom_emit,
|
const char* custom_emit,
|
||||||
const Args&... args) {
|
Args&&... args) {
|
||||||
internal::ValueVector converted_args = {
|
internal::ValueVector converted_args = {
|
||||||
ConvertToV8(isolate, args)...,
|
ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||||
};
|
};
|
||||||
return internal::CallMethodWithArgs(isolate, object, custom_emit,
|
return internal::CallMethodWithArgs(isolate, object, custom_emit,
|
||||||
&converted_args);
|
&converted_args);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue