Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / mojo / services / html_viewer / html_viewer.cc
blobaa8d46bfb299d1bc5330006a5c5aa56880c4da95
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.
5 #include "base/message_loop/message_loop.h"
6 #include "mojo/public/c/system/main.h"
7 #include "mojo/public/cpp/application/application_connection.h"
8 #include "mojo/public/cpp/application/application_delegate.h"
9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/application/application_runner_chromium.h"
11 #include "mojo/public/cpp/application/interface_factory_impl.h"
12 #include "mojo/services/html_viewer/blink_platform_impl.h"
13 #include "mojo/services/html_viewer/html_document_view.h"
14 #include "mojo/services/public/cpp/view_manager/types.h"
15 #include "mojo/services/public/cpp/view_manager/view.h"
16 #include "mojo/services/public/cpp/view_manager/view_manager.h"
17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
19 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
20 #include "third_party/WebKit/public/web/WebKit.h"
22 namespace mojo {
24 class HTMLViewer;
26 class NavigatorImpl : public InterfaceImpl<Navigator> {
27 public:
28 explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {}
29 virtual ~NavigatorImpl() {}
31 private:
32 // Overridden from Navigator:
33 virtual void Navigate(
34 uint32_t view_id,
35 NavigationDetailsPtr navigation_details,
36 ResponseDetailsPtr response_details) OVERRIDE;
38 HTMLViewer* viewer_;
40 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
43 class HTMLViewer : public ApplicationDelegate, public ViewManagerDelegate {
44 public:
45 HTMLViewer()
46 : application_impl_(NULL),
47 document_view_(NULL),
48 navigator_factory_(this),
49 view_manager_client_factory_(this) {}
50 virtual ~HTMLViewer() {
51 blink::shutdown();
54 void Load(ResponseDetailsPtr response_details) {
55 // Need to wait for OnEmbed.
56 response_details_ = response_details.Pass();
57 MaybeLoad();
60 private:
61 // Overridden from ApplicationDelegate:
62 virtual void Initialize(ApplicationImpl* app) OVERRIDE {
63 application_impl_ = app;
64 blink_platform_impl_.reset(new BlinkPlatformImpl(app));
65 blink::initialize(blink_platform_impl_.get());
68 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
69 OVERRIDE {
70 connection->AddService(&navigator_factory_);
71 connection->AddService(&view_manager_client_factory_);
72 return true;
75 // Overridden from ViewManagerDelegate:
76 virtual void OnEmbed(ViewManager* view_manager,
77 View* root,
78 ServiceProviderImpl* exported_services,
79 scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
80 document_view_ = new HTMLDocumentView(
81 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")->
82 GetServiceProvider(),
83 view_manager);
84 document_view_->AttachToView(root);
85 MaybeLoad();
87 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
88 base::MessageLoop::current()->Quit();
91 void MaybeLoad() {
92 if (document_view_ && response_details_ && response_details_->response)
93 document_view_->Load(response_details_->response.Pass());
96 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
97 ApplicationImpl* application_impl_;
99 // TODO(darin): Figure out proper ownership of this instance.
100 HTMLDocumentView* document_view_;
101 ResponseDetailsPtr response_details_;
102 InterfaceFactoryImplWithContext<NavigatorImpl, HTMLViewer> navigator_factory_;
103 ViewManagerClientFactory view_manager_client_factory_;
105 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
108 void NavigatorImpl::Navigate(
109 uint32_t view_id,
110 NavigationDetailsPtr navigation_details,
111 ResponseDetailsPtr response_details) {
112 viewer_->Load(response_details.Pass());
115 } // namespace mojo
117 MojoResult MojoMain(MojoHandle shell_handle) {
118 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer);
119 return runner.Run(shell_handle);