Bug 1577499 - Part 1: Implement transient activation flag; r=smaug

https://github.com/whatwg/html/pull/3851

Differential Revision: https://phabricator.services.mozilla.com/D44479

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edgar Chen 2019-09-07 19:12:20 +00:00
Родитель 3e8ba858e5
Коммит 2d3cc9c52b
4 изменённых файлов: 44 добавлений и 4 удалений

Просмотреть файл

@ -384,6 +384,7 @@ void BrowsingContext::PrepareForProcessChange() {
MOZ_ASSERT(!mIsDiscarded, "We're already closed?");
mIsInProcess = false;
mUserGestureStart = TimeStamp();
// NOTE: For now, clear our nsDocShell reference, as we're primarily in a
// different process now. This may need to change in the future with
@ -696,14 +697,30 @@ JSObject* BrowsingContext::ReadStructuredClone(JSContext* aCx,
void BrowsingContext::NotifyUserGestureActivation() {
SetIsActivatedByUserGesture(true);
// TODO: Bug 1577499 - Implement transient activation flag
}
void BrowsingContext::NotifyResetUserGestureActivation() {
SetIsActivatedByUserGesture(false);
}
// TODO: Bug 1577499 - Implement transient activation flag
bool BrowsingContext::HasValidTransientUserGestureActivation() {
MOZ_ASSERT(mIsInProcess);
if (!mIsActivatedByUserGesture) {
MOZ_ASSERT(mUserGestureStart.IsNull(),
"mUserGestureStart should be null if the document hasn't ever "
"been activated by user gesture");
return false;
}
MOZ_ASSERT(!mUserGestureStart.IsNull(),
"mUserGestureStart shouldn't be null if the document has ever "
"been activated by user gesture");
TimeDuration timeout = TimeDuration::FromMilliseconds(
StaticPrefs::dom_user_activation_transient_timeout());
return timeout <= TimeDuration() ||
(TimeStamp::Now() - mUserGestureStart) <= timeout;
}
NS_IMPL_CYCLE_COLLECTION_CLASS(BrowsingContext)
@ -1040,10 +1057,18 @@ void BrowsingContext::StartDelayedAutoplayMediaComponents() {
}
void BrowsingContext::DidSetIsActivatedByUserGesture() {
MOZ_ASSERT_IF(!mIsInProcess, mUserGestureStart.IsNull());
USER_ACTIVATION_LOG(
"Set user gesture activation %d for %s browsing context 0x%08" PRIx64,
mIsActivatedByUserGesture, XRE_IsParentProcess() ? "Parent" : "Child",
Id());
if (mIsInProcess) {
USER_ACTIVATION_LOG(
"Set user gesture start time for %s browsing context 0x%08" PRIx64,
XRE_IsParentProcess() ? "Parent" : "Child", Id());
mUserGestureStart =
mIsActivatedByUserGesture ? TimeStamp::Now() : TimeStamp();
}
}
void BrowsingContext::DidSetMuted() {

Просмотреть файл

@ -279,6 +279,11 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
// activation flag of the top level browsing context.
void NotifyResetUserGestureActivation();
// Return true if its corresponding document has transient user gesture
// activation and the transient user gesture activation haven't yet timed
// out.
bool HasValidTransientUserGestureActivation();
// Return the window proxy object that corresponds to this browsing context.
inline JSObject* GetWindowProxy() const { return mWindowProxy; }
// Set the window proxy object that corresponds to this browsing context.
@ -551,6 +556,10 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
// This is true if the BrowsingContext was out of process, but is now in
// process, and might have remote window proxies that need to be cleaned up.
bool mDanglingRemoteOuterProxies : 1;
// The start time of user gesture, this is only available if the browsing
// context is in process.
TimeStamp mUserGestureStart;
};
/**

Просмотреть файл

@ -818,7 +818,7 @@ void EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
}
Document* doc = node->OwnerDoc();
if (!doc || doc->HasBeenUserGestureActivated()) {
if (!doc) {
return;
}

Просмотреть файл

@ -2293,6 +2293,12 @@
value: false
mirror: always
# Time limit, in milliseconds, for user gesture transient activation.
- name: dom.user_activation.transient.timeout
type: uint32_t
value: 5000
mirror: always
# Is support for Window.visualViewport enabled?
- name: dom.visualviewport.enabled
type: bool