Bug 1053966 - move mozsettings-changed Observer info from aSubject to aData, r=bz,qDot

This commit is contained in:
Mike Habicher 2014-09-16 13:15:16 -04:00
Родитель a999720947
Коммит e9ff4e12a0
29 изменённых файлов: 234 добавлений и 431 удалений

Просмотреть файл

@ -178,13 +178,12 @@ PaymentSettings.prototype = {
}
try {
let setting = JSON.parse(aData);
if (!setting.key ||
(setting.key !== kRilDefaultDataServiceId &&
setting.key !== kRilDefaultPaymentServiceId)) {
if (!aSubject.key ||
(aSubject.key !== kRilDefaultDataServiceId &&
aSubject.key !== kRilDefaultPaymentServiceId)) {
return;
}
this.setServiceId(setting.key, setting.value);
this.setServiceId(aSubject.key, aSubject.value);
} catch (e) {
LOGE(e);
}

Просмотреть файл

@ -20,6 +20,7 @@
#include "nsComponentManagerUtils.h"
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#ifdef MOZ_WIDGET_GONK
#include "nsJSUtils.h"
@ -801,48 +802,33 @@ AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const ch
// To process the volume control on each audio channel according to
// change of settings
else if (!strcmp(aTopic, "mozsettings-changed")) {
AutoSafeJSContext cx;
nsDependentString dataStr(aData);
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) ||
!val.isObject()) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return NS_OK;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) ||
!key.isString()) {
if (!StringBeginsWith(setting.mKey, NS_LITERAL_STRING("audio.volume."))) {
return NS_OK;
}
JS::Rooted<JSString*> jsKey(cx, JS::ToString(cx, key));
if (!jsKey) {
if (!setting.mValue.isNumber()) {
return NS_OK;
}
nsAutoJSString keyStr;
if (!keyStr.init(cx, jsKey) || keyStr.Find("audio.volume.", 0, false)) {
return NS_OK;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value) || !value.isInt32()) {
return NS_OK;
}
nsCOMPtr<nsIAudioManager> audioManager = do_GetService(NS_AUDIOMANAGER_CONTRACTID);
NS_ENSURE_TRUE(audioManager, NS_OK);
int32_t index = value.toInt32();
if (keyStr.EqualsLiteral("audio.volume.content")) {
int32_t index = setting.mValue.toNumber();
if (setting.mKey.EqualsLiteral("audio.volume.content")) {
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Content, index);
} else if (keyStr.EqualsLiteral("audio.volume.notification")) {
} else if (setting.mKey.EqualsLiteral("audio.volume.notification")) {
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Notification, index);
} else if (keyStr.EqualsLiteral("audio.volume.alarm")) {
} else if (setting.mKey.EqualsLiteral("audio.volume.alarm")) {
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Alarm, index);
} else if (keyStr.EqualsLiteral("audio.volume.telephony")) {
} else if (setting.mKey.EqualsLiteral("audio.volume.telephony")) {
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Telephony, index);
} else if (!keyStr.EqualsLiteral("audio.volume.bt_sco")) {
} else if (!setting.mKey.EqualsLiteral("audio.volume.bt_sco")) {
// bt_sco is not a valid audio channel so we manipulate it in
// AudioManager.cpp. And the others should not be used.
// We didn't use MOZ_CRASH or MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE here

Просмотреть файл

@ -2959,25 +2959,21 @@ CallerSubsumes(JS::Handle<JS::Value> aValue)
template<class T>
inline bool
WrappedJSToDictionary(nsISupports* aObject, T& aDictionary)
WrappedJSToDictionary(JSContext* aCx, nsISupports* aObject, T& aDictionary)
{
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(aObject);
if (!wrappedObj) {
return false;
}
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> obj(cx, wrappedObj->GetJSObject());
JS::Rooted<JSObject*> obj(aCx, wrappedObj->GetJSObject());
if (!obj) {
return false;
}
JSAutoCompartment ac(cx, obj);
JS::Rooted<JS::Value> v(cx, OBJECT_TO_JSVAL(obj));
return aDictionary.Init(cx, v);
JSAutoCompartment ac(aCx, obj);
JS::Rooted<JS::Value> v(aCx, JS::ObjectValue(*obj));
return aDictionary.Init(aCx, v);
}

Просмотреть файл

@ -36,6 +36,7 @@
#include "nsITimer.h"
#include "nsServiceManagerUtils.h"
#include "nsXPCOM.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#if defined(MOZ_WIDGET_GONK)
#include "cutils/properties.h"
@ -562,91 +563,44 @@ BluetoothService::HandleStartupSettingsCheck(bool aEnable)
}
nsresult
BluetoothService::HandleSettingsChanged(const nsAString& aData)
BluetoothService::HandleSettingsChanged(nsISupports* aSubject)
{
MOZ_ASSERT(NS_IsMainThread());
// The string that we're interested in will be a JSON string that looks like:
// {"key":"bluetooth.enabled","value":true}
AutoSafeJSContext cx;
if (!cx) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return NS_OK;
}
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val)) {
return JS_ReportPendingException(cx) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
if (!val.isObject()) {
return NS_OK;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!key.isString()) {
return NS_OK;
}
// First, check if the string equals to BLUETOOTH_DEBUGGING_SETTING
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_DEBUGGING_SETTING, &match)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (match) {
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!value.isBoolean()) {
if (setting.mKey.EqualsASCII(BLUETOOTH_DEBUGGING_SETTING)) {
if (!setting.mValue.isBoolean()) {
MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.debugging.enabled'!");
return NS_ERROR_UNEXPECTED;
}
SWITCH_BT_DEBUG(value.toBoolean());
SWITCH_BT_DEBUG(setting.mValue.toBoolean());
return NS_OK;
}
// Second, check if the string is BLUETOOTH_ENABLED_SETTING
if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_ENABLED_SETTING, &match)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
if (!setting.mKey.EqualsASCII(BLUETOOTH_ENABLED_SETTING)) {
return NS_OK;
}
if (!setting.mValue.isBoolean()) {
MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.enabled'!");
return NS_ERROR_UNEXPECTED;
}
if (match) {
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
sToggleInProgress = true;
if (!value.isBoolean()) {
MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.enabled'!");
return NS_ERROR_UNEXPECTED;
}
if (sToggleInProgress || value.toBoolean() == IsEnabled()) {
// Nothing to do here.
return NS_OK;
}
sToggleInProgress = true;
nsresult rv = StartStopBluetooth(value.toBoolean(), false);
NS_ENSURE_SUCCESS(rv, rv);
}
nsresult rv = StartStopBluetooth(setting.mValue.toBoolean(), false);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -757,7 +711,7 @@ BluetoothService::Observe(nsISupports* aSubject, const char* aTopic,
}
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
return HandleSettingsChanged(nsDependentString(aData));
return HandleSettingsChanged(aSubject);
}
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {

Просмотреть файл

@ -377,7 +377,7 @@ protected:
* Called when "mozsettings-changed" observer topic fires.
*/
nsresult
HandleSettingsChanged(const nsAString& aData);
HandleSettingsChanged(nsISupports* aSubject);
/**
* Called when XPCOM is shutting down.

Просмотреть файл

@ -27,6 +27,8 @@
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
#define AUDIO_VOLUME_BT_SCO_ID "audio.volume.bt_sco"
@ -462,7 +464,7 @@ BluetoothHfpManager::Observe(nsISupports* aSubject,
const char16_t* aData)
{
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
HandleVolumeChanged(nsDependentString(aData));
HandleVolumeChanged(aSubject);
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
HandleShutdown();
} else {
@ -561,39 +563,28 @@ public:
};
void
BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
BluetoothHfpManager::HandleVolumeChanged(nsISupports* aSubject)
{
MOZ_ASSERT(NS_IsMainThread());
// The string that we're interested in will be a JSON string that looks like:
// {"key":"volumeup", "value":10}
// {"key":"volumedown", "value":2}
JSContext* cx = nsContentUtils::GetSafeJSContext();
NS_ENSURE_TRUE_VOID(cx);
JS::Rooted<JS::Value> val(cx);
NS_ENSURE_TRUE_VOID(JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val));
NS_ENSURE_TRUE_VOID(val.isObject());
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) || !key.isString()) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<dom::SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return;
}
if (!setting.mKey.EqualsASCII(AUDIO_VOLUME_BT_SCO_ID)) {
return;
}
if (!setting.mValue.isNumber()) {
return;
}
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO_ID, &match) ||
!match) {
return;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value) ||
!value.isNumber()) {
return;
}
mCurrentVgs = value.toNumber();
mCurrentVgs = setting.mValue.toNumber();
// Adjust volume by headset and we don't have to send volume back to headset
if (mReceiveVgsFlag) {

Просмотреть файл

@ -149,7 +149,7 @@ private:
void Cleanup();
void HandleShutdown();
void HandleVolumeChanged(const nsAString& aData);
void HandleVolumeChanged(nsISupports* aSubject);
void Notify(const hal::BatteryInformation& aBatteryInfo);
void NotifyConnectionStateChanged(const nsAString& aType);

Просмотреть файл

@ -23,6 +23,8 @@
#include "nsIObserverService.h"
#include "nsISettingsService.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#ifdef MOZ_B2G_RIL
#include "nsIDOMIccInfo.h"
@ -205,7 +207,7 @@ BluetoothHfpManager::Observe(nsISupports* aSubject,
const char16_t* aData)
{
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
HandleVolumeChanged(nsDependentString(aData));
HandleVolumeChanged(aSubject);
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
HandleShutdown();
} else {
@ -555,7 +557,7 @@ BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
#endif // MOZ_B2G_RIL
void
BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
BluetoothHfpManager::HandleVolumeChanged(nsISupports* aSubject)
{
MOZ_ASSERT(NS_IsMainThread());
@ -563,32 +565,21 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
// {"key":"volumeup", "value":10}
// {"key":"volumedown", "value":2}
JSContext* cx = nsContentUtils::GetSafeJSContext();
NS_ENSURE_TRUE_VOID(cx);
JS::Rooted<JS::Value> val(cx);
NS_ENSURE_TRUE_VOID(JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val));
NS_ENSURE_TRUE_VOID(val.isObject());
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) || !key.isString()) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return;
}
if (!setting.mKey.EqualsASCII(AUDIO_VOLUME_BT_SCO_ID)) {
return;
}
if (!setting.mValue.isNumber()) {
return;
}
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO_ID, &match) ||
!match) {
return;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value)||
!value.isNumber()) {
return;
}
mCurrentVgs = value.toNumber();
mCurrentVgs = setting.mValue.toNumber();
// Adjust volume by headset and we don't have to send volume back to headset
if (mReceiveVgsFlag) {

Просмотреть файл

@ -149,7 +149,7 @@ private:
BluetoothHfpManager();
void HandleShutdown();
void HandleVolumeChanged(const nsAString& aData);
void HandleVolumeChanged(nsISupports* aSubject);
bool Init();
void Notify(const hal::BatteryInformation& aBatteryInfo);

Просмотреть файл

@ -35,6 +35,7 @@
#include "nsITimer.h"
#include "nsServiceManagerUtils.h"
#include "nsXPCOM.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#if defined(MOZ_WIDGET_GONK)
#include "cutils/properties.h"
@ -524,60 +525,29 @@ BluetoothService::HandleStartupSettingsCheck(bool aEnable)
}
nsresult
BluetoothService::HandleSettingsChanged(const nsAString& aData)
BluetoothService::HandleSettingsChanged(nsISupports* aSubject)
{
MOZ_ASSERT(NS_IsMainThread());
// The string that we're interested in will be a JSON string that looks like:
// {"key":"bluetooth.enabled","value":true}
AutoSafeJSContext cx;
if (!cx) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return NS_OK;
}
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val)) {
return JS_ReportPendingException(cx) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
if (!val.isObject()) {
if (!setting.mKey.EqualsASCII(BLUETOOTH_DEBUGGING_SETTING)) {
return NS_OK;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
if (!setting.mValue.isBoolean()) {
MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.debugging.enabled'!");
return NS_ERROR_UNEXPECTED;
}
if (!key.isString()) {
return NS_OK;
}
// Check whether the string is BLUETOOTH_DEBUGGING_SETTING
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_DEBUGGING_SETTING, &match)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (match) {
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!value.isBoolean()) {
MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.debugging.enabled'!");
return NS_ERROR_UNEXPECTED;
}
SWITCH_BT_DEBUG(value.toBoolean());
}
SWITCH_BT_DEBUG(setting.mValue.toBoolean());
return NS_OK;
}
@ -688,7 +658,7 @@ BluetoothService::Observe(nsISupports* aSubject, const char* aTopic,
}
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
return HandleSettingsChanged(nsDependentString(aData));
return HandleSettingsChanged(aSubject);
}
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {

Просмотреть файл

@ -376,7 +376,7 @@ protected:
* Called when "mozsettings-changed" observer topic fires.
*/
nsresult
HandleSettingsChanged(const nsAString& aData);
HandleSettingsChanged(nsISupports* aSubject);
/**
* Called when XPCOM is shutting down.

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
#define AUDIO_VOLUME_BT_SCO_ID "audio.volume.bt_sco"
@ -465,7 +466,7 @@ BluetoothHfpManager::Observe(nsISupports* aSubject,
const char16_t* aData)
{
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
HandleVolumeChanged(nsDependentString(aData));
HandleVolumeChanged(aSubject);
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
HandleShutdown();
} else {
@ -564,39 +565,29 @@ public:
};
void
BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
BluetoothHfpManager::HandleVolumeChanged(nsISupports* aSubject)
{
MOZ_ASSERT(NS_IsMainThread());
// The string that we're interested in will be a JSON string that looks like:
// {"key":"volumeup", "value":10}
// {"key":"volumedown", "value":2}
JSContext* cx = nsContentUtils::GetSafeJSContext();
NS_ENSURE_TRUE_VOID(cx);
JS::Rooted<JS::Value> val(cx);
NS_ENSURE_TRUE_VOID(JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val));
NS_ENSURE_TRUE_VOID(val.isObject());
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) || !key.isString()) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<dom::SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return;
}
if (!setting.mKey.EqualsASCII(AUDIO_VOLUME_BT_SCO_ID)) {
return;
}
if (!setting.mValue.isNumber()) {
return;
}
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO_ID, &match) ||
!match) {
return;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value) ||
!value.isNumber()) {
return;
}
mCurrentVgs = value.toNumber();
mCurrentVgs = setting.mValue.toNumber();
// Adjust volume by headset and we don't have to send volume back to headset
if (mReceiveVgsFlag) {

Просмотреть файл

@ -147,7 +147,7 @@ private:
bool Init();
void HandleShutdown();
void HandleVolumeChanged(const nsAString& aData);
void HandleVolumeChanged(nsISupports* aSubject);
void Notify(const hal::BatteryInformation& aBatteryInfo);
void NotifyConnectionStateChanged(const nsAString& aType);

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsIObserverService.h"
#include "nsISettingsService.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#ifdef MOZ_B2G_RIL
#include "nsIDOMIccInfo.h"
@ -205,7 +206,7 @@ BluetoothHfpManager::Observe(nsISupports* aSubject,
const char16_t* aData)
{
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
HandleVolumeChanged(nsDependentString(aData));
HandleVolumeChanged(aSubject);
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
HandleShutdown();
} else {
@ -555,7 +556,7 @@ BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
#endif // MOZ_B2G_RIL
void
BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
BluetoothHfpManager::HandleVolumeChanged(nsISupports* aSubject)
{
MOZ_ASSERT(NS_IsMainThread());
@ -563,32 +564,21 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
// {"key":"volumeup", "value":10}
// {"key":"volumedown", "value":2}
JSContext* cx = nsContentUtils::GetSafeJSContext();
NS_ENSURE_TRUE_VOID(cx);
JS::Rooted<JS::Value> val(cx);
NS_ENSURE_TRUE_VOID(JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val));
NS_ENSURE_TRUE_VOID(val.isObject());
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) || !key.isString()) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<dom::SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return;
}
if (!setting.mKey.EqualsASCII(AUDIO_VOLUME_BT_SCO_ID)) {
return;
}
if (!setting.mValue.isNumber()) {
return;
}
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO_ID, &match) ||
!match) {
return;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value)||
!value.isNumber()) {
return;
}
mCurrentVgs = value.toNumber();
mCurrentVgs = setting.mValue.toNumber();
// Adjust volume by headset and we don't have to send volume back to headset
if (mReceiveVgsFlag) {

Просмотреть файл

@ -149,7 +149,7 @@ private:
BluetoothHfpManager();
void HandleShutdown();
void HandleVolumeChanged(const nsAString& aData);
void HandleVolumeChanged(nsISupports* aSubject);
bool Init();
void Notify(const hal::BatteryInformation& aBatteryInfo);

Просмотреть файл

@ -16,6 +16,8 @@
#include "nsIObserverService.h"
#include "nsISettingsService.h"
#include "nsJSUtils.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#define BAND_87500_108000_kHz 1
#define BAND_76000_108000_kHz 2
@ -678,9 +680,9 @@ FMRadioService::CancelSeek(FMRadioReplyRunnable* aReplyRunnable)
}
NS_IMETHODIMP
FMRadioService::Observe(nsISupports * aSubject,
const char * aTopic,
const char16_t * aData)
FMRadioService::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(sFMRadioService);
@ -691,47 +693,26 @@ FMRadioService::Observe(nsISupports * aSubject,
// The string that we're interested in will be a JSON string looks like:
// {"key":"airplaneMode.enabled","value":true}
AutoSafeJSContext cx;
const nsDependentString dataStr(aData);
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) ||
!val.isObject()) {
NS_WARNING("Bad JSON string format.");
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<dom::SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return NS_OK;
}
if (!setting.mKey.EqualsASCII(SETTING_KEY_AIRPLANEMODE_ENABLED)) {
return NS_OK;
}
if (!setting.mValue.isBoolean()) {
return NS_OK;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) ||
!key.isString()) {
NS_WARNING("Failed to get string property `key`.");
return NS_OK;
}
mAirplaneModeEnabled = setting.mValue.toBoolean();
mHasReadAirplaneModeSetting = true;
JS::Rooted<JSString*> jsKey(cx, key.toString());
nsAutoJSString keyStr;
if (!keyStr.init(cx, jsKey)) {
return NS_OK;
}
if (keyStr.EqualsLiteral(SETTING_KEY_AIRPLANEMODE_ENABLED)) {
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value)) {
NS_WARNING("Failed to get property `value`.");
return NS_OK;
}
if (!value.isBoolean()) {
return NS_OK;
}
mAirplaneModeEnabled = value.toBoolean();
mHasReadAirplaneModeSetting = true;
// Disable the FM radio HW if Airplane mode is enabled.
if (mAirplaneModeEnabled) {
Disable(nullptr);
}
// Disable the FM radio HW if Airplane mode is enabled.
if (mAirplaneModeEnabled) {
Disable(nullptr);
}
return NS_OK;

Просмотреть файл

@ -24,6 +24,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
class nsIPrincipal;
@ -712,36 +713,26 @@ nsGeolocationService::~nsGeolocationService()
}
void
nsGeolocationService::HandleMozsettingChanged(const char16_t* aData)
nsGeolocationService::HandleMozsettingChanged(nsISupports* aSubject)
{
// The string that we're interested in will be a JSON string that looks like:
// {"key":"gelocation.enabled","value":true}
AutoSafeJSContext cx;
nsDependentString dataStr(aData);
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) || !val.isObject()) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return;
}
if (!setting.mKey.EqualsASCII(GEO_SETINGS_ENABLED)) {
return;
}
if (!setting.mValue.isBoolean()) {
return;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) || !key.isString()) {
return;
}
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), GEO_SETINGS_ENABLED, &match) || !match) {
return;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value) || !value.isBoolean()) {
return;
}
HandleMozsettingValue(value.toBoolean());
HandleMozsettingValue(setting.mValue.toBoolean());
}
void
@ -786,7 +777,7 @@ nsGeolocationService::Observe(nsISupports* aSubject,
}
if (!strcmp("mozsettings-changed", aTopic)) {
HandleMozsettingChanged(aData);
HandleMozsettingChanged(aSubject);
return NS_OK;
}

Просмотреть файл

@ -70,7 +70,7 @@ public:
nsresult Init();
void HandleMozsettingChanged(const char16_t* aData);
void HandleMozsettingChanged(nsISupports* aSubject);
void HandleMozsettingValue(const bool aValue);
// Management of the Geolocation objects

Просмотреть файл

@ -663,12 +663,12 @@ let SettingsRequestManager = {
sendSettingsChange: function(aKey, aValue, aIsServiceLock) {
this.broadcastMessage("Settings:Change:Return:OK",
{ key: aKey, value: aValue });
Services.obs.notifyObservers(this, kMozSettingsChangedObserverTopic,
JSON.stringify({
key: aKey,
value: aValue,
isInternalChange: aIsServiceLock
}));
var setting = {
key: aKey,
value: aValue,
isInternalChange: aIsServiceLock
};
Services.obs.notifyObservers(setting, kMozSettingsChangedObserverTopic, "");
},
broadcastMessage: function broadcastMessage(aMsgName, aContent) {

Просмотреть файл

@ -264,11 +264,10 @@ WifiGeoPositionProvider.prototype = {
}
try {
let setting = JSON.parse(aData);
if (setting.key == SETTINGS_DEBUG_ENABLED) {
gLoggingEnabled = setting.value;
} else if (setting.key == SETTINGS_WIFI_ENABLED) {
gWifiScanningEnabled = setting.value;
if (aSubject.key == SETTINGS_DEBUG_ENABLED) {
gLoggingEnabled = aSubject.value;
} else if (aSubject.key == SETTINGS_WIFI_ENABLED) {
gWifiScanningEnabled = aSubject.value;
}
} catch (e) {
}

Просмотреть файл

@ -41,6 +41,8 @@
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsXULAppAPI.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
using namespace mozilla::dom::gonk;
using namespace android;
@ -350,36 +352,21 @@ AudioManager::Observe(nsISupports* aSubject,
// To process the volume control on each audio channel according to
// change of settings
else if (!strcmp(aTopic, MOZ_SETTINGS_CHANGE_ID)) {
AutoSafeJSContext cx;
nsDependentString dataStr(aData);
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) ||
!val.isObject()) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<dom::SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return NS_OK;
}
if (!setting.mKey.EqualsASCII("audio.volume.bt_sco")) {
return NS_OK;
}
if (!setting.mValue.isNumber()) {
return NS_OK;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) ||
!key.isString()) {
return NS_OK;
}
JS::Rooted<JSString*> jsKey(cx, JS::ToString(cx, key));
if (!jsKey) {
return NS_OK;
}
nsAutoJSString keyStr;
if (!keyStr.init(cx, jsKey) || !keyStr.EqualsLiteral("audio.volume.bt_sco")) {
return NS_OK;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value) || !value.isInt32()) {
return NS_OK;
}
int32_t index = value.toInt32();
int32_t index = setting.mValue.toNumber();
SetStreamVolumeIndex(AUDIO_STREAM_BLUETOOTH_SCO, index);
return NS_OK;

Просмотреть файл

@ -20,6 +20,8 @@
#include "xpcpublic.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#undef LOG
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "AutoMounterSetting" , ## args)
@ -31,6 +33,8 @@
#define UMS_VOLUME_ENABLED_SUFFIX ".enabled"
#define MOZSETTINGS_CHANGED "mozsettings-changed"
using namespace mozilla::dom;
namespace mozilla {
namespace system {
@ -235,52 +239,35 @@ AutoMounterSetting::Observe(nsISupports* aSubject,
// The string that we're interested in will be a JSON string that looks like:
// {"key":"ums.autoMount","value":true}
mozilla::AutoSafeJSContext cx;
nsDependentString dataStr(aData);
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) ||
!val.isObject()) {
return NS_OK;
}
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) ||
!key.isString()) {
return NS_OK;
}
JSString *jsKey = JS::ToString(cx, key);
nsAutoJSString keyStr;
if (!keyStr.init(cx, jsKey)) {
return NS_OK;
}
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value)) {
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
RootedDictionary<SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return NS_OK;
}
// Check for ums.mode changes
if (keyStr.EqualsLiteral(UMS_MODE)) {
if (!value.isInt32()) {
if (setting.mKey.EqualsASCII(UMS_MODE)) {
if (!setting.mValue.isInt32()) {
return NS_OK;
}
int32_t mode = value.toInt32();
int32_t mode = setting.mValue.toInt32();
SetAutoMounterMode(mode);
return NS_OK;
}
// Check for ums.volume.NAME.enabled
if (StringBeginsWith(keyStr, NS_LITERAL_STRING(UMS_VOLUME_ENABLED_PREFIX)) &&
StringEndsWith(keyStr, NS_LITERAL_STRING(UMS_VOLUME_ENABLED_SUFFIX))) {
if (!value.isBoolean()) {
if (StringBeginsWith(setting.mKey, NS_LITERAL_STRING(UMS_VOLUME_ENABLED_PREFIX)) &&
StringEndsWith(setting.mKey, NS_LITERAL_STRING(UMS_VOLUME_ENABLED_SUFFIX))) {
if (!setting.mValue.isBoolean()) {
return NS_OK;
}
const size_t prefixLen = sizeof(UMS_VOLUME_ENABLED_PREFIX) - 1;
const size_t suffixLen = sizeof(UMS_VOLUME_ENABLED_SUFFIX) - 1;
nsDependentSubstring volumeName =
Substring(keyStr, prefixLen, keyStr.Length() - prefixLen - suffixLen);
bool isSharingEnabled = value.toBoolean();
Substring(setting.mKey, prefixLen, setting.mKey.Length() - prefixLen - suffixLen);
bool isSharingEnabled = setting.mValue.toBoolean();
SetAutoMounterSharingMode(NS_LossyConvertUTF16toASCII(volumeName), isSharingEnabled);
return NS_OK;
}

Просмотреть файл

@ -220,8 +220,7 @@ NetworkManager.prototype = {
observe: function(subject, topic, data) {
switch (topic) {
case TOPIC_MOZSETTINGS_CHANGED:
let setting = JSON.parse(data);
this.handle(setting.key, setting.value);
this.handle(subject.key, subject.value);
break;
case TOPIC_PREF_CHANGED:
this._manageOfflineStatus =

Просмотреть файл

@ -960,8 +960,7 @@ XPCOMUtils.defineLazyGetter(this, "gDataConnectionManager", function () {
observe: function(subject, topic, data) {
switch (topic) {
case kMozSettingsChangedObserverTopic:
let setting = JSON.parse(data);
this.handle(setting.key, setting.value);
this.handle(subject.key, subject.value);
break;
case NS_XPCOM_SHUTDOWN_OBSERVER_ID:
this._shutdown();
@ -3052,8 +3051,7 @@ RadioInterface.prototype = {
observe: function(subject, topic, data) {
switch (topic) {
case kMozSettingsChangedObserverTopic:
let setting = JSON.parse(data);
this.handleSettingsChange(setting.key, setting.value, setting.isInternalChange);
this.handleSettingsChange(subject.key, subject.value, subject.isInternalChange);
break;
case kSysClockChangeObserverTopic:
let offset = parseInt(data, 10);

Просмотреть файл

@ -22,6 +22,8 @@
#include "xpcpublic.h"
#include "nsContentUtils.h"
#include "nsPrintfCString.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/SettingChangeNotificationBinding.h"
#undef LOG
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Time Zone Setting" , ## args)
@ -31,6 +33,7 @@
#define MOZSETTINGS_CHANGED "mozsettings-changed"
using namespace mozilla;
using namespace mozilla::dom;
namespace {
@ -184,8 +187,8 @@ NS_IMPL_ISUPPORTS(TimeZoneSettingObserver, nsIObserver)
NS_IMETHODIMP
TimeZoneSettingObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const char16_t *aData)
const char *aTopic,
const char16_t *aData)
{
if (strcmp(aTopic, MOZSETTINGS_CHANGED) != 0) {
return NS_OK;
@ -199,37 +202,19 @@ TimeZoneSettingObserver::Observe(nsISupports *aSubject,
// {"key":"time.timezone","value":"UTC-05:00"}
AutoSafeJSContext cx;
// Parse the JSON value.
nsDependentString dataStr(aData);
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) ||
!val.isObject()) {
RootedDictionary<SettingChangeNotification> setting(cx);
if (!WrappedJSToDictionary(cx, aSubject, setting)) {
return NS_OK;
}
// Get the key, which should be the JS string "time.timezone".
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", &key) ||
!key.isString()) {
if (!setting.mKey.EqualsASCII(TIME_TIMEZONE)) {
return NS_OK;
}
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), TIME_TIMEZONE, &match) ||
!match) {
return NS_OK;
}
// Get the value, which should be a JS string like "America/Chicago".
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", &value) ||
!value.isString()) {
if (!setting.mValue.isString()) {
return NS_OK;
}
// Set the system timezone.
return SetTimeZone(value, cx);
return SetTimeZone(setting.mValue, cx);
}
} // anonymous namespace

Просмотреть файл

@ -0,0 +1,12 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Used internally by Gecko
dictionary SettingChangeNotification {
DOMString key = "";
any value;
boolean isInternalChange = false;
};

Просмотреть файл

@ -337,6 +337,7 @@ WEBIDL_FILES = [
'ServiceWorkerContainer.webidl',
'ServiceWorkerGlobalScope.webidl',
'ServiceWorkerRegistration.webidl',
'SettingChangeNotification.webidl',
'SettingsManager.webidl',
'ShadowRoot.webidl',
'SharedWorker.webidl',

Просмотреть файл

@ -3631,17 +3631,13 @@ WifiWorker.prototype = {
observe: function observe(subject, topic, data) {
switch (topic) {
case kMozSettingsChangedObserverTopic:
// The string we're interested in will be a JSON string that looks like:
// {"key":"wifi.enabled","value":"true"}.
let setting = JSON.parse(data);
// To avoid WifiWorker setting the wifi again, don't need to deal with
// the "mozsettings-changed" event fired from internal setting.
if (setting.isInternalChange) {
if (subject.isInternalChange) {
return;
}
this.handle(setting.key, setting.value);
this.handle(subject.key, subject.value);
break;
case "xpcom-shutdown":

Просмотреть файл

@ -205,11 +205,10 @@ LocalDevice.prototype = {
if (topic !== "mozsettings-changed") {
return;
}
let setting = JSON.parse(data);
if (setting.key !== LocalDevice.SETTING) {
if (subject.key !== LocalDevice.SETTING) {
return;
}
this._name = setting.value;
this._name = subject.value;
log("Device: " + this._name);
},