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 "ash/system/chromeos/multi_user/user_switch_util.h" | 5 #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" |
6 | 6 |
7 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" | 7 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/strings/grit/ash_strings.h" | |
9 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
10 #include "grit/ash_strings.h" | |
11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
14 #include "ui/views/layout/grid_layout.h" | 14 #include "ui/views/layout/grid_layout.h" |
15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
16 #include "ui/views/window/dialog_delegate.h" | 16 #include "ui/views/window/dialog_delegate.h" |
17 | 17 |
18 namespace ash { | |
19 | |
20 namespace { | 18 namespace { |
21 | 19 |
22 // Default width/height of the dialog. | 20 // Default width/height of the dialog. |
23 const int kDefaultWidth = 500; | 21 const int kDefaultWidth = 500; |
24 const int kDefaultHeight = 150; | 22 const int kDefaultHeight = 150; |
25 | 23 |
26 const int kPaddingToMessage = 30; | 24 const int kPaddingToMessage = 30; |
27 const int kInset = 40; | 25 const int kInset = 40; |
28 const int kTopInset = 10; | 26 const int kTopInset = 10; |
29 | 27 |
30 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
31 // Dialog for multi-profiles desktop casting warning. | 29 // Dialog for multi-profiles desktop casting warning. |
32 class DesktopCastingWarningView : public views::DialogDelegateView { | 30 class DesktopCastingWarningView : public views::DialogDelegateView { |
33 public: | 31 public: |
34 DesktopCastingWarningView(base::Callback<void()> on_accept); | 32 explicit DesktopCastingWarningView(base::Callback<void()> on_accept); |
James Cook
2016/07/13 19:26:06
Thanks for fixing. (Out of curiosity, do you use "
msw
2016/07/13 19:31:52
Nope; just saw this lint error in presubmit.
| |
35 ~DesktopCastingWarningView() override; | 33 ~DesktopCastingWarningView() override; |
36 | 34 |
37 static void ShowDialog(const base::Callback<void()> on_accept); | 35 static void ShowDialog(const base::Callback<void()> on_accept); |
38 | 36 |
39 // views::DialogDelegate overrides. | 37 // views::DialogDelegate overrides. |
40 bool Accept() override; | 38 bool Accept() override; |
41 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 39 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
42 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | 40 bool IsDialogButtonEnabled(ui::DialogButton button) const override; |
43 int GetDefaultDialogButton() const override; | 41 int GetDefaultDialogButton() const override; |
44 | 42 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 views::DialogDelegate::CreateDialogWidget( | 81 views::DialogDelegate::CreateDialogWidget( |
84 dialog_view, ash::Shell::GetTargetRootWindow(), NULL); | 82 dialog_view, ash::Shell::GetTargetRootWindow(), NULL); |
85 dialog_view->InitDialog(); | 83 dialog_view->InitDialog(); |
86 views::Widget* widget = dialog_view->GetWidget(); | 84 views::Widget* widget = dialog_view->GetWidget(); |
87 DCHECK(widget); | 85 DCHECK(widget); |
88 widget->Show(); | 86 widget->Show(); |
89 } | 87 } |
90 | 88 |
91 bool DesktopCastingWarningView::Accept() { | 89 bool DesktopCastingWarningView::Accept() { |
92 // Stop screen sharing and capturing. | 90 // Stop screen sharing and capturing. |
93 SystemTray* system_tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 91 ash::SystemTray* system_tray = |
92 ash::Shell::GetInstance()->GetPrimarySystemTray(); | |
94 if (system_tray->GetScreenShareItem()->is_started()) | 93 if (system_tray->GetScreenShareItem()->is_started()) |
95 system_tray->GetScreenShareItem()->Stop(); | 94 system_tray->GetScreenShareItem()->Stop(); |
96 if (system_tray->GetScreenCaptureItem()->is_started()) | 95 if (system_tray->GetScreenCaptureItem()->is_started()) |
97 system_tray->GetScreenCaptureItem()->Stop(); | 96 system_tray->GetScreenCaptureItem()->Stop(); |
98 | 97 |
99 on_switch_.Run(); | 98 on_switch_.Run(); |
100 return true; | 99 return true; |
101 } | 100 } |
102 | 101 |
103 base::string16 DesktopCastingWarningView::GetDialogButtonLabel( | 102 base::string16 DesktopCastingWarningView::GetDialogButtonLabel( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 // Factory function. | 167 // Factory function. |
169 | 168 |
170 void TrySwitchingActiveUser(const base::Callback<void()> on_switch) { | 169 void TrySwitchingActiveUser(const base::Callback<void()> on_switch) { |
171 // Some unit tests do not have a shell. In that case simply execute. | 170 // Some unit tests do not have a shell. In that case simply execute. |
172 if (!ash::Shell::HasInstance()) { | 171 if (!ash::Shell::HasInstance()) { |
173 on_switch.Run(); | 172 on_switch.Run(); |
174 return; | 173 return; |
175 } | 174 } |
176 // If neither screen sharing nor capturing is going on we can immediately | 175 // If neither screen sharing nor capturing is going on we can immediately |
177 // switch users. | 176 // switch users. |
178 SystemTray* system_tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 177 ash::SystemTray* system_tray = |
178 ash::Shell::GetInstance()->GetPrimarySystemTray(); | |
179 if (!system_tray->GetScreenShareItem()->is_started() && | 179 if (!system_tray->GetScreenShareItem()->is_started() && |
180 !system_tray->GetScreenCaptureItem()->is_started()) { | 180 !system_tray->GetScreenCaptureItem()->is_started()) { |
181 on_switch.Run(); | 181 on_switch.Run(); |
182 return; | 182 return; |
183 } | 183 } |
184 DesktopCastingWarningView::ShowDialog(on_switch); | 184 DesktopCastingWarningView::ShowDialog(on_switch); |
185 } | 185 } |
186 | 186 |
187 bool TestAndTerminateDesktopCastingWarningForTest(bool accept) { | 187 bool TestAndTerminateDesktopCastingWarningForTest(bool accept) { |
188 if (!instance_for_test) | 188 if (!instance_for_test) |
189 return false; | 189 return false; |
190 if (accept) | 190 if (accept) |
191 instance_for_test->Accept(); | 191 instance_for_test->Accept(); |
192 delete instance_for_test->GetWidget()->GetNativeWindow(); | 192 delete instance_for_test->GetWidget()->GetNativeWindow(); |
193 CHECK(!instance_for_test); | 193 CHECK(!instance_for_test); |
194 return true; | 194 return true; |
195 } | 195 } |
196 | |
197 } // namespace chromeos | |
OLD | NEW |