blob: 0ede5d2ecbc7b62a3d8aaf20b2bc76781d98b50f [file] [log] [blame]
Jeff Brown7c8fe652016-01-26 15:51:52 -08001// 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
10namespace mojo {
11namespace ui {
12
13class 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
36ContentViewerApp::ContentViewerApp() {}
37
38ContentViewerApp::~ContentViewerApp() {}
39
40void 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
50bool ContentViewerApp::ConfigureIncomingConnection(
Viet-Trung Luu22e78b32016-05-13 15:27:15 -070051 ServiceProviderImpl* service_provider_impl) {
52 service_provider_impl->AddService<ContentHandler>([this](
Viet-Trung Luu66402b52016-05-13 11:19:54 -070053 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 Brown7c8fe652016-01-26 15:51:52 -080059 return true;
60}
61
Jeff Brown7c8fe652016-01-26 15:51:52 -080062void 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 Luu21a4f272016-05-19 09:53:20 -070067 if (app) {
68 // TODO(vtl): This is leaky, since |ApplicationImpl| doesn't own itself.
69 // (Also, who owns |*app|?)
Jeff Brown7c8fe652016-01-26 15:51:52 -080070 new mojo::ApplicationImpl(app, application_request.Pass());
Viet-Trung Luu21a4f272016-05-19 09:53:20 -070071 }
Jeff Brown7c8fe652016-01-26 15:51:52 -080072}
73
74} // namespace ui
75} // namespace mojo