When page option 'add page shortcut' is clicked, creating a shortcut(not PWA) on launcher.
Also make sure that heavy tasks are executed in background thread.
MozReview-Commit-ID: 8KtwdXENtEd
Instead of using `getLayerView()` to perform haptic feedback, this patch
adds a `HapticFeedbackDelegate`, which `GeckoApplication` implements to
call `performHapticFeedback()` on the active view. Also, use
HapticFeedbackDelegate elsewhere in the Fennec codebase where we want to
perform haptic feedback.
MozReview-Commit-ID: GAArA6yJFNF
Instead of using `getLayerView()` to perform haptic feedback, this patch
adds a `HapticFeedbackDelegate`, which `GeckoApplication` implements to
call `performHapticFeedback()` on the active view. Also, use
HapticFeedbackDelegate elsewhere in the Fennec codebase where we want to
perform haptic feedback.
MozReview-Commit-ID: GAArA6yJFNF
Move the "Share:Text" event listener from GeckoApp to GeckoApplication,
so ActionBarHandler.js can use it for the Share action from any window.
MozReview-Commit-ID: 8w1llJy4pwy
Right now we have two Snackbar handlers in GeckoApp and
GeckoPreferences, respectively. This patch combines the two handlers
into one inside GeckoApplication, and lets us display Snackbars in other
Activities like custom tabs and PWA.
MozReview-Commit-ID: Iu6p2VNnVVC
Instead of initializing IntentHelper in GeckoApp, initialize it in
GeckoApplication, and make it available globally. This will let custom
tabs / PWA use IntentHelper-provided services.
MozReview-Commit-ID: Icedph6KG4u
Move the check permission event from `GeckoApp` to `GeckoApplication`,
and use the current activity if possible, so that we can use
`RuntimePermissions` in custom tabs and PWA. Also implement
`onRequestPermissionsResult` for custom tabs and PWA, in order to
forward the result back to `RuntimePermissions`.
MozReview-Commit-ID: Bg4BoXAUCz6
This patch includes some "pre" work, which should have been a separate patch (my apologies!):
- telemetry ping is (needlessly) coupled with information about where it should
be uploaded. It wasn't a problem before, since core pings are "upload right away",
and are never bundled together during an upload. However, for sync ping, we need to
bundle a bunch of "syncs" and "events" (down the road) into one single "sync ping", and as such
we need a separate representation for a "ping that is not meant to be uploaded directly".
- instead of dealing with the coupling directly, a simpler approach is taken:
- a "ping" is split into two types of pings: local and outgoing
- outgoing ping is what the old "ping" was - a data bundle that is ready to be uploaded
- local ping is not meant to be uploaded directly, but is intended to be a part of an
outgoing ping, along with other local pings
- the main difference between local and outgoing pings is the URL: local pings don't have
it while outgoing pings do have it.
As background telemetry is received via LocalBroadcastManager, it is processed as follows:
- telemetry data is processed into "local pings" which are stored on disk
- as enough telemetry is gathered, or we hit one of "let's upload now" conditions, the
persisted local pings are gathered into an "outgoing ping" via a SyncPingBundleBuilder,
which is persisted on disk.
- upload of the bundled "sync ping" is attempted
- as individual "local pings" are processed into outgoing "Sync ping" bundles, they are removed
from disk
Hooks for the upcoming event telemetry data are in place to make that follow-up work easier.
MozReview-Commit-ID: 6uXi6pjXiSv
At the moment, we forward these from GeckoActivity, which means that they won't work if no GeckoActivity-based activity is active (can happen within our settings for example).
As of API14, we can now register an app-wide ComponentCallbacks(2) class, allowing us to easily receive low memory notifications no matter which activity is currently alive.
MozReview-Commit-ID: 5GjSjsTKxAD
Now that GeckoInterface only contains openUriExternal and
getHandlersFor* methods, we can set GeckoInterface from GeckoApplication
only, and not GeckoApp or GeckoView. This also lets us get rid of
BaseGeckoInterface.
MozReview-Commit-ID: KQloIO6ITlK
We want to do certain things on the Gecko side when our app goes into the background (being prepared for being killed without further ado [1], setting tab visibility status, ...) or comes back into the foreground.
At the moment, this works by having participating activities manually call into GeckoApplication from onPause()/onResume(), from where we then forward this to Gecko as appropriate. There also is some additional logic because we want to avoid triggering a background-/foreground-notification combo each time we switch activities *within* Firefox, e.g. when going from BrowserApp into our settings, or navigating within the settings themselves.
The problem with the current implementation is that we basically need to second guess whether we were opening one of our own activities or not when an onPause() call comes in and that we have to keep remembering the assumptions made there when implementing new activities.
E.g. currently we assume that if an activity is finishing during onPause(), we're not leaving the app and therefore never trigger an application-background notification. Until recently, this was correct because except for quitting the app [2], we only finished activities when going backwards through our settings menu, from which we would only end up back in our main activity. With the advent of custom tabs, this is no longer correct, as we have to finish those as well when going back - and in that case we're returning to the app that originally created the custom tab, so we ought to send an application-background notification in fact.
With this patch, we therefore switch our approach and base our background-/foreground tracking on watching onStop() instead. While unlike onPause(), onStop() has the slight drawback of not being absolutely guaranteed to be called before Android possibly kills us, the big advantage is that because of the normal Android lifecycle event order [3], by the time onStop for the previous activity is called we know for sure whether another activity of our own has been launched or whether we're being sent into the background.
Additionally, using an ActivityLifecycleCallbacks instance makes it easy to monitor *all* onStop/onStart calls in our app without requiring any special support from our activities.
[1] E.g. cleanly shutting down the cache service, flushing pending session store writes...
[2] In which case Gecko would be shutting down on its own anyway, so a missing application-background notification wouldn't matter.
[3] Old activity onPause, new activity onCreate, onStart, onResume, old activity onStop, onDestroy.
MozReview-Commit-ID: 4QEUMz6NLfV
Move shortcut creation code in GeckoApp to GeckoApplication, and make
the methods static so that we can call them without a GeckoInterface
instance. This lets us remove GeckoInterface.createShortcut.
MozReview-Commit-ID: AUnQGI02Bk
There are two callers of isOfficial() in GeckoThread. For purging the
startup cache, the code to add the extra argument is moved to
GeckoApplication/GeckoApp/GeckoService. For logging the arguments, the
"debug" flag is used instead of the "official" flag.
MozReview-Commit-ID: 9atEWY1MVVt
Move the code that actually performs shutdown from BrowserApp to
GeckoApplication, so we can shutdown even without an active BrowserApp.
From inside GeckoApp/BrowserApp, all shutdown now go through
finishAndShutdown(), which destroys the Activity before shutting down.
Currently, we basically take a snapshot of the currently selected tab when pausing an activity and then later re-select that tab ID when switching back from another activity within our application. In practice, this doesn't seem entirely fool-proof, so when switching between our normal UI (BrowserApp) and custom tabs or web apps we can eventually end up with the wrong tab being selected in the wrong activity.
In this part, we'll rip out the current code and replace it by a new implementation for BrowserApp - following parts will then cover custom tabs and web apps.
As BrowserApp is our normal tabbed browsing interface, we can simply track all tab switches for BROWSING-type tabs as they happen, which ensures that our data is always up-to-date.
Because tab IDs remain unique only within the same application session and are reused if we're terminated and then later restart, we need to take additional precautions to make sure we're really selecting the correct tab object - the savedInstanceState can carry even across (OOM-)kills. Therefore we now additionally also store and compare the current per-session UUID to make sure that the tab we're trying to select is really the same one it was when the activity was last running.
For BrowserApp caring about this is less important because on a full startup, the selection behaviour will be overridden by session restore anyway (although we can still hit it if only BrowserApp gets destroyed while Gecko keeps running, or if BrowserApp is launched after some other activity has already loaded Gecko), but it'll be quite relevant for web apps and custom tabs which don't have that benefit.
As it stands, this patch temporarily breaks behaviour around activity restoring for custom tabs/web apps, but tearing the old implementation out in one go was easier and the patch needs to be split somewhere.
MozReview-Commit-ID: I0Tq9XZGvpV
Required because later on, we'll need to know if we're in the correct activity for a tab or need to switch activities.
As a follow-up, we can later also hook up our current manual activity tracking from GeckoApplication to this (we most probably won't be able to get rid of the GeckoActivityStatus shenanigans, though).
MozReview-Commit-ID: 5lZrAMsB9Gy
The state of the switch added in Part 4 is stored in our Android-side shared preferences. For this to have any actual effect on rendering, we now add a class that is initialised when Gecko starts up and listens to changes of that particular pref.
When it is turned on, we enable font inflation and add another listener for the system font scale, which then forwards the current font scale as well as any changes to Gecko, so mobile mode pages can be scaled correspondingly as well.
When the setting is turned back off again, the system font scale listener is stopped again and the Gecko font size settings reverted back to their default values.
MozReview-Commit-ID: GyffpZTQQX8
Launching a new activity within our app triggers both onActivityPause() (the current activity) and onActivityResume() (the new activity) in GeckoApplication. The most prominent example at the moment are probably our preferences - entering/exiting/navigating within them always triggers a pause/resume combo. This means that currently each time this happens, the network manager is stopped only to be immediately restarted.
To prevent this, we now stop the network manager only when Gecko is actually being paused. In order to avoid unmatched start/stop calls, we need to treat the calls to start() similarly and provide an additional code path for the initial call to start() immediately after startup.
Since the BatteryManager is only started and currently never stopped, we can use this for its startup, too, so as to avoid duplicated calls to its start() method.
MozReview-Commit-ID: 6NdScT5cLYL
Launching a new activity within our app triggers both onActivityPause() (the current activity) and onActivityResume() (the new activity) in GeckoApplication. The most prominent example at the moment are probably our preferences - entering/exiting/navigating within them always triggers a pause/resume combo. This means that currently each time this happens, the network manager is stopped only to be immediately restarted.
To prevent this, we now stop the network manager only when Gecko is actually being paused. In order to avoid unmatched start/stop calls, we need to treat the calls to start() similarly and provide an additional code path for the initial call to start() immediately after startup.
Since the BatteryManager is only started and currently never stopped, we can use this for its startup, too, so as to avoid duplicated calls to its start() method.
MozReview-Commit-ID: 6NdScT5cLYL
Previously we started the DLC service from GeckoApplication. The reason for that was that we wanted to
download content like fonts as early as possible so that they are available the next time we display
a website.
However we do not know whether we are running in automation until the BrowserApp activity is launched.
This patch will start the service from BrowserApp.onCreate() now if we are not running in automation.
MozReview-Commit-ID: C3Ob6S3yve4
Bug 1307820 - 1a. Move GeckoApp EventDispatcher to GeckoView; r=snorp
Make it a GeckoView-specific EventDispatcher instead of
GeckoApp-specific, so that GeckoView consumers can benefit from a
per-view EventDispatcher. In addition, a few events like Gecko:Ready are
moved back to the global EventDispatcher because that makes more sense.
Bug 1307820 - 1b. Don't use GeckoApp EventDispatcher during inflation; r=snorp
During layout inflation, we don't yet have GeckoView and therefore the
GeckoView EventDispatcher, so we should not register events until later,
typically during onAttachedToWindow.
Bug 1307820 - 2. Introduce GeckoBundle; r=snorp
The Android Bundle class has several disadvantages when used for holding
structured data from JS.
The most obvious one is the differentiation between int and double,
which doesn't exist in JS. So when a JS number is converted to either a
Bundle int or double, we run the risk of making a wrong conversion,
resulting in a type mismatch exception when Java uses the Bundle. This
extends to number arrays from JS.
There is one more gotcha when using arrays. When we receive an empty
array from JS, there is no way for us to determine the type of the
array, because even empty arrays in Java have types. We are forced to
pick an arbitrary type like boolean[], which can easily result in a type
mismatch exception when using the array on the Java side.
In addition, Bundle is fairly cumbersome, and we cannot access the inner
structures of Bundle from Java or JNI, making it harder to use.
With these factors in mind, this patch introduces GeckoBundle as a
better choice for Gecko/Java communication. It is almost fully
API-compatible with the Android Bundle; only the Bundle array methods
are different. It resolves the numbers problem by performing conversions
if necessary, and it is a lot more lightweight than Bundle.
Bug 1307820 - 3. Convert BundleEventListener to use GeckoBundle; r=snorp
Convert BundleEventListener from using Bundle to using GeckoBundle.
Because NativeJSContainer still only supports Bundle, we do an extra
conversion when sending Bundle messages, but eventually, as we eliminate
the use of NativeJSContainer, that will go away as well.
Bug 1307820 - 4. Introduce EventDispatcher interfaces; r=snorp
Introduce several new XPCOM interfaces for the new EventDispatcher API,
these interfaces are mostly mirrored after their Java counterparts.
* nsIAndroidEventDispatcher is the main interface for
registering/unregistering listeners and for dispatching events from
JS/C++.
* nsIAndroidEventListener is the interface that JS/C++ clients implement
to receive events.
* nsIAndroidEventCallback is the interface that JS/C++ clients implement
to receive responses from dispatched events.
* nsIAndroidView is the new interface that every window receives
that is specific to the window/GeckoView pair. It is passed to chrome
scripts through window arguments.
Bug 1307820 - 5. Remove EventDispatcher references from gfx code; r=snorp
EventDispatcher was used for JPZC, but NPZC doesn't use it anymore.
Bug 1307820 - 6. General JNI template improvements; r=snorp
This patch includes several improvements to the JNI templates.
* Context::RawClassRef is removed to avoid misuse, as Context::ClassRef
should be used instead.
* Fix a compile error, in certain usages, in the DisposeNative overload
in NativeStub.
* Add Ref::IsInstanceOf and Context::IsInstanceOf to mirror the
JNIEnv::IsInstanceOf call.
* Add Ref::operator* and Context::operator* to provide an easy way to
get a Context object.
* Add built-in declarations for boxed Java objects (e.g. Boolean,
Integer, etc).
* Add ObjectArray::New for creating new object arrays of specific types.
* Add lvalue qualifiers to LocalRef::operator= and GlobalRef::operator=,
to prevent accidentally assigning to rvalues. (e.g.
`objectArray->GetElement(0) = newObject;`, which won't work as intended.)
Bug 1307820 - 7. Support ownership through RefPtr for native JNI objects; r=snorp
In addition to direct ownership and weak pointer ownership, add a third
ownership model where a native JNI object owns a RefPtr that holds a
strong reference to the actual C++ object. This ownership model works
well with ref-counted objects such as XPCOM objects, and is activated
through the presence of public members AddRef() and Release() in the C++
object.
Bug 1307820 - 8. Implement Gecko-side EventDispatcher; r=snorp
Add a skeletal implementation of EventDispatcher on the Gecko side.
Each widget::EventDispatcher will be associated with a Java
EventDispatcher, so events can be dispatched from Gecko to Java and vice
versa. AndroidBridge and nsWindow will implement
nsIAndroidEventDispatcher through widget::EventDispatcher.
Other patches will add more complete functionality such as
GeckoBundle/JSObject translation and support for callbacks.
Bug 1307820 - 9. Implement dispatching between Gecko/Java; r=snorp
Implement translation between JSObject and GeckoBundle, and use that for
dispatching events from Gecko to Java and vice versa.
Bug 1307820 - 10. Implement callback support; r=snorp
Implement callback support for both Gecko-to-Java events and
Java-to-Gecko events.
For Gecko-to-Java, we translate nsIAndroidEventCallback to a Java
EventCallback through NativeCallbackDelegate and pass it to the Java
listener.
For Java-to-Gecko, we translate EventCallback to a
nsIAndroidEventCallback through JavaCallbackDelegate and pass it to the
Gecko listener. There is another JavaCallbackDelegate on the Java side
that redirects the callback to a particular thread. For example, if the
event was dispatched from the UI thread, we make sure the callback
happens on the UI thread as well.
Bug 1307820 - 11. Add BundleEventListener support for Gecko thread; r=snorp
Add support for BundleEventListener on the Gecko thread, so that we can
use it to replace any existing GeckoEventListener or NativeEventListener
implementations that require the listener be run synchronously on the
Gecko thread.
Bug 1307820 - 12. Add global EventDispatcher in AndroidBridge; r=snorp
Add an instance of EventDispatcher to AndroidBridge to act as a global
event dispatcher.
Bug 1307820 - 13. Add per-nsWindow EventDispatcher; r=snorp
Add an instance of EventDispatcher to each nsWindow through an
AndroidView object, which implements nsIAndroidView. The nsIAndroidView
is passed to the chrome script through the window argument when opening
the window.
Bug 1307820 - 14. Update auto-generated bindings; r=me
Bug 1307820 - 15. Update testEventDispatcher; r=snorp
Update testEventDispatcher to include new functionalities in
EventDisptcher.
* Add tests for dispatching events to UI/background thread through
nsIAndroidEventDispatcher::dispatch.
* Add tests for dispatching events to UI/background thread through
EventDispatcher.dispatch.
* Add tests for dispatching events to Gecko thread through
EventDispatcher.dispatch.
Each kind of test exercises both the global EventDispatcher through
EventDispatcher.getInstance() and the per-GeckoView EventDispatcher
through GeckoApp.getEventDispatcher().
We only extract metadata that we'd want to store. For now this is just image_url.
In case we try to store page metadata before corresponding history record has been inserted,
we queue up metadata and wait for an event from GlobalHistory letting us know that history
record is now available, at which point we try inserting metadata again.
MozReview-Commit-ID: 2FpIqc6uHMb
Bug 1305498 - 1. Remove NotificationClient task queue; r=sebastian
Not sure why we needed a task queue for NotificationClient actions. The
actions all go through IPC and are non-blocking, so it's perfectly fine
to perform them off of whatever thread we're on.
Bug 1305498 - 2. Integrate NotificationHandler et al into NotificationCllient; r=sebastian
There's no reason to have NotificationHandler, AppNotificationClient,
and ServiceNotificationClient all separate from the base
NotificationClient class. This patch adds the functionality of
those three classes to NotificationClient.
The notifications hash map is changed from a ConcurrentHashMap to a
regular HashMap with synchronization because I think the use case here
doesn't warrant the added performance and overhead of ConcurrentHashMap.
NotificationService is changed to match the new NotificationClient. Now
the only job for NotificationService is to set a notification as
foreground, rather than to manage all notifications like before.
NotificationHandler, AppNotificationClient, and
ServiceNotificationClient will be removed in a later patch.
Bug 1305498 - 3. Set NotificationListener in GeckoApplication; r=sebastian
Set NotificationListener once in GeckoApplication.onCreate, instead of
spreading it out in GeckoApp, BrowserApp, and GeckoService. This is
possible because there's no longer a distinction between
AppNotificationClient and ServiceNotificationClient in the new,
consolidated NotificationClient.
Bug 1305498 - 4. Remove obsolete notification classes; r=sebastian
Remove AppNotificationClient, ServiceNotificationClient, and
NotificationHandler, now that they've all been replaced by the new,
consolidated NotificationClient.
Bug 1305498 - 5. Use NotificationReceiver for web notification callbacks; r=sebastian
Previously, web notification callbacks went to GeckoApp directly, but
that presented some problems such as not being able to implement the
on-close callback, because we don't want to launch GeckoApp when the
notification is closed by swiping. This patch makes us use
NotificationReceiver for callbacks, and let NotificationReceiver launch
GeckoApp if necessary.
Bug 1305498 - 6. Don't keep notification cookie in native code; r=sebastian
Keep the notification cookie a single location (in the notification
intent itself), and simplify the native notification handling code.
Bug 1305498 - 7. Use NotificationReceiver for persistent notifications; r=sebastian
Currently, persistent notification callbacks go through a different code
path, but it'd be more consistent and correct to let persistent
notification callbacks go through NotificationReceiver as well.
This takes care of some housekeeping work that was missing for
persistent notifications, such as deleting the mNotifications entry when
the notification is closed.
Instead of using NotificationClient directly from GeckoAppShell, add a
NotificationListener interface, which NotificationClient would
implement. This isolates NotificationClient (and the notification
package) from GeckoAppShell and lets us move the notification package to
Fennec. It also makes a cleaner interface for GeckoView consumers to
implement notification support.
Remove references to BrowserDB and its factory from GeckoProfile.
Instead of keeping the DB in mDB, GeckoProfile now keeps an arbitrary
object in mData. Using a data object lets us avoid needing another map
to map profiles to DBs. This feature could be very useful for GeckoView
consumers as well.
The new way to get a BrowserDB from a profile/context is through
BrowserDB.from(Context) or BrowserDB.from(GeckoProfile), which takes
care of creating a local DB if necessary and associating the DB with the
profile.
Use application context for delayed callbacks to prevent leaking the
BrowserApp instance. Also, use application context for accessing
Distribution, to prevent leaking old BrowserApp instances, and to avoid
using a destroyed Context. Finally, attach AudioFocusAgent to the
application context instead of the BrowserApp context to avoid leaking
BrowserApp.
Move registration of AccessibilityManager listeners to GeckoApplication,
and change all Context references to the application context, so that
GeckoAccessibility doesn't leak old BrowserApp instances as new
BrowserApp instances are created.
Moved notification classes to notification folder. Refactored uses which added
imports to some Gecko classes as well as the Notification classes. Added getter
to GeckoAppShell for access to static NotificationClient. Changed paths in
AndroidManifest.xml.in to reflect changes.
MozReview-Commit-ID: 2CUJa0YsV1V
I initially tested my code with a branch around the multidex dependency:
if (mozconfig.substs.MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE) {
compile ...multidex...
}
I removed it because it seemed unnecessary - the code shouldn't be
included if it's not referenced.
I tested:
* Locally with a build that did not exceed the method limit, pre-Lollipop
* On try, with fx-team
* On try, with beta
MozReview-Commit-ID: APaOdlKd3QF