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" |
11 #include "mojo/public/cpp/application/interface_factory_impl.h" | 11 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
12 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom.
h" | 13 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom.
h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace examples { | 16 namespace examples { |
16 | 17 |
17 class PrintBodyApplication : public InterfaceImpl<Application> { | 18 class PrintBodyApplication : public Application { |
18 public: | 19 public: |
19 PrintBodyApplication(ShellPtr shell, ScopedDataPipeConsumerHandle body) | 20 PrintBodyApplication(InterfaceRequest<Application> request, |
20 : shell_(shell.Pass()), body_(body.Pass()) { | 21 ScopedDataPipeConsumerHandle body) |
21 shell_.set_client(this); | 22 : binding_(this, request.Pass()), body_(body.Pass()) {} |
| 23 |
| 24 virtual void Initialize(ShellPtr shell, Array<String> args) override { |
| 25 shell_ = shell.Pass(); |
22 } | 26 } |
23 | |
24 virtual void Initialize(Array<String> args) override {} | |
25 virtual void RequestQuit() override {} | 27 virtual void RequestQuit() override {} |
26 | 28 |
27 virtual void AcceptConnection(const String& requestor_url, | 29 virtual void AcceptConnection(const String& requestor_url, |
28 InterfaceRequest<ServiceProvider> services, | 30 InterfaceRequest<ServiceProvider> services, |
29 ServiceProviderPtr exported_services) override { | 31 ServiceProviderPtr exported_services) override { |
30 printf("ContentHandler::OnConnect - requestor_url:%s - body follows\n\n", | 32 printf("ContentHandler::OnConnect - requestor_url:%s - body follows\n\n", |
31 requestor_url.To<std::string>().c_str()); | 33 requestor_url.To<std::string>().c_str()); |
32 PrintResponse(body_.Pass()); | 34 PrintResponse(body_.Pass()); |
33 delete this; | 35 delete this; |
34 } | 36 } |
(...skipping 16 matching lines...) Expand all Loading... |
51 break; | 53 break; |
52 } | 54 } |
53 } else { | 55 } else { |
54 break; | 56 break; |
55 } | 57 } |
56 | 58 |
57 printf("\n>>> EOF <<<\n"); | 59 printf("\n>>> EOF <<<\n"); |
58 } | 60 } |
59 } | 61 } |
60 | 62 |
| 63 StrongBinding<Application> binding_; |
61 ShellPtr shell_; | 64 ShellPtr shell_; |
62 ScopedDataPipeConsumerHandle body_; | 65 ScopedDataPipeConsumerHandle body_; |
63 | 66 |
64 MOJO_DISALLOW_COPY_AND_ASSIGN(PrintBodyApplication); | 67 MOJO_DISALLOW_COPY_AND_ASSIGN(PrintBodyApplication); |
65 }; | 68 }; |
66 | 69 |
67 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { | 70 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
68 public: | 71 public: |
69 explicit ContentHandlerImpl() {} | 72 explicit ContentHandlerImpl() {} |
70 virtual ~ContentHandlerImpl() {} | 73 virtual ~ContentHandlerImpl() {} |
71 | 74 |
72 private: | 75 private: |
73 virtual void StartApplication(ShellPtr shell, | 76 virtual void StartApplication(InterfaceRequest<Application> application, |
74 URLResponsePtr response) override { | 77 URLResponsePtr response) override { |
75 // The application will delete itself after being connected to. | 78 // The application will delete itself after being connected to. |
76 new PrintBodyApplication(shell.Pass(), response->body.Pass()); | 79 new PrintBodyApplication(application.Pass(), response->body.Pass()); |
77 } | 80 } |
78 }; | 81 }; |
79 | 82 |
80 class ContentHandlerApp : public ApplicationDelegate { | 83 class ContentHandlerApp : public ApplicationDelegate { |
81 public: | 84 public: |
82 ContentHandlerApp() : content_handler_factory_() {} | 85 ContentHandlerApp() : content_handler_factory_() {} |
83 | 86 |
84 virtual void Initialize(ApplicationImpl* app) override {} | 87 virtual void Initialize(ApplicationImpl* app) override {} |
85 | 88 |
86 virtual bool ConfigureIncomingConnection( | 89 virtual bool ConfigureIncomingConnection( |
87 ApplicationConnection* connection) override { | 90 ApplicationConnection* connection) override { |
88 connection->AddService(&content_handler_factory_); | 91 connection->AddService(&content_handler_factory_); |
89 return true; | 92 return true; |
90 } | 93 } |
91 | 94 |
92 private: | 95 private: |
93 InterfaceFactoryImpl<ContentHandlerImpl> content_handler_factory_; | 96 InterfaceFactoryImpl<ContentHandlerImpl> content_handler_factory_; |
94 | 97 |
95 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentHandlerApp); | 98 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentHandlerApp); |
96 }; | 99 }; |
97 | 100 |
98 } // namespace examples | 101 } // namespace examples |
99 } // namespace mojo | 102 } // namespace mojo |
100 | 103 |
101 MojoResult MojoMain(MojoHandle shell_handle) { | 104 MojoResult MojoMain(MojoHandle shell_handle) { |
102 mojo::ApplicationRunner runner(new mojo::examples::ContentHandlerApp); | 105 mojo::ApplicationRunner runner(new mojo::examples::ContentHandlerApp); |
103 return runner.Run(shell_handle); | 106 return runner.Run(shell_handle); |
104 } | 107 } |
OLD | NEW |