| 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" |
| 11 #include "components/mus/public/cpp/window_tree_connection.h" | 11 #include "components/mus/public/cpp/window_tree_connection.h" |
| 12 #include "components/mus/public/interfaces/window_tree.mojom.h" | 12 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 13 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 14 #include "mojo/converters/network/network_type_converters.h" | 14 #include "mojo/converters/network/network_type_converters.h" |
| 15 #include "mojo/shell/public/cpp/application_connection.h" | 15 #include "mojo/shell/public/cpp/application_connection.h" |
| 16 #include "mojo/shell/public/cpp/application_impl.h" | 16 #include "mojo/shell/public/cpp/shell.h" |
| 17 #include "ui/views/mus/native_widget_mus.h" | 17 #include "ui/views/mus/native_widget_mus.h" |
| 18 #include "ui/views/mus/screen_mus.h" | 18 #include "ui/views/mus/screen_mus.h" |
| 19 #include "ui/views/views_delegate.h" | 19 #include "ui/views/views_delegate.h" |
| 20 | 20 |
| 21 namespace views { | 21 namespace views { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 using WindowManagerConnectionPtr = | 24 using WindowManagerConnectionPtr = |
| 25 base::ThreadLocalPointer<views::WindowManagerConnection>; | 25 base::ThreadLocalPointer<views::WindowManagerConnection>; |
| 26 | 26 |
| 27 // Env is thread local so that aura may be used on multiple threads. | 27 // Env is thread local so that aura may be used on multiple threads. |
| 28 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = | 28 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = |
| 29 LAZY_INSTANCE_INITIALIZER; | 29 LAZY_INSTANCE_INITIALIZER; |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 void WindowManagerConnection::Create(mojo::ApplicationImpl* app) { | 34 void WindowManagerConnection::Create(mojo::Shell* shell) { |
| 35 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 35 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
| 36 lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(app)); | 36 lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(shell)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 WindowManagerConnection* WindowManagerConnection::Get() { | 40 WindowManagerConnection* WindowManagerConnection::Get() { |
| 41 WindowManagerConnection* connection = lazy_tls_ptr.Pointer()->Get(); | 41 WindowManagerConnection* connection = lazy_tls_ptr.Pointer()->Get(); |
| 42 DCHECK(connection); | 42 DCHECK(connection); |
| 43 return connection; | 43 return connection; |
| 44 } | 44 } |
| 45 | 45 |
| 46 mus::Window* WindowManagerConnection::NewWindow( | 46 mus::Window* WindowManagerConnection::NewWindow( |
| 47 const std::map<std::string, std::vector<uint8_t>>& properties) { | 47 const std::map<std::string, std::vector<uint8_t>>& properties) { |
| 48 return window_tree_connection_->NewTopLevelWindow(&properties); | 48 return window_tree_connection_->NewTopLevelWindow(&properties); |
| 49 } | 49 } |
| 50 | 50 |
| 51 WindowManagerConnection::WindowManagerConnection(mojo::ApplicationImpl* app) | 51 WindowManagerConnection::WindowManagerConnection(mojo::Shell* shell) |
| 52 : app_(app), window_tree_connection_(nullptr) { | 52 : shell_(shell), window_tree_connection_(nullptr) { |
| 53 window_tree_connection_.reset(mus::WindowTreeConnection::Create(this, app_)); | 53 window_tree_connection_.reset( |
| 54 mus::WindowTreeConnection::Create(this, shell_)); |
| 54 | 55 |
| 55 screen_.reset(new ScreenMus(this)); | 56 screen_.reset(new ScreenMus(this)); |
| 56 screen_->Init(app); | 57 screen_->Init(shell); |
| 57 | 58 |
| 58 ViewsDelegate::GetInstance()->set_native_widget_factory( | 59 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 59 base::Bind(&WindowManagerConnection::CreateNativeWidget, | 60 base::Bind(&WindowManagerConnection::CreateNativeWidget, |
| 60 base::Unretained(this))); | 61 base::Unretained(this))); |
| 61 } | 62 } |
| 62 | 63 |
| 63 WindowManagerConnection::~WindowManagerConnection() { | 64 WindowManagerConnection::~WindowManagerConnection() { |
| 64 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), | 65 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), |
| 65 // destroy it while we are still valid. | 66 // destroy it while we are still valid. |
| 66 window_tree_connection_.reset(); | 67 window_tree_connection_.reset(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void WindowManagerConnection::OnEmbed(mus::Window* root) {} | 70 void WindowManagerConnection::OnEmbed(mus::Window* root) {} |
| 70 | 71 |
| 71 void WindowManagerConnection::OnConnectionLost( | 72 void WindowManagerConnection::OnConnectionLost( |
| 72 mus::WindowTreeConnection* connection) {} | 73 mus::WindowTreeConnection* connection) {} |
| 73 | 74 |
| 74 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 75 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 75 if (window_tree_connection_) | 76 if (window_tree_connection_) |
| 76 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); | 77 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); |
| 77 } | 78 } |
| 78 | 79 |
| 79 NativeWidget* WindowManagerConnection::CreateNativeWidget( | 80 NativeWidget* WindowManagerConnection::CreateNativeWidget( |
| 80 const Widget::InitParams& init_params, | 81 const Widget::InitParams& init_params, |
| 81 internal::NativeWidgetDelegate* delegate) { | 82 internal::NativeWidgetDelegate* delegate) { |
| 82 std::map<std::string, std::vector<uint8_t>> properties; | 83 std::map<std::string, std::vector<uint8_t>> properties; |
| 83 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); | 84 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); |
| 84 return new NativeWidgetMus(delegate, app_->shell(), NewWindow(properties), | 85 return new NativeWidgetMus(delegate, shell_, NewWindow(properties), |
| 85 mus::mojom::SurfaceType::DEFAULT); | 86 mus::mojom::SurfaceType::DEFAULT); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace views | 89 } // namespace views |
| OLD | NEW |