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