| 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 27 matching lines...) Expand all Loading... |
| 38 class AuraInit; | 38 class AuraInit; |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace mash { | 41 namespace mash { |
| 42 namespace webtest { | 42 namespace webtest { |
| 43 | 43 |
| 44 class UI : public views::WidgetDelegateView, | 44 class UI : public views::WidgetDelegateView, |
| 45 public navigation::mojom::ViewClient { | 45 public navigation::mojom::ViewClient { |
| 46 public: | 46 public: |
| 47 UI(Webtest* webtest, | 47 UI(Webtest* webtest, |
| 48 bool is_popup, | |
| 49 navigation::mojom::ViewPtr view, | 48 navigation::mojom::ViewPtr view, |
| 50 navigation::mojom::ViewClientRequest request) | 49 navigation::mojom::ViewClientRequest request) |
| 51 : webtest_(webtest), | 50 : webtest_(webtest), |
| 52 is_popup_(is_popup), | |
| 53 view_(std::move(view)), | 51 view_(std::move(view)), |
| 54 view_client_binding_(this, std::move(request)) {} | 52 view_client_binding_(this, std::move(request)) {} |
| 55 ~UI() override { | 53 ~UI() override { |
| 56 webtest_->RemoveWindow(GetWidget()); | 54 webtest_->RemoveWindow(GetWidget()); |
| 57 } | 55 } |
| 58 | 56 |
| 59 void NavigateTo(const GURL& url) { | 57 void NavigateTo(const GURL& url) { |
| 60 view_->NavigateTo(url); | 58 view_->NavigateTo(url); |
| 61 } | 59 } |
| 62 | 60 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 current_title_ = base::UTF8ToUTF16(title.get()); | 108 current_title_ = base::UTF8ToUTF16(title.get()); |
| 111 GetWidget()->UpdateWindowTitle(); | 109 GetWidget()->UpdateWindowTitle(); |
| 112 } | 110 } |
| 113 void LoadProgressChanged(double progress) override {} | 111 void LoadProgressChanged(double progress) override {} |
| 114 void ViewCreated(navigation::mojom::ViewPtr view, | 112 void ViewCreated(navigation::mojom::ViewPtr view, |
| 115 navigation::mojom::ViewClientRequest request, | 113 navigation::mojom::ViewClientRequest request, |
| 116 bool is_popup, | 114 bool is_popup, |
| 117 mojo::RectPtr initial_rect, | 115 mojo::RectPtr initial_rect, |
| 118 bool user_gesture) override { | 116 bool user_gesture) override { |
| 119 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 117 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
| 120 new UI(webtest_, is_popup, std::move(view), std::move(request)), | 118 new UI(webtest_, std::move(view), std::move(request)), nullptr, |
| 121 nullptr, initial_rect.To<gfx::Rect>()); | 119 initial_rect.To<gfx::Rect>()); |
| 122 window->Show(); | 120 window->Show(); |
| 123 webtest_->AddWindow(window); | 121 webtest_->AddWindow(window); |
| 124 } | 122 } |
| 125 void Close() override { | 123 void Close() override { |
| 126 GetWidget()->Close(); | 124 GetWidget()->Close(); |
| 127 } | 125 } |
| 128 | 126 |
| 129 Webtest* webtest_; | 127 Webtest* webtest_; |
| 130 bool is_popup_; | |
| 131 mus::Window* content_area_ = nullptr; | 128 mus::Window* content_area_ = nullptr; |
| 132 navigation::mojom::ViewPtr view_; | 129 navigation::mojom::ViewPtr view_; |
| 133 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; | 130 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; |
| 134 base::string16 current_title_; | 131 base::string16 current_title_; |
| 135 | 132 |
| 136 DISALLOW_COPY_AND_ASSIGN(UI); | 133 DISALLOW_COPY_AND_ASSIGN(UI); |
| 137 }; | 134 }; |
| 138 | 135 |
| 139 Webtest::Webtest() {} | 136 Webtest::Webtest() {} |
| 140 Webtest::~Webtest() {} | 137 Webtest::~Webtest() {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return; | 171 return; |
| 175 } | 172 } |
| 176 | 173 |
| 177 navigation::mojom::ViewFactoryPtr view_factory; | 174 navigation::mojom::ViewFactoryPtr view_factory; |
| 178 connector_->ConnectToInterface("exe:navigation", &view_factory); | 175 connector_->ConnectToInterface("exe:navigation", &view_factory); |
| 179 navigation::mojom::ViewPtr view; | 176 navigation::mojom::ViewPtr view; |
| 180 navigation::mojom::ViewClientPtr view_client; | 177 navigation::mojom::ViewClientPtr view_client; |
| 181 navigation::mojom::ViewClientRequest view_client_request = | 178 navigation::mojom::ViewClientRequest view_client_request = |
| 182 GetProxy(&view_client); | 179 GetProxy(&view_client); |
| 183 view_factory->CreateView(std::move(view_client), GetProxy(&view)); | 180 view_factory->CreateView(std::move(view_client), GetProxy(&view)); |
| 184 UI* ui = new UI(this, false, std::move(view), std::move(view_client_request)); | 181 UI* ui = new UI(this, std::move(view), std::move(view_client_request)); |
| 185 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 182 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
| 186 ui, nullptr, gfx::Rect(50, 10, 600, 600)); | 183 ui, nullptr, gfx::Rect(50, 10, 600, 600)); |
| 187 ui->NavigateTo(GURL("http://www.theverge.com/")); | 184 ui->NavigateTo(GURL("http://www.theverge.com/")); |
| 188 window->Show(); | 185 window->Show(); |
| 189 AddWindow(window); | 186 AddWindow(window); |
| 190 } | 187 } |
| 191 | 188 |
| 192 void Webtest::Create(shell::Connection* connection, | 189 void Webtest::Create(shell::Connection* connection, |
| 193 mojom::LaunchableRequest request) { | 190 mojom::LaunchableRequest request) { |
| 194 bindings_.AddBinding(this, std::move(request)); | 191 bindings_.AddBinding(this, std::move(request)); |
| 195 } | 192 } |
| 196 | 193 |
| 197 } // namespace webtest | 194 } // namespace webtest |
| 198 } // namespace mash | 195 } // namespace mash |
| OLD | NEW |