Bug 1513039 - part1 : remove caching temporary autoplay permission. r=smaug,florian

We're going to remove all autoplay temporary permission related codes, so we don't need to cache it anymore.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2019-01-07 18:29:10 +00:00
Родитель b05708ce89
Коммит 242554622e
8 изменённых файлов: 2 добавлений и 181 удалений

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

@ -64,7 +64,6 @@ const TemporaryPermissions = {
entry[prePath] = {};
}
entry[prePath][id] = {timeStamp: Date.now(), state};
this.notifyWhenTemporaryPermissionChanged(browser, id, prePath, state);
},
// Removes a permission with the specified id for the specified browser.
@ -76,7 +75,6 @@ const TemporaryPermissions = {
let prePath = browser.currentURI.prePath;
if (entry && entry[prePath]) {
delete entry[prePath][id];
this.notifyWhenTemporaryPermissionChanged(browser, id, prePath, SitePermissions.UNKNOWN);
}
},
@ -114,29 +112,11 @@ const TemporaryPermissions = {
return permissions;
},
// Gets all permissions ID for the specified browser, this method will return
// all permissions ID stored in browser without checking current URI.
getAllPermissionIds(browser) {
let permissions = new Set();
let entry = this._stateByBrowser.get(browser);
for (let prePath in entry) {
for (let id in entry[prePath]) {
permissions.add(id);
}
}
return permissions;
},
// Clears all permissions for the specified browser.
// Unlike other methods, this does NOT clear only for
// the currentURI but the whole browser state.
clear(browser) {
let permissions = this.getAllPermissionIds(browser);
this._stateByBrowser.delete(browser);
for (let permission of permissions) {
this.notifyWhenTemporaryPermissionChanged(browser, permission, null,
SitePermissions.UNKNOWN);
}
},
// Copies the temporary permission state of one browser
@ -147,20 +127,6 @@ const TemporaryPermissions = {
this._stateByBrowser.set(newBrowser, entry);
}
},
// If permission has property 'notifyWhenTemporaryPermissionChanged', then
// notify browser when the temporary permission changed.
notifyWhenTemporaryPermissionChanged(browser, id, prePath, state) {
if (!(id in gPermissionObject) ||
!gPermissionObject[id].notifyWhenTemporaryPermissionChanged) {
return;
}
browser.messageManager
.sendAsyncMessage("TemporaryPermissionChanged",
{ permission: id,
prePath,
state });
},
};
// This hold a flag per browser to indicate whether we should show the
@ -747,7 +713,6 @@ var gPermissionObject = {
"autoplay-media": {
exactHostMatch: true,
permitTemporaryAllow: true,
notifyWhenTemporaryPermissionChanged: true,
getDefault() {
let state = Services.prefs.getIntPref("media.autoplay.default",
Ci.nsIAutoplay.PROMPT);

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

@ -3988,36 +3988,6 @@ nsDOMWindowUtils::ResetPrefersReducedMotionOverrideForTest() {
return widget->ResetPrefersReducedMotionOverrideForTest();
}
NS_IMETHODIMP
nsDOMWindowUtils::NotifyTemporaryAutoplayPermissionChanged(
int32_t aState, const nsAString& aPrePath) {
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
nsCOMPtr<nsPIDOMWindowOuter> topWindow = window->GetScriptableTop();
if (!topWindow) {
return NS_OK;
}
topWindow->NotifyTemporaryAutoplayPermissionChanged(aState, aPrePath);
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::IsAutoplayTemporarilyAllowed(bool* aResult) {
*aResult = false;
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
nsCOMPtr<nsPIDOMWindowOuter> topWindow = window->GetScriptableTop();
if (!topWindow) {
return NS_OK;
}
*aResult = topWindow->HasTemporaryAutoplayPermission();
return NS_OK;
}
NS_INTERFACE_MAP_BEGIN(nsTranslationNodeList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsITranslationNodeList)

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

@ -252,8 +252,6 @@
#include "mozilla/dom/SpeechSynthesis.h"
#endif
#include "mozilla/HashFunctions.h"
// Apple system headers seem to have a check() macro. <sigh>
#ifdef check
class nsIScriptTimeoutHandler;
@ -322,11 +320,6 @@ static int32_t gOpenPopupSpamCount = 0;
nsGlobalWindowOuter::OuterWindowByIdTable*
nsGlobalWindowOuter::sOuterWindowsById = nullptr;
extern mozilla::LazyLogModule gAutoplayPermissionLog;
#define AUTOPLAY_LOG(msg, ...) \
MOZ_LOG(gAutoplayPermissionLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
/* static */
nsPIDOMWindowOuter* nsPIDOMWindowOuter::GetFromCurrentInner(
nsPIDOMWindowInner* aInner) {
@ -7379,68 +7372,6 @@ nsIURI* nsPIDOMWindowOuter::GetDocumentURI() const {
return mDoc ? mDoc->GetDocumentURI() : mDocumentURI.get();
}
void nsPIDOMWindowOuter::NotifyTemporaryAutoplayPermissionChanged(
int32_t aState, const nsAString& aPrePath) {
MOZ_ASSERT(int32_t(nsIPermissionManager::ALLOW_ACTION) ==
int32_t(nsIDOMWindowUtils::PERMISSION_ALLOW) &&
int32_t(nsIPermissionManager::DENY_ACTION) ==
int32_t(nsIDOMWindowUtils::PERMISSION_DENY) &&
int32_t(nsIPermissionManager::UNKNOWN_ACTION) ==
int32_t(nsIDOMWindowUtils::PERMISSION_UNKNOWN));
bool isAllowed = aState == nsIDOMWindowUtils::PERMISSION_ALLOW;
switch (aState) {
case nsIDOMWindowUtils::PERMISSION_ALLOW:
case nsIDOMWindowUtils::PERMISSION_DENY:
AUTOPLAY_LOG("update temporary autoplay permission");
mAutoplayTemporaryPermission.Put(
aPrePath, PermissionInfo(isAllowed, TimeStamp::Now()));
break;
case nsIDOMWindowUtils::PERMISSION_UNKNOWN:
if (!aPrePath.Length()) {
AUTOPLAY_LOG("remove temporary autoplay permission for all domains");
mAutoplayTemporaryPermission.Clear();
} else {
AUTOPLAY_LOG("remove temporary autoplay permission");
mAutoplayTemporaryPermission.Remove(aPrePath);
}
break;
default:
AUTOPLAY_LOG("ERROR! non-defined permission state!");
}
}
bool nsPIDOMWindowOuter::HasTemporaryAutoplayPermission() {
if (!mDoc) {
return false;
}
nsIPrincipal* principal = mDoc->NodePrincipal();
if (!principal) {
return false;
}
nsCOMPtr<nsIURI> URI;
nsresult rv = principal->GetURI(getter_AddRefs(URI));
if (NS_FAILED(rv) || !URI) {
return false;
}
nsAutoCString prePath;
URI->GetPrePath(prePath);
NS_ConvertUTF8toUTF16 key(prePath);
PermissionInfo info = mAutoplayTemporaryPermission.Get(key);
int32_t expireTime = Preferences::GetInt(
"privacy.temporary_permission_expire_time_ms", 3600 * 1000);
if (info.first && TimeStamp::Now() - info.second >=
TimeDuration::FromMilliseconds(expireTime)) {
AUTOPLAY_LOG("remove expired temporary autoplay permission");
mAutoplayTemporaryPermission.Remove(key);
return false;
}
return info.first;
}
void nsPIDOMWindowOuter::MaybeCreateDoc() {
MOZ_ASSERT(!mDoc);
if (nsIDocShell* docShell = GetDocShell()) {

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

@ -11,11 +11,9 @@
#include "mozIDOMWindow.h"
#include "nsCOMPtr.h"
#include "nsDataHashtable.h"
#include "nsTArray.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/TimeStamp.h"
#include "js/TypeDecls.h"
#include "nsRefPtrHashtable.h"
@ -789,13 +787,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
virtual void ActivateOrDeactivate(bool aActivate) = 0;
/**
* These functions are used to modify and check temporary autoplay permission.
*/
void NotifyTemporaryAutoplayPermissionChanged(int32_t aState,
const nsAString& aPrePath);
bool HasTemporaryAutoplayPermission();
/**
* |top| gets the root of the window hierarchy.
*
@ -1190,9 +1181,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
mozilla::dom::LargeAllocStatus mLargeAllocStatus;
RefPtr<mozilla::dom::BrowsingContext> mOpenerForInitialContentBrowser;
using PermissionInfo = std::pair<bool, mozilla::TimeStamp>;
nsDataHashtable<nsStringHashKey, PermissionInfo> mAutoplayTemporaryPermission;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowOuter, NS_PIDOMWINDOWOUTER_IID)

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

@ -830,9 +830,9 @@ interface nsIDOMWindowUtils : nsISupports {
/**
* Returns the offset of the window's visual viewport relative to the
* layout viewport.
* layout viewport.
*/
void getVisualViewportOffsetRelativeToLayoutViewport(out float aOffsetX,
void getVisualViewportOffsetRelativeToLayoutViewport(out float aOffsetX,
out float aOffsetY);
const long FLUSH_NONE = -1;
@ -1933,23 +1933,6 @@ interface nsIDOMWindowUtils : nsISupports {
*/
void resetPrefersReducedMotionOverrideForTest();
/**
* Used to notify temporary autoplay permission change and cache it on the dom
* window. These states are equal to nsIPermissionManager's action states.
*/
const long PERMISSION_UNKNOWN = 0;
const long PERMISSION_ALLOW = 1;
const long PERMISSION_DENY = 2;
void notifyTemporaryAutoplayPermissionChanged(in long aState,
in AString aPrePath);
/**
* Used to check whether the window temporarily allows autoplay for current
* domain.
*/
bool isAutoplayTemporarilyAllowed();
// These consts are only for testing purposes.
const long DEFAULT_MOUSE_POINTER_ID = 0;
const long DEFAULT_PEN_POINTER_ID = 1;

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

@ -87,13 +87,6 @@ static bool IsWindowAllowedToPlay(nsPIDOMWindowInner* aWindow) {
return false;
}
nsCOMPtr<nsPIDOMWindowOuter> topWindow = aWindow->GetScriptableTop();
if (topWindow && topWindow->HasTemporaryAutoplayPermission()) {
AUTOPLAY_LOG(
"Allow autoplay as document has temporary autoplay permission.");
return true;
}
Document* approver = ApproverDocOf(*aWindow->GetExtantDoc());
if (!approver) {
return false;

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

@ -69,14 +69,6 @@ class AudioPlaybackChild extends ActorChild {
case "AudioPlayback":
this.handleMediaControlMessage(data.type);
break;
case "TemporaryPermissionChanged":
if (data.permission !== "autoplay-media") {
return;
}
let utils = this.content.windowUtils;
utils.notifyTemporaryAutoplayPermissionChanged(data.state,
data.prePath);
break;
}
}
}

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

@ -106,7 +106,6 @@ let ACTORS = {
module: "resource://gre/actors/AudioPlaybackChild.jsm",
messages: [
"AudioPlayback",
"TemporaryPermissionChanged",
],
observers: [
"audio-playback",