| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "mojo/public/c/system/main.h" | 10 #include "mojo/public/c/system/main.h" |
| 10 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
| 12 #include "mojo/public/cpp/application/application_runner.h" | 13 #include "mojo/public/cpp/application/application_runner.h" |
| 13 #include "mojo/public/cpp/application/interface_factory_impl.h" | 14 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" | 16 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" |
| 16 | 17 |
| 17 namespace mojo { | 18 namespace mojo { |
| 18 namespace examples { | 19 namespace examples { |
| 19 | 20 |
| 20 class PrintBodyApplication : public Application { | 21 class PrintBodyApplication : public Application { |
| 21 public: | 22 public: |
| 22 PrintBodyApplication(InterfaceRequest<Application> request, | 23 PrintBodyApplication(InterfaceRequest<Application> request, |
| 23 ScopedDataPipeConsumerHandle body) | 24 ScopedDataPipeConsumerHandle body) |
| 24 : binding_(this, request.Pass()), body_(body.Pass()) {} | 25 : binding_(this, request.Pass()), body_(body.Pass()) {} |
| 25 | 26 |
| 26 void Initialize(ShellPtr shell, | 27 void Initialize(InterfaceHandle<Shell> shell, |
| 27 Array<String> args, | 28 Array<String> args, |
| 28 const mojo::String& url) override { | 29 const mojo::String& url) override { |
| 29 shell_ = shell.Pass(); | 30 shell_ = ShellPtr::Create(std::move(shell)); |
| 30 } | 31 } |
| 31 void RequestQuit() override {} | 32 void RequestQuit() override {} |
| 32 | 33 |
| 33 void AcceptConnection(const String& requestor_url, | 34 void AcceptConnection(const String& requestor_url, |
| 34 InterfaceRequest<ServiceProvider> services, | 35 InterfaceRequest<ServiceProvider> services, |
| 35 ServiceProviderPtr exported_services, | 36 InterfaceHandle<ServiceProvider> exported_services, |
| 36 const String& url) override { | 37 const String& url) override { |
| 37 printf( | 38 printf( |
| 38 "ContentHandler::OnConnect - url:%s - requestor_url:%s - body " | 39 "ContentHandler::OnConnect - url:%s - requestor_url:%s - body " |
| 39 "follows\n\n", | 40 "follows\n\n", |
| 40 url.To<std::string>().c_str(), requestor_url.To<std::string>().c_str()); | 41 url.To<std::string>().c_str(), requestor_url.To<std::string>().c_str()); |
| 41 PrintResponse(body_.Pass()); | 42 PrintResponse(body_.Pass()); |
| 42 delete this; | 43 delete this; |
| 43 } | 44 } |
| 44 | 45 |
| 45 private: | 46 private: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 connection->AddService(this); | 104 connection->AddService(this); |
| 104 return true; | 105 return true; |
| 105 } | 106 } |
| 106 | 107 |
| 107 void Create(ApplicationConnection* app, | 108 void Create(ApplicationConnection* app, |
| 108 InterfaceRequest<ContentHandler> request) override { | 109 InterfaceRequest<ContentHandler> request) override { |
| 109 new ContentHandlerImpl(request.Pass()); | 110 new ContentHandlerImpl(request.Pass()); |
| 110 } | 111 } |
| 111 | 112 |
| 112 private: | 113 private: |
| 113 | |
| 114 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentHandlerApp); | 114 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentHandlerApp); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 } // namespace examples | 117 } // namespace examples |
| 118 } // namespace mojo | 118 } // namespace mojo |
| 119 | 119 |
| 120 MojoResult MojoMain(MojoHandle application_request) { | 120 MojoResult MojoMain(MojoHandle application_request) { |
| 121 mojo::ApplicationRunner runner( | 121 mojo::ApplicationRunner runner( |
| 122 std::unique_ptr<mojo::examples::ContentHandlerApp>( | 122 std::unique_ptr<mojo::examples::ContentHandlerApp>( |
| 123 new mojo::examples::ContentHandlerApp())); | 123 new mojo::examples::ContentHandlerApp())); |
| 124 return runner.Run(application_request); | 124 return runner.Run(application_request); |
| 125 } | 125 } |
| OLD | NEW |