Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Unified Diff: extensions/renderer/api_binding_js_util.cc

Issue 2762623003: [Extensions Bindings] Add lastError utilities to APIBindingJSUtil (Closed)
Patch Set: jbroman's Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/api_binding_js_util.h ('k') | extensions/renderer/api_binding_js_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d554bb54d1006e7e65d8d89e8f3b2e741cfbc491..99bfd731adfd4c06e2379a0c49bdcfd7e4d12d17 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(
@@ -114,4 +121,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);
jbroman 2017/03/21 22:02:47 nit: Since the gin::Wrappable isn't shared between
Devlin 2017/03/21 22:51:19 Oooh, fancy. For consistency's sake, I'll stick w
+}
+
+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
« no previous file with comments | « extensions/renderer/api_binding_js_util.h ('k') | extensions/renderer/api_binding_js_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698