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 #include <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "mojo/public/c/system/main.h" | 7 #include "mojo/public/c/system/main.h" |
8 #include "mojo/public/cpp/application/application_delegate.h" | 8 #include "mojo/public/cpp/application/application_delegate.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/application/application_runner.h" | 10 #include "mojo/public/cpp/application/application_runner.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 virtual void Initialize(ShellPtr shell, | 24 virtual void Initialize(ShellPtr shell, |
25 Array<String> args, | 25 Array<String> args, |
26 const mojo::String& url) override { | 26 const mojo::String& url) override { |
27 shell_ = shell.Pass(); | 27 shell_ = shell.Pass(); |
28 } | 28 } |
29 virtual void RequestQuit() override {} | 29 virtual void RequestQuit() override {} |
30 | 30 |
31 virtual void AcceptConnection(const String& requestor_url, | 31 virtual void AcceptConnection(const String& requestor_url, |
32 InterfaceRequest<ServiceProvider> services, | 32 InterfaceRequest<ServiceProvider> services, |
33 ServiceProviderPtr exported_services) override { | 33 ServiceProviderPtr exported_services, |
34 printf("ContentHandler::OnConnect - requestor_url:%s - body follows\n\n", | 34 const String& url) override { |
35 requestor_url.To<std::string>().c_str()); | 35 printf( |
| 36 "ContentHandler::OnConnect - url:%s - requestor_url:%s - body " |
| 37 "follows\n\n", |
| 38 url.To<std::string>().c_str(), requestor_url.To<std::string>().c_str()); |
36 PrintResponse(body_.Pass()); | 39 PrintResponse(body_.Pass()); |
37 delete this; | 40 delete this; |
38 } | 41 } |
39 | 42 |
40 private: | 43 private: |
41 void PrintResponse(ScopedDataPipeConsumerHandle body) const { | 44 void PrintResponse(ScopedDataPipeConsumerHandle body) const { |
42 for (;;) { | 45 for (;;) { |
43 char buf[512]; | 46 char buf[512]; |
44 uint32_t num_bytes = sizeof(buf); | 47 uint32_t num_bytes = sizeof(buf); |
45 MojoResult result = ReadDataRaw(body.get(), buf, &num_bytes, | 48 MojoResult result = ReadDataRaw(body.get(), buf, &num_bytes, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 }; | 90 }; |
88 | 91 |
89 class ContentHandlerApp : public ApplicationDelegate, | 92 class ContentHandlerApp : public ApplicationDelegate, |
90 public InterfaceFactory<ContentHandler> { | 93 public InterfaceFactory<ContentHandler> { |
91 public: | 94 public: |
92 ContentHandlerApp() {} | 95 ContentHandlerApp() {} |
93 ~ContentHandlerApp() override {} | 96 ~ContentHandlerApp() override {} |
94 | 97 |
95 void Initialize(ApplicationImpl* app) override {} | 98 void Initialize(ApplicationImpl* app) override {} |
96 | 99 |
97 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 100 bool ConfigureIncomingConnection(ApplicationConnection* connection, const std:
:string& url) override { |
98 connection->AddService(this); | 101 connection->AddService(this); |
99 return true; | 102 return true; |
100 } | 103 } |
101 | 104 |
102 void Create(ApplicationConnection* app, | 105 void Create(ApplicationConnection* app, |
103 InterfaceRequest<ContentHandler> request) override { | 106 InterfaceRequest<ContentHandler> request) override { |
104 new ContentHandlerImpl(request.Pass()); | 107 new ContentHandlerImpl(request.Pass()); |
105 } | 108 } |
106 | 109 |
107 private: | 110 private: |
108 | 111 |
109 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentHandlerApp); | 112 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentHandlerApp); |
110 }; | 113 }; |
111 | 114 |
112 } // namespace examples | 115 } // namespace examples |
113 } // namespace mojo | 116 } // namespace mojo |
114 | 117 |
115 MojoResult MojoMain(MojoHandle shell_handle) { | 118 MojoResult MojoMain(MojoHandle shell_handle) { |
116 mojo::ApplicationRunner runner(new mojo::examples::ContentHandlerApp); | 119 mojo::ApplicationRunner runner(new mojo::examples::ContentHandlerApp); |
117 return runner.Run(shell_handle); | 120 return runner.Run(shell_handle); |
118 } | 121 } |
OLD | NEW |