OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/views/mus/window_manager_connection.h" | 5 #include "ui/views/mus/window_manager_connection.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 // static | 104 // static |
105 WindowManagerConnection* WindowManagerConnection::Get() { | 105 WindowManagerConnection* WindowManagerConnection::Get() { |
106 WindowManagerConnection* connection = lazy_tls_ptr.Pointer()->Get(); | 106 WindowManagerConnection* connection = lazy_tls_ptr.Pointer()->Get(); |
107 DCHECK(connection); | 107 DCHECK(connection); |
108 return connection; | 108 return connection; |
109 } | 109 } |
110 | 110 |
111 mus::Window* WindowManagerConnection::NewWindow( | 111 mus::Window* WindowManagerConnection::NewWindow( |
112 const std::map<std::string, std::vector<uint8_t>>& properties) { | 112 const std::map<std::string, std::vector<uint8_t>>& properties) { |
| 113 if (window_tree_connection_) |
| 114 return window_tree_connection_->NewTopLevelWindow(&properties); |
| 115 |
113 mus::mojom::WindowTreeClientPtr window_tree_client; | 116 mus::mojom::WindowTreeClientPtr window_tree_client; |
114 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> | 117 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> |
115 window_tree_client_request = GetProxy(&window_tree_client); | 118 window_tree_client_request = GetProxy(&window_tree_client); |
116 window_manager_->OpenWindow( | 119 window_manager_->OpenWindow( |
117 std::move(window_tree_client), | 120 std::move(window_tree_client), |
118 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(properties)); | 121 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(properties)); |
119 | 122 |
120 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 123 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
121 mus::WindowTreeConnection* window_tree_connection = | 124 window_tree_connection_.reset(mus::WindowTreeConnection::Create( |
122 mus::WindowTreeConnection::Create( | 125 this, std::move(window_tree_client_request), |
123 this, std::move(window_tree_client_request), | 126 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED)); |
124 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED); | 127 window_tree_connection_->SetDeleteOnNoRoots(false); |
125 DCHECK_EQ(1u, window_tree_connection->GetRoots().size()); | 128 DCHECK_EQ(1u, window_tree_connection_->GetRoots().size()); |
126 return *window_tree_connection->GetRoots().begin(); | 129 return *window_tree_connection_->GetRoots().begin(); |
127 } | 130 } |
128 | 131 |
129 WindowManagerConnection::WindowManagerConnection(mojo::ApplicationImpl* app) | 132 WindowManagerConnection::WindowManagerConnection(mojo::ApplicationImpl* app) |
130 : app_(app) { | 133 : app_(app), window_tree_connection_(nullptr) { |
131 app->ConnectToService("mojo:mus", &window_manager_); | 134 app->ConnectToService("mojo:mus", &window_manager_); |
132 | 135 |
133 ui_init_.reset(new ui::mojo::UIInit( | 136 ui_init_.reset(new ui::mojo::UIInit( |
134 GetDisplaysFromWindowManager(&window_manager_))); | 137 GetDisplaysFromWindowManager(&window_manager_))); |
135 ViewsDelegate::GetInstance()->set_native_widget_factory( | 138 ViewsDelegate::GetInstance()->set_native_widget_factory( |
136 base::Bind(&WindowManagerConnection::CreateNativeWidget, | 139 base::Bind(&WindowManagerConnection::CreateNativeWidget, |
137 base::Unretained(this))); | 140 base::Unretained(this))); |
138 } | 141 } |
139 | 142 |
140 WindowManagerConnection::~WindowManagerConnection() {} | 143 WindowManagerConnection::~WindowManagerConnection() { |
| 144 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), |
| 145 // destroy it while we are still valid. |
| 146 window_tree_connection_.reset(); |
| 147 } |
141 | 148 |
142 void WindowManagerConnection::OnEmbed(mus::Window* root) {} | 149 void WindowManagerConnection::OnEmbed(mus::Window* root) {} |
| 150 |
143 void WindowManagerConnection::OnConnectionLost( | 151 void WindowManagerConnection::OnConnectionLost( |
144 mus::WindowTreeConnection* connection) {} | 152 mus::WindowTreeConnection* connection) {} |
145 | 153 |
146 NativeWidget* WindowManagerConnection::CreateNativeWidget( | 154 NativeWidget* WindowManagerConnection::CreateNativeWidget( |
147 const Widget::InitParams& init_params, | 155 const Widget::InitParams& init_params, |
148 internal::NativeWidgetDelegate* delegate) { | 156 internal::NativeWidgetDelegate* delegate) { |
149 std::map<std::string, std::vector<uint8_t>> properties; | 157 std::map<std::string, std::vector<uint8_t>> properties; |
150 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); | 158 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); |
151 return new NativeWidgetMus(delegate, app_->shell(), NewWindow(properties), | 159 return new NativeWidgetMus(delegate, app_->shell(), NewWindow(properties), |
152 mus::mojom::SURFACE_TYPE_DEFAULT); | 160 mus::mojom::SURFACE_TYPE_DEFAULT); |
153 } | 161 } |
154 | 162 |
155 } // namespace views | 163 } // namespace views |
OLD | NEW |