Bug 1197957 - Introduce GeckoView.Window class; r=snorp

GeckoView.Window is a class that acts as the interface between
GeckoView in Java and nsWindow in C++. It will contain native methods
that GeckoView will use to interact with nsWindow.

On initialization, Window.open is called to create a nsWindow and
establish the JNI association between Window and the native nsWindow.
Then, whenever Window instance methods are called, the JNI stubs will
automatically call members of nsWindow.
This commit is contained in:
Jim Chen
2015-09-21 10:13:32 -04:00
parent efd29e7f91
commit 3bedd655b1
4 changed files with 134 additions and 0 deletions

View File

@@ -12,8 +12,10 @@ import java.util.Set;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.gfx.LayerView; import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.mozglue.GeckoLoader; import org.mozilla.gecko.mozglue.GeckoLoader;
import org.mozilla.gecko.mozglue.JNIObject;
import org.mozilla.gecko.util.Clipboard; import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.EventCallback; import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoEventListener; import org.mozilla.gecko.util.GeckoEventListener;
@@ -104,6 +106,14 @@ public class GeckoView extends LayerView
} }
}; };
@WrapForJNI
private static final class Window extends JNIObject {
static native void open(Window instance, int width, int height);
@Override protected native void disposeNative();
}
private final Window window = new Window();
public GeckoView(Context context) { public GeckoView(Context context) {
super(context); super(context);
init(context, null, true); init(context, null, true);

View File

@@ -66,6 +66,25 @@ public:
template<class Impl> template<class Impl>
constexpr JNINativeMethod GeckoThread::Natives<Impl>::methods[]; constexpr JNINativeMethod GeckoThread::Natives<Impl>::methods[];
template<class Impl>
class GeckoView::Window::Natives : public mozilla::jni::NativeImpl<Window, Impl>
{
public:
static constexpr JNINativeMethod methods[] = {
mozilla::jni::MakeNativeMethod<GeckoView::Window::DisposeNative_t>(
mozilla::jni::NativeStub<GeckoView::Window::DisposeNative_t, Impl>
::template Wrap<&Impl::DisposeNative>),
mozilla::jni::MakeNativeMethod<GeckoView::Window::Open_t>(
mozilla::jni::NativeStub<GeckoView::Window::Open_t, Impl>
::template Wrap<&Impl::Open>)
};
};
template<class Impl>
constexpr JNINativeMethod GeckoView::Window::Natives<Impl>::methods[];
template<class Impl> template<class Impl>
class NativeJSContainer::Natives : public mozilla::jni::NativeImpl<NativeJSContainer, Impl> class NativeJSContainer::Natives : public mozilla::jni::NativeImpl<NativeJSContainer, Impl>
{ {

View File

@@ -938,6 +938,24 @@ auto GeckoThread::State::RUNNING() -> State::LocalRef
return mozilla::jni::Field<RUNNING_t>::Get(nullptr, nullptr); return mozilla::jni::Field<RUNNING_t>::Get(nullptr, nullptr);
} }
constexpr char GeckoView::name[];
constexpr char GeckoView::Window::name[];
constexpr char GeckoView::Window::New_t::name[];
constexpr char GeckoView::Window::New_t::signature[];
auto GeckoView::Window::New() -> Window::LocalRef
{
return mozilla::jni::Constructor<New_t>::Call(nullptr, nullptr);
}
constexpr char GeckoView::Window::DisposeNative_t::name[];
constexpr char GeckoView::Window::DisposeNative_t::signature[];
constexpr char GeckoView::Window::Open_t::name[];
constexpr char GeckoView::Window::Open_t::signature[];
constexpr char RestrictedProfiles::name[]; constexpr char RestrictedProfiles::name[];
constexpr char RestrictedProfiles::IsAllowed_t::name[]; constexpr char RestrictedProfiles::IsAllowed_t::name[];

View File

@@ -2225,6 +2225,93 @@ public:
}; };
class GeckoView : public mozilla::jni::Class<GeckoView>
{
public:
typedef mozilla::jni::Ref<GeckoView> Ref;
typedef mozilla::jni::LocalRef<GeckoView> LocalRef;
typedef mozilla::jni::GlobalRef<GeckoView> GlobalRef;
typedef const mozilla::jni::Param<GeckoView>& Param;
static constexpr char name[] =
"org/mozilla/gecko/GeckoView";
protected:
GeckoView(jobject instance) : Class(instance) {}
public:
class Window;
};
class GeckoView::Window : public mozilla::jni::Class<Window>
{
public:
typedef mozilla::jni::Ref<Window> Ref;
typedef mozilla::jni::LocalRef<Window> LocalRef;
typedef mozilla::jni::GlobalRef<Window> GlobalRef;
typedef const mozilla::jni::Param<Window>& Param;
static constexpr char name[] =
"org/mozilla/gecko/GeckoView$Window";
protected:
Window(jobject instance) : Class(instance) {}
public:
struct New_t {
typedef Window Owner;
typedef Window::LocalRef ReturnType;
typedef Window::Param SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "<init>";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
static auto New() -> Window::LocalRef;
public:
struct DisposeNative_t {
typedef Window Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "disposeNative";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct Open_t {
typedef Window Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
Window::Param,
int32_t,
int32_t> Args;
static constexpr char name[] = "open";
static constexpr char signature[] =
"(Lorg/mozilla/gecko/GeckoView$Window;II)V";
static const bool isStatic = true;
static const bool isMultithreaded = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
template<class Impl> class Natives;
};
class RestrictedProfiles : public mozilla::jni::Class<RestrictedProfiles> class RestrictedProfiles : public mozilla::jni::Class<RestrictedProfiles>
{ {
public: public: