mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1200343 - Implment PrefsHelper native calls; r=snorp
This patch implements the PrefsHelper native calls for getting prefs;
This commit is contained in:
parent
b0bd9828c5
commit
cc4a1b8406
78
widget/android/PrefsHelper.h
Normal file
78
widget/android/PrefsHelper.h
Normal file
@ -0,0 +1,78 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* 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/. */
|
||||
|
||||
#ifndef PrefsHelper_h
|
||||
#define PrefsHelper_h
|
||||
|
||||
#include "GeneratedJNINatives.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "nsAppShell.h"
|
||||
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
struct PrefsHelper
|
||||
: widget::PrefsHelper::Natives<PrefsHelper>
|
||||
, UsesGeckoThreadProxy
|
||||
{
|
||||
PrefsHelper() = delete;
|
||||
|
||||
static void GetPrefsById(const jni::ClassObject::LocalRef& cls,
|
||||
int32_t requestId,
|
||||
jni::ObjectArray::Param prefNames,
|
||||
bool observe)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(nsAppShell::gAppShell);
|
||||
|
||||
nsTArray<jni::Object::LocalRef> namesRefArray(prefNames.GetElements());
|
||||
const size_t len = namesRefArray.Length();
|
||||
|
||||
// Java strings are not null-terminated, but XPCOM expects
|
||||
// null-terminated strings, so we copy the strings to nsString to
|
||||
// ensure null-termination.
|
||||
nsTArray<nsString> namesStrArray;
|
||||
nsTArray<const char16_t*> namesPtrArray;
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (!namesRefArray[i]) {
|
||||
namesPtrArray.AppendElement(nullptr);
|
||||
continue;
|
||||
}
|
||||
namesPtrArray.AppendElement(namesStrArray.AppendElement(
|
||||
nsString(jni::String::LocalRef(
|
||||
mozilla::Move(namesRefArray[i]))))->Data());
|
||||
}
|
||||
|
||||
nsIAndroidBrowserApp* browserApp = nullptr;
|
||||
nsAppShell::gAppShell->GetBrowserApp(&browserApp);
|
||||
MOZ_ASSERT(browserApp);
|
||||
|
||||
if (observe) {
|
||||
browserApp->ObservePreferences(
|
||||
requestId, len ? &namesPtrArray[0] : nullptr, len);
|
||||
} else {
|
||||
browserApp->GetPreferences(
|
||||
requestId, len ? &namesPtrArray[0] : nullptr, len);
|
||||
}
|
||||
}
|
||||
|
||||
static void RemovePrefsObserver(int32_t requestId)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(nsAppShell::gAppShell);
|
||||
|
||||
nsIAndroidBrowserApp* browserApp = nullptr;
|
||||
nsAppShell::gAppShell->GetBrowserApp(&browserApp);
|
||||
MOZ_ASSERT(browserApp);
|
||||
|
||||
browserApp->RemovePreferenceObservers(requestId);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // PrefsHelper_h
|
@ -60,6 +60,7 @@
|
||||
#endif
|
||||
|
||||
#include "ANRReporter.h"
|
||||
#include "PrefsHelper.h"
|
||||
|
||||
#ifdef DEBUG_ANDROID_EVENTS
|
||||
#define EVLOG(args...) ALOG(args)
|
||||
@ -196,6 +197,7 @@ nsAppShell::nsAppShell()
|
||||
AndroidBridge::ConstructBridge();
|
||||
GeckoThreadNatives::Init();
|
||||
mozilla::ANRReporter::Init();
|
||||
mozilla::PrefsHelper::Init();
|
||||
nsWindow::InitNatives();
|
||||
|
||||
widget::GeckoThread::SetState(widget::GeckoThread::State::JNI_READY());
|
||||
|
Loading…
Reference in New Issue
Block a user