Bug 1593843 - part3 : store the request status in top-level browsing context. r=farre

If the page has already had same type pending request, then we don't want to send another request. If the page has already got the response from the request, we also don't want to send another request again.

In order to achieve that, we decide to store the request's staus on the top-browsing context to make sure that all media elements in the same browsing context tree can share the same status. Thereforw, we could avoid sending redudant request when there is a pending request, and reuse the previous request's result.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2019-11-25 11:00:13 +00:00
parent 1d93afb4e6
commit 9b3e1e1236
5 changed files with 57 additions and 0 deletions

View File

@ -43,6 +43,7 @@
#include "xpcprivate.h"
#include "AutoplayPolicy.h"
#include "GVAutoplayRequestStatusIPC.h"
extern mozilla::LazyLogModule gAutoplayPermissionLog;
@ -1229,6 +1230,26 @@ void BrowsingContext::StartDelayedAutoplayMediaComponents() {
mDocShell->StartDelayedAutoplayMediaComponents();
}
void BrowsingContext::ResetGVAutoplayRequestStatus() {
MOZ_ASSERT(!GetParent(),
"Should only set GVAudibleAutoplayRequestStatus in the top-level "
"browsing context");
SetGVAudibleAutoplayRequestStatus(GVAutoplayRequestStatus::eUNKNOWN);
SetGVInaudibleAutoplayRequestStatus(GVAutoplayRequestStatus::eUNKNOWN);
}
void BrowsingContext::DidSetGVAudibleAutoplayRequestStatus() {
MOZ_ASSERT(!GetParent(),
"Should only set GVAudibleAutoplayRequestStatus in the top-level "
"browsing context");
}
void BrowsingContext::DidSetGVInaudibleAutoplayRequestStatus() {
MOZ_ASSERT(!GetParent(),
"Should only set GVAudibleAutoplayRequestStatus in the top-level "
"browsing context");
}
void BrowsingContext::DidSetUserActivationState() {
MOZ_ASSERT_IF(!mIsInProcess, mUserGestureStart.IsNull());
USER_ACTIVATION_LOG("Set user gesture activation %" PRIu8

View File

@ -7,6 +7,7 @@
#ifndef mozilla_dom_BrowsingContext_h
#define mozilla_dom_BrowsingContext_h
#include "GVAutoplayRequestUtils.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Tuple.h"
@ -391,6 +392,8 @@ class BrowsingContext : public nsISupports,
void StartDelayedAutoplayMediaComponents();
void ResetGVAutoplayRequestStatus();
/**
* Transaction object. This object is used to specify and then commit
* modifications to synchronized fields in BrowsingContexts.
@ -553,6 +556,9 @@ class BrowsingContext : public nsISupports,
void DidSetIsPopupSpam();
void DidSetGVAudibleAutoplayRequestStatus();
void DidSetGVInaudibleAutoplayRequestStatus();
// Type of BrowsingContent
const Type mType;

View File

@ -46,4 +46,10 @@ MOZ_BC_FIELD(HistoryID, nsID)
MOZ_BC_FIELD(InRDMPane, bool)
// These field are used to store the states of autoplay media request on
// GeckoView only, and it would only be modified on the top level browsing
// context.
MOZ_BC_FIELD(GVAudibleAutoplayRequestStatus, GVAutoplayRequestStatus)
MOZ_BC_FIELD(GVInaudibleAutoplayRequestStatus, GVAutoplayRequestStatus)
#undef MOZ_BC_FIELD

View File

@ -0,0 +1,23 @@
/* 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 DOM_MEDIA_GVAUTOPLAYREQUESTSTATUSIPC_H_
#define DOM_MEDIA_GVAUTOPLAYREQUESTSTATUSIPC_H_
#include "ipc/IPCMessageUtils.h"
#include "GVAutoplayRequestUtils.h"
namespace IPC {
template <>
struct ParamTraits<mozilla::dom::GVAutoplayRequestStatus>
: public ContiguousEnumSerializerInclusive<
mozilla::dom::GVAutoplayRequestStatus,
mozilla::dom::GVAutoplayRequestStatus::eUNKNOWN,
mozilla::dom::GVAutoplayRequestStatus::ePENDING> {};
} // namespace IPC
#endif // DOM_MEDIA_GVAUTOPLAYREQUESTSTATUSIPC_H_

View File

@ -133,6 +133,7 @@ EXPORTS += [
'ForwardedInputTrack.h',
'FrameStatistics.h',
'GVAutoplayPermissionRequest.h',
'GVAutoplayRequestStatusIPC.h',
'GVAutoplayRequestUtils.h',
'ImageToI420.h',
'Intervals.h',