| 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/interface_registry.h" |
| 19 #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" | 20 #include "services/service_manager/public/cpp/service_context.h" |
| 21 #include "services/service_manager/public/cpp/service_runner.h" | 21 #include "services/service_manager/public/cpp/service_runner.h" |
| 22 #include "services/tracing/public/cpp/provider.h" | 22 #include "services/tracing/public/cpp/provider.h" |
| 23 #include "services/ui/public/cpp/window.h" | 23 #include "ui/aura/mus/window_port_mus.h" |
| 24 #include "services/ui/public/cpp/window_tree_client.h" | 24 #include "ui/aura/window.h" |
| 25 #include "ui/aura/mus/mus_util.h" | |
| 26 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/paint_throbber.h" | 26 #include "ui/gfx/paint_throbber.h" |
| 28 #include "ui/native_theme/native_theme.h" | 27 #include "ui/native_theme/native_theme.h" |
| 29 #include "ui/views/background.h" | 28 #include "ui/views/background.h" |
| 30 #include "ui/views/controls/button/label_button.h" | 29 #include "ui/views/controls/button/label_button.h" |
| 31 #include "ui/views/controls/textfield/textfield.h" | 30 #include "ui/views/controls/textfield/textfield.h" |
| 32 #include "ui/views/controls/textfield/textfield_controller.h" | 31 #include "ui/views/controls/textfield/textfield_controller.h" |
| 33 #include "ui/views/mus/aura_init.h" | 32 #include "ui/views/mus/aura_init.h" |
| 34 #include "ui/views/mus/window_manager_connection.h" | 33 #include "ui/views/widget/widget.h" |
| 35 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
| 36 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 37 | 36 |
| 38 namespace views { | 37 namespace views { |
| 39 class AuraInit; | 38 class AuraInit; |
| 40 } | 39 } |
| 41 | 40 |
| 42 namespace mash { | 41 namespace mash { |
| 43 namespace webtest { | 42 namespace webtest { |
| 43 namespace { |
| 44 |
| 45 // Callback from Embed(). |
| 46 void EmbedCallback(bool result) {} |
| 47 |
| 48 } // namespace |
| 44 | 49 |
| 45 class UI : public views::WidgetDelegateView, | 50 class UI : public views::WidgetDelegateView, |
| 46 public navigation::mojom::ViewClient { | 51 public navigation::mojom::ViewClient { |
| 47 public: | 52 public: |
| 48 UI(Webtest* webtest, | 53 UI(Webtest* webtest, |
| 49 navigation::mojom::ViewPtr view, | 54 navigation::mojom::ViewPtr view, |
| 50 navigation::mojom::ViewClientRequest request) | 55 navigation::mojom::ViewClientRequest request) |
| 51 : webtest_(webtest), | 56 : webtest_(webtest), |
| 52 view_(std::move(view)), | 57 view_(std::move(view)), |
| 53 view_client_binding_(this, std::move(request)) {} | 58 view_client_binding_(this, std::move(request)) {} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 82 ConvertPointToWidget(this, &offset); | 87 ConvertPointToWidget(this, &offset); |
| 83 int width = local_bounds.width(); | 88 int width = local_bounds.width(); |
| 84 int height = local_bounds.height(); | 89 int height = local_bounds.height(); |
| 85 content_area_->SetBounds( | 90 content_area_->SetBounds( |
| 86 gfx::Rect(offset.x(), offset.y(), width, height)); | 91 gfx::Rect(offset.x(), offset.y(), width, height)); |
| 87 } | 92 } |
| 88 } | 93 } |
| 89 void ViewHierarchyChanged( | 94 void ViewHierarchyChanged( |
| 90 const views::View::ViewHierarchyChangedDetails& details) override { | 95 const views::View::ViewHierarchyChangedDetails& details) override { |
| 91 if (details.is_add && GetWidget() && !content_area_) { | 96 if (details.is_add && GetWidget() && !content_area_) { |
| 92 ui::Window* window = aura::GetMusWindow(GetWidget()->GetNativeWindow()); | 97 aura::Window* window = GetWidget()->GetNativeWindow(); |
| 93 content_area_ = window->window_tree()->NewWindow(nullptr); | 98 content_area_ = new aura::Window(nullptr); |
| 99 content_area_->Init(ui::LAYER_NOT_DRAWN); |
| 94 window->AddChild(content_area_); | 100 window->AddChild(content_area_); |
| 95 | 101 |
| 96 ui::mojom::WindowTreeClientPtr client; | 102 ui::mojom::WindowTreeClientPtr client; |
| 97 view_->GetWindowTreeClient(GetProxy(&client)); | 103 view_->GetWindowTreeClient(GetProxy(&client)); |
| 98 content_area_->Embed(std::move(client)); | 104 const uint32_t embed_flags = 0; // Nothing special. |
| 105 aura::WindowPortMus::Get(content_area_) |
| 106 ->Embed(std::move(client), embed_flags, base::Bind(&EmbedCallback)); |
| 99 } | 107 } |
| 100 } | 108 } |
| 101 | 109 |
| 102 // navigation::mojom::ViewClient: | 110 // navigation::mojom::ViewClient: |
| 103 void OpenURL(navigation::mojom::OpenURLParamsPtr params) override {} | 111 void OpenURL(navigation::mojom::OpenURLParamsPtr params) override {} |
| 104 void LoadingStateChanged(bool is_loading) override {} | 112 void LoadingStateChanged(bool is_loading) override {} |
| 105 void NavigationStateChanged(const GURL& url, | 113 void NavigationStateChanged(const GURL& url, |
| 106 const std::string& title, | 114 const std::string& title, |
| 107 bool can_go_back, | 115 bool can_go_back, |
| 108 bool can_go_forward) override { | 116 bool can_go_forward) override { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 128 void NavigationPending(navigation::mojom::NavigationEntryPtr entry) override { | 136 void NavigationPending(navigation::mojom::NavigationEntryPtr entry) override { |
| 129 } | 137 } |
| 130 void NavigationCommitted( | 138 void NavigationCommitted( |
| 131 navigation::mojom::NavigationCommittedDetailsPtr details, | 139 navigation::mojom::NavigationCommittedDetailsPtr details, |
| 132 int current_index) override {} | 140 int current_index) override {} |
| 133 void NavigationEntryChanged(navigation::mojom::NavigationEntryPtr entry, | 141 void NavigationEntryChanged(navigation::mojom::NavigationEntryPtr entry, |
| 134 int entry_index) override {} | 142 int entry_index) override {} |
| 135 void NavigationListPruned(bool from_front, int count) override {} | 143 void NavigationListPruned(bool from_front, int count) override {} |
| 136 | 144 |
| 137 Webtest* webtest_; | 145 Webtest* webtest_; |
| 138 ui::Window* content_area_ = nullptr; | 146 aura::Window* content_area_ = nullptr; |
| 139 navigation::mojom::ViewPtr view_; | 147 navigation::mojom::ViewPtr view_; |
| 140 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; | 148 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; |
| 141 base::string16 current_title_; | 149 base::string16 current_title_; |
| 142 | 150 |
| 143 DISALLOW_COPY_AND_ASSIGN(UI); | 151 DISALLOW_COPY_AND_ASSIGN(UI); |
| 144 }; | 152 }; |
| 145 | 153 |
| 146 Webtest::Webtest() {} | 154 Webtest::Webtest() {} |
| 147 Webtest::~Webtest() {} | 155 Webtest::~Webtest() {} |
| 148 | 156 |
| 149 void Webtest::AddWindow(views::Widget* window) { | 157 void Webtest::AddWindow(views::Widget* window) { |
| 150 windows_.push_back(window); | 158 windows_.push_back(window); |
| 151 } | 159 } |
| 152 | 160 |
| 153 void Webtest::RemoveWindow(views::Widget* window) { | 161 void Webtest::RemoveWindow(views::Widget* window) { |
| 154 auto it = std::find(windows_.begin(), windows_.end(), window); | 162 auto it = std::find(windows_.begin(), windows_.end(), window); |
| 155 DCHECK(it != windows_.end()); | 163 DCHECK(it != windows_.end()); |
| 156 windows_.erase(it); | 164 windows_.erase(it); |
| 157 if (windows_.empty()) | 165 if (windows_.empty()) |
| 158 base::MessageLoop::current()->QuitWhenIdle(); | 166 base::MessageLoop::current()->QuitWhenIdle(); |
| 159 } | 167 } |
| 160 | 168 |
| 161 void Webtest::OnStart() { | 169 void Webtest::OnStart() { |
| 162 tracing_.Initialize(context()->connector(), context()->identity().name()); | 170 tracing_.Initialize(context()->connector(), context()->identity().name()); |
| 163 aura_init_ = base::MakeUnique<views::AuraInit>( | 171 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 164 context()->connector(), context()->identity(), "views_mus_resources.pak"); | 172 context()->connector(), context()->identity(), "views_mus_resources.pak", |
| 165 window_manager_connection_ = views::WindowManagerConnection::Create( | 173 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); |
| 166 context()->connector(), context()->identity()); | |
| 167 } | 174 } |
| 168 | 175 |
| 169 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, | 176 bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 170 service_manager::InterfaceRegistry* registry) { | 177 service_manager::InterfaceRegistry* registry) { |
| 171 registry->AddInterface<mojom::Launchable>(this); | 178 registry->AddInterface<mojom::Launchable>(this); |
| 172 return true; | 179 return true; |
| 173 } | 180 } |
| 174 | 181 |
| 175 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { | 182 void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { |
| 176 bool reuse = how == mojom::LaunchMode::REUSE || | 183 bool reuse = how == mojom::LaunchMode::REUSE || |
| (...skipping 18 matching lines...) Expand all Loading... |
| 195 AddWindow(window); | 202 AddWindow(window); |
| 196 } | 203 } |
| 197 | 204 |
| 198 void Webtest::Create(const service_manager::Identity& remote_identity, | 205 void Webtest::Create(const service_manager::Identity& remote_identity, |
| 199 mojom::LaunchableRequest request) { | 206 mojom::LaunchableRequest request) { |
| 200 bindings_.AddBinding(this, std::move(request)); | 207 bindings_.AddBinding(this, std::move(request)); |
| 201 } | 208 } |
| 202 | 209 |
| 203 } // namespace webtest | 210 } // namespace webtest |
| 204 } // namespace mash | 211 } // namespace mash |
| OLD | NEW |