| 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(service_manager::ServiceContext* context) { | 161 void Webtest::OnStart() { |
| 162 context_ = context; | 162 tracing_.Initialize(context()->connector(), context()->identity().name()); |
| 163 | |
| 164 tracing_.Initialize(context->connector(), context->identity().name()); | |
| 165 aura_init_ = base::MakeUnique<views::AuraInit>( | 163 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 166 context->connector(), context->identity(), "views_mus_resources.pak"); | 164 context()->connector(), context()->identity(), "views_mus_resources.pak"); |
| 167 window_manager_connection_ = views::WindowManagerConnection::Create( | 165 window_manager_connection_ = views::WindowManagerConnection::Create( |
| 168 context->connector(), context->identity()); | 166 context()->connector(), context()->identity()); |
| 169 } | 167 } |
| 170 | 168 |
| 171 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, | 169 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 172 service_manager::InterfaceRegistry* registry) { | 170 service_manager::InterfaceRegistry* registry) { |
| 173 registry->AddInterface<mojom::Launchable>(this); | 171 registry->AddInterface<mojom::Launchable>(this); |
| 174 return true; | 172 return true; |
| 175 } | 173 } |
| 176 | 174 |
| 177 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { | 175 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { |
| 178 bool reuse = how == mojom::LaunchMode::REUSE || | 176 bool reuse = how == mojom::LaunchMode::REUSE || |
| 179 how == mojom::LaunchMode::DEFAULT; | 177 how == mojom::LaunchMode::DEFAULT; |
| 180 if (reuse && !windows_.empty()) { | 178 if (reuse && !windows_.empty()) { |
| 181 windows_.back()->Activate(); | 179 windows_.back()->Activate(); |
| 182 return; | 180 return; |
| 183 } | 181 } |
| 184 | 182 |
| 185 navigation::mojom::ViewFactoryPtr view_factory; | 183 navigation::mojom::ViewFactoryPtr view_factory; |
| 186 context_->connector()->ConnectToInterface("exe:navigation", &view_factory); | 184 context()->connector()->ConnectToInterface("exe:navigation", &view_factory); |
| 187 navigation::mojom::ViewPtr view; | 185 navigation::mojom::ViewPtr view; |
| 188 navigation::mojom::ViewClientPtr view_client; | 186 navigation::mojom::ViewClientPtr view_client; |
| 189 navigation::mojom::ViewClientRequest view_client_request = | 187 navigation::mojom::ViewClientRequest view_client_request = |
| 190 GetProxy(&view_client); | 188 GetProxy(&view_client); |
| 191 view_factory->CreateView(std::move(view_client), GetProxy(&view)); | 189 view_factory->CreateView(std::move(view_client), GetProxy(&view)); |
| 192 UI* ui = new UI(this, std::move(view), std::move(view_client_request)); | 190 UI* ui = new UI(this, std::move(view), std::move(view_client_request)); |
| 193 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 191 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
| 194 ui, nullptr, gfx::Rect(50, 10, 600, 600)); | 192 ui, nullptr, gfx::Rect(50, 10, 600, 600)); |
| 195 ui->NavigateTo(GURL("http://www.theverge.com/")); | 193 ui->NavigateTo(GURL("http://www.theverge.com/")); |
| 196 window->Show(); | 194 window->Show(); |
| 197 AddWindow(window); | 195 AddWindow(window); |
| 198 } | 196 } |
| 199 | 197 |
| 200 void Webtest::Create(const service_manager::Identity& remote_identity, | 198 void Webtest::Create(const service_manager::Identity& remote_identity, |
| 201 mojom::LaunchableRequest request) { | 199 mojom::LaunchableRequest request) { |
| 202 bindings_.AddBinding(this, std::move(request)); | 200 bindings_.AddBinding(this, std::move(request)); |
| 203 } | 201 } |
| 204 | 202 |
| 205 } // namespace webtest | 203 } // namespace webtest |
| 206 } // namespace mash | 204 } // namespace mash |
| OLD | NEW |