зеркало из https://github.com/mozilla/pjs.git
Bug 738530 - Move PowerManager from shell.js to gaia. r=vingtetun
This commit is contained in:
Родитель
5a951fc862
Коммит
7d7ca5399c
|
@ -23,10 +23,6 @@ XPCOMUtils.defineLazyServiceGetter(Services, 'ss',
|
|||
'@mozilla.org/content/style-sheet-service;1',
|
||||
'nsIStyleSheetService');
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(Services, 'idle',
|
||||
'@mozilla.org/widget/idleservice;1',
|
||||
'nsIIdleService');
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
XPCOMUtils.defineLazyServiceGetter(Services, 'audioManager',
|
||||
'@mozilla.org/telephony/audiomanager;1',
|
||||
|
@ -174,7 +170,7 @@ var shell = {
|
|||
delete Services.audioManager;
|
||||
#endif
|
||||
},
|
||||
|
||||
|
||||
changeVolume: function shell_changeVolume(delta) {
|
||||
let steps = 10;
|
||||
try {
|
||||
|
@ -435,11 +431,11 @@ var AlertsHelper = {
|
|||
return id;
|
||||
},
|
||||
|
||||
showAlertNotification: function alert_showAlertNotification(imageUrl, title, text, textClickable,
|
||||
showAlertNotification: function alert_showAlertNotification(imageUrl, title, text, textClickable,
|
||||
cookie, alertListener, name) {
|
||||
let id = this.registerListener(cookie, alertListener);
|
||||
let content = shell.contentBrowser.contentWindow;
|
||||
shell.sendEvent(content, "mozChromeEvent", { type: "desktop-notification", id: id, icon: imageUrl,
|
||||
shell.sendEvent(content, "mozChromeEvent", { type: "desktop-notification", id: id, icon: imageUrl,
|
||||
title: title, text: text } );
|
||||
}
|
||||
}
|
||||
|
@ -522,76 +518,6 @@ window.addEventListener('ContentStart', function(evt) {
|
|||
}
|
||||
});
|
||||
|
||||
(function PowerManager() {
|
||||
// This will eventually be moved to content, so use content API as
|
||||
// much as possible here. TODO: Bug 738530
|
||||
let power = navigator.mozPower;
|
||||
let idleHandler = function idleHandler(subject, topic, time) {
|
||||
if (topic !== 'idle')
|
||||
return;
|
||||
|
||||
if (power.getWakeLockState("screen") != "locked-foreground") {
|
||||
navigator.mozPower.screenEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
let wakeLockHandler = function(topic, state) {
|
||||
// Turn off the screen when no one needs the it or all of them are
|
||||
// invisible, otherwise turn the screen on. Note that the CPU
|
||||
// might go to sleep as soon as the screen is turned off and
|
||||
// acquiring wake lock will not bring it back (actually the code
|
||||
// is not executed at all).
|
||||
if (topic === 'screen') {
|
||||
if (state != "locked-foreground") {
|
||||
if (Services.idle.idleTime > idleTimeout*1000) {
|
||||
navigator.mozPower.screenEnabled = false;
|
||||
}
|
||||
} else {
|
||||
navigator.mozPower.screenEnabled = true;
|
||||
}
|
||||
} else if (topic == 'cpu') {
|
||||
navigator.mozPower.cpuSleepAllowed = (state != 'locked-foreground' &&
|
||||
state != 'locked-background');
|
||||
}
|
||||
}
|
||||
|
||||
let idleTimeout = Services.prefs.getIntPref('power.screen.timeout');
|
||||
if (!('mozSettings' in navigator))
|
||||
return;
|
||||
|
||||
let request = navigator.mozSettings.getLock().get('power.screen.timeout');
|
||||
request.onsuccess = function onSuccess() {
|
||||
idleTimeout = request.result['power.screen.timeout'] || idleTimeout;
|
||||
if (!idleTimeout)
|
||||
return;
|
||||
|
||||
Services.idle.addIdleObserver(idleHandler, idleTimeout);
|
||||
power.addWakeLockListener(wakeLockHandler);
|
||||
};
|
||||
|
||||
request.onerror = function onError() {
|
||||
if (!idleTimeout)
|
||||
return;
|
||||
|
||||
Services.idle.addIdleObserver(idleHandler, idleTimeout);
|
||||
power.addWakeLockListener(wakeLockHandler);
|
||||
};
|
||||
|
||||
SettingsListener.observe('power.screen.timeout', idleTimeout, function(value) {
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
Services.idle.removeIdleObserver(idleHandler, idleTimeout);
|
||||
idleTimeout = value;
|
||||
Services.idle.addIdleObserver(idleHandler, idleTimeout);
|
||||
});
|
||||
|
||||
window.addEventListener('unload', function removeIdleObjects() {
|
||||
Services.idle.removeIdleObserver(idleHandler, idleTimeout);
|
||||
power.removeWakeLockListener(wakeLockHandler);
|
||||
});
|
||||
})();
|
||||
|
||||
// This is the backend for Gaia's screenshot feature. Gaia requests a
|
||||
// screenshot by sending a mozContentEvent with detail.type set to
|
||||
// 'take-screenshot'. Then we take a screenshot and send a
|
||||
|
|
Загрузка…
Ссылка в новой задаче