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

Unified Diff: extensions/renderer/api_binding_js_util.cc

Issue 2762623003: [Extensions Bindings] Add lastError utilities to APIBindingJSUtil (Closed)
Patch Set: Rebase 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 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
« 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