Add experimental extensions APIs to notify about wakeup and screen unlock

BUG=chromium-os:20009
TEST=None


Review URL: http://codereview.chromium.org/8558014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111076 0039d316-1c4b-4281-b951-d872f2087c98
parent 61176efe
......@@ -213,6 +213,20 @@ void AccessibilityVolumeInfo::SerializeToDict(DictionaryValue *dict) const {
dict->SetBoolean(keys::kIsVolumeMutedKey, is_muted_);
}
ScreenUnlockedEventInfo::ScreenUnlockedEventInfo(Profile* profile)
: AccessibilityEventInfo(profile) {
}
void ScreenUnlockedEventInfo::SerializeToDict(DictionaryValue *dict) const {
}
WokeUpEventInfo::WokeUpEventInfo(Profile* profile)
: AccessibilityEventInfo(profile) {
}
void WokeUpEventInfo::SerializeToDict(DictionaryValue *dict) const {
}
AccessibilityMenuInfo::AccessibilityMenuInfo(Profile* profile,
const std::string& menu_name)
: AccessibilityControlInfo(profile, menu_name) {
......
......@@ -285,6 +285,20 @@ class AccessibilityVolumeInfo : public AccessibilityEventInfo {
bool is_muted_;
};
// Screen unlock event information; this class is used by onScreenUnlocked.
class ScreenUnlockedEventInfo : public AccessibilityEventInfo {
public:
ScreenUnlockedEventInfo(Profile* profile);
virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE;
};
// Wake up event information; this class is used by onWokeUp.
class WokeUpEventInfo : public AccessibilityEventInfo {
public:
WokeUpEventInfo(Profile* profile);
virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE;
};
// Accessibility information about a menu item; this class is used by
// onControlFocused event listeners.
class AccessibilityMenuItemInfo : public AccessibilityControlInfo {
......
// Copyright (c) 2011 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/accessibility/system_event_observer.h"
#include "base/logging.h"
#include "chrome/browser/accessibility_events.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_notification_types.h"
namespace chromeos {
namespace accessibility {
namespace {
SystemEventObserver* g_system_event_observer = NULL;
}
SystemEventObserver::SystemEventObserver() {
CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this);
CrosLibrary::Get()->GetScreenLockLibrary()->AddObserver(this);
}
SystemEventObserver::~SystemEventObserver() {
CrosLibrary::Get()->GetScreenLockLibrary()->RemoveObserver(this);
CrosLibrary::Get()->GetPowerLibrary()->RemoveObserver(this);
}
void SystemEventObserver::SystemResumed() {
Profile* profile = ProfileManager::GetDefaultProfile();
WokeUpEventInfo info(profile);
SendAccessibilityNotification(
chrome::NOTIFICATION_ACCESSIBILITY_WOKE_UP, &info);
}
void SystemEventObserver::LockScreen(ScreenLockLibrary* screen_lock_library) {
}
void SystemEventObserver::UnlockScreen(ScreenLockLibrary* screen_lock_library) {
Profile* profile = ProfileManager::GetDefaultProfile();
ScreenUnlockedEventInfo info(profile);
SendAccessibilityNotification(
chrome::NOTIFICATION_ACCESSIBILITY_SCREEN_UNLOCKED, &info);
}
void SystemEventObserver::UnlockScreenFailed(
ScreenLockLibrary* screen_lock_library) {
}
// static
void SystemEventObserver::Initialize() {
DCHECK(!g_system_event_observer);
g_system_event_observer = new SystemEventObserver();
VLOG(1) << "SystemEventObserver initialized";
}
// static
SystemEventObserver* SystemEventObserver::GetInstance() {
return g_system_event_observer;
}
// static
void SystemEventObserver::Shutdown() {
DCHECK(g_system_event_observer);
delete g_system_event_observer;
g_system_event_observer = NULL;
VLOG(1) << "SystemEventObserver Shutdown completed";
}
} // namespace accessibility
} // namespace chromeos
// Copyright (c) 2011 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_CHROMEOS_ACCESSIBILITY_SYSTEM_EVENT_OBSERVER_H_
#define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SYSTEM_EVENT_OBSERVER_H_
#pragma once
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/cros/screen_lock_library.h"
namespace chromeos {
namespace accessibility {
// A singleton class to observe system events like wake up from sleep and
// screen unlock.
class SystemEventObserver : public PowerLibrary::Observer,
public ScreenLockLibrary::Observer {
public:
virtual ~SystemEventObserver();
// PowerLibrary::Observer override.
virtual void SystemResumed() OVERRIDE;
// ScreenLockLibrary::Observer override.
virtual void LockScreen(ScreenLockLibrary* screen_lock_library) OVERRIDE;
// ScreenLockLibrary::Observer override.
virtual void UnlockScreen(ScreenLockLibrary* screen_lock_library) OVERRIDE;
// ScreenLockLibrary::Observer override.
virtual void UnlockScreenFailed(ScreenLockLibrary* screen_lock_library)
OVERRIDE;
// Creates the global SystemEventObserver instance.
static void Initialize();
// Returns a pointer to the global SystemEventObserver instance.
// Initialize() should already have been called.
static SystemEventObserver* GetInstance();
// Destroys the global SystemEventObserver Instance.
static void Shutdown();
private:
SystemEventObserver();
DISALLOW_COPY_AND_ASSIGN(SystemEventObserver);
};
} // namespace accessibility
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SYSTEM_EVENT_OBSERVER_H_
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/message_loop.h"
#include "chrome/browser/chromeos/accessibility/system_event_observer.h"
#include "chrome/browser/chromeos/bluetooth/bluetooth_manager.h"
#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/brightness_observer.h"
......@@ -93,6 +94,8 @@ ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() {
chromeos::DBusThreadManager::Shutdown();
chromeos::accessibility::SystemEventObserver::Shutdown();
if (!parameters().ui_task && chromeos::CrosLibrary::Get())
chromeos::CrosLibrary::Shutdown();
......@@ -126,6 +129,8 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopStart() {
// implementation.
net::NetworkChangeNotifier::SetFactory(
new chromeos::CrosNetworkChangeNotifierFactory());
chromeos::accessibility::SystemEventObserver::Initialize();
}
void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() {
......
......@@ -65,6 +65,12 @@ ExtensionAccessibilityEventRouter::ExtensionAccessibilityEventRouter()
registrar_.Add(this,
chrome::NOTIFICATION_ACCESSIBILITY_VOLUME_CHANGED,
content::NotificationService::AllSources());
registrar_.Add(this,
chrome::NOTIFICATION_ACCESSIBILITY_SCREEN_UNLOCKED,
content::NotificationService::AllSources());
registrar_.Add(this,
chrome::NOTIFICATION_ACCESSIBILITY_WOKE_UP,
content::NotificationService::AllSources());
}
ExtensionAccessibilityEventRouter::~ExtensionAccessibilityEventRouter() {
......@@ -107,6 +113,14 @@ void ExtensionAccessibilityEventRouter::Observe(
OnVolumeChanged(
content::Details<const AccessibilityVolumeInfo>(details).ptr());
break;
case chrome::NOTIFICATION_ACCESSIBILITY_SCREEN_UNLOCKED:
OnScreenUnlocked(
content::Details<const ScreenUnlockedEventInfo>(details).ptr());
break;
case chrome::NOTIFICATION_ACCESSIBILITY_WOKE_UP:
OnWokeUp(
content::Details<const WokeUpEventInfo>(details).ptr());
break;
default:
NOTREACHED();
}
......@@ -170,6 +184,17 @@ void ExtensionAccessibilityEventRouter::OnVolumeChanged(
DispatchEvent(info->profile(), keys::kOnVolumeChanged, json_args);
}
void ExtensionAccessibilityEventRouter::OnScreenUnlocked(
const ScreenUnlockedEventInfo* info) {
std::string json_args = ControlInfoToJsonString(info);
DispatchEvent(info->profile(), keys::kOnScreenUnlocked, json_args);
}
void ExtensionAccessibilityEventRouter::OnWokeUp(const WokeUpEventInfo* info) {
std::string json_args = ControlInfoToJsonString(info);
DispatchEvent(info->profile(), keys::kOnWokeUp, json_args);
}
void ExtensionAccessibilityEventRouter::DispatchEvent(
Profile* profile,
const char* event_name,
......
......@@ -55,6 +55,8 @@ class ExtensionAccessibilityEventRouter : public content::NotificationObserver {
void OnMenuOpened(const AccessibilityMenuInfo* details);
void OnMenuClosed(const AccessibilityMenuInfo* details);
void OnVolumeChanged(const AccessibilityVolumeInfo* details);
void OnScreenUnlocked(const ScreenUnlockedEventInfo* details);
void OnWokeUp(const WokeUpEventInfo* details);
void DispatchEvent(Profile* profile,
const char* event_name,
......
......@@ -30,6 +30,8 @@ const char kOnTextChanged[] = "experimental.accessibility.onTextChanged";
const char kOnMenuOpened[] = "experimental.accessibility.onMenuOpened";
const char kOnMenuClosed[] = "experimental.accessibility.onMenuClosed";
const char kOnVolumeChanged[] = "experimental.accessibility.onVolumeChanged";
const char kOnScreenUnlocked[] = "experimental.accessibility.onScreenUnlocked";
const char kOnWokeUp[] = "experimental.accessibility.onWokeUp";
// Types of controls that can receive accessibility events.
const char kTypeButton[] = "button";
......
......@@ -34,6 +34,8 @@ extern const char kOnTextChanged[];
extern const char kOnMenuOpened[];
extern const char kOnMenuClosed[];
extern const char kOnVolumeChanged[];
extern const char kOnScreenUnlocked[];
extern const char kOnWokeUp[];
// Types of controls that can receive accessibility events
extern const char kTypeButton[];
......
......@@ -375,6 +375,8 @@
'browser/chrome_quota_permission_context.h',
'browser/chromeos/accessibility_util.cc',
'browser/chromeos/accessibility_util.h',
'browser/chromeos/accessibility/system_event_observer.cc',
'browser/chromeos/accessibility/system_event_observer.h',
'browser/chromeos/audio_handler.cc',
'browser/chromeos/audio_handler.h',
'browser/chromeos/audio_mixer.h',
......
......@@ -658,6 +658,16 @@ enum NotificationType {
// Details will be an AccessibilityVolumeInfo.
NOTIFICATION_ACCESSIBILITY_VOLUME_CHANGED,
// Notification that the screen is unlocked, for propagating to an
// accessibility extension.
// Details will be an AccessibilityEmptyEventInfo.
NOTIFICATION_ACCESSIBILITY_SCREEN_UNLOCKED,
// Notification that the system woke up from sleep, for propagating to an
// accessibility extension.
// Details will be an AccessibilityEmptyEventInfo.
NOTIFICATION_ACCESSIBILITY_WOKE_UP,
// Content Settings --------------------------------------------------------
// Sent when content settings change. The source is a HostContentSettings
......
......@@ -509,6 +509,18 @@
"description": "Information about the current state of the system volume control, including whether it is muted."
}
]
},
{
"name": "onScreenUnlocked",
"type": "function",
"description": "Fired when the screen is unlocked.",
"parameters": []
},
{
"name": "onWokeUp",
"type": "function",
"description": "Fired when the device wakes up from sleep.",
"parameters": []
}
]
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment