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

Unified Diff: runtime/vm/service.cc

Issue 1270103002: Allow Dart code to register service protocol handlers (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 | « runtime/vm/service.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/service.cc
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
index 6f4fd03d4d14791d0f72abcb848b08fda3063987..3868b9ca7dd8ad18ef946a3f5d6da57e66553e73 100644
--- a/runtime/vm/service.cc
+++ b/runtime/vm/service.cc
@@ -585,6 +585,16 @@ void Service::InvokeMethod(Isolate* isolate, const Array& msg) {
return;
}
+ if (ExtensionHandlerExists(method_name)) {
+ InvokeExtensionHandler(method_name,
+ param_keys,
+ param_values,
+ reply_port,
+ seq);
+ // The reply is posted asynchronously.
+ return;
+ }
+
PrintUnrecognizedMethodError(&js);
js.PostReply();
return;
@@ -869,6 +879,46 @@ EmbedderServiceHandler* Service::FindRootEmbedderHandler(
}
+bool Service::ExtensionHandlerExists(const String& method) {
+ ASSERT(!method.IsNull());
+ const Library& developer_lib = Library::Handle(Library::DeveloperLibrary());
+ ASSERT(!developer_lib.IsNull());
+ const Function& extension_exists = Function::Handle(
+ developer_lib.LookupLocalFunction(Symbols::_extensionExists()));
+ ASSERT(!extension_exists.IsNull());
+ const Array& arguments = Array::Handle(Array::New(1));
+ ASSERT(!arguments.IsNull());
+ arguments.SetAt(0, method);
+ return (DartEntry::InvokeFunction(extension_exists, arguments) ==
+ Object::bool_true().raw());
+}
+
+
+bool Service::InvokeExtensionHandler(const String& method_name,
+ const Array& parameter_keys,
+ const Array& parameter_values,
+ const Instance& reply_port,
+ const Instance& id) {
+ ASSERT(!method_name.IsNull());
+ ASSERT(!parameter_keys.IsNull());
+ ASSERT(!parameter_values.IsNull());
+ ASSERT(!reply_port.IsNull());
+ const Library& developer_lib = Library::Handle(Library::DeveloperLibrary());
+ ASSERT(!developer_lib.IsNull());
+ const Function& invoke_extension = Function::Handle(
+ developer_lib.LookupLocalFunction(Symbols::_invokeExtension()));
+ ASSERT(!invoke_extension.IsNull());
+ const Array& arguments = Array::Handle(Array::New(5));
+ arguments.SetAt(0, method_name);
+ arguments.SetAt(1, parameter_keys);
+ arguments.SetAt(2, parameter_values);
+ arguments.SetAt(3, reply_port);
+ arguments.SetAt(4, id);
+ return (DartEntry::InvokeFunction(invoke_extension, arguments) ==
+ Object::bool_true().raw());
+}
+
+
static const MethodParameter* get_isolate_params[] = {
ISOLATE_PARAMETER,
NULL,
« no previous file with comments | « runtime/vm/service.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698