From 51e39ebc5a0c1f261e91f3bc510c8622e5c67ef1 Mon Sep 17 00:00:00 2001 From: Iulian Moraru Date: Tue, 4 Jun 2024 16:49:11 +0300 Subject: [PATCH] Backed out changeset a00be88f3708 (bug 1877969) for causing multiple failures. CLOSED TREE --- dom/html/HTMLInputElement.cpp | 24 +++++++++++------------- dom/html/HTMLSelectElement.cpp | 10 ---------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 06b7c46d96fd..42cef0b0290e 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -677,11 +677,16 @@ nsColorPickerShownCallback::Done(const nsAString& aColor) { NS_IMPL_ISUPPORTS(nsColorPickerShownCallback, nsIColorPickerShownCallback) -static bool IsPickerBlocked(Document* aDoc) { +static bool IsPopupBlocked(Document* aDoc) { if (aDoc->ConsumeTransientUserGestureActivation()) { return false; } + WindowContext* wc = aDoc->GetWindowContext(); + if (wc && wc->CanShowPopup()) { + return false; + } + nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns, aDoc, nsContentUtils::eDOM_PROPERTIES, "InputPickerBlockedNoUserActivation"); @@ -730,7 +735,7 @@ nsresult HTMLInputElement::InitColorPicker() { return NS_ERROR_FAILURE; } - if (IsPickerBlocked(doc)) { + if (IsPopupBlocked(doc)) { return NS_OK; } @@ -778,7 +783,7 @@ nsresult HTMLInputElement::InitFilePicker(FilePickerType aType) { return NS_ERROR_FAILURE; } - if (IsPickerBlocked(doc)) { + if (IsPopupBlocked(doc)) { return NS_OK; } @@ -3572,7 +3577,7 @@ nsresult HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor) { // open a color picker when we receive a click on a . // A click is handled if it's the left mouse button. // We do not prevent non-trusted click because authors can already use - // .click(). However, the pickers will check and consume user activation. + // .click(). However, the pickers will follow the rules of popup-blocking. WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); if (!(mouseEvent && mouseEvent->IsLeftClickEvent())) { return NS_OK; @@ -5840,11 +5845,7 @@ void HTMLInputElement::ShowPicker(ErrorResult& aRv) { // Step 2. If element is not mutable, then return. // (See above.) - // Step 3. Consume user activation given element's relevant global object. - // InitFilePicker() and InitColorPicker() consume it themselves, - // so only consume in this function if not those. - - // Step 4. If element's type attribute is in the File Upload state, then run + // Step 3. If element's type attribute is in the File Upload state, then run // these steps in parallel: if (mType == FormControlType::InputFile) { FilePickerType type = FILE_PICKER_FILE; @@ -5856,7 +5857,7 @@ void HTMLInputElement::ShowPicker(ErrorResult& aRv) { return; } - // Step 5. Otherwise, the user agent should show any relevant user interface + // Step 4. Otherwise, the user agent should show any relevant user interface // for selecting a value for element, in the way it normally would when the // user interacts with the control if (mType == FormControlType::InputColor) { @@ -5864,9 +5865,6 @@ void HTMLInputElement::ShowPicker(ErrorResult& aRv) { return; } - // See Step 3. - OwnerDoc()->ConsumeTransientUserGestureActivation(); - if (!IsInComposedDoc()) { return; } diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp index 2d1765692f59..44531cccbc68 100644 --- a/dom/html/HTMLSelectElement.cpp +++ b/dom/html/HTMLSelectElement.cpp @@ -201,16 +201,6 @@ void HTMLSelectElement::ShowPicker(ErrorResult& aRv) { } // Step 5. Show the picker, if applicable, for this. - // https://html.spec.whatwg.org/multipage/input.html#show-the-picker,-if-applicable - // To show the picker, if applicable for an input element element: - // We already checked if mutable and user activation earlier, so skip 1 & 2. - - // Step 3. Consume user activation given element's relevant global object. - OwnerDoc()->ConsumeTransientUserGestureActivation(); - - // Step 5. Otherwise, the user agent should show any relevant user interface - // for selecting a value for element, in the way it normally would when the - // user interacts with the control. #if !defined(ANDROID) if (!IsCombobox()) { return;