mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1200343 - Add native calls for pref events; r=snorp
This patch adds two native calls to PrefsHelper to avoid using GeckoEvent for getting prefs.
This commit is contained in:
parent
3c7836a62a
commit
67b18214ea
@ -191,15 +191,15 @@ public class FennecNativeActions implements Actions {
|
||||
}
|
||||
|
||||
public void sendPreferencesGetEvent(int requestId, String[] prefNames) {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createPreferencesGetEvent(requestId, prefNames));
|
||||
PrefsHelper.getPrefsById(requestId, prefNames, /* observe */ false);
|
||||
}
|
||||
|
||||
public void sendPreferencesObserveEvent(int requestId, String[] prefNames) {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createPreferencesObserveEvent(requestId, prefNames));
|
||||
PrefsHelper.getPrefsById(requestId, prefNames, /* observe */ true);
|
||||
}
|
||||
|
||||
public void sendPreferencesRemoveObserversEvent(int requestId) {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createPreferencesRemoveObserversEvent(requestId));
|
||||
PrefsHelper.removePrefsObserver(requestId);
|
||||
}
|
||||
|
||||
class PaintExpecter implements RepeatedEventExpecter {
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.annotation.RobocopTarget;
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@ -26,6 +28,11 @@ public final class PrefsHelper {
|
||||
private static int sUniqueRequestId = 1;
|
||||
static final SparseArray<PrefHandler> sCallbacks = new SparseArray<PrefHandler>();
|
||||
|
||||
@WrapForJNI @RobocopTarget
|
||||
/* package */ static native void getPrefsById(int requestId, String[] prefNames, boolean observe);
|
||||
@WrapForJNI @RobocopTarget
|
||||
/* package */ static native void removePrefsObserver(int requestId);
|
||||
|
||||
public static int getPref(String prefName, PrefHandler callback) {
|
||||
return getPrefsInternal(new String[] { prefName }, callback);
|
||||
}
|
||||
@ -47,14 +54,15 @@ public final class PrefsHelper {
|
||||
sCallbacks.put(requestId, callback);
|
||||
}
|
||||
|
||||
GeckoEvent event;
|
||||
if (callback.isObserver()) {
|
||||
event = GeckoEvent.createPreferencesObserveEvent(requestId, prefNames);
|
||||
// Because we use JS to handle pref events, we need to wait until the RUNNING state.
|
||||
// If we ever convert that to native code, we can switch to using the JNI_READY state.
|
||||
if (GeckoThread.isStateAtLeast(GeckoThread.State.RUNNING)) {
|
||||
getPrefsById(requestId, prefNames, callback.isObserver());
|
||||
} else {
|
||||
event = GeckoEvent.createPreferencesGetEvent(requestId, prefNames);
|
||||
GeckoThread.queueNativeCallUntil(
|
||||
GeckoThread.State.RUNNING, PrefsHelper.class, "getPrefsById",
|
||||
requestId, prefNames, callback.isObserver());
|
||||
}
|
||||
GeckoAppShell.sendEventToGecko(event);
|
||||
|
||||
return requestId;
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,25 @@ public:
|
||||
template<class Impl>
|
||||
constexpr JNINativeMethod GeckoView::Window::Natives<Impl>::methods[];
|
||||
|
||||
template<class Impl>
|
||||
class PrefsHelper::Natives : public mozilla::jni::NativeImpl<PrefsHelper, Impl>
|
||||
{
|
||||
public:
|
||||
static constexpr JNINativeMethod methods[] = {
|
||||
|
||||
mozilla::jni::MakeNativeMethod<PrefsHelper::GetPrefsById_t>(
|
||||
mozilla::jni::NativeStub<PrefsHelper::GetPrefsById_t, Impl>
|
||||
::template Wrap<&Impl::GetPrefsById>),
|
||||
|
||||
mozilla::jni::MakeNativeMethod<PrefsHelper::RemovePrefsObserver_t>(
|
||||
mozilla::jni::NativeStub<PrefsHelper::RemovePrefsObserver_t, Impl>
|
||||
::template Wrap<&Impl::RemovePrefsObserver>)
|
||||
};
|
||||
};
|
||||
|
||||
template<class Impl>
|
||||
constexpr JNINativeMethod PrefsHelper::Natives<Impl>::methods[];
|
||||
|
||||
template<class Impl>
|
||||
class NativeJSContainer::Natives : public mozilla::jni::NativeImpl<NativeJSContainer, Impl>
|
||||
{
|
||||
|
@ -956,6 +956,14 @@ constexpr char GeckoView::Window::DisposeNative_t::signature[];
|
||||
constexpr char GeckoView::Window::Open_t::name[];
|
||||
constexpr char GeckoView::Window::Open_t::signature[];
|
||||
|
||||
constexpr char PrefsHelper::name[];
|
||||
|
||||
constexpr char PrefsHelper::GetPrefsById_t::name[];
|
||||
constexpr char PrefsHelper::GetPrefsById_t::signature[];
|
||||
|
||||
constexpr char PrefsHelper::RemovePrefsObserver_t::name[];
|
||||
constexpr char PrefsHelper::RemovePrefsObserver_t::signature[];
|
||||
|
||||
constexpr char RestrictedProfiles::name[];
|
||||
|
||||
constexpr char RestrictedProfiles::IsAllowed_t::name[];
|
||||
|
@ -2312,6 +2312,58 @@ public:
|
||||
template<class Impl> class Natives;
|
||||
};
|
||||
|
||||
class PrefsHelper : public mozilla::jni::Class<PrefsHelper>
|
||||
{
|
||||
public:
|
||||
typedef mozilla::jni::Ref<PrefsHelper> Ref;
|
||||
typedef mozilla::jni::LocalRef<PrefsHelper> LocalRef;
|
||||
typedef mozilla::jni::GlobalRef<PrefsHelper> GlobalRef;
|
||||
typedef const mozilla::jni::Param<PrefsHelper>& Param;
|
||||
|
||||
static constexpr char name[] =
|
||||
"org/mozilla/gecko/PrefsHelper";
|
||||
|
||||
protected:
|
||||
PrefsHelper(jobject instance) : Class(instance) {}
|
||||
|
||||
public:
|
||||
struct GetPrefsById_t {
|
||||
typedef PrefsHelper Owner;
|
||||
typedef void ReturnType;
|
||||
typedef void SetterType;
|
||||
typedef mozilla::jni::Args<
|
||||
int32_t,
|
||||
mozilla::jni::ObjectArray::Param,
|
||||
bool> Args;
|
||||
static constexpr char name[] = "getPrefsById";
|
||||
static constexpr char signature[] =
|
||||
"(I[Ljava/lang/String;Z)V";
|
||||
static const bool isStatic = true;
|
||||
static const bool isMultithreaded = false;
|
||||
static const mozilla::jni::ExceptionMode exceptionMode =
|
||||
mozilla::jni::ExceptionMode::ABORT;
|
||||
};
|
||||
|
||||
public:
|
||||
struct RemovePrefsObserver_t {
|
||||
typedef PrefsHelper Owner;
|
||||
typedef void ReturnType;
|
||||
typedef void SetterType;
|
||||
typedef mozilla::jni::Args<
|
||||
int32_t> Args;
|
||||
static constexpr char name[] = "removePrefsObserver";
|
||||
static constexpr char signature[] =
|
||||
"(I)V";
|
||||
static const bool isStatic = true;
|
||||
static const bool isMultithreaded = false;
|
||||
static const mozilla::jni::ExceptionMode exceptionMode =
|
||||
mozilla::jni::ExceptionMode::ABORT;
|
||||
};
|
||||
|
||||
public:
|
||||
template<class Impl> class Natives;
|
||||
};
|
||||
|
||||
class RestrictedProfiles : public mozilla::jni::Class<RestrictedProfiles>
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user