Jeff Brown | 7c8fe65 | 2016-01-26 15:51:52 -0800 | [diff] [blame] | 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 | #include "mojo/ui/content_viewer_app.h" |
| 6 | |
| 7 | #include "base/command_line.h" |
| 8 | #include "base/logging.h" |
| 9 | |
| 10 | namespace mojo { |
| 11 | namespace ui { |
| 12 | |
| 13 | class ContentViewerApp::DelegatingContentHandler : public mojo::ContentHandler { |
| 14 | public: |
| 15 | DelegatingContentHandler(ContentViewerApp* app, |
| 16 | const std::string& content_handler_url) |
| 17 | : app_(app), content_handler_url_(content_handler_url) {} |
| 18 | |
| 19 | ~DelegatingContentHandler() override {} |
| 20 | |
| 21 | private: |
| 22 | // |ContentHandler|: |
| 23 | void StartApplication( |
| 24 | mojo::InterfaceRequest<mojo::Application> application_request, |
| 25 | mojo::URLResponsePtr response) override { |
| 26 | app_->StartViewer(content_handler_url_, application_request.Pass(), |
| 27 | response.Pass()); |
| 28 | } |
| 29 | |
| 30 | ContentViewerApp* app_; |
| 31 | std::string content_handler_url_; |
| 32 | |
| 33 | MOJO_DISALLOW_COPY_AND_ASSIGN(DelegatingContentHandler); |
| 34 | }; |
| 35 | |
| 36 | ContentViewerApp::ContentViewerApp() {} |
| 37 | |
| 38 | ContentViewerApp::~ContentViewerApp() {} |
| 39 | |
| 40 | void ContentViewerApp::Initialize(mojo::ApplicationImpl* app_impl) { |
| 41 | app_impl_ = app_impl; |
| 42 | |
| 43 | auto command_line = base::CommandLine::ForCurrentProcess(); |
| 44 | command_line->InitFromArgv(app_impl_->args()); |
| 45 | logging::LoggingSettings settings; |
| 46 | settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 47 | logging::InitLogging(settings); |
| 48 | } |
| 49 | |
| 50 | bool ContentViewerApp::ConfigureIncomingConnection( |
Viet-Trung Luu | 22e78b3 | 2016-05-13 15:27:15 -0700 | [diff] [blame] | 51 | ServiceProviderImpl* service_provider_impl) { |
| 52 | service_provider_impl->AddService<ContentHandler>([this]( |
Viet-Trung Luu | 66402b5 | 2016-05-13 11:19:54 -0700 | [diff] [blame] | 53 | const ConnectionContext& connection_context, |
| 54 | InterfaceRequest<ContentHandler> content_handler_request) { |
| 55 | bindings_.AddBinding( |
| 56 | new DelegatingContentHandler(this, connection_context.connection_url), |
| 57 | content_handler_request.Pass()); |
| 58 | }); |
Jeff Brown | 7c8fe65 | 2016-01-26 15:51:52 -0800 | [diff] [blame] | 59 | return true; |
| 60 | } |
| 61 | |
Jeff Brown | 7c8fe65 | 2016-01-26 15:51:52 -0800 | [diff] [blame] | 62 | void ContentViewerApp::StartViewer( |
| 63 | const std::string& content_handler_url, |
| 64 | mojo::InterfaceRequest<mojo::Application> application_request, |
| 65 | mojo::URLResponsePtr response) { |
| 66 | ViewProviderApp* app = LoadContent(content_handler_url, response.Pass()); |
Viet-Trung Luu | 21a4f27 | 2016-05-19 09:53:20 -0700 | [diff] [blame] | 67 | if (app) { |
| 68 | // TODO(vtl): This is leaky, since |ApplicationImpl| doesn't own itself. |
| 69 | // (Also, who owns |*app|?) |
Jeff Brown | 7c8fe65 | 2016-01-26 15:51:52 -0800 | [diff] [blame] | 70 | new mojo::ApplicationImpl(app, application_request.Pass()); |
Viet-Trung Luu | 21a4f27 | 2016-05-19 09:53:20 -0700 | [diff] [blame] | 71 | } |
Jeff Brown | 7c8fe65 | 2016-01-26 15:51:52 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | } // namespace ui |
| 75 | } // namespace mojo |