2018-11-29 13:30:46 +03:00
|
|
|
/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2013-08-02 11:04:22 +04:00
|
|
|
#include "nsAppShell.h"
|
|
|
|
|
2011-10-29 14:35:29 +04:00
|
|
|
#include "base/basictypes.h"
|
2012-06-14 20:08:51 +04:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/task.h"
|
2012-01-17 22:40:39 +04:00
|
|
|
#include "mozilla/Hal.h"
|
2013-08-02 11:04:22 +04:00
|
|
|
#include "nsIScreen.h"
|
|
|
|
#include "nsIScreenManager.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "nsWindow.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2010-06-18 21:42:51 +04:00
|
|
|
#include "nsICommandLineRunner.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIAppStartup.h"
|
2010-06-05 01:14:43 +04:00
|
|
|
#include "nsIGeolocationProvider.h"
|
2012-04-17 21:29:52 +04:00
|
|
|
#include "nsCacheService.h"
|
2012-04-24 23:13:36 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2012-06-07 06:39:01 +04:00
|
|
|
#include "nsIDOMWakeLockListener.h"
|
|
|
|
#include "nsIPowerManagerService.h"
|
2015-08-20 01:14:47 +03:00
|
|
|
#include "nsISpeculativeConnect.h"
|
|
|
|
#include "nsIURIFixup.h"
|
2014-07-12 01:15:39 +04:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2015-08-20 01:14:47 +03:00
|
|
|
#include "nsCDefaultURIFixup.h"
|
2015-09-18 16:17:10 +03:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2016-07-08 18:39:10 +03:00
|
|
|
#include "nsGeoPosition.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2016-12-21 21:37:20 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
2010-06-18 01:33:15 +04:00
|
|
|
#include "mozilla/Services.h"
|
2011-06-07 11:38:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-10-29 14:35:29 +04:00
|
|
|
#include "mozilla/Hal.h"
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2017-11-10 18:20:04 +03:00
|
|
|
#include "mozilla/intl/OSPreferences.h"
|
2018-07-27 21:24:49 +03:00
|
|
|
#include "mozilla/widget/ScreenManager.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2013-11-12 22:41:01 +04:00
|
|
|
#include "AndroidBridgeUtilities.h"
|
2015-08-20 01:14:47 +03:00
|
|
|
#include "GeneratedJNINatives.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include <android/log.h>
|
|
|
|
#include <pthread.h>
|
2011-02-27 18:50:56 +03:00
|
|
|
#include <wchar.h>
|
2012-02-22 20:35:25 +04:00
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-01-06 04:14:23 +04:00
|
|
|
#ifdef MOZ_ANDROID_HISTORY
|
2012-11-09 13:55:59 +04:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIURI.h"
|
2012-11-09 13:55:59 +04:00
|
|
|
#include "IHistory.h"
|
2012-01-06 04:14:23 +04:00
|
|
|
#endif
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
#ifdef MOZ_LOGGING
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2016-08-19 01:04:11 +03:00
|
|
|
#endif
|
|
|
|
|
2016-08-04 16:17:54 +03:00
|
|
|
#include "AndroidAlerts.h"
|
2016-12-01 01:59:57 +03:00
|
|
|
#include "AndroidUiThread.h"
|
2015-08-13 07:53:40 +03:00
|
|
|
#include "ANRReporter.h"
|
2016-08-19 01:04:11 +03:00
|
|
|
#include "GeckoBatteryManager.h"
|
2016-07-21 04:44:48 +03:00
|
|
|
#include "GeckoNetworkManager.h"
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
#include "GeckoProcessManager.h"
|
2016-07-21 04:44:48 +03:00
|
|
|
#include "GeckoScreenOrientation.h"
|
2018-09-15 13:03:29 +03:00
|
|
|
#include "GeckoSystemStateListener.h"
|
2017-11-01 02:40:41 +03:00
|
|
|
#include "GeckoVRManager.h"
|
2015-09-28 19:07:10 +03:00
|
|
|
#include "PrefsHelper.h"
|
2018-11-13 17:29:21 +03:00
|
|
|
#include "ScreenHelperAndroid.h"
|
|
|
|
#include "Telemetry.h"
|
2016-09-16 22:13:48 +03:00
|
|
|
#include "fennec/MemoryMonitor.h"
|
|
|
|
#include "fennec/ThumbnailHelper.h"
|
2018-10-18 16:28:09 +03:00
|
|
|
#include "WebExecutorSupport.h"
|
2015-08-13 07:53:40 +03:00
|
|
|
|
2011-08-29 22:29:39 +04:00
|
|
|
#ifdef DEBUG_ANDROID_EVENTS
|
2010-06-04 00:56:36 +04:00
|
|
|
#define EVLOG(args...) ALOG(args)
|
|
|
|
#else
|
|
|
|
#define EVLOG(args...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2018-07-27 21:24:49 +03:00
|
|
|
using namespace mozilla::widget;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIGeolocationUpdate *gLocationCallback = nullptr;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2015-12-24 06:03:35 +03:00
|
|
|
nsAppShell* nsAppShell::sAppShell;
|
2016-01-13 22:35:27 +03:00
|
|
|
StaticAutoPtr<Mutex> nsAppShell::sAppShellLock;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2016-12-21 21:37:20 +03:00
|
|
|
uint32_t nsAppShell::Queue::sLatencyCount[];
|
|
|
|
uint64_t nsAppShell::Queue::sLatencyTime[];
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsAppShell, nsBaseAppShell, nsIObserver)
|
2010-12-22 00:28:45 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class WakeLockListener final : public nsIDOMMozWakeLockListener {
|
2014-08-26 23:07:59 +04:00
|
|
|
private:
|
|
|
|
~WakeLockListener() {}
|
|
|
|
|
|
|
|
public:
|
2012-06-07 06:39:01 +04:00
|
|
|
NS_DECL_ISUPPORTS;
|
|
|
|
|
2015-08-15 05:06:20 +03:00
|
|
|
nsresult Callback(const nsAString& topic, const nsAString& state) override {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoAppShell::NotifyWakeLockChanged(topic, state);
|
2012-06-07 06:39:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(WakeLockListener, nsIDOMMozWakeLockListener)
|
2012-07-30 18:20:58 +04:00
|
|
|
nsCOMPtr<nsIPowerManagerService> sPowerManagerService = nullptr;
|
2013-08-13 17:32:03 +04:00
|
|
|
StaticRefPtr<WakeLockListener> sWakeLockListener;
|
2012-06-07 06:39:01 +04:00
|
|
|
|
2016-04-06 04:43:41 +03:00
|
|
|
|
|
|
|
class GeckoThreadSupport final
|
2016-07-21 20:49:04 +03:00
|
|
|
: public java::GeckoThread::Natives<GeckoThreadSupport>
|
2015-08-20 01:14:47 +03:00
|
|
|
{
|
2016-09-12 20:43:08 +03:00
|
|
|
// When this number goes above 0, the app is paused. When less than or
|
|
|
|
// equal to zero, the app is resumed.
|
|
|
|
static int32_t sPauseCount;
|
2016-04-06 04:43:41 +03:00
|
|
|
|
2015-08-20 01:14:47 +03:00
|
|
|
public:
|
2016-07-21 04:43:34 +03:00
|
|
|
static void SpeculativeConnect(jni::String::Param aUriStr)
|
2015-08-20 01:14:47 +03:00
|
|
|
{
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
// We will be on the main thread if the call was queued on the Java
|
|
|
|
// side during startup. Otherwise, the call was not queued, which
|
|
|
|
// means Gecko is already sufficiently loaded, and we don't really
|
|
|
|
// care about speculative connections at this point.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIOService> ioServ = do_GetIOService();
|
|
|
|
nsCOMPtr<nsISpeculativeConnect> specConn = do_QueryInterface(ioServ);
|
|
|
|
if (!specConn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-21 04:43:34 +03:00
|
|
|
nsCOMPtr<nsIURI> uri = nsAppShell::ResolveURI(aUriStr->ToCString());
|
2015-08-20 01:14:47 +03:00
|
|
|
if (!uri) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-03 06:18:00 +03:00
|
|
|
|
|
|
|
OriginAttributes attrs;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
|
|
|
|
specConn->SpeculativeConnect2(uri, principal, nullptr);
|
2015-08-20 01:14:47 +03:00
|
|
|
}
|
2016-04-06 04:43:40 +03:00
|
|
|
|
|
|
|
static void WaitOnGecko()
|
|
|
|
{
|
2017-03-17 06:30:54 +03:00
|
|
|
struct NoOpRunnable : Runnable
|
|
|
|
{
|
2017-06-12 22:34:10 +03:00
|
|
|
NoOpRunnable() : Runnable("NoOpRunnable") {}
|
2017-03-17 06:30:54 +03:00
|
|
|
NS_IMETHOD Run() override { return NS_OK; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NoOpEvent : nsAppShell::Event
|
|
|
|
{
|
|
|
|
void Run() override
|
|
|
|
{
|
|
|
|
// We cannot call NS_DispatchToMainThread from within
|
|
|
|
// WaitOnGecko itself because the thread that is calling
|
|
|
|
// WaitOnGecko may not be an nsThread, and may not be able to do
|
|
|
|
// a sync dispatch.
|
|
|
|
NS_DispatchToMainThread(do_AddRef(new NoOpRunnable()),
|
|
|
|
NS_DISPATCH_SYNC);
|
|
|
|
}
|
2016-04-06 04:43:40 +03:00
|
|
|
};
|
|
|
|
nsAppShell::SyncRunEvent(NoOpEvent());
|
|
|
|
}
|
2016-04-06 04:43:41 +03:00
|
|
|
|
|
|
|
static void OnPause()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-09-12 20:43:08 +03:00
|
|
|
sPauseCount++;
|
|
|
|
// If sPauseCount is now 1, we just crossed the threshold from "resumed"
|
|
|
|
// "paused". so we should notify observers and so on.
|
|
|
|
if (sPauseCount != 1) {
|
2016-04-06 04:43:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
obsServ->NotifyObservers(nullptr, "application-background", nullptr);
|
|
|
|
|
2017-03-14 05:26:27 +03:00
|
|
|
obsServ->NotifyObservers(nullptr, "memory-pressure", u"heap-minimize");
|
2016-04-06 04:43:41 +03:00
|
|
|
|
|
|
|
// If we are OOM killed with the disk cache enabled, the entire
|
|
|
|
// cache will be cleared (bug 105843), so shut down the cache here
|
|
|
|
// and re-init on foregrounding
|
|
|
|
if (nsCacheService::GlobalInstance()) {
|
|
|
|
nsCacheService::GlobalInstance()->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We really want to send a notification like profile-before-change,
|
|
|
|
// but profile-before-change ends up shutting some things down instead
|
|
|
|
// of flushing data
|
2017-06-14 20:38:17 +03:00
|
|
|
Preferences* prefs = static_cast<Preferences *>(Preferences::GetService());
|
2016-04-06 04:43:41 +03:00
|
|
|
if (prefs) {
|
2017-06-14 20:38:17 +03:00
|
|
|
// Force a main thread blocking save
|
|
|
|
prefs->SavePrefFileBlocking();
|
2016-04-06 04:43:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OnResume()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-09-12 20:43:08 +03:00
|
|
|
sPauseCount--;
|
|
|
|
// If sPauseCount is now 0, we just crossed the threshold from "paused"
|
|
|
|
// to "resumed", so we should notify observers and so on.
|
|
|
|
if (sPauseCount != 0) {
|
2016-04-06 04:43:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are OOM killed with the disk cache enabled, the entire
|
|
|
|
// cache will be cleared (bug 105843), so shut down cache on backgrounding
|
|
|
|
// and re-init here
|
|
|
|
if (nsCacheService::GlobalInstance()) {
|
|
|
|
nsCacheService::GlobalInstance()->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We didn't return from one of our own activities, so restore
|
|
|
|
// to foreground status
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
obsServ->NotifyObservers(nullptr, "application-foreground", nullptr);
|
|
|
|
}
|
2016-04-20 22:06:13 +03:00
|
|
|
|
2016-04-16 09:19:37 +03:00
|
|
|
static void CreateServices(jni::String::Param aCategory, jni::String::Param aData)
|
2016-04-20 22:06:13 +03:00
|
|
|
{
|
2016-08-13 06:15:53 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-04-20 22:06:13 +03:00
|
|
|
nsCString category(aCategory->ToCString());
|
|
|
|
|
|
|
|
NS_CreateServicesFromCategory(
|
2016-04-16 09:19:37 +03:00
|
|
|
category.get(),
|
|
|
|
nullptr, // aOrigin
|
|
|
|
category.get(),
|
|
|
|
aData ? aData->ToString().get() : nullptr);
|
2016-04-20 22:06:13 +03:00
|
|
|
}
|
2016-08-19 01:04:11 +03:00
|
|
|
|
|
|
|
static int64_t RunUiThreadCallback()
|
|
|
|
{
|
2017-06-02 21:03:14 +03:00
|
|
|
return RunAndroidUiTasks();
|
2016-08-19 01:04:11 +03:00
|
|
|
}
|
2017-06-06 19:17:10 +03:00
|
|
|
|
|
|
|
static void ForceQuit()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAppStartup> appStartup =
|
|
|
|
do_GetService(NS_APPSTARTUP_CONTRACTID);
|
|
|
|
|
|
|
|
if (appStartup) {
|
|
|
|
appStartup->Quit(nsIAppStartup::eForceQuit);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-04-19 23:49:09 +03:00
|
|
|
|
|
|
|
static void Crash()
|
|
|
|
{
|
|
|
|
printf_stderr("Intentionally crashing...\n");
|
|
|
|
MOZ_CRASH("intentional crash");
|
|
|
|
}
|
2015-08-20 01:14:47 +03:00
|
|
|
};
|
|
|
|
|
2016-09-12 20:43:08 +03:00
|
|
|
int32_t GeckoThreadSupport::sPauseCount;
|
2016-04-06 04:43:41 +03:00
|
|
|
|
|
|
|
|
2016-03-23 21:42:38 +03:00
|
|
|
class GeckoAppShellSupport final
|
2016-07-21 20:49:04 +03:00
|
|
|
: public java::GeckoAppShell::Natives<GeckoAppShellSupport>
|
2016-03-23 21:42:38 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-08-26 19:25:57 +03:00
|
|
|
static void ReportJavaCrash(const jni::Class::LocalRef& aCls,
|
|
|
|
jni::Throwable::Param aException,
|
|
|
|
jni::String::Param aStack)
|
2016-08-19 01:04:11 +03:00
|
|
|
{
|
2016-08-26 19:25:57 +03:00
|
|
|
if (!jni::ReportException(aCls.Env(), aException.Get(), aStack.Get())) {
|
2016-08-19 01:04:11 +03:00
|
|
|
// Only crash below if crash reporter is initialized and annotation
|
|
|
|
// succeeded. Otherwise try other means of reporting the crash in
|
|
|
|
// Java.
|
|
|
|
return;
|
|
|
|
}
|
2016-08-26 19:25:57 +03:00
|
|
|
|
2016-08-19 01:04:11 +03:00
|
|
|
MOZ_CRASH("Uncaught Java exception");
|
|
|
|
}
|
|
|
|
|
2016-03-23 21:42:38 +03:00
|
|
|
static void NotifyObservers(jni::String::Param aTopic,
|
|
|
|
jni::String::Param aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aTopic);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ = services::GetObserverService();
|
|
|
|
if (!obsServ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obsServ->NotifyObservers(nullptr, aTopic->ToCString().get(),
|
|
|
|
aData ? aData->ToString().get() : nullptr);
|
|
|
|
}
|
2016-07-08 18:39:09 +03:00
|
|
|
|
|
|
|
static void OnSensorChanged(int32_t aType, float aX, float aY, float aZ,
|
2018-06-27 16:05:48 +03:00
|
|
|
float aW, int64_t aTime)
|
2016-07-08 18:39:09 +03:00
|
|
|
{
|
|
|
|
AutoTArray<float, 4> values;
|
|
|
|
|
|
|
|
switch (aType) {
|
|
|
|
// Bug 938035, transfer HAL data for orientation sensor to meet w3c
|
|
|
|
// spec, ex: HAL report alpha=90 means East but alpha=90 means West
|
|
|
|
// in w3c spec
|
|
|
|
case hal::SENSOR_ORIENTATION:
|
|
|
|
values.AppendElement(360.0f - aX);
|
|
|
|
values.AppendElement(-aY);
|
|
|
|
values.AppendElement(-aZ);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hal::SENSOR_LINEAR_ACCELERATION:
|
|
|
|
case hal::SENSOR_ACCELERATION:
|
|
|
|
case hal::SENSOR_GYROSCOPE:
|
|
|
|
case hal::SENSOR_PROXIMITY:
|
|
|
|
values.AppendElement(aX);
|
|
|
|
values.AppendElement(aY);
|
|
|
|
values.AppendElement(aZ);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hal::SENSOR_LIGHT:
|
|
|
|
values.AppendElement(aX);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hal::SENSOR_ROTATION_VECTOR:
|
|
|
|
case hal::SENSOR_GAME_ROTATION_VECTOR:
|
|
|
|
values.AppendElement(aX);
|
|
|
|
values.AppendElement(aY);
|
|
|
|
values.AppendElement(aZ);
|
|
|
|
values.AppendElement(aW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "Gecko",
|
|
|
|
"Unknown sensor type %d", aType);
|
|
|
|
}
|
|
|
|
|
2018-06-27 16:05:48 +03:00
|
|
|
hal::SensorData sdata(hal::SensorType(aType), aTime, values);
|
2016-07-08 18:39:09 +03:00
|
|
|
hal::NotifySensorChange(sdata);
|
|
|
|
}
|
2016-07-08 18:39:10 +03:00
|
|
|
|
|
|
|
static void OnLocationChanged(double aLatitude, double aLongitude,
|
|
|
|
double aAltitude, float aAccuracy,
|
2018-02-26 10:35:16 +03:00
|
|
|
float aAltitudeAccuracy,
|
|
|
|
float aHeading, float aSpeed, int64_t aTime)
|
2016-07-08 18:39:10 +03:00
|
|
|
{
|
|
|
|
if (!gLocationCallback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsIDOMGeoPosition> geoPosition(
|
|
|
|
new nsGeoPosition(aLatitude, aLongitude, aAltitude, aAccuracy,
|
2018-02-26 10:35:16 +03:00
|
|
|
aAltitudeAccuracy, aHeading, aSpeed, aTime));
|
2016-07-08 18:39:10 +03:00
|
|
|
gLocationCallback->Update(geoPosition);
|
|
|
|
}
|
2016-07-12 01:07:35 +03:00
|
|
|
|
|
|
|
static void NotifyUriVisited(jni::String::Param aUri)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_ANDROID_HISTORY
|
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
nsCOMPtr<nsIURI> visitedURI;
|
|
|
|
if (history &&
|
|
|
|
NS_SUCCEEDED(NS_NewURI(getter_AddRefs(visitedURI),
|
|
|
|
aUri->ToString()))) {
|
|
|
|
history->NotifyVisited(visitedURI);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2016-08-04 16:17:54 +03:00
|
|
|
|
|
|
|
static void NotifyAlertListener(jni::String::Param aName,
|
Bug 1305498 - Refactor notification code to be more concise; r=sebastian
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.
2016-10-06 04:52:32 +03:00
|
|
|
jni::String::Param aTopic,
|
|
|
|
jni::String::Param aCookie)
|
2016-08-04 16:17:54 +03:00
|
|
|
{
|
Bug 1305498 - Refactor notification code to be more concise; r=sebastian
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.
2016-10-06 04:52:32 +03:00
|
|
|
if (!aName || !aTopic || !aCookie) {
|
2016-08-04 16:17:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
widget::AndroidAlerts::NotifyListener(
|
Bug 1305498 - Refactor notification code to be more concise; r=sebastian
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.
2016-10-06 04:52:32 +03:00
|
|
|
aName->ToString(), aTopic->ToCString().get(),
|
|
|
|
aCookie->ToString().get());
|
2016-08-04 16:17:54 +03:00
|
|
|
}
|
2016-03-23 21:42:38 +03:00
|
|
|
};
|
|
|
|
|
2017-11-10 18:20:04 +03:00
|
|
|
|
|
|
|
class BrowserLocaleManagerSupport final
|
|
|
|
: public java::BrowserLocaleManager::Natives<BrowserLocaleManagerSupport>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void RefreshLocales()
|
|
|
|
{
|
|
|
|
intl::OSPreferences::GetInstance()->Refresh();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
nsAppShell::nsAppShell()
|
2016-01-13 22:35:27 +03:00
|
|
|
: mSyncRunFinished(*(sAppShellLock = new Mutex("nsAppShell")),
|
|
|
|
"nsAppShell.SyncRun")
|
2015-12-24 06:03:35 +03:00
|
|
|
, mSyncRunQuit(false)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2015-12-24 06:03:35 +03:00
|
|
|
{
|
2016-01-13 22:35:27 +03:00
|
|
|
MutexAutoLock lock(*sAppShellLock);
|
2015-12-24 06:03:35 +03:00
|
|
|
sAppShell = this;
|
|
|
|
}
|
2012-06-07 06:39:01 +04:00
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
hal::Init();
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
if (jni::IsAvailable()) {
|
2018-04-19 23:49:09 +03:00
|
|
|
GeckoThreadSupport::Init();
|
2018-04-19 23:13:56 +03:00
|
|
|
GeckoAppShellSupport::Init();
|
2018-11-16 17:34:48 +03:00
|
|
|
mozilla::GeckoSystemStateListener::Init();
|
2018-11-13 17:29:21 +03:00
|
|
|
mozilla::widget::Telemetry::Init();
|
2018-04-19 23:13:56 +03:00
|
|
|
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
// Set the corresponding state in GeckoThread.
|
|
|
|
java::GeckoThread::SetState(java::GeckoThread::State::RUNNING());
|
|
|
|
}
|
2012-08-16 23:34:53 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-13 23:57:34 +03:00
|
|
|
if (jni::IsAvailable()) {
|
2018-07-27 21:24:49 +03:00
|
|
|
ScreenManager& screenManager = ScreenManager::GetSingleton();
|
|
|
|
screenManager.SetHelper(mozilla::MakeUnique<ScreenHelperAndroid>());
|
|
|
|
|
2015-08-13 23:57:34 +03:00
|
|
|
// Initialize JNI and Set the corresponding state in GeckoThread.
|
|
|
|
AndroidBridge::ConstructBridge();
|
2016-03-23 21:42:38 +03:00
|
|
|
GeckoAppShellSupport::Init();
|
2016-04-06 04:43:41 +03:00
|
|
|
GeckoThreadSupport::Init();
|
2016-08-19 01:04:11 +03:00
|
|
|
mozilla::GeckoBatteryManager::Init();
|
2016-07-21 04:44:48 +03:00
|
|
|
mozilla::GeckoNetworkManager::Init();
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
mozilla::GeckoProcessManager::Init();
|
2016-07-21 04:44:48 +03:00
|
|
|
mozilla::GeckoScreenOrientation::Init();
|
2018-09-15 13:03:29 +03:00
|
|
|
mozilla::GeckoSystemStateListener::Init();
|
2015-09-28 19:07:10 +03:00
|
|
|
mozilla::PrefsHelper::Init();
|
2018-11-13 17:29:21 +03:00
|
|
|
mozilla::widget::Telemetry::Init();
|
2018-10-18 16:28:09 +03:00
|
|
|
mozilla::widget::WebExecutorSupport::Init();
|
2015-09-21 17:13:32 +03:00
|
|
|
nsWindow::InitNatives();
|
2015-08-13 23:57:34 +03:00
|
|
|
|
2016-09-29 06:49:25 +03:00
|
|
|
if (jni::IsFennec()) {
|
2017-11-10 18:20:04 +03:00
|
|
|
BrowserLocaleManagerSupport::Init();
|
2016-09-29 06:49:25 +03:00
|
|
|
mozilla::ANRReporter::Init();
|
|
|
|
mozilla::MemoryMonitor::Init();
|
|
|
|
mozilla::ThumbnailHelper::Init();
|
|
|
|
}
|
|
|
|
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoThread::SetState(java::GeckoThread::State::JNI_READY());
|
2016-12-01 01:59:57 +03:00
|
|
|
|
|
|
|
CreateAndroidUiThread();
|
2015-08-13 23:57:34 +03:00
|
|
|
}
|
|
|
|
|
2012-06-07 06:39:01 +04:00
|
|
|
sPowerManagerService = do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (sPowerManagerService) {
|
|
|
|
sWakeLockListener = new WakeLockListener();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Failed to retrieve PowerManagerService, wakelocks will be broken!");
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::~nsAppShell()
|
|
|
|
{
|
2015-12-24 06:03:35 +03:00
|
|
|
{
|
2017-03-17 06:30:54 +03:00
|
|
|
// Release any thread waiting for a sync call to finish.
|
2016-01-13 22:35:27 +03:00
|
|
|
MutexAutoLock lock(*sAppShellLock);
|
2015-12-24 06:03:35 +03:00
|
|
|
sAppShell = nullptr;
|
2017-03-17 06:30:54 +03:00
|
|
|
mSyncRunFinished.NotifyAll();
|
2015-12-24 06:03:35 +03:00
|
|
|
}
|
2012-06-07 06:39:01 +04:00
|
|
|
|
2015-12-24 06:03:35 +03:00
|
|
|
while (mEventQueue.Pop(/* mayWait */ false)) {
|
|
|
|
NS_WARNING("Discarded event on shutdown");
|
|
|
|
}
|
|
|
|
|
2012-06-07 06:39:01 +04:00
|
|
|
if (sPowerManagerService) {
|
|
|
|
sPowerManagerService->RemoveWakeLockListener(sWakeLockListener);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
sPowerManagerService = nullptr;
|
|
|
|
sWakeLockListener = nullptr;
|
2012-06-07 06:39:01 +04:00
|
|
|
}
|
2015-08-13 07:53:40 +03:00
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
hal::Shutdown();
|
|
|
|
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
if (jni::IsAvailable() && XRE_IsParentProcess()) {
|
2016-12-01 01:59:57 +03:00
|
|
|
DestroyAndroidUiThread();
|
2015-08-13 23:57:34 +03:00
|
|
|
AndroidBridge::DeconstructBridge();
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::NotifyNativeEvent()
|
|
|
|
{
|
2015-09-21 17:13:32 +03:00
|
|
|
mEventQueue.Signal();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2016-12-21 21:37:20 +03:00
|
|
|
void
|
|
|
|
nsAppShell::RecordLatencies()
|
|
|
|
{
|
|
|
|
if (!mozilla::Telemetry::CanRecordExtended()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-15 22:15:15 +03:00
|
|
|
const mozilla::Telemetry::HistogramID timeIDs[] = {
|
|
|
|
mozilla::Telemetry::HistogramID::FENNEC_LOOP_UI_LATENCY,
|
|
|
|
mozilla::Telemetry::HistogramID::FENNEC_LOOP_OTHER_LATENCY
|
2016-12-21 21:37:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(ArrayLength(Queue::sLatencyCount) == Queue::LATENCY_COUNT,
|
|
|
|
"Count array length mismatch");
|
|
|
|
static_assert(ArrayLength(Queue::sLatencyTime) == Queue::LATENCY_COUNT,
|
|
|
|
"Time array length mismatch");
|
|
|
|
static_assert(ArrayLength(timeIDs) == Queue::LATENCY_COUNT,
|
|
|
|
"Time ID array length mismatch");
|
|
|
|
|
|
|
|
for (size_t i = 0; i < Queue::LATENCY_COUNT; i++) {
|
|
|
|
if (!Queue::sLatencyCount[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t time = Queue::sLatencyTime[i] / 1000ull /
|
|
|
|
Queue::sLatencyCount[i];
|
|
|
|
if (time) {
|
|
|
|
mozilla::Telemetry::Accumulate(
|
|
|
|
timeIDs[i], uint32_t(std::min<uint64_t>(UINT32_MAX, time)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset latency counts.
|
|
|
|
Queue::sLatencyCount[i] = 0;
|
|
|
|
Queue::sLatencyTime[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 23:54:36 +04:00
|
|
|
#define PREFNAME_COALESCE_TOUCHES "dom.event.touch.coalescing.enabled"
|
2011-06-07 11:38:00 +04:00
|
|
|
static const char* kObservedPrefs[] = {
|
2012-08-09 23:54:36 +04:00
|
|
|
PREFNAME_COALESCE_TOUCHES,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2011-06-07 11:38:00 +04:00
|
|
|
};
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
nsresult
|
|
|
|
nsAppShell::Init()
|
|
|
|
{
|
2010-10-26 07:10:07 +04:00
|
|
|
nsresult rv = nsBaseAppShell::Init();
|
2010-12-22 00:28:45 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 18:50:56 +03:00
|
|
|
mozilla::services::GetObserverService();
|
2010-12-22 00:28:45 +03:00
|
|
|
if (obsServ) {
|
2014-07-12 01:15:39 +04:00
|
|
|
obsServ->AddObserver(this, "browser-delayed-startup-finished", false);
|
2015-09-21 17:13:33 +03:00
|
|
|
obsServ->AddObserver(this, "profile-after-change", false);
|
2017-05-11 23:39:29 +03:00
|
|
|
obsServ->AddObserver(this, "quit-application", false);
|
2015-10-15 22:49:48 +03:00
|
|
|
obsServ->AddObserver(this, "quit-application-granted", false);
|
2015-08-20 01:14:47 +03:00
|
|
|
obsServ->AddObserver(this, "xpcom-shutdown", false);
|
2017-03-09 01:19:07 +03:00
|
|
|
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
obsServ->AddObserver(this, "chrome-document-loaded", false);
|
2018-06-19 23:31:35 +03:00
|
|
|
} else {
|
|
|
|
obsServ->AddObserver(this, "content-document-global-created", false);
|
2018-11-06 08:12:06 +03:00
|
|
|
obsServ->AddObserver(this, "geckoview-content-global-transferred", false);
|
2017-03-09 01:19:07 +03:00
|
|
|
}
|
2010-12-22 00:28:45 +03:00
|
|
|
}
|
2011-02-27 18:50:56 +03:00
|
|
|
|
2012-06-07 06:39:01 +04:00
|
|
|
if (sPowerManagerService)
|
|
|
|
sPowerManagerService->AddWakeLockListener(sWakeLockListener);
|
|
|
|
|
2011-06-07 11:38:00 +04:00
|
|
|
Preferences::AddStrongObservers(this, kObservedPrefs);
|
2012-08-09 23:54:36 +04:00
|
|
|
mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true);
|
2010-10-26 07:10:07 +04:00
|
|
|
return rv;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2010-12-22 00:28:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShell::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData)
|
2010-12-22 00:28:45 +03:00
|
|
|
{
|
2015-10-15 22:49:48 +03:00
|
|
|
bool removeObserver = false;
|
|
|
|
|
2010-12-22 00:28:45 +03:00
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
2015-12-24 06:03:35 +03:00
|
|
|
{
|
|
|
|
// Release any thread waiting for a sync call to finish.
|
2016-01-13 22:35:27 +03:00
|
|
|
mozilla::MutexAutoLock shellLock(*sAppShellLock);
|
2015-12-24 06:03:35 +03:00
|
|
|
mSyncRunQuit = true;
|
2016-01-13 22:35:27 +03:00
|
|
|
mSyncRunFinished.NotifyAll();
|
2015-12-24 06:03:35 +03:00
|
|
|
}
|
2010-12-22 00:28:45 +03:00
|
|
|
// We need to ensure no observers stick around after XPCOM shuts down
|
|
|
|
// or we'll see crashes, as the app shell outlives XPConnect.
|
|
|
|
mObserversHash.Clear();
|
2011-03-14 19:45:44 +03:00
|
|
|
return nsBaseAppShell::Observe(aSubject, aTopic, aData);
|
2015-09-18 16:17:10 +03:00
|
|
|
|
2013-12-04 03:05:43 +04:00
|
|
|
} else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) &&
|
|
|
|
aData &&
|
|
|
|
nsDependentString(aData).Equals(NS_LITERAL_STRING(PREFNAME_COALESCE_TOUCHES))) {
|
2012-08-09 23:54:36 +04:00
|
|
|
mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true);
|
2011-02-27 18:50:56 +03:00
|
|
|
return NS_OK;
|
2015-09-18 16:17:10 +03:00
|
|
|
|
2014-07-12 01:15:39 +04:00
|
|
|
} else if (!strcmp(aTopic, "browser-delayed-startup-finished")) {
|
|
|
|
NS_CreateServicesFromCategory("browser-delayed-startup-finished", nullptr,
|
|
|
|
"browser-delayed-startup-finished");
|
2015-09-18 16:17:10 +03:00
|
|
|
|
2015-09-21 17:13:33 +03:00
|
|
|
} else if (!strcmp(aTopic, "profile-after-change")) {
|
2015-08-20 01:14:47 +03:00
|
|
|
if (jni::IsAvailable()) {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoThread::SetState(
|
|
|
|
java::GeckoThread::State::PROFILE_READY());
|
2015-09-18 16:17:10 +03:00
|
|
|
|
|
|
|
// Gecko on Android follows the Android app model where it never
|
|
|
|
// stops until it is killed by the system or told explicitly to
|
|
|
|
// quit. Therefore, we should *not* exit Gecko when there is no
|
|
|
|
// window or the last window is closed. nsIAppStartup::Quit will
|
|
|
|
// still force Gecko to exit.
|
|
|
|
nsCOMPtr<nsIAppStartup> appStartup =
|
|
|
|
do_GetService(NS_APPSTARTUP_CONTRACTID);
|
|
|
|
if (appStartup) {
|
|
|
|
appStartup->EnterLastWindowClosingSurvivalArea();
|
|
|
|
}
|
2015-08-20 01:14:47 +03:00
|
|
|
}
|
2015-10-15 22:49:48 +03:00
|
|
|
removeObserver = true;
|
|
|
|
|
2016-02-02 01:38:14 +03:00
|
|
|
} else if (!strcmp(aTopic, "chrome-document-loaded")) {
|
2017-04-19 00:42:59 +03:00
|
|
|
// Set the global ready state and enable the window event dispatcher
|
|
|
|
// for this particular GeckoView.
|
2017-03-09 01:16:19 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aSubject);
|
|
|
|
MOZ_ASSERT(doc);
|
2018-11-16 20:31:58 +03:00
|
|
|
if (const RefPtr<nsWindow> window = nsWindow::From(doc->GetWindow())) {
|
2017-04-19 00:42:59 +03:00
|
|
|
if (jni::IsAvailable()) {
|
|
|
|
// When our first window has loaded, assume any JS
|
|
|
|
// initialization has run and set Gecko to ready.
|
|
|
|
java::GeckoThread::CheckAndSetState(
|
|
|
|
java::GeckoThread::State::PROFILE_READY(),
|
|
|
|
java::GeckoThread::State::RUNNING());
|
|
|
|
}
|
2018-03-09 20:34:38 +03:00
|
|
|
window->OnGeckoViewReady();
|
2017-03-09 01:19:07 +03:00
|
|
|
}
|
2017-05-11 23:39:29 +03:00
|
|
|
} else if (!strcmp(aTopic, "quit-application")) {
|
2015-10-15 22:49:48 +03:00
|
|
|
if (jni::IsAvailable()) {
|
2017-05-11 23:39:29 +03:00
|
|
|
const bool restarting =
|
|
|
|
aData && NS_LITERAL_STRING("restart").Equals(aData);
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoThread::SetState(
|
2017-05-11 23:39:29 +03:00
|
|
|
restarting ?
|
|
|
|
java::GeckoThread::State::RESTARTING() :
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoThread::State::EXITING());
|
2017-05-11 23:39:29 +03:00
|
|
|
}
|
|
|
|
removeObserver = true;
|
2016-02-02 01:38:14 +03:00
|
|
|
|
2017-05-11 23:39:29 +03:00
|
|
|
} else if (!strcmp(aTopic, "quit-application-granted")) {
|
|
|
|
if (jni::IsAvailable()) {
|
2015-10-15 22:49:48 +03:00
|
|
|
// We are told explicitly to quit, perhaps due to
|
|
|
|
// nsIAppStartup::Quit being called. We should release our hold on
|
|
|
|
// nsIAppStartup and let it continue to quit.
|
|
|
|
nsCOMPtr<nsIAppStartup> appStartup =
|
|
|
|
do_GetService(NS_APPSTARTUP_CONTRACTID);
|
|
|
|
if (appStartup) {
|
|
|
|
appStartup->ExitLastWindowClosingSurvivalArea();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeObserver = true;
|
2016-02-02 01:38:13 +03:00
|
|
|
|
|
|
|
} else if (!strcmp(aTopic, "nsPref:changed")) {
|
|
|
|
if (jni::IsAvailable()) {
|
|
|
|
mozilla::PrefsHelper::OnPrefChange(aData);
|
|
|
|
}
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
|
2018-06-19 23:31:35 +03:00
|
|
|
} else if (!strcmp(aTopic, "content-document-global-created")) {
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
// Associate the PuppetWidget of the newly-created TabChild with a
|
|
|
|
// GeckoEditableChild instance.
|
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess());
|
|
|
|
|
2018-06-19 23:31:35 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWindow = do_QueryInterface(aSubject);
|
|
|
|
MOZ_ASSERT(domWindow);
|
|
|
|
nsCOMPtr<nsIWidget> domWidget = widget::WidgetUtils::DOMWindowToWidget(
|
|
|
|
nsPIDOMWindowOuter::From(domWindow));
|
|
|
|
NS_ENSURE_TRUE(domWidget, NS_OK);
|
|
|
|
|
2018-11-06 08:12:06 +03:00
|
|
|
widget::GeckoEditableSupport::SetOnTabChild(
|
|
|
|
domWidget->GetOwningTabChild());
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
|
2018-11-06 08:12:06 +03:00
|
|
|
} else if (!strcmp(aTopic, "geckoview-content-global-transferred")) {
|
|
|
|
// We're transferring to a new GeckoEditableParent, so notify the
|
|
|
|
// existing GeckoEditableChild instance associated with the docshell.
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(aSubject);
|
|
|
|
widget::GeckoEditableSupport::SetOnTabChild(
|
|
|
|
dom::TabChild::GetFrom(docShell));
|
2015-10-15 22:49:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (removeObserver) {
|
2015-08-20 01:14:47 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsServ) {
|
2015-10-15 22:49:48 +03:00
|
|
|
obsServ->RemoveObserver(this, aTopic);
|
2015-08-20 01:14:47 +03:00
|
|
|
}
|
2010-12-22 00:28:45 +03:00
|
|
|
}
|
2011-03-14 19:45:44 +03:00
|
|
|
return NS_OK;
|
2010-12-22 00:28:45 +03:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
EVLOG("nsAppShell::ProcessNextNativeEvent %d", mayWait);
|
|
|
|
|
2018-05-19 00:36:30 +03:00
|
|
|
AUTO_PROFILER_LABEL("nsAppShell::ProcessNextNativeEvent", OTHER);
|
2014-05-24 01:12:29 +04:00
|
|
|
|
2015-09-21 17:13:32 +03:00
|
|
|
mozilla::UniquePtr<Event> curEvent;
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
{
|
2015-09-21 17:13:32 +03:00
|
|
|
curEvent = mEventQueue.Pop(/* mayWait */ false);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
if (!curEvent && mayWait) {
|
2015-04-28 03:52:52 +03:00
|
|
|
// This processes messages in the Android Looper. Note that we only
|
|
|
|
// get here if the normal Gecko event loop has been awoken
|
|
|
|
// (bug 750713). Looper messages effectively have the lowest
|
|
|
|
// priority because we only process them before we're about to
|
|
|
|
// wait for new events.
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
if (jni::IsAvailable() && XRE_IsParentProcess() &&
|
2015-04-28 03:52:52 +03:00
|
|
|
AndroidBridge::Bridge()->PumpMessageLoop()) {
|
2015-04-28 03:52:52 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("nsAppShell::ProcessNextNativeEvent:Wait",
|
2018-05-19 01:15:46 +03:00
|
|
|
IDLE);
|
2018-04-30 04:21:20 +03:00
|
|
|
mozilla::BackgroundHangMonitor().NotifyWait();
|
2014-05-24 01:12:29 +04:00
|
|
|
|
2018-11-02 19:26:50 +03:00
|
|
|
AUTO_PROFILER_THREAD_SLEEP;
|
2015-09-21 17:13:32 +03:00
|
|
|
curEvent = mEventQueue.Pop(/* mayWait */ true);
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!curEvent)
|
|
|
|
return false;
|
|
|
|
|
2018-04-30 04:21:20 +03:00
|
|
|
mozilla::BackgroundHangMonitor().NotifyActivity();
|
2015-09-21 17:13:32 +03:00
|
|
|
|
|
|
|
curEvent->Run();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-24 06:03:35 +03:00
|
|
|
void
|
|
|
|
nsAppShell::SyncRunEvent(Event&& event,
|
|
|
|
UniquePtr<Event>(*eventFactory)(UniquePtr<Event>&&))
|
|
|
|
{
|
|
|
|
// Perform the call on the Gecko thread in a separate lambda, and wait
|
|
|
|
// on the monitor on the current thread.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
2016-01-13 22:35:27 +03:00
|
|
|
// This is the lock to check that app shell is still alive,
|
|
|
|
// and to wait on for the sync call to complete.
|
|
|
|
mozilla::MutexAutoLock shellLock(*sAppShellLock);
|
2015-12-24 06:03:35 +03:00
|
|
|
nsAppShell* const appShell = sAppShell;
|
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(!appShell)) {
|
|
|
|
// Post-shutdown.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool finished = false;
|
|
|
|
auto runAndNotify = [&event, &finished] {
|
2017-03-17 06:30:54 +03:00
|
|
|
nsAppShell* const appShell = nsAppShell::Get();
|
2015-12-24 06:03:35 +03:00
|
|
|
if (MOZ_UNLIKELY(!appShell || appShell->mSyncRunQuit)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.Run();
|
|
|
|
finished = true;
|
2017-03-17 06:30:54 +03:00
|
|
|
mozilla::MutexAutoLock shellLock(*sAppShellLock);
|
2016-01-13 22:35:27 +03:00
|
|
|
appShell->mSyncRunFinished.NotifyAll();
|
2015-12-24 06:03:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
UniquePtr<Event> runAndNotifyEvent = mozilla::MakeUnique<
|
2018-05-30 22:15:35 +03:00
|
|
|
LambdaEvent<decltype(runAndNotify)>>(std::move(runAndNotify));
|
2015-12-24 06:03:35 +03:00
|
|
|
|
|
|
|
if (eventFactory) {
|
2018-05-30 22:15:35 +03:00
|
|
|
runAndNotifyEvent = (*eventFactory)(std::move(runAndNotifyEvent));
|
2015-12-24 06:03:35 +03:00
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
appShell->mEventQueue.Post(std::move(runAndNotifyEvent));
|
2015-12-24 06:03:35 +03:00
|
|
|
|
2016-01-13 22:35:27 +03:00
|
|
|
while (!finished && MOZ_LIKELY(sAppShell && !sAppShell->mSyncRunQuit)) {
|
|
|
|
appShell->mSyncRunFinished.Wait();
|
2015-12-24 06:03:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 04:43:34 +03:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsAppShell::ResolveURI(const nsCString& aUriStr)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIIOService> ioServ = do_GetIOService();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(ioServ->NewURI(aUriStr, nullptr,
|
|
|
|
nullptr, getter_AddRefs(uri)))) {
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURIFixup> fixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
|
|
|
if (fixup && NS_SUCCEEDED(
|
|
|
|
fixup->CreateFixupURI(aUriStr, 0, nullptr, getter_AddRefs(uri)))) {
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-06-15 06:17:37 +04:00
|
|
|
nsresult
|
|
|
|
nsAppShell::AddObserver(const nsAString &aObserverKey, nsIObserver *aObserver)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aObserver != nullptr, "nsAppShell::AddObserver: aObserver is null!");
|
2012-05-18 21:30:49 +04:00
|
|
|
mObserversHash.Put(aObserverKey, aObserver);
|
|
|
|
return NS_OK;
|
2010-06-15 06:17:37 +04:00
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
// Used by IPC code
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
bool ProcessNextEvent()
|
|
|
|
{
|
2015-12-24 06:03:35 +03:00
|
|
|
nsAppShell* const appShell = nsAppShell::Get();
|
|
|
|
if (!appShell) {
|
2014-12-16 01:04:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-24 06:03:35 +03:00
|
|
|
return appShell->ProcessNextNativeEvent(true) ? true : false;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyEvent()
|
|
|
|
{
|
2015-12-24 06:03:35 +03:00
|
|
|
nsAppShell* const appShell = nsAppShell::Get();
|
|
|
|
if (!appShell) {
|
|
|
|
return;
|
2014-12-16 01:04:33 +03:00
|
|
|
}
|
2015-12-24 06:03:35 +03:00
|
|
|
appShell->NotifyNativeEvent();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|