Bug 1270753 part 1 - Use the weak reference itself as an index for OldWindowSize item. r?smaug
MozReview-Commit-ID: 3X7O5pAuZ3N
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3102,64 +3102,53 @@ PrepareForFullscreenChange(nsIPresShell*
viewManager->SetWindowDimensions(aSize.width, aSize.height);
}
}
}
class OldWindowSize : public LinkedListElement<OldWindowSize>
{
public:
- static void Set(nsPIDOMWindowOuter* aWindow, const nsSize& aSize)
+ static void Set(nsIWeakReference* aWindowRef, const nsSize& aSize)
{
- OldWindowSize* item = GetItem(aWindow);
+ OldWindowSize* item = GetItem(aWindowRef);
if (item) {
item->mSize = aSize;
- } else if (aWindow) {
- item = new OldWindowSize(do_GetWeakReference(aWindow), aSize);
+ } else {
+ item = new OldWindowSize(aWindowRef, aSize);
sList.insertBack(item);
}
}
- static nsSize GetAndRemove(nsPIDOMWindowOuter* aWindow)
+ static nsSize GetAndRemove(nsIWeakReference* aWindowRef)
{
nsSize result;
- if (OldWindowSize* item = GetItem(aWindow)) {
+ if (OldWindowSize* item = GetItem(aWindowRef)) {
result = item->mSize;
delete item;
}
return result;
}
private:
- explicit OldWindowSize(already_AddRefed<nsIWeakReference>&& aWindow,
- const nsSize& aSize)
- : mWindow(Move(aWindow)), mSize(aSize) { }
+ explicit OldWindowSize(nsIWeakReference* aWindowRef, const nsSize& aSize)
+ : mWindowRef(aWindowRef), mSize(aSize) { }
~OldWindowSize() { };
- static OldWindowSize* GetItem(nsPIDOMWindowOuter* aWindow)
+ static OldWindowSize* GetItem(nsIWeakReference* aWindowRef)
{
OldWindowSize* item = sList.getFirst();
- while (item) {
- nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(item->mWindow);
- if (!window) {
- OldWindowSize* thisItem = item;
- item = thisItem->getNext();
- delete thisItem;
- continue;
- }
- if (window == aWindow) {
- break;
- }
+ while (item && item->mWindowRef != aWindowRef) {
item = item->getNext();
}
return item;
}
static LinkedList<OldWindowSize> sList;
- nsWeakPtr mWindow;
+ nsWeakPtr mWindowRef;
nsSize mSize;
};
LinkedList<OldWindowSize> OldWindowSize::sList;
NS_IMETHODIMP
nsDOMWindowUtils::HandleFullscreenRequests(bool* aRetVal)
{
@@ -3172,32 +3161,32 @@ nsDOMWindowUtils::HandleFullscreenReques
// comes after the fullscreen change call, doing so could avoid an
// extra resize reflow after this point.
nsRect screenRect;
if (nsPresContext* presContext = GetPresContext()) {
presContext->DeviceContext()->GetRect(screenRect);
}
nsSize oldSize;
PrepareForFullscreenChange(GetPresShell(), screenRect.Size(), &oldSize);
- OldWindowSize::Set(doc->GetWindow(), oldSize);
+ OldWindowSize::Set(mWindow, oldSize);
*aRetVal = nsIDocument::HandlePendingFullscreenRequests(doc);
return NS_OK;
}
nsresult
nsDOMWindowUtils::ExitFullscreen()
{
PROFILER_MARKER("Exit fullscreen");
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ENSURE_STATE(doc);
// Although we would not use the old size if we have already exited
// fullscreen, we still want to cleanup in case we haven't.
- nsSize oldSize = OldWindowSize::GetAndRemove(doc->GetWindow());
+ nsSize oldSize = OldWindowSize::GetAndRemove(mWindow);
if (!doc->GetFullscreenElement()) {
return NS_OK;
}
// Notify the pres shell that we are starting fullscreen change, and
// set the window dimensions in advance. Since the resize message
// comes after the fullscreen change call, doing so could avoid an
// extra resize reflow after this point.