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