Bug 1837963 - Disallow opening file pickers from background tabs; r=geckoview-reviewers,emilio,m_kato

Differential Revision: https://phabricator.services.mozilla.com/D230087
This commit is contained in:
Edgar Chen
2025-01-14 12:33:43 +00:00
parent 1395b20685
commit eda589c635
7 changed files with 71 additions and 12 deletions

View File

@@ -3233,6 +3233,32 @@ CanonicalBrowsingContext::GetBounceTrackingState() {
return mWebProgress->GetBounceTrackingState();
}
bool CanonicalBrowsingContext::CanOpenModalPicker() {
if (!mozilla::StaticPrefs::browser_disable_pickers_background_tabs()) {
return true;
}
// Alway allows to open picker from chrome.
if (IsChrome()) {
return true;
}
if (!IsActive()) {
return false;
}
RefPtr<Document> chromeDoc = TopCrossChromeBoundary()->GetExtantDocument();
if (!chromeDoc || !chromeDoc->HasFocus(mozilla::IgnoreErrors())) {
return false;
}
// Only allow web content to open a picker when it has focus. For example, if
// the focus is on the URL bar, web content cannot open a picker, even if it
// is the foreground tab.
mozilla::dom::Element* topFrameElement = GetTopFrameElement();
return !topFrameElement || topFrameElement == chromeDoc->GetActiveElement();
}
NS_IMPL_CYCLE_COLLECTION_CLASS(CanonicalBrowsingContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CanonicalBrowsingContext,