Skip to content

Commit

Permalink
Bug 1279086 - Allow painting for tab switch when JS is running (r=dva…
Browse files Browse the repository at this point in the history
…nder,mconley,mrbkap)
  • Loading branch information
bill-mccloskey committed Aug 19, 2016
1 parent b62177b commit feaf768
Show file tree
Hide file tree
Showing 31 changed files with 559 additions and 390 deletions.
7 changes: 6 additions & 1 deletion browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3300,6 +3300,7 @@ var PrintPreviewListener = {
this._simplifyPageTab = null;
}
gBrowser.removeTab(this._printPreviewTab);
gBrowser.deactivatePrintPreviewBrowsers();
this._printPreviewTab = null;
},
_toggleAffectedChrome: function () {
Expand Down Expand Up @@ -3355,7 +3356,11 @@ var PrintPreviewListener = {

if (this._chromeState.sidebarOpen)
SidebarUI.show(this._sidebarCommand);
}
},

activateBrowser(browser) {
gBrowser.activateBrowserForPrintPreview(browser);
},
}

function getMarkupDocumentViewer()
Expand Down
314 changes: 201 additions & 113 deletions browser/base/content/tabbrowser.xml

Large diffs are not rendered by default.

42 changes: 0 additions & 42 deletions dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,6 @@ nsFrameLoader::SwapWithOtherRemoteLoader(nsFrameLoader* aOther,
return rv;
}

mRemoteBrowser->SwapLayerTreeObservers(aOther->mRemoteBrowser);

nsCOMPtr<nsIBrowserDOMWindow> otherBrowserDOMWindow =
aOther->mRemoteBrowser->GetBrowserDOMWindow();
nsCOMPtr<nsIBrowserDOMWindow> browserDOMWindow =
Expand Down Expand Up @@ -3203,46 +3201,6 @@ nsFrameLoader::RequestNotifyAfterRemotePaint()
return NS_OK;
}

NS_IMETHODIMP
nsFrameLoader::RequestNotifyLayerTreeReady()
{
if (mRemoteBrowser) {
return mRemoteBrowser->RequestNotifyLayerTreeReady() ? NS_OK : NS_ERROR_NOT_AVAILABLE;
}

if (!mOwnerContent) {
return NS_ERROR_NOT_AVAILABLE;
}

RefPtr<AsyncEventDispatcher> event =
new AsyncEventDispatcher(mOwnerContent,
NS_LITERAL_STRING("MozLayerTreeReady"),
true, false);
event->PostDOMEvent();

return NS_OK;
}

NS_IMETHODIMP
nsFrameLoader::RequestNotifyLayerTreeCleared()
{
if (mRemoteBrowser) {
return mRemoteBrowser->RequestNotifyLayerTreeCleared() ? NS_OK : NS_ERROR_NOT_AVAILABLE;
}

if (!mOwnerContent) {
return NS_ERROR_NOT_AVAILABLE;
}

RefPtr<AsyncEventDispatcher> event =
new AsyncEventDispatcher(mOwnerContent,
NS_LITERAL_STRING("MozLayerTreeCleared"),
true, false);
event->PostDOMEvent();

return NS_OK;
}

NS_IMETHODIMP
nsFrameLoader::Print(uint64_t aOuterWindowID,
nsIPrintSettings* aPrintSettings,
Expand Down
8 changes: 0 additions & 8 deletions dom/base/nsIFrameLoader.idl
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ interface nsIFrameLoader : nsISupports
*/
void requestNotifyAfterRemotePaint();

/**
* Request an event when the layer tree from the remote tab becomes
* available or unavailable. When this happens, a mozLayerTreeReady
* or mozLayerTreeCleared event is fired.
*/
void requestNotifyLayerTreeReady();
void requestNotifyLayerTreeCleared();

/**
* Print the current document.
*
Expand Down
9 changes: 9 additions & 0 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5501,3 +5501,12 @@ ContentParent::SendGetFilesResponseAndForget(const nsID& aUUID,
Unused << SendGetFilesResponse(aUUID, aResult);
}
}

void
ContentParent::ForceTabPaint(TabParent* aTabParent, uint64_t aLayerObserverEpoch)
{
if (!mHangMonitorActor) {
return;
}
ProcessHangMonitor::ForcePaint(mHangMonitorActor, aTabParent, aLayerObserverEpoch);
}
3 changes: 3 additions & 0 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ class ContentParent final : public PContentParent

virtual int32_t Pid() const override;

// Use the PHangMonitor channel to ask the child to repaint a tab.
void ForceTabPaint(TabParent* aTabParent, uint64_t aLayerObserverEpoch);

protected:
void OnChannelConnected(int32_t pid) override;

Expand Down
7 changes: 6 additions & 1 deletion dom/ipc/PBrowser.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ parent:
*/
async RemotePaintIsReady();

/**
* Child informs the parent that the layer tree is already available.
*/
async ForcePaintNoOp(uint64_t aLayerObserverEpoch);

/**
* Sent by the child to the parent to inform it that an update to the
* dimensions has been requested, likely through win.moveTo or resizeTo
Expand Down Expand Up @@ -721,7 +726,7 @@ child:
/**
* Update the child side docShell active (resource use) state.
*/
async SetDocShellIsActive(bool aIsActive, bool aIsHidden);
async SetDocShellIsActive(bool aIsActive, bool aIsHidden, uint64_t aLayerObserverEpoch);

/**
* Notify the child that it shouldn't paint the offscreen displayport.
Expand Down
2 changes: 2 additions & 0 deletions dom/ipc/PProcessHangMonitor.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ child:

async BeginStartingDebugger();
async EndStartingDebugger();

async ForcePaint(TabId tabId, uint64_t aLayerObserverEpoch);
};

} // namespace mozilla
104 changes: 104 additions & 0 deletions dom/ipc/ProcessHangMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "mozilla/ProcessHangMonitor.h"
#include "mozilla/ProcessHangMonitorIPC.h"

#include "jsapi.h"
#include "js/GCAPI.h"

#include "mozilla/Atomics.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/Monitor.h"
Expand Down Expand Up @@ -96,8 +100,11 @@ class HangMonitorChild
virtual bool RecvBeginStartingDebugger() override;
virtual bool RecvEndStartingDebugger() override;

virtual bool RecvForcePaint(const TabId& aTabId, const uint64_t& aLayerObserverEpoch) override;

virtual void ActorDestroy(ActorDestroyReason aWhy) override;

void InterruptCallback();
void Shutdown();

static HangMonitorChild* Get() { return sInstance; }
Expand All @@ -119,6 +126,10 @@ class HangMonitorChild
bool mTerminateScript;
bool mStartDebugger;
bool mFinishedStartingDebugger;
bool mForcePaint;
TabId mForcePaintTab;
uint64_t mForcePaintEpoch;
JSContext* mContext;
bool mShutdownDone;

// This field is only accessed on the hang thread.
Expand Down Expand Up @@ -208,6 +219,8 @@ class HangMonitorParent

void Shutdown();

void ForcePaint(dom::TabParent* aTabParent, uint64_t aLayerObserverEpoch);

void TerminateScript();
void BeginStartingDebugger();
void EndStartingDebugger();
Expand All @@ -224,6 +237,9 @@ class HangMonitorParent

private:
bool TakeBrowserMinidump(const PluginHangData& aPhd, nsString& aCrashId);

void ForcePaintOnThread(TabId aTabId, uint64_t aLayerObserverEpoch);

void ShutdownOnThread();

const RefPtr<ProcessHangMonitor> mHangMonitor;
Expand Down Expand Up @@ -255,10 +271,12 @@ HangMonitorChild::HangMonitorChild(ProcessHangMonitor* aMonitor)
mTerminateScript(false),
mStartDebugger(false),
mFinishedStartingDebugger(false),
mForcePaint(false),
mShutdownDone(false),
mIPCOpen(true)
{
MOZ_RELEASE_ASSERT(NS_IsMainThread());
mContext = danger::GetJSContext();
}

HangMonitorChild::~HangMonitorChild()
Expand All @@ -268,6 +286,33 @@ HangMonitorChild::~HangMonitorChild()
sInstance = nullptr;
}

void
HangMonitorChild::InterruptCallback()
{
MOZ_RELEASE_ASSERT(NS_IsMainThread());

bool forcePaint;
TabId forcePaintTab;
uint64_t forcePaintEpoch;

{
MonitorAutoLock lock(mMonitor);
forcePaint = mForcePaint;
forcePaintTab = mForcePaintTab;
forcePaintEpoch = mForcePaintEpoch;

mForcePaint = false;
}

if (forcePaint) {
RefPtr<TabChild> tabChild = TabChild::FindTabChild(forcePaintTab);
if (tabChild) {
JS::AutoAssertOnGC aaogc(mContext);
tabChild->ForcePaint(forcePaintEpoch);
}
}
}

void
HangMonitorChild::Shutdown()
{
Expand Down Expand Up @@ -331,6 +376,23 @@ HangMonitorChild::RecvEndStartingDebugger()
return true;
}

bool
HangMonitorChild::RecvForcePaint(const TabId& aTabId, const uint64_t& aLayerObserverEpoch)
{
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());

{
MonitorAutoLock lock(mMonitor);
mForcePaint = true;
mForcePaintTab = aTabId;
mForcePaintEpoch = aLayerObserverEpoch;
}

JS_RequestInterruptCallback(mContext);

return true;
}

void
HangMonitorChild::Open(Transport* aTransport, ProcessId aPid,
MessageLoop* aIOLoop)
Expand Down Expand Up @@ -524,6 +586,25 @@ HangMonitorParent::ShutdownOnThread()
mMonitor.Notify();
}

void
HangMonitorParent::ForcePaint(dom::TabParent* aTab, uint64_t aLayerObserverEpoch)
{
MOZ_RELEASE_ASSERT(NS_IsMainThread());
TabId id = aTab->GetTabId();
MonitorLoop()->PostTask(NewNonOwningRunnableMethod<TabId, uint64_t>(
this, &HangMonitorParent::ForcePaintOnThread, id, aLayerObserverEpoch));
}

void
HangMonitorParent::ForcePaintOnThread(TabId aTabId, uint64_t aLayerObserverEpoch)
{
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());

if (mIPCOpen) {
Unused << SendForcePaint(aTabId, aLayerObserverEpoch);
}
}

void
HangMonitorParent::ActorDestroy(ActorDestroyReason aWhy)
{
Expand Down Expand Up @@ -959,6 +1040,16 @@ HangMonitoredProcess::UserCanceled()
return NS_OK;
}

static bool
InterruptCallback(JSContext* cx)
{
if (HangMonitorChild* child = HangMonitorChild::Get()) {
child->InterruptCallback();
}

return true;
}

ProcessHangMonitor* ProcessHangMonitor::sInstance;

ProcessHangMonitor::ProcessHangMonitor()
Expand Down Expand Up @@ -1094,6 +1185,9 @@ mozilla::CreateHangMonitorChild(mozilla::ipc::Transport* aTransport,
{
MOZ_RELEASE_ASSERT(NS_IsMainThread());

JSContext* cx = danger::GetJSContext();
JS_AddInterruptCallback(cx, InterruptCallback);

ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
HangMonitorChild* child = new HangMonitorChild(monitor);

Expand Down Expand Up @@ -1142,3 +1236,13 @@ ProcessHangMonitor::ClearHang()
child->ClearHang();
}
}

/* static */ void
ProcessHangMonitor::ForcePaint(PProcessHangMonitorParent* aParent,
dom::TabParent* aTabParent,
uint64_t aLayerObserverEpoch)
{
MOZ_RELEASE_ASSERT(NS_IsMainThread());
auto parent = static_cast<HangMonitorParent*>(aParent);
parent->ForcePaint(aTabParent, aLayerObserverEpoch);
}
5 changes: 5 additions & 0 deletions dom/ipc/ProcessHangMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace mozilla {

namespace dom {
class ContentParent;
class TabParent;
} // namespace dom

class PProcessHangMonitorParent;
Expand All @@ -45,6 +46,10 @@ class ProcessHangMonitor final

static void ClearHang();

static void ForcePaint(PProcessHangMonitorParent* aParent,
dom::TabParent* aTab,
uint64_t aLayerObserverEpoch);

enum SlowScriptAction {
Continue,
Terminate,
Expand Down
Loading

0 comments on commit feaf768

Please sign in to comment.