Skip to content

Commit c8f8d4b

Browse files
committed
Bug 1577499 - Part 1: Implement transient activation flag; r=smaug
whatwg/html#3851 Differential Revision: https://phabricator.services.mozilla.com/D44479
1 parent 6b1b71e commit c8f8d4b

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

docshell/base/BrowsingContext.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ void BrowsingContext::PrepareForProcessChange() {
384384
MOZ_ASSERT(!mIsDiscarded, "We're already closed?");
385385

386386
mIsInProcess = false;
387+
mUserGestureStart = TimeStamp();
387388

388389
// NOTE: For now, clear our nsDocShell reference, as we're primarily in a
389390
// different process now. This may need to change in the future with
@@ -696,14 +697,30 @@ JSObject* BrowsingContext::ReadStructuredClone(JSContext* aCx,
696697

697698
void BrowsingContext::NotifyUserGestureActivation() {
698699
SetIsActivatedByUserGesture(true);
699-
700-
// TODO: Bug 1577499 - Implement transient activation flag
701700
}
702701

703702
void BrowsingContext::NotifyResetUserGestureActivation() {
704703
SetIsActivatedByUserGesture(false);
704+
}
705+
706+
bool BrowsingContext::HasValidTransientUserGestureActivation() {
707+
MOZ_ASSERT(mIsInProcess);
708+
709+
if (!mIsActivatedByUserGesture) {
710+
MOZ_ASSERT(mUserGestureStart.IsNull(),
711+
"mUserGestureStart should be null if the document hasn't ever "
712+
"been activated by user gesture");
713+
return false;
714+
}
705715

706-
// TODO: Bug 1577499 - Implement transient activation flag
716+
MOZ_ASSERT(!mUserGestureStart.IsNull(),
717+
"mUserGestureStart shouldn't be null if the document has ever "
718+
"been activated by user gesture");
719+
TimeDuration timeout = TimeDuration::FromMilliseconds(
720+
StaticPrefs::dom_user_activation_transient_timeout());
721+
722+
return timeout <= TimeDuration() ||
723+
(TimeStamp::Now() - mUserGestureStart) <= timeout;
707724
}
708725

709726
NS_IMPL_CYCLE_COLLECTION_CLASS(BrowsingContext)
@@ -1040,10 +1057,18 @@ void BrowsingContext::StartDelayedAutoplayMediaComponents() {
10401057
}
10411058

10421059
void BrowsingContext::DidSetIsActivatedByUserGesture() {
1060+
MOZ_ASSERT_IF(!mIsInProcess, mUserGestureStart.IsNull());
10431061
USER_ACTIVATION_LOG(
10441062
"Set user gesture activation %d for %s browsing context 0x%08" PRIx64,
10451063
mIsActivatedByUserGesture, XRE_IsParentProcess() ? "Parent" : "Child",
10461064
Id());
1065+
if (mIsInProcess) {
1066+
USER_ACTIVATION_LOG(
1067+
"Set user gesture start time for %s browsing context 0x%08" PRIx64,
1068+
XRE_IsParentProcess() ? "Parent" : "Child", Id());
1069+
mUserGestureStart =
1070+
mIsActivatedByUserGesture ? TimeStamp::Now() : TimeStamp();
1071+
}
10471072
}
10481073

10491074
void BrowsingContext::DidSetMuted() {

docshell/base/BrowsingContext.h

+9
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
279279
// activation flag of the top level browsing context.
280280
void NotifyResetUserGestureActivation();
281281

282+
// Return true if its corresponding document has transient user gesture
283+
// activation and the transient user gesture activation haven't yet timed
284+
// out.
285+
bool HasValidTransientUserGestureActivation();
286+
282287
// Return the window proxy object that corresponds to this browsing context.
283288
inline JSObject* GetWindowProxy() const { return mWindowProxy; }
284289
// Set the window proxy object that corresponds to this browsing context.
@@ -551,6 +556,10 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
551556
// This is true if the BrowsingContext was out of process, but is now in
552557
// process, and might have remote window proxies that need to be cleaned up.
553558
bool mDanglingRemoteOuterProxies : 1;
559+
560+
// The start time of user gesture, this is only available if the browsing
561+
// context is in process.
562+
TimeStamp mUserGestureStart;
554563
};
555564

556565
/**

dom/events/EventStateManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ void EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
818818
}
819819

820820
Document* doc = node->OwnerDoc();
821-
if (!doc || doc->HasBeenUserGestureActivated()) {
821+
if (!doc) {
822822
return;
823823
}
824824

modules/libpref/init/StaticPrefList.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,12 @@
22932293
value: false
22942294
mirror: always
22952295

2296+
# Time limit, in milliseconds, for user gesture transient activation.
2297+
- name: dom.user_activation.transient.timeout
2298+
type: uint32_t
2299+
value: 5000
2300+
mirror: always
2301+
22962302
# Is support for Window.visualViewport enabled?
22972303
- name: dom.visualviewport.enabled
22982304
type: bool

0 commit comments

Comments
 (0)