2010-06-03 13:56:36 -07:00
|
|
|
/* -*- Mode: c++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
|
2012-05-21 04:12:37 -07: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-03 13:56:36 -07:00
|
|
|
|
2011-10-29 03:35:29 -07:00
|
|
|
// Make sure the order of included headers
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "nspr/prtypes.h"
|
2012-06-14 09:08:51 -07:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/task.h"
|
2011-10-29 03:35:29 -07:00
|
|
|
|
2012-01-17 10:40:39 -08:00
|
|
|
#include "mozilla/Hal.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include "nsWindow.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2010-06-18 10:42:51 -07:00
|
|
|
#include "nsICommandLineRunner.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIAppStartup.h"
|
2010-06-04 14:14:43 -07:00
|
|
|
#include "nsIGeolocationProvider.h"
|
2012-04-17 10:29:52 -07:00
|
|
|
#include "nsCacheService.h"
|
2012-04-24 12:13:36 -07:00
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsDOMNotifyPaintEvent.h"
|
|
|
|
#include "nsIDOMClientRectList.h"
|
|
|
|
#include "nsIDOMClientRect.h"
|
2012-06-06 19:39:01 -07:00
|
|
|
#include "nsIDOMWakeLockListener.h"
|
|
|
|
#include "nsIPowerManagerService.h"
|
2012-07-04 08:42:29 -07:00
|
|
|
#include "nsFrameManager.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-06-17 14:33:15 -07:00
|
|
|
#include "mozilla/Services.h"
|
2011-02-11 09:27:17 -08:00
|
|
|
#include "mozilla/unused.h"
|
2011-06-07 00:38:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-10-29 03:35:29 -07:00
|
|
|
#include "mozilla/Hal.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include <android/log.h>
|
|
|
|
#include <pthread.h>
|
2011-02-27 07:50:56 -08:00
|
|
|
#include <wchar.h>
|
2012-02-22 08:35:25 -08:00
|
|
|
|
2012-03-20 06:09:45 -07:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
|
|
|
|
2012-04-16 12:07:56 -07:00
|
|
|
#include "sampler.h"
|
2012-01-05 16:14:23 -08:00
|
|
|
#ifdef MOZ_ANDROID_HISTORY
|
|
|
|
#include "nsAndroidHistory.h"
|
|
|
|
#endif
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG
|
|
|
|
#include "prlog.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-29 11:29:39 -07:00
|
|
|
#ifdef DEBUG_ANDROID_EVENTS
|
2010-06-03 13:56:36 -07:00
|
|
|
#define EVLOG(args...) ALOG(args)
|
|
|
|
#else
|
|
|
|
#define EVLOG(args...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PRLogModuleInfo *gWidgetLog = nsnull;
|
|
|
|
#endif
|
|
|
|
|
2010-06-04 14:14:43 -07:00
|
|
|
nsIGeolocationUpdate *gLocationCallback = nsnull;
|
2011-08-09 09:08:19 -07:00
|
|
|
nsAutoPtr<mozilla::AndroidGeckoEvent> gLastSizeChange;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
nsAppShell *nsAppShell::gAppShell = nsnull;
|
|
|
|
|
2010-12-21 13:28:45 -08:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver)
|
|
|
|
|
2012-06-14 09:08:51 -07:00
|
|
|
class ScreenshotRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
ScreenshotRunnable(nsIAndroidBrowserApp* aBrowserApp, int aTabId, nsTArray<nsIntPoint>& aPoints, int aToken, RefCountedJavaObject* aBuffer):
|
2012-07-12 09:52:52 -07:00
|
|
|
mBrowserApp(aBrowserApp), mPoints(aPoints), mTabId(aTabId), mToken(aToken), mBuffer(aBuffer) {}
|
2012-06-14 09:08:51 -07:00
|
|
|
|
|
|
|
virtual nsresult Run() {
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsCOMPtr<nsIBrowserTab> tab;
|
|
|
|
mBrowserApp->GetBrowserTab(mTabId, getter_AddRefs(tab));
|
|
|
|
if (!tab)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
tab->GetWindow(getter_AddRefs(domWindow));
|
|
|
|
if (!domWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_ASSERTION(mPoints.Length() == 5, "Screenshot event does not have enough coordinates");
|
|
|
|
|
|
|
|
AndroidBridge::Bridge()->TakeScreenshot(domWindow, mPoints[0].x, mPoints[0].y, mPoints[1].x, mPoints[1].y, mPoints[2].x, mPoints[2].y, mPoints[3].x, mPoints[3].y, mPoints[4].x, mPoints[4].y, mTabId, mToken, mBuffer->GetObject());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIAndroidBrowserApp> mBrowserApp;
|
|
|
|
nsTArray<nsIntPoint> mPoints;
|
|
|
|
int mTabId, mToken;
|
|
|
|
nsRefPtr<RefCountedJavaObject> mBuffer;
|
|
|
|
};
|
|
|
|
|
2012-04-24 12:13:36 -07:00
|
|
|
class AfterPaintListener : public nsIDOMEventListener {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
void Register(nsIDOMWindow* window) {
|
|
|
|
if (mEventTarget)
|
|
|
|
Unregister();
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window);
|
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
mEventTarget = win->GetChromeEventHandler();
|
|
|
|
if (mEventTarget)
|
|
|
|
mEventTarget->AddEventListener(NS_LITERAL_STRING("MozAfterPaint"), this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Unregister() {
|
|
|
|
if (mEventTarget)
|
|
|
|
mEventTarget->RemoveEventListener(NS_LITERAL_STRING("MozAfterPaint"), this, false);
|
|
|
|
mEventTarget = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult HandleEvent(nsIDOMEvent* aEvent) {
|
2012-07-04 08:42:29 -07:00
|
|
|
PRUint32 generation = nsFrameManager::GetGlobalGenerationNumber();
|
|
|
|
if (mLastGeneration == generation) {
|
|
|
|
// the frame tree has not changed since our last AfterPaint
|
|
|
|
// so we can drop this event.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastGeneration = generation;
|
|
|
|
|
2012-04-24 12:13:36 -07:00
|
|
|
nsCOMPtr<nsIDOMNotifyPaintEvent> paintEvent = do_QueryInterface(aEvent);
|
|
|
|
if (!paintEvent)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-06-14 09:08:51 -07:00
|
|
|
nsCOMPtr<nsIDOMClientRect> rect;
|
|
|
|
paintEvent->GetBoundingClientRect(getter_AddRefs(rect));
|
|
|
|
float top, left, bottom, right;
|
|
|
|
rect->GetTop(&top);
|
|
|
|
rect->GetLeft(&left);
|
|
|
|
rect->GetRight(&right);
|
|
|
|
rect->GetBottom(&bottom);
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "GeckoScreenshot", "rect: %f, %f, %f, %f", top, left, right, bottom);
|
|
|
|
AndroidBridge::NotifyPaintedRect(top, left, bottom, right);
|
2012-04-24 12:13:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AfterPaintListener() {
|
|
|
|
if (mEventTarget)
|
|
|
|
Unregister();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-07-04 08:42:29 -07:00
|
|
|
PRUint32 mLastGeneration;
|
2012-04-24 12:13:36 -07:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> mEventTarget;
|
|
|
|
};
|
|
|
|
|
2012-06-06 19:39:01 -07:00
|
|
|
class WakeLockListener : public nsIDOMMozWakeLockListener {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS;
|
|
|
|
|
|
|
|
nsresult Callback(const nsAString& topic, const nsAString& state) {
|
|
|
|
AndroidBridge::Bridge()->NotifyWakeLockChanged(topic, state);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-24 12:13:36 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(AfterPaintListener, nsIDOMEventListener)
|
|
|
|
nsCOMPtr<AfterPaintListener> sAfterPaintListener = nsnull;
|
|
|
|
|
2012-06-06 19:39:01 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(WakeLockListener, nsIDOMMozWakeLockListener)
|
|
|
|
nsCOMPtr<nsIPowerManagerService> sPowerManagerService = nsnull;
|
|
|
|
nsCOMPtr<nsIDOMMozWakeLockListener> sWakeLockListener = nsnull;
|
|
|
|
|
2010-06-03 13:56:36 -07: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-03-31 21:29:02 -07:00
|
|
|
: mQueueLock("nsAppShell.mQueueLock"),
|
|
|
|
mCondLock("nsAppShell.mCondLock"),
|
|
|
|
mQueueCond(mCondLock, "nsAppShell.mQueueCond"),
|
2012-04-07 21:50:42 -07:00
|
|
|
mQueuedDrawEvent(nsnull),
|
2012-04-10 07:27:04 -07:00
|
|
|
mQueuedViewportEvent(nsnull),
|
|
|
|
mAllowCoalescingNextDraw(false)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
gAppShell = this;
|
2012-04-24 12:13:36 -07:00
|
|
|
sAfterPaintListener = new AfterPaintListener();
|
2012-06-06 19:39:01 -07:00
|
|
|
|
|
|
|
sPowerManagerService = do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (sPowerManagerService) {
|
|
|
|
sWakeLockListener = new WakeLockListener();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Failed to retrieve PowerManagerService, wakelocks will be broken!");
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::~nsAppShell()
|
|
|
|
{
|
|
|
|
gAppShell = nsnull;
|
2012-04-24 12:13:36 -07:00
|
|
|
delete sAfterPaintListener;
|
2012-06-06 19:39:01 -07:00
|
|
|
|
|
|
|
if (sPowerManagerService) {
|
|
|
|
sPowerManagerService->RemoveWakeLockListener(sWakeLockListener);
|
|
|
|
|
|
|
|
sPowerManagerService = nsnull;
|
|
|
|
sWakeLockListener = nsnull;
|
|
|
|
}
|
2010-06-03 13:56:36 -07: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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mCondLock);
|
|
|
|
mQueueCond.Notify();
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-06-07 00:38:00 -07:00
|
|
|
#define PREFNAME_MATCH_OS "intl.locale.matchOS"
|
|
|
|
#define PREFNAME_UA_LOCALE "general.useragent.locale"
|
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
PREFNAME_MATCH_OS,
|
|
|
|
PREFNAME_UA_LOCALE,
|
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
nsresult
|
|
|
|
nsAppShell::Init()
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!gWidgetLog)
|
|
|
|
gWidgetLog = PR_NewLogModule("Widget");
|
|
|
|
#endif
|
|
|
|
|
2010-06-14 19:17:37 -07:00
|
|
|
mObserversHash.Init();
|
|
|
|
|
2010-10-25 20:10:07 -07:00
|
|
|
nsresult rv = nsBaseAppShell::Init();
|
2011-02-27 07:50:56 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
2010-12-21 13:28:45 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 07:50:56 -08:00
|
|
|
mozilla::services::GetObserverService();
|
2010-12-21 13:28:45 -08:00
|
|
|
if (obsServ) {
|
2011-10-17 07:59:28 -07:00
|
|
|
obsServ->AddObserver(this, "xpcom-shutdown", false);
|
2010-12-21 13:28:45 -08:00
|
|
|
}
|
2011-02-27 07:50:56 -08:00
|
|
|
|
2012-06-06 19:39:01 -07:00
|
|
|
if (sPowerManagerService)
|
|
|
|
sPowerManagerService->AddWakeLockListener(sWakeLockListener);
|
|
|
|
|
2011-02-27 07:50:56 -08:00
|
|
|
if (!bridge)
|
|
|
|
return rv;
|
|
|
|
|
2011-06-07 00:38:00 -07:00
|
|
|
Preferences::AddStrongObservers(this, kObservedPrefs);
|
2011-03-16 16:17:59 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool match;
|
2011-06-07 00:38:00 -07:00
|
|
|
rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match);
|
2011-03-16 16:17:59 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
bridge->SetSelectedLocale(EmptyString());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-06-07 00:38:00 -07:00
|
|
|
|
|
|
|
nsAutoString locale;
|
|
|
|
rv = Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = Preferences::GetString(PREFNAME_UA_LOCALE, &locale);
|
2011-03-16 16:17:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bridge->SetSelectedLocale(locale);
|
2010-10-25 20:10:07 -07:00
|
|
|
return rv;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2010-12-21 13:28:45 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShell::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
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 09:45:44 -07:00
|
|
|
return nsBaseAppShell::Observe(aSubject, aTopic, aData);
|
2011-03-16 16:17:59 -07:00
|
|
|
} else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && aData && (
|
|
|
|
nsDependentString(aData).Equals(
|
2011-06-07 00:38:00 -07:00
|
|
|
NS_LITERAL_STRING(PREFNAME_UA_LOCALE)) ||
|
2011-03-16 16:17:59 -07:00
|
|
|
nsDependentString(aData).Equals(
|
2011-06-07 00:38:00 -07:00
|
|
|
NS_LITERAL_STRING(PREFNAME_MATCH_OS)))) {
|
2011-02-27 07:50:56 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
2011-06-07 00:38:00 -07:00
|
|
|
if (!bridge) {
|
2011-02-27 07:50:56 -08:00
|
|
|
return NS_OK;
|
2011-06-07 00:38:00 -07:00
|
|
|
}
|
2011-03-16 16:17:59 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool match;
|
2011-06-07 00:38:00 -07:00
|
|
|
nsresult rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match);
|
2011-03-16 16:17:59 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-02-27 07:50:56 -08:00
|
|
|
|
2011-03-16 16:17:59 -07:00
|
|
|
if (match) {
|
|
|
|
bridge->SetSelectedLocale(EmptyString());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-06-07 00:38:00 -07:00
|
|
|
|
|
|
|
nsAutoString locale;
|
|
|
|
if (NS_FAILED(Preferences::GetLocalizedString(PREFNAME_UA_LOCALE,
|
|
|
|
&locale))) {
|
|
|
|
locale = Preferences::GetString(PREFNAME_UA_LOCALE);
|
2011-03-16 16:17:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bridge->SetSelectedLocale(locale);
|
2011-02-27 07:50:56 -08:00
|
|
|
return NS_OK;
|
2010-12-21 13:28:45 -08:00
|
|
|
}
|
2011-03-14 09:45:44 -07:00
|
|
|
return NS_OK;
|
2010-12-21 13:28:45 -08:00
|
|
|
}
|
2010-06-03 13:56:36 -07: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.
|
|
|
|
PostEvent(new AndroidGeckoEvent(AndroidGeckoEvent::NATIVE_POKE));
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
EVLOG("nsAppShell::ProcessNextNativeEvent %d", mayWait);
|
|
|
|
|
2012-04-16 12:07:56 -07:00
|
|
|
SAMPLE_LABEL("nsAppShell", "ProcessNextNativeEvent");
|
2010-06-03 13:56:36 -07: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-03-31 21:29:02 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mCondLock);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-11-30 08:17:17 -08: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-03-31 21:29:02 -07:00
|
|
|
if (!curEvent && mayWait) {
|
2012-04-16 12:07:56 -07:00
|
|
|
SAMPLE_LABEL("nsAppShell::ProcessNextNativeEvent", "Wait");
|
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-03-31 21:29:02 -07:00
|
|
|
// hmm, should we really hardcode this 10s?
|
2011-08-29 11:29:39 -07: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-03-31 21:29:02 -07: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-03 13:56:36 -07: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-03-31 21:29:02 -07:00
|
|
|
mQueueCond.Wait();
|
2010-06-03 13:56:36 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-30 08:17:17 -08: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-03-31 21:29:02 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!curEvent)
|
|
|
|
return false;
|
|
|
|
|
2012-04-07 21:50:42 -07:00
|
|
|
EVLOG("nsAppShell: event %p %d", (void*)curEvent.get(), curEvent->Type());
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
switch (curEvent->Type()) {
|
|
|
|
case AndroidGeckoEvent::NATIVE_POKE:
|
|
|
|
NativeEventCallback();
|
|
|
|
break;
|
|
|
|
|
2012-03-13 16:57:51 -07:00
|
|
|
case AndroidGeckoEvent::SENSOR_EVENT:
|
2012-03-20 23:36:17 -07:00
|
|
|
{
|
|
|
|
InfallibleTArray<float> values;
|
|
|
|
mozilla::hal::SensorType type = (mozilla::hal::SensorType) curEvent->Flags();
|
2012-03-13 16:57:51 -07:00
|
|
|
|
2012-03-20 23:36:17 -07:00
|
|
|
switch (type) {
|
|
|
|
case hal::SENSOR_ORIENTATION:
|
|
|
|
case hal::SENSOR_LINEAR_ACCELERATION:
|
2012-04-04 14:20:25 -07:00
|
|
|
case hal::SENSOR_ACCELERATION:
|
2012-03-20 23:36:17 -07:00
|
|
|
case hal::SENSOR_GYROSCOPE:
|
2012-05-08 20:56:54 -07:00
|
|
|
case hal::SENSOR_PROXIMITY:
|
2012-04-04 14:20:25 -07:00
|
|
|
values.AppendElement(curEvent->X());
|
|
|
|
values.AppendElement(curEvent->Y());
|
2012-03-20 23:36:17 -07:00
|
|
|
values.AppendElement(curEvent->Z());
|
2012-03-20 14:51:06 -07:00
|
|
|
break;
|
|
|
|
|
2012-05-02 09:43:45 -07:00
|
|
|
case hal::SENSOR_LIGHT:
|
2012-03-20 23:36:17 -07:00
|
|
|
values.AppendElement(curEvent->X());
|
|
|
|
break;
|
|
|
|
|
2012-03-13 16:57:51 -07:00
|
|
|
default:
|
2012-03-20 23:36:17 -07:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR,
|
|
|
|
"Gecko", "### SENSOR_EVENT fired, but type wasn't known %d",
|
|
|
|
type);
|
2012-03-13 16:57:51 -07:00
|
|
|
}
|
2012-03-20 23:36:17 -07:00
|
|
|
|
|
|
|
const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState();
|
|
|
|
hal::SensorData sdata(type, PR_Now(), values, accuracy);
|
|
|
|
hal::NotifySensorChange(sdata);
|
|
|
|
}
|
|
|
|
break;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-03-17 00:03:11 -07:00
|
|
|
case AndroidGeckoEvent::LOCATION_EVENT: {
|
2010-06-04 14:14:43 -07:00
|
|
|
if (!gLocationCallback)
|
|
|
|
break;
|
|
|
|
|
2011-03-17 00:03:11 -07:00
|
|
|
nsGeoPosition* p = curEvent->GeoPosition();
|
2012-03-08 22:16:25 -08:00
|
|
|
if (p)
|
2010-06-04 14:14:43 -07:00
|
|
|
gLocationCallback->Update(curEvent->GeoPosition());
|
|
|
|
else
|
|
|
|
NS_WARNING("Received location event without geoposition!");
|
|
|
|
break;
|
2011-03-17 00:03:11 -07:00
|
|
|
}
|
2010-06-04 14:14:43 -07:00
|
|
|
|
2011-02-01 22:34:12 -08:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_STOPPING: {
|
2012-02-15 12:34:31 -08:00
|
|
|
if (curEvent->Flags() > 0)
|
|
|
|
break;
|
|
|
|
|
2011-02-01 22:34:12 -08:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 07:50:56 -08:00
|
|
|
mozilla::services::GetObserverService();
|
2011-02-01 22:34:12 -08:00
|
|
|
NS_NAMED_LITERAL_STRING(minimize, "heap-minimize");
|
|
|
|
obsServ->NotifyObservers(nsnull, "memory-pressure", minimize.get());
|
2011-08-21 12:11:31 -07:00
|
|
|
obsServ->NotifyObservers(nsnull, "application-background", nsnull);
|
2011-02-01 22:34:12 -08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-11 14:36:11 -08:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_SHUTDOWN: {
|
2010-06-17 14:33:15 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 07:50:56 -08:00
|
|
|
mozilla::services::GetObserverService();
|
2010-06-17 14:33:15 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(context, "shutdown-persist");
|
|
|
|
obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
|
|
|
|
obsServ->NotifyObservers(nsnull, "quit-application-forced", nsnull);
|
|
|
|
obsServ->NotifyObservers(nsnull, "profile-change-net-teardown", context.get());
|
|
|
|
obsServ->NotifyObservers(nsnull, "profile-change-teardown", context.get());
|
|
|
|
obsServ->NotifyObservers(nsnull, "profile-before-change", context.get());
|
2010-06-03 13:56:36 -07:00
|
|
|
nsCOMPtr<nsIAppStartup> appSvc = do_GetService("@mozilla.org/toolkit/app-startup;1");
|
|
|
|
if (appSvc)
|
|
|
|
appSvc->Quit(nsIAppStartup::eForceQuit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-17 14:33:15 -07:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_PAUSING: {
|
2012-02-15 12:34:31 -08:00
|
|
|
if (curEvent->Flags() == 0) {
|
|
|
|
// We aren't transferring to one of our own activities, so set
|
|
|
|
// background status
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
obsServ->NotifyObservers(nsnull, "application-background", nsnull);
|
2012-04-17 10:29:52 -07: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 resume
|
2012-04-18 13:08:36 -07:00
|
|
|
if (nsCacheService::GlobalInstance())
|
|
|
|
nsCacheService::GlobalInstance()->Shutdown();
|
2012-02-15 12:34:31 -08:00
|
|
|
}
|
|
|
|
|
2010-06-22 17:13:23 -07: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 00:38:00 -07:00
|
|
|
nsIPrefService* prefs = Preferences::GetService();
|
|
|
|
if (prefs) {
|
2012-01-27 22:04:54 -08:00
|
|
|
// reset the crash loop state
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch;
|
|
|
|
prefs->GetBranch("browser.sessionstore.", getter_AddRefs(prefBranch));
|
|
|
|
if (prefBranch)
|
|
|
|
prefBranch->SetIntPref("recent_crashes", 0);
|
|
|
|
|
2010-06-22 17:13:23 -07:00
|
|
|
prefs->SavePrefFile(nsnull);
|
2011-06-07 00:38:00 -07:00
|
|
|
}
|
2010-06-22 08:22:31 -07:00
|
|
|
|
2010-06-17 14:33:15 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-21 12:11:31 -07:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_START: {
|
2012-02-15 12:34:31 -08:00
|
|
|
if (curEvent->Flags() > 0)
|
|
|
|
break;
|
|
|
|
|
2011-08-21 12:11:31 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
obsServ->NotifyObservers(nsnull, "application-foreground", nsnull);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-24 12:13:36 -07:00
|
|
|
case AndroidGeckoEvent::PAINT_LISTEN_START_EVENT: {
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsCOMPtr<nsIBrowserTab> tab;
|
|
|
|
mBrowserApp->GetBrowserTab(curEvent->MetaState(), getter_AddRefs(tab));
|
|
|
|
if (!tab)
|
|
|
|
break;
|
|
|
|
|
|
|
|
tab->GetWindow(getter_AddRefs(domWindow));
|
|
|
|
if (!domWindow)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sAfterPaintListener->Register(domWindow);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-17 10:52:26 -08:00
|
|
|
case AndroidGeckoEvent::SCREENSHOT: {
|
|
|
|
if (!mBrowserApp)
|
|
|
|
break;
|
|
|
|
|
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge)
|
|
|
|
break;
|
|
|
|
|
2012-04-26 10:45:31 -07:00
|
|
|
PRInt32 token = curEvent->Flags();
|
2012-06-14 09:08:51 -07:00
|
|
|
PRInt32 tabId = curEvent->MetaState();
|
2012-02-17 10:52:26 -08:00
|
|
|
nsTArray<nsIntPoint> points = curEvent->Points();
|
2012-06-14 09:08:51 -07:00
|
|
|
RefCountedJavaObject* buffer = curEvent->ByteBuffer();
|
|
|
|
nsCOMPtr<ScreenshotRunnable> sr =
|
|
|
|
new ScreenshotRunnable(mBrowserApp, tabId, points, token, buffer);
|
|
|
|
MessageLoop::current()->PostIdleTask(
|
|
|
|
FROM_HERE, NewRunnableMethod(sr.get(), &ScreenshotRunnable::Run));
|
2012-02-17 10:52:26 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:50:07 -07: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());
|
|
|
|
|
|
|
|
obsServ->NotifyObservers(nsnull, topic.get(), data.get());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-18 10:42:51 -07:00
|
|
|
case AndroidGeckoEvent::LOAD_URI: {
|
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdline
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
if (!cmdline)
|
|
|
|
break;
|
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
if (curEvent->Characters().Length() == 0)
|
|
|
|
break;
|
|
|
|
|
2010-06-18 10:42:51 -07:00
|
|
|
char *uri = ToNewUTF8String(curEvent->Characters());
|
|
|
|
if (!uri)
|
|
|
|
break;
|
|
|
|
|
2012-04-13 19:45:25 -07:00
|
|
|
char *flag = ToNewUTF8String(curEvent->CharactersExtra());
|
|
|
|
|
|
|
|
const char *argv[4] = {
|
2010-06-18 10:42:51 -07:00
|
|
|
"dummyappname",
|
2012-04-13 19:45:25 -07:00
|
|
|
"-url",
|
|
|
|
uri,
|
|
|
|
flag ? flag : ""
|
2010-06-18 10:42:51 -07:00
|
|
|
};
|
2012-04-13 19:45:25 -07:00
|
|
|
nsresult rv = cmdline->Init(4, const_cast<char **>(argv), nsnull, nsICommandLine::STATE_REMOTE_AUTO);
|
2010-06-18 10:42:51 -07:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
cmdline->Run();
|
|
|
|
nsMemory::Free(uri);
|
2012-04-13 19:45:25 -07:00
|
|
|
if (flag)
|
|
|
|
nsMemory::Free(flag);
|
2010-06-18 10:42:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-09 09:08:19 -07:00
|
|
|
case AndroidGeckoEvent::SIZE_CHANGED: {
|
|
|
|
// store the last resize event to dispatch it to new windows with a FORCED_RESIZE event
|
|
|
|
if (curEvent != gLastSizeChange) {
|
|
|
|
gLastSizeChange = new AndroidGeckoEvent(curEvent);
|
|
|
|
}
|
|
|
|
nsWindow::OnGlobalAndroidEvent(curEvent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-05 16:14:23 -08:00
|
|
|
case AndroidGeckoEvent::VISITED: {
|
|
|
|
#ifdef MOZ_ANDROID_HISTORY
|
|
|
|
nsAndroidHistory::NotifyURIVisited(nsString(curEvent->Characters()));
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-17 10:40:39 -08:00
|
|
|
case AndroidGeckoEvent::NETWORK_CHANGED: {
|
|
|
|
hal::NotifyNetworkChange(hal::NetworkInformation(curEvent->Bandwidth(),
|
|
|
|
curEvent->CanBeMetered()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-15 12:34:31 -08:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_RESUMING: {
|
|
|
|
if (curEvent->Flags() == 0) {
|
2012-04-17 10:29:52 -07:00
|
|
|
// If we are OOM killed with the disk cache enabled, the entire
|
|
|
|
// cache will be cleared (bug 105843), so shut down cache on pause
|
|
|
|
// and re-init here
|
2012-04-18 13:08:36 -07:00
|
|
|
if (nsCacheService::GlobalInstance())
|
|
|
|
nsCacheService::GlobalInstance()->Init();
|
2012-04-17 10:29:52 -07:00
|
|
|
|
2012-02-15 12:34:31 -08:00
|
|
|
// We didn't return from one of our own activities, so restore
|
|
|
|
// to foreground status
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
obsServ->NotifyObservers(nsnull, "application-foreground", nsnull);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-20 06:09:45 -07:00
|
|
|
case AndroidGeckoEvent::SCREENORIENTATION_CHANGED: {
|
2012-05-08 14:36:07 -07: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;
|
|
|
|
PRInt32 colorDepth, pixelDepth;
|
|
|
|
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 06:09:45 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
default:
|
2011-01-18 16:25:20 -08:00
|
|
|
nsWindow::OnGlobalAndroidEvent(curEvent);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EVLOG("nsAppShell: -- done event %p %d", (void*)curEvent.get(), curEvent->Type());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-09 09:08:19 -07:00
|
|
|
void
|
|
|
|
nsAppShell::ResendLastResizeEvent(nsWindow* aDest) {
|
|
|
|
if (gLastSizeChange) {
|
|
|
|
nsWindow::OnGlobalAndroidEvent(gLastSizeChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
AndroidGeckoEvent*
|
2011-11-30 08:17:17 -08:00
|
|
|
nsAppShell::PopNextEvent()
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
AndroidGeckoEvent *ae = nsnull;
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mQueueLock);
|
2010-06-03 13:56:36 -07:00
|
|
|
if (mEventQueue.Length()) {
|
|
|
|
ae = mEventQueue[0];
|
|
|
|
mEventQueue.RemoveElementAt(0);
|
2012-04-07 21:50:42 -07:00
|
|
|
if (mQueuedDrawEvent == ae) {
|
|
|
|
mQueuedDrawEvent = nsnull;
|
|
|
|
} else if (mQueuedViewportEvent == ae) {
|
|
|
|
mQueuedViewportEvent = nsnull;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ae;
|
|
|
|
}
|
|
|
|
|
|
|
|
AndroidGeckoEvent*
|
|
|
|
nsAppShell::PeekNextEvent()
|
|
|
|
{
|
|
|
|
AndroidGeckoEvent *ae = nsnull;
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mQueueLock);
|
2010-06-03 13:56:36 -07: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-03-31 21:29:02 -07:00
|
|
|
{
|
2012-04-10 07:28:43 -07: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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mQueueLock);
|
2012-04-07 21:50:42 -07:00
|
|
|
EVLOG("nsAppShell::PostEvent %p %d", ae, ae->Type());
|
|
|
|
switch (ae->Type()) {
|
|
|
|
case AndroidGeckoEvent::SURFACE_DESTROYED:
|
2011-08-23 13:52:03 -07:00
|
|
|
// Give priority to this event, and discard any pending
|
|
|
|
// SURFACE_CREATED events.
|
|
|
|
mEventQueue.InsertElementAt(0, ae);
|
|
|
|
AndroidGeckoEvent *event;
|
2012-04-07 21:50:42 -07:00
|
|
|
for (int i = mEventQueue.Length() - 1; i >= 1; i--) {
|
2011-08-23 13:52:03 -07:00
|
|
|
event = mEventQueue[i];
|
|
|
|
if (event->Type() == AndroidGeckoEvent::SURFACE_CREATED) {
|
2012-04-07 21:50:42 -07:00
|
|
|
EVLOG("nsAppShell: Dropping old SURFACE_CREATED event at %p %d", event, i);
|
2011-08-23 13:52:03 -07:00
|
|
|
mEventQueue.RemoveElementAt(i);
|
|
|
|
delete event;
|
|
|
|
}
|
|
|
|
}
|
2012-04-07 21:50:42 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::COMPOSITOR_PAUSE:
|
|
|
|
case AndroidGeckoEvent::COMPOSITOR_RESUME:
|
2012-03-28 15:00:32 -07:00
|
|
|
// Give priority to these events, but maintain their order wrt each other.
|
2012-04-07 21:50:42 -07:00
|
|
|
{
|
2012-07-12 09:52:52 -07:00
|
|
|
PRUint32 i = 0;
|
2012-04-07 21:50:42 -07:00
|
|
|
while (i < mEventQueue.Length() &&
|
|
|
|
(mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_PAUSE ||
|
|
|
|
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-28 15:00:32 -07:00
|
|
|
}
|
2012-04-07 21:50:42 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::DRAW:
|
|
|
|
if (mQueuedDrawEvent) {
|
|
|
|
// coalesce this new draw event with the one already in the queue
|
|
|
|
const nsIntRect& oldRect = mQueuedDrawEvent->Rect();
|
|
|
|
const nsIntRect& newRect = ae->Rect();
|
|
|
|
int combinedArea = (oldRect.width * oldRect.height) +
|
|
|
|
(newRect.width * newRect.height);
|
|
|
|
|
|
|
|
nsIntRect combinedRect = oldRect.Union(newRect);
|
|
|
|
// XXX We may want to consider using regions instead of rectangles.
|
|
|
|
// Print an error if we're upload a lot more than we would
|
|
|
|
// if we handled this as two separate events.
|
|
|
|
int boundsArea = combinedRect.width * combinedRect.height;
|
|
|
|
if (boundsArea > combinedArea * 8)
|
|
|
|
ALOG("nsAppShell: Area of bounds greatly exceeds combined area: %d > %d",
|
|
|
|
boundsArea, combinedArea);
|
|
|
|
|
|
|
|
// coalesce into the new draw event rather than the queued one because
|
|
|
|
// it is not always safe to move draws earlier in the queue; there may
|
|
|
|
// be events between the two draws that affect scroll position or something.
|
|
|
|
ae->Init(AndroidGeckoEvent::DRAW, combinedRect);
|
|
|
|
|
|
|
|
EVLOG("nsAppShell: Coalescing previous DRAW event at %p into new DRAW event %p", mQueuedDrawEvent, ae);
|
|
|
|
mEventQueue.RemoveElement(mQueuedDrawEvent);
|
|
|
|
delete mQueuedDrawEvent;
|
|
|
|
}
|
|
|
|
|
2012-04-16 07:31:13 -07:00
|
|
|
if (!mAllowCoalescingNextDraw) {
|
2012-04-10 07:27:04 -07:00
|
|
|
// if we're not allowing coalescing of this draw event, then
|
|
|
|
// don't set mQueuedDrawEvent to point to this; that way the
|
|
|
|
// next draw event that comes in won't kill this one.
|
|
|
|
mAllowCoalescingNextDraw = true;
|
|
|
|
mQueuedDrawEvent = nsnull;
|
|
|
|
} else {
|
|
|
|
mQueuedDrawEvent = ae;
|
|
|
|
}
|
2012-04-10 07:28:43 -07:00
|
|
|
|
|
|
|
allowCoalescingNextViewport = true;
|
|
|
|
|
2011-08-23 13:52:03 -07:00
|
|
|
mEventQueue.AppendElement(ae);
|
2012-04-07 21:50:42 -07: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 07:27:04 -07:00
|
|
|
// temporarily turn off draw-coalescing, so that we process a draw
|
|
|
|
// event as soon as possible after a viewport change
|
|
|
|
mAllowCoalescingNextDraw = false;
|
2012-04-10 07:28:43 -07:00
|
|
|
allowCoalescingNextViewport = true;
|
2012-04-10 07:27:04 -07:00
|
|
|
|
2012-04-07 21:50:42 -07:00
|
|
|
mEventQueue.AppendElement(ae);
|
|
|
|
break;
|
2011-08-23 13:52:03 -07:00
|
|
|
|
2012-04-07 21:50:42 -07:00
|
|
|
case AndroidGeckoEvent::MOTION_EVENT:
|
|
|
|
if (ae->Action() == AndroidMotionEvent::ACTION_MOVE) {
|
|
|
|
int len = mEventQueue.Length();
|
|
|
|
if (len > 0) {
|
|
|
|
AndroidGeckoEvent* event = mEventQueue[len - 1];
|
|
|
|
if (event->Type() == AndroidGeckoEvent::MOTION_EVENT && event->Action() == AndroidMotionEvent::ACTION_MOVE) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mEventQueue.AppendElement(ae);
|
|
|
|
break;
|
|
|
|
|
2012-04-10 07:28:43 -07:00
|
|
|
case AndroidGeckoEvent::NATIVE_POKE:
|
|
|
|
allowCoalescingNextViewport = true;
|
|
|
|
// fall through
|
|
|
|
|
2012-04-07 21:50:42 -07: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-03-31 21:29:02 -07:00
|
|
|
}
|
2012-04-10 07:28:43 -07: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)
|
|
|
|
mQueuedViewportEvent = nsnull;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
NotifyNativeEvent();
|
|
|
|
}
|
|
|
|
|
2011-02-01 22:34:12 -08:00
|
|
|
void
|
|
|
|
nsAppShell::OnResume()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-14 19:17:37 -07:00
|
|
|
nsresult
|
|
|
|
nsAppShell::AddObserver(const nsAString &aObserverKey, nsIObserver *aObserver)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aObserver != nsnull, "nsAppShell::AddObserver: aObserver is null!");
|
2012-05-18 10:30:49 -07:00
|
|
|
mObserversHash.Put(aObserverKey, aObserver);
|
|
|
|
return NS_OK;
|
2010-06-14 19:17:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The XPCOM event that will call the observer on the main thread.
|
|
|
|
*/
|
|
|
|
class ObserverCaller : public nsRunnable {
|
|
|
|
public:
|
|
|
|
ObserverCaller(nsIObserver *aObserver, const char *aTopic, const PRUnichar *aData) :
|
|
|
|
mObserver(aObserver), mTopic(aTopic), mData(aData) {
|
|
|
|
NS_ASSERTION(aObserver != nsnull, "ObserverCaller: aObserver is null!");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
ALOG("ObserverCaller::Run: observer = %p, topic = '%s')",
|
|
|
|
(nsIObserver*)mObserver, mTopic.get());
|
|
|
|
mObserver->Observe(nsnull, mTopic.get(), mData.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIObserver> mObserver;
|
|
|
|
nsCString mTopic;
|
|
|
|
nsString mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::CallObserver(const nsAString &aObserverKey, const nsAString &aTopic, const nsAString &aData)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserver> observer;
|
|
|
|
mObserversHash.Get(aObserverKey, getter_AddRefs(observer));
|
|
|
|
|
|
|
|
if (!observer) {
|
|
|
|
ALOG("nsAppShell::CallObserver: Observer was not found!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NS_ConvertUTF16toUTF8 sTopic(aTopic);
|
|
|
|
const nsPromiseFlatString& sData = PromiseFlatString(aData);
|
2011-02-27 07:50:56 -08:00
|
|
|
|
2010-06-14 19:17:37 -07:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
// This branch will unlikely be hit, have it just in case
|
|
|
|
observer->Observe(nsnull, sTopic.get(), sData.get());
|
|
|
|
} else {
|
|
|
|
// Java is not running on main thread, so we have to use NS_DispatchToMainThread
|
|
|
|
nsCOMPtr<nsIRunnable> observerCaller = new ObserverCaller(observer, sTopic.get(), sData.get());
|
|
|
|
nsresult rv = NS_DispatchToMainThread(observerCaller);
|
|
|
|
ALOG("NS_DispatchToMainThread result: %d", rv);
|
2011-02-11 09:27:17 -08:00
|
|
|
unused << rv;
|
2010-06-14 19:17:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::RemoveObserver(const nsAString &aObserverKey)
|
|
|
|
{
|
|
|
|
mObserversHash.Remove(aObserverKey);
|
|
|
|
}
|
|
|
|
|
2010-12-21 00:01:00 -08:00
|
|
|
// NotifyObservers support. NotifyObservers only works on main thread.
|
|
|
|
|
|
|
|
class NotifyObserversCaller : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NotifyObserversCaller(nsISupports *aSupports,
|
|
|
|
const char *aTopic, const PRUnichar *aData) :
|
2011-02-27 07:50:56 -08:00
|
|
|
mSupports(aSupports), mTopic(aTopic), mData(aData) {
|
2010-12-21 00:01:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os)
|
|
|
|
os->NotifyObservers(mSupports, mTopic.get(), mData.get());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mSupports;
|
|
|
|
nsCString mTopic;
|
|
|
|
nsString mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::NotifyObservers(nsISupports *aSupports,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
|
|
|
// This isn't main thread, so post this to main thread
|
|
|
|
nsCOMPtr<nsIRunnable> caller =
|
|
|
|
new NotifyObserversCaller(aSupports, aTopic, aData);
|
|
|
|
NS_DispatchToMainThread(caller);
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
// Used by IPC code
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
bool ProcessNextEvent()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return nsAppShell::gAppShell->ProcessNextNativeEvent(true) ? true : false;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyEvent()
|
|
|
|
{
|
|
|
|
nsAppShell::gAppShell->NotifyNativeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|