| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 178 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 179 : connector_(connector), | 179 : connector_(connector), |
| 180 client_id_(0), | 180 client_id_(0), |
| 181 next_window_id_(1), | 181 next_window_id_(1), |
| 182 next_change_id_(1), | 182 next_change_id_(1), |
| 183 delegate_(delegate), | 183 delegate_(delegate), |
| 184 window_manager_delegate_(window_manager_delegate), | 184 window_manager_delegate_(window_manager_delegate), |
| 185 binding_(this), | 185 binding_(this), |
| 186 tree_(nullptr), | 186 tree_(nullptr), |
| 187 in_destructor_(false), | 187 in_destructor_(false), |
| 188 in_external_window_mode_(false), |
| 188 weak_factory_(this) { | 189 weak_factory_(this) { |
| 189 DCHECK(delegate_); | 190 DCHECK(delegate_); |
| 190 // Allow for a null request in tests. | 191 // Allow for a null request in tests. |
| 191 if (request.is_pending()) | 192 if (request.is_pending()) |
| 192 binding_.Bind(std::move(request)); | 193 binding_.Bind(std::move(request)); |
| 193 client::GetTransientWindowClient()->AddObserver(this); | 194 client::GetTransientWindowClient()->AddObserver(this); |
| 194 if (window_manager_delegate) | 195 if (window_manager_delegate) |
| 195 window_manager_delegate->SetWindowManagerClient(this); | 196 window_manager_delegate->SetWindowManagerClient(this); |
| 196 if (connector) { // |connector| can be null in tests. | 197 if (connector) { // |connector| can be null in tests. |
| 197 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); | 198 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 227 client_id_ = 101; | 228 client_id_ = 101; |
| 228 | 229 |
| 229 ui::mojom::WindowTreeFactoryPtr factory; | 230 ui::mojom::WindowTreeFactoryPtr factory; |
| 230 connector_->BindInterface(ui::mojom::kServiceName, &factory); | 231 connector_->BindInterface(ui::mojom::kServiceName, &factory); |
| 231 ui::mojom::WindowTreePtr window_tree; | 232 ui::mojom::WindowTreePtr window_tree; |
| 232 factory->CreateWindowTree(MakeRequest(&window_tree), | 233 factory->CreateWindowTree(MakeRequest(&window_tree), |
| 233 binding_.CreateInterfacePtrAndBind()); | 234 binding_.CreateInterfacePtrAndBind()); |
| 234 SetWindowTree(std::move(window_tree)); | 235 SetWindowTree(std::move(window_tree)); |
| 235 } | 236 } |
| 236 | 237 |
| 238 void WindowTreeClient::ConnectViaWindowTreeHostFactory() { |
| 239 // The client id doesn't really matter, we use 101 purely for debugging. |
| 240 client_id_ = 101; |
| 241 |
| 242 ui::mojom::WindowTreeHostFactoryRegistrarPtr host_factory_registrar; |
| 243 connector_->BindInterface(ui::mojom::kServiceName, &host_factory_registrar); |
| 244 |
| 245 ui::mojom::WindowTreePtr window_tree; |
| 246 host_factory_registrar->Register(MakeRequest(&window_tree_host_factory_ptr_), |
| 247 MakeRequest(&window_tree), |
| 248 binding_.CreateInterfacePtrAndBind()); |
| 249 SetWindowTree(std::move(window_tree)); |
| 250 |
| 251 in_external_window_mode_ = true; |
| 252 } |
| 253 |
| 237 void WindowTreeClient::ConnectAsWindowManager() { | 254 void WindowTreeClient::ConnectAsWindowManager() { |
| 238 DCHECK(window_manager_delegate_); | 255 DCHECK(window_manager_delegate_); |
| 239 | 256 |
| 240 ui::mojom::WindowManagerWindowTreeFactoryPtr factory; | 257 ui::mojom::WindowManagerWindowTreeFactoryPtr factory; |
| 241 connector_->BindInterface(ui::mojom::kServiceName, &factory); | 258 connector_->BindInterface(ui::mojom::kServiceName, &factory); |
| 242 ui::mojom::WindowTreePtr window_tree; | 259 ui::mojom::WindowTreePtr window_tree; |
| 243 factory->CreateWindowTree(MakeRequest(&window_tree), | 260 factory->CreateWindowTree(MakeRequest(&window_tree), |
| 244 binding_.CreateInterfacePtrAndBind()); | 261 binding_.CreateInterfacePtrAndBind()); |
| 245 SetWindowTree(std::move(window_tree)); | 262 SetWindowTree(std::move(window_tree)); |
| 246 } | 263 } |
| 247 | 264 |
| 265 void WindowTreeClient::CreateHost(ui::mojom::WindowTreeHostRequest host, |
| 266 uint32_t client_id) { |
| 267 window_tree_host_factory_ptr_->CreatePlatformWindow(std::move(host), |
| 268 client_id); |
| 269 } |
| 270 |
| 248 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { | 271 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { |
| 249 DCHECK(tree_); | 272 DCHECK(tree_); |
| 250 DCHECK(window); | 273 DCHECK(window); |
| 251 tree_->SetCanFocus(WindowMus::Get(window)->server_id(), can_focus); | 274 tree_->SetCanFocus(WindowMus::Get(window)->server_id(), can_focus); |
| 252 } | 275 } |
| 253 | 276 |
| 254 void WindowTreeClient::SetPredefinedCursor(WindowMus* window, | 277 void WindowTreeClient::SetPredefinedCursor(WindowMus* window, |
| 255 ui::mojom::Cursor old_cursor, | 278 ui::mojom::Cursor old_cursor, |
| 256 ui::mojom::Cursor new_cursor) { | 279 ui::mojom::Cursor new_cursor) { |
| 257 DCHECK(tree_); | 280 DCHECK(tree_); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 WindowMusType window_mus_type, | 437 WindowMusType window_mus_type, |
| 415 const ui::mojom::WindowData& window_data, | 438 const ui::mojom::WindowData& window_data, |
| 416 int64_t display_id) { | 439 int64_t display_id) { |
| 417 std::unique_ptr<WindowPortMus> window_port = | 440 std::unique_ptr<WindowPortMus> window_port = |
| 418 CreateWindowPortMus(window_data, window_mus_type); | 441 CreateWindowPortMus(window_data, window_mus_type); |
| 419 roots_.insert(window_port.get()); | 442 roots_.insert(window_port.get()); |
| 420 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 443 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
| 421 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, | 444 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, |
| 422 display_id); | 445 display_id); |
| 423 window_tree_host->InitHost(); | 446 window_tree_host->InitHost(); |
| 447 |
| 448 ConfigureWindowDataFromServer(window_tree_host.get(), window_data); |
| 449 return window_tree_host; |
| 450 } |
| 451 |
| 452 void WindowTreeClient::ConfigureWindowDataFromServer( |
| 453 WindowTreeHostMus* window_tree_host, |
| 454 const ui::mojom::WindowData& window_data) { |
| 424 SetLocalPropertiesFromServerProperties( | 455 SetLocalPropertiesFromServerProperties( |
| 425 WindowMus::Get(window_tree_host->window()), window_data); | 456 WindowMus::Get(window_tree_host->window()), window_data); |
| 426 if (window_data.visible) { | 457 if (window_data.visible) { |
| 427 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()), | 458 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()), |
| 428 true); | 459 true); |
| 429 } | 460 } |
| 430 SetWindowBoundsFromServer(WindowMus::Get(window_tree_host->window()), | 461 SetWindowBoundsFromServer(WindowMus::Get(window_tree_host->window()), |
| 431 window_data.bounds); | 462 window_data.bounds); |
| 432 return window_tree_host; | |
| 433 } | 463 } |
| 434 | 464 |
| 435 WindowMus* WindowTreeClient::NewWindowFromWindowData( | 465 WindowMus* WindowTreeClient::NewWindowFromWindowData( |
| 436 WindowMus* parent, | 466 WindowMus* parent, |
| 437 const ui::mojom::WindowData& window_data) { | 467 const ui::mojom::WindowData& window_data) { |
| 438 // This function is only called for windows coming from other clients. | 468 // This function is only called for windows coming from other clients. |
| 439 std::unique_ptr<WindowPortMus> window_port_mus( | 469 std::unique_ptr<WindowPortMus> window_port_mus( |
| 440 CreateWindowPortMus(window_data, WindowMusType::OTHER)); | 470 CreateWindowPortMus(window_data, WindowMusType::OTHER)); |
| 441 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); | 471 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
| 442 Window* window = new Window(nullptr, std::move(window_port_mus)); | 472 Window* window = new Window(nullptr, std::move(window_port_mus)); |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 DCHECK(tree_); | 867 DCHECK(tree_); |
| 838 tree_->SetEventTargetingPolicy(window->server_id(), policy); | 868 tree_->SetEventTargetingPolicy(window->server_id(), policy); |
| 839 } | 869 } |
| 840 | 870 |
| 841 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, | 871 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
| 842 ui::mojom::WindowDataPtr root_data, | 872 ui::mojom::WindowDataPtr root_data, |
| 843 ui::mojom::WindowTreePtr tree, | 873 ui::mojom::WindowTreePtr tree, |
| 844 int64_t display_id, | 874 int64_t display_id, |
| 845 Id focused_window_id, | 875 Id focused_window_id, |
| 846 bool drawn) { | 876 bool drawn) { |
| 877 if (in_external_window_mode_) { |
| 878 // No need to set 'tree_ptr_' whether it was already set during |
| 879 // ConnectViaWindowManagerHostFactory. |
| 880 DCHECK(tree_ptr_); |
| 881 DCHECK(!tree); |
| 882 |
| 883 auto it = windows_.find(focused_window_id); |
| 884 DCHECK(it != windows_.end()); |
| 885 |
| 886 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(it->second); |
| 887 window_tree_host->InitHost(); |
| 888 ConfigureWindowDataFromServer(window_tree_host, *root_data); |
| 889 |
| 890 delegate_->OnEmbed(nullptr); |
| 891 return; |
| 892 } |
| 893 |
| 847 DCHECK(!tree_ptr_); | 894 DCHECK(!tree_ptr_); |
| 895 DCHECK(tree); |
| 848 tree_ptr_ = std::move(tree); | 896 tree_ptr_ = std::move(tree); |
| 849 | 897 |
| 850 is_from_embed_ = true; | 898 is_from_embed_ = true; |
| 851 | 899 |
| 852 if (window_manager_delegate_) { | 900 if (window_manager_delegate_) { |
| 853 tree_ptr_->GetWindowManagerClient( | 901 tree_ptr_->GetWindowManagerClient( |
| 854 MakeRequest(&window_manager_internal_client_)); | 902 MakeRequest(&window_manager_internal_client_)); |
| 855 } | 903 } |
| 856 | 904 |
| 857 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, | 905 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 } | 1759 } |
| 1712 | 1760 |
| 1713 void WindowTreeClient::OnWindowTreeHostCancelWindowMove( | 1761 void WindowTreeClient::OnWindowTreeHostCancelWindowMove( |
| 1714 WindowTreeHostMus* window_tree_host) { | 1762 WindowTreeHostMus* window_tree_host) { |
| 1715 tree_->CancelWindowMove( | 1763 tree_->CancelWindowMove( |
| 1716 WindowMus::Get(window_tree_host->window())->server_id()); | 1764 WindowMus::Get(window_tree_host->window())->server_id()); |
| 1717 } | 1765 } |
| 1718 | 1766 |
| 1719 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel( | 1767 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel( |
| 1720 const std::map<std::string, std::vector<uint8_t>>* properties) { | 1768 const std::map<std::string, std::vector<uint8_t>>* properties) { |
| 1769 WindowMusType window_type = in_external_window_mode_ |
| 1770 ? WindowMusType::EMBED |
| 1771 : WindowMusType::TOP_LEVEL; |
| 1772 |
| 1721 std::unique_ptr<WindowPortMus> window_port = | 1773 std::unique_ptr<WindowPortMus> window_port = |
| 1722 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); | 1774 base::MakeUnique<WindowPortMus>(this, window_type); |
| 1723 roots_.insert(window_port.get()); | 1775 roots_.insert(window_port.get()); |
| 1724 | 1776 |
| 1725 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++)); | 1777 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++)); |
| 1726 RegisterWindowMus(window_port.get()); | 1778 RegisterWindowMus(window_port.get()); |
| 1727 | 1779 |
| 1728 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; | 1780 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; |
| 1729 if (properties) { | 1781 if (properties) { |
| 1730 for (const auto& property_pair : *properties) | 1782 for (const auto& property_pair : *properties) |
| 1731 transport_properties[property_pair.first] = property_pair.second; | 1783 transport_properties[property_pair.first] = property_pair.second; |
| 1732 } | 1784 } |
| 1733 | 1785 |
| 1734 const uint32_t change_id = | 1786 if (in_external_window_mode_) { |
| 1735 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 1787 ui::mojom::WindowTreeHostPtr host; |
| 1736 window_port.get(), ChangeType::NEW_TOP_LEVEL_WINDOW)); | 1788 CreateHost(MakeRequest(&host), window_port->server_id()); |
| 1737 tree_->NewTopLevelWindow(change_id, window_port->server_id(), | 1789 } else { |
| 1738 transport_properties); | 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 |
| 1739 return window_port; | 1797 return window_port; |
| 1740 } | 1798 } |
| 1741 | 1799 |
| 1742 void WindowTreeClient::OnWindowTreeHostCreated( | 1800 void WindowTreeClient::OnWindowTreeHostCreated( |
| 1743 WindowTreeHostMus* window_tree_host) { | 1801 WindowTreeHostMus* window_tree_host) { |
| 1744 // 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 |
| 1745 // the DragDropClient. | 1803 // the DragDropClient. |
| 1746 client::SetDragDropClient(window_tree_host->window(), | 1804 client::SetDragDropClient(window_tree_host->window(), |
| 1747 drag_drop_controller_.get()); | 1805 drag_drop_controller_.get()); |
| 1748 } | 1806 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1881 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1824 this, capture_synchronizer_.get(), window)); | 1882 this, capture_synchronizer_.get(), window)); |
| 1825 } | 1883 } |
| 1826 | 1884 |
| 1827 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1885 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1828 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1886 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1829 this, focus_synchronizer_.get(), window)); | 1887 this, focus_synchronizer_.get(), window)); |
| 1830 } | 1888 } |
| 1831 | 1889 |
| 1832 } // namespace aura | 1890 } // namespace aura |
| OLD | NEW |