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

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
« 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 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->LookupServiceExtensionHandler(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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 while (current != NULL) { 907 while (current != NULL) {
885 if (strcmp(name, current->name()) == 0) { 908 if (strcmp(name, current->name()) == 0) {
886 return current; 909 return current;
887 } 910 }
888 current = current->next(); 911 current = current->next();
889 } 912 }
890 return NULL; 913 return NULL;
891 } 914 }
892 915
893 916
894 bool Service::ScheduleExtensionHandler(const String& method_name, 917 void Service::ScheduleExtensionHandler(const Instance& handler,
918 const String& method_name,
895 const Array& parameter_keys, 919 const Array& parameter_keys,
896 const Array& parameter_values, 920 const Array& parameter_values,
897 const Instance& reply_port, 921 const Instance& reply_port,
898 const Instance& id) { 922 const Instance& id) {
923 ASSERT(!handler.IsNull());
899 ASSERT(!method_name.IsNull()); 924 ASSERT(!method_name.IsNull());
900 ASSERT(!parameter_keys.IsNull()); 925 ASSERT(!parameter_keys.IsNull());
901 ASSERT(!parameter_values.IsNull()); 926 ASSERT(!parameter_values.IsNull());
902 ASSERT(!reply_port.IsNull()); 927 ASSERT(!reply_port.IsNull());
903 const Library& developer_lib = Library::Handle(Library::DeveloperLibrary()); 928 Isolate* isolate = Isolate::Current();
904 ASSERT(!developer_lib.IsNull()); 929 ASSERT(isolate != NULL);
905 const Function& schedule_extension = Function::Handle( 930 isolate->AppendServiceExtensionCall(handler,
906 developer_lib.LookupLocalFunction(Symbols::_scheduleExtension())); 931 method_name,
907 ASSERT(!schedule_extension.IsNull()); 932 parameter_keys,
908 const Array& arguments = Array::Handle(Array::New(5)); 933 parameter_values,
909 arguments.SetAt(0, method_name); 934 reply_port,
910 arguments.SetAt(1, parameter_keys); 935 id);
911 arguments.SetAt(2, parameter_values);
912 arguments.SetAt(3, reply_port);
913 arguments.SetAt(4, id);
914 return (DartEntry::InvokeFunction(schedule_extension, arguments) ==
915 Object::bool_true().raw());
916 } 936 }
917 937
918 938
919 static const MethodParameter* get_isolate_params[] = { 939 static const MethodParameter* get_isolate_params[] = {
920 ISOLATE_PARAMETER, 940 ISOLATE_PARAMETER,
921 NULL, 941 NULL,
922 }; 942 };
923 943
924 944
925 static bool GetIsolate(Isolate* isolate, JSONStream* js) { 945 static bool GetIsolate(Isolate* isolate, JSONStream* js) {
(...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 ServiceMethodDescriptor& method = service_methods_[i]; 3162 ServiceMethodDescriptor& method = service_methods_[i];
3143 if (strcmp(method_name, method.name) == 0) { 3163 if (strcmp(method_name, method.name) == 0) {
3144 return &method; 3164 return &method;
3145 } 3165 }
3146 } 3166 }
3147 return NULL; 3167 return NULL;
3148 } 3168 }
3149 3169
3150 3170
3151 } // namespace dart 3171 } // 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