OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_UI_CONTENT_VIEWER_APP_H_ | 5 #ifndef MOJO_UI_CONTENT_VIEWER_APP_H_ |
6 #define MOJO_UI_CONTENT_VIEWER_APP_H_ | 6 #define MOJO_UI_CONTENT_VIEWER_APP_H_ |
7 | 7 |
8 #include "mojo/common/strong_binding_set.h" | 8 #include "mojo/common/strong_binding_set.h" |
9 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" | 9 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" |
10 #include "mojo/ui/view_provider_app.h" | 10 #include "mojo/ui/view_provider_app.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 // A simple ContentHandler application implementation for rendering | 15 // A simple ContentHandler application implementation for rendering |
16 // content as Views. Subclasses must provide a function to create | 16 // content as Views. Subclasses must provide a function to create |
17 // the view provider application on demand. | 17 // the view provider application on demand. |
18 // | 18 // |
19 // TODO(jeffbrown): Support creating the view provider application in a | 19 // TODO(jeffbrown): Support creating the view provider application in a |
20 // separate thread if desired (often not the case). This is one reason | 20 // separate thread if desired (often not the case). This is one reason |
21 // we are not using the ContentHandlerFactory here. | 21 // we are not using the ContentHandlerFactory here. |
22 class ContentViewerApp : public mojo::ApplicationDelegate, | 22 class ContentViewerApp : public ApplicationDelegate, |
23 public mojo::InterfaceFactory<mojo::ContentHandler> { | 23 public InterfaceFactory<ContentHandler> { |
24 public: | 24 public: |
25 ContentViewerApp(); | 25 ContentViewerApp(); |
26 ~ContentViewerApp() override; | 26 ~ContentViewerApp() override; |
27 | 27 |
28 mojo::ApplicationImpl* app_impl() { return app_impl_; } | 28 ApplicationImpl* app_impl() { return app_impl_; } |
29 | 29 |
30 // |ApplicationDelegate|: | 30 // |ApplicationDelegate|: |
31 void Initialize(mojo::ApplicationImpl* app) override; | 31 void Initialize(ApplicationImpl* app) override; |
32 bool ConfigureIncomingConnection( | 32 bool ConfigureIncomingConnection(ApplicationConnection* connection) override; |
33 mojo::ApplicationConnection* connection) override; | |
34 | 33 |
35 // Called to create the view provider application to view the content. | 34 // Called to create the view provider application to view the content. |
36 // | 35 // |
37 // This method may be called multiple times to load different content | 36 // This method may be called multiple times to load different content |
38 // into separate view providers. The view provider implementation should | 37 // into separate view providers. The view provider implementation should |
39 // cache the loaded content in case it is asked to create multiple instances | 38 // cache the loaded content in case it is asked to create multiple instances |
40 // of the view since the response can only be consumed once. | 39 // of the view since the response can only be consumed once. |
41 // | 40 // |
42 // The |content_handler_url| is the connection URL of the content handler | 41 // The |content_handler_url| is the connection URL of the content handler |
43 // request. | 42 // request. |
44 // The |response| carries the data retrieved by the content handler. | 43 // The |response| carries the data retrieved by the content handler. |
45 // | 44 // |
46 // Returns the view provider application delegate to view the content, | 45 // Returns the view provider application delegate to view the content, |
47 // or nullptr if the content could not be loaded. | 46 // or nullptr if the content could not be loaded. |
48 virtual ViewProviderApp* LoadContent(const std::string& content_handler_url, | 47 virtual ViewProviderApp* LoadContent(const std::string& content_handler_url, |
49 mojo::URLResponsePtr response) = 0; | 48 URLResponsePtr response) = 0; |
50 | 49 |
51 private: | 50 private: |
52 class DelegatingContentHandler; | 51 class DelegatingContentHandler; |
53 | 52 |
54 // |InterfaceFactory<ContentHandler>|: | 53 // |InterfaceFactory<ContentHandler>|: |
55 void Create(mojo::ApplicationConnection* connection, | 54 void Create(const ConnectionContext& connection_context, |
56 mojo::InterfaceRequest<mojo::ContentHandler> request) override; | 55 InterfaceRequest<ContentHandler> request) override; |
57 | 56 |
58 void StartViewer( | 57 void StartViewer(const std::string& content_handler_url, |
59 const std::string& content_handler_url, | 58 InterfaceRequest<Application> application_request, |
60 mojo::InterfaceRequest<mojo::Application> application_request, | 59 URLResponsePtr response); |
61 mojo::URLResponsePtr response); | |
62 | 60 |
63 mojo::ApplicationImpl* app_impl_ = nullptr; | 61 ApplicationImpl* app_impl_ = nullptr; |
64 mojo::StrongBindingSet<mojo::ContentHandler> bindings_; | 62 StrongBindingSet<ContentHandler> bindings_; |
65 | 63 |
66 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentViewerApp); | 64 MOJO_DISALLOW_COPY_AND_ASSIGN(ContentViewerApp); |
67 }; | 65 }; |
68 | 66 |
69 } // namespace ui | 67 } // namespace ui |
70 } // namespace mojo | 68 } // namespace mojo |
71 | 69 |
72 #endif // MOJO_UI_CONTENT_VIEWER_APP_H_ | 70 #endif // MOJO_UI_CONTENT_VIEWER_APP_H_ |
OLD | NEW |