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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user