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