Bug 1233812 - Fix possible race in accessing nsAppShell instance; r=snorp

When getting nsAppShell from another thread, there could be a race with
nsAppShell being destroyed on the main thread. This patch makes the raw
nsAppShell pointer only accessible from the main thread, and use a
static mutex to coordinate accessing nsAppShell from other threads.
This commit is contained in:
Jim Chen
2015-12-23 22:03:35 -05:00
parent 73881b6aa8
commit e56235cd4f
7 changed files with 84 additions and 51 deletions

View File

@@ -512,9 +512,9 @@ AndroidBridge::ShowAlertNotification(const nsAString& aImageUrl,
const nsAString& aAlertName,
nsIPrincipal* aPrincipal)
{
if (nsAppShell::gAppShell && aAlertListener) {
if (aAlertListener) {
// This will remove any observers already registered for this id
nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeAddObserver(aAlertName, aAlertListener));
nsAppShell::PostEvent(AndroidGeckoEvent::MakeAddObserver(aAlertName, aAlertListener));
}
nsAutoString host;
@@ -1706,15 +1706,17 @@ AndroidBridge::PumpMessageLoop()
NS_IMETHODIMP nsAndroidBridge::GetBrowserApp(nsIAndroidBrowserApp * *aBrowserApp)
{
if (nsAppShell::gAppShell)
nsAppShell::gAppShell->GetBrowserApp(aBrowserApp);
nsAppShell* const appShell = nsAppShell::Get();
if (appShell)
appShell->GetBrowserApp(aBrowserApp);
return NS_OK;
}
NS_IMETHODIMP nsAndroidBridge::SetBrowserApp(nsIAndroidBrowserApp *aBrowserApp)
{
if (nsAppShell::gAppShell)
nsAppShell::gAppShell->SetBrowserApp(aBrowserApp);
nsAppShell* const appShell = nsAppShell::Get();
if (appShell)
appShell->SetBrowserApp(aBrowserApp);
return NS_OK;
}