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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/service.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/service.h" 5 #include "vm/service.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/globals.h" 9 #include "platform/globals.h"
10 10
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 if (handler == NULL) { 578 if (handler == NULL) {
579 handler = FindRootEmbedderHandler(c_method_name); 579 handler = FindRootEmbedderHandler(c_method_name);
580 } 580 }
581 581
582 if (handler != NULL) { 582 if (handler != NULL) {
583 EmbedderHandleMessage(handler, &js); 583 EmbedderHandleMessage(handler, &js);
584 js.PostReply(); 584 js.PostReply();
585 return; 585 return;
586 } 586 }
587 587
588 if (ExtensionHandlerExists(method_name)) {
589 InvokeExtensionHandler(method_name,
590 param_keys,
591 param_values,
592 reply_port,
593 seq);
594 // The reply is posted asynchronously.
595 return;
596 }
597
588 PrintUnrecognizedMethodError(&js); 598 PrintUnrecognizedMethodError(&js);
589 js.PostReply(); 599 js.PostReply();
590 return; 600 return;
591 } 601 }
592 } 602 }
593 603
594 604
595 void Service::HandleRootMessage(const Array& msg_instance) { 605 void Service::HandleRootMessage(const Array& msg_instance) {
596 Isolate* isolate = Isolate::Current(); 606 Isolate* isolate = Isolate::Current();
597 InvokeMethod(isolate, msg_instance); 607 InvokeMethod(isolate, msg_instance);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 while (current != NULL) { 872 while (current != NULL) {
863 if (strcmp(name, current->name()) == 0) { 873 if (strcmp(name, current->name()) == 0) {
864 return current; 874 return current;
865 } 875 }
866 current = current->next(); 876 current = current->next();
867 } 877 }
868 return NULL; 878 return NULL;
869 } 879 }
870 880
871 881
882 bool Service::ExtensionHandlerExists(const String& method) {
883 ASSERT(!method.IsNull());
884 const Library& developer_lib = Library::Handle(Library::DeveloperLibrary());
885 ASSERT(!developer_lib.IsNull());
886 const Function& extension_exists = Function::Handle(
887 developer_lib.LookupLocalFunction(Symbols::_extensionExists()));
888 ASSERT(!extension_exists.IsNull());
889 const Array& arguments = Array::Handle(Array::New(1));
890 ASSERT(!arguments.IsNull());
891 arguments.SetAt(0, method);
892 return (DartEntry::InvokeFunction(extension_exists, arguments) ==
893 Object::bool_true().raw());
894 }
895
896
897 bool Service::InvokeExtensionHandler(const String& method_name,
898 const Array& parameter_keys,
899 const Array& parameter_values,
900 const Instance& reply_port,
901 const Instance& id) {
902 ASSERT(!method_name.IsNull());
903 ASSERT(!parameter_keys.IsNull());
904 ASSERT(!parameter_values.IsNull());
905 ASSERT(!reply_port.IsNull());
906 const Library& developer_lib = Library::Handle(Library::DeveloperLibrary());
907 ASSERT(!developer_lib.IsNull());
908 const Function& invoke_extension = Function::Handle(
909 developer_lib.LookupLocalFunction(Symbols::_invokeExtension()));
910 ASSERT(!invoke_extension.IsNull());
911 const Array& arguments = Array::Handle(Array::New(5));
912 arguments.SetAt(0, method_name);
913 arguments.SetAt(1, parameter_keys);
914 arguments.SetAt(2, parameter_values);
915 arguments.SetAt(3, reply_port);
916 arguments.SetAt(4, id);
917 return (DartEntry::InvokeFunction(invoke_extension, arguments) ==
918 Object::bool_true().raw());
919 }
920
921
872 static const MethodParameter* get_isolate_params[] = { 922 static const MethodParameter* get_isolate_params[] = {
873 ISOLATE_PARAMETER, 923 ISOLATE_PARAMETER,
874 NULL, 924 NULL,
875 }; 925 };
876 926
877 927
878 static bool GetIsolate(Isolate* isolate, JSONStream* js) { 928 static bool GetIsolate(Isolate* isolate, JSONStream* js) {
879 isolate->PrintJSON(js, false); 929 isolate->PrintJSON(js, false);
880 return true; 930 return true;
881 } 931 }
(...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 ServiceMethodDescriptor& method = service_methods_[i]; 3134 ServiceMethodDescriptor& method = service_methods_[i];
3085 if (strcmp(method_name, method.name) == 0) { 3135 if (strcmp(method_name, method.name) == 0) {
3086 return &method; 3136 return &method;
3087 } 3137 }
3088 } 3138 }
3089 return NULL; 3139 return NULL;
3090 } 3140 }
3091 3141
3092 3142
3093 } // namespace dart 3143 } // namespace dart
OLDNEW
« 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