@@ -384,6 +384,7 @@ void BrowsingContext::PrepareForProcessChange() {
384
384
MOZ_ASSERT (!mIsDiscarded , " We're already closed?" );
385
385
386
386
mIsInProcess = false ;
387
+ mUserGestureStart = TimeStamp ();
387
388
388
389
// NOTE: For now, clear our nsDocShell reference, as we're primarily in a
389
390
// different process now. This may need to change in the future with
@@ -696,14 +697,30 @@ JSObject* BrowsingContext::ReadStructuredClone(JSContext* aCx,
696
697
697
698
void BrowsingContext::NotifyUserGestureActivation () {
698
699
SetIsActivatedByUserGesture (true );
699
-
700
- // TODO: Bug 1577499 - Implement transient activation flag
701
700
}
702
701
703
702
void BrowsingContext::NotifyResetUserGestureActivation () {
704
703
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
+ }
705
715
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;
707
724
}
708
725
709
726
NS_IMPL_CYCLE_COLLECTION_CLASS (BrowsingContext)
@@ -1040,10 +1057,18 @@ void BrowsingContext::StartDelayedAutoplayMediaComponents() {
1040
1057
}
1041
1058
1042
1059
void BrowsingContext::DidSetIsActivatedByUserGesture () {
1060
+ MOZ_ASSERT_IF (!mIsInProcess , mUserGestureStart .IsNull ());
1043
1061
USER_ACTIVATION_LOG (
1044
1062
" Set user gesture activation %d for %s browsing context 0x%08" PRIx64,
1045
1063
mIsActivatedByUserGesture , XRE_IsParentProcess () ? " Parent" : " Child" ,
1046
1064
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
+ }
1047
1072
}
1048
1073
1049
1074
void BrowsingContext::DidSetMuted () {
0 commit comments