Bug 907410 - Winrt async input - rework shutdown logic. r=bbondy

This commit is contained in:
Jim Mathies 2013-09-06 08:11:16 -05:00
parent 9318ea54dc
commit 356e5e00ad
4 changed files with 36 additions and 59 deletions

View File

@ -77,26 +77,6 @@ FrameworkView::Initialize(ICoreApplicationView* aAppView)
HRESULT
FrameworkView::Uninitialize()
{
LogFunction();
mShuttingDown = true;
if (mAutomationProvider) {
ComPtr<IUIABridge> provider;
mAutomationProvider.As(&provider);
if (provider) {
provider->Disconnect();
}
}
mAutomationProvider = nullptr;
mMetroInput = nullptr;
mD2DWindowSurface = nullptr;
delete sSettingsArray;
sSettingsArray = nullptr;
mWidget = nullptr;
mMetroApp = nullptr;
mWindow = nullptr;
return S_OK;
}
@ -117,6 +97,7 @@ FrameworkView::Run()
// off normal browser execution / event dispatching.
mMetroApp->Run();
// Gecko is completely shut down at this point.
Log("Exiting FrameworkView::Run()");
return S_OK;
@ -203,7 +184,25 @@ FrameworkView::AddEventHandlers() {
void
FrameworkView::ShutdownXPCOM()
{
Uninitialize();
LogFunction();
mShuttingDown = true;
if (mAutomationProvider) {
ComPtr<IUIABridge> provider;
mAutomationProvider.As(&provider);
if (provider) {
provider->Disconnect();
}
}
mAutomationProvider = nullptr;
mMetroInput = nullptr;
mD2DWindowSurface = nullptr;
delete sSettingsArray;
sSettingsArray = nullptr;
mWidget = nullptr;
mMetroApp = nullptr;
mWindow = nullptr;
}
void

View File

@ -82,8 +82,6 @@ public:
// Public apis for MetroWidget
void ShutdownXPCOM();
bool Render();
bool Render(const nsIntRegion& aInvalidRegion);
float GetDPI() { return mDPI; }
ICoreWindow* GetCoreWindow() { return mWindow.Get(); }
void SetWidget(MetroWidget* aWidget);

View File

@ -113,6 +113,12 @@ MetroAppShell::Run(void)
sFrameworkView->ActivateView();
rv = nsBaseAppShell::Run();
mozilla::widget::StopAudioSession();
// This calls XRE_metroShutdown() in xre. This will also destroy
// MessagePump.
sMetroApp->ShutdownXPCOM();
// This will free the real main thread in CoreApplication::Run()
// once winrt cleans up this thread.
sMetroApp->CoreExit();
break;
}
@ -164,39 +170,11 @@ MetroAppShell::ProcessNextNativeEvent(bool mayWait)
return ProcessOneNativeEventIfPresent();
}
// Results from a call to appstartup->quit, which fires a final nsAppExitEvent
// event which calls us here. This is on the metro main thread. We want to
// call xpcom shutdown here, but we need to wait until the runnable that fires
// this is off the stack. See NativeEventCallback below.
NS_IMETHODIMP
MetroAppShell::Exit(void)
{
LogFunction();
mExiting = true;
return NS_OK;
}
void
MetroAppShell::NativeCallback()
{
NS_ASSERTION(NS_IsMainThread(), "Native callbacks must be on the metro main thread");
NativeEventCallback();
// Handle shutdown after Exit() is called and unwinds.
if (mExiting) {
// shutdown fires events, don't recurse
static bool sShutdown = false;
if (sShutdown)
return;
sShutdown = true;
if (sMetroApp) {
// This calls XRE_metroShutdown() in xre
sMetroApp->ShutdownXPCOM();
// This will free the real main thread in CoreApplication::Run()
// once winrt cleans up this thread.
sMetroApp->CoreExit();
}
}
}
// static

View File

@ -15,8 +15,11 @@ class MetroAppShell : public nsBaseAppShell
public:
NS_DECL_NSIOBSERVER
MetroAppShell() : mEventWnd(NULL), mExiting(false), mPowerRequestCount(0)
{}
MetroAppShell() :
mEventWnd(NULL),
mPowerRequestCount(0)
{
}
nsresult Init();
void DoProcessMoreGeckoEvents();
@ -26,14 +29,13 @@ public:
static bool ProcessOneNativeEventIfPresent();
protected:
HWND mEventWnd;
bool mExiting;
nsAutoHandle mPowerRequest;
ULONG mPowerRequestCount;
NS_IMETHOD Run();
NS_IMETHOD Exit();
virtual void ScheduleNativeEventCallback();
virtual bool ProcessNextNativeEvent(bool mayWait);
virtual ~MetroAppShell();
HWND mEventWnd;
nsAutoHandle mPowerRequest;
ULONG mPowerRequestCount;
};