зеркало из https://github.com/electron/electron.git
refactor: make util::Promise type safe when chaining in native (#19809)
* refactor: make util::Promise type safe when chaining in native * fixup! refactor: make util::Promise type safe when chaining in native * chore: remove spare brackets
This commit is contained in:
Родитель
f7e3e1f97a
Коммит
6a3922d330
|
@ -532,7 +532,7 @@ int ImportIntoCertStore(CertificateManagerModel* model,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void OnIconDataAvailable(util::Promise promise, gfx::Image icon) {
|
void OnIconDataAvailable(util::Promise<gfx::Image> promise, gfx::Image icon) {
|
||||||
if (!icon.IsEmpty()) {
|
if (!icon.IsEmpty()) {
|
||||||
promise.Resolve(icon);
|
promise.Resolve(icon);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1167,7 +1167,7 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
|
||||||
|
|
||||||
v8::Local<v8::Promise> App::GetFileIcon(const base::FilePath& path,
|
v8::Local<v8::Promise> App::GetFileIcon(const base::FilePath& path,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<gfx::Image> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
base::FilePath normalized_path = path.NormalizePathSeparators();
|
base::FilePath normalized_path = path.NormalizePathSeparators();
|
||||||
|
|
||||||
|
@ -1272,7 +1272,7 @@ v8::Local<v8::Value> App::GetGPUFeatureStatus(v8::Isolate* isolate) {
|
||||||
v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
|
v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
|
||||||
const std::string& info_type) {
|
const std::string& info_type) {
|
||||||
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
|
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
|
||||||
util::Promise promise(isolate);
|
util::Promise<base::DictionaryValue> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
if (info_type != "basic" && info_type != "complete") {
|
if (info_type != "basic" && info_type != "complete") {
|
||||||
promise.RejectWithErrorMessage(
|
promise.RejectWithErrorMessage(
|
||||||
|
|
|
@ -64,13 +64,13 @@ base::Optional<base::FilePath> CreateTemporaryFileOnIO() {
|
||||||
return base::make_optional(std::move(temp_file_path));
|
return base::make_optional(std::move(temp_file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopTracing(electron::util::Promise promise,
|
void StopTracing(electron::util::Promise<base::FilePath> promise,
|
||||||
base::Optional<base::FilePath> file_path) {
|
base::Optional<base::FilePath> file_path) {
|
||||||
if (file_path) {
|
if (file_path) {
|
||||||
auto endpoint = TracingController::CreateFileEndpoint(
|
auto endpoint = TracingController::CreateFileEndpoint(
|
||||||
*file_path,
|
*file_path,
|
||||||
base::AdaptCallbackForRepeating(base::BindOnce(
|
base::AdaptCallbackForRepeating(base::BindOnce(
|
||||||
&electron::util::Promise::ResolvePromise<base::FilePath>,
|
&electron::util::Promise<base::FilePath>::ResolvePromise,
|
||||||
std::move(promise), *file_path)));
|
std::move(promise), *file_path)));
|
||||||
TracingController::GetInstance()->StopTracing(endpoint);
|
TracingController::GetInstance()->StopTracing(endpoint);
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,7 +80,7 @@ void StopTracing(electron::util::Promise promise,
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> StopRecording(mate::Arguments* args) {
|
v8::Local<v8::Promise> StopRecording(mate::Arguments* args) {
|
||||||
electron::util::Promise promise(args->isolate());
|
electron::util::Promise<base::FilePath> promise(args->isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
|
@ -98,12 +98,12 @@ v8::Local<v8::Promise> StopRecording(mate::Arguments* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
|
v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<const std::set<std::string>&> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
// Note: This method always succeeds.
|
// Note: This method always succeeds.
|
||||||
TracingController::GetInstance()->GetCategories(base::BindOnce(
|
TracingController::GetInstance()->GetCategories(base::BindOnce(
|
||||||
electron::util::Promise::ResolvePromise<const std::set<std::string>&>,
|
electron::util::Promise<const std::set<std::string>&>::ResolvePromise,
|
||||||
std::move(promise)));
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -112,34 +112,35 @@ v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
|
||||||
v8::Local<v8::Promise> StartTracing(
|
v8::Local<v8::Promise> StartTracing(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const base::trace_event::TraceConfig& trace_config) {
|
const base::trace_event::TraceConfig& trace_config) {
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (!TracingController::GetInstance()->StartTracing(
|
if (!TracingController::GetInstance()->StartTracing(
|
||||||
trace_config,
|
trace_config,
|
||||||
base::BindOnce(electron::util::Promise::ResolveEmptyPromise,
|
base::BindOnce(electron::util::Promise<void*>::ResolveEmptyPromise,
|
||||||
std::move(promise)))) {
|
std::move(promise)))) {
|
||||||
// If StartTracing returns false, that means it didn't invoke its callback.
|
// If StartTracing returns false, that means it didn't invoke its callback.
|
||||||
// Return an already-resolved promise and abandon the previous promise (it
|
// Return an already-resolved promise and abandon the previous promise (it
|
||||||
// was std::move()d into the StartTracing callback and has been deleted by
|
// was std::move()d into the StartTracing callback and has been deleted by
|
||||||
// this point).
|
// this point).
|
||||||
return electron::util::Promise::ResolvedPromise(isolate);
|
return electron::util::Promise<void*>::ResolvedPromise(isolate);
|
||||||
}
|
}
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTraceBufferUsageAvailable(electron::util::Promise promise,
|
void OnTraceBufferUsageAvailable(
|
||||||
float percent_full,
|
electron::util::Promise<mate::Dictionary> promise,
|
||||||
size_t approximate_count) {
|
float percent_full,
|
||||||
|
size_t approximate_count) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("percentage", percent_full);
|
dict.Set("percentage", percent_full);
|
||||||
dict.Set("value", approximate_count);
|
dict.Set("value", approximate_count);
|
||||||
|
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> GetTraceBufferUsage(v8::Isolate* isolate) {
|
v8::Local<v8::Promise> GetTraceBufferUsage(v8::Isolate* isolate) {
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<mate::Dictionary> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
// Note: This method always succeeds.
|
// Note: This method always succeeds.
|
||||||
|
|
|
@ -121,7 +121,7 @@ bool MatchesCookie(const base::Value& filter,
|
||||||
|
|
||||||
// Remove cookies from |list| not matching |filter|, and pass it to |callback|.
|
// Remove cookies from |list| not matching |filter|, and pass it to |callback|.
|
||||||
void FilterCookies(const base::Value& filter,
|
void FilterCookies(const base::Value& filter,
|
||||||
util::Promise promise,
|
util::Promise<net::CookieList> promise,
|
||||||
const net::CookieList& list,
|
const net::CookieList& list,
|
||||||
const net::CookieStatusList& excluded_list) {
|
const net::CookieStatusList& excluded_list) {
|
||||||
net::CookieList result;
|
net::CookieList result;
|
||||||
|
@ -130,7 +130,7 @@ void FilterCookies(const base::Value& filter,
|
||||||
result.push_back(cookie);
|
result.push_back(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.Resolve(gin::ConvertToV8(promise.isolate(), result));
|
promise.ResolveWithGin(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InclusionStatusToString(
|
std::string InclusionStatusToString(
|
||||||
|
@ -170,7 +170,7 @@ Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||||
Cookies::~Cookies() {}
|
Cookies::~Cookies() {}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Cookies::Get(const base::DictionaryValue& filter) {
|
v8::Local<v8::Promise> Cookies::Get(const base::DictionaryValue& filter) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<net::CookieList> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
std::string url_string;
|
std::string url_string;
|
||||||
|
@ -206,7 +206,7 @@ v8::Local<v8::Promise> Cookies::Get(const base::DictionaryValue& filter) {
|
||||||
|
|
||||||
v8::Local<v8::Promise> Cookies::Remove(const GURL& url,
|
v8::Local<v8::Promise> Cookies::Remove(const GURL& url,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<void*> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
auto cookie_deletion_filter = network::mojom::CookieDeletionFilter::New();
|
auto cookie_deletion_filter = network::mojom::CookieDeletionFilter::New();
|
||||||
|
@ -220,8 +220,8 @@ v8::Local<v8::Promise> Cookies::Remove(const GURL& url,
|
||||||
manager->DeleteCookies(
|
manager->DeleteCookies(
|
||||||
std::move(cookie_deletion_filter),
|
std::move(cookie_deletion_filter),
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](util::Promise promise, uint32_t num_deleted) {
|
[](util::Promise<void*> promise, uint32_t num_deleted) {
|
||||||
util::Promise::ResolveEmptyPromise(std::move(promise));
|
util::Promise<void*>::ResolveEmptyPromise(std::move(promise));
|
||||||
},
|
},
|
||||||
std::move(promise)));
|
std::move(promise)));
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ v8::Local<v8::Promise> Cookies::Remove(const GURL& url,
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Cookies::Set(const base::DictionaryValue& details) {
|
v8::Local<v8::Promise> Cookies::Set(const base::DictionaryValue& details) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<void*> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
const std::string* url_string = details.FindStringKey("url");
|
const std::string* url_string = details.FindStringKey("url");
|
||||||
|
@ -288,7 +288,7 @@ v8::Local<v8::Promise> Cookies::Set(const base::DictionaryValue& details) {
|
||||||
manager->SetCanonicalCookie(
|
manager->SetCanonicalCookie(
|
||||||
*canonical_cookie, url.scheme(), options,
|
*canonical_cookie, url.scheme(), options,
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](util::Promise promise,
|
[](util::Promise<void*> promise,
|
||||||
net::CanonicalCookie::CookieInclusionStatus status) {
|
net::CanonicalCookie::CookieInclusionStatus status) {
|
||||||
auto errmsg = InclusionStatusToString(status);
|
auto errmsg = InclusionStatusToString(status);
|
||||||
if (errmsg.empty()) {
|
if (errmsg.empty()) {
|
||||||
|
@ -303,15 +303,15 @@ v8::Local<v8::Promise> Cookies::Set(const base::DictionaryValue& details) {
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Cookies::FlushStore() {
|
v8::Local<v8::Promise> Cookies::FlushStore() {
|
||||||
util::Promise promise(isolate());
|
util::Promise<void*> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
auto* storage_partition = content::BrowserContext::GetDefaultStoragePartition(
|
auto* storage_partition = content::BrowserContext::GetDefaultStoragePartition(
|
||||||
browser_context_.get());
|
browser_context_.get());
|
||||||
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
|
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
|
||||||
|
|
||||||
manager->FlushCookieStore(
|
manager->FlushCookieStore(base::BindOnce(
|
||||||
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
|
util::Promise<void*>::ResolveEmptyPromise, std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,8 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
|
||||||
if (it == pending_requests_.end())
|
if (it == pending_requests_.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
electron::util::Promise promise = std::move(it->second);
|
electron::util::Promise<base::DictionaryValue> promise =
|
||||||
|
std::move(it->second);
|
||||||
pending_requests_.erase(it);
|
pending_requests_.erase(it);
|
||||||
|
|
||||||
base::DictionaryValue* error = nullptr;
|
base::DictionaryValue* error = nullptr;
|
||||||
|
@ -129,7 +130,7 @@ void Debugger::Detach() {
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Debugger::SendCommand(mate::Arguments* args) {
|
v8::Local<v8::Promise> Debugger::SendCommand(mate::Arguments* args) {
|
||||||
electron::util::Promise promise(isolate());
|
electron::util::Promise<base::DictionaryValue> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (!agent_host_) {
|
if (!agent_host_) {
|
||||||
|
|
|
@ -54,7 +54,8 @@ class Debugger : public mate::TrackableObject<Debugger>,
|
||||||
content::RenderFrameHost* new_rfh) override;
|
content::RenderFrameHost* new_rfh) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using PendingRequestMap = std::map<int, electron::util::Promise>;
|
using PendingRequestMap =
|
||||||
|
std::map<int, electron::util::Promise<base::DictionaryValue>>;
|
||||||
|
|
||||||
void Attach(mate::Arguments* args);
|
void Attach(mate::Arguments* args);
|
||||||
bool IsAttached();
|
bool IsAttached();
|
||||||
|
|
|
@ -24,7 +24,7 @@ int ShowMessageBoxSync(const electron::MessageBoxSettings& settings) {
|
||||||
return electron::ShowMessageBoxSync(settings);
|
return electron::ShowMessageBoxSync(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResolvePromiseObject(electron::util::Promise promise,
|
void ResolvePromiseObject(electron::util::Promise<gin::Dictionary> promise,
|
||||||
int result,
|
int result,
|
||||||
bool checkbox_checked) {
|
bool checkbox_checked) {
|
||||||
v8::Isolate* isolate = promise.isolate();
|
v8::Isolate* isolate = promise.isolate();
|
||||||
|
@ -33,14 +33,14 @@ void ResolvePromiseObject(electron::util::Promise promise,
|
||||||
dict.Set("response", result);
|
dict.Set("response", result);
|
||||||
dict.Set("checkboxChecked", checkbox_checked);
|
dict.Set("checkboxChecked", checkbox_checked);
|
||||||
|
|
||||||
promise.Resolve(gin::ConvertToV8(isolate, dict));
|
promise.ResolveWithGin(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> ShowMessageBox(
|
v8::Local<v8::Promise> ShowMessageBox(
|
||||||
const electron::MessageBoxSettings& settings,
|
const electron::MessageBoxSettings& settings,
|
||||||
gin::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<gin::Dictionary> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
electron::ShowMessageBox(
|
electron::ShowMessageBox(
|
||||||
|
@ -59,7 +59,7 @@ void ShowOpenDialogSync(const file_dialog::DialogSettings& settings,
|
||||||
v8::Local<v8::Promise> ShowOpenDialog(
|
v8::Local<v8::Promise> ShowOpenDialog(
|
||||||
const file_dialog::DialogSettings& settings,
|
const file_dialog::DialogSettings& settings,
|
||||||
gin::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
electron::util::Promise promise(args->isolate());
|
electron::util::Promise<mate::Dictionary> promise(args->isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
file_dialog::ShowOpenDialog(settings, std::move(promise));
|
file_dialog::ShowOpenDialog(settings, std::move(promise));
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -75,7 +75,7 @@ void ShowSaveDialogSync(const file_dialog::DialogSettings& settings,
|
||||||
v8::Local<v8::Promise> ShowSaveDialog(
|
v8::Local<v8::Promise> ShowSaveDialog(
|
||||||
const file_dialog::DialogSettings& settings,
|
const file_dialog::DialogSettings& settings,
|
||||||
gin::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
electron::util::Promise promise(args->isolate());
|
electron::util::Promise<mate::Dictionary> promise(args->isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
file_dialog::ShowSaveDialog(settings, std::move(promise));
|
file_dialog::ShowSaveDialog(settings, std::move(promise));
|
||||||
|
|
|
@ -104,7 +104,7 @@ v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
|
||||||
const std::string& product_id,
|
const std::string& product_id,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<bool> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
int quantity = 1;
|
int quantity = 1;
|
||||||
|
@ -112,7 +112,7 @@ v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
|
||||||
|
|
||||||
in_app_purchase::PurchaseProduct(
|
in_app_purchase::PurchaseProduct(
|
||||||
product_id, quantity,
|
product_id, quantity,
|
||||||
base::BindOnce(electron::util::Promise::ResolvePromise<bool>,
|
base::BindOnce(electron::util::Promise<bool>::ResolvePromise,
|
||||||
std::move(promise)));
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -122,13 +122,15 @@ v8::Local<v8::Promise> InAppPurchase::GetProducts(
|
||||||
const std::vector<std::string>& productIDs,
|
const std::vector<std::string>& productIDs,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<std::vector<in_app_purchase::Product>> promise(
|
||||||
|
isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
in_app_purchase::GetProducts(
|
in_app_purchase::GetProducts(
|
||||||
productIDs, base::BindOnce(electron::util::Promise::ResolvePromise<
|
productIDs,
|
||||||
std::vector<in_app_purchase::Product>>,
|
base::BindOnce(electron::util::Promise<
|
||||||
std::move(promise)));
|
std::vector<in_app_purchase::Product>>::ResolvePromise,
|
||||||
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ base::File OpenFileForWriting(base::FilePath path) {
|
||||||
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
|
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResolvePromiseWithNetError(util::Promise promise, int32_t error) {
|
void ResolvePromiseWithNetError(util::Promise<void*> promise, int32_t error) {
|
||||||
if (error == net::OK) {
|
if (error == net::OK) {
|
||||||
promise.Resolve();
|
promise.Resolve();
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,7 +119,7 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
|
||||||
return v8::Local<v8::Promise>();
|
return v8::Local<v8::Promise>();
|
||||||
}
|
}
|
||||||
|
|
||||||
pending_start_promise_ = base::make_optional<util::Promise>(isolate());
|
pending_start_promise_ = base::make_optional<util::Promise<void*>>(isolate());
|
||||||
v8::Local<v8::Promise> handle = pending_start_promise_->GetHandle();
|
v8::Local<v8::Promise> handle = pending_start_promise_->GetHandle();
|
||||||
|
|
||||||
auto command_line_string =
|
auto command_line_string =
|
||||||
|
@ -189,7 +189,7 @@ bool NetLog::IsCurrentlyLogging() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> NetLog::StopLogging(mate::Arguments* args) {
|
v8::Local<v8::Promise> NetLog::StopLogging(mate::Arguments* args) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<void*> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (net_log_exporter_) {
|
if (net_log_exporter_) {
|
||||||
|
@ -199,7 +199,7 @@ v8::Local<v8::Promise> NetLog::StopLogging(mate::Arguments* args) {
|
||||||
net_log_exporter_->Stop(
|
net_log_exporter_->Stop(
|
||||||
base::Value(base::Value::Type::DICTIONARY),
|
base::Value(base::Value::Type::DICTIONARY),
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](network::mojom::NetLogExporterPtr, util::Promise promise,
|
[](network::mojom::NetLogExporterPtr, util::Promise<void*> promise,
|
||||||
int32_t error) {
|
int32_t error) {
|
||||||
ResolvePromiseWithNetError(std::move(promise), error);
|
ResolvePromiseWithNetError(std::move(promise), error);
|
||||||
},
|
},
|
||||||
|
|
|
@ -53,7 +53,7 @@ class NetLog : public mate::TrackableObject<NetLog> {
|
||||||
|
|
||||||
network::mojom::NetLogExporterPtr net_log_exporter_;
|
network::mojom::NetLogExporterPtr net_log_exporter_;
|
||||||
|
|
||||||
base::Optional<util::Promise> pending_start_promise_;
|
base::Optional<util::Promise<void*>> pending_start_promise_;
|
||||||
|
|
||||||
scoped_refptr<base::TaskRunner> file_task_runner_;
|
scoped_refptr<base::TaskRunner> file_task_runner_;
|
||||||
|
|
||||||
|
|
|
@ -232,18 +232,17 @@ v8::Local<v8::Promise> ProtocolNS::IsProtocolHandled(const std::string& scheme,
|
||||||
"protocol.isProtocolRegistered or protocol.isProtocolIntercepted "
|
"protocol.isProtocolRegistered or protocol.isProtocolIntercepted "
|
||||||
"instead.",
|
"instead.",
|
||||||
"ProtocolDeprecateIsProtocolHandled");
|
"ProtocolDeprecateIsProtocolHandled");
|
||||||
util::Promise promise(isolate());
|
return util::Promise<bool>::ResolvedPromise(
|
||||||
promise.Resolve(IsProtocolRegistered(scheme) ||
|
isolate(), IsProtocolRegistered(scheme) ||
|
||||||
IsProtocolIntercepted(scheme) ||
|
IsProtocolIntercepted(scheme) ||
|
||||||
// The |isProtocolHandled| should return true for builtin
|
// The |isProtocolHandled| should return true for builtin
|
||||||
// schemes, however with NetworkService it is impossible to
|
// schemes, however with NetworkService it is impossible to
|
||||||
// know which schemes are registered until a real network
|
// know which schemes are registered until a real network
|
||||||
// request is sent.
|
// request is sent.
|
||||||
// So we have to test against a hard-coded builtin schemes
|
// So we have to test against a hard-coded builtin schemes
|
||||||
// list make it work with old code. We should deprecate this
|
// list make it work with old code. We should deprecate
|
||||||
// API with the new |isProtocolRegistered| API.
|
// this API with the new |isProtocolRegistered| API.
|
||||||
base::Contains(kBuiltinSchemes, scheme));
|
base::Contains(kBuiltinSchemes, scheme));
|
||||||
return promise.GetHandle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolNS::HandleOptionalCallback(mate::Arguments* args,
|
void ProtocolNS::HandleOptionalCallback(mate::Arguments* args,
|
||||||
|
|
|
@ -236,14 +236,14 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::ResolveProxy(mate::Arguments* args) {
|
v8::Local<v8::Promise> Session::ResolveProxy(mate::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
util::Promise promise(isolate);
|
util::Promise<std::string> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
GURL url;
|
GURL url;
|
||||||
args->GetNext(&url);
|
args->GetNext(&url);
|
||||||
|
|
||||||
browser_context_->GetResolveProxyHelper()->ResolveProxy(
|
browser_context_->GetResolveProxyHelper()->ResolveProxy(
|
||||||
url, base::BindOnce(util::Promise::ResolvePromise<std::string>,
|
url, base::BindOnce(util::Promise<std::string>::ResolvePromise,
|
||||||
std::move(promise)));
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -251,36 +251,37 @@ v8::Local<v8::Promise> Session::ResolveProxy(mate::Arguments* args) {
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::GetCacheSize() {
|
v8::Local<v8::Promise> Session::GetCacheSize() {
|
||||||
auto* isolate = v8::Isolate::GetCurrent();
|
auto* isolate = v8::Isolate::GetCurrent();
|
||||||
auto promise = util::Promise(isolate);
|
util::Promise<int64_t> promise(isolate);
|
||||||
auto handle = promise.GetHandle();
|
auto handle = promise.GetHandle();
|
||||||
|
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||||
->GetNetworkContext()
|
->GetNetworkContext()
|
||||||
->ComputeHttpCacheSize(base::Time(), base::Time::Max(),
|
->ComputeHttpCacheSize(
|
||||||
base::BindOnce(
|
base::Time(), base::Time::Max(),
|
||||||
[](util::Promise promise, bool is_upper_bound,
|
base::BindOnce(
|
||||||
int64_t size_or_error) {
|
[](util::Promise<int64_t> promise, bool is_upper_bound,
|
||||||
if (size_or_error < 0) {
|
int64_t size_or_error) {
|
||||||
promise.RejectWithErrorMessage(
|
if (size_or_error < 0) {
|
||||||
net::ErrorToString(size_or_error));
|
promise.RejectWithErrorMessage(
|
||||||
} else {
|
net::ErrorToString(size_or_error));
|
||||||
promise.Resolve(size_or_error);
|
} else {
|
||||||
}
|
promise.Resolve(size_or_error);
|
||||||
},
|
}
|
||||||
std::move(promise)));
|
},
|
||||||
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::ClearCache() {
|
v8::Local<v8::Promise> Session::ClearCache() {
|
||||||
auto* isolate = v8::Isolate::GetCurrent();
|
auto* isolate = v8::Isolate::GetCurrent();
|
||||||
auto promise = util::Promise(isolate);
|
util::Promise<void*> promise(isolate);
|
||||||
auto handle = promise.GetHandle();
|
auto handle = promise.GetHandle();
|
||||||
|
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||||
->GetNetworkContext()
|
->GetNetworkContext()
|
||||||
->ClearHttpCache(base::Time(), base::Time::Max(), nullptr,
|
->ClearHttpCache(base::Time(), base::Time::Max(), nullptr,
|
||||||
base::BindOnce(util::Promise::ResolveEmptyPromise,
|
base::BindOnce(util::Promise<void*>::ResolveEmptyPromise,
|
||||||
std::move(promise)));
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -288,7 +289,7 @@ v8::Local<v8::Promise> Session::ClearCache() {
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::ClearStorageData(mate::Arguments* args) {
|
v8::Local<v8::Promise> Session::ClearStorageData(mate::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
util::Promise promise(isolate);
|
util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
ClearStorageDataOptions options;
|
ClearStorageDataOptions options;
|
||||||
|
@ -305,7 +306,8 @@ v8::Local<v8::Promise> Session::ClearStorageData(mate::Arguments* args) {
|
||||||
storage_partition->ClearData(
|
storage_partition->ClearData(
|
||||||
options.storage_types, options.quota_types, options.origin, base::Time(),
|
options.storage_types, options.quota_types, options.origin, base::Time(),
|
||||||
base::Time::Max(),
|
base::Time::Max(),
|
||||||
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
|
base::BindOnce(util::Promise<void*>::ResolveEmptyPromise,
|
||||||
|
std::move(promise)));
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +319,7 @@ void Session::FlushStorageData() {
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::SetProxy(mate::Arguments* args) {
|
v8::Local<v8::Promise> Session::SetProxy(mate::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
util::Promise promise(isolate);
|
util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
mate::Dictionary options;
|
mate::Dictionary options;
|
||||||
|
@ -350,8 +352,8 @@ v8::Local<v8::Promise> Session::SetProxy(mate::Arguments* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE, base::BindOnce(util::Promise<void*>::ResolveEmptyPromise,
|
||||||
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
@ -449,13 +451,13 @@ void Session::SetPermissionCheckHandler(v8::Local<v8::Value> val,
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::ClearHostResolverCache(mate::Arguments* args) {
|
v8::Local<v8::Promise> Session::ClearHostResolverCache(mate::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
util::Promise promise(isolate);
|
util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||||
->GetNetworkContext()
|
->GetNetworkContext()
|
||||||
->ClearHostCache(nullptr,
|
->ClearHostCache(nullptr,
|
||||||
base::BindOnce(util::Promise::ResolveEmptyPromise,
|
base::BindOnce(util::Promise<void*>::ResolveEmptyPromise,
|
||||||
std::move(promise)));
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -463,14 +465,15 @@ v8::Local<v8::Promise> Session::ClearHostResolverCache(mate::Arguments* args) {
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::ClearAuthCache() {
|
v8::Local<v8::Promise> Session::ClearAuthCache() {
|
||||||
auto* isolate = v8::Isolate::GetCurrent();
|
auto* isolate = v8::Isolate::GetCurrent();
|
||||||
util::Promise promise(isolate);
|
util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||||
->GetNetworkContext()
|
->GetNetworkContext()
|
||||||
->ClearHttpAuthCache(base::Time(),
|
->ClearHttpAuthCache(
|
||||||
base::BindOnce(util::Promise::ResolveEmptyPromise,
|
base::Time(),
|
||||||
std::move(promise)));
|
base::BindOnce(util::Promise<void*>::ResolveEmptyPromise,
|
||||||
|
std::move(promise)));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
@ -495,7 +498,7 @@ std::string Session::GetUserAgent() {
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::GetBlobData(v8::Isolate* isolate,
|
v8::Local<v8::Promise> Session::GetBlobData(v8::Isolate* isolate,
|
||||||
const std::string& uuid) {
|
const std::string& uuid) {
|
||||||
util::Promise promise(isolate);
|
util::Promise<v8::Local<v8::Value>> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
AtomBlobReader* blob_reader = browser_context()->GetBlobReader();
|
AtomBlobReader* blob_reader = browser_context()->GetBlobReader();
|
||||||
|
|
|
@ -451,7 +451,7 @@ bool SystemPreferences::CanPromptTouchID() {
|
||||||
v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const std::string& reason) {
|
const std::string& reason) {
|
||||||
util::Promise promise(isolate);
|
util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (@available(macOS 10.12.2, *)) {
|
if (@available(macOS 10.12.2, *)) {
|
||||||
|
@ -468,7 +468,7 @@ v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
||||||
scoped_refptr<base::SequencedTaskRunner> runner =
|
scoped_refptr<base::SequencedTaskRunner> runner =
|
||||||
base::SequencedTaskRunnerHandle::Get();
|
base::SequencedTaskRunnerHandle::Get();
|
||||||
|
|
||||||
__block util::Promise p = std::move(promise);
|
__block util::Promise<void*> p = std::move(promise);
|
||||||
[context
|
[context
|
||||||
evaluateAccessControl:access_control
|
evaluateAccessControl:access_control
|
||||||
operation:LAAccessControlOperationUseKeySign
|
operation:LAAccessControlOperationUseKeySign
|
||||||
|
@ -479,14 +479,14 @@ v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
||||||
[error.localizedDescription UTF8String]);
|
[error.localizedDescription UTF8String]);
|
||||||
runner->PostTask(
|
runner->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::BindOnce(util::Promise::RejectPromise,
|
base::BindOnce(
|
||||||
std::move(p),
|
util::Promise<void*>::RejectPromise,
|
||||||
std::move(err_msg)));
|
std::move(p), std::move(err_msg)));
|
||||||
} else {
|
} else {
|
||||||
runner->PostTask(
|
runner->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
util::Promise::ResolveEmptyPromise,
|
util::Promise<void*>::ResolveEmptyPromise,
|
||||||
std::move(p)));
|
std::move(p)));
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
@ -607,12 +607,12 @@ std::string SystemPreferences::GetMediaAccessStatus(
|
||||||
v8::Local<v8::Promise> SystemPreferences::AskForMediaAccess(
|
v8::Local<v8::Promise> SystemPreferences::AskForMediaAccess(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const std::string& media_type) {
|
const std::string& media_type) {
|
||||||
util::Promise promise(isolate);
|
util::Promise<bool> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (auto type = ParseMediaType(media_type)) {
|
if (auto type = ParseMediaType(media_type)) {
|
||||||
if (@available(macOS 10.14, *)) {
|
if (@available(macOS 10.14, *)) {
|
||||||
__block util::Promise p = std::move(promise);
|
__block util::Promise<bool> p = std::move(promise);
|
||||||
[AVCaptureDevice requestAccessForMediaType:type
|
[AVCaptureDevice requestAccessForMediaType:type
|
||||||
completionHandler:^(BOOL granted) {
|
completionHandler:^(BOOL granted) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
|
@ -302,7 +302,8 @@ namespace api {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Called when CapturePage is done.
|
// Called when CapturePage is done.
|
||||||
void OnCapturePageDone(util::Promise promise, const SkBitmap& bitmap) {
|
void OnCapturePageDone(util::Promise<gfx::Image> promise,
|
||||||
|
const SkBitmap& bitmap) {
|
||||||
// Hack to enable transparency in captured image
|
// Hack to enable transparency in captured image
|
||||||
promise.Resolve(gfx::Image::CreateFrom1xBitmap(bitmap));
|
promise.Resolve(gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||||
}
|
}
|
||||||
|
@ -1417,7 +1418,7 @@ std::string WebContents::GetUserAgent() {
|
||||||
v8::Local<v8::Promise> WebContents::SavePage(
|
v8::Local<v8::Promise> WebContents::SavePage(
|
||||||
const base::FilePath& full_file_path,
|
const base::FilePath& full_file_path,
|
||||||
const content::SavePageType& save_type) {
|
const content::SavePageType& save_type) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<void*> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
auto* handler = new SavePageHandler(web_contents(), std::move(promise));
|
auto* handler = new SavePageHandler(web_contents(), std::move(promise));
|
||||||
|
@ -1749,7 +1750,7 @@ std::vector<printing::PrinterBasicInfo> WebContents::GetPrinterList() {
|
||||||
|
|
||||||
v8::Local<v8::Promise> WebContents::PrintToPDF(
|
v8::Local<v8::Promise> WebContents::PrintToPDF(
|
||||||
const base::DictionaryValue& settings) {
|
const base::DictionaryValue& settings) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<v8::Local<v8::Value>> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
PrintPreviewMessageHandler::FromWebContents(web_contents())
|
PrintPreviewMessageHandler::FromWebContents(web_contents())
|
||||||
->PrintToPDF(settings, std::move(promise));
|
->PrintToPDF(settings, std::move(promise));
|
||||||
|
@ -2052,7 +2053,7 @@ void WebContents::StartDrag(const mate::Dictionary& item,
|
||||||
|
|
||||||
v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* args) {
|
v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* args) {
|
||||||
gfx::Rect rect;
|
gfx::Rect rect;
|
||||||
util::Promise promise(isolate());
|
util::Promise<gfx::Image> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
// get rect arguments if they exist
|
// get rect arguments if they exist
|
||||||
|
@ -2319,7 +2320,7 @@ void WebContents::GrantOriginAccess(const GURL& url) {
|
||||||
|
|
||||||
v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
|
v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
|
||||||
const base::FilePath& file_path) {
|
const base::FilePath& file_path) {
|
||||||
util::Promise promise(isolate());
|
util::Promise<void*> promise(isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
|
@ -2346,8 +2347,8 @@ v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
|
||||||
(*raw_ptr)->TakeHeapSnapshot(
|
(*raw_ptr)->TakeHeapSnapshot(
|
||||||
mojo::WrapPlatformFile(file.TakePlatformFile()),
|
mojo::WrapPlatformFile(file.TakePlatformFile()),
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](mojom::ElectronRendererAssociatedPtr* ep, util::Promise promise,
|
[](mojom::ElectronRendererAssociatedPtr* ep,
|
||||||
bool success) {
|
util::Promise<void*> promise, bool success) {
|
||||||
if (success) {
|
if (success) {
|
||||||
promise.Resolve();
|
promise.Resolve();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -61,7 +61,8 @@ void GPUInfoManager::OnGpuInfoUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should be posted to the task runner
|
// Should be posted to the task runner
|
||||||
void GPUInfoManager::CompleteInfoFetcher(util::Promise promise) {
|
void GPUInfoManager::CompleteInfoFetcher(
|
||||||
|
util::Promise<base::DictionaryValue> promise) {
|
||||||
complete_info_promise_set_.emplace_back(std::move(promise));
|
complete_info_promise_set_.emplace_back(std::move(promise));
|
||||||
|
|
||||||
if (NeedsCompleteGpuInfoCollection()) {
|
if (NeedsCompleteGpuInfoCollection()) {
|
||||||
|
@ -71,7 +72,8 @@ void GPUInfoManager::CompleteInfoFetcher(util::Promise promise) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPUInfoManager::FetchCompleteInfo(util::Promise promise) {
|
void GPUInfoManager::FetchCompleteInfo(
|
||||||
|
util::Promise<base::DictionaryValue> promise) {
|
||||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||||
FROM_HERE, base::BindOnce(&GPUInfoManager::CompleteInfoFetcher,
|
FROM_HERE, base::BindOnce(&GPUInfoManager::CompleteInfoFetcher,
|
||||||
base::Unretained(this), std::move(promise)));
|
base::Unretained(this), std::move(promise)));
|
||||||
|
@ -79,7 +81,8 @@ void GPUInfoManager::FetchCompleteInfo(util::Promise promise) {
|
||||||
|
|
||||||
// This fetches the info synchronously, so no need to post to the task queue.
|
// This fetches the info synchronously, so no need to post to the task queue.
|
||||||
// There cannot be multiple promises as they are resolved synchronously.
|
// There cannot be multiple promises as they are resolved synchronously.
|
||||||
void GPUInfoManager::FetchBasicInfo(util::Promise promise) {
|
void GPUInfoManager::FetchBasicInfo(
|
||||||
|
util::Promise<base::DictionaryValue> promise) {
|
||||||
gpu::GPUInfo gpu_info;
|
gpu::GPUInfo gpu_info;
|
||||||
CollectBasicGraphicsInfo(&gpu_info);
|
CollectBasicGraphicsInfo(&gpu_info);
|
||||||
promise.Resolve(*EnumerateGPUInfo(gpu_info));
|
promise.Resolve(*EnumerateGPUInfo(gpu_info));
|
||||||
|
|
|
@ -25,8 +25,8 @@ class GPUInfoManager : public content::GpuDataManagerObserver {
|
||||||
GPUInfoManager();
|
GPUInfoManager();
|
||||||
~GPUInfoManager() override;
|
~GPUInfoManager() override;
|
||||||
bool NeedsCompleteGpuInfoCollection() const;
|
bool NeedsCompleteGpuInfoCollection() const;
|
||||||
void FetchCompleteInfo(util::Promise promise);
|
void FetchCompleteInfo(util::Promise<base::DictionaryValue> promise);
|
||||||
void FetchBasicInfo(util::Promise promise);
|
void FetchBasicInfo(util::Promise<base::DictionaryValue> promise);
|
||||||
void OnGpuInfoUpdate() override;
|
void OnGpuInfoUpdate() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -34,12 +34,12 @@ class GPUInfoManager : public content::GpuDataManagerObserver {
|
||||||
gpu::GPUInfo gpu_info) const;
|
gpu::GPUInfo gpu_info) const;
|
||||||
|
|
||||||
// These should be posted to the task queue
|
// These should be posted to the task queue
|
||||||
void CompleteInfoFetcher(util::Promise promise);
|
void CompleteInfoFetcher(util::Promise<base::DictionaryValue> promise);
|
||||||
void ProcessCompleteInfo();
|
void ProcessCompleteInfo();
|
||||||
|
|
||||||
// This set maintains all the promises that should be fulfilled
|
// This set maintains all the promises that should be fulfilled
|
||||||
// once we have the complete information data
|
// once we have the complete information data
|
||||||
std::vector<util::Promise> complete_info_promise_set_;
|
std::vector<util::Promise<base::DictionaryValue>> complete_info_promise_set_;
|
||||||
content::GpuDataManager* gpu_data_manager_;
|
content::GpuDataManager* gpu_data_manager_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(GPUInfoManager);
|
DISALLOW_COPY_AND_ASSIGN(GPUInfoManager);
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace electron {
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
SavePageHandler::SavePageHandler(content::WebContents* web_contents,
|
SavePageHandler::SavePageHandler(content::WebContents* web_contents,
|
||||||
util::Promise promise)
|
util::Promise<void*> promise)
|
||||||
: web_contents_(web_contents), promise_(std::move(promise)) {}
|
: web_contents_(web_contents), promise_(std::move(promise)) {}
|
||||||
|
|
||||||
SavePageHandler::~SavePageHandler() {}
|
SavePageHandler::~SavePageHandler() {}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class SavePageHandler : public content::DownloadManager::Observer,
|
||||||
public download::DownloadItem::Observer {
|
public download::DownloadItem::Observer {
|
||||||
public:
|
public:
|
||||||
SavePageHandler(content::WebContents* web_contents,
|
SavePageHandler(content::WebContents* web_contents,
|
||||||
electron::util::Promise promise);
|
electron::util::Promise<void*> promise);
|
||||||
~SavePageHandler() override;
|
~SavePageHandler() override;
|
||||||
|
|
||||||
bool Handle(const base::FilePath& full_path,
|
bool Handle(const base::FilePath& full_path,
|
||||||
|
@ -47,7 +47,7 @@ class SavePageHandler : public content::DownloadManager::Observer,
|
||||||
void OnDownloadUpdated(download::DownloadItem* item) override;
|
void OnDownloadUpdated(download::DownloadItem* item) override;
|
||||||
|
|
||||||
content::WebContents* web_contents_; // weak
|
content::WebContents* web_contents_; // weak
|
||||||
electron::util::Promise promise_;
|
electron::util::Promise<void*> promise_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -27,7 +27,9 @@ void FreeNodeBufferData(char* data, void* hint) {
|
||||||
delete[] data;
|
delete[] data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunPromiseInUI(util::Promise promise, char* blob_data, int size) {
|
void RunPromiseInUI(util::Promise<v8::Local<v8::Value>> promise,
|
||||||
|
char* blob_data,
|
||||||
|
int size) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
v8::Isolate* isolate = promise.isolate();
|
v8::Isolate* isolate = promise.isolate();
|
||||||
|
|
||||||
|
@ -52,13 +54,13 @@ AtomBlobReader::AtomBlobReader(content::ChromeBlobStorageContext* blob_context)
|
||||||
AtomBlobReader::~AtomBlobReader() {}
|
AtomBlobReader::~AtomBlobReader() {}
|
||||||
|
|
||||||
void AtomBlobReader::StartReading(const std::string& uuid,
|
void AtomBlobReader::StartReading(const std::string& uuid,
|
||||||
util::Promise promise) {
|
util::Promise<v8::Local<v8::Value>> promise) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
|
|
||||||
auto blob_data_handle = blob_context_->context()->GetBlobDataFromUUID(uuid);
|
auto blob_data_handle = blob_context_->context()->GetBlobDataFromUUID(uuid);
|
||||||
if (!blob_data_handle) {
|
if (!blob_data_handle) {
|
||||||
util::Promise::RejectPromise(std::move(promise),
|
util::Promise<v8::Local<v8::Value>>::RejectPromise(
|
||||||
"Could not get blob data handle");
|
std::move(promise), "Could not get blob data handle");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ class AtomBlobReader {
|
||||||
explicit AtomBlobReader(content::ChromeBlobStorageContext* blob_context);
|
explicit AtomBlobReader(content::ChromeBlobStorageContext* blob_context);
|
||||||
~AtomBlobReader();
|
~AtomBlobReader();
|
||||||
|
|
||||||
void StartReading(const std::string& uuid, electron::util::Promise promise);
|
void StartReading(const std::string& uuid,
|
||||||
|
electron::util::Promise<v8::Local<v8::Value>> promise);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// A self-destroyed helper class to read the blob data.
|
// A self-destroyed helper class to read the blob data.
|
||||||
|
|
|
@ -122,7 +122,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
settings.force_detached = offscreen;
|
settings.force_detached = offscreen;
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
electron::util::Promise dialog_promise(isolate);
|
electron::util::Promise<mate::Dictionary> dialog_promise(isolate);
|
||||||
auto dialog_callback =
|
auto dialog_callback =
|
||||||
base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
|
base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
|
||||||
base::Unretained(this), download_id, callback);
|
base::Unretained(this), download_id, callback);
|
||||||
|
|
|
@ -165,9 +165,9 @@ void Browser::DidFinishLaunching(const base::DictionaryValue& launch_info) {
|
||||||
observer.OnFinishLaunching(launch_info);
|
observer.OnFinishLaunching(launch_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
const util::Promise& Browser::WhenReady(v8::Isolate* isolate) {
|
const util::Promise<void*>& Browser::WhenReady(v8::Isolate* isolate) {
|
||||||
if (!ready_promise_) {
|
if (!ready_promise_) {
|
||||||
ready_promise_.reset(new util::Promise(isolate));
|
ready_promise_.reset(new util::Promise<void*>(isolate));
|
||||||
if (is_ready()) {
|
if (is_ready()) {
|
||||||
ready_promise_->Resolve();
|
ready_promise_->Resolve();
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ class Browser : public WindowListObserver {
|
||||||
bool is_shutting_down() const { return is_shutdown_; }
|
bool is_shutting_down() const { return is_shutdown_; }
|
||||||
bool is_quiting() const { return is_quiting_; }
|
bool is_quiting() const { return is_quiting_; }
|
||||||
bool is_ready() const { return is_ready_; }
|
bool is_ready() const { return is_ready_; }
|
||||||
const util::Promise& WhenReady(v8::Isolate* isolate);
|
const util::Promise<void*>& WhenReady(v8::Isolate* isolate);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Returns the version of application bundle or executable file.
|
// Returns the version of application bundle or executable file.
|
||||||
|
@ -301,7 +301,7 @@ class Browser : public WindowListObserver {
|
||||||
|
|
||||||
int badge_count_ = 0;
|
int badge_count_ = 0;
|
||||||
|
|
||||||
std::unique_ptr<util::Promise> ready_promise_;
|
std::unique_ptr<util::Promise<void*>> ready_promise_;
|
||||||
|
|
||||||
#if defined(OS_LINUX) || defined(OS_WIN)
|
#if defined(OS_LINUX) || defined(OS_WIN)
|
||||||
base::Value about_panel_options_;
|
base::Value about_panel_options_;
|
||||||
|
|
|
@ -313,7 +313,7 @@ bool Browser::DockIsVisible() {
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Browser::DockShow(v8::Isolate* isolate) {
|
v8::Local<v8::Promise> Browser::DockShow(v8::Isolate* isolate) {
|
||||||
util::Promise promise(isolate);
|
util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
BOOL active = [[NSRunningApplication currentApplication] isActive];
|
BOOL active = [[NSRunningApplication currentApplication] isActive];
|
||||||
|
@ -327,7 +327,7 @@ v8::Local<v8::Promise> Browser::DockShow(v8::Isolate* isolate) {
|
||||||
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
__block util::Promise p = std::move(promise);
|
__block util::Promise<void*> p = std::move(promise);
|
||||||
dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
|
dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
|
||||||
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
|
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
|
||||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
|
|
|
@ -142,7 +142,7 @@ void PrintPreviewMessageHandler::OnPrintPreviewCancelled(
|
||||||
|
|
||||||
void PrintPreviewMessageHandler::PrintToPDF(
|
void PrintPreviewMessageHandler::PrintToPDF(
|
||||||
const base::DictionaryValue& options,
|
const base::DictionaryValue& options,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<v8::Local<v8::Value>> promise) {
|
||||||
int request_id;
|
int request_id;
|
||||||
options.GetInteger(printing::kPreviewRequestID, &request_id);
|
options.GetInteger(printing::kPreviewRequestID, &request_id);
|
||||||
promise_map_.emplace(request_id, std::move(promise));
|
promise_map_.emplace(request_id, std::move(promise));
|
||||||
|
@ -154,11 +154,12 @@ void PrintPreviewMessageHandler::PrintToPDF(
|
||||||
rfh->Send(new PrintMsg_PrintPreview(rfh->GetRoutingID(), options));
|
rfh->Send(new PrintMsg_PrintPreview(rfh->GetRoutingID(), options));
|
||||||
}
|
}
|
||||||
|
|
||||||
util::Promise PrintPreviewMessageHandler::GetPromise(int request_id) {
|
util::Promise<v8::Local<v8::Value>> PrintPreviewMessageHandler::GetPromise(
|
||||||
|
int request_id) {
|
||||||
auto it = promise_map_.find(request_id);
|
auto it = promise_map_.find(request_id);
|
||||||
DCHECK(it != promise_map_.end());
|
DCHECK(it != promise_map_.end());
|
||||||
|
|
||||||
util::Promise promise = std::move(it->second);
|
util::Promise<v8::Local<v8::Value>> promise = std::move(it->second);
|
||||||
promise_map_.erase(it);
|
promise_map_.erase(it);
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
|
@ -169,7 +170,7 @@ void PrintPreviewMessageHandler::ResolvePromise(
|
||||||
scoped_refptr<base::RefCountedMemory> data_bytes) {
|
scoped_refptr<base::RefCountedMemory> data_bytes) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
util::Promise promise = GetPromise(request_id);
|
util::Promise<v8::Local<v8::Value>> promise = GetPromise(request_id);
|
||||||
|
|
||||||
v8::Isolate* isolate = promise.isolate();
|
v8::Isolate* isolate = promise.isolate();
|
||||||
mate::Locker locker(isolate);
|
mate::Locker locker(isolate);
|
||||||
|
@ -189,7 +190,7 @@ void PrintPreviewMessageHandler::ResolvePromise(
|
||||||
void PrintPreviewMessageHandler::RejectPromise(int request_id) {
|
void PrintPreviewMessageHandler::RejectPromise(int request_id) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
util::Promise promise = GetPromise(request_id);
|
util::Promise<v8::Local<v8::Value>> promise = GetPromise(request_id);
|
||||||
promise.RejectWithErrorMessage("Failed to generate PDF");
|
promise.RejectWithErrorMessage("Failed to generate PDF");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@ class PrintPreviewMessageHandler
|
||||||
public:
|
public:
|
||||||
~PrintPreviewMessageHandler() override;
|
~PrintPreviewMessageHandler() override;
|
||||||
|
|
||||||
void PrintToPDF(const base::DictionaryValue& options, util::Promise promise);
|
void PrintToPDF(const base::DictionaryValue& options,
|
||||||
|
util::Promise<v8::Local<v8::Value>> promise);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// content::WebContentsObserver implementation.
|
// content::WebContentsObserver implementation.
|
||||||
|
@ -55,13 +56,14 @@ class PrintPreviewMessageHandler
|
||||||
void OnPrintPreviewCancelled(int document_cookie,
|
void OnPrintPreviewCancelled(int document_cookie,
|
||||||
const PrintHostMsg_PreviewIds& ids);
|
const PrintHostMsg_PreviewIds& ids);
|
||||||
|
|
||||||
util::Promise GetPromise(int request_id);
|
util::Promise<v8::Local<v8::Value>> GetPromise(int request_id);
|
||||||
|
|
||||||
void ResolvePromise(int request_id,
|
void ResolvePromise(int request_id,
|
||||||
scoped_refptr<base::RefCountedMemory> data_bytes);
|
scoped_refptr<base::RefCountedMemory> data_bytes);
|
||||||
void RejectPromise(int request_id);
|
void RejectPromise(int request_id);
|
||||||
|
|
||||||
using PromiseMap = std::map<int, electron::util::Promise>;
|
using PromiseMap =
|
||||||
|
std::map<int, electron::util::Promise<v8::Local<v8::Value>>>;
|
||||||
PromiseMap promise_map_;
|
PromiseMap promise_map_;
|
||||||
|
|
||||||
base::WeakPtrFactory<PrintPreviewMessageHandler> weak_ptr_factory_;
|
base::WeakPtrFactory<PrintPreviewMessageHandler> weak_ptr_factory_;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
@interface TrustDelegate : NSObject {
|
@interface TrustDelegate : NSObject {
|
||||||
@private
|
@private
|
||||||
std::unique_ptr<electron::util::Promise> promise_;
|
std::unique_ptr<electron::util::Promise<void*>> promise_;
|
||||||
SFCertificateTrustPanel* panel_;
|
SFCertificateTrustPanel* panel_;
|
||||||
scoped_refptr<net::X509Certificate> cert_;
|
scoped_refptr<net::X509Certificate> cert_;
|
||||||
SecTrustRef trust_;
|
SecTrustRef trust_;
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
SecPolicyRef sec_policy_;
|
SecPolicyRef sec_policy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithPromise:(electron::util::Promise)promise
|
- (id)initWithPromise:(electron::util::Promise<void*>)promise
|
||||||
panel:(SFCertificateTrustPanel*)panel
|
panel:(SFCertificateTrustPanel*)panel
|
||||||
cert:(const scoped_refptr<net::X509Certificate>&)cert
|
cert:(const scoped_refptr<net::X509Certificate>&)cert
|
||||||
trust:(SecTrustRef)trust
|
trust:(SecTrustRef)trust
|
||||||
|
@ -51,14 +51,14 @@
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithPromise:(electron::util::Promise)promise
|
- (id)initWithPromise:(electron::util::Promise<void*>)promise
|
||||||
panel:(SFCertificateTrustPanel*)panel
|
panel:(SFCertificateTrustPanel*)panel
|
||||||
cert:(const scoped_refptr<net::X509Certificate>&)cert
|
cert:(const scoped_refptr<net::X509Certificate>&)cert
|
||||||
trust:(SecTrustRef)trust
|
trust:(SecTrustRef)trust
|
||||||
certChain:(CFArrayRef)certChain
|
certChain:(CFArrayRef)certChain
|
||||||
secPolicy:(SecPolicyRef)secPolicy {
|
secPolicy:(SecPolicyRef)secPolicy {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
promise_.reset(new electron::util::Promise(std::move(promise)));
|
promise_.reset(new electron::util::Promise<void*>(std::move(promise)));
|
||||||
panel_ = panel;
|
panel_ = panel;
|
||||||
cert_ = cert;
|
cert_ = cert;
|
||||||
trust_ = trust;
|
trust_ = trust;
|
||||||
|
@ -90,7 +90,7 @@ v8::Local<v8::Promise> ShowCertificateTrust(
|
||||||
const scoped_refptr<net::X509Certificate>& cert,
|
const scoped_refptr<net::X509Certificate>& cert,
|
||||||
const std::string& message) {
|
const std::string& message) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
auto* sec_policy = SecPolicyCreateBasicX509();
|
auto* sec_policy = SecPolicyCreateBasicX509();
|
||||||
|
|
|
@ -61,7 +61,7 @@ v8::Local<v8::Promise> ShowCertificateTrust(
|
||||||
const scoped_refptr<net::X509Certificate>& cert,
|
const scoped_refptr<net::X509Certificate>& cert,
|
||||||
const std::string& message) {
|
const std::string& message) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<void*> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
PCCERT_CHAIN_CONTEXT chain_context;
|
PCCERT_CHAIN_CONTEXT chain_context;
|
||||||
|
|
|
@ -66,12 +66,12 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
std::vector<base::FilePath>* paths);
|
std::vector<base::FilePath>* paths);
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise);
|
electron::util::Promise<mate::Dictionary> promise);
|
||||||
|
|
||||||
bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path);
|
bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path);
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise);
|
electron::util::Promise<mate::Dictionary> promise);
|
||||||
|
|
||||||
} // namespace file_dialog
|
} // namespace file_dialog
|
||||||
|
|
||||||
|
|
|
@ -157,13 +157,15 @@ class FileChooserDialog {
|
||||||
gtk_window_present_with_time(GTK_WINDOW(dialog_), time);
|
gtk_window_present_with_time(GTK_WINDOW(dialog_), time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunSaveAsynchronous(electron::util::Promise promise) {
|
void RunSaveAsynchronous(electron::util::Promise<mate::Dictionary> promise) {
|
||||||
save_promise_.reset(new electron::util::Promise(std::move(promise)));
|
save_promise_.reset(
|
||||||
|
new electron::util::Promise<mate::Dictionary>(std::move(promise)));
|
||||||
RunAsynchronous();
|
RunAsynchronous();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunOpenAsynchronous(electron::util::Promise promise) {
|
void RunOpenAsynchronous(electron::util::Promise<mate::Dictionary> promise) {
|
||||||
open_promise_.reset(new electron::util::Promise(std::move(promise)));
|
open_promise_.reset(
|
||||||
|
new electron::util::Promise<mate::Dictionary>(std::move(promise)));
|
||||||
RunAsynchronous();
|
RunAsynchronous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,8 +206,8 @@ class FileChooserDialog {
|
||||||
GtkWidget* preview_;
|
GtkWidget* preview_;
|
||||||
|
|
||||||
Filters filters_;
|
Filters filters_;
|
||||||
std::unique_ptr<electron::util::Promise> save_promise_;
|
std::unique_ptr<electron::util::Promise<mate::Dictionary>> save_promise_;
|
||||||
std::unique_ptr<electron::util::Promise> open_promise_;
|
std::unique_ptr<electron::util::Promise<mate::Dictionary>> open_promise_;
|
||||||
|
|
||||||
// Callback for when we update the preview for the selection.
|
// Callback for when we update the preview for the selection.
|
||||||
CHROMEG_CALLBACK_0(FileChooserDialog, void, OnUpdatePreview, GtkWidget*);
|
CHROMEG_CALLBACK_0(FileChooserDialog, void, OnUpdatePreview, GtkWidget*);
|
||||||
|
@ -225,7 +227,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePath", base::FilePath());
|
dict.Set("filePath", base::FilePath());
|
||||||
}
|
}
|
||||||
save_promise_->Resolve(dict.GetHandle());
|
save_promise_->Resolve(dict);
|
||||||
} else if (open_promise_) {
|
} else if (open_promise_) {
|
||||||
mate::Dictionary dict =
|
mate::Dictionary dict =
|
||||||
mate::Dictionary::CreateEmpty(open_promise_->isolate());
|
mate::Dictionary::CreateEmpty(open_promise_->isolate());
|
||||||
|
@ -236,7 +238,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePaths", std::vector<base::FilePath>());
|
dict.Set("filePaths", std::vector<base::FilePath>());
|
||||||
}
|
}
|
||||||
open_promise_->Resolve(dict.GetHandle());
|
open_promise_->Resolve(dict);
|
||||||
}
|
}
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +314,7 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||||
if (settings.properties & OPEN_DIALOG_OPEN_DIRECTORY)
|
if (settings.properties & OPEN_DIALOG_OPEN_DIRECTORY)
|
||||||
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
||||||
|
@ -335,7 +337,7 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
FileChooserDialog* save_dialog =
|
FileChooserDialog* save_dialog =
|
||||||
new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
|
new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
|
||||||
save_dialog->RunSaveAsynchronous(std::move(promise));
|
save_dialog->RunSaveAsynchronous(std::move(promise));
|
||||||
|
|
|
@ -300,7 +300,7 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
void OpenDialogCompletion(int chosen,
|
void OpenDialogCompletion(int chosen,
|
||||||
NSOpenPanel* dialog,
|
NSOpenPanel* dialog,
|
||||||
bool security_scoped_bookmarks,
|
bool security_scoped_bookmarks,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
||||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
|
@ -308,7 +308,7 @@ void OpenDialogCompletion(int chosen,
|
||||||
#if defined(MAS_BUILD)
|
#if defined(MAS_BUILD)
|
||||||
dict.Set("bookmarks", std::vector<std::string>());
|
dict.Set("bookmarks", std::vector<std::string>());
|
||||||
#endif
|
#endif
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
} else {
|
} else {
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
dict.Set("canceled", false);
|
dict.Set("canceled", false);
|
||||||
|
@ -324,12 +324,12 @@ void OpenDialogCompletion(int chosen,
|
||||||
ReadDialogPaths(dialog, &paths);
|
ReadDialogPaths(dialog, &paths);
|
||||||
dict.Set("filePaths", paths);
|
dict.Set("filePaths", paths);
|
||||||
#endif
|
#endif
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
SetupDialog(dialog, settings);
|
SetupDialog(dialog, settings);
|
||||||
|
@ -339,7 +339,7 @@ void ShowOpenDialog(const DialogSettings& settings,
|
||||||
// and pass it to the completion handler.
|
// and pass it to the completion handler.
|
||||||
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
||||||
|
|
||||||
__block electron::util::Promise p = std::move(promise);
|
__block electron::util::Promise<mate::Dictionary> p = std::move(promise);
|
||||||
|
|
||||||
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
||||||
settings.force_detached) {
|
settings.force_detached) {
|
||||||
|
@ -377,7 +377,7 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
|
||||||
void SaveDialogCompletion(int chosen,
|
void SaveDialogCompletion(int chosen,
|
||||||
NSSavePanel* dialog,
|
NSSavePanel* dialog,
|
||||||
bool security_scoped_bookmarks,
|
bool security_scoped_bookmarks,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
||||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
|
@ -397,11 +397,11 @@ void SaveDialogCompletion(int chosen,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||||
|
|
||||||
SetupDialog(dialog, settings);
|
SetupDialog(dialog, settings);
|
||||||
|
@ -412,7 +412,7 @@ void ShowSaveDialog(const DialogSettings& settings,
|
||||||
// and pass it to the completion handler.
|
// and pass it to the completion handler.
|
||||||
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
||||||
|
|
||||||
__block electron::util::Promise p = std::move(promise);
|
__block electron::util::Promise<mate::Dictionary> p = std::move(promise);
|
||||||
|
|
||||||
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
||||||
settings.force_detached) {
|
settings.force_detached) {
|
||||||
|
|
|
@ -81,18 +81,19 @@ bool CreateDialogThread(RunState* run_state) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDialogOpened(electron::util::Promise promise,
|
void OnDialogOpened(electron::util::Promise<mate::Dictionary> promise,
|
||||||
bool canceled,
|
bool canceled,
|
||||||
std::vector<base::FilePath> paths) {
|
std::vector<base::FilePath> paths) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("canceled", canceled);
|
dict.Set("canceled", canceled);
|
||||||
dict.Set("filePaths", paths);
|
dict.Set("filePaths", paths);
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunOpenDialogInNewThread(const RunState& run_state,
|
void RunOpenDialogInNewThread(
|
||||||
const DialogSettings& settings,
|
const RunState& run_state,
|
||||||
electron::util::Promise promise) {
|
const DialogSettings& settings,
|
||||||
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
bool result = ShowOpenDialogSync(settings, &paths);
|
bool result = ShowOpenDialogSync(settings, &paths);
|
||||||
run_state.ui_task_runner->PostTask(
|
run_state.ui_task_runner->PostTask(
|
||||||
|
@ -101,18 +102,19 @@ void RunOpenDialogInNewThread(const RunState& run_state,
|
||||||
run_state.ui_task_runner->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
run_state.ui_task_runner->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSaveDialogDone(electron::util::Promise promise,
|
void OnSaveDialogDone(electron::util::Promise<mate::Dictionary> promise,
|
||||||
bool canceled,
|
bool canceled,
|
||||||
const base::FilePath path) {
|
const base::FilePath path) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("canceled", canceled);
|
dict.Set("canceled", canceled);
|
||||||
dict.Set("filePath", path);
|
dict.Set("filePath", path);
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunSaveDialogInNewThread(const RunState& run_state,
|
void RunSaveDialogInNewThread(
|
||||||
const DialogSettings& settings,
|
const RunState& run_state,
|
||||||
electron::util::Promise promise) {
|
const DialogSettings& settings,
|
||||||
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
bool result = ShowSaveDialogSync(settings, &path);
|
bool result = ShowSaveDialogSync(settings, &path);
|
||||||
run_state.ui_task_runner->PostTask(
|
run_state.ui_task_runner->PostTask(
|
||||||
|
@ -274,13 +276,13 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
||||||
RunState run_state;
|
RunState run_state;
|
||||||
if (!CreateDialogThread(&run_state)) {
|
if (!CreateDialogThread(&run_state)) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePaths", std::vector<base::FilePath>());
|
dict.Set("filePaths", std::vector<base::FilePath>());
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
} else {
|
} else {
|
||||||
run_state.dialog_thread->task_runner()->PostTask(
|
run_state.dialog_thread->task_runner()->PostTask(
|
||||||
FROM_HERE, base::BindOnce(&RunOpenDialogInNewThread, run_state,
|
FROM_HERE, base::BindOnce(&RunOpenDialogInNewThread, run_state,
|
||||||
|
@ -324,13 +326,13 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise promise) {
|
electron::util::Promise<mate::Dictionary> promise) {
|
||||||
RunState run_state;
|
RunState run_state;
|
||||||
if (!CreateDialogThread(&run_state)) {
|
if (!CreateDialogThread(&run_state)) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePath", base::FilePath());
|
dict.Set("filePath", base::FilePath());
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
} else {
|
} else {
|
||||||
run_state.dialog_thread->task_runner()->PostTask(
|
run_state.dialog_thread->task_runner()->PostTask(
|
||||||
FROM_HERE, base::BindOnce(&RunSaveDialogInNewThread, run_state,
|
FROM_HERE, base::BindOnce(&RunSaveDialogInNewThread, run_state,
|
||||||
|
|
|
@ -54,7 +54,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
|
||||||
|
|
||||||
void ShowOpenDialog(const file_dialog::DialogSettings& settings) {
|
void ShowOpenDialog(const file_dialog::DialogSettings& settings) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<mate::Dictionary> promise(isolate);
|
||||||
|
|
||||||
auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
|
auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
|
||||||
ignore_result(promise.Then(std::move(callback)));
|
ignore_result(promise.Then(std::move(callback)));
|
||||||
|
@ -65,7 +65,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
|
||||||
void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
|
void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||||
electron::util::Promise promise(isolate);
|
electron::util::Promise<mate::Dictionary> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
file_dialog::ShowSaveDialog(settings, std::move(promise));
|
file_dialog::ShowSaveDialog(settings, std::move(promise));
|
||||||
|
|
|
@ -44,7 +44,7 @@ struct Converter<base::win::ShortcutOperation> {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void OnOpenExternalFinished(electron::util::Promise promise,
|
void OnOpenExternalFinished(electron::util::Promise<void*> promise,
|
||||||
const std::string& error) {
|
const std::string& error) {
|
||||||
if (error.empty())
|
if (error.empty())
|
||||||
promise.Resolve();
|
promise.Resolve();
|
||||||
|
@ -53,7 +53,7 @@ void OnOpenExternalFinished(electron::util::Promise promise,
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> OpenExternal(const GURL& url, mate::Arguments* args) {
|
v8::Local<v8::Promise> OpenExternal(const GURL& url, mate::Arguments* args) {
|
||||||
electron::util::Promise promise(args->isolate());
|
electron::util::Promise<void*> promise(args->isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
platform_util::OpenExternalOptions options;
|
platform_util::OpenExternalOptions options;
|
||||||
|
|
|
@ -232,7 +232,7 @@ v8::Local<v8::Value> ElectronBindings::GetSystemMemoryInfo(
|
||||||
// static
|
// static
|
||||||
v8::Local<v8::Promise> ElectronBindings::GetProcessMemoryInfo(
|
v8::Local<v8::Promise> ElectronBindings::GetProcessMemoryInfo(
|
||||||
v8::Isolate* isolate) {
|
v8::Isolate* isolate) {
|
||||||
util::Promise promise(isolate);
|
util::Promise<mate::Dictionary> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (mate::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) {
|
if (mate::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) {
|
||||||
|
@ -266,7 +266,7 @@ v8::Local<v8::Value> ElectronBindings::GetBlinkMemoryInfo(
|
||||||
// static
|
// static
|
||||||
void ElectronBindings::DidReceiveMemoryDump(
|
void ElectronBindings::DidReceiveMemoryDump(
|
||||||
v8::Global<v8::Context> context,
|
v8::Global<v8::Context> context,
|
||||||
util::Promise promise,
|
util::Promise<mate::Dictionary> promise,
|
||||||
bool success,
|
bool success,
|
||||||
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> global_dump) {
|
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> global_dump) {
|
||||||
v8::Isolate* isolate = promise.isolate();
|
v8::Isolate* isolate = promise.isolate();
|
||||||
|
@ -293,7 +293,7 @@ void ElectronBindings::DidReceiveMemoryDump(
|
||||||
#endif
|
#endif
|
||||||
dict.Set("private", osdump.private_footprint_kb);
|
dict.Set("private", osdump.private_footprint_kb);
|
||||||
dict.Set("shared", osdump.shared_footprint_kb);
|
dict.Set("shared", osdump.shared_footprint_kb);
|
||||||
promise.Resolve(dict.GetHandle());
|
promise.Resolve(dict);
|
||||||
resolved = true;
|
resolved = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class ElectronBindings {
|
||||||
|
|
||||||
static void DidReceiveMemoryDump(
|
static void DidReceiveMemoryDump(
|
||||||
v8::Global<v8::Context> context,
|
v8::Global<v8::Context> context,
|
||||||
util::Promise promise,
|
util::Promise<mate::Dictionary> promise,
|
||||||
bool success,
|
bool success,
|
||||||
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
|
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
|
||||||
|
|
||||||
|
|
|
@ -2,71 +2,21 @@
|
||||||
// Use of this source code is governed by the MIT license that can be
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "shell/common/api/locker.h"
|
|
||||||
#include "shell/common/promise_util.h"
|
#include "shell/common/promise_util.h"
|
||||||
|
|
||||||
namespace electron {
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
Promise::Promise(v8::Isolate* isolate)
|
|
||||||
: Promise(isolate,
|
|
||||||
v8::Promise::Resolver::New(isolate->GetCurrentContext())
|
|
||||||
.ToLocalChecked()) {}
|
|
||||||
|
|
||||||
Promise::Promise(v8::Isolate* isolate, v8::Local<v8::Promise::Resolver> handle)
|
|
||||||
: isolate_(isolate),
|
|
||||||
context_(isolate, isolate->GetCurrentContext()),
|
|
||||||
resolver_(isolate, handle) {}
|
|
||||||
|
|
||||||
Promise::~Promise() = default;
|
|
||||||
|
|
||||||
Promise::Promise(Promise&&) = default;
|
|
||||||
Promise& Promise::operator=(Promise&&) = default;
|
|
||||||
|
|
||||||
v8::Maybe<bool> Promise::RejectWithErrorMessage(const std::string& string) {
|
|
||||||
v8::HandleScope handle_scope(isolate());
|
|
||||||
v8::MicrotasksScope script_scope(isolate(),
|
|
||||||
v8::MicrotasksScope::kRunMicrotasks);
|
|
||||||
v8::Context::Scope context_scope(
|
|
||||||
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
|
||||||
|
|
||||||
v8::Local<v8::String> error_message =
|
|
||||||
v8::String::NewFromUtf8(isolate(), string.c_str(),
|
|
||||||
v8::NewStringType::kNormal,
|
|
||||||
static_cast<int>(string.size()))
|
|
||||||
.ToLocalChecked();
|
|
||||||
v8::Local<v8::Value> error = v8::Exception::Error(error_message);
|
|
||||||
return Reject(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::Promise> Promise::GetHandle() const {
|
|
||||||
return GetInner()->GetPromise();
|
|
||||||
}
|
|
||||||
|
|
||||||
CopyablePromise::CopyablePromise(const Promise& promise)
|
|
||||||
: isolate_(promise.isolate()), handle_(isolate_, promise.GetInner()) {}
|
|
||||||
|
|
||||||
CopyablePromise::CopyablePromise(const CopyablePromise&) = default;
|
|
||||||
|
|
||||||
CopyablePromise::~CopyablePromise() = default;
|
|
||||||
|
|
||||||
Promise CopyablePromise::GetPromise() const {
|
|
||||||
return Promise(isolate_,
|
|
||||||
v8::Local<v8::Promise::Resolver>::New(isolate_, handle_));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace util
|
|
||||||
|
|
||||||
} // namespace electron
|
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
v8::Local<v8::Value> mate::Converter<electron::util::Promise>::ToV8(
|
template <typename T>
|
||||||
|
v8::Local<v8::Value> mate::Converter<electron::util::Promise<T>>::ToV8(
|
||||||
v8::Isolate*,
|
v8::Isolate*,
|
||||||
const electron::util::Promise& val) {
|
const electron::util::Promise<T>& val) {
|
||||||
|
return val.GetHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
v8::Local<v8::Value> mate::Converter<electron::util::Promise<void*>>::ToV8(
|
||||||
|
v8::Isolate*,
|
||||||
|
const electron::util::Promise<void*>& val) {
|
||||||
return val.GetHandle();
|
return val.GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#define SHELL_COMMON_PROMISE_UTIL_H_
|
#define SHELL_COMMON_PROMISE_UTIL_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "base/task/post_task.h"
|
#include "base/task/post_task.h"
|
||||||
|
@ -24,19 +26,26 @@ namespace util {
|
||||||
//
|
//
|
||||||
// This is a move-only type that should always be `std::move`d when passed to
|
// This is a move-only type that should always be `std::move`d when passed to
|
||||||
// callbacks, and it should be destroyed on the same thread of creation.
|
// callbacks, and it should be destroyed on the same thread of creation.
|
||||||
|
template <typename RT>
|
||||||
class Promise {
|
class Promise {
|
||||||
public:
|
public:
|
||||||
// Create a new promise.
|
// Create a new promise.
|
||||||
explicit Promise(v8::Isolate* isolate);
|
explicit Promise(v8::Isolate* isolate)
|
||||||
|
: Promise(isolate,
|
||||||
|
v8::Promise::Resolver::New(isolate->GetCurrentContext())
|
||||||
|
.ToLocalChecked()) {}
|
||||||
|
|
||||||
// Wrap an existing v8 promise.
|
// Wrap an existing v8 promise.
|
||||||
Promise(v8::Isolate* isolate, v8::Local<v8::Promise::Resolver> handle);
|
Promise(v8::Isolate* isolate, v8::Local<v8::Promise::Resolver> handle)
|
||||||
|
: isolate_(isolate),
|
||||||
|
context_(isolate, isolate->GetCurrentContext()),
|
||||||
|
resolver_(isolate, handle) {}
|
||||||
|
|
||||||
~Promise();
|
~Promise() = default;
|
||||||
|
|
||||||
// Support moving.
|
// Support moving.
|
||||||
Promise(Promise&&);
|
Promise(Promise&&) = default;
|
||||||
Promise& operator=(Promise&&);
|
Promise& operator=(Promise&&) = default;
|
||||||
|
|
||||||
v8::Isolate* isolate() const { return isolate_; }
|
v8::Isolate* isolate() const { return isolate_; }
|
||||||
v8::Local<v8::Context> GetContext() {
|
v8::Local<v8::Context> GetContext() {
|
||||||
|
@ -45,35 +54,34 @@ class Promise {
|
||||||
|
|
||||||
// helpers for promise resolution and rejection
|
// helpers for promise resolution and rejection
|
||||||
|
|
||||||
template <typename T>
|
static void ResolvePromise(Promise<RT> promise, RT result) {
|
||||||
static void ResolvePromise(Promise promise, T result) {
|
|
||||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||||
base::PostTaskWithTraits(
|
base::PostTaskWithTraits(
|
||||||
FROM_HERE, {content::BrowserThread::UI},
|
FROM_HERE, {content::BrowserThread::UI},
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](Promise promise, T result) { promise.Resolve(result); },
|
[](Promise<RT> promise, RT result) { promise.Resolve(result); },
|
||||||
std::move(promise), std::move(result)));
|
std::move(promise), std::move(result)));
|
||||||
} else {
|
} else {
|
||||||
promise.Resolve(result);
|
promise.Resolve(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResolveEmptyPromise(Promise promise) {
|
static void ResolveEmptyPromise(Promise<RT> promise) {
|
||||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||||
base::PostTaskWithTraits(
|
base::PostTaskWithTraits(
|
||||||
FROM_HERE, {content::BrowserThread::UI},
|
FROM_HERE, {content::BrowserThread::UI},
|
||||||
base::BindOnce([](Promise promise) { promise.Resolve(); },
|
base::BindOnce([](Promise<RT> promise) { promise.Resolve(); },
|
||||||
std::move(promise)));
|
std::move(promise)));
|
||||||
} else {
|
} else {
|
||||||
promise.Resolve();
|
promise.Resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RejectPromise(Promise promise, std::string errmsg) {
|
static void RejectPromise(Promise<RT> promise, std::string errmsg) {
|
||||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||||
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
|
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](Promise promise, std::string errmsg) {
|
[](Promise<RT> promise, std::string errmsg) {
|
||||||
promise.RejectWithErrorMessage(errmsg);
|
promise.RejectWithErrorMessage(errmsg);
|
||||||
},
|
},
|
||||||
std::move(promise), std::move(errmsg)));
|
std::move(promise), std::move(errmsg)));
|
||||||
|
@ -83,23 +91,24 @@ class Promise {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns an already-resolved promise.
|
// Returns an already-resolved promise.
|
||||||
template <typename T>
|
|
||||||
static v8::Local<v8::Promise> ResolvedPromise(v8::Isolate* isolate,
|
static v8::Local<v8::Promise> ResolvedPromise(v8::Isolate* isolate,
|
||||||
T result) {
|
RT result) {
|
||||||
Promise resolved(isolate);
|
Promise<RT> resolved(isolate);
|
||||||
resolved.Resolve(result);
|
resolved.Resolve(result);
|
||||||
return resolved.GetHandle();
|
return resolved.GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
static v8::Local<v8::Promise> ResolvedPromise(v8::Isolate* isolate) {
|
static v8::Local<v8::Promise> ResolvedPromise(v8::Isolate* isolate) {
|
||||||
Promise resolved(isolate);
|
Promise<void*> resolved(isolate);
|
||||||
resolved.Resolve();
|
resolved.Resolve();
|
||||||
return resolved.GetHandle();
|
return resolved.GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> GetHandle() const;
|
v8::Local<v8::Promise> GetHandle() const { return GetInner()->GetPromise(); }
|
||||||
|
|
||||||
v8::Maybe<bool> Resolve() {
|
v8::Maybe<bool> Resolve() {
|
||||||
|
static_assert(std::is_same<void*, RT>(),
|
||||||
|
"Can only resolve void* promises with no value");
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::MicrotasksScope script_scope(isolate(),
|
v8::MicrotasksScope script_scope(isolate(),
|
||||||
v8::MicrotasksScope::kRunMicrotasks);
|
v8::MicrotasksScope::kRunMicrotasks);
|
||||||
|
@ -119,25 +128,16 @@ class Promise {
|
||||||
return GetInner()->Reject(GetContext(), v8::Undefined(isolate()));
|
return GetInner()->Reject(GetContext(), v8::Undefined(isolate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Please note that using Then is effectively the same as calling .then
|
|
||||||
// in javascript. This means (a) it is not type safe and (b) please note
|
|
||||||
// it is NOT type safe.
|
|
||||||
// If the base::Callback you provide here is of type void(boolean) and you
|
|
||||||
// resolve the promise with a string, Electron will compile successfully and
|
|
||||||
// then that promise will be rejected as soon as you try to use it as the
|
|
||||||
// mate converters doing work behind the scenes will throw an error for you.
|
|
||||||
// This can be really hard to trace so until either
|
|
||||||
// * This helper becomes typesafe (by templating the class instead of each
|
|
||||||
// method)
|
|
||||||
// * or the world goes mad
|
|
||||||
// Please try your hardest not to use this method
|
|
||||||
// The world thanks you
|
|
||||||
template <typename... ResolveType>
|
template <typename... ResolveType>
|
||||||
v8::MaybeLocal<v8::Promise> Then(
|
v8::MaybeLocal<v8::Promise> Then(
|
||||||
base::OnceCallback<void(ResolveType...)> cb) {
|
base::OnceCallback<void(ResolveType...)> cb) {
|
||||||
static_assert(sizeof...(ResolveType) <= 1,
|
static_assert(sizeof...(ResolveType) <= 1,
|
||||||
"A promise's 'Then' callback should only receive at most one "
|
"A promise's 'Then' callback should only receive at most one "
|
||||||
"parameter");
|
"parameter");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<RT, std::tuple_element_t<0, std::tuple<ResolveType...>>>(),
|
||||||
|
"A promises's 'Then' callback must handle the same type as the "
|
||||||
|
"promises resolve type");
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::Context::Scope context_scope(
|
v8::Context::Scope context_scope(
|
||||||
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
||||||
|
@ -150,8 +150,9 @@ class Promise {
|
||||||
|
|
||||||
// Promise resolution is a microtask
|
// Promise resolution is a microtask
|
||||||
// We use the MicrotasksRunner to trigger the running of pending microtasks
|
// We use the MicrotasksRunner to trigger the running of pending microtasks
|
||||||
template <typename T>
|
v8::Maybe<bool> Resolve(const RT& value) {
|
||||||
v8::Maybe<bool> Resolve(const T& value) {
|
static_assert(!std::is_same<void*, RT>(),
|
||||||
|
"void* promises can not be resolved with a value");
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::MicrotasksScope script_scope(isolate(),
|
v8::MicrotasksScope script_scope(isolate(),
|
||||||
v8::MicrotasksScope::kRunMicrotasks);
|
v8::MicrotasksScope::kRunMicrotasks);
|
||||||
|
@ -162,23 +163,36 @@ class Promise {
|
||||||
mate::ConvertToV8(isolate(), value));
|
mate::ConvertToV8(isolate(), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
v8::Maybe<bool> ResolveWithGin(const RT& value) {
|
||||||
v8::Maybe<bool> Reject(const T& value) {
|
static_assert(!std::is_same<void*, RT>(),
|
||||||
|
"void* promises can not be resolved with a value");
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::MicrotasksScope script_scope(isolate(),
|
v8::MicrotasksScope script_scope(isolate(),
|
||||||
v8::MicrotasksScope::kRunMicrotasks);
|
v8::MicrotasksScope::kRunMicrotasks);
|
||||||
v8::Context::Scope context_scope(
|
v8::Context::Scope context_scope(
|
||||||
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
||||||
|
|
||||||
return GetInner()->Reject(GetContext(),
|
return GetInner()->Resolve(GetContext(),
|
||||||
mate::ConvertToV8(isolate(), value));
|
gin::ConvertToV8(isolate(), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Maybe<bool> RejectWithErrorMessage(const std::string& error);
|
v8::Maybe<bool> RejectWithErrorMessage(const std::string& string) {
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
v8::MicrotasksScope script_scope(isolate(),
|
||||||
|
v8::MicrotasksScope::kRunMicrotasks);
|
||||||
|
v8::Context::Scope context_scope(
|
||||||
|
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
||||||
|
|
||||||
|
v8::Local<v8::String> error_message =
|
||||||
|
v8::String::NewFromUtf8(isolate(), string.c_str(),
|
||||||
|
v8::NewStringType::kNormal,
|
||||||
|
static_cast<int>(string.size()))
|
||||||
|
.ToLocalChecked();
|
||||||
|
v8::Local<v8::Value> error = v8::Exception::Error(error_message);
|
||||||
|
return GetInner()->Reject(GetContext(), (error));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CopyablePromise;
|
|
||||||
|
|
||||||
v8::Local<v8::Promise::Resolver> GetInner() const {
|
v8::Local<v8::Promise::Resolver> GetInner() const {
|
||||||
return resolver_.Get(isolate());
|
return resolver_.Get(isolate());
|
||||||
}
|
}
|
||||||
|
@ -190,70 +204,16 @@ class Promise {
|
||||||
DISALLOW_COPY_AND_ASSIGN(Promise);
|
DISALLOW_COPY_AND_ASSIGN(Promise);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A wrapper of Promise that can be copied.
|
|
||||||
//
|
|
||||||
// This class should only be used when we have to pass Promise to a Chromium API
|
|
||||||
// that does not take OnceCallback.
|
|
||||||
class CopyablePromise {
|
|
||||||
public:
|
|
||||||
explicit CopyablePromise(const Promise& promise);
|
|
||||||
CopyablePromise(const CopyablePromise&);
|
|
||||||
~CopyablePromise();
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static void ResolveCopyablePromise(const CopyablePromise& promise, T result) {
|
|
||||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
|
||||||
base::PostTaskWithTraits(
|
|
||||||
FROM_HERE, {content::BrowserThread::UI},
|
|
||||||
base::BindOnce(Promise::ResolvePromise<T>, promise.GetPromise(),
|
|
||||||
std::move(result)));
|
|
||||||
} else {
|
|
||||||
promise.GetPromise().Resolve(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ResolveEmptyCopyablePromise(const CopyablePromise& promise) {
|
|
||||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
|
||||||
base::PostTaskWithTraits(
|
|
||||||
FROM_HERE, {content::BrowserThread::UI},
|
|
||||||
base::BindOnce(Promise::ResolveEmptyPromise, promise.GetPromise()));
|
|
||||||
} else {
|
|
||||||
promise.GetPromise().Resolve();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void RejectCopyablePromise(const CopyablePromise& promise,
|
|
||||||
std::string errmsg) {
|
|
||||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
|
||||||
base::PostTaskWithTraits(
|
|
||||||
FROM_HERE, {content::BrowserThread::UI},
|
|
||||||
base::BindOnce(Promise::RejectPromise, promise.GetPromise(),
|
|
||||||
std::move(errmsg)));
|
|
||||||
} else {
|
|
||||||
promise.GetPromise().RejectWithErrorMessage(errmsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Promise GetPromise() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
using CopyablePersistent =
|
|
||||||
v8::CopyablePersistentTraits<v8::Promise::Resolver>::CopyablePersistent;
|
|
||||||
|
|
||||||
v8::Isolate* isolate_;
|
|
||||||
CopyablePersistent handle_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
template <>
|
template <typename T>
|
||||||
struct Converter<electron::util::Promise> {
|
struct Converter<electron::util::Promise<T>> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const electron::util::Promise& val);
|
const electron::util::Promise<T>& val);
|
||||||
// TODO(MarshallOfSound): Implement FromV8 to allow promise chaining
|
// TODO(MarshallOfSound): Implement FromV8 to allow promise chaining
|
||||||
// in native land
|
// in native land
|
||||||
// static bool FromV8(v8::Isolate* isolate,
|
// static bool FromV8(v8::Isolate* isolate,
|
||||||
|
|
|
@ -75,12 +75,12 @@ class IPCRenderer : public mate::Wrappable<IPCRenderer> {
|
||||||
v8::Local<v8::Promise> Invoke(mate::Arguments* args,
|
v8::Local<v8::Promise> Invoke(mate::Arguments* args,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
const base::Value& arguments) {
|
const base::Value& arguments) {
|
||||||
electron::util::Promise p(args->isolate());
|
electron::util::Promise<base::Value> p(args->isolate());
|
||||||
auto handle = p.GetHandle();
|
auto handle = p.GetHandle();
|
||||||
|
|
||||||
electron_browser_ptr_->get()->Invoke(
|
electron_browser_ptr_->get()->Invoke(
|
||||||
channel, arguments.Clone(),
|
channel, arguments.Clone(),
|
||||||
base::BindOnce([](electron::util::Promise p,
|
base::BindOnce([](electron::util::Promise<base::Value> p,
|
||||||
base::Value result) { p.Resolve(result); },
|
base::Value result) { p.Resolve(result); },
|
||||||
std::move(p)));
|
std::move(p)));
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,8 @@ class RenderFrameStatus : public content::RenderFrameObserver {
|
||||||
|
|
||||||
class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
|
class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
|
||||||
public:
|
public:
|
||||||
explicit ScriptExecutionCallback(electron::util::Promise promise)
|
explicit ScriptExecutionCallback(
|
||||||
|
electron::util::Promise<v8::Local<v8::Value>> promise)
|
||||||
: promise_(std::move(promise)) {}
|
: promise_(std::move(promise)) {}
|
||||||
~ScriptExecutionCallback() override {}
|
~ScriptExecutionCallback() override {}
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
electron::util::Promise promise_;
|
electron::util::Promise<v8::Local<v8::Value>> promise_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ScriptExecutionCallback);
|
DISALLOW_COPY_AND_ASSIGN(ScriptExecutionCallback);
|
||||||
};
|
};
|
||||||
|
@ -376,7 +377,7 @@ v8::Local<v8::Promise> ExecuteJavaScript(mate::Arguments* args,
|
||||||
v8::Local<v8::Value> window,
|
v8::Local<v8::Value> window,
|
||||||
const base::string16& code) {
|
const base::string16& code) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
util::Promise promise(isolate);
|
util::Promise<v8::Local<v8::Value>> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
bool has_user_gesture = false;
|
bool has_user_gesture = false;
|
||||||
|
@ -395,7 +396,7 @@ v8::Local<v8::Promise> ExecuteJavaScriptInIsolatedWorld(
|
||||||
int world_id,
|
int world_id,
|
||||||
const std::vector<mate::Dictionary>& scripts) {
|
const std::vector<mate::Dictionary>& scripts) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
util::Promise promise(isolate);
|
util::Promise<v8::Local<v8::Value>> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
std::vector<blink::WebScriptSource> sources;
|
std::vector<blink::WebScriptSource> sources;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче