mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
5dc21d568c
The inclusions were removed with the following very crude script and the resulting breakage was fixed up by hand. The manual fixups did either revert the changes done by the script, replace a generic header with a more specific one or replace a header with a forward declaration. find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2) if [ -n "$interfaces" ]; then if [[ "$interfaces" == *$'\n'* ]]; then regexp="\(" for i in $interfaces; do regexp="$regexp$i\|"; done regexp="${regexp%%\\\|}\)" else regexp="$interfaces" fi interface=$(basename "$path") rg -l "#include.*${interface%%.idl}.h" . | while read path2; do hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" ) if [ $hits -eq 0 ]; then echo "Removing ${interface} from ${path2}" grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp mv -f "$path2".tmp "$path2" fi done fi done Differential Revision: https://phabricator.services.mozilla.com/D55444 --HG-- extra : moz-landing-system : lando
82 lines
2.8 KiB
Plaintext
82 lines
2.8 KiB
Plaintext
/* 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/. */
|
|
|
|
#include "nsMacPreferencesReader.h"
|
|
|
|
#include "js/JSON.h"
|
|
#include "JSONWriter.h"
|
|
|
|
NS_IMPL_ISUPPORTS(nsMacPreferencesReader, nsIMacPreferencesReader)
|
|
|
|
using namespace mozilla;
|
|
|
|
struct StringWriteFunc : public JSONWriteFunc {
|
|
nsAString& mString;
|
|
explicit StringWriteFunc(nsAString& aStr) : mString(aStr) {}
|
|
void Write(const char* aStr) override { mString.Append(NS_ConvertUTF8toUTF16(aStr)); }
|
|
};
|
|
|
|
static void EvaluateDict(JSONWriter* aWriter, NSDictionary<NSString*, id>* aDict);
|
|
|
|
static void EvaluateArray(JSONWriter* aWriter, NSArray* aArray) {
|
|
for (id elem in aArray) {
|
|
if ([elem isKindOfClass:[NSString class]]) {
|
|
aWriter->StringElement([elem UTF8String]);
|
|
} else if ([elem isKindOfClass:[NSNumber class]]) {
|
|
aWriter->IntElement([elem longLongValue]);
|
|
} else if ([elem isKindOfClass:[NSArray class]]) {
|
|
aWriter->StartArrayElement();
|
|
EvaluateArray(aWriter, elem);
|
|
aWriter->EndArray();
|
|
} else if ([elem isKindOfClass:[NSDictionary class]]) {
|
|
aWriter->StartObjectElement();
|
|
EvaluateDict(aWriter, elem);
|
|
aWriter->EndObject();
|
|
}
|
|
}
|
|
}
|
|
|
|
static void EvaluateDict(JSONWriter* aWriter, NSDictionary<NSString*, id>* aDict) {
|
|
for (NSString* key in aDict) {
|
|
id value = aDict[key];
|
|
if ([value isKindOfClass:[NSString class]]) {
|
|
aWriter->StringProperty([key UTF8String], [value UTF8String]);
|
|
} else if ([value isKindOfClass:[NSNumber class]]) {
|
|
aWriter->IntProperty([key UTF8String], [value longLongValue]);
|
|
} else if ([value isKindOfClass:[NSArray class]]) {
|
|
aWriter->StartArrayProperty([key UTF8String]);
|
|
EvaluateArray(aWriter, value);
|
|
aWriter->EndArray();
|
|
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
|
aWriter->StartObjectProperty([key UTF8String]);
|
|
EvaluateDict(aWriter, value);
|
|
aWriter->EndObject();
|
|
}
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsMacPreferencesReader::PoliciesEnabled(bool* aPoliciesEnabled) {
|
|
NSString* policiesEnabledStr = [NSString stringWithUTF8String:ENTERPRISE_POLICIES_ENABLED_KEY];
|
|
*aPoliciesEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:policiesEnabledStr] == YES;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsMacPreferencesReader::ReadPreferences(JSContext* aCx, JS::MutableHandle<JS::Value> aResult) {
|
|
nsAutoString jsonStr;
|
|
JSONWriter w(MakeUnique<StringWriteFunc>(jsonStr));
|
|
w.Start();
|
|
EvaluateDict(&w, [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
|
|
w.End();
|
|
|
|
auto json = static_cast<const char16_t*>(jsonStr.get());
|
|
|
|
JS::RootedValue val(aCx);
|
|
MOZ_ALWAYS_TRUE(JS_ParseJSON(aCx, json, jsonStr.Length(), &val));
|
|
|
|
aResult.set(val);
|
|
return NS_OK;
|
|
}
|