2010-06-04 00:56:36 +04:00
|
|
|
/* -*- Mode: c++; tab-width: 40; 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"
|
|
|
|
#include "nsIDOMClientRectList.h"
|
|
|
|
#include "nsIDOMClientRect.h"
|
2012-06-07 06:39:01 +04:00
|
|
|
#include "nsIDOMWakeLockListener.h"
|
|
|
|
#include "nsIPowerManagerService.h"
|
2013-06-18 01:09:09 +04:00
|
|
|
#include "nsINetworkLinkService.h"
|
2014-07-12 01:15:39 +04:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2015-04-22 18:30:13 +03:00
|
|
|
#include "mozilla/HangMonitor.h"
|
2010-06-18 01:33:15 +04:00
|
|
|
#include "mozilla/Services.h"
|
2011-02-11 20:27:17 +03:00
|
|
|
#include "mozilla/unused.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"
|
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"
|
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
|
|
|
|
2012-03-20 17:09:45 +04:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
2014-04-22 18:53:48 +04:00
|
|
|
#ifdef MOZ_GAMEPAD
|
2015-04-24 01:05:29 +03:00
|
|
|
#include "mozilla/dom/GamepadFunctions.h"
|
|
|
|
#include "mozilla/dom/Gamepad.h"
|
2014-04-22 18:53:48 +04:00
|
|
|
#endif
|
2012-03-20 17:09:45 +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"
|
|
|
|
#include "IHistory.h"
|
2012-01-06 04:14:23 +04:00
|
|
|
#endif
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#include "prlog.h"
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
2012-07-30 18:20:58 +04:00
|
|
|
PRLogModuleInfo *gWidgetLog = nullptr;
|
2010-06-04 00:56:36 +04:00
|
|
|
#endif
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIGeolocationUpdate *gLocationCallback = nullptr;
|
2011-08-09 20:08:19 +04:00
|
|
|
nsAutoPtr<mozilla::AndroidGeckoEvent> gLastSizeChange;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsAppShell *nsAppShell::gAppShell = nullptr;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsAppShell, nsBaseAppShell, nsIObserver)
|
2010-12-22 00:28:45 +03:00
|
|
|
|
2012-12-15 19:43:52 +04:00
|
|
|
class ThumbnailRunnable : public nsRunnable {
|
2012-06-14 20:08:51 +04:00
|
|
|
public:
|
2012-12-15 19:43:52 +04:00
|
|
|
ThumbnailRunnable(nsIAndroidBrowserApp* aBrowserApp, int aTabId,
|
|
|
|
const nsTArray<nsIntPoint>& aPoints, RefCountedJavaObject* aBuffer):
|
|
|
|
mBrowserApp(aBrowserApp), mPoints(aPoints), mTabId(aTabId), mBuffer(aBuffer) {}
|
2012-06-14 20:08:51 +04:00
|
|
|
|
|
|
|
virtual nsresult Run() {
|
2015-01-10 03:33:57 +03:00
|
|
|
const auto& buffer = jni::Object::Ref::From(mBuffer->GetObject());
|
2012-06-14 20:08:51 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsCOMPtr<nsIBrowserTab> tab;
|
|
|
|
mBrowserApp->GetBrowserTab(mTabId, getter_AddRefs(tab));
|
2013-01-23 21:18:05 +04:00
|
|
|
if (!tab) {
|
2015-01-10 03:33:57 +03:00
|
|
|
widget::ThumbnailHelper::SendThumbnail(buffer, mTabId, false, false);
|
2013-01-23 21:18:05 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-06-14 20:08:51 +04:00
|
|
|
|
|
|
|
tab->GetWindow(getter_AddRefs(domWindow));
|
2013-01-23 21:18:05 +04:00
|
|
|
if (!domWindow) {
|
2015-01-10 03:33:57 +03:00
|
|
|
widget::ThumbnailHelper::SendThumbnail(buffer, mTabId, false, false);
|
2013-01-23 21:18:05 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-06-14 20:08:51 +04:00
|
|
|
|
2012-12-15 19:43:52 +04:00
|
|
|
NS_ASSERTION(mPoints.Length() == 1, "Thumbnail event does not have enough coordinates");
|
2012-06-14 20:08:51 +04:00
|
|
|
|
2014-05-06 09:33:29 +04:00
|
|
|
bool shouldStore = true;
|
|
|
|
nsresult rv = AndroidBridge::Bridge()->CaptureThumbnail(domWindow, mPoints[0].x, mPoints[0].y, mTabId, buffer, shouldStore);
|
2015-01-10 03:33:57 +03:00
|
|
|
widget::ThumbnailHelper::SendThumbnail(buffer, mTabId, NS_SUCCEEDED(rv), shouldStore);
|
2013-01-23 21:18:05 +04:00
|
|
|
return rv;
|
2012-06-14 20:08:51 +04:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIAndroidBrowserApp> mBrowserApp;
|
|
|
|
nsTArray<nsIntPoint> mPoints;
|
2012-12-15 19:43:52 +04:00
|
|
|
int mTabId;
|
2012-06-14 20:08:51 +04:00
|
|
|
nsRefPtr<RefCountedJavaObject> mBuffer;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
nsresult Callback(const nsAString& topic, const nsAString& state) {
|
2015-01-10 03:33:57 +03:00
|
|
|
widget::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
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
nsAppShell::nsAppShell()
|
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
|
|
|
: mQueueLock("nsAppShell.mQueueLock"),
|
|
|
|
mCondLock("nsAppShell.mCondLock"),
|
|
|
|
mQueueCond(mCondLock, "nsAppShell.mQueueCond"),
|
2014-06-02 19:13:09 +04:00
|
|
|
mQueuedViewportEvent(nullptr)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
gAppShell = this;
|
2012-06-07 06:39:01 +04:00
|
|
|
|
2012-08-16 23:34:53 +04:00
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
gAppShell = nullptr;
|
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
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::NotifyNativeEvent()
|
|
|
|
{
|
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
|
|
|
MutexAutoLock lock(mCondLock);
|
|
|
|
mQueueCond.Notify();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!gWidgetLog)
|
|
|
|
gWidgetLog = PR_NewLogModule("Widget");
|
|
|
|
#endif
|
|
|
|
|
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) {
|
2011-10-17 18:59:28 +04:00
|
|
|
obsServ->AddObserver(this, "xpcom-shutdown", false);
|
2014-07-12 01:15:39 +04:00
|
|
|
obsServ->AddObserver(this, "browser-delayed-startup-finished", false);
|
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
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
// 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);
|
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;
|
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");
|
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
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::ScheduleNativeEventCallback()
|
|
|
|
{
|
|
|
|
EVLOG("nsAppShell::ScheduleNativeEventCallback pth: %p thread: %p main: %d", (void*) pthread_self(), (void*) NS_GetCurrentThread(), NS_IsMainThread());
|
|
|
|
|
|
|
|
// this is valid to be called from any thread, so do so.
|
2013-04-18 01:39:12 +04:00
|
|
|
PostEvent(AndroidGeckoEvent::MakeNativePoke());
|
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);
|
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsAppShell", "ProcessNextNativeEvent",
|
|
|
|
js::ProfileEntry::Category::EVENTS);
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
nsAutoPtr<AndroidGeckoEvent> 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
|
|
|
{
|
|
|
|
MutexAutoLock lock(mCondLock);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-11-30 20:17:17 +04:00
|
|
|
curEvent = PopNextEvent();
|
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.
|
|
|
|
if (widget::GeckoAppShell::PumpMessageLoop()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsAppShell", "ProcessNextNativeEvent::Wait",
|
|
|
|
js::ProfileEntry::Category::EVENTS);
|
2015-04-22 18:30:13 +03:00
|
|
|
mozilla::HangMonitor::Suspend();
|
2014-05-24 01:12:29 +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
|
|
|
// hmm, should we really hardcode this 10s?
|
2011-08-29 22:29:39 +04:00
|
|
|
#if defined(DEBUG_ANDROID_EVENTS)
|
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
|
|
|
PRTime t0, t1;
|
|
|
|
EVLOG("nsAppShell: waiting on mQueueCond");
|
|
|
|
t0 = PR_Now();
|
|
|
|
mQueueCond.Wait(PR_MillisecondsToInterval(10000));
|
|
|
|
t1 = PR_Now();
|
|
|
|
EVLOG("nsAppShell: wait done, waited %d ms", (int)(t1-t0)/1000);
|
2010-06-04 00:56:36 +04:00
|
|
|
#else
|
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
|
|
|
mQueueCond.Wait();
|
2010-06-04 00:56:36 +04:00
|
|
|
#endif
|
|
|
|
|
2011-11-30 20:17:17 +04:00
|
|
|
curEvent = PopNextEvent();
|
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;
|
|
|
|
|
2015-04-22 18:30:13 +03:00
|
|
|
mozilla::HangMonitor::NotifyActivity(curEvent->IsInputEvent() ?
|
|
|
|
mozilla::HangMonitor::kUIActivity :
|
|
|
|
mozilla::HangMonitor::kGeneralActivity);
|
2014-07-18 20:53:41 +04:00
|
|
|
|
2012-04-08 08:50:42 +04:00
|
|
|
EVLOG("nsAppShell: event %p %d", (void*)curEvent.get(), curEvent->Type());
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
switch (curEvent->Type()) {
|
|
|
|
case AndroidGeckoEvent::NATIVE_POKE:
|
|
|
|
NativeEventCallback();
|
|
|
|
break;
|
|
|
|
|
2013-12-10 22:41:34 +04:00
|
|
|
case AndroidGeckoEvent::SENSOR_EVENT: {
|
2015-04-01 23:02:20 +03:00
|
|
|
nsAutoTArray<float, 4> values;
|
2012-03-21 10:36:17 +04:00
|
|
|
mozilla::hal::SensorType type = (mozilla::hal::SensorType) curEvent->Flags();
|
2012-03-14 03:57:51 +04:00
|
|
|
|
2012-03-21 10:36:17 +04:00
|
|
|
switch (type) {
|
2013-11-26 22:58:15 +04:00
|
|
|
// 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
|
2012-03-21 10:36:17 +04:00
|
|
|
case hal::SENSOR_ORIENTATION:
|
2013-11-26 22:58:15 +04:00
|
|
|
values.AppendElement(360 -curEvent->X());
|
2014-04-01 16:29:25 +04:00
|
|
|
values.AppendElement(-curEvent->Y());
|
2013-11-26 22:58:15 +04:00
|
|
|
values.AppendElement(-curEvent->Z());
|
|
|
|
break;
|
2012-03-21 10:36:17 +04:00
|
|
|
case hal::SENSOR_LINEAR_ACCELERATION:
|
2012-04-05 01:20:25 +04:00
|
|
|
case hal::SENSOR_ACCELERATION:
|
2012-03-21 10:36:17 +04:00
|
|
|
case hal::SENSOR_GYROSCOPE:
|
2012-05-09 07:56:54 +04:00
|
|
|
case hal::SENSOR_PROXIMITY:
|
2012-04-05 01:20:25 +04:00
|
|
|
values.AppendElement(curEvent->X());
|
2014-04-01 16:29:25 +04:00
|
|
|
values.AppendElement(curEvent->Y());
|
2012-03-21 10:36:17 +04:00
|
|
|
values.AppendElement(curEvent->Z());
|
2012-03-21 01:51:06 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-02 20:43:45 +04:00
|
|
|
case hal::SENSOR_LIGHT:
|
2012-03-21 10:36:17 +04:00
|
|
|
values.AppendElement(curEvent->X());
|
|
|
|
break;
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
case hal::SENSOR_ROTATION_VECTOR:
|
|
|
|
case hal::SENSOR_GAME_ROTATION_VECTOR:
|
|
|
|
values.AppendElement(curEvent->X());
|
|
|
|
values.AppendElement(curEvent->Y());
|
|
|
|
values.AppendElement(curEvent->Z());
|
|
|
|
values.AppendElement(curEvent->W());
|
|
|
|
break;
|
|
|
|
|
2012-03-14 03:57:51 +04:00
|
|
|
default:
|
2012-03-21 10:36:17 +04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR,
|
|
|
|
"Gecko", "### SENSOR_EVENT fired, but type wasn't known %d",
|
|
|
|
type);
|
2012-03-14 03:57:51 +04:00
|
|
|
}
|
2012-03-21 10:36:17 +04:00
|
|
|
|
|
|
|
const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState();
|
|
|
|
hal::SensorData sdata(type, PR_Now(), values, accuracy);
|
|
|
|
hal::NotifySensorChange(sdata);
|
|
|
|
}
|
|
|
|
break;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2014-10-01 02:20:58 +04:00
|
|
|
case AndroidGeckoEvent::PROCESS_OBJECT: {
|
|
|
|
|
|
|
|
switch (curEvent->Action()) {
|
|
|
|
case AndroidGeckoEvent::ACTION_OBJECT_LAYER_CLIENT:
|
2015-01-10 03:33:57 +03:00
|
|
|
AndroidBridge::Bridge()->SetLayerClient(
|
|
|
|
widget::GeckoLayerClient::Ref::From(curEvent->Object().wrappedObject()));
|
2014-10-01 02:20:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:03:11 +03:00
|
|
|
case AndroidGeckoEvent::LOCATION_EVENT: {
|
2010-06-05 01:14:43 +04:00
|
|
|
if (!gLocationCallback)
|
|
|
|
break;
|
|
|
|
|
2011-03-17 10:03:11 +03:00
|
|
|
nsGeoPosition* p = curEvent->GeoPosition();
|
2012-03-09 10:16:25 +04:00
|
|
|
if (p)
|
2010-06-05 01:14:43 +04:00
|
|
|
gLocationCallback->Update(curEvent->GeoPosition());
|
|
|
|
else
|
|
|
|
NS_WARNING("Received location event without geoposition!");
|
|
|
|
break;
|
2011-03-17 10:03:11 +03:00
|
|
|
}
|
2010-06-05 01:14:43 +04:00
|
|
|
|
2013-03-26 22:05:10 +04:00
|
|
|
case AndroidGeckoEvent::APP_BACKGROUNDING: {
|
2011-02-02 09:34:12 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 18:50:56 +03:00
|
|
|
mozilla::services::GetObserverService();
|
2012-07-30 18:20:58 +04:00
|
|
|
obsServ->NotifyObservers(nullptr, "application-background", nullptr);
|
2011-02-02 09:34:12 +03:00
|
|
|
|
2013-03-26 22:05:10 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(minimize, "heap-minimize");
|
|
|
|
obsServ->NotifyObservers(nullptr, "memory-pressure", minimize.get());
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2013-03-26 22:05:10 +04: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();
|
2012-02-16 00:34:31 +04:00
|
|
|
}
|
|
|
|
|
2010-06-23 04:13:23 +04:00
|
|
|
// 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
|
2011-06-07 11:38:00 +04:00
|
|
|
nsIPrefService* prefs = Preferences::GetService();
|
|
|
|
if (prefs) {
|
2012-01-28 10:04:54 +04:00
|
|
|
// reset the crash loop state
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch;
|
|
|
|
prefs->GetBranch("browser.sessionstore.", getter_AddRefs(prefBranch));
|
|
|
|
if (prefBranch)
|
|
|
|
prefBranch->SetIntPref("recent_crashes", 0);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
prefs->SavePrefFile(nullptr);
|
2011-06-07 11:38:00 +04:00
|
|
|
}
|
2010-06-18 01:33:15 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-26 22:05:10 +04:00
|
|
|
case AndroidGeckoEvent::APP_FOREGROUNDING: {
|
|
|
|
// 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();
|
|
|
|
}
|
2012-02-16 00:34:31 +04:00
|
|
|
|
2013-03-26 22:05:10 +04:00
|
|
|
// We didn't return from one of our own activities, so restore
|
|
|
|
// to foreground status
|
2011-08-21 23:11:31 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
2012-07-30 18:20:58 +04:00
|
|
|
obsServ->NotifyObservers(nullptr, "application-foreground", nullptr);
|
2011-08-21 23:11:31 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-15 19:43:52 +04:00
|
|
|
case AndroidGeckoEvent::THUMBNAIL: {
|
2012-02-17 22:52:26 +04:00
|
|
|
if (!mBrowserApp)
|
|
|
|
break;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t tabId = curEvent->MetaState();
|
2012-11-29 20:14:14 +04:00
|
|
|
const nsTArray<nsIntPoint>& points = curEvent->Points();
|
2012-06-14 20:08:51 +04:00
|
|
|
RefCountedJavaObject* buffer = curEvent->ByteBuffer();
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<ThumbnailRunnable> sr = new ThumbnailRunnable(mBrowserApp, tabId, points, buffer);
|
2012-12-15 19:43:52 +04:00
|
|
|
MessageLoop::current()->PostIdleTask(FROM_HERE, NewRunnableMethod(sr.get(), &ThumbnailRunnable::Run));
|
2012-02-17 22:52:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-21 07:59:23 +03:00
|
|
|
case AndroidGeckoEvent::ZOOMEDVIEW: {
|
|
|
|
if (!mBrowserApp)
|
|
|
|
break;
|
|
|
|
int32_t tabId = curEvent->MetaState();
|
|
|
|
const nsTArray<nsIntPoint>& points = curEvent->Points();
|
|
|
|
float scaleFactor = (float) curEvent->X();
|
|
|
|
nsRefPtr<RefCountedJavaObject> javaBuffer = curEvent->ByteBuffer();
|
|
|
|
const auto& mBuffer = jni::Object::Ref::From(javaBuffer->GetObject());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsCOMPtr<nsIBrowserTab> tab;
|
|
|
|
mBrowserApp->GetBrowserTab(tabId, getter_AddRefs(tab));
|
|
|
|
if (!tab) {
|
|
|
|
NS_ERROR("Can't find tab!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tab->GetWindow(getter_AddRefs(domWindow));
|
|
|
|
if (!domWindow) {
|
|
|
|
NS_ERROR("Can't find dom window!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(points.Length() == 2, "ZoomedView event does not have enough coordinates");
|
|
|
|
nsIntRect r(points[0].x, points[0].y, points[1].x, points[1].y);
|
2015-01-28 06:13:24 +03:00
|
|
|
AndroidBridge::Bridge()->CaptureZoomedView(domWindow, r, mBuffer, scaleFactor);
|
2015-01-21 07:59:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-20 08:50:07 +04:00
|
|
|
case AndroidGeckoEvent::VIEWPORT:
|
|
|
|
case AndroidGeckoEvent::BROADCAST: {
|
|
|
|
if (curEvent->Characters().Length() == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
|
|
|
|
const NS_ConvertUTF16toUTF8 topic(curEvent->Characters());
|
|
|
|
const nsPromiseFlatString& data = PromiseFlatString(curEvent->CharactersExtra());
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
obsServ->NotifyObservers(nullptr, topic.get(), data.get());
|
2012-04-20 08:50:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-10 22:41:34 +04:00
|
|
|
case AndroidGeckoEvent::TELEMETRY_UI_SESSION_STOP: {
|
|
|
|
if (curEvent->Characters().Length() == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUITelemetryObserver> obs;
|
|
|
|
mBrowserApp->GetUITelemetryObserver(getter_AddRefs(obs));
|
|
|
|
if (!obs)
|
|
|
|
break;
|
|
|
|
|
|
|
|
obs->StopSession(
|
|
|
|
nsString(curEvent->Characters()).get(),
|
|
|
|
nsString(curEvent->CharactersExtra()).get(),
|
|
|
|
curEvent->Time()
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::TELEMETRY_UI_SESSION_START: {
|
|
|
|
if (curEvent->Characters().Length() == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUITelemetryObserver> obs;
|
|
|
|
mBrowserApp->GetUITelemetryObserver(getter_AddRefs(obs));
|
|
|
|
if (!obs)
|
|
|
|
break;
|
|
|
|
|
|
|
|
obs->StartSession(
|
|
|
|
nsString(curEvent->Characters()).get(),
|
|
|
|
curEvent->Time()
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::TELEMETRY_UI_EVENT: {
|
2014-06-20 21:39:33 +04:00
|
|
|
if (curEvent->Data().Length() == 0)
|
2013-12-10 22:41:34 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUITelemetryObserver> obs;
|
|
|
|
mBrowserApp->GetUITelemetryObserver(getter_AddRefs(obs));
|
|
|
|
if (!obs)
|
|
|
|
break;
|
|
|
|
|
|
|
|
obs->AddEvent(
|
|
|
|
nsString(curEvent->Data()).get(),
|
|
|
|
nsString(curEvent->Characters()).get(),
|
|
|
|
curEvent->Time(),
|
|
|
|
nsString(curEvent->CharactersExtra()).get()
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-18 21:42:51 +04:00
|
|
|
case AndroidGeckoEvent::LOAD_URI: {
|
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdline
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
if (!cmdline)
|
|
|
|
break;
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
if (curEvent->Characters().Length() == 0)
|
|
|
|
break;
|
|
|
|
|
2010-06-18 21:42:51 +04:00
|
|
|
char *uri = ToNewUTF8String(curEvent->Characters());
|
|
|
|
if (!uri)
|
|
|
|
break;
|
|
|
|
|
2012-04-14 06:45:25 +04:00
|
|
|
char *flag = ToNewUTF8String(curEvent->CharactersExtra());
|
|
|
|
|
|
|
|
const char *argv[4] = {
|
2010-06-18 21:42:51 +04:00
|
|
|
"dummyappname",
|
2012-04-14 06:45:25 +04:00
|
|
|
"-url",
|
|
|
|
uri,
|
|
|
|
flag ? flag : ""
|
2010-06-18 21:42:51 +04:00
|
|
|
};
|
2013-01-04 01:52:32 +04:00
|
|
|
nsresult rv = cmdline->Init(4, argv, nullptr, nsICommandLine::STATE_REMOTE_AUTO);
|
2010-06-18 21:42:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
cmdline->Run();
|
2015-03-27 03:01:12 +03:00
|
|
|
free(uri);
|
2012-04-14 06:45:25 +04:00
|
|
|
if (flag)
|
2015-03-27 03:01:12 +03:00
|
|
|
free(flag);
|
2010-06-18 21:42:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-09 20:08:19 +04:00
|
|
|
case AndroidGeckoEvent::SIZE_CHANGED: {
|
|
|
|
// store the last resize event to dispatch it to new windows with a FORCED_RESIZE event
|
|
|
|
if (curEvent != gLastSizeChange) {
|
2013-04-18 01:39:12 +04:00
|
|
|
gLastSizeChange = AndroidGeckoEvent::CopyResizeEvent(curEvent);
|
2011-08-09 20:08:19 +04:00
|
|
|
}
|
|
|
|
nsWindow::OnGlobalAndroidEvent(curEvent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-06 04:14:23 +04:00
|
|
|
case AndroidGeckoEvent::VISITED: {
|
|
|
|
#ifdef MOZ_ANDROID_HISTORY
|
2012-11-09 13:55:59 +04:00
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
nsCOMPtr<nsIURI> visitedURI;
|
|
|
|
if (history &&
|
|
|
|
NS_SUCCEEDED(NS_NewURI(getter_AddRefs(visitedURI),
|
|
|
|
nsString(curEvent->Characters())))) {
|
|
|
|
history->NotifyVisited(visitedURI);
|
|
|
|
}
|
2012-01-06 04:14:23 +04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-17 22:40:39 +04:00
|
|
|
case AndroidGeckoEvent::NETWORK_CHANGED: {
|
2014-03-05 13:42:42 +04:00
|
|
|
hal::NotifyNetworkChange(hal::NetworkInformation(curEvent->ConnectionType(),
|
2013-07-11 19:39:36 +04:00
|
|
|
curEvent->IsWifi(),
|
|
|
|
curEvent->DHCPGateway()));
|
2012-01-17 22:40:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-20 17:09:45 +04:00
|
|
|
case AndroidGeckoEvent::SCREENORIENTATION_CHANGED: {
|
2012-05-09 01:36:07 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIScreenManager> screenMgr =
|
|
|
|
do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Can't find nsIScreenManager!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect rect;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t colorDepth, pixelDepth;
|
2012-05-09 01:36:07 +04:00
|
|
|
dom::ScreenOrientation orientation;
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
|
|
|
|
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
|
|
|
|
screen->GetColorDepth(&colorDepth);
|
|
|
|
screen->GetPixelDepth(&pixelDepth);
|
|
|
|
orientation =
|
|
|
|
static_cast<dom::ScreenOrientation>(curEvent->ScreenOrientation());
|
|
|
|
|
|
|
|
hal::NotifyScreenConfigurationChange(
|
|
|
|
hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth));
|
2012-03-20 17:09:45 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-16 01:40:27 +04:00
|
|
|
case AndroidGeckoEvent::CALL_OBSERVER:
|
2013-06-19 21:55:35 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserver> observer;
|
|
|
|
mObserversHash.Get(curEvent->Characters(), getter_AddRefs(observer));
|
|
|
|
|
|
|
|
if (observer) {
|
|
|
|
observer->Observe(nullptr, NS_ConvertUTF16toUTF8(curEvent->CharactersExtra()).get(),
|
|
|
|
nsString(curEvent->Data()).get());
|
|
|
|
} else {
|
|
|
|
ALOG("Call_Observer event: Observer was not found!");
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::REMOVE_OBSERVER:
|
|
|
|
mObserversHash.Remove(curEvent->Characters());
|
2013-06-16 01:40:27 +04:00
|
|
|
break;
|
|
|
|
|
2013-09-05 23:32:04 +04:00
|
|
|
case AndroidGeckoEvent::ADD_OBSERVER:
|
|
|
|
AddObserver(curEvent->Characters(), curEvent->Observer());
|
|
|
|
break;
|
|
|
|
|
2013-09-04 17:58:23 +04:00
|
|
|
case AndroidGeckoEvent::PREFERENCES_GET:
|
|
|
|
case AndroidGeckoEvent::PREFERENCES_OBSERVE: {
|
|
|
|
const nsTArray<nsString> &prefNames = curEvent->PrefNames();
|
|
|
|
size_t count = prefNames.Length();
|
2014-01-04 19:02:17 +04:00
|
|
|
nsAutoArrayPtr<const char16_t*> prefNamePtrs(new const char16_t*[count]);
|
2013-09-04 17:58:23 +04:00
|
|
|
for (size_t i = 0; i < count; ++i) {
|
|
|
|
prefNamePtrs[i] = prefNames[i].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curEvent->Type() == AndroidGeckoEvent::PREFERENCES_GET) {
|
|
|
|
mBrowserApp->GetPreferences(curEvent->RequestId(), prefNamePtrs, count);
|
|
|
|
} else {
|
|
|
|
mBrowserApp->ObservePreferences(curEvent->RequestId(), prefNamePtrs, count);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::PREFERENCES_REMOVE_OBSERVERS:
|
|
|
|
mBrowserApp->RemovePreferenceObservers(curEvent->RequestId());
|
|
|
|
break;
|
|
|
|
|
2013-06-18 01:09:09 +04:00
|
|
|
case AndroidGeckoEvent::LOW_MEMORY:
|
|
|
|
// TODO hook in memory-reduction stuff for different levels here
|
|
|
|
if (curEvent->MetaState() >= AndroidGeckoEvent::MEMORY_PRESSURE_MEDIUM) {
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(nullptr,
|
|
|
|
"memory-pressure",
|
2013-12-13 05:50:01 +04:00
|
|
|
MOZ_UTF16("low-memory"));
|
2013-06-18 01:09:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::NETWORK_LINK_CHANGE:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(nullptr,
|
|
|
|
NS_NETWORK_LINK_TOPIC,
|
|
|
|
nsString(curEvent->Characters()).get());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-15 23:03:47 +04:00
|
|
|
case AndroidGeckoEvent::TELEMETRY_HISTOGRAM_ADD:
|
|
|
|
Telemetry::Accumulate(NS_ConvertUTF16toUTF8(curEvent->Characters()).get(),
|
|
|
|
curEvent->Count());
|
|
|
|
break;
|
|
|
|
|
2014-04-22 18:53:48 +04:00
|
|
|
case AndroidGeckoEvent::GAMEPAD_ADDREMOVE: {
|
|
|
|
#ifdef MOZ_GAMEPAD
|
|
|
|
if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_ADDED) {
|
2015-04-24 01:05:29 +03:00
|
|
|
int svc_id = dom::GamepadFunctions::AddGamepad("android",
|
|
|
|
dom::GamepadMappingType::Standard,
|
|
|
|
dom::kStandardGamepadButtons,
|
|
|
|
dom::kStandardGamepadAxes);
|
2015-01-10 03:33:57 +03:00
|
|
|
widget::GeckoAppShell::GamepadAdded(curEvent->ID(),
|
|
|
|
svc_id);
|
2014-04-22 18:53:48 +04:00
|
|
|
} else if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_REMOVED) {
|
2015-04-24 01:05:29 +03:00
|
|
|
dom::GamepadFunctions::RemoveGamepad(curEvent->ID());
|
2014-04-22 18:53:48 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::GAMEPAD_DATA: {
|
|
|
|
#ifdef MOZ_GAMEPAD
|
|
|
|
int id = curEvent->ID();
|
|
|
|
if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_BUTTON) {
|
2015-04-24 01:05:29 +03:00
|
|
|
dom::GamepadFunctions::NewButtonEvent(id, curEvent->GamepadButton(),
|
2014-04-22 18:53:48 +04:00
|
|
|
curEvent->GamepadButtonPressed(),
|
|
|
|
curEvent->GamepadButtonValue());
|
|
|
|
} else if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_AXES) {
|
|
|
|
int valid = curEvent->Flags();
|
|
|
|
const nsTArray<float>& values = curEvent->GamepadValues();
|
|
|
|
for (unsigned i = 0; i < values.Length(); i++) {
|
|
|
|
if (valid & (1<<i)) {
|
2015-04-24 01:05:29 +03:00
|
|
|
dom::GamepadFunctions::NewAxisMoveEvent(id, i, values[i]);
|
2014-04-22 18:53:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2013-03-11 02:43:30 +04:00
|
|
|
case AndroidGeckoEvent::NOOP:
|
|
|
|
break;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
default:
|
2011-01-19 03:25:20 +03:00
|
|
|
nsWindow::OnGlobalAndroidEvent(curEvent);
|
2013-03-11 02:43:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curEvent->AckNeeded()) {
|
2015-01-10 03:33:57 +03:00
|
|
|
widget::GeckoAppShell::AcknowledgeEvent();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
EVLOG("nsAppShell: -- done event %p %d", (void*)curEvent.get(), curEvent->Type());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-09 20:08:19 +04:00
|
|
|
void
|
|
|
|
nsAppShell::ResendLastResizeEvent(nsWindow* aDest) {
|
|
|
|
if (gLastSizeChange) {
|
|
|
|
nsWindow::OnGlobalAndroidEvent(gLastSizeChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
AndroidGeckoEvent*
|
2011-11-30 20:17:17 +04:00
|
|
|
nsAppShell::PopNextEvent()
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
AndroidGeckoEvent *ae = nullptr;
|
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
|
|
|
MutexAutoLock lock(mQueueLock);
|
2010-06-04 00:56:36 +04:00
|
|
|
if (mEventQueue.Length()) {
|
|
|
|
ae = mEventQueue[0];
|
|
|
|
mEventQueue.RemoveElementAt(0);
|
2014-06-02 19:13:09 +04:00
|
|
|
if (mQueuedViewportEvent == ae) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mQueuedViewportEvent = nullptr;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ae;
|
|
|
|
}
|
|
|
|
|
|
|
|
AndroidGeckoEvent*
|
|
|
|
nsAppShell::PeekNextEvent()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
AndroidGeckoEvent *ae = nullptr;
|
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
|
|
|
MutexAutoLock lock(mQueueLock);
|
2010-06-04 00:56:36 +04:00
|
|
|
if (mEventQueue.Length()) {
|
|
|
|
ae = mEventQueue[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ae;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::PostEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
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
|
|
|
{
|
2012-04-10 18:28:43 +04:00
|
|
|
// set this to true when inserting events that we can coalesce
|
|
|
|
// viewport events across. this is effectively maintaining a whitelist
|
|
|
|
// of events that are unaffected by viewport changes.
|
|
|
|
bool allowCoalescingNextViewport = false;
|
|
|
|
|
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
|
|
|
MutexAutoLock lock(mQueueLock);
|
2012-04-08 08:50:42 +04:00
|
|
|
EVLOG("nsAppShell::PostEvent %p %d", ae, ae->Type());
|
|
|
|
switch (ae->Type()) {
|
2013-03-21 02:45:07 +04:00
|
|
|
case AndroidGeckoEvent::COMPOSITOR_CREATE:
|
2012-04-08 08:50:42 +04:00
|
|
|
case AndroidGeckoEvent::COMPOSITOR_PAUSE:
|
|
|
|
case AndroidGeckoEvent::COMPOSITOR_RESUME:
|
2012-03-29 02:00:32 +04:00
|
|
|
// Give priority to these events, but maintain their order wrt each other.
|
2012-04-08 08:50:42 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i = 0;
|
2012-04-08 08:50:42 +04:00
|
|
|
while (i < mEventQueue.Length() &&
|
2013-03-21 02:45:07 +04:00
|
|
|
(mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_CREATE ||
|
|
|
|
mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_PAUSE ||
|
2012-04-08 08:50:42 +04:00
|
|
|
mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_RESUME)) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
EVLOG("nsAppShell: Inserting compositor event %d at position %d to maintain priority order", ae->Type(), i);
|
|
|
|
mEventQueue.InsertElementAt(i, ae);
|
2012-03-29 02:00:32 +04:00
|
|
|
}
|
2012-04-08 08:50:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::VIEWPORT:
|
|
|
|
if (mQueuedViewportEvent) {
|
|
|
|
// drop the previous viewport event now that we have a new one
|
|
|
|
EVLOG("nsAppShell: Dropping old viewport event at %p in favour of new VIEWPORT event %p", mQueuedViewportEvent, ae);
|
|
|
|
mEventQueue.RemoveElement(mQueuedViewportEvent);
|
|
|
|
delete mQueuedViewportEvent;
|
|
|
|
}
|
|
|
|
mQueuedViewportEvent = ae;
|
2012-04-10 18:28:43 +04:00
|
|
|
allowCoalescingNextViewport = true;
|
2012-04-10 18:27:04 +04:00
|
|
|
|
2012-04-08 08:50:42 +04:00
|
|
|
mEventQueue.AppendElement(ae);
|
|
|
|
break;
|
2011-08-24 00:52:03 +04:00
|
|
|
|
2012-04-08 08:50:42 +04:00
|
|
|
case AndroidGeckoEvent::MOTION_EVENT:
|
2014-08-09 02:15:37 +04:00
|
|
|
case AndroidGeckoEvent::APZ_INPUT_EVENT:
|
|
|
|
if (mAllowCoalescingTouches && mEventQueue.Length() > 0) {
|
2012-04-08 08:50:42 +04:00
|
|
|
int len = mEventQueue.Length();
|
2014-08-09 02:15:37 +04:00
|
|
|
AndroidGeckoEvent* event = mEventQueue[len - 1];
|
|
|
|
if (ae->CanCoalesceWith(event)) {
|
|
|
|
// consecutive motion-move events; drop the last one before adding the new one
|
|
|
|
EVLOG("nsAppShell: Dropping old move event at %p in favour of new move event %p", event, ae);
|
|
|
|
mEventQueue.RemoveElementAt(len - 1);
|
|
|
|
delete event;
|
2012-04-08 08:50:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mEventQueue.AppendElement(ae);
|
|
|
|
break;
|
|
|
|
|
2012-04-10 18:28:43 +04:00
|
|
|
case AndroidGeckoEvent::NATIVE_POKE:
|
|
|
|
allowCoalescingNextViewport = true;
|
|
|
|
// fall through
|
|
|
|
|
2012-04-08 08:50:42 +04:00
|
|
|
default:
|
|
|
|
mEventQueue.AppendElement(ae);
|
|
|
|
break;
|
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
|
|
|
}
|
2012-04-10 18:28:43 +04:00
|
|
|
|
|
|
|
// if the event wasn't on our whitelist then reset mQueuedViewportEvent
|
|
|
|
// so that we don't coalesce future viewport events into the last viewport
|
|
|
|
// event we added
|
|
|
|
if (!allowCoalescingNextViewport)
|
2012-07-30 18:20:58 +04:00
|
|
|
mQueuedViewportEvent = nullptr;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
NotifyNativeEvent();
|
|
|
|
}
|
|
|
|
|
2011-02-02 09:34:12 +03:00
|
|
|
void
|
|
|
|
nsAppShell::OnResume()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2014-12-16 01:04:33 +03:00
|
|
|
if (!nsAppShell::gAppShell) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return nsAppShell::gAppShell->ProcessNextNativeEvent(true) ? true : false;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyEvent()
|
|
|
|
{
|
2014-12-16 01:04:33 +03:00
|
|
|
if (nsAppShell::gAppShell) {
|
|
|
|
nsAppShell::gAppShell->NotifyNativeEvent();
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|