2010-06-03 20:56:36 +00:00
|
|
|
/* -*- Mode: c++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009-2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-10-29 10:35:29 +00:00
|
|
|
// Make sure the order of included headers
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "nspr/prtypes.h"
|
|
|
|
|
2012-01-17 18:40:39 +00:00
|
|
|
#include "mozilla/Hal.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include "nsWindow.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2010-06-18 17:42:51 +00:00
|
|
|
#include "nsICommandLineRunner.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIAppStartup.h"
|
2010-06-04 21:14:43 +00:00
|
|
|
#include "nsIGeolocationProvider.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2010-06-17 21:33:15 +00:00
|
|
|
#include "mozilla/Services.h"
|
2011-02-11 17:27:17 +00:00
|
|
|
#include "mozilla/unused.h"
|
2011-06-07 07:38:00 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-10-29 10:35:29 +00:00
|
|
|
#include "mozilla/Hal.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2011-06-20 05:36:17 +00:00
|
|
|
#include "nsDeviceMotionSystem.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
#include <android/log.h>
|
|
|
|
#include <pthread.h>
|
2011-02-27 15:50:56 +00:00
|
|
|
#include <wchar.h>
|
2012-02-22 16:35:25 +00:00
|
|
|
|
2012-01-06 00:14:23 +00:00
|
|
|
#ifdef MOZ_ANDROID_HISTORY
|
|
|
|
#include "nsAndroidHistory.h"
|
|
|
|
#endif
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG
|
|
|
|
#include "prlog.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-29 18:29:39 +00:00
|
|
|
#ifdef DEBUG_ANDROID_EVENTS
|
2010-06-03 20:56:36 +00:00
|
|
|
#define EVLOG(args...) ALOG(args)
|
|
|
|
#else
|
|
|
|
#define EVLOG(args...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PRLogModuleInfo *gWidgetLog = nsnull;
|
|
|
|
#endif
|
|
|
|
|
2011-06-20 05:36:17 +00:00
|
|
|
nsDeviceMotionSystem *gDeviceMotionSystem = nsnull;
|
2010-06-04 21:14:43 +00:00
|
|
|
nsIGeolocationUpdate *gLocationCallback = nsnull;
|
2011-08-09 16:08:19 +00:00
|
|
|
nsAutoPtr<mozilla::AndroidGeckoEvent> gLastSizeChange;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
nsAppShell *nsAppShell::gAppShell = nsnull;
|
|
|
|
|
2010-12-21 21:28:45 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver)
|
|
|
|
|
2010-06-03 20:56:36 +00: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 04:29:02 +00:00
|
|
|
: mQueueLock("nsAppShell.mQueueLock"),
|
|
|
|
mCondLock("nsAppShell.mCondLock"),
|
|
|
|
mQueueCond(mCondLock, "nsAppShell.mQueueCond"),
|
2011-12-22 11:35:32 +00:00
|
|
|
mNumDraws(0),
|
2012-02-17 07:03:57 +00:00
|
|
|
mNumViewports(0),
|
2012-03-13 23:57:51 +00:00
|
|
|
mPendingSensorEvents(false)
|
2010-06-03 20:56:36 +00:00
|
|
|
{
|
|
|
|
gAppShell = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::~nsAppShell()
|
|
|
|
{
|
|
|
|
gAppShell = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mCondLock);
|
|
|
|
mQueueCond.Notify();
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 07:38:00 +00: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 20:56:36 +00:00
|
|
|
nsresult
|
|
|
|
nsAppShell::Init()
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!gWidgetLog)
|
|
|
|
gWidgetLog = PR_NewLogModule("Widget");
|
|
|
|
#endif
|
|
|
|
|
2010-06-15 02:17:37 +00:00
|
|
|
mObserversHash.Init();
|
|
|
|
|
2010-10-26 03:10:07 +00:00
|
|
|
nsresult rv = nsBaseAppShell::Init();
|
2011-02-27 15:50:56 +00:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
2010-12-21 21:28:45 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 15:50:56 +00:00
|
|
|
mozilla::services::GetObserverService();
|
2010-12-21 21:28:45 +00:00
|
|
|
if (obsServ) {
|
2011-10-17 14:59:28 +00:00
|
|
|
obsServ->AddObserver(this, "xpcom-shutdown", false);
|
2010-12-21 21:28:45 +00:00
|
|
|
}
|
2011-02-27 15:50:56 +00:00
|
|
|
|
|
|
|
if (!bridge)
|
|
|
|
return rv;
|
|
|
|
|
2011-06-07 07:38:00 +00:00
|
|
|
Preferences::AddStrongObservers(this, kObservedPrefs);
|
2011-03-16 23:17:59 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool match;
|
2011-06-07 07:38:00 +00:00
|
|
|
rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match);
|
2011-03-16 23:17:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
bridge->SetSelectedLocale(EmptyString());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-06-07 07:38:00 +00:00
|
|
|
|
|
|
|
nsAutoString locale;
|
|
|
|
rv = Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = Preferences::GetString(PREFNAME_UA_LOCALE, &locale);
|
2011-03-16 23:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bridge->SetSelectedLocale(locale);
|
2010-10-26 03:10:07 +00:00
|
|
|
return rv;
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 21:28:45 +00: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 16:45:44 +00:00
|
|
|
return nsBaseAppShell::Observe(aSubject, aTopic, aData);
|
2011-03-16 23:17:59 +00:00
|
|
|
} else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && aData && (
|
|
|
|
nsDependentString(aData).Equals(
|
2011-06-07 07:38:00 +00:00
|
|
|
NS_LITERAL_STRING(PREFNAME_UA_LOCALE)) ||
|
2011-03-16 23:17:59 +00:00
|
|
|
nsDependentString(aData).Equals(
|
2011-06-07 07:38:00 +00:00
|
|
|
NS_LITERAL_STRING(PREFNAME_MATCH_OS)))) {
|
2011-02-27 15:50:56 +00:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
2011-06-07 07:38:00 +00:00
|
|
|
if (!bridge) {
|
2011-02-27 15:50:56 +00:00
|
|
|
return NS_OK;
|
2011-06-07 07:38:00 +00:00
|
|
|
}
|
2011-03-16 23:17:59 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool match;
|
2011-06-07 07:38:00 +00:00
|
|
|
nsresult rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match);
|
2011-03-16 23:17:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2011-03-16 23:17:59 +00:00
|
|
|
if (match) {
|
|
|
|
bridge->SetSelectedLocale(EmptyString());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-06-07 07:38:00 +00:00
|
|
|
|
|
|
|
nsAutoString locale;
|
|
|
|
if (NS_FAILED(Preferences::GetLocalizedString(PREFNAME_UA_LOCALE,
|
|
|
|
&locale))) {
|
|
|
|
locale = Preferences::GetString(PREFNAME_UA_LOCALE);
|
2011-03-16 23:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bridge->SetSelectedLocale(locale);
|
2011-02-27 15:50:56 +00:00
|
|
|
return NS_OK;
|
2010-12-21 21:28:45 +00:00
|
|
|
}
|
2011-03-14 16:45:44 +00:00
|
|
|
return NS_OK;
|
2010-12-21 21:28:45 +00:00
|
|
|
}
|
2010-06-03 20:56:36 +00: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-29 06:19:26 +00:00
|
|
|
bool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
2010-06-03 20:56:36 +00:00
|
|
|
{
|
|
|
|
EVLOG("nsAppShell::ProcessNextNativeEvent %d", mayWait);
|
|
|
|
|
|
|
|
nsAutoPtr<AndroidGeckoEvent> curEvent;
|
|
|
|
AndroidGeckoEvent *nextEvent;
|
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 04:29:02 +00:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mCondLock);
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2011-11-30 16:17:17 +00: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 04:29:02 +00:00
|
|
|
if (!curEvent && mayWait) {
|
|
|
|
// hmm, should we really hardcode this 10s?
|
2011-08-29 18:29:39 +00: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 04:29:02 +00:00
|
|
|
PRTime t0, t1;
|
|
|
|
EVLOG("nsAppShell: waiting on mQueueCond");
|
|
|
|
t0 = PR_Now();
|
2010-06-03 20:56:36 +00: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 04:29:02 +00:00
|
|
|
mQueueCond.Wait(PR_MillisecondsToInterval(10000));
|
|
|
|
t1 = PR_Now();
|
|
|
|
EVLOG("nsAppShell: wait done, waited %d ms", (int)(t1-t0)/1000);
|
2010-06-03 20:56:36 +00: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 04:29:02 +00:00
|
|
|
mQueueCond.Wait();
|
2010-06-03 20:56:36 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-30 16:17:17 +00: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 04:29:02 +00:00
|
|
|
}
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!curEvent)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Combine subsequent events of the same type
|
|
|
|
|
|
|
|
nextEvent = PeekNextEvent();
|
|
|
|
|
|
|
|
while (nextEvent) {
|
|
|
|
int curType = curEvent->Type();
|
|
|
|
int nextType = nextEvent->Type();
|
|
|
|
|
2011-12-22 11:35:32 +00:00
|
|
|
while (nextType == AndroidGeckoEvent::VIEWPORT && mNumViewports > 1) {
|
|
|
|
// Skip this viewport change, as there's another one later and
|
|
|
|
// processing this one will only cause more unnecessary work
|
|
|
|
PopNextEvent();
|
|
|
|
delete nextEvent;
|
|
|
|
nextEvent = PeekNextEvent();
|
|
|
|
nextType = nextEvent->Type();
|
|
|
|
}
|
|
|
|
|
2011-11-30 16:17:17 +00:00
|
|
|
while (nextType == AndroidGeckoEvent::DRAW && mLastDrawEvent &&
|
2010-06-03 20:56:36 +00:00
|
|
|
mNumDraws > 1)
|
|
|
|
{
|
|
|
|
// skip this draw, since there's a later one already in the queue.. this will let us
|
|
|
|
// deal with sequences that look like:
|
|
|
|
// MOVE DRAW MOVE DRAW MOVE DRAW
|
|
|
|
// and end up with just
|
|
|
|
// MOVE DRAW
|
|
|
|
// when we process all the events.
|
2011-11-30 16:17:17 +00:00
|
|
|
|
|
|
|
// Combine the next draw event's rect with the last one in the queue
|
|
|
|
const nsIntRect& nextRect = nextEvent->Rect();
|
|
|
|
const nsIntRect& lastRect = mLastDrawEvent->Rect();
|
|
|
|
int combinedArea = (lastRect.width * lastRect.height) +
|
|
|
|
(nextRect.width * nextRect.height);
|
|
|
|
|
|
|
|
nsIntRect combinedRect = lastRect.Union(nextRect);
|
|
|
|
mLastDrawEvent->Init(AndroidGeckoEvent::DRAW, combinedRect);
|
|
|
|
|
|
|
|
// 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::ProcessNextNativeEvent: "
|
|
|
|
"Area of bounds greatly exceeds combined area: %d > %d",
|
|
|
|
boundsArea, combinedArea);
|
|
|
|
|
|
|
|
// Remove the next draw event
|
|
|
|
PopNextEvent();
|
2010-07-16 18:25:38 +00:00
|
|
|
delete nextEvent;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2011-08-29 18:29:39 +00:00
|
|
|
#if defined(DEBUG_ANDROID_EVENTS)
|
2010-06-03 20:56:36 +00:00
|
|
|
ALOG("# Removing DRAW event (%d outstanding)", mNumDraws);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nextEvent = PeekNextEvent();
|
|
|
|
nextType = nextEvent->Type();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the next type of event isn't the same as the current type,
|
|
|
|
// we don't coalesce.
|
|
|
|
if (nextType != curType)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Can only coalesce motion move events, for motion events
|
|
|
|
if (curType != AndroidGeckoEvent::MOTION_EVENT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!(curEvent->Action() == AndroidMotionEvent::ACTION_MOVE &&
|
|
|
|
nextEvent->Action() == AndroidMotionEvent::ACTION_MOVE))
|
|
|
|
break;
|
|
|
|
|
2011-08-29 18:29:39 +00:00
|
|
|
#if defined(DEBUG_ANDROID_EVENTS)
|
2010-06-03 20:56:36 +00:00
|
|
|
ALOG("# Removing % 2d event", curType);
|
|
|
|
#endif
|
|
|
|
|
2011-11-30 16:17:17 +00:00
|
|
|
curEvent = PopNextEvent();
|
2010-06-03 20:56:36 +00:00
|
|
|
nextEvent = PeekNextEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
EVLOG("nsAppShell: event %p %d [ndraws %d]", (void*)curEvent.get(), curEvent->Type(), mNumDraws);
|
|
|
|
|
|
|
|
switch (curEvent->Type()) {
|
|
|
|
case AndroidGeckoEvent::NATIVE_POKE:
|
|
|
|
NativeEventCallback();
|
|
|
|
break;
|
|
|
|
|
2012-03-13 23:57:09 +00:00
|
|
|
case AndroidGeckoEvent::SENSOR_ACCURACY:
|
|
|
|
if (curEvent->Flags() == 0)
|
|
|
|
gDeviceMotionSystem->NeedsCalibration();
|
2011-06-20 05:36:17 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-13 23:57:51 +00:00
|
|
|
case AndroidGeckoEvent::SENSOR_EVENT:
|
|
|
|
mPendingSensorEvents = false;
|
|
|
|
switch (curEvent->Flags()) {
|
|
|
|
case hal::SENSOR_ORIENTATION:
|
|
|
|
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
|
|
|
|
curEvent->X(),
|
|
|
|
-curEvent->Y(),
|
|
|
|
-curEvent->Z());
|
|
|
|
break;
|
2012-03-13 16:59:24 +00:00
|
|
|
|
2012-03-13 23:57:51 +00:00
|
|
|
case hal::SENSOR_ACCELERATION:
|
|
|
|
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
|
|
|
|
-curEvent->X(),
|
|
|
|
curEvent->Y(),
|
|
|
|
curEvent->Z());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hal::SENSOR_LINEAR_ACCELERATION:
|
|
|
|
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION,
|
|
|
|
-curEvent->X(),
|
|
|
|
curEvent->Y(),
|
|
|
|
curEvent->Z());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hal::SENSOR_GYROSCOPE:
|
|
|
|
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_GYROSCOPE,
|
|
|
|
-curEvent->X(),
|
|
|
|
curEvent->Y(),
|
|
|
|
curEvent->Z());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "Gecko", "### SENSOR_EVENT fired, but type wasn't known %d", curEvent->Flags());
|
|
|
|
}
|
|
|
|
break;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2011-03-17 07:03:11 +00:00
|
|
|
case AndroidGeckoEvent::LOCATION_EVENT: {
|
2010-06-04 21:14:43 +00:00
|
|
|
if (!gLocationCallback)
|
|
|
|
break;
|
|
|
|
|
2011-03-17 07:03:11 +00:00
|
|
|
nsGeoPosition* p = curEvent->GeoPosition();
|
2012-03-09 06:16:25 +00:00
|
|
|
if (p)
|
2010-06-04 21:14:43 +00:00
|
|
|
gLocationCallback->Update(curEvent->GeoPosition());
|
|
|
|
else
|
|
|
|
NS_WARNING("Received location event without geoposition!");
|
|
|
|
break;
|
2011-03-17 07:03:11 +00:00
|
|
|
}
|
2010-06-04 21:14:43 +00:00
|
|
|
|
2011-10-29 10:35:29 +00:00
|
|
|
case AndroidGeckoEvent::PROXIMITY_EVENT: {
|
|
|
|
InfallibleTArray<float> values;
|
|
|
|
values.AppendElement(curEvent->Distance());
|
|
|
|
|
|
|
|
hal::SensorData sdata(hal::SENSOR_PROXIMITY, PR_Now(), values);
|
|
|
|
hal::NotifySensorChange(sdata);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-02 06:34:12 +00:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_STOPPING: {
|
2012-02-15 20:34:31 +00:00
|
|
|
if (curEvent->Flags() > 0)
|
|
|
|
break;
|
|
|
|
|
2011-02-02 06:34:12 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 15:50:56 +00:00
|
|
|
mozilla::services::GetObserverService();
|
2011-02-02 06:34:12 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(minimize, "heap-minimize");
|
|
|
|
obsServ->NotifyObservers(nsnull, "memory-pressure", minimize.get());
|
2011-08-21 19:11:31 +00:00
|
|
|
obsServ->NotifyObservers(nsnull, "application-background", nsnull);
|
2011-02-02 06:34:12 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-11 22:36:11 +00:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_SHUTDOWN: {
|
2010-06-17 21:33:15 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
2011-02-27 15:50:56 +00:00
|
|
|
mozilla::services::GetObserverService();
|
2010-06-17 21:33:15 +00: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 20:56:36 +00:00
|
|
|
nsCOMPtr<nsIAppStartup> appSvc = do_GetService("@mozilla.org/toolkit/app-startup;1");
|
|
|
|
if (appSvc)
|
|
|
|
appSvc->Quit(nsIAppStartup::eForceQuit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-17 21:33:15 +00:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_PAUSING: {
|
2012-02-15 20:34:31 +00: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);
|
|
|
|
}
|
|
|
|
|
2010-06-23 00:13:23 +00: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 07:38:00 +00:00
|
|
|
nsIPrefService* prefs = Preferences::GetService();
|
|
|
|
if (prefs) {
|
2012-01-28 06:04:54 +00: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-23 00:13:23 +00:00
|
|
|
prefs->SavePrefFile(nsnull);
|
2011-06-07 07:38:00 +00:00
|
|
|
}
|
2010-06-22 15:22:31 +00:00
|
|
|
|
2010-06-17 21:33:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-21 19:11:31 +00:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_START: {
|
2012-02-15 20:34:31 +00:00
|
|
|
if (curEvent->Flags() > 0)
|
|
|
|
break;
|
|
|
|
|
2011-08-21 19:11:31 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
obsServ->NotifyObservers(nsnull, "application-foreground", nsnull);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:52:26 +00:00
|
|
|
case AndroidGeckoEvent::SCREENSHOT: {
|
|
|
|
if (!mBrowserApp)
|
|
|
|
break;
|
|
|
|
|
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
2012-03-12 18:05:43 +00:00
|
|
|
nsCOMPtr<nsIBrowserTab> tab;
|
|
|
|
float scale;
|
|
|
|
mBrowserApp->GetBrowserTab(curEvent->MetaState(), getter_AddRefs(tab));
|
|
|
|
if (!tab)
|
|
|
|
break;
|
|
|
|
|
|
|
|
tab->GetWindow(getter_AddRefs(domWindow));
|
|
|
|
if (!domWindow)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (NS_FAILED(tab->GetScale(&scale)))
|
|
|
|
break;
|
|
|
|
|
2012-02-17 18:52:26 +00:00
|
|
|
nsTArray<nsIntPoint> points = curEvent->Points();
|
2012-02-22 16:29:21 +00:00
|
|
|
NS_ASSERTION(points.Length() == 2, "Screenshot event does not have enough coordinates");
|
2012-03-13 22:21:58 +00:00
|
|
|
bridge->TakeScreenshot(domWindow, 0, 0, points[0].x, points[0].y, points[1].x, points[1].y, curEvent->MetaState(), scale);
|
2012-02-17 18:52:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-22 11:35:32 +00:00
|
|
|
case AndroidGeckoEvent::VIEWPORT:
|
2011-11-15 03:12:14 +00:00
|
|
|
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 17:42:51 +00:00
|
|
|
case AndroidGeckoEvent::LOAD_URI: {
|
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdline
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
if (!cmdline)
|
|
|
|
break;
|
|
|
|
|
2011-11-15 03:12:14 +00:00
|
|
|
if (curEvent->Characters().Length() == 0)
|
|
|
|
break;
|
|
|
|
|
2010-06-18 17:42:51 +00:00
|
|
|
char *uri = ToNewUTF8String(curEvent->Characters());
|
|
|
|
if (!uri)
|
|
|
|
break;
|
|
|
|
|
2011-02-11 17:27:17 +00:00
|
|
|
const char *argv[3] = {
|
2010-06-18 17:42:51 +00:00
|
|
|
"dummyappname",
|
|
|
|
"-remote",
|
|
|
|
uri
|
|
|
|
};
|
2011-02-11 17:27:17 +00:00
|
|
|
nsresult rv = cmdline->Init(3, const_cast<char **>(argv), nsnull, nsICommandLine::STATE_REMOTE_AUTO);
|
2010-06-18 17:42:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
cmdline->Run();
|
|
|
|
nsMemory::Free(uri);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-09 16:08:19 +00: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-06 00:14:23 +00:00
|
|
|
case AndroidGeckoEvent::VISITED: {
|
|
|
|
#ifdef MOZ_ANDROID_HISTORY
|
|
|
|
nsAndroidHistory::NotifyURIVisited(nsString(curEvent->Characters()));
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-17 18:40:39 +00:00
|
|
|
case AndroidGeckoEvent::NETWORK_CHANGED: {
|
|
|
|
hal::NotifyNetworkChange(hal::NetworkInformation(curEvent->Bandwidth(),
|
|
|
|
curEvent->CanBeMetered()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-15 20:34:31 +00:00
|
|
|
case AndroidGeckoEvent::ACTIVITY_RESUMING: {
|
|
|
|
if (curEvent->Flags() == 0) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
default:
|
2011-01-19 00:25:20 +00:00
|
|
|
nsWindow::OnGlobalAndroidEvent(curEvent);
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EVLOG("nsAppShell: -- done event %p %d", (void*)curEvent.get(), curEvent->Type());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-09 16:08:19 +00:00
|
|
|
void
|
|
|
|
nsAppShell::ResendLastResizeEvent(nsWindow* aDest) {
|
|
|
|
if (gLastSizeChange) {
|
|
|
|
nsWindow::OnGlobalAndroidEvent(gLastSizeChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
AndroidGeckoEvent*
|
2011-11-30 16:17:17 +00:00
|
|
|
nsAppShell::PopNextEvent()
|
2010-06-03 20:56:36 +00: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-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mQueueLock);
|
2010-06-03 20:56:36 +00:00
|
|
|
if (mEventQueue.Length()) {
|
|
|
|
ae = mEventQueue[0];
|
|
|
|
mEventQueue.RemoveElementAt(0);
|
|
|
|
if (ae->Type() == AndroidGeckoEvent::DRAW) {
|
2011-11-30 16:17:17 +00:00
|
|
|
if (--mNumDraws == 0)
|
|
|
|
mLastDrawEvent = nsnull;
|
2011-12-22 11:35:32 +00:00
|
|
|
} else if (ae->Type() == AndroidGeckoEvent::VIEWPORT) {
|
|
|
|
mNumViewports--;
|
2010-06-03 20:56:36 +00: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-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mQueueLock);
|
2010-06-03 20:56:36 +00: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 04:29:02 +00:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mQueueLock);
|
2011-08-23 20:52:03 +00:00
|
|
|
if (ae->Type() == AndroidGeckoEvent::SURFACE_DESTROYED) {
|
|
|
|
// Give priority to this event, and discard any pending
|
|
|
|
// SURFACE_CREATED events.
|
|
|
|
mEventQueue.InsertElementAt(0, ae);
|
|
|
|
AndroidGeckoEvent *event;
|
|
|
|
for (int i = mEventQueue.Length()-1; i >=1; i--) {
|
|
|
|
event = mEventQueue[i];
|
|
|
|
if (event->Type() == AndroidGeckoEvent::SURFACE_CREATED) {
|
|
|
|
mEventQueue.RemoveElementAt(i);
|
|
|
|
delete event;
|
|
|
|
}
|
|
|
|
}
|
2012-03-13 23:57:51 +00:00
|
|
|
} else if (ae->Type() == AndroidGeckoEvent::SENSOR_EVENT) {
|
|
|
|
if (!mPendingSensorEvents)
|
|
|
|
mEventQueue.AppendElement(ae);
|
|
|
|
mPendingSensorEvents = true;
|
2011-08-23 20:52:03 +00:00
|
|
|
} else {
|
|
|
|
mEventQueue.AppendElement(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 04:29:02 +00:00
|
|
|
if (ae->Type() == AndroidGeckoEvent::DRAW) {
|
|
|
|
mNumDraws++;
|
2011-11-30 16:17:17 +00:00
|
|
|
mLastDrawEvent = ae;
|
2011-12-22 11:35:32 +00:00
|
|
|
} else if (ae->Type() == AndroidGeckoEvent::VIEWPORT) {
|
|
|
|
mNumViewports++;
|
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 04:29:02 +00:00
|
|
|
}
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
NotifyNativeEvent();
|
|
|
|
}
|
|
|
|
|
2011-02-02 06:34:12 +00:00
|
|
|
void
|
|
|
|
nsAppShell::OnResume()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-15 02:17:37 +00:00
|
|
|
nsresult
|
|
|
|
nsAppShell::AddObserver(const nsAString &aObserverKey, nsIObserver *aObserver)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aObserver != nsnull, "nsAppShell::AddObserver: aObserver is null!");
|
|
|
|
return mObserversHash.Put(aObserverKey, aObserver) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 15:50:56 +00:00
|
|
|
|
2010-06-15 02:17:37 +00: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 17:27:17 +00:00
|
|
|
unused << rv;
|
2010-06-15 02:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::RemoveObserver(const nsAString &aObserverKey)
|
|
|
|
{
|
|
|
|
mObserversHash.Remove(aObserverKey);
|
|
|
|
}
|
|
|
|
|
2010-12-21 08:01:00 +00: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 15:50:56 +00:00
|
|
|
mSupports(aSupports), mTopic(aTopic), mData(aData) {
|
2010-12-21 08:01:00 +00: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 20:56:36 +00:00
|
|
|
// Used by IPC code
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
bool ProcessNextEvent()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return nsAppShell::gAppShell->ProcessNextNativeEvent(true) ? true : false;
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyEvent()
|
|
|
|
{
|
|
|
|
nsAppShell::gAppShell->NotifyNativeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|