Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Unified Diff: components/keyboard_lock/page_observer.h

Issue 2879033002: Keyboard Lock Host implementation
Patch Set: Remove useless files Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/keyboard_lock/keyboard_lock_host_x11.cc ('k') | components/keyboard_lock/page_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/keyboard_lock/page_observer.h
diff --git a/components/keyboard_lock/page_observer.h b/components/keyboard_lock/page_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..13a754445c7d865241df7d2003401f90b251d410
--- /dev/null
+++ b/components/keyboard_lock/page_observer.h
@@ -0,0 +1,65 @@
+// Copyright 2017 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.
+
+#ifndef COMPONENTS_KEYBOARD_LOCK_PAGE_OBSERVER_H_
+#define COMPONENTS_KEYBOARD_LOCK_PAGE_OBSERVER_H_
+
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/web_contents_observer.h"
+
+namespace content {
+class NotificationDetails;
+class NotificationSource;
+class WebContents;
+} // namespace content
+
+namespace keyboard_lock {
+
+class KeyHookActivator;
+class KeyHookActivatorCollection;
+
+// A PageObserver instance keeps a reference of a KeyHookActivator (usually a
+// KeyHookActivatorThreadProxy wrapped KeyHookStateKeeper instance) and a
+// WebContents. Once an interesting event, e.g. page taking or losing focus,
+// entering or exiting fullscreen, PageObserver calls
+// KeyHookActivator::Activate() or KeyHookActivator::Deactivate() functions.
+// A PageObserver instance has the same lifetime with its WebContents, it
+// deletes itself once WebContentsObserver::WebContentsDestroyed() is called.
+// This class must be instantiated in UI thread to ensure correct signals can be
+// received.
+class PageObserver final
+ : public content::NotificationObserver,
+ public content::WebContentsObserver {
+ public:
+ // |collection| must outlive current instance.
+ static void Observe(content::WebContents* web_contents,
+ KeyHookActivatorCollection* collection);
+
+ private:
+ PageObserver(content::WebContents* web_contents,
+ KeyHookActivatorCollection* collection);
+ ~PageObserver() override;
+
+ // NotificationObserver implementations
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // WebContentsObserver implementations
+ void OnWebContentsLostFocus() override;
+ void OnWebContentsFocused() override;
+ void WebContentsDestroyed() override;
+
+ void TriggerActivator();
+
+ bool is_fullscreen_ = false;
+ bool is_focused_ = false;
+ content::NotificationRegistrar registrar_;
+ KeyHookActivatorCollection* const collection_;
+};
+
+} // namespace keyboard_lock
+
+#endif // COMPONENTS_KEYBOARD_LOCK_PAGE_OBSERVER_H_
« no previous file with comments | « components/keyboard_lock/keyboard_lock_host_x11.cc ('k') | components/keyboard_lock/page_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698