Bug 1105098 - Make AnimationTimeline always return the same parent object (even after document.open()) and replace the document's timeline if the document is reset. r=smaug,birtles

This commit is contained in:
Jonathan Watt 2015-01-26 17:08:51 +00:00
parent c726fb7ecf
commit 514dc59de8
3 changed files with 15 additions and 2 deletions

View File

@ -15,7 +15,7 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AnimationTimeline, mDocument)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AnimationTimeline, mDocument, mWindow)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AnimationTimeline, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AnimationTimeline, Release)

View File

@ -10,6 +10,7 @@
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Attributes.h"
#include "mozilla/TimeStamp.h"
#include "nsIGlobalObject.h"
#include "js/TypeDecls.h"
#include "nsIDocument.h"
#include "nsRefreshDriver.h"
@ -24,7 +25,9 @@ class AnimationTimeline MOZ_FINAL : public nsWrapperCache
public:
explicit AnimationTimeline(nsIDocument* aDocument)
: mDocument(aDocument)
, mWindow(aDocument->GetParentObject())
{
MOZ_ASSERT(mWindow);
}
protected:
@ -36,7 +39,7 @@ public:
nsIGlobalObject* GetParentObject() const
{
return mDocument->GetParentObject();
return mWindow;
}
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
@ -70,7 +73,12 @@ public:
protected:
TimeStamp GetCurrentTimeStamp() const;
// Sometimes documents can be given a new window, or windows can be given a
// new document (e.g. document.open()). Since GetParentObject is required to
// _always_ return the same object it can't get the window from our
// mDocument, which is why we have pointers to both our document and window.
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsIGlobalObject> mWindow;
// The most recently used refresh driver time. This is used in cases where
// we don't have a refresh driver (e.g. because we are in a display:none

View File

@ -2290,6 +2290,11 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
ResetToURI(uri, aLoadGroup, principal);
// Note that, since mTiming does not change during a reset, the
// navigationStart time remains unchanged and therefore any future new
// timeline will have the same global clock time as the old one.
mAnimationTimeline = nullptr;
nsCOMPtr<nsIPropertyBag2> bag = do_QueryInterface(aChannel);
if (bag) {
nsCOMPtr<nsIURI> baseURI;