Chromium Code Reviews| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 DCHECK(tree_); | 870 DCHECK(tree_); |
| 841 tree_->SetEventTargetingPolicy(window->server_id(), policy); | 871 tree_->SetEventTargetingPolicy(window->server_id(), policy); |
| 842 } | 872 } |
| 843 | 873 |
| 844 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, | 874 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
| 845 ui::mojom::WindowDataPtr root_data, | 875 ui::mojom::WindowDataPtr root_data, |
| 846 ui::mojom::WindowTreePtr tree, | 876 ui::mojom::WindowTreePtr tree, |
| 847 int64_t display_id, | 877 int64_t display_id, |
| 848 Id focused_window_id, | 878 Id focused_window_id, |
| 849 bool drawn) { | 879 bool drawn) { |
| 880 if (in_external_window_mode_) { | |
| 881 // No need to set 'tree_ptr_' whether it was already set during | |
| 882 // ConnectViaWindowManagerHostFactory. | |
| 883 DCHECK(tree_ptr_); | |
| 884 DCHECK(!tree); | |
| 885 | |
| 886 auto it = windows_.find(focused_window_id); | |
| 887 DCHECK(it != windows_.end()); | |
| 888 | |
| 889 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(it->second); | |
| 890 window_tree_host->InitHost(); | |
| 891 ConfigureWindowDataFromServer(window_tree_host, *root_data); | |
| 892 | |
| 893 delegate_->OnEmbed(nullptr); | |
|
fwang
2017/03/07 09:21:25
I believe this is the key point. In the future, we
| |
| 894 return; | |
| 895 } | |
| 896 | |
| 850 DCHECK(!tree_ptr_); | 897 DCHECK(!tree_ptr_); |
| 898 DCHECK(tree); | |
| 851 tree_ptr_ = std::move(tree); | 899 tree_ptr_ = std::move(tree); |
| 852 | 900 |
| 853 is_from_embed_ = true; | 901 is_from_embed_ = true; |
| 854 | 902 |
| 855 if (window_manager_delegate_) { | 903 if (window_manager_delegate_) { |
| 856 tree_ptr_->GetWindowManagerClient( | 904 tree_ptr_->GetWindowManagerClient( |
| 857 MakeRequest(&window_manager_internal_client_)); | 905 MakeRequest(&window_manager_internal_client_)); |
| 858 } | 906 } |
| 859 | 907 |
| 860 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, | 908 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1712 } | 1760 } |
| 1713 | 1761 |
| 1714 void WindowTreeClient::OnWindowTreeHostCancelWindowMove( | 1762 void WindowTreeClient::OnWindowTreeHostCancelWindowMove( |
| 1715 WindowTreeHostMus* window_tree_host) { | 1763 WindowTreeHostMus* window_tree_host) { |
| 1716 tree_->CancelWindowMove( | 1764 tree_->CancelWindowMove( |
| 1717 WindowMus::Get(window_tree_host->window())->server_id()); | 1765 WindowMus::Get(window_tree_host->window())->server_id()); |
| 1718 } | 1766 } |
| 1719 | 1767 |
| 1720 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel( | 1768 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel( |
| 1721 const std::map<std::string, std::vector<uint8_t>>* properties) { | 1769 const std::map<std::string, std::vector<uint8_t>>* properties) { |
| 1770 WindowMusType window_type = in_external_window_mode_ | |
| 1771 ? WindowMusType::EMBED | |
| 1772 : WindowMusType::TOP_LEVEL; | |
| 1773 | |
| 1722 std::unique_ptr<WindowPortMus> window_port = | 1774 std::unique_ptr<WindowPortMus> window_port = |
| 1723 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); | 1775 base::MakeUnique<WindowPortMus>(this, window_type); |
| 1724 roots_.insert(window_port.get()); | 1776 roots_.insert(window_port.get()); |
| 1725 | 1777 |
| 1726 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++)); | 1778 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++)); |
| 1727 RegisterWindowMus(window_port.get()); | 1779 RegisterWindowMus(window_port.get()); |
| 1728 | 1780 |
| 1729 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; | 1781 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; |
| 1730 if (properties) { | 1782 if (properties) { |
| 1731 for (const auto& property_pair : *properties) | 1783 for (const auto& property_pair : *properties) |
| 1732 transport_properties[property_pair.first] = property_pair.second; | 1784 transport_properties[property_pair.first] = property_pair.second; |
| 1733 } | 1785 } |
| 1734 | 1786 |
| 1735 const uint32_t change_id = | 1787 if (in_external_window_mode_) { |
| 1736 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 1788 ui::mojom::WindowTreeHostPtr host; |
| 1737 window_port.get(), ChangeType::NEW_TOP_LEVEL_WINDOW)); | 1789 CreateHost(MakeRequest(&host), window_port->server_id()); |
| 1738 tree_->NewTopLevelWindow(change_id, window_port->server_id(), | 1790 } else { |
| 1739 transport_properties); | 1791 const uint32_t change_id = |
| 1792 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | |
| 1793 window_port.get(), ChangeType::NEW_TOP_LEVEL_WINDOW)); | |
| 1794 tree_->NewTopLevelWindow(change_id, window_port->server_id(), | |
| 1795 transport_properties); | |
| 1796 } | |
| 1797 | |
| 1740 return window_port; | 1798 return window_port; |
| 1741 } | 1799 } |
| 1742 | 1800 |
| 1743 void WindowTreeClient::OnWindowTreeHostCreated( | 1801 void WindowTreeClient::OnWindowTreeHostCreated( |
| 1744 WindowTreeHostMus* window_tree_host) { | 1802 WindowTreeHostMus* window_tree_host) { |
| 1745 // All WindowTreeHosts are destroyed before this, so we don't need to unset | 1803 // All WindowTreeHosts are destroyed before this, so we don't need to unset |
| 1746 // the DragDropClient. | 1804 // the DragDropClient. |
| 1747 client::SetDragDropClient(window_tree_host->window(), | 1805 client::SetDragDropClient(window_tree_host->window(), |
| 1748 drag_drop_controller_.get()); | 1806 drag_drop_controller_.get()); |
| 1749 } | 1807 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1824 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1882 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1825 this, capture_synchronizer_.get(), window)); | 1883 this, capture_synchronizer_.get(), window)); |
| 1826 } | 1884 } |
| 1827 | 1885 |
| 1828 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1886 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1829 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1887 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1830 this, focus_synchronizer_.get(), window)); | 1888 this, focus_synchronizer_.get(), window)); |
| 1831 } | 1889 } |
| 1832 | 1890 |
| 1833 } // namespace aura | 1891 } // namespace aura |
| OLD | NEW |