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

Side by Side Diff: runtime/vm/service.cc

Issue 1299493007: Rework service extensions to be safe (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 498 }
499 if (has_parameter && !parameter->Validate(value)) { 499 if (has_parameter && !parameter->Validate(value)) {
500 PrintInvalidParamError(js, name); 500 PrintInvalidParamError(js, name);
501 return false; 501 return false;
502 } 502 }
503 } 503 }
504 return true; 504 return true;
505 } 505 }
506 506
507 507
508 void Service::PostError(const String& method_name,
509 const Array& parameter_keys,
510 const Array& parameter_values,
511 const Instance& reply_port,
512 const Instance& id,
513 const Error& error) {
514 Isolate* isolate = Isolate::Current();
515 StackZone zone(isolate);
516 HANDLESCOPE(isolate);
517 JSONStream js;
518 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(),
519 id, method_name, parameter_keys, parameter_values);
520 js.PrintError(kExtensionError,
521 "Error in extension `%s`: %s",
522 js.method(), error.ToErrorCString());
523 js.PostReply();
524 }
525
526
508 void Service::InvokeMethod(Isolate* isolate, const Array& msg) { 527 void Service::InvokeMethod(Isolate* isolate, const Array& msg) {
509 ASSERT(isolate != NULL); 528 ASSERT(isolate != NULL);
510 ASSERT(!msg.IsNull()); 529 ASSERT(!msg.IsNull());
511 ASSERT(msg.Length() == 6); 530 ASSERT(msg.Length() == 6);
512 531
513 { 532 {
514 StackZone zone(isolate); 533 StackZone zone(isolate);
515 HANDLESCOPE(isolate); 534 HANDLESCOPE(isolate);
516 535
517 Instance& reply_port = Instance::Handle(isolate); 536 Instance& reply_port = Instance::Handle(isolate);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 if (handler == NULL) { 603 if (handler == NULL) {
585 handler = FindRootEmbedderHandler(c_method_name); 604 handler = FindRootEmbedderHandler(c_method_name);
586 } 605 }
587 606
588 if (handler != NULL) { 607 if (handler != NULL) {
589 EmbedderHandleMessage(handler, &js); 608 EmbedderHandleMessage(handler, &js);
590 js.PostReply(); 609 js.PostReply();
591 return; 610 return;
592 } 611 }
593 612
594 if (ScheduleExtensionHandler(method_name, 613 const Instance& extension_handler =
595 param_keys, 614 Instance::Handle(isolate->LookupExtensionHandler(method_name));
596 param_values, 615 if (!extension_handler.IsNull()) {
597 reply_port, 616 ScheduleExtensionHandler(extension_handler,
598 seq)) { 617 method_name,
618 param_keys,
619 param_values,
620 reply_port,
621 seq);
599 // Schedule was successful. Extension code will post a reply 622 // Schedule was successful. Extension code will post a reply
600 // asynchronously. 623 // asynchronously.
601 return; 624 return;
602 } 625 }
603 626
604 PrintUnrecognizedMethodError(&js); 627 PrintUnrecognizedMethodError(&js);
605 js.PostReply(); 628 js.PostReply();
606 return; 629 return;
607 } 630 }
608 } 631 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 while (current != NULL) { 901 while (current != NULL) {
879 if (strcmp(name, current->name()) == 0) { 902 if (strcmp(name, current->name()) == 0) {
880 return current; 903 return current;
881 } 904 }
882 current = current->next(); 905 current = current->next();
883 } 906 }
884 return NULL; 907 return NULL;
885 } 908 }
886 909
887 910
888 bool Service::ScheduleExtensionHandler(const String& method_name, 911 void Service::ScheduleExtensionHandler(const Instance& handler,
912 const String& method_name,
889 const Array& parameter_keys, 913 const Array& parameter_keys,
890 const Array& parameter_values, 914 const Array& parameter_values,
891 const Instance& reply_port, 915 const Instance& reply_port,
892 const Instance& id) { 916 const Instance& id) {
917 ASSERT(!handler.IsNull());
893 ASSERT(!method_name.IsNull()); 918 ASSERT(!method_name.IsNull());
894 ASSERT(!parameter_keys.IsNull()); 919 ASSERT(!parameter_keys.IsNull());
895 ASSERT(!parameter_values.IsNull()); 920 ASSERT(!parameter_values.IsNull());
896 ASSERT(!reply_port.IsNull()); 921 ASSERT(!reply_port.IsNull());
897 const Library& developer_lib = Library::Handle(Library::DeveloperLibrary()); 922 Isolate* isolate = Isolate::Current();
898 ASSERT(!developer_lib.IsNull()); 923 ASSERT(isolate != NULL);
899 const Function& schedule_extension = Function::Handle( 924 isolate->AppendExtensionCall(handler,
900 developer_lib.LookupLocalFunction(Symbols::_scheduleExtension())); 925 method_name,
901 ASSERT(!schedule_extension.IsNull()); 926 parameter_keys,
902 const Array& arguments = Array::Handle(Array::New(5)); 927 parameter_values,
903 arguments.SetAt(0, method_name); 928 reply_port,
904 arguments.SetAt(1, parameter_keys); 929 id);
905 arguments.SetAt(2, parameter_values);
906 arguments.SetAt(3, reply_port);
907 arguments.SetAt(4, id);
908 return (DartEntry::InvokeFunction(schedule_extension, arguments) ==
909 Object::bool_true().raw());
910 } 930 }
911 931
912 932
913 static const MethodParameter* get_isolate_params[] = { 933 static const MethodParameter* get_isolate_params[] = {
914 ISOLATE_PARAMETER, 934 ISOLATE_PARAMETER,
915 NULL, 935 NULL,
916 }; 936 };
917 937
918 938
919 static bool GetIsolate(Isolate* isolate, JSONStream* js) { 939 static bool GetIsolate(Isolate* isolate, JSONStream* js) {
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after
3134 ServiceMethodDescriptor& method = service_methods_[i]; 3154 ServiceMethodDescriptor& method = service_methods_[i];
3135 if (strcmp(method_name, method.name) == 0) { 3155 if (strcmp(method_name, method.name) == 0) {
3136 return &method; 3156 return &method;
3137 } 3157 }
3138 } 3158 }
3139 return NULL; 3159 return NULL;
3140 } 3160 }
3141 3161
3142 3162
3143 } // namespace dart 3163 } // namespace dart
OLDNEW
« runtime/vm/isolate.cc ('K') | « runtime/vm/service.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698