Bug 1267718 - Add a nsPIDOMWindow::GetScriptableParentOrNull method. r=bz

MozReview-Commit-ID: 9L33Wq0fBF6
This commit is contained in:
Jonathan Watt 2016-04-25 15:17:32 +01:00
Родитель 91fa002ac4
Коммит 258f5b6244
5 изменённых файлов: 26 добавлений и 6 удалений

Просмотреть файл

@ -387,8 +387,8 @@ AudioChannelService::GetState(nsPIDOMWindowOuter* aWindow, uint32_t aAudioChanne
// TODO : distiguish between suspend and mute, it would be done in bug1242874.
*aMuted = *aMuted || window->GetMediaSuspended() || window->GetAudioMuted();
nsCOMPtr<nsPIDOMWindowOuter> win = window->GetScriptableParent();
if (window == win) {
nsCOMPtr<nsPIDOMWindowOuter> win = window->GetScriptableParentOrNull();
if (!win) {
break;
}

Просмотреть файл

@ -3658,8 +3658,8 @@ nsPIDOMWindowInner::CreatePerformanceObjectIfNeeded()
// If we are dealing with an iframe, we will need the parent's performance
// object (so we can add the iframe as a resource of that page).
nsPerformance* parentPerformance = nullptr;
nsCOMPtr<nsPIDOMWindowOuter> parentWindow = GetScriptableParent();
if (GetOuterWindow() != parentWindow) {
nsCOMPtr<nsPIDOMWindowOuter> parentWindow = GetScriptableParentOrNull();
if (parentWindow) {
nsPIDOMWindowInner* parentInnerWindow = nullptr;
if (parentWindow) {
parentInnerWindow = parentWindow->GetCurrentInnerWindow();
@ -3878,6 +3878,19 @@ nsGlobalWindow::GetScriptableParent()
return parent.get();
}
/**
* Behavies identically to GetScriptableParent extept that it returns null
* if GetScriptableParent would return this window.
*/
nsPIDOMWindowOuter*
nsGlobalWindow::GetScriptableParentOrNull()
{
FORWARD_TO_OUTER(GetScriptableParentOrNull, (), nullptr);
nsPIDOMWindowOuter* parent = GetScriptableParent();
return (Cast(parent) == this) ? nullptr : parent;
}
/**
* nsPIDOMWindow::GetParent (when called from C++) is just a wrapper around
* GetRealParent.

Просмотреть файл

@ -896,6 +896,7 @@ public:
already_AddRefed<nsPIDOMWindowOuter> GetParent(mozilla::ErrorResult& aError);
already_AddRefed<nsPIDOMWindowOuter> GetParent() override;
nsPIDOMWindowOuter* GetScriptableParent() override;
nsPIDOMWindowOuter* GetScriptableParentOrNull() override;
mozilla::dom::Element* GetFrameElementOuter();
mozilla::dom::Element* GetFrameElement(mozilla::ErrorResult& aError);
already_AddRefed<nsIDOMElement> GetFrameElement() override;

Просмотреть файл

@ -118,6 +118,12 @@ public:
virtual nsPIDOMWindowOuter* GetScriptableParent() = 0;
virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() = 0;
/**
* Behavies identically to GetScriptableParent extept that it returns null
* if GetScriptableParent would return this window.
*/
virtual nsPIDOMWindowOuter* GetScriptableParentOrNull() = 0;
// Inner windows only.
virtual nsresult RegisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0;
virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0;

Просмотреть файл

@ -3275,8 +3275,8 @@ TabParent::AudioChannelChangeNotification(nsPIDOMWindowOuter* aWindow,
break;
}
nsCOMPtr<nsPIDOMWindowOuter> win = window->GetScriptableParent();
if (window == win) {
nsCOMPtr<nsPIDOMWindowOuter> win = window->GetScriptableParentOrNull();
if (!win) {
break;
}