| 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/connection.h" | 15 #include "mojo/shell/public/cpp/connection.h" |
| 16 #include "mojo/shell/public/cpp/shell.h" | 16 #include "mojo/shell/public/cpp/connector.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::Shell* shell) { | 34 void WindowManagerConnection::Create(mojo::Connector* connector) { |
| 35 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 35 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
| 36 lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(shell)); | 36 lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(connector)); |
| 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 // static | 46 // static |
| 47 void WindowManagerConnection::Reset() { | 47 void WindowManagerConnection::Reset() { |
| 48 delete Get(); | 48 delete Get(); |
| 49 lazy_tls_ptr.Pointer()->Set(nullptr); | 49 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 50 } | 50 } |
| 51 | 51 |
| 52 mus::Window* WindowManagerConnection::NewWindow( | 52 mus::Window* WindowManagerConnection::NewWindow( |
| 53 const std::map<std::string, std::vector<uint8_t>>& properties) { | 53 const std::map<std::string, std::vector<uint8_t>>& properties) { |
| 54 return window_tree_connection_->NewTopLevelWindow(&properties); | 54 return window_tree_connection_->NewTopLevelWindow(&properties); |
| 55 } | 55 } |
| 56 | 56 |
| 57 NativeWidget* WindowManagerConnection::CreateNativeWidgetMus( | 57 NativeWidget* WindowManagerConnection::CreateNativeWidgetMus( |
| 58 const std::map<std::string, std::vector<uint8_t>>& props, | 58 const std::map<std::string, std::vector<uint8_t>>& props, |
| 59 const Widget::InitParams& init_params, | 59 const Widget::InitParams& init_params, |
| 60 internal::NativeWidgetDelegate* delegate) { | 60 internal::NativeWidgetDelegate* delegate) { |
| 61 std::map<std::string, std::vector<uint8_t>> properties = props; | 61 std::map<std::string, std::vector<uint8_t>> properties = props; |
| 62 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); | 62 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); |
| 63 return new NativeWidgetMus(delegate, shell_, NewWindow(properties), | 63 return new NativeWidgetMus(delegate, connector_, NewWindow(properties), |
| 64 mus::mojom::SurfaceType::DEFAULT); | 64 mus::mojom::SurfaceType::DEFAULT); |
| 65 } | 65 } |
| 66 | 66 |
| 67 WindowManagerConnection::WindowManagerConnection(mojo::Shell* shell) | 67 WindowManagerConnection::WindowManagerConnection(mojo::Connector* connector) |
| 68 : shell_(shell), window_tree_connection_(nullptr) { | 68 : connector_(connector), window_tree_connection_(nullptr) { |
| 69 window_tree_connection_.reset( | 69 window_tree_connection_.reset( |
| 70 mus::WindowTreeConnection::Create(this, shell_)); | 70 mus::WindowTreeConnection::Create(this, connector_)); |
| 71 | 71 |
| 72 screen_.reset(new ScreenMus(this)); | 72 screen_.reset(new ScreenMus(this)); |
| 73 screen_->Init(shell); | 73 screen_->Init(connector); |
| 74 | 74 |
| 75 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 75 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
| 76 &WindowManagerConnection::CreateNativeWidgetMus, | 76 &WindowManagerConnection::CreateNativeWidgetMus, |
| 77 base::Unretained(this), | 77 base::Unretained(this), |
| 78 std::map<std::string, std::vector<uint8_t>>())); | 78 std::map<std::string, std::vector<uint8_t>>())); |
| 79 } | 79 } |
| 80 | 80 |
| 81 WindowManagerConnection::~WindowManagerConnection() { | 81 WindowManagerConnection::~WindowManagerConnection() { |
| 82 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), | 82 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), |
| 83 // destroy it while we are still valid. | 83 // destroy it while we are still valid. |
| 84 window_tree_connection_.reset(); | 84 window_tree_connection_.reset(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void WindowManagerConnection::OnEmbed(mus::Window* root) {} | 87 void WindowManagerConnection::OnEmbed(mus::Window* root) {} |
| 88 | 88 |
| 89 void WindowManagerConnection::OnConnectionLost( | 89 void WindowManagerConnection::OnConnectionLost( |
| 90 mus::WindowTreeConnection* connection) {} | 90 mus::WindowTreeConnection* connection) {} |
| 91 | 91 |
| 92 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 92 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 93 if (window_tree_connection_) | 93 if (window_tree_connection_) |
| 94 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); | 94 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace views | 97 } // namespace views |
| OLD | NEW |