OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "base/message_loop/message_loop.h" | |
6 #include "mojo/examples/html_viewer/blink_platform_impl.h" | |
7 #include "mojo/examples/html_viewer/html_document_view.h" | |
8 #include "mojo/public/cpp/application/application_connection.h" | |
9 #include "mojo/public/cpp/application/application_delegate.h" | |
10 #include "mojo/public/cpp/application/application_impl.h" | |
11 #include "mojo/services/public/cpp/view_manager/node.h" | |
12 #include "mojo/services/public/cpp/view_manager/types.h" | |
13 #include "mojo/services/public/cpp/view_manager/view.h" | |
14 #include "mojo/services/public/cpp/view_manager/view_manager.h" | |
15 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | |
16 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | |
17 #include "third_party/WebKit/public/web/WebKit.h" | |
18 | |
19 namespace mojo { | |
20 namespace examples { | |
21 | |
22 class HTMLViewer; | |
23 | |
24 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { | |
25 public: | |
26 explicit NavigatorImpl(ApplicationConnection* connection, | |
27 HTMLViewer* viewer) : viewer_(viewer) {} | |
28 virtual ~NavigatorImpl() {} | |
29 | |
30 private: | |
31 // Overridden from navigation::Navigator: | |
32 virtual void Navigate( | |
33 uint32_t node_id, | |
34 navigation::NavigationDetailsPtr navigation_details, | |
35 navigation::ResponseDetailsPtr response_details) OVERRIDE; | |
36 | |
37 HTMLViewer* viewer_; | |
38 | |
39 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | |
40 }; | |
41 | |
42 class HTMLViewer : public ApplicationDelegate, | |
43 public view_manager::ViewManagerDelegate { | |
44 public: | |
45 HTMLViewer() : application_impl_(NULL), document_view_(NULL) { | |
46 } | |
47 virtual ~HTMLViewer() { | |
48 blink::shutdown(); | |
49 } | |
50 | |
51 void Load(URLResponsePtr response) { | |
52 // Need to wait for OnRootAdded. | |
53 response_ = response.Pass(); | |
54 MaybeLoad(); | |
55 } | |
56 | |
57 private: | |
58 // Overridden from ApplicationDelegate: | |
59 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | |
60 application_impl_ = app; | |
61 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); | |
62 blink::initialize(blink_platform_impl_.get()); | |
63 } | |
64 | |
65 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | |
66 OVERRIDE { | |
67 connection->AddService<NavigatorImpl>(this); | |
68 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); | |
69 return true; | |
70 } | |
71 | |
72 // Overridden from view_manager::ViewManagerDelegate: | |
73 virtual void OnRootAdded(view_manager::ViewManager* view_manager, | |
74 view_manager::Node* root) OVERRIDE { | |
75 document_view_ = new HTMLDocumentView( | |
76 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")-> | |
77 GetServiceProvider(), view_manager); | |
78 document_view_->AttachToNode(root); | |
79 MaybeLoad(); | |
80 } | |
81 virtual void OnViewManagerDisconnected( | |
82 view_manager::ViewManager* view_manager) OVERRIDE { | |
83 base::MessageLoop::current()->Quit(); | |
84 } | |
85 | |
86 void MaybeLoad() { | |
87 if (document_view_ && response_.get()) | |
88 document_view_->Load(response_.Pass()); | |
89 } | |
90 | |
91 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; | |
92 ApplicationImpl* application_impl_; | |
93 | |
94 // TODO(darin): Figure out proper ownership of this instance. | |
95 HTMLDocumentView* document_view_; | |
96 URLResponsePtr response_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | |
99 }; | |
100 | |
101 void NavigatorImpl::Navigate( | |
102 uint32_t node_id, | |
103 navigation::NavigationDetailsPtr navigation_details, | |
104 navigation::ResponseDetailsPtr response_details) { | |
105 printf("In HTMLViewer, rendering url: %s\n", | |
106 response_details->response->url.data()); | |
107 viewer_->Load(response_details->response.Pass()); | |
108 } | |
109 | |
110 } | |
111 | |
112 // static | |
113 ApplicationDelegate* ApplicationDelegate::Create() { | |
114 return new examples::HTMLViewer; | |
115 } | |
116 | |
117 } | |
OLD | NEW |