summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_accessibility_api.h
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-30 01:18:56 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-30 01:18:56 +0000
commit5cbe1e21980f42927d7d1c11cc860131be266e7e (patch)
tree3b52e15044336cb89e3004214b4714e6148e5ea9 /chrome/browser/extensions/extension_accessibility_api.h
parent7a12518454d36fb4ac79431f56106b38cd2482ab (diff)
downloadchromium_src-5cbe1e21980f42927d7d1c11cc860131be266e7e.zip
chromium_src-5cbe1e21980f42927d7d1c11cc860131be266e7e.tar.gz
chromium_src-5cbe1e21980f42927d7d1c11cc860131be266e7e.tar.bz2
Add an accessibility API for events raised outside of the web content.
BUG=none TEST=none patch by Dominic Mazzoni <dmazzoni [at] google> review url: http://codereview.chromium.org/402099/show git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_accessibility_api.h')
-rw-r--r--chrome/browser/extensions/extension_accessibility_api.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_accessibility_api.h b/chrome/browser/extensions/extension_accessibility_api.h
new file mode 100644
index 0000000..afae039
--- /dev/null
+++ b/chrome/browser/extensions/extension_accessibility_api.h
@@ -0,0 +1,96 @@
+// Copyright (c) 2010 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_ACCESSIBILITY_API_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACCESSIBILITY_API_H_
+
+#include <string>
+#include <vector>
+
+#include "base/singleton.h"
+#include "chrome/browser/extensions/extension_function.h"
+#include "chrome/common/accessibility_events.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_registrar.h"
+
+// Observes the profile and routes accessibility notifications as events
+// to the extension system.
+class ExtensionAccessibilityEventRouter : public NotificationObserver {
+ public:
+ // Single instance of the event router.
+ static ExtensionAccessibilityEventRouter* GetInstance();
+
+ // Safe to call multiple times.
+ void ObserveProfile(Profile* profile);
+
+ // Get the dict representing the last control that received an
+ // OnControlFocus event.
+ DictionaryValue* last_focused_control_dict() {
+ return &last_focused_control_dict_;
+ }
+
+ // Accessibility support is disabled until an extension expicitly enables
+ // it, so that this extension api has no impact on Chrome's performance
+ // otherwise. These methods handle enabling, disabling, querying the
+ // status, and installing callbacks to execute when accessibility support
+ // is enabled or disabled.
+ void SetAccessibilityEnabled(bool enabled);
+ bool IsAccessibilityEnabled() const;
+ typedef Callback0::Type Callback;
+ void AddOnEnabledListener(Callback* callback);
+ void AddOnDisabledListener(Callback* callback);
+
+ private:
+ friend struct DefaultSingletonTraits<ExtensionAccessibilityEventRouter>;
+
+ ExtensionAccessibilityEventRouter()
+ : enabled_(false) {}
+ virtual ~ExtensionAccessibilityEventRouter() {}
+
+ // NotificationObserver::Observe.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ void OnWindowOpened(const AccessibilityWindowInfo* details);
+ void OnWindowClosed(const AccessibilityWindowInfo* details);
+ void OnControlFocused(const AccessibilityControlInfo* details);
+ void OnControlAction(const AccessibilityControlInfo* details);
+ void OnTextChanged(const AccessibilityControlInfo* details);
+
+ void DispatchEvent(Profile* profile,
+ const char* event_name,
+ const std::string& json_args);
+
+ // Used for tracking registrations to history service notifications.
+ NotificationRegistrar registrar_;
+
+ DictionaryValue last_focused_control_dict_;
+
+ bool enabled_;
+ std::vector<Callback*> on_enabled_listeners_;
+ std::vector<Callback*> on_disabled_listeners_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionAccessibilityEventRouter);
+};
+
+// API function that enables or disables accessibility support. Event
+// listeners are only installed when accessibility support is enabled, to
+// minimize the impact.
+class SetAccessibilityEnabledFunction : public SyncExtensionFunction {
+ virtual ~SetAccessibilityEnabledFunction() {}
+ virtual bool RunImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME(
+ "experimental.accessibility.setAccessibilityEnabled")
+};
+
+// API function that returns the most recent focused control.
+class GetFocusedControlFunction : public SyncExtensionFunction {
+ virtual ~GetFocusedControlFunction() {}
+ virtual bool RunImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME(
+ "experimental.accessibility.getFocusedControl")
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACCESSIBILITY_API_H_