OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/ui/password_echo_controller.h" |
| 6 |
| 7 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 8 #include "ash/common/wm_shell.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" |
| 11 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/render_widget_host.h" |
| 13 #include "content/public/browser/render_widget_host_iterator.h" |
| 14 #include "ui/views/views_delegate.h" |
| 15 |
| 16 namespace chromeos { |
| 17 |
| 18 namespace { |
| 19 |
| 20 PasswordEchoController* instance = nullptr; |
| 21 |
| 22 } // namespace |
| 23 |
| 24 // static |
| 25 PasswordEchoController* PasswordEchoController::Get() { |
| 26 return instance; |
| 27 } |
| 28 |
| 29 PasswordEchoController::PasswordEchoController() { |
| 30 DCHECK(!instance); |
| 31 instance = this; |
| 32 |
| 33 ash::WmShell::Get()->AddShellObserver(this); |
| 34 SetEnabled(ash::WmShell::Get() |
| 35 ->maximize_mode_controller() |
| 36 ->IsMaximizeModeWindowManagerEnabled()); |
| 37 } |
| 38 |
| 39 PasswordEchoController::~PasswordEchoController() { |
| 40 DCHECK_EQ(this, instance); |
| 41 instance = nullptr; |
| 42 ash::WmShell::Get()->RemoveShellObserver(this); |
| 43 } |
| 44 |
| 45 void PasswordEchoController::SetEnabled(bool enabled) { |
| 46 if (enabled_ == enabled) |
| 47 return; |
| 48 |
| 49 enabled_ = enabled; |
| 50 |
| 51 UpdateWebkitPreferences(); |
| 52 // Textfield gets the state via ChromeViewsDelegate which will query the |
| 53 // state set here. So nothing needs to done here. |
| 54 } |
| 55 |
| 56 void PasswordEchoController::UpdateWebkitPreferences() { |
| 57 std::unique_ptr<content::RenderWidgetHostIterator> widgets( |
| 58 content::RenderWidgetHost::GetRenderWidgetHosts()); |
| 59 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 60 content::RenderViewHost* rvh = content::RenderViewHost::From(widget); |
| 61 if (!rvh) |
| 62 continue; |
| 63 |
| 64 rvh->OnWebkitPreferencesChanged(); |
| 65 } |
| 66 } |
| 67 |
| 68 void PasswordEchoController::OnMaximizeModeStarted() { |
| 69 SetEnabled(true); |
| 70 } |
| 71 |
| 72 void PasswordEchoController::OnMaximizeModeEnded() { |
| 73 SetEnabled(false); |
| 74 } |
| 75 |
| 76 } // namespace chromeos |
OLD | NEW |