| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ | |
| 6 #define MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "mojo/application/public/cpp/interface_factory.h" | |
| 10 #include "mojo/application/public/interfaces/content_handler.mojom.h" | |
| 11 #include "mojo/application/public/interfaces/shell.mojom.h" | |
| 12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | |
| 13 | |
| 14 namespace mojo { | |
| 15 | |
| 16 class ContentHandlerFactory : public InterfaceFactory<ContentHandler> { | |
| 17 public: | |
| 18 class HandledApplicationHolder { | |
| 19 public: | |
| 20 virtual ~HandledApplicationHolder() {} | |
| 21 }; | |
| 22 | |
| 23 class Delegate { | |
| 24 public: | |
| 25 virtual ~Delegate() {} | |
| 26 // Implement this method to create the Application. This method will be | |
| 27 // called on a new thread. Leaving this method will quit the application. | |
| 28 virtual void RunApplication( | |
| 29 InterfaceRequest<Application> application_request, | |
| 30 URLResponsePtr response) = 0; | |
| 31 }; | |
| 32 | |
| 33 class ManagedDelegate : public Delegate { | |
| 34 public: | |
| 35 ~ManagedDelegate() override {} | |
| 36 // Implement this method to create the Application for the given content. | |
| 37 // This method will be called on a new thread. The application will be run | |
| 38 // on this new thread, and the returned value will be kept alive until the | |
| 39 // application ends. | |
| 40 virtual scoped_ptr<HandledApplicationHolder> CreateApplication( | |
| 41 InterfaceRequest<Application> application_request, | |
| 42 URLResponsePtr response) = 0; | |
| 43 | |
| 44 private: | |
| 45 void RunApplication(InterfaceRequest<Application> application_request, | |
| 46 URLResponsePtr response) override; | |
| 47 }; | |
| 48 | |
| 49 explicit ContentHandlerFactory(Delegate* delegate); | |
| 50 ~ContentHandlerFactory() override; | |
| 51 | |
| 52 private: | |
| 53 // From InterfaceFactory: | |
| 54 void Create(ApplicationConnection* connection, | |
| 55 InterfaceRequest<ContentHandler> request) override; | |
| 56 | |
| 57 Delegate* delegate_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory); | |
| 60 }; | |
| 61 | |
| 62 template <class A> | |
| 63 class HandledApplicationHolderImpl | |
| 64 : public ContentHandlerFactory::HandledApplicationHolder { | |
| 65 public: | |
| 66 explicit HandledApplicationHolderImpl(A* value) : value_(value) {} | |
| 67 | |
| 68 private: | |
| 69 scoped_ptr<A> value_; | |
| 70 }; | |
| 71 | |
| 72 template <class A> | |
| 73 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> | |
| 74 make_handled_factory_holder(A* value) { | |
| 75 return make_scoped_ptr(new HandledApplicationHolderImpl<A>(value)); | |
| 76 } | |
| 77 | |
| 78 } // namespace mojo | |
| 79 | |
| 80 #endif // MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_ | |
| OLD | NEW |