| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "mash/public/interfaces/launchable.mojom.h" | 14 #include "mash/public/interfaces/launchable.mojom.h" |
| 15 #include "services/navigation/public/interfaces/view.mojom.h" | 15 #include "services/navigation/public/interfaces/view.mojom.h" |
| 16 #include "services/service_manager/public/c/main.h" | 16 #include "services/service_manager/public/c/main.h" |
| 17 #include "services/service_manager/public/cpp/connector.h" | 17 #include "services/service_manager/public/cpp/connector.h" |
| 18 #include "services/service_manager/public/cpp/interface_registry.h" |
| 18 #include "services/service_manager/public/cpp/service.h" | 19 #include "services/service_manager/public/cpp/service.h" |
| 20 #include "services/service_manager/public/cpp/service_context.h" |
| 19 #include "services/service_manager/public/cpp/service_runner.h" | 21 #include "services/service_manager/public/cpp/service_runner.h" |
| 20 #include "services/tracing/public/cpp/provider.h" | 22 #include "services/tracing/public/cpp/provider.h" |
| 21 #include "services/ui/public/cpp/window.h" | 23 #include "services/ui/public/cpp/window.h" |
| 22 #include "services/ui/public/cpp/window_tree_client.h" | 24 #include "services/ui/public/cpp/window_tree_client.h" |
| 23 #include "ui/aura/mus/mus_util.h" | 25 #include "ui/aura/mus/mus_util.h" |
| 24 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/paint_throbber.h" | 27 #include "ui/gfx/paint_throbber.h" |
| 26 #include "ui/native_theme/native_theme.h" | 28 #include "ui/native_theme/native_theme.h" |
| 27 #include "ui/views/background.h" | 29 #include "ui/views/background.h" |
| 28 #include "ui/views/controls/button/label_button.h" | 30 #include "ui/views/controls/button/label_button.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 151 } |
| 150 | 152 |
| 151 void Webtest::RemoveWindow(views::Widget* window) { | 153 void Webtest::RemoveWindow(views::Widget* window) { |
| 152 auto it = std::find(windows_.begin(), windows_.end(), window); | 154 auto it = std::find(windows_.begin(), windows_.end(), window); |
| 153 DCHECK(it != windows_.end()); | 155 DCHECK(it != windows_.end()); |
| 154 windows_.erase(it); | 156 windows_.erase(it); |
| 155 if (windows_.empty()) | 157 if (windows_.empty()) |
| 156 base::MessageLoop::current()->QuitWhenIdle(); | 158 base::MessageLoop::current()->QuitWhenIdle(); |
| 157 } | 159 } |
| 158 | 160 |
| 159 void Webtest::OnStart(const service_manager::ServiceInfo& info) { | 161 void Webtest::OnStart(service_manager::ServiceContext* context) { |
| 160 tracing_.Initialize(connector(), info.identity.name()); | 162 context_ = context; |
| 161 | 163 |
| 162 aura_init_ = base::MakeUnique<views::AuraInit>(connector(), info.identity, | 164 tracing_.Initialize(context->connector(), context->identity().name()); |
| 163 "views_mus_resources.pak"); | 165 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 164 window_manager_connection_ = | 166 context->connector(), context->identity(), "views_mus_resources.pak"); |
| 165 views::WindowManagerConnection::Create(connector(), info.identity); | 167 window_manager_connection_ = views::WindowManagerConnection::Create( |
| 168 context->connector(), context->identity()); |
| 166 } | 169 } |
| 167 | 170 |
| 168 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, | 171 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 169 service_manager::InterfaceRegistry* registry) { | 172 service_manager::InterfaceRegistry* registry) { |
| 170 registry->AddInterface<mojom::Launchable>(this); | 173 registry->AddInterface<mojom::Launchable>(this); |
| 171 return true; | 174 return true; |
| 172 } | 175 } |
| 173 | 176 |
| 174 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { | 177 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { |
| 175 bool reuse = how == mojom::LaunchMode::REUSE || | 178 bool reuse = how == mojom::LaunchMode::REUSE || |
| 176 how == mojom::LaunchMode::DEFAULT; | 179 how == mojom::LaunchMode::DEFAULT; |
| 177 if (reuse && !windows_.empty()) { | 180 if (reuse && !windows_.empty()) { |
| 178 windows_.back()->Activate(); | 181 windows_.back()->Activate(); |
| 179 return; | 182 return; |
| 180 } | 183 } |
| 181 | 184 |
| 182 navigation::mojom::ViewFactoryPtr view_factory; | 185 navigation::mojom::ViewFactoryPtr view_factory; |
| 183 connector()->ConnectToInterface("exe:navigation", &view_factory); | 186 context_->connector()->ConnectToInterface("exe:navigation", &view_factory); |
| 184 navigation::mojom::ViewPtr view; | 187 navigation::mojom::ViewPtr view; |
| 185 navigation::mojom::ViewClientPtr view_client; | 188 navigation::mojom::ViewClientPtr view_client; |
| 186 navigation::mojom::ViewClientRequest view_client_request = | 189 navigation::mojom::ViewClientRequest view_client_request = |
| 187 GetProxy(&view_client); | 190 GetProxy(&view_client); |
| 188 view_factory->CreateView(std::move(view_client), GetProxy(&view)); | 191 view_factory->CreateView(std::move(view_client), GetProxy(&view)); |
| 189 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)); |
| 190 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 193 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
| 191 ui, nullptr, gfx::Rect(50, 10, 600, 600)); | 194 ui, nullptr, gfx::Rect(50, 10, 600, 600)); |
| 192 ui->NavigateTo(GURL("http://www.theverge.com/")); | 195 ui->NavigateTo(GURL("http://www.theverge.com/")); |
| 193 window->Show(); | 196 window->Show(); |
| 194 AddWindow(window); | 197 AddWindow(window); |
| 195 } | 198 } |
| 196 | 199 |
| 197 void Webtest::Create(const service_manager::Identity& remote_identity, | 200 void Webtest::Create(const service_manager::Identity& remote_identity, |
| 198 mojom::LaunchableRequest request) { | 201 mojom::LaunchableRequest request) { |
| 199 bindings_.AddBinding(this, std::move(request)); | 202 bindings_.AddBinding(this, std::move(request)); |
| 200 } | 203 } |
| 201 | 204 |
| 202 } // namespace webtest | 205 } // namespace webtest |
| 203 } // namespace mash | 206 } // namespace mash |
| OLD | NEW |