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