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 "mojo/application/application_runner_chromium.h" | 5 #include "sky/tools/debugger/debugger.h" |
6 #include "mojo/public/c/system/main.h" | |
7 #include "mojo/public/cpp/application/application_delegate.h" | |
8 #include "mojo/public/cpp/application/application_impl.h" | |
9 #include "mojo/public/cpp/application/connect.h" | |
10 #include "mojo/public/cpp/application/service_provider_impl.h" | |
11 #include "mojo/services/public/cpp/view_manager/view_manager.h" | |
12 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | |
13 #include "mojo/services/public/cpp/view_manager/view_observer.h" | |
14 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | |
15 #include "mojo/services/window_manager/window_manager_app.h" | |
16 #include "mojo/services/window_manager/window_manager_delegate.h" | |
17 #include "sky/tools/debugger/focus_rules.h" | |
18 #include "sky/tools/debugger/debugger.mojom.h" | |
19 #include "sky/viewer/services/inspector.mojom.h" | |
20 | 6 |
21 namespace sky { | 7 namespace sky { |
| 8 namespace debugger { |
22 | 9 |
23 class SkyDebugger : public mojo::ApplicationDelegate, | 10 SkyDebugger::SkyDebugger() |
24 public mojo::ViewManagerDelegate, | 11 : window_manager_app_(new mojo::WindowManagerApp(this, nullptr)), |
25 public mojo::ViewObserver, | 12 view_manager_(nullptr), |
26 public mojo::InterfaceFactory<Debugger>, | 13 root_(nullptr), |
27 public mojo::InterfaceImpl<Debugger> { | 14 content_(nullptr), |
28 public: | 15 navigator_host_factory_(this), |
29 SkyDebugger() | 16 weak_factory_(this) { |
30 : window_manager_app_(new mojo::WindowManagerApp(this, nullptr)), | 17 } |
31 view_manager_(nullptr), | |
32 root_(nullptr), | |
33 content_(nullptr) {} | |
34 virtual ~SkyDebugger() {} | |
35 | 18 |
36 private: | 19 SkyDebugger::~SkyDebugger() { |
37 // Overridden from mojo::ApplicationDelegate: | 20 } |
38 virtual void Initialize(mojo::ApplicationImpl* app) override { | 21 |
39 window_manager_app_->Initialize(app); | 22 base::WeakPtr<SkyDebugger> SkyDebugger::GetWeakPtr() { |
40 app->ConnectToApplication("mojo:sky_debugger_prompt"); | 23 return weak_factory_.GetWeakPtr(); |
| 24 } |
| 25 |
| 26 void SkyDebugger::Initialize(mojo::ApplicationImpl* app) { |
| 27 window_manager_app_->Initialize(app); |
| 28 app->ConnectToApplication("mojo:sky_debugger_prompt"); |
| 29 } |
| 30 |
| 31 bool SkyDebugger::ConfigureIncomingConnection( |
| 32 mojo::ApplicationConnection* connection) { |
| 33 window_manager_app_->ConfigureIncomingConnection(connection); |
| 34 connection->AddService(this); |
| 35 return true; |
| 36 } |
| 37 |
| 38 bool SkyDebugger::ConfigureOutgoingConnection( |
| 39 mojo::ApplicationConnection* connection) { |
| 40 window_manager_app_->ConfigureOutgoingConnection(connection); |
| 41 connection->AddService(this); |
| 42 return true; |
| 43 } |
| 44 |
| 45 void SkyDebugger::OnEmbed( |
| 46 mojo::ViewManager* view_manager, |
| 47 mojo::View* root, |
| 48 mojo::ServiceProviderImpl* exported_services, |
| 49 scoped_ptr<mojo::ServiceProvider> imported_services) { |
| 50 view_manager_ = view_manager; |
| 51 |
| 52 root_ = root; |
| 53 root_->AddObserver(this); |
| 54 |
| 55 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); |
| 56 |
| 57 content_ = mojo::View::Create(view_manager_); |
| 58 content_->SetBounds(root_->bounds()); |
| 59 root_->AddChild(content_); |
| 60 |
| 61 window_manager_app_->InitFocus( |
| 62 new FocusRules(window_manager_app_.get(), content_)); |
| 63 |
| 64 if (!pending_url_.empty()) |
| 65 NavigateToURL(pending_url_); |
| 66 } |
| 67 |
| 68 void SkyDebugger::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { |
| 69 CHECK(false); // FIXME: This is dead code, why? |
| 70 view_manager_ = nullptr; |
| 71 root_ = nullptr; |
| 72 } |
| 73 |
| 74 void SkyDebugger::OnViewDestroyed(mojo::View* view) { |
| 75 CHECK(false); // FIXME: This is dead code, why? |
| 76 view->RemoveObserver(this); |
| 77 } |
| 78 |
| 79 void SkyDebugger::OnViewBoundsChanged(mojo::View* view, |
| 80 const mojo::Rect& old_bounds, |
| 81 const mojo::Rect& new_bounds) { |
| 82 content_->SetBounds(new_bounds); |
| 83 } |
| 84 |
| 85 void SkyDebugger::Create(mojo::ApplicationConnection* connection, |
| 86 mojo::InterfaceRequest<Debugger> request) { |
| 87 mojo::WeakBindToRequest(this, &request); |
| 88 } |
| 89 |
| 90 void SkyDebugger::NavigateToURL(const mojo::String& url) { |
| 91 // We can get Navigate commands before we've actually been |
| 92 // embedded into the view and content_ created. |
| 93 // Just save the last one. |
| 94 if (content_) { |
| 95 scoped_ptr<mojo::ServiceProviderImpl> exported_services( |
| 96 new mojo::ServiceProviderImpl()); |
| 97 exported_services->AddService(&navigator_host_factory_); |
| 98 viewer_services_ = content_->Embed(url, exported_services.Pass()); |
| 99 } else { |
| 100 pending_url_ = url; |
41 } | 101 } |
| 102 } |
42 | 103 |
43 virtual bool ConfigureIncomingConnection( | 104 void SkyDebugger::InjectInspector() { |
44 mojo::ApplicationConnection* connection) override { | 105 InspectorServicePtr inspector_service; |
45 window_manager_app_->ConfigureIncomingConnection(connection); | 106 mojo::ConnectToService(viewer_services_.get(), &inspector_service); |
46 connection->AddService(this); | 107 inspector_service->Inject(); |
47 return true; | 108 } |
48 } | |
49 | 109 |
50 virtual bool ConfigureOutgoingConnection( | 110 } // namespace debugger |
51 mojo::ApplicationConnection* connection) override { | |
52 window_manager_app_->ConfigureOutgoingConnection(connection); | |
53 connection->AddService(this); | |
54 return true; | |
55 } | |
56 | |
57 // Overridden from mojo::ViewManagerDelegate: | |
58 virtual void OnEmbed( | |
59 mojo::ViewManager* view_manager, | |
60 mojo::View* root, | |
61 mojo::ServiceProviderImpl* exported_services, | |
62 scoped_ptr<mojo::ServiceProvider> imported_services) override { | |
63 view_manager_ = view_manager; | |
64 | |
65 root_ = root; | |
66 root_->AddObserver(this); | |
67 | |
68 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); | |
69 | |
70 content_ = mojo::View::Create(view_manager_); | |
71 content_->SetBounds(root_->bounds()); | |
72 root_->AddChild(content_); | |
73 | |
74 window_manager_app_->InitFocus( | |
75 new FocusRules(window_manager_app_.get(), content_)); | |
76 | |
77 if (!pending_url_.empty()) | |
78 NavigateToURL(pending_url_); | |
79 } | |
80 | |
81 virtual void OnViewManagerDisconnected( | |
82 mojo::ViewManager* view_manager) override { | |
83 CHECK(false); // FIXME: This is dead code, why? | |
84 view_manager_ = nullptr; | |
85 root_ = nullptr; | |
86 } | |
87 | |
88 virtual void OnViewDestroyed(mojo::View* view) override { | |
89 CHECK(false); // FIXME: This is dead code, why? | |
90 view->RemoveObserver(this); | |
91 } | |
92 | |
93 virtual void OnViewBoundsChanged(mojo::View* view, | |
94 const mojo::Rect& old_bounds, | |
95 const mojo::Rect& new_bounds) override { | |
96 content_->SetBounds(new_bounds); | |
97 } | |
98 | |
99 // Overridden from InterfaceFactory<Debugger> | |
100 virtual void Create(mojo::ApplicationConnection* connection, | |
101 mojo::InterfaceRequest<Debugger> request) override { | |
102 mojo::WeakBindToRequest(this, &request); | |
103 } | |
104 | |
105 // Overridden from Debugger | |
106 virtual void NavigateToURL(const mojo::String& url) override { | |
107 // We can get Navigate commands before we've actually been | |
108 // embedded into the view and content_ created. | |
109 // Just save the last one. | |
110 if (content_) { | |
111 scoped_ptr<mojo::ServiceProviderImpl> exported_services( | |
112 new mojo::ServiceProviderImpl()); | |
113 viewer_services_ = content_->Embed(url, exported_services.Pass()); | |
114 } else { | |
115 pending_url_ = url; | |
116 } | |
117 } | |
118 | |
119 virtual void InjectInspector() override { | |
120 InspectorServicePtr inspector_service; | |
121 mojo::ConnectToService(viewer_services_.get(), &inspector_service); | |
122 inspector_service->Inject(); | |
123 } | |
124 | |
125 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; | |
126 | |
127 mojo::ViewManager* view_manager_; | |
128 mojo::View* root_; | |
129 mojo::View* content_; | |
130 std::string pending_url_; | |
131 | |
132 scoped_ptr<mojo::ServiceProvider> viewer_services_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(SkyDebugger); | |
135 }; | |
136 | |
137 } // namespace sky | 111 } // namespace sky |
138 | |
139 MojoResult MojoMain(MojoHandle shell_handle) { | |
140 mojo::ApplicationRunnerChromium runner(new sky::SkyDebugger); | |
141 return runner.Run(shell_handle); | |
142 } | |
OLD | NEW |