Bug 1365127 - Move history accessors from GeckoAppShell to GlobalHistory; r=droeh

Move checkUriVisited, markUriVisited, and setUriTitle from
GeckoApp/GeckoAppShell to GlobalHistory. Make them static and directly
accessible from native code, so that we can remove those methods from
GeckoInterface.

MozReview-Commit-ID: JrmlfeKibaW
This commit is contained in:
Jim Chen 2017-05-18 18:09:16 -04:00
parent 5412475e7c
commit b5676f0d84
9 changed files with 138 additions and 198 deletions

View File

@ -2959,35 +2959,6 @@ public abstract class GeckoApp extends GeckoActivity
protected void recordStartupActionTelemetry(final String passedURL, final String action) {
}
@Override
public void checkUriVisited(String uri) {
GlobalHistory.getInstance().checkUriVisited(uri);
}
@Override
public void markUriVisited(final String uri) {
final Context context = getApplicationContext();
final BrowserDB db = BrowserDB.from(context);
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GlobalHistory.getInstance().add(context, db, uri);
}
});
}
@Override
public void setUriTitle(final String uri, final String title) {
final Context context = getApplicationContext();
final BrowserDB db = BrowserDB.from(context);
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GlobalHistory.getInstance().update(context.getContentResolver(), db, uri, title);
}
});
}
@Override
public String[] getHandlersForMimeType(String mimeType, String action) {
Intent intent = IntentHelper.getIntentForActionString(action);

View File

@ -11,6 +11,7 @@ import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.reader.ReaderModeUtils;
import org.mozilla.gecko.util.GeckoBundle;
@ -149,7 +150,36 @@ class GlobalHistory {
Telemetry.addToHistogram(TELEMETRY_HISTOGRAM_UPDATE, (int) Math.min(took, Integer.MAX_VALUE));
}
public void checkUriVisited(final String uri) {
@WrapForJNI(stubName = "CheckURIVisited", calledFrom = "gecko")
private static void checkUriVisited(final String uri) {
getInstance().checkVisited(uri);
}
@WrapForJNI(stubName = "MarkURIVisited", calledFrom = "gecko")
private static void markUriVisited(final String uri) {
final Context context = GeckoAppShell.getApplicationContext();
final BrowserDB db = BrowserDB.from(context);
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
getInstance().add(context, db, uri);
}
});
}
@WrapForJNI(stubName = "SetURITitle", calledFrom = "gecko")
private static void setUriTitle(final String uri, final String title) {
final Context context = GeckoAppShell.getApplicationContext();
final BrowserDB db = BrowserDB.from(context);
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
getInstance().update(context.getContentResolver(), db, uri, title);
}
});
}
/* protected */ void checkVisited(final String uri) {
final String storedURI = ReaderModeUtils.stripAboutReaderUrl(uri);
final NotifierRunnable runnable = new NotifierRunnable(GeckoAppShell.getContext());

View File

@ -7,7 +7,7 @@
#include "nsComponentManagerUtils.h"
#include "nsIURI.h"
#include "nsIObserverService.h"
#include "GeneratedJNIWrappers.h"
#include "FennecJNIWrappers.h"
#include "Link.h"
#include "mozilla/Services.h"
@ -76,8 +76,8 @@ nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent)
}
list->AppendElement(aContent);
if (jni::IsAvailable()) {
java::GeckoAppShell::CheckURIVisited(uriString);
if (jni::IsFennec()) {
java::GlobalHistory::CheckURIVisited(uriString);
}
return NS_OK;
@ -199,11 +199,11 @@ nsAndroidHistory::SaveVisitURI(nsIURI* aURI) {
// Add the URI to our cache so we can take a fast path later
AppendToRecentlyVisitedURIs(aURI);
if (jni::IsAvailable()) {
if (jni::IsFennec()) {
// Save this URI in our history
nsAutoCString spec;
(void)aURI->GetSpec(spec);
java::GeckoAppShell::MarkURIVisited(NS_ConvertUTF8toUTF16(spec));
java::GlobalHistory::MarkURIVisited(NS_ConvertUTF8toUTF16(spec));
}
// Finally, notify that we've been visited.
@ -283,7 +283,7 @@ nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle)
return NS_OK;
}
if (jni::IsAvailable()) {
if (jni::IsFennec()) {
nsAutoCString uri;
nsresult rv = aURI->GetSpec(uri);
if (NS_FAILED(rv)) return rv;
@ -292,7 +292,7 @@ nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle)
SaveVisitURI(aURI);
}
NS_ConvertUTF8toUTF16 uriString(uri);
java::GeckoAppShell::SetURITitle(uriString, aTitle);
java::GlobalHistory::SetURITitle(uriString, aTitle);
}
return NS_OK;
}

View File

@ -34,21 +34,6 @@ public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
@Override
public void removeAppStateListener(GeckoAppShell.AppStateListener listener) {}
@Override
public void checkUriVisited(String uri) {
// By default, no URIs are considered visited.
}
@Override
public void markUriVisited(final String uri) {
// By default, no URIs are marked as visited.
}
@Override
public void setUriTitle(final String uri, final String title) {
// By default, no titles are associated with URIs.
}
@Override
public void setAccessibilityEnabled(boolean enabled) {
// By default, take no action when accessibility is toggled on or off.

View File

@ -1666,40 +1666,6 @@ public class GeckoAppShell
public void addAppStateListener(AppStateListener listener);
public void removeAppStateListener(AppStateListener listener);
/**
* Check if the given URI is visited.
* <p/>
* If it has been visited, call {@link GeckoAppShell#notifyUriVisited(String)}. (If it
* has not been visited, do nothing.)
* <p/>
* This method is always invoked on the Gecko thread.
*
* @param uri to check.
*/
public void checkUriVisited(String uri);
/**
* Mark the given URI as visited in Gecko.
* <p/>
* Implementors may maintain some local store of visited URIs in order to be able to
* answer {@link #checkUriVisited(String)} requests affirmatively.
* <p/>
* This method is always invoked on the Gecko thread.
*
* @param uri to mark.
*/
public void markUriVisited(final String uri);
/**
* Set the title of the given URI, as determined by Gecko.
* <p/>
* This method is always invoked on the Gecko thread.
*
* @param uri given.
* @param title to associate with the given URI.
*/
public void setUriTitle(final String uri, final String title);
public void setAccessibilityEnabled(boolean enabled);
public boolean openUriExternal(String targetURI, String mimeType, String packageName, String className, String action, String title);
@ -1863,33 +1829,6 @@ public class GeckoAppShell
return GeckoBatteryManager.getCurrentInformation();
}
@WrapForJNI(stubName = "CheckURIVisited", calledFrom = "gecko")
private static void checkUriVisited(String uri) {
final GeckoInterface geckoInterface = getGeckoInterface();
if (geckoInterface == null) {
return;
}
geckoInterface.checkUriVisited(uri);
}
@WrapForJNI(stubName = "MarkURIVisited", calledFrom = "gecko")
private static void markUriVisited(final String uri) {
final GeckoInterface geckoInterface = getGeckoInterface();
if (geckoInterface == null) {
return;
}
geckoInterface.markUriVisited(uri);
}
@WrapForJNI(stubName = "SetURITitle", calledFrom = "gecko")
private static void setUriTitle(final String uri, final String title) {
final GeckoInterface geckoInterface = getGeckoInterface();
if (geckoInterface == null) {
return;
}
geckoInterface.setUriTitle(uri, title);
}
@WrapForJNI(calledFrom = "gecko")
private static void hideProgressDialog() {
// unused stub

View File

@ -113,14 +113,6 @@ auto GeckoAppShell::CancelVibrate() -> void
return mozilla::jni::Method<CancelVibrate_t>::Call(GeckoAppShell::Context(), nullptr);
}
constexpr char GeckoAppShell::CheckURIVisited_t::name[];
constexpr char GeckoAppShell::CheckURIVisited_t::signature[];
auto GeckoAppShell::CheckURIVisited(mozilla::jni::String::Param a0) -> void
{
return mozilla::jni::Method<CheckURIVisited_t>::Call(GeckoAppShell::Context(), nullptr, a0);
}
constexpr char GeckoAppShell::CloseCamera_t::name[];
constexpr char GeckoAppShell::CloseCamera_t::signature[];
@ -497,14 +489,6 @@ auto GeckoAppShell::LockScreenOrientation(int32_t a0) -> void
return mozilla::jni::Method<LockScreenOrientation_t>::Call(GeckoAppShell::Context(), nullptr, a0);
}
constexpr char GeckoAppShell::MarkURIVisited_t::name[];
constexpr char GeckoAppShell::MarkURIVisited_t::signature[];
auto GeckoAppShell::MarkURIVisited(mozilla::jni::String::Param a0) -> void
{
return mozilla::jni::Method<MarkURIVisited_t>::Call(GeckoAppShell::Context(), nullptr, a0);
}
constexpr char GeckoAppShell::MoveTaskToBack_t::name[];
constexpr char GeckoAppShell::MoveTaskToBack_t::signature[];
@ -563,14 +547,6 @@ auto GeckoAppShell::SetScreenDepthOverride(int32_t a0) -> void
return mozilla::jni::Method<SetScreenDepthOverride_t>::Call(GeckoAppShell::Context(), nullptr, a0);
}
constexpr char GeckoAppShell::SetURITitle_t::name[];
constexpr char GeckoAppShell::SetURITitle_t::signature[];
auto GeckoAppShell::SetURITitle(mozilla::jni::String::Param a0, mozilla::jni::String::Param a1) -> void
{
return mozilla::jni::Method<SetURITitle_t>::Call(GeckoAppShell::Context(), nullptr, a0, a1);
}
constexpr char GeckoAppShell::ShowNotification_t::name[];
constexpr char GeckoAppShell::ShowNotification_t::signature[];

View File

@ -394,26 +394,6 @@ public:
static auto CancelVibrate() -> void;
struct CheckURIVisited_t {
typedef GeckoAppShell Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::String::Param> Args;
static constexpr char name[] = "checkUriVisited";
static constexpr char signature[] =
"(Ljava/lang/String;)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 CheckURIVisited(mozilla::jni::String::Param) -> void;
struct CloseCamera_t {
typedef GeckoAppShell Owner;
typedef void ReturnType;
@ -1336,26 +1316,6 @@ public:
static auto LockScreenOrientation(int32_t) -> void;
struct MarkURIVisited_t {
typedef GeckoAppShell Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::String::Param> Args;
static constexpr char name[] = "markUriVisited";
static constexpr char signature[] =
"(Ljava/lang/String;)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 MarkURIVisited(mozilla::jni::String::Param) -> void;
struct MoveTaskToBack_t {
typedef GeckoAppShell Owner;
typedef void ReturnType;
@ -1585,27 +1545,6 @@ public:
static auto SetScreenDepthOverride(int32_t) -> void;
struct SetURITitle_t {
typedef GeckoAppShell Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::String::Param,
mozilla::jni::String::Param> Args;
static constexpr char name[] = "setUriTitle";
static constexpr char signature[] =
"(Ljava/lang/String;Ljava/lang/String;)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 SetURITitle(mozilla::jni::String::Param, mozilla::jni::String::Param) -> void;
struct ShowNotification_t {
typedef GeckoAppShell Owner;
typedef void ReturnType;

View File

@ -144,6 +144,33 @@ auto GeckoJavaSampler::Unpause() -> void
return mozilla::jni::Method<Unpause_t>::Call(GeckoJavaSampler::Context(), nullptr);
}
const char GlobalHistory::name[] =
"org/mozilla/gecko/GlobalHistory";
constexpr char GlobalHistory::CheckURIVisited_t::name[];
constexpr char GlobalHistory::CheckURIVisited_t::signature[];
auto GlobalHistory::CheckURIVisited(mozilla::jni::String::Param a0) -> void
{
return mozilla::jni::Method<CheckURIVisited_t>::Call(GlobalHistory::Context(), nullptr, a0);
}
constexpr char GlobalHistory::MarkURIVisited_t::name[];
constexpr char GlobalHistory::MarkURIVisited_t::signature[];
auto GlobalHistory::MarkURIVisited(mozilla::jni::String::Param a0) -> void
{
return mozilla::jni::Method<MarkURIVisited_t>::Call(GlobalHistory::Context(), nullptr, a0);
}
constexpr char GlobalHistory::SetURITitle_t::name[];
constexpr char GlobalHistory::SetURITitle_t::signature[];
auto GlobalHistory::SetURITitle(mozilla::jni::String::Param a0, mozilla::jni::String::Param a1) -> void
{
return mozilla::jni::Method<SetURITitle_t>::Call(GlobalHistory::Context(), nullptr, a0, a1);
}
const char MemoryMonitor::name[] =
"org/mozilla/gecko/MemoryMonitor";

View File

@ -423,6 +423,79 @@ public:
template<class Impl> class Natives;
};
class GlobalHistory : public mozilla::jni::ObjectBase<GlobalHistory>
{
public:
static const char name[];
explicit GlobalHistory(const Context& ctx) : ObjectBase<GlobalHistory>(ctx) {}
struct CheckURIVisited_t {
typedef GlobalHistory Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::String::Param> Args;
static constexpr char name[] = "checkUriVisited";
static constexpr char signature[] =
"(Ljava/lang/String;)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 CheckURIVisited(mozilla::jni::String::Param) -> void;
struct MarkURIVisited_t {
typedef GlobalHistory Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::String::Param> Args;
static constexpr char name[] = "markUriVisited";
static constexpr char signature[] =
"(Ljava/lang/String;)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 MarkURIVisited(mozilla::jni::String::Param) -> void;
struct SetURITitle_t {
typedef GlobalHistory Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::String::Param,
mozilla::jni::String::Param> Args;
static constexpr char name[] = "setUriTitle";
static constexpr char signature[] =
"(Ljava/lang/String;Ljava/lang/String;)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 SetURITitle(mozilla::jni::String::Param, mozilla::jni::String::Param) -> void;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::GECKO;
};
class MemoryMonitor : public mozilla::jni::ObjectBase<MemoryMonitor>
{
public: