OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/screenlock/screenlock.h" | 5 #include "mash/screenlock/screenlock.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/mus/public/cpp/property_type_converters.h" | 9 #include "components/mus/public/cpp/property_type_converters.h" |
10 #include "mash/shell/public/interfaces/shell.mojom.h" | 10 #include "mash/shell/public/interfaces/shell.mojom.h" |
11 #include "mash/wm/public/interfaces/container.mojom.h" | 11 #include "mash/wm/public/interfaces/container.mojom.h" |
12 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
13 #include "mojo/shell/public/cpp/application_impl.h" | 13 #include "mojo/shell/public/cpp/shell.h" |
14 #include "ui/views/background.h" | 14 #include "ui/views/background.h" |
15 #include "ui/views/controls/button/label_button.h" | 15 #include "ui/views/controls/button/label_button.h" |
16 #include "ui/views/mus/aura_init.h" | 16 #include "ui/views/mus/aura_init.h" |
17 #include "ui/views/mus/native_widget_mus.h" | 17 #include "ui/views/mus/native_widget_mus.h" |
18 #include "ui/views/mus/window_manager_connection.h" | 18 #include "ui/views/mus/window_manager_connection.h" |
19 #include "ui/views/widget/widget_delegate.h" | 19 #include "ui/views/widget/widget_delegate.h" |
20 | 20 |
21 namespace mash { | 21 namespace mash { |
22 namespace screenlock { | 22 namespace screenlock { |
23 namespace { | 23 namespace { |
24 | 24 |
25 class ScreenlockView : public views::WidgetDelegateView, | 25 class ScreenlockView : public views::WidgetDelegateView, |
26 public views::ButtonListener { | 26 public views::ButtonListener { |
27 public: | 27 public: |
28 explicit ScreenlockView(mojo::ApplicationImpl* app) | 28 explicit ScreenlockView(mojo::Shell* shell) |
29 : app_(app), | 29 : shell_(shell), |
30 unlock_button_( | 30 unlock_button_( |
31 new views::LabelButton(this, base::ASCIIToUTF16("Unlock"))) { | 31 new views::LabelButton(this, base::ASCIIToUTF16("Unlock"))) { |
32 set_background(views::Background::CreateSolidBackground(SK_ColorYELLOW)); | 32 set_background(views::Background::CreateSolidBackground(SK_ColorYELLOW)); |
33 unlock_button_->SetStyle(views::Button::STYLE_BUTTON); | 33 unlock_button_->SetStyle(views::Button::STYLE_BUTTON); |
34 AddChildView(unlock_button_); | 34 AddChildView(unlock_button_); |
35 } | 35 } |
36 ~ScreenlockView() override {} | 36 ~ScreenlockView() override {} |
37 | 37 |
38 private: | 38 private: |
39 // Overridden from views::WidgetDelegate: | 39 // Overridden from views::WidgetDelegate: |
(...skipping 13 matching lines...) Expand all Loading... |
53 | 53 |
54 unlock_button_->SetBounds(bounds.width() - ps.width(), | 54 unlock_button_->SetBounds(bounds.width() - ps.width(), |
55 bounds.bottom() + 10, | 55 bounds.bottom() + 10, |
56 ps.width(), ps.height()); | 56 ps.width(), ps.height()); |
57 } | 57 } |
58 | 58 |
59 // Overridden from views::ButtonListener: | 59 // Overridden from views::ButtonListener: |
60 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 60 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
61 DCHECK_EQ(sender, unlock_button_); | 61 DCHECK_EQ(sender, unlock_button_); |
62 mash::shell::mojom::ShellPtr shell; | 62 mash::shell::mojom::ShellPtr shell; |
63 app_->ConnectToService("mojo:mash_shell", &shell); | 63 shell_->ConnectToService("mojo:mash_shell", &shell); |
64 shell->UnlockScreen(); | 64 shell->UnlockScreen(); |
65 } | 65 } |
66 | 66 |
67 mojo::ApplicationImpl* app_; | 67 mojo::Shell* shell_; |
68 views::LabelButton* unlock_button_; | 68 views::LabelButton* unlock_button_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(ScreenlockView); | 70 DISALLOW_COPY_AND_ASSIGN(ScreenlockView); |
71 }; | 71 }; |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 Screenlock::Screenlock() : app_(nullptr) {} | 75 Screenlock::Screenlock() : shell_(nullptr) {} |
76 Screenlock::~Screenlock() {} | 76 Screenlock::~Screenlock() {} |
77 | 77 |
78 void Screenlock::Initialize(mojo::ApplicationImpl* app) { | 78 void Screenlock::Initialize(mojo::Shell* shell, const std::string& url, |
79 app_ = app; | 79 uint32_t id) { |
80 tracing_.Initialize(app); | 80 shell_ = shell; |
| 81 tracing_.Initialize(shell, url); |
81 | 82 |
82 mash::shell::mojom::ShellPtr shell; | 83 mash::shell::mojom::ShellPtr mash_shell; |
83 app_->ConnectToService("mojo:mash_shell", &shell); | 84 shell_->ConnectToService("mojo:mash_shell", &mash_shell); |
84 shell->AddScreenlockStateListener(bindings_.CreateInterfacePtrAndBind(this)); | 85 mash_shell->AddScreenlockStateListener( |
| 86 bindings_.CreateInterfacePtrAndBind(this)); |
85 | 87 |
86 aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak")); | 88 aura_init_.reset(new views::AuraInit(shell, "views_mus_resources.pak")); |
87 views::WindowManagerConnection::Create(app); | 89 views::WindowManagerConnection::Create(shell); |
88 | 90 |
89 views::Widget* widget = new views::Widget; | 91 views::Widget* widget = new views::Widget; |
90 views::Widget::InitParams params( | 92 views::Widget::InitParams params( |
91 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 93 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
92 params.delegate = new ScreenlockView(app); | 94 params.delegate = new ScreenlockView(shell); |
93 | 95 |
94 std::map<std::string, std::vector<uint8_t>> properties; | 96 std::map<std::string, std::vector<uint8_t>> properties; |
95 properties[mash::wm::mojom::kWindowContainer_Property] = | 97 properties[mash::wm::mojom::kWindowContainer_Property] = |
96 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert( | 98 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert( |
97 static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS)); | 99 static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS)); |
98 mus::Window* window = | 100 mus::Window* window = |
99 views::WindowManagerConnection::Get()->NewWindow(properties); | 101 views::WindowManagerConnection::Get()->NewWindow(properties); |
100 params.native_widget = new views::NativeWidgetMus( | 102 params.native_widget = new views::NativeWidgetMus( |
101 widget, app->shell(), window, mus::mojom::SurfaceType::DEFAULT); | 103 widget, shell, window, mus::mojom::SurfaceType::DEFAULT); |
102 widget->Init(params); | 104 widget->Init(params); |
103 widget->Show(); | 105 widget->Show(); |
104 } | 106 } |
105 | 107 |
106 void Screenlock::ScreenlockStateChanged(bool screen_locked) { | 108 void Screenlock::ScreenlockStateChanged(bool screen_locked) { |
107 if (!screen_locked) | 109 if (!screen_locked) |
108 app_->Quit(); | 110 shell_->Quit(); |
109 } | 111 } |
110 | 112 |
111 } // namespace screenlock | 113 } // namespace screenlock |
112 } // namespace main | 114 } // namespace main |
OLD | NEW |