Index: chrome/browser/chromeos/ui/password_echo_controller.cc |
diff --git a/chrome/browser/chromeos/ui/password_echo_controller.cc b/chrome/browser/chromeos/ui/password_echo_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..441305675f93b14df6d6e0e05d2822a90c9580d1 |
--- /dev/null |
+++ b/chrome/browser/chromeos/ui/password_echo_controller.cc |
@@ -0,0 +1,76 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/chromeos/ui/password_echo_controller.h" |
+ |
+#include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
+#include "ash/common/wm_shell.h" |
+#include "base/logging.h" |
+#include "base/time/time.h" |
+#include "content/public/browser/render_view_host.h" |
+#include "content/public/browser/render_widget_host.h" |
+#include "content/public/browser/render_widget_host_iterator.h" |
+#include "ui/views/views_delegate.h" |
+ |
+namespace chromeos { |
+ |
+namespace { |
+ |
+PasswordEchoController* instance = nullptr; |
+ |
+} // namespace |
+ |
+// static |
+PasswordEchoController* PasswordEchoController::Get() { |
+ return instance; |
+} |
+ |
+PasswordEchoController::PasswordEchoController() { |
+ DCHECK(!instance); |
+ instance = this; |
+ |
+ ash::WmShell::Get()->AddShellObserver(this); |
+ SetEnabled(ash::WmShell::Get() |
+ ->maximize_mode_controller() |
+ ->IsMaximizeModeWindowManagerEnabled()); |
+} |
+ |
+PasswordEchoController::~PasswordEchoController() { |
+ DCHECK_EQ(this, instance); |
+ instance = nullptr; |
+ ash::WmShell::Get()->RemoveShellObserver(this); |
+} |
+ |
+void PasswordEchoController::SetEnabled(bool enabled) { |
+ if (enabled_ == enabled) |
+ return; |
+ |
+ enabled_ = enabled; |
+ |
+ UpdateWebkitPreferences(); |
+ // Textfield gets the state via ChromeViewsDelegate which will query the |
+ // state set here. So nothing needs to done here. |
+} |
+ |
+void PasswordEchoController::UpdateWebkitPreferences() { |
+ std::unique_ptr<content::RenderWidgetHostIterator> widgets( |
+ content::RenderWidgetHost::GetRenderWidgetHosts()); |
+ while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
+ content::RenderViewHost* rvh = content::RenderViewHost::From(widget); |
+ if (!rvh) |
+ continue; |
+ |
+ rvh->OnWebkitPreferencesChanged(); |
+ } |
+} |
+ |
+void PasswordEchoController::OnMaximizeModeStarted() { |
+ SetEnabled(true); |
+} |
+ |
+void PasswordEchoController::OnMaximizeModeEnded() { |
+ SetEnabled(false); |
+} |
+ |
+} // namespace chromeos |