This commit is contained in:
Cameron Kaiser 2017-10-03 19:19:57 -07:00
parent b9509fba4d
commit d375d57d33
4 changed files with 50 additions and 1 deletions

View File

@ -1008,6 +1008,8 @@
var newBrowser = this.getBrowserAtIndex(this.tabContainer.selectedIndex);
if (this.mCurrentBrowser == newBrowser && !aForceUpdate)
return;
if (!aForceUpdate)
document.commandDispatcher.lock();
/*
if (!aForceUpdate) {
@ -1204,6 +1206,8 @@
this.tabContainer._setPositionalAttributes();
//if (!gMultiProcessBrowser) {
document.commandDispatcher.unlock();
let event = new CustomEvent("TabSwitchDone", {
bubbles: true,
cancelable: true
@ -3203,6 +3207,8 @@ let remote = false;
fromBrowser.setAttribute("type", "content-targetable");
}
document.commandDispatcher.unlock();
let event = new CustomEvent("TabSwitchDone", {
bubbles: true,
cancelable: true

View File

@ -31,4 +31,9 @@ interface nsIDOMXULCommandDispatcher : nsISupports
void rewindFocus();
void advanceFocusIntoSubtree(in nsIDOMElement elt);
attribute boolean suppressFocusScroll;
// When locked, command updating is batched until unlocked. Always ensure that
// lock and unlock is called in a pair.
void lock();
void unlock();
};

View File

@ -42,7 +42,7 @@ static LazyLogModule gCommandLog("nsXULCommandDispatcher");
////////////////////////////////////////////////////////////////////////
nsXULCommandDispatcher::nsXULCommandDispatcher(nsIDocument* aDocument)
: mDocument(aDocument), mUpdaters(nullptr)
: mDocument(aDocument), mUpdaters(nullptr), mLocked(false)
{
}
@ -351,6 +351,14 @@ nsXULCommandDispatcher::RemoveCommandUpdater(nsIDOMElement* aElement)
NS_IMETHODIMP
nsXULCommandDispatcher::UpdateCommands(const nsAString& aEventName)
{
if (mLocked) {
if (!mPendingUpdates.Contains(aEventName)) {
mPendingUpdates.AppendElement(aEventName);
}
return NS_OK;
}
nsAutoString id;
nsCOMPtr<nsIDOMElement> element;
GetFocusedElement(getter_AddRefs(element));
@ -458,3 +466,30 @@ nsXULCommandDispatcher::SetSuppressFocusScroll(bool aSuppressFocusScroll)
return NS_OK;
}
NS_IMETHODIMP
nsXULCommandDispatcher::Lock()
{
// Since locking is used only as a performance optimization, we don't worry
// about nested lock calls. If that does happen, it just means we will unlock
// and process updates earlier.
mLocked = true;
return NS_OK;
}
NS_IMETHODIMP
nsXULCommandDispatcher::Unlock()
{
if (mLocked) {
mLocked = false;
// Handle any pending updates one at a time. In the unlikely case where a
// lock is added during the update, break out.
while (!mLocked && mPendingUpdates.Length() > 0) {
nsString name = mPendingUpdates.ElementAt(0);
mPendingUpdates.RemoveElementAt(0);
UpdateCommands(name);
}
}
return NS_OK;
}

View File

@ -68,6 +68,9 @@ protected:
bool Matches(const nsString& aList,
const nsAString& aElement);
bool mLocked;
nsTArray<nsString> mPendingUpdates;
};
#endif // nsXULCommandDispatcher_h__