| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 library http_server_mojom; | 5 library http_server_mojom; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'package:mojo/bindings.dart' as bindings; | 7 import 'package:mojo/bindings.dart' as bindings; |
| 8 import 'package:mojo/core.dart' as core; | 8 import 'package:mojo/core.dart' as core; |
| 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic
e_describer; | 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic
e_describer; |
| 10 import 'package:mojo_services/http_server/http_request.mojom.dart' as http_reque
st_mojom; | 10 import 'package:mojo_services/http_server/http_request.mojom.dart' as http_reque
st_mojom; |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 responseFactory(null); | 455 responseFactory(null); |
| 456 } | 456 } |
| 457 | 457 |
| 458 abstract class HttpServer { | 458 abstract class HttpServer { |
| 459 static const String serviceName = null; | 459 static const String serviceName = null; |
| 460 dynamic setHandler(String pattern,Object handler,[Function responseFactory = n
ull]); | 460 dynamic setHandler(String pattern,Object handler,[Function responseFactory = n
ull]); |
| 461 dynamic getPort([Function responseFactory = null]); | 461 dynamic getPort([Function responseFactory = null]); |
| 462 } | 462 } |
| 463 | 463 |
| 464 | 464 |
| 465 class _HttpServerProxyImpl extends bindings.Proxy { | 465 class _HttpServerProxyControl extends bindings.ProxyMessageHandler |
| 466 _HttpServerProxyImpl.fromEndpoint( | 466 implements bindings.ProxyControl { |
| 467 _HttpServerProxyControl.fromEndpoint( |
| 467 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 468 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
| 468 | 469 |
| 469 _HttpServerProxyImpl.fromHandle(core.MojoHandle handle) : | 470 _HttpServerProxyControl.fromHandle( |
| 470 super.fromHandle(handle); | 471 core.MojoHandle handle) : super.fromHandle(handle); |
| 471 | 472 |
| 472 _HttpServerProxyImpl.unbound() : super.unbound(); | 473 _HttpServerProxyControl.unbound() : super.unbound(); |
| 473 | |
| 474 static _HttpServerProxyImpl newFromEndpoint( | |
| 475 core.MojoMessagePipeEndpoint endpoint) { | |
| 476 assert(endpoint.setDescription("For _HttpServerProxyImpl")); | |
| 477 return new _HttpServerProxyImpl.fromEndpoint(endpoint); | |
| 478 } | |
| 479 | 474 |
| 480 service_describer.ServiceDescription get serviceDescription => | 475 service_describer.ServiceDescription get serviceDescription => |
| 481 new _HttpServerServiceDescription(); | 476 new _HttpServerServiceDescription(); |
| 482 | 477 |
| 478 String get serviceName => HttpServer.serviceName; |
| 479 |
| 480 @override |
| 483 void handleResponse(bindings.ServiceMessage message) { | 481 void handleResponse(bindings.ServiceMessage message) { |
| 484 switch (message.header.type) { | 482 switch (message.header.type) { |
| 485 case _httpServerMethodSetHandlerName: | 483 case _httpServerMethodSetHandlerName: |
| 486 var r = HttpServerSetHandlerResponseParams.deserialize( | 484 var r = HttpServerSetHandlerResponseParams.deserialize( |
| 487 message.payload); | 485 message.payload); |
| 488 if (!message.header.hasRequestId) { | 486 if (!message.header.hasRequestId) { |
| 489 proxyError("Expected a message with a valid request Id."); | 487 proxyError("Expected a message with a valid request Id."); |
| 490 return; | 488 return; |
| 491 } | 489 } |
| 492 Completer c = completerMap[message.header.requestId]; | 490 Completer c = completerMap[message.header.requestId]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 522 } | 520 } |
| 523 c.complete(r); | 521 c.complete(r); |
| 524 break; | 522 break; |
| 525 default: | 523 default: |
| 526 proxyError("Unexpected message type: ${message.header.type}"); | 524 proxyError("Unexpected message type: ${message.header.type}"); |
| 527 close(immediate: true); | 525 close(immediate: true); |
| 528 break; | 526 break; |
| 529 } | 527 } |
| 530 } | 528 } |
| 531 | 529 |
| 530 @override |
| 532 String toString() { | 531 String toString() { |
| 533 var superString = super.toString(); | 532 var superString = super.toString(); |
| 534 return "_HttpServerProxyImpl($superString)"; | 533 return "_HttpServerProxyControl($superString)"; |
| 535 } | 534 } |
| 536 } | 535 } |
| 537 | 536 |
| 538 | 537 |
| 539 class _HttpServerProxyCalls implements HttpServer { | 538 class HttpServerProxy extends bindings.Proxy |
| 540 _HttpServerProxyImpl _proxyImpl; | 539 implements HttpServer { |
| 540 HttpServerProxy.fromEndpoint( |
| 541 core.MojoMessagePipeEndpoint endpoint) |
| 542 : super(new _HttpServerProxyControl.fromEndpoint(endpoint)); |
| 541 | 543 |
| 542 _HttpServerProxyCalls(this._proxyImpl); | 544 HttpServerProxy.fromHandle(core.MojoHandle handle) |
| 543 dynamic setHandler(String pattern,Object handler,[Function responseFactory =
null]) { | 545 : super(new _HttpServerProxyControl.fromHandle(handle)); |
| 544 var params = new _HttpServerSetHandlerParams(); | |
| 545 params.pattern = pattern; | |
| 546 params.handler = handler; | |
| 547 return _proxyImpl.sendMessageWithRequestId( | |
| 548 params, | |
| 549 _httpServerMethodSetHandlerName, | |
| 550 -1, | |
| 551 bindings.MessageHeader.kMessageExpectsResponse); | |
| 552 } | |
| 553 dynamic getPort([Function responseFactory = null]) { | |
| 554 var params = new _HttpServerGetPortParams(); | |
| 555 return _proxyImpl.sendMessageWithRequestId( | |
| 556 params, | |
| 557 _httpServerMethodGetPortName, | |
| 558 -1, | |
| 559 bindings.MessageHeader.kMessageExpectsResponse); | |
| 560 } | |
| 561 } | |
| 562 | 546 |
| 547 HttpServerProxy.unbound() |
| 548 : super(new _HttpServerProxyControl.unbound()); |
| 563 | 549 |
| 564 class HttpServerProxy implements bindings.ProxyBase { | 550 static HttpServerProxy newFromEndpoint( |
| 565 final bindings.Proxy impl; | 551 core.MojoMessagePipeEndpoint endpoint) { |
| 566 HttpServer ptr; | 552 assert(endpoint.setDescription("For HttpServerProxy")); |
| 567 | 553 return new HttpServerProxy.fromEndpoint(endpoint); |
| 568 HttpServerProxy(_HttpServerProxyImpl proxyImpl) : | |
| 569 impl = proxyImpl, | |
| 570 ptr = new _HttpServerProxyCalls(proxyImpl); | |
| 571 | |
| 572 HttpServerProxy.fromEndpoint( | |
| 573 core.MojoMessagePipeEndpoint endpoint) : | |
| 574 impl = new _HttpServerProxyImpl.fromEndpoint(endpoint) { | |
| 575 ptr = new _HttpServerProxyCalls(impl); | |
| 576 } | |
| 577 | |
| 578 HttpServerProxy.fromHandle(core.MojoHandle handle) : | |
| 579 impl = new _HttpServerProxyImpl.fromHandle(handle) { | |
| 580 ptr = new _HttpServerProxyCalls(impl); | |
| 581 } | |
| 582 | |
| 583 HttpServerProxy.unbound() : | |
| 584 impl = new _HttpServerProxyImpl.unbound() { | |
| 585 ptr = new _HttpServerProxyCalls(impl); | |
| 586 } | 554 } |
| 587 | 555 |
| 588 factory HttpServerProxy.connectToService( | 556 factory HttpServerProxy.connectToService( |
| 589 bindings.ServiceConnector s, String url, [String serviceName]) { | 557 bindings.ServiceConnector s, String url, [String serviceName]) { |
| 590 HttpServerProxy p = new HttpServerProxy.unbound(); | 558 HttpServerProxy p = new HttpServerProxy.unbound(); |
| 591 s.connectToService(url, p, serviceName); | 559 s.connectToService(url, p, serviceName); |
| 592 return p; | 560 return p; |
| 593 } | 561 } |
| 594 | 562 |
| 595 static HttpServerProxy newFromEndpoint( | 563 |
| 596 core.MojoMessagePipeEndpoint endpoint) { | 564 dynamic setHandler(String pattern,Object handler,[Function responseFactory = n
ull]) { |
| 597 assert(endpoint.setDescription("For HttpServerProxy")); | 565 var params = new _HttpServerSetHandlerParams(); |
| 598 return new HttpServerProxy.fromEndpoint(endpoint); | 566 params.pattern = pattern; |
| 567 params.handler = handler; |
| 568 return ctrl.sendMessageWithRequestId( |
| 569 params, |
| 570 _httpServerMethodSetHandlerName, |
| 571 -1, |
| 572 bindings.MessageHeader.kMessageExpectsResponse); |
| 599 } | 573 } |
| 600 | 574 dynamic getPort([Function responseFactory = null]) { |
| 601 String get serviceName => HttpServer.serviceName; | 575 var params = new _HttpServerGetPortParams(); |
| 602 | 576 return ctrl.sendMessageWithRequestId( |
| 603 Future close({bool immediate: false}) => impl.close(immediate: immediate); | 577 params, |
| 604 | 578 _httpServerMethodGetPortName, |
| 605 Future responseOrError(Future f) => impl.responseOrError(f); | 579 -1, |
| 606 | 580 bindings.MessageHeader.kMessageExpectsResponse); |
| 607 Future get errorFuture => impl.errorFuture; | |
| 608 | |
| 609 int get version => impl.version; | |
| 610 | |
| 611 Future<int> queryVersion() => impl.queryVersion(); | |
| 612 | |
| 613 void requireVersion(int requiredVersion) { | |
| 614 impl.requireVersion(requiredVersion); | |
| 615 } | |
| 616 | |
| 617 String toString() { | |
| 618 return "HttpServerProxy($impl)"; | |
| 619 } | 581 } |
| 620 } | 582 } |
| 621 | 583 |
| 622 | 584 |
| 623 class HttpServerStub extends bindings.Stub { | 585 class HttpServerStub extends bindings.Stub { |
| 624 HttpServer _impl; | 586 HttpServer _impl; |
| 625 | 587 |
| 626 HttpServerStub.fromEndpoint( | 588 HttpServerStub.fromEndpoint( |
| 627 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl]) | 589 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl]) |
| 628 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 590 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 dynamic getAllTypeDefinitions([Function responseFactory]) => | 723 dynamic getAllTypeDefinitions([Function responseFactory]) => |
| 762 responseFactory(null); | 724 responseFactory(null); |
| 763 } | 725 } |
| 764 | 726 |
| 765 abstract class HttpHandler { | 727 abstract class HttpHandler { |
| 766 static const String serviceName = null; | 728 static const String serviceName = null; |
| 767 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons
eFactory = null]); | 729 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons
eFactory = null]); |
| 768 } | 730 } |
| 769 | 731 |
| 770 | 732 |
| 771 class _HttpHandlerProxyImpl extends bindings.Proxy { | 733 class _HttpHandlerProxyControl extends bindings.ProxyMessageHandler |
| 772 _HttpHandlerProxyImpl.fromEndpoint( | 734 implements bindings.ProxyControl { |
| 735 _HttpHandlerProxyControl.fromEndpoint( |
| 773 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 736 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
| 774 | 737 |
| 775 _HttpHandlerProxyImpl.fromHandle(core.MojoHandle handle) : | 738 _HttpHandlerProxyControl.fromHandle( |
| 776 super.fromHandle(handle); | 739 core.MojoHandle handle) : super.fromHandle(handle); |
| 777 | 740 |
| 778 _HttpHandlerProxyImpl.unbound() : super.unbound(); | 741 _HttpHandlerProxyControl.unbound() : super.unbound(); |
| 779 | |
| 780 static _HttpHandlerProxyImpl newFromEndpoint( | |
| 781 core.MojoMessagePipeEndpoint endpoint) { | |
| 782 assert(endpoint.setDescription("For _HttpHandlerProxyImpl")); | |
| 783 return new _HttpHandlerProxyImpl.fromEndpoint(endpoint); | |
| 784 } | |
| 785 | 742 |
| 786 service_describer.ServiceDescription get serviceDescription => | 743 service_describer.ServiceDescription get serviceDescription => |
| 787 new _HttpHandlerServiceDescription(); | 744 new _HttpHandlerServiceDescription(); |
| 788 | 745 |
| 746 String get serviceName => HttpHandler.serviceName; |
| 747 |
| 748 @override |
| 789 void handleResponse(bindings.ServiceMessage message) { | 749 void handleResponse(bindings.ServiceMessage message) { |
| 790 switch (message.header.type) { | 750 switch (message.header.type) { |
| 791 case _httpHandlerMethodHandleRequestName: | 751 case _httpHandlerMethodHandleRequestName: |
| 792 var r = HttpHandlerHandleRequestResponseParams.deserialize( | 752 var r = HttpHandlerHandleRequestResponseParams.deserialize( |
| 793 message.payload); | 753 message.payload); |
| 794 if (!message.header.hasRequestId) { | 754 if (!message.header.hasRequestId) { |
| 795 proxyError("Expected a message with a valid request Id."); | 755 proxyError("Expected a message with a valid request Id."); |
| 796 return; | 756 return; |
| 797 } | 757 } |
| 798 Completer c = completerMap[message.header.requestId]; | 758 Completer c = completerMap[message.header.requestId]; |
| 799 if (c == null) { | 759 if (c == null) { |
| 800 proxyError( | 760 proxyError( |
| 801 "Message had unknown request Id: ${message.header.requestId}"); | 761 "Message had unknown request Id: ${message.header.requestId}"); |
| 802 return; | 762 return; |
| 803 } | 763 } |
| 804 completerMap.remove(message.header.requestId); | 764 completerMap.remove(message.header.requestId); |
| 805 if (c.isCompleted) { | 765 if (c.isCompleted) { |
| 806 proxyError("Response completer already completed"); | 766 proxyError("Response completer already completed"); |
| 807 return; | 767 return; |
| 808 } | 768 } |
| 809 c.complete(r); | 769 c.complete(r); |
| 810 break; | 770 break; |
| 811 default: | 771 default: |
| 812 proxyError("Unexpected message type: ${message.header.type}"); | 772 proxyError("Unexpected message type: ${message.header.type}"); |
| 813 close(immediate: true); | 773 close(immediate: true); |
| 814 break; | 774 break; |
| 815 } | 775 } |
| 816 } | 776 } |
| 817 | 777 |
| 778 @override |
| 818 String toString() { | 779 String toString() { |
| 819 var superString = super.toString(); | 780 var superString = super.toString(); |
| 820 return "_HttpHandlerProxyImpl($superString)"; | 781 return "_HttpHandlerProxyControl($superString)"; |
| 821 } | 782 } |
| 822 } | 783 } |
| 823 | 784 |
| 824 | 785 |
| 825 class _HttpHandlerProxyCalls implements HttpHandler { | 786 class HttpHandlerProxy extends bindings.Proxy |
| 826 _HttpHandlerProxyImpl _proxyImpl; | 787 implements HttpHandler { |
| 788 HttpHandlerProxy.fromEndpoint( |
| 789 core.MojoMessagePipeEndpoint endpoint) |
| 790 : super(new _HttpHandlerProxyControl.fromEndpoint(endpoint)); |
| 827 | 791 |
| 828 _HttpHandlerProxyCalls(this._proxyImpl); | 792 HttpHandlerProxy.fromHandle(core.MojoHandle handle) |
| 829 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respo
nseFactory = null]) { | 793 : super(new _HttpHandlerProxyControl.fromHandle(handle)); |
| 830 var params = new _HttpHandlerHandleRequestParams(); | |
| 831 params.request = request; | |
| 832 return _proxyImpl.sendMessageWithRequestId( | |
| 833 params, | |
| 834 _httpHandlerMethodHandleRequestName, | |
| 835 -1, | |
| 836 bindings.MessageHeader.kMessageExpectsResponse); | |
| 837 } | |
| 838 } | |
| 839 | 794 |
| 795 HttpHandlerProxy.unbound() |
| 796 : super(new _HttpHandlerProxyControl.unbound()); |
| 840 | 797 |
| 841 class HttpHandlerProxy implements bindings.ProxyBase { | 798 static HttpHandlerProxy newFromEndpoint( |
| 842 final bindings.Proxy impl; | 799 core.MojoMessagePipeEndpoint endpoint) { |
| 843 HttpHandler ptr; | 800 assert(endpoint.setDescription("For HttpHandlerProxy")); |
| 844 | 801 return new HttpHandlerProxy.fromEndpoint(endpoint); |
| 845 HttpHandlerProxy(_HttpHandlerProxyImpl proxyImpl) : | |
| 846 impl = proxyImpl, | |
| 847 ptr = new _HttpHandlerProxyCalls(proxyImpl); | |
| 848 | |
| 849 HttpHandlerProxy.fromEndpoint( | |
| 850 core.MojoMessagePipeEndpoint endpoint) : | |
| 851 impl = new _HttpHandlerProxyImpl.fromEndpoint(endpoint) { | |
| 852 ptr = new _HttpHandlerProxyCalls(impl); | |
| 853 } | |
| 854 | |
| 855 HttpHandlerProxy.fromHandle(core.MojoHandle handle) : | |
| 856 impl = new _HttpHandlerProxyImpl.fromHandle(handle) { | |
| 857 ptr = new _HttpHandlerProxyCalls(impl); | |
| 858 } | |
| 859 | |
| 860 HttpHandlerProxy.unbound() : | |
| 861 impl = new _HttpHandlerProxyImpl.unbound() { | |
| 862 ptr = new _HttpHandlerProxyCalls(impl); | |
| 863 } | 802 } |
| 864 | 803 |
| 865 factory HttpHandlerProxy.connectToService( | 804 factory HttpHandlerProxy.connectToService( |
| 866 bindings.ServiceConnector s, String url, [String serviceName]) { | 805 bindings.ServiceConnector s, String url, [String serviceName]) { |
| 867 HttpHandlerProxy p = new HttpHandlerProxy.unbound(); | 806 HttpHandlerProxy p = new HttpHandlerProxy.unbound(); |
| 868 s.connectToService(url, p, serviceName); | 807 s.connectToService(url, p, serviceName); |
| 869 return p; | 808 return p; |
| 870 } | 809 } |
| 871 | 810 |
| 872 static HttpHandlerProxy newFromEndpoint( | |
| 873 core.MojoMessagePipeEndpoint endpoint) { | |
| 874 assert(endpoint.setDescription("For HttpHandlerProxy")); | |
| 875 return new HttpHandlerProxy.fromEndpoint(endpoint); | |
| 876 } | |
| 877 | 811 |
| 878 String get serviceName => HttpHandler.serviceName; | 812 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons
eFactory = null]) { |
| 879 | 813 var params = new _HttpHandlerHandleRequestParams(); |
| 880 Future close({bool immediate: false}) => impl.close(immediate: immediate); | 814 params.request = request; |
| 881 | 815 return ctrl.sendMessageWithRequestId( |
| 882 Future responseOrError(Future f) => impl.responseOrError(f); | 816 params, |
| 883 | 817 _httpHandlerMethodHandleRequestName, |
| 884 Future get errorFuture => impl.errorFuture; | 818 -1, |
| 885 | 819 bindings.MessageHeader.kMessageExpectsResponse); |
| 886 int get version => impl.version; | |
| 887 | |
| 888 Future<int> queryVersion() => impl.queryVersion(); | |
| 889 | |
| 890 void requireVersion(int requiredVersion) { | |
| 891 impl.requireVersion(requiredVersion); | |
| 892 } | |
| 893 | |
| 894 String toString() { | |
| 895 return "HttpHandlerProxy($impl)"; | |
| 896 } | 820 } |
| 897 } | 821 } |
| 898 | 822 |
| 899 | 823 |
| 900 class HttpHandlerStub extends bindings.Stub { | 824 class HttpHandlerStub extends bindings.Stub { |
| 901 HttpHandler _impl; | 825 HttpHandler _impl; |
| 902 | 826 |
| 903 HttpHandlerStub.fromEndpoint( | 827 HttpHandlerStub.fromEndpoint( |
| 904 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl]) | 828 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl]) |
| 905 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 829 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 static service_describer.ServiceDescription get serviceDescription { | 920 static service_describer.ServiceDescription get serviceDescription { |
| 997 if (_cachedServiceDescription == null) { | 921 if (_cachedServiceDescription == null) { |
| 998 _cachedServiceDescription = new _HttpHandlerServiceDescription(); | 922 _cachedServiceDescription = new _HttpHandlerServiceDescription(); |
| 999 } | 923 } |
| 1000 return _cachedServiceDescription; | 924 return _cachedServiceDescription; |
| 1001 } | 925 } |
| 1002 } | 926 } |
| 1003 | 927 |
| 1004 | 928 |
| 1005 | 929 |
| OLD | NEW |