diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index dc4124a52add..85b49f3d8d38 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1314,7 +1314,6 @@ void nsDocShell::FirePageHideShowNonRecursive(bool aShow) { mScriptGlobal ? mScriptGlobal->GetCurrentInnerWindow() : nullptr; if (mBrowsingContext->IsTop()) { doc->NotifyPossibleTitleChange(false); - doc->SetLoadingOrRestoredFromBFCacheTimeStampToNow(); if (inner) { // Now that we have found the inner window of the page restored // from the history, we have to make sure that diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index cd3f68b1a392..d3648732f868 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -12225,7 +12225,7 @@ void Document::SetReadyStateInternal(ReadyState aReadyState, } if (aUpdateTimingInformation && READYSTATE_LOADING == aReadyState) { - SetLoadingOrRestoredFromBFCacheTimeStampToNow(); + mLoadingTimeStamp = TimeStamp::Now(); } NotifyLoading(mAncestorIsLoading, mReadyState, aReadyState); mReadyState = aReadyState; @@ -13578,9 +13578,8 @@ nsresult Document::GetStateObject(JS::MutableHandle aState) { void Document::SetNavigationTiming(nsDOMNavigationTiming* aTiming) { mTiming = aTiming; - if (!mLoadingOrRestoredFromBFCacheTimeStamp.IsNull() && mTiming) { - mTiming->SetDOMLoadingTimeStamp(GetDocumentURI(), - mLoadingOrRestoredFromBFCacheTimeStamp); + if (!mLoadingTimeStamp.IsNull() && mTiming) { + mTiming->SetDOMLoadingTimeStamp(GetDocumentURI(), mLoadingTimeStamp); } // If there's already the DocumentTimeline instance, tell it since the diff --git a/dom/base/Document.h b/dom/base/Document.h index d775f944b0fd..4d82a83edc40 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -1045,13 +1045,6 @@ class Document : public nsINode, void SetLoadedAsData(bool aLoadedAsData, bool aConsiderForMemoryReporting); - TimeStamp GetLoadingOrRestoredFromBFCacheTimeStamp() const { - return mLoadingOrRestoredFromBFCacheTimeStamp; - } - void SetLoadingOrRestoredFromBFCacheTimeStampToNow() { - mLoadingOrRestoredFromBFCacheTimeStamp = TimeStamp::Now(); - } - /** * Normally we assert if a runnable labeled with one DocGroup touches data * from another DocGroup. Calling IgnoreDocGroupMismatches() on a document @@ -5122,9 +5115,8 @@ class Document : public nsINode, RefPtr mTiming; - // Recorded time of change to 'loading' state - // or time of the page gets restored from BFCache. - TimeStamp mLoadingOrRestoredFromBFCacheTimeStamp; + // Recorded time of change to 'loading' state. + TimeStamp mLoadingTimeStamp; // Decided to use nsTObserverArray because it allows us to // remove candidates while iterating them and this is what diff --git a/dom/base/test/browser.ini b/dom/base/test/browser.ini index 4a556174081d..9054f586e7a7 100644 --- a/dom/base/test/browser.ini +++ b/dom/base/test/browser.ini @@ -105,6 +105,3 @@ support-files = file_browser_refresh_iframe.sjs [browser_page_load_event_telemetry.js] [browser_xml_toggle.js] -[browser_user_input_handling_delay.js] -[browser_user_input_handling_delay_bfcache.js] -[browser_user_input_handling_delay_aboutblank.js] diff --git a/dom/base/test/browser_user_input_handling_delay.js b/dom/base/test/browser_user_input_handling_delay.js deleted file mode 100644 index 683f4628de10..000000000000 --- a/dom/base/test/browser_user_input_handling_delay.js +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: JavaScript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -async function test_user_input_handling_delay_helper(prefs) { - await SpecialPowers.pushPrefEnv({ - set: prefs, - }); - - const tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - `data:text/html,` - ); - - let canHandleInput = false; - let mouseDownPromise = BrowserTestUtils.waitForContentEvent( - tab.linkedBrowser, - "mousedown" - ).then(function () { - Assert.ok( - canHandleInput, - "This promise should be resolved after the 5 seconds mark has passed" - ); - }); - - for (let i = 0; i < 10; ++i) { - await BrowserTestUtils.synthesizeMouseAtPoint( - 10, - 10, - { type: "mousedown" }, - tab.linkedBrowser - ); - } - // Wait for roughly 5 seconds to give chances for the - // above mousedown event to be handled. - await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { - for (let i = 0; i < 300; ++i) { - await new Promise(r => { - content.requestAnimationFrame(r); - }); - } - }); - - // If any user input events were handled in the above 5 seconds - // the mouseDownPromise would be resolved with canHandleInput = false, - // so that the test would fail. - canHandleInput = true; - - // Ensure the events can be handled eventually - await BrowserTestUtils.synthesizeMouseAtPoint( - 10, - 10, - { type: "mousedown" }, - tab.linkedBrowser - ); - - await mouseDownPromise; - - BrowserTestUtils.removeTab(tab); -} - -add_task(async function test_MinRAF() { - const prefs = [ - ["dom.input_events.security.minNumTicks", 100], - ["dom.input_events.security.minTimeElapsedInMS", 0], - ["dom.input_events.security.isUserInputHandlingDelayTest", true], - ]; - - await test_user_input_handling_delay_helper(prefs); -}); - -add_task(async function test_MinElapsedTime() { - const prefs = [ - ["dom.input_events.security.minNumTicks", 0], - ["dom.input_events.security.minTimeElapsedInMS", 5000], - ["dom.input_events.security.isUserInputHandlingDelayTest", true], - ]; - - await test_user_input_handling_delay_helper(prefs); -}); diff --git a/dom/base/test/browser_user_input_handling_delay_aboutblank.js b/dom/base/test/browser_user_input_handling_delay_aboutblank.js deleted file mode 100644 index c49a9bf7ed9c..000000000000 --- a/dom/base/test/browser_user_input_handling_delay_aboutblank.js +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: JavaScript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -async function test_user_input_handling_delay_aboutblank_helper(prefs) { - await SpecialPowers.pushPrefEnv({ - set: prefs, - }); - - let newTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, "about:blank"); - - await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { - // Open about:blank - content.window.open(); - }); - - const tab = await newTabOpened; - - let mouseDownPromise = BrowserTestUtils.waitForContentEvent( - tab.linkedBrowser, - "mousedown" - ).then(function () { - Assert.ok(true, "about:blank can handle user input events anytime"); - }); - - // Now gBrowser.selectedBrowser is the newly opened about:blank - await BrowserTestUtils.synthesizeMouseAtPoint( - 10, - 10, - { type: "mousedown" }, - tab.linkedBrowser - ); - - await mouseDownPromise; - BrowserTestUtils.removeTab(tab); -} - -add_task(async function test_MinRAF_aboutblank() { - const prefs = [ - ["dom.input_events.security.minNumTicks", 100], - ["dom.input_events.security.minTimeElapsedInMS", 0], - ["dom.input_events.security.isUserInputHandlingDelayTest", true], - ]; - - await test_user_input_handling_delay_aboutblank_helper(prefs); -}); - -add_task(async function test_MinElapsedTime_aboutblank() { - const prefs = [ - ["dom.input_events.security.minNumTicks", 0], - ["dom.input_events.security.minTimeElapsedInMS", 5000], - ["dom.input_events.security.isUserInputHandlingDelayTest", true], - ]; - - await test_user_input_handling_delay_aboutblank_helper(prefs); -}); diff --git a/dom/base/test/browser_user_input_handling_delay_bfcache.js b/dom/base/test/browser_user_input_handling_delay_bfcache.js deleted file mode 100644 index a026e942105c..000000000000 --- a/dom/base/test/browser_user_input_handling_delay_bfcache.js +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: JavaScript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -async function test_user_input_handling_delay_BFCache_helper(prefs) { - await SpecialPowers.pushPrefEnv({ - set: prefs, - }); - - const tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - `data:text/html,`, - true - ); - - let switchAwayPromise = BrowserTestUtils.browserLoaded( - browser, - false, - "about:blank" - ); - // Navigate away to make the page enters BFCache - await SpecialPowers.spawn(tab.linkedBrowser, [], () => { - content.location = "about:blank"; - }); - await switchAwayPromise; - - // Navigate back to restore the page from BFCache - let pageShownPromise = BrowserTestUtils.waitForContentEvent( - tab.linkedBrowser, - "pageshow", - true - ); - - await SpecialPowers.spawn(tab.linkedBrowser, [], () => { - content.history.back(); - }); - - await pageShownPromise; - - let canHandleInput = false; - let mouseDownPromise = BrowserTestUtils.waitForContentEvent( - tab.linkedBrowser, - "mousedown" - ).then(function () { - Assert.ok( - canHandleInput, - "This promise should be resolved after the 5 seconds mark has passed" - ); - }); - // Ensure the events are discarded initially - for (let i = 0; i < 10; ++i) { - await BrowserTestUtils.synthesizeMouseAtPoint( - 10, - 10, - { type: "mousedown" }, - tab.linkedBrowser - ); - } - - // Wait for roughly 5 seconds to give chances for the - // above mousedown event to be handled. - await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { - for (let i = 0; i < 300; ++i) { - await new Promise(r => { - content.requestAnimationFrame(r); - }); - } - }); - - // If any user input events were handled in the above 5 seconds - // the mouseDownPromise would be resolved with canHandleInput = false, - // so that the test would fail. - canHandleInput = true; - - // Ensure the events can be handled eventually - await BrowserTestUtils.synthesizeMouseAtPoint( - 10, - 10, - { type: "mousedown" }, - tab.linkedBrowser - ); - - await mouseDownPromise; - BrowserTestUtils.removeTab(tab); -} - -add_task(async function test_MinRAF_BFCache() { - const prefs = [ - ["dom.input_events.security.minNumTicks", 100], - ["dom.input_events.security.minTimeElapsedInMS", 0], - ["dom.input_events.security.isUserInputHandlingDelayTest", true], - ]; - - await test_user_input_handling_delay_BFCache_helper(prefs); -}); - -add_task(async function test_MinElapsedTime_BFCache() { - const prefs = [ - ["dom.input_events.security.minNumTicks", 0], - ["dom.input_events.security.minTimeElapsedInMS", 5000], - ["dom.input_events.security.isUserInputHandlingDelayTest", true], - ]; - - await test_user_input_handling_delay_BFCache_helper(prefs); -}); diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index c0f5b19e6026..60059ca8e670 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -1983,27 +1983,6 @@ bool PresShell::SimpleResizeReflow(nscoord aWidth, nscoord aHeight) { return true; } -bool PresShell::CanHandleUserInputEvents(WidgetGUIEvent* aGUIEvent) { - if (XRE_IsParentProcess()) { - return true; - } - - if (aGUIEvent->mFlags.mIsSynthesizedForTests && - !StaticPrefs::dom_input_events_security_isUserInputHandlingDelayTest()) { - return true; - } - - if (!aGUIEvent->IsUserAction()) { - return true; - } - - if (nsPresContext* rootPresContext = mPresContext->GetRootPresContext()) { - return rootPresContext->UserInputEventsAllowed(); - } - - return true; -} - void PresShell::AddResizeEventFlushObserverIfNeeded() { if (!mIsDestroying && !mResizeEventPending && MOZ_LIKELY(!mDocument->GetBFCacheEntry())) { @@ -6901,17 +6880,6 @@ nsresult PresShell::HandleEvent(nsIFrame* aFrameForPresShell, aGUIEvent->AsMouseEvent()->mReason == WidgetMouseEvent::eSynthesized) { return NS_OK; } - - // Here we are granting some delays to ensure that user input events are - // created while the page content may not be visible to the user are not - // processed. - // The main purpose of this is to avoid user inputs are handled in the - // new document where as the user inputs were originally targeting some - // content in the old document. - if (!CanHandleUserInputEvents(aGUIEvent)) { - return NS_OK; - } - EventHandler eventHandler(*this); return eventHandler.HandleEvent(aFrameForPresShell, aGUIEvent, aDontRetargetEvents, aEventStatus); @@ -9334,10 +9302,6 @@ void PresShell::Freeze(bool aIncludeSubDocuments) { if (presContext->RefreshDriver()->GetPresContext() == presContext) { presContext->RefreshDriver()->Freeze(); } - - if (nsPresContext* rootPresContext = presContext->GetRootPresContext()) { - rootPresContext->ResetUserInputEventsAllowed(); - } } mFrozen = true; @@ -9396,16 +9360,6 @@ void PresShell::Thaw(bool aIncludeSubDocuments) { UpdateImageLockingState(); UnsuppressPainting(); - - // In case the above UnsuppressPainting call didn't start the - // refresh driver, we manually start the refresh driver to - // ensure nsPresContext::MaybeIncreaseMeasuredTicksSinceLoading - // can be called for user input events handling. - if (presContext && presContext->IsRoot()) { - if (!presContext->RefreshDriver()->HasPendingTick()) { - presContext->RefreshDriver()->InitializeTimer(); - } - } } //-------------------------------------------------------- diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index 07af3a7a2595..07784be4eca3 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -385,8 +385,6 @@ class PresShell final : public nsStubDocumentObserver, */ bool SimpleResizeReflow(nscoord aWidth, nscoord aHeight); - bool CanHandleUserInputEvents(WidgetGUIEvent* aGUIEvent); - public: /** * Updates pending layout, assuming reasonable (up-to-date, or mid-update for diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 951eaea0dab0..8230cc62576d 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -252,7 +252,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType) // mImageAnimationMode is initialised below, in constructor body mImageAnimationModePref(imgIContainer::kNormalAnimMode), mType(aType), - mMeasuredTicksSinceLoading(0), mInflationDisabledForShrinkWrap(false), mInteractionTimeEnabled(true), mHasPendingInterrupt(false), @@ -285,7 +284,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType) mHadFirstContentfulPaint(false), mHadNonTickContentfulPaint(false), mHadContentfulPaintComposite(false), - mUserInputEventsAllowed(false), #ifdef DEBUG mInitialized(false), #endif @@ -1237,69 +1235,6 @@ nsRootPresContext* nsPresContext::GetRootPresContext() const { return pc->IsRoot() ? static_cast(pc) : nullptr; } -bool nsPresContext::UserInputEventsAllowed() { - MOZ_ASSERT(IsRoot()); - if (mUserInputEventsAllowed) { - return true; - } - - // Special document - if (Document()->IsInitialDocument()) { - return true; - } - - if (mMeasuredTicksSinceLoading < - StaticPrefs::dom_input_events_security_minNumTicks()) { - return false; - } - - if (!StaticPrefs::dom_input_events_security_minTimeElapsedInMS()) { - return true; - } - - dom::Document* doc = Document(); - - MOZ_ASSERT_IF(StaticPrefs::dom_input_events_security_minNumTicks(), - doc->GetReadyStateEnum() >= Document::READYSTATE_LOADING); - - TimeStamp loadingOrRestoredFromBFCacheTime = - doc->GetLoadingOrRestoredFromBFCacheTimeStamp(); - MOZ_ASSERT(!loadingOrRestoredFromBFCacheTime.IsNull()); - - TimeDuration elapsed = TimeStamp::Now() - loadingOrRestoredFromBFCacheTime; - if (elapsed.ToMilliseconds() >= - StaticPrefs::dom_input_events_security_minTimeElapsedInMS()) { - mUserInputEventsAllowed = true; - return true; - } - - return false; -} - -void nsPresContext::MaybeIncreaseMeasuredTicksSinceLoading() { - MOZ_ASSERT(IsRoot()); - if (mMeasuredTicksSinceLoading >= - StaticPrefs::dom_input_events_security_minNumTicks()) { - return; - } - - // We consider READYSTATE_LOADING is the point when the page - // becomes interactive - if (Document()->GetReadyStateEnum() >= Document::READYSTATE_LOADING || - Document()->IsInitialDocument()) { - ++mMeasuredTicksSinceLoading; - } - - if (mMeasuredTicksSinceLoading < - StaticPrefs::dom_input_events_security_minNumTicks()) { - // Here we are forcing refresh driver to run because we can't always - // guarantee refresh driver will run enough times to meet the minNumTicks - // requirement. i.e. about:blank. - if (!RefreshDriver()->HasPendingTick()) { - RefreshDriver()->InitializeTimer(); - } - } -} // Helper function for setting Anim Mode on image static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, uint16_t aMode) { if (aImgReq) { diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index a21e09c8b6f3..d6f109a66f93 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -257,7 +257,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { */ nsRootPresContext* GetRootPresContext() const; - virtual bool IsRoot() const { return false; } + virtual bool IsRoot() { return false; } mozilla::dom::Document* Document() const { #ifdef DEBUG @@ -512,16 +512,6 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { nsDeviceContext* DeviceContext() const { return mDeviceContext; } mozilla::EventStateManager* EventStateManager() { return mEventManager; } - bool UserInputEventsAllowed(); - - void MaybeIncreaseMeasuredTicksSinceLoading(); - - void ResetUserInputEventsAllowed() { - MOZ_ASSERT(IsRoot()); - mMeasuredTicksSinceLoading = 0; - mUserInputEventsAllowed = false; - } - // Get the text zoom factor in use. float TextZoom() const { return mTextZoom; } @@ -1283,8 +1273,6 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { nsPresContextType mType; - uint32_t mMeasuredTicksSinceLoading; - public: // The following are public member variables so that we can use them // with mozilla::AutoToggle or mozilla::AutoRestore. @@ -1354,7 +1342,6 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { // Has NotifyDidPaintForSubtree been called for a contentful paint? unsigned mHadContentfulPaintComposite : 1; - unsigned mUserInputEventsAllowed : 1; #ifdef DEBUG unsigned mInitialized : 1; #endif @@ -1387,7 +1374,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { class nsRootPresContext final : public nsPresContext { public: nsRootPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType); - virtual bool IsRoot() const override { return true; } + virtual bool IsRoot() override { return true; } /** * Add a runnable that will get called before the next paint. They will get diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 0308e7497f69..b39954749c10 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -2149,12 +2149,6 @@ void nsRefreshDriver::FlushAutoFocusDocuments() { } } -void nsRefreshDriver::MaybeIncreaseMeasuredTicksSinceLoading() { - if (mPresContext && mPresContext->IsRoot()) { - mPresContext->MaybeIncreaseMeasuredTicksSinceLoading(); - } -} - void nsRefreshDriver::CancelFlushAutoFocus(Document* aDocument) { mAutoFocusFlushDocuments.RemoveElement(aDocument); } @@ -2599,7 +2593,6 @@ void nsRefreshDriver::Tick(VsyncId aId, TimeStamp aNowTime, DispatchAnimationEvents(); RunFullscreenSteps(); RunFrameRequestCallbacks(aNowTime); - MaybeIncreaseMeasuredTicksSinceLoading(); if (mPresContext && mPresContext->GetPresShell()) { AutoTArray observers; diff --git a/layout/base/nsRefreshDriver.h b/layout/base/nsRefreshDriver.h index 2de9d5f37b0e..84f7d3a2c683 100644 --- a/layout/base/nsRefreshDriver.h +++ b/layout/base/nsRefreshDriver.h @@ -486,7 +486,6 @@ class nsRefreshDriver final : public mozilla::layers::TransactionIdAllocator, void RunFrameRequestCallbacks(mozilla::TimeStamp aNowTime); void UpdateIntersectionObservations(mozilla::TimeStamp aNowTime); void UpdateRelevancyOfContentVisibilityAutoFrames(); - void MaybeIncreaseMeasuredTicksSinceLoading(); enum class IsExtraTick { No, diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 69e72c730e5d..66c24524aeb1 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -2812,27 +2812,6 @@ value: false mirror: always -# The minimum number of ticks after page navigation -# that need to occur before user input events are allowed to be handled. -- name: dom.input_events.security.minNumTicks - type: uint32_t - value: 3 - mirror: always - -# The minimum elapsed time (in milliseconds) after page navigation -# for user input events are allowed to be handled. -- name: dom.input_events.security.minTimeElapsedInMS - type: uint32_t - value: 100 - mirror: always - -# By default user input handling delay is disabled (mostly) for testing , -# this is used for forcefully enable it for certain tests. -- name: dom.input_events.security.isUserInputHandlingDelayTest - type: bool - value: false - mirror: always - # The maximum time (milliseconds) we reserve for handling input events in each # frame. - name: dom.input_event_queue.duration.max diff --git a/testing/profiles/base/user.js b/testing/profiles/base/user.js index ed25f8b1d150..20e22692c4cd 100644 --- a/testing/profiles/base/user.js +++ b/testing/profiles/base/user.js @@ -6,5 +6,3 @@ /* globals user_pref */ // ensure webrender is set (and we don't need MOZ_WEBRENDER env variable) user_pref("gfx.webrender.all", true); -user_pref("dom.input_events.security.minNumTicks", 0); -user_pref("dom.input_events.security.minTimeElapsedInMS", 0);