зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1578355 - Part 2: Introduce UserActivation::State; r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D45344 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
5bc0854d2b
Коммит
6fd87e8695
|
@ -17,6 +17,7 @@
|
|||
#include "mozilla/dom/Location.h"
|
||||
#include "mozilla/dom/LocationBinding.h"
|
||||
#include "mozilla/dom/StructuredCloneTags.h"
|
||||
#include "mozilla/dom/UserActivationIPCUtils.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/WindowGlobalChild.h"
|
||||
#include "mozilla/dom/WindowGlobalParent.h"
|
||||
|
@ -696,17 +697,21 @@ JSObject* BrowsingContext::ReadStructuredClone(JSContext* aCx,
|
|||
}
|
||||
|
||||
void BrowsingContext::NotifyUserGestureActivation() {
|
||||
SetIsActivatedByUserGesture(true);
|
||||
SetUserActivationState(UserActivation::State::FullActivated);
|
||||
}
|
||||
|
||||
void BrowsingContext::NotifyResetUserGestureActivation() {
|
||||
SetIsActivatedByUserGesture(false);
|
||||
SetUserActivationState(UserActivation::State::None);
|
||||
}
|
||||
|
||||
bool BrowsingContext::HasBeenUserGestureActivated() {
|
||||
return mUserActivationState != UserActivation::State::None;
|
||||
}
|
||||
|
||||
bool BrowsingContext::HasValidTransientUserGestureActivation() {
|
||||
MOZ_ASSERT(mIsInProcess);
|
||||
|
||||
if (!mIsActivatedByUserGesture) {
|
||||
if (mUserActivationState != UserActivation::State::FullActivated) {
|
||||
MOZ_ASSERT(mUserGestureStart.IsNull(),
|
||||
"mUserGestureStart should be null if the document hasn't ever "
|
||||
"been activated by user gesture");
|
||||
|
@ -1068,18 +1073,20 @@ void BrowsingContext::StartDelayedAutoplayMediaComponents() {
|
|||
mDocShell->StartDelayedAutoplayMediaComponents();
|
||||
}
|
||||
|
||||
void BrowsingContext::DidSetIsActivatedByUserGesture() {
|
||||
void BrowsingContext::DidSetUserActivationState() {
|
||||
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());
|
||||
USER_ACTIVATION_LOG("Set user gesture activation %" PRIu8
|
||||
" for %s browsing context 0x%08" PRIx64,
|
||||
static_cast<uint8_t>(mUserActivationState),
|
||||
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();
|
||||
(mUserActivationState == UserActivation::State::FullActivated)
|
||||
? TimeStamp::Now()
|
||||
: TimeStamp();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "mozilla/WeakPtr.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/LocationBase.h"
|
||||
#include "mozilla/dom/UserActivation.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIDocShell.h"
|
||||
|
@ -279,6 +280,10 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
|
|||
// activation flag of the top level browsing context.
|
||||
void NotifyResetUserGestureActivation();
|
||||
|
||||
// Return true if its corresponding document has been activated by user
|
||||
// gesture.
|
||||
bool HasBeenUserGestureActivated();
|
||||
|
||||
// Return true if its corresponding document has transient user gesture
|
||||
// activation and the transient user gesture activation haven't yet timed
|
||||
// out.
|
||||
|
@ -503,8 +508,7 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Ensure that we only set the flag on the top level browsing context.
|
||||
void DidSetIsActivatedByUserGesture();
|
||||
void DidSetUserActivationState();
|
||||
|
||||
// Ensure that we only set the flag on the top level browsingContext.
|
||||
// And then, we do a pre-order walk in the tree to refresh the
|
||||
|
|
|
@ -23,9 +23,9 @@ MOZ_BC_FIELD(OnePermittedSandboxedNavigatorId, uint64_t)
|
|||
|
||||
MOZ_BC_FIELD(HadOriginalOpener, bool)
|
||||
|
||||
// Toplevel browsing contexts only. This field controls whether the browsing
|
||||
// context is currently considered to be activated by a gesture.
|
||||
MOZ_BC_FIELD(IsActivatedByUserGesture, bool)
|
||||
// This field controls whether the browsing context is currently considered to
|
||||
// be activated by a gesture.
|
||||
MOZ_BC_FIELD(UserActivationState, UserActivation::State)
|
||||
|
||||
// Hold the audio muted state and should be used
|
||||
// on top level browsing contexts only.
|
||||
|
|
|
@ -15015,7 +15015,7 @@ void Document::NotifyUserGestureActivation() {
|
|||
|
||||
bool Document::HasBeenUserGestureActivated() {
|
||||
RefPtr<BrowsingContext> bc = GetBrowsingContext();
|
||||
return bc ? bc->GetIsActivatedByUserGesture() : false;
|
||||
return bc && bc->HasBeenUserGestureActivated();
|
||||
}
|
||||
|
||||
void Document::ClearUserGestureActivation() {
|
||||
|
|
|
@ -14,6 +14,15 @@ namespace dom {
|
|||
|
||||
class UserActivation final {
|
||||
public:
|
||||
enum class State : uint8_t {
|
||||
// Not activated.
|
||||
None,
|
||||
// It is considered as has-been-activated, and also transient-activated if
|
||||
// haven't timed out.
|
||||
FullActivated,
|
||||
EndGuard_
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the current code is being executed as a result of
|
||||
* user input or keyboard input. The former includes anything that is
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/* -*- Mode: C++; 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/. */
|
||||
|
||||
#ifndef mozilla_dom_useractivation_ipc_utils_h__
|
||||
#define mozilla_dom_useractivation_ipc_utils_h__
|
||||
|
||||
#include "ipc/IPCMessageUtils.h"
|
||||
|
||||
// Undo X11/X.h's definition of None
|
||||
#undef None
|
||||
|
||||
#include "mozilla/dom/UserActivation.h"
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::UserActivation::State>
|
||||
: public ContiguousEnumSerializer<
|
||||
mozilla::dom::UserActivation::State,
|
||||
mozilla::dom::UserActivation::State::None,
|
||||
mozilla::dom::UserActivation::State::EndGuard_> {};
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_dom_useractivation_ipc_utils_h__
|
|
@ -66,6 +66,7 @@ EXPORTS.mozilla.dom += [
|
|||
'TabMessageUtils.h',
|
||||
'URLClassifierChild.h',
|
||||
'URLClassifierParent.h',
|
||||
'UserActivationIPCUtils.h',
|
||||
'WindowGlobalActor.h',
|
||||
'WindowGlobalChild.h',
|
||||
'WindowGlobalParent.h',
|
||||
|
|
Загрузка…
Ссылка в новой задаче