Skip to content

Commit

Permalink
Bug 1646601 move fully active predicate to nsPIDOMWindowInner r=farre
Browse files Browse the repository at this point in the history
Depends on D90216

Differential Revision: https://phabricator.services.mozilla.com/D90217
  • Loading branch information
karlt committed Sep 15, 2020
1 parent 820dfc0 commit 9e13b21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
14 changes: 14 additions & 0 deletions dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,20 @@ bool nsPIDOMWindowInner::IsCurrentInnerWindow() const {
return outer && outer->GetCurrentInnerWindow() == this;
}

bool nsPIDOMWindowInner::IsFullyActive() const {
WindowContext* currentContext = GetWindowContext();
if (!currentContext) {
return false;
}
do {
if (currentContext->IsDiscarded() || currentContext->IsCached()) {
return false;
}
} while ((currentContext = currentContext->GetParentWindowContext()));

return true;
}

void nsPIDOMWindowInner::SetAudioCapture(bool aCapture) {
RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
if (service) {
Expand Down
5 changes: 5 additions & 0 deletions dom/base/nsPIDOMWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class nsPIDOMWindowInner : public mozIDOMWindow {
// creates new inner windows for the document it is called on.
inline bool HasActiveDocument();

// Return true if this object is the currently-active inner window for its
// BrowsingContext and any container document is also fully active.
// For https://html.spec.whatwg.org/multipage/browsers.html#fully-active
bool IsFullyActive() const;

// Returns true if this window is the same as mTopInnerWindow
inline bool IsTopInnerWindow() const;

Expand Down
17 changes: 1 addition & 16 deletions dom/media/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,21 +2282,6 @@ nsresult MediaManager::GenerateUUID(nsAString& aResult) {
return NS_OK;
}

static bool IsFullyActive(nsPIDOMWindowInner* aWindow) {
dom::WindowContext* currentContext;
if (!aWindow || !(currentContext = aWindow->GetWindowContext())) {
return false;
}
for (; currentContext;
currentContext = currentContext->GetParentWindowContext()) {
if (currentContext->IsDiscarded() || currentContext->IsCached()) {
return false;
}
}

return true;
}

enum class GetUserMediaSecurityState {
Other = 0,
HTTPS = 1,
Expand Down Expand Up @@ -2363,7 +2348,7 @@ RefPtr<MediaManager::StreamPromise> MediaManager::GetUserMedia(
__func__);
}

if (!IsFullyActive(aWindow)) {
if (!aWindow->IsFullyActive()) {
return StreamPromise::CreateAndReject(
MakeRefPtr<MediaMgrError>(MediaMgrError::Name::InvalidStateError),
__func__);
Expand Down

0 comments on commit 9e13b21

Please sign in to comment.