OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/window_tree_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 176 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
177 : connector_(connector), | 177 : connector_(connector), |
178 client_id_(0), | 178 client_id_(0), |
179 next_window_id_(1), | 179 next_window_id_(1), |
180 next_change_id_(1), | 180 next_change_id_(1), |
181 delegate_(delegate), | 181 delegate_(delegate), |
182 window_manager_delegate_(window_manager_delegate), | 182 window_manager_delegate_(window_manager_delegate), |
183 binding_(this), | 183 binding_(this), |
184 tree_(nullptr), | 184 tree_(nullptr), |
185 in_destructor_(false), | 185 in_destructor_(false), |
| 186 in_external_window_mode_(false), |
186 weak_factory_(this) { | 187 weak_factory_(this) { |
187 DCHECK(delegate_); | 188 DCHECK(delegate_); |
188 // Allow for a null request in tests. | 189 // Allow for a null request in tests. |
189 if (request.is_pending()) | 190 if (request.is_pending()) |
190 binding_.Bind(std::move(request)); | 191 binding_.Bind(std::move(request)); |
191 client::GetTransientWindowClient()->AddObserver(this); | 192 client::GetTransientWindowClient()->AddObserver(this); |
192 if (window_manager_delegate) | 193 if (window_manager_delegate) |
193 window_manager_delegate->SetWindowManagerClient(this); | 194 window_manager_delegate->SetWindowManagerClient(this); |
194 if (connector) { // |connector| can be null in tests. | 195 if (connector) { // |connector| can be null in tests. |
195 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); | 196 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); |
(...skipping 17 matching lines...) Expand all Loading... |
213 | 214 |
214 client::GetTransientWindowClient()->RemoveObserver(this); | 215 client::GetTransientWindowClient()->RemoveObserver(this); |
215 | 216 |
216 Env* env = Env::GetInstance(); | 217 Env* env = Env::GetInstance(); |
217 if (compositor_context_factory_ && | 218 if (compositor_context_factory_ && |
218 env->context_factory() == compositor_context_factory_.get()) { | 219 env->context_factory() == compositor_context_factory_.get()) { |
219 env->set_context_factory(initial_context_factory_); | 220 env->set_context_factory(initial_context_factory_); |
220 } | 221 } |
221 } | 222 } |
222 | 223 |
| 224 void WindowTreeClient::ConnectViaWindowTreeHostFactory() { |
| 225 // The client id doesn't really matter, we use 101 purely for debugging. |
| 226 client_id_ = 101; |
| 227 |
| 228 ui::mojom::WindowTreeHostFactoryRegistrarPtr host_factory_registrar; |
| 229 connector_->BindInterface(ui::mojom::kServiceName, &host_factory_registrar); |
| 230 |
| 231 ui::mojom::WindowTreePtr window_tree; |
| 232 host_factory_registrar->Register(MakeRequest(&window_tree_host_factory_ptr_), |
| 233 MakeRequest(&window_tree), |
| 234 binding_.CreateInterfacePtrAndBind()); |
| 235 SetWindowTree(std::move(window_tree)); |
| 236 |
| 237 in_external_window_mode_ = true; |
| 238 } |
| 239 |
223 void WindowTreeClient::ConnectViaWindowTreeFactory() { | 240 void WindowTreeClient::ConnectViaWindowTreeFactory() { |
224 // The client id doesn't really matter, we use 101 purely for debugging. | 241 // The client id doesn't really matter, we use 101 purely for debugging. |
225 client_id_ = 101; | 242 client_id_ = 101; |
226 | 243 |
227 ui::mojom::WindowTreeFactoryPtr factory; | 244 ui::mojom::WindowTreeFactoryPtr factory; |
228 connector_->BindInterface(ui::mojom::kServiceName, &factory); | 245 connector_->BindInterface(ui::mojom::kServiceName, &factory); |
229 ui::mojom::WindowTreePtr window_tree; | 246 ui::mojom::WindowTreePtr window_tree; |
230 factory->CreateWindowTree(MakeRequest(&window_tree), | 247 factory->CreateWindowTree(MakeRequest(&window_tree), |
231 binding_.CreateInterfacePtrAndBind()); | 248 binding_.CreateInterfacePtrAndBind()); |
232 SetWindowTree(std::move(window_tree)); | 249 SetWindowTree(std::move(window_tree)); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 WindowMusType window_mus_type, | 429 WindowMusType window_mus_type, |
413 const ui::mojom::WindowData& window_data, | 430 const ui::mojom::WindowData& window_data, |
414 int64_t display_id) { | 431 int64_t display_id) { |
415 std::unique_ptr<WindowPortMus> window_port = | 432 std::unique_ptr<WindowPortMus> window_port = |
416 CreateWindowPortMus(window_data, window_mus_type); | 433 CreateWindowPortMus(window_data, window_mus_type); |
417 roots_.insert(window_port.get()); | 434 roots_.insert(window_port.get()); |
418 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 435 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
419 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, | 436 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, |
420 display_id); | 437 display_id); |
421 window_tree_host->InitHost(); | 438 window_tree_host->InitHost(); |
| 439 |
| 440 ConfigureWindowDataFromServer(window_tree_host.get(), window_data); |
| 441 return window_tree_host; |
| 442 } |
| 443 |
| 444 void WindowTreeClient::ConfigureWindowDataFromServer( |
| 445 WindowTreeHostMus* window_tree_host, |
| 446 const ui::mojom::WindowData& window_data) { |
422 SetLocalPropertiesFromServerProperties( | 447 SetLocalPropertiesFromServerProperties( |
423 WindowMus::Get(window_tree_host->window()), window_data); | 448 WindowMus::Get(window_tree_host->window()), window_data); |
424 if (window_data.visible) { | 449 if (window_data.visible) { |
425 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()), | 450 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()), |
426 true); | 451 true); |
427 } | 452 } |
428 SetWindowBoundsFromServer(WindowMus::Get(window_tree_host->window()), | 453 SetWindowBoundsFromServer(WindowMus::Get(window_tree_host->window()), |
429 window_data.bounds); | 454 window_data.bounds); |
430 return window_tree_host; | |
431 } | 455 } |
432 | 456 |
433 WindowMus* WindowTreeClient::NewWindowFromWindowData( | 457 WindowMus* WindowTreeClient::NewWindowFromWindowData( |
434 WindowMus* parent, | 458 WindowMus* parent, |
435 const ui::mojom::WindowData& window_data) { | 459 const ui::mojom::WindowData& window_data) { |
436 // This function is only called for windows coming from other clients. | 460 // This function is only called for windows coming from other clients. |
437 std::unique_ptr<WindowPortMus> window_port_mus( | 461 std::unique_ptr<WindowPortMus> window_port_mus( |
438 CreateWindowPortMus(window_data, WindowMusType::OTHER)); | 462 CreateWindowPortMus(window_data, WindowMusType::OTHER)); |
439 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); | 463 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
440 Window* window = new Window(nullptr, std::move(window_port_mus)); | 464 Window* window = new Window(nullptr, std::move(window_port_mus)); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 DCHECK(tree_); | 860 DCHECK(tree_); |
837 tree_->SetEventTargetingPolicy(window->server_id(), policy); | 861 tree_->SetEventTargetingPolicy(window->server_id(), policy); |
838 } | 862 } |
839 | 863 |
840 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, | 864 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
841 ui::mojom::WindowDataPtr root_data, | 865 ui::mojom::WindowDataPtr root_data, |
842 ui::mojom::WindowTreePtr tree, | 866 ui::mojom::WindowTreePtr tree, |
843 int64_t display_id, | 867 int64_t display_id, |
844 Id focused_window_id, | 868 Id focused_window_id, |
845 bool drawn) { | 869 bool drawn) { |
| 870 if (in_external_window_mode_) { |
| 871 // No need to set 'tree_ptr_' whether it was already set during |
| 872 // ConnectViaWindowManagerHostFactory. |
| 873 DCHECK(tree_ptr_); |
| 874 DCHECK(!tree); |
| 875 |
| 876 auto it = windows_.find(focused_window_id); |
| 877 DCHECK(it != windows_.end()); |
| 878 |
| 879 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(it->second); |
| 880 window_tree_host->InitHost(); |
| 881 ConfigureWindowDataFromServer(window_tree_host, *root_data); |
| 882 |
| 883 // TODO(tonikitoo): Fix the WindowTreeClientDelegate::OnEmbed API. |
| 884 // In external window mode, this needs not to pass the ownership of the |
| 885 // WindowTreeHostMus instance to the delegate_. A raw pointer should |
| 886 // surface. |
| 887 delegate_->OnEmbed(nullptr); |
| 888 return; |
| 889 } |
| 890 |
846 DCHECK(!tree_ptr_); | 891 DCHECK(!tree_ptr_); |
| 892 DCHECK(tree); |
847 tree_ptr_ = std::move(tree); | 893 tree_ptr_ = std::move(tree); |
848 | 894 |
849 is_from_embed_ = true; | 895 is_from_embed_ = true; |
850 | 896 |
851 if (window_manager_delegate_) { | 897 if (window_manager_delegate_) { |
852 tree_ptr_->GetWindowManagerClient( | 898 tree_ptr_->GetWindowManagerClient( |
853 MakeRequest(&window_manager_internal_client_)); | 899 MakeRequest(&window_manager_internal_client_)); |
854 } | 900 } |
855 | 901 |
856 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, | 902 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 } | 1755 } |
1710 | 1756 |
1711 void WindowTreeClient::OnWindowTreeHostCancelWindowMove( | 1757 void WindowTreeClient::OnWindowTreeHostCancelWindowMove( |
1712 WindowTreeHostMus* window_tree_host) { | 1758 WindowTreeHostMus* window_tree_host) { |
1713 tree_->CancelWindowMove( | 1759 tree_->CancelWindowMove( |
1714 WindowMus::Get(window_tree_host->window())->server_id()); | 1760 WindowMus::Get(window_tree_host->window())->server_id()); |
1715 } | 1761 } |
1716 | 1762 |
1717 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel( | 1763 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel( |
1718 const std::map<std::string, std::vector<uint8_t>>* properties) { | 1764 const std::map<std::string, std::vector<uint8_t>>* properties) { |
| 1765 WindowMusType window_type = in_external_window_mode_ |
| 1766 ? WindowMusType::EMBED |
| 1767 : WindowMusType::TOP_LEVEL; |
| 1768 |
1719 std::unique_ptr<WindowPortMus> window_port = | 1769 std::unique_ptr<WindowPortMus> window_port = |
1720 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); | 1770 base::MakeUnique<WindowPortMus>(this, window_type); |
1721 roots_.insert(window_port.get()); | 1771 roots_.insert(window_port.get()); |
1722 | 1772 |
1723 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++)); | 1773 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++)); |
1724 RegisterWindowMus(window_port.get()); | 1774 RegisterWindowMus(window_port.get()); |
1725 | 1775 |
1726 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; | 1776 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; |
1727 if (properties) { | 1777 if (properties) { |
1728 for (const auto& property_pair : *properties) | 1778 for (const auto& property_pair : *properties) |
1729 transport_properties[property_pair.first] = property_pair.second; | 1779 transport_properties[property_pair.first] = property_pair.second; |
1730 } | 1780 } |
1731 | 1781 |
1732 const uint32_t change_id = | 1782 if (in_external_window_mode_) { |
1733 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 1783 // Triggers the creation of a mojom::WindowTreeHost (aka ws::Display) |
1734 window_port.get(), ChangeType::NEW_TOP_LEVEL_WINDOW)); | 1784 // instance on the server side. |
1735 tree_->NewTopLevelWindow(change_id, window_port->server_id(), | 1785 // Ends up calling back to client side, aura::WindowTreeClient::OnEmbed. |
1736 transport_properties); | 1786 ui::mojom::WindowTreeHostPtr host; |
| 1787 window_tree_host_factory_ptr_->CreatePlatformWindow( |
| 1788 MakeRequest(&host), window_port->server_id()); |
| 1789 } else { |
| 1790 const uint32_t change_id = |
| 1791 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| 1792 window_port.get(), ChangeType::NEW_TOP_LEVEL_WINDOW)); |
| 1793 tree_->NewTopLevelWindow(change_id, window_port->server_id(), |
| 1794 transport_properties); |
| 1795 } |
| 1796 |
1737 return window_port; | 1797 return window_port; |
1738 } | 1798 } |
1739 | 1799 |
1740 void WindowTreeClient::OnWindowTreeHostCreated( | 1800 void WindowTreeClient::OnWindowTreeHostCreated( |
1741 WindowTreeHostMus* window_tree_host) { | 1801 WindowTreeHostMus* window_tree_host) { |
1742 // All WindowTreeHosts are destroyed before this, so we don't need to unset | 1802 // All WindowTreeHosts are destroyed before this, so we don't need to unset |
1743 // the DragDropClient. | 1803 // the DragDropClient. |
1744 client::SetDragDropClient(window_tree_host->window(), | 1804 client::SetDragDropClient(window_tree_host->window(), |
1745 drag_drop_controller_.get()); | 1805 drag_drop_controller_.get()); |
1746 } | 1806 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1881 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
1822 this, capture_synchronizer_.get(), window)); | 1882 this, capture_synchronizer_.get(), window)); |
1823 } | 1883 } |
1824 | 1884 |
1825 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1885 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
1826 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1886 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
1827 this, focus_synchronizer_.get(), window)); | 1887 this, focus_synchronizer_.get(), window)); |
1828 } | 1888 } |
1829 | 1889 |
1830 } // namespace aura | 1890 } // namespace aura |
OLD | NEW |