Bug 1365122 - Move launchOrBringToFront from GeckoAppShell to GeckoApp; r=droeh

Move GeckoAppShell.launchOrBringToFront to GeckoApp, so that we can use
GeckoActivityMonitor to check whether BrowserApp is the current
foreground Activity. This lets us remove GeckoInterface.isForegrounded.

MozReview-Commit-ID: CgjnaNK8OGW
This commit is contained in:
Jim Chen 2017-05-18 18:09:04 -04:00
Родитель 91d00481cb
Коммит 9fe9e6e1c3
9 изменённых файлов: 48 добавлений и 52 удалений

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

@ -34,7 +34,7 @@
#include "nsWeakReference.h"
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidBridge.h"
#include "FennecJNIWrappers.h"
#endif
using namespace mozilla;
@ -554,7 +554,9 @@ public:
#ifdef MOZ_WIDGET_ANDROID
// This fires an intent that will start launching Fennec and foreground it,
// if necessary.
java::GeckoAppShell::LaunchOrBringToFront();
if (jni::IsFennec()) {
java::GeckoApp::LaunchOrBringToFront();
}
#endif
nsCOMPtr<nsPIDOMWindowOuter> window;
@ -596,7 +598,7 @@ public:
return NS_OK;
}
#ifdef MOZ_WIDGET_ANDROID
else if (rv == NS_ERROR_NOT_AVAILABLE) {
else if (rv == NS_ERROR_NOT_AVAILABLE && jni::IsFennec()) {
// We couldn't get a browser window, so Fennec must not be running.
// Send an Intent to launch Fennec and wait for "BrowserChrome:Ready"
// to try opening a window again.

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

@ -2390,9 +2390,21 @@ public abstract class GeckoApp extends GeckoActivity
return GeckoScreenOrientation.getInstance().getAndroidOrientation();
}
@Override
public boolean isForegrounded() {
return foregrounded;
@WrapForJNI(calledFrom = "gecko")
public static void launchOrBringToFront() {
final Activity activity = GeckoActivityMonitor.getInstance().getCurrentActivity();
// Check that BrowserApp is not the current foreground activity.
if (activity instanceof BrowserApp && ((GeckoApp) activity).foregrounded) {
return;
}
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
GeckoAppShell.getApplicationContext().startActivity(intent);
}
@Override

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

@ -725,7 +725,7 @@ public class Tabs implements BundleEventListener {
} else if ("Tab:Select".equals(event)) {
if (message.getBoolean("foreground", false)) {
GeckoAppShell.launchOrBringToFront();
GeckoApp.launchOrBringToFront();
}
selectTab(tab.getId());

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

@ -82,9 +82,4 @@ public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
// By default, use the GeckoView-specific chrome URI.
return "chrome://geckoview/content/geckoview.xul";
}
@Override
public boolean isForegrounded() {
return false;
}
}

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

@ -280,18 +280,6 @@ public class GeckoAppShell
CRASH_HANDLER.uncaughtException(null, e);
}
@WrapForJNI
public static void launchOrBringToFront() {
GeckoInterface gi = getGeckoInterface();
if (gi == null || !gi.isForegrounded()) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
getApplicationContext().startActivity(intent);
}
}
private static float getLocationAccuracy(Location location) {
float radius = location.getAccuracy();
return (location.hasAccuracy() && radius > 0) ? radius : 1001;
@ -1688,7 +1676,6 @@ public class GeckoAppShell
public void disableOrientationListener();
public void addAppStateListener(AppStateListener listener);
public void removeAppStateListener(AppStateListener listener);
public boolean isForegrounded();
/**
* Create a shortcut -- generally a home-screen icon -- linking the given title to the given URI.

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

@ -489,14 +489,6 @@ auto GeckoAppShell::KillAnyZombies() -> void
return mozilla::jni::Method<KillAnyZombies_t>::Call(GeckoAppShell::Context(), nullptr);
}
constexpr char GeckoAppShell::LaunchOrBringToFront_t::name[];
constexpr char GeckoAppShell::LaunchOrBringToFront_t::signature[];
auto GeckoAppShell::LaunchOrBringToFront() -> void
{
return mozilla::jni::Method<LaunchOrBringToFront_t>::Call(GeckoAppShell::Context(), nullptr);
}
constexpr char GeckoAppShell::LoadPluginClass_t::name[];
constexpr char GeckoAppShell::LoadPluginClass_t::signature[];

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

@ -1316,25 +1316,6 @@ public:
static auto KillAnyZombies() -> void;
struct LaunchOrBringToFront_t {
typedef GeckoAppShell Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "launchOrBringToFront";
static constexpr char signature[] =
"()V";
static const bool isStatic = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::ANY;
static const mozilla::jni::DispatchTarget dispatchTarget =
mozilla::jni::DispatchTarget::CURRENT;
};
static auto LaunchOrBringToFront() -> void;
struct LoadPluginClass_t {
typedef GeckoAppShell Owner;
typedef mozilla::jni::Class::LocalRef ReturnType;

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

@ -52,6 +52,14 @@ auto GeckoApp::AddPluginView(mozilla::jni::Object::Param a0) -> void
return mozilla::jni::Method<AddPluginView_t>::Call(GeckoApp::Context(), nullptr, a0);
}
constexpr char GeckoApp::LaunchOrBringToFront_t::name[];
constexpr char GeckoApp::LaunchOrBringToFront_t::signature[];
auto GeckoApp::LaunchOrBringToFront() -> void
{
return mozilla::jni::Method<LaunchOrBringToFront_t>::Call(GeckoApp::Context(), nullptr);
}
constexpr char GeckoApp::OnFullScreenPluginHidden_t::name[];
constexpr char GeckoApp::OnFullScreenPluginHidden_t::signature[];

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

@ -156,6 +156,25 @@ public:
static auto AddPluginView(mozilla::jni::Object::Param) -> void;
struct LaunchOrBringToFront_t {
typedef GeckoApp Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "launchOrBringToFront";
static constexpr char signature[] =
"()V";
static const bool isStatic = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::GECKO;
static const mozilla::jni::DispatchTarget dispatchTarget =
mozilla::jni::DispatchTarget::CURRENT;
};
static auto LaunchOrBringToFront() -> void;
struct OnFullScreenPluginHidden_t {
typedef GeckoApp Owner;
typedef void ReturnType;