Bug 1143848 - Query Document from Parent in case of nested workers (r=bent)

--HG--
extra : rebase_source : bfdc5979488a489e4adf66fccbdce8fd65255db3
This commit is contained in:
Christoph Kerschbaumer 2015-04-07 09:19:19 -07:00
parent 0f4cd2b27f
commit 4653f5de8c
2 changed files with 23 additions and 6 deletions

View File

@ -2662,6 +2662,28 @@ struct WorkerPrivate::PreemptingRunnableInfo final
}
};
template <class Derived>
nsIDocument*
WorkerPrivateParent<Derived>::GetDocument() const
{
AssertIsOnMainThread();
if (mLoadInfo.mWindow) {
return mLoadInfo.mWindow->GetExtantDoc();
}
// if we don't have a document, we should query the document
// from the parent in case of a nested worker
WorkerPrivate* parent = mParent;
while (parent) {
if (parent->mLoadInfo.mWindow) {
return parent->mLoadInfo.mWindow->GetExtantDoc();
}
parent = parent->GetParent();
}
// couldn't query a document, give up and return nullptr
return nullptr;
}
// Can't use NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerPrivateParent) because of the
// templates.
template <class Derived>

View File

@ -581,12 +581,7 @@ public:
return mLoadInfo.mChannel.forget();
}
nsIDocument*
GetDocument() const
{
AssertIsOnMainThread();
return mLoadInfo.mWindow ? mLoadInfo.mWindow->GetExtantDoc() : nullptr;
}
nsIDocument* GetDocument() const;
nsPIDOMWindow*
GetWindow()