OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/webtest/webtest.h" | 5 #include "mash/webtest/webtest.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 151 } |
152 | 152 |
153 void Webtest::RemoveWindow(views::Widget* window) { | 153 void Webtest::RemoveWindow(views::Widget* window) { |
154 auto it = std::find(windows_.begin(), windows_.end(), window); | 154 auto it = std::find(windows_.begin(), windows_.end(), window); |
155 DCHECK(it != windows_.end()); | 155 DCHECK(it != windows_.end()); |
156 windows_.erase(it); | 156 windows_.erase(it); |
157 if (windows_.empty()) | 157 if (windows_.empty()) |
158 base::MessageLoop::current()->QuitWhenIdle(); | 158 base::MessageLoop::current()->QuitWhenIdle(); |
159 } | 159 } |
160 | 160 |
161 void Webtest::OnStart() { | 161 void Webtest::OnStart(service_manager::ServiceContext* context) { |
162 tracing_.Initialize(context()->connector(), context()->identity().name()); | 162 context_ = context; |
| 163 |
| 164 tracing_.Initialize(context->connector(), context->identity().name()); |
163 aura_init_ = base::MakeUnique<views::AuraInit>( | 165 aura_init_ = base::MakeUnique<views::AuraInit>( |
164 context()->connector(), context()->identity(), "views_mus_resources.pak"); | 166 context->connector(), context->identity(), "views_mus_resources.pak"); |
165 window_manager_connection_ = views::WindowManagerConnection::Create( | 167 window_manager_connection_ = views::WindowManagerConnection::Create( |
166 context()->connector(), context()->identity()); | 168 context->connector(), context->identity()); |
167 } | 169 } |
168 | 170 |
169 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, | 171 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, |
170 service_manager::InterfaceRegistry* registry) { | 172 service_manager::InterfaceRegistry* registry) { |
171 registry->AddInterface<mojom::Launchable>(this); | 173 registry->AddInterface<mojom::Launchable>(this); |
172 return true; | 174 return true; |
173 } | 175 } |
174 | 176 |
175 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { | 177 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { |
176 bool reuse = how == mojom::LaunchMode::REUSE || | 178 bool reuse = how == mojom::LaunchMode::REUSE || |
177 how == mojom::LaunchMode::DEFAULT; | 179 how == mojom::LaunchMode::DEFAULT; |
178 if (reuse && !windows_.empty()) { | 180 if (reuse && !windows_.empty()) { |
179 windows_.back()->Activate(); | 181 windows_.back()->Activate(); |
180 return; | 182 return; |
181 } | 183 } |
182 | 184 |
183 navigation::mojom::ViewFactoryPtr view_factory; | 185 navigation::mojom::ViewFactoryPtr view_factory; |
184 context()->connector()->ConnectToInterface("exe:navigation", &view_factory); | 186 context_->connector()->ConnectToInterface("exe:navigation", &view_factory); |
185 navigation::mojom::ViewPtr view; | 187 navigation::mojom::ViewPtr view; |
186 navigation::mojom::ViewClientPtr view_client; | 188 navigation::mojom::ViewClientPtr view_client; |
187 navigation::mojom::ViewClientRequest view_client_request = | 189 navigation::mojom::ViewClientRequest view_client_request = |
188 GetProxy(&view_client); | 190 GetProxy(&view_client); |
189 view_factory->CreateView(std::move(view_client), GetProxy(&view)); | 191 view_factory->CreateView(std::move(view_client), GetProxy(&view)); |
190 UI* ui = new UI(this, std::move(view), std::move(view_client_request)); | 192 UI* ui = new UI(this, std::move(view), std::move(view_client_request)); |
191 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 193 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
192 ui, nullptr, gfx::Rect(50, 10, 600, 600)); | 194 ui, nullptr, gfx::Rect(50, 10, 600, 600)); |
193 ui->NavigateTo(GURL("http://www.theverge.com/")); | 195 ui->NavigateTo(GURL("http://www.theverge.com/")); |
194 window->Show(); | 196 window->Show(); |
195 AddWindow(window); | 197 AddWindow(window); |
196 } | 198 } |
197 | 199 |
198 void Webtest::Create(const service_manager::Identity& remote_identity, | 200 void Webtest::Create(const service_manager::Identity& remote_identity, |
199 mojom::LaunchableRequest request) { | 201 mojom::LaunchableRequest request) { |
200 bindings_.AddBinding(this, std::move(request)); | 202 bindings_.AddBinding(this, std::move(request)); |
201 } | 203 } |
202 | 204 |
203 } // namespace webtest | 205 } // namespace webtest |
204 } // namespace mash | 206 } // namespace mash |
OLD | NEW |