Index: extensions/renderer/api_binding_js_util.cc |
diff --git a/extensions/renderer/api_binding_js_util.cc b/extensions/renderer/api_binding_js_util.cc |
index 84b596633a96f228138e483200712a74e71c5a03..d88d2315341ed8864d1d66f3f16c9d661992ad51 100644 |
--- a/extensions/renderer/api_binding_js_util.cc |
+++ b/extensions/renderer/api_binding_js_util.cc |
@@ -18,10 +18,12 @@ gin::WrapperInfo APIBindingJSUtil::kWrapperInfo = {gin::kEmbedderNativeGin}; |
APIBindingJSUtil::APIBindingJSUtil(const APITypeReferenceMap* type_refs, |
APIRequestHandler* request_handler, |
- APIEventHandler* event_handler) |
+ APIEventHandler* event_handler, |
+ const binding::RunJSFunction& run_js) |
: type_refs_(type_refs), |
request_handler_(request_handler), |
- event_handler_(event_handler) {} |
+ event_handler_(event_handler), |
+ run_js_(run_js) {} |
APIBindingJSUtil::~APIBindingJSUtil() {} |
@@ -32,7 +34,12 @@ gin::ObjectTemplateBuilder APIBindingJSUtil::GetObjectTemplateBuilder( |
.SetMethod("registerEventArgumentMassager", |
&APIBindingJSUtil::RegisterEventArgumentMassager) |
.SetMethod("createCustomEvent", &APIBindingJSUtil::CreateCustomEvent) |
- .SetMethod("invalidateEvent", &APIBindingJSUtil::InvalidateEvent); |
+ .SetMethod("invalidateEvent", &APIBindingJSUtil::InvalidateEvent) |
+ .SetMethod("setLastError", &APIBindingJSUtil::SetLastError) |
+ .SetMethod("clearLastError", &APIBindingJSUtil::ClearLastError) |
+ .SetMethod("hasLastError", &APIBindingJSUtil::HasLastError) |
+ .SetMethod("runCallbackWithLastError", |
+ &APIBindingJSUtil::RunCallbackWithLastError); |
} |
void APIBindingJSUtil::SendRequest( |
@@ -118,4 +125,54 @@ void APIBindingJSUtil::InvalidateEvent(gin::Arguments* arguments, |
event_handler_->InvalidateCustomEvent(context, event); |
} |
+void APIBindingJSUtil::SetLastError(gin::Arguments* arguments, |
+ const std::string& error) { |
+ v8::Isolate* isolate = arguments->isolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Local<v8::Object> holder; |
+ CHECK(arguments->GetHolder(&holder)); |
+ v8::Local<v8::Context> context = holder->CreationContext(); |
+ |
+ request_handler_->last_error()->SetError(context, error); |
+} |
+ |
+void APIBindingJSUtil::ClearLastError(gin::Arguments* arguments) { |
+ v8::Isolate* isolate = arguments->isolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Local<v8::Object> holder; |
+ CHECK(arguments->GetHolder(&holder)); |
+ v8::Local<v8::Context> context = holder->CreationContext(); |
+ |
+ bool report_if_unchecked = false; |
+ request_handler_->last_error()->ClearError(context, report_if_unchecked); |
+} |
+ |
+void APIBindingJSUtil::HasLastError(gin::Arguments* arguments) { |
+ v8::Isolate* isolate = arguments->isolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Local<v8::Object> holder; |
+ CHECK(arguments->GetHolder(&holder)); |
+ v8::Local<v8::Context> context = holder->CreationContext(); |
+ |
+ bool has_last_error = request_handler_->last_error()->HasError(context); |
+ arguments->Return(has_last_error); |
+} |
+ |
+void APIBindingJSUtil::RunCallbackWithLastError( |
+ gin::Arguments* arguments, |
+ const std::string& error, |
+ v8::Local<v8::Function> callback) { |
+ v8::Isolate* isolate = arguments->isolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Local<v8::Object> holder; |
+ CHECK(arguments->GetHolder(&holder)); |
+ v8::Local<v8::Context> context = holder->CreationContext(); |
+ |
+ request_handler_->last_error()->SetError(context, error); |
+ run_js_.Run(callback, context, 0, nullptr); |
+ |
+ bool report_if_unchecked = true; |
+ request_handler_->last_error()->ClearError(context, report_if_unchecked); |
+} |
+ |
} // namespace extensions |