From 242554622ee34a864627458f60851bb614928ad8 Mon Sep 17 00:00:00 2001 From: alwu Date: Mon, 7 Jan 2019 18:29:10 +0000 Subject: [PATCH] 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 --- browser/modules/SitePermissions.jsm | 35 ------------ dom/base/nsDOMWindowUtils.cpp | 30 ---------- dom/base/nsGlobalWindowOuter.cpp | 69 ----------------------- dom/base/nsPIDOMWindow.h | 12 ---- dom/interfaces/base/nsIDOMWindowUtils.idl | 21 +------ dom/media/AutoplayPolicy.cpp | 7 --- toolkit/actors/AudioPlaybackChild.jsm | 8 --- toolkit/modules/ActorManagerParent.jsm | 1 - 8 files changed, 2 insertions(+), 181 deletions(-) diff --git a/browser/modules/SitePermissions.jsm b/browser/modules/SitePermissions.jsm index 582566001dba..a223f0c0a8d2 100644 --- a/browser/modules/SitePermissions.jsm +++ b/browser/modules/SitePermissions.jsm @@ -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); diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 022b0f4bcd71..8e883816549f 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -3988,36 +3988,6 @@ nsDOMWindowUtils::ResetPrefersReducedMotionOverrideForTest() { return widget->ResetPrefersReducedMotionOverrideForTest(); } -NS_IMETHODIMP -nsDOMWindowUtils::NotifyTemporaryAutoplayPermissionChanged( - int32_t aState, const nsAString& aPrePath) { - nsCOMPtr window = do_QueryReferent(mWindow); - NS_ENSURE_STATE(window); - - nsCOMPtr topWindow = window->GetScriptableTop(); - if (!topWindow) { - return NS_OK; - } - - topWindow->NotifyTemporaryAutoplayPermissionChanged(aState, aPrePath); - return NS_OK; -} - -NS_IMETHODIMP -nsDOMWindowUtils::IsAutoplayTemporarilyAllowed(bool* aResult) { - *aResult = false; - nsCOMPtr window = do_QueryReferent(mWindow); - NS_ENSURE_STATE(window); - - nsCOMPtr 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) diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index f182ce5498ab..186675e04565 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -252,8 +252,6 @@ #include "mozilla/dom/SpeechSynthesis.h" #endif -#include "mozilla/HashFunctions.h" - // Apple system headers seem to have a check() macro. #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 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()) { diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 13b944ec1b88..e7d2dfa61477 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -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 mOpenerForInitialContentBrowser; - - using PermissionInfo = std::pair; - nsDataHashtable mAutoplayTemporaryPermission; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowOuter, NS_PIDOMWINDOWOUTER_IID) diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 77d07cca5417..6f2338f5337a 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -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; diff --git a/dom/media/AutoplayPolicy.cpp b/dom/media/AutoplayPolicy.cpp index 103fd1ca6569..9c53b4e6e678 100644 --- a/dom/media/AutoplayPolicy.cpp +++ b/dom/media/AutoplayPolicy.cpp @@ -87,13 +87,6 @@ static bool IsWindowAllowedToPlay(nsPIDOMWindowInner* aWindow) { return false; } - nsCOMPtr 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; diff --git a/toolkit/actors/AudioPlaybackChild.jsm b/toolkit/actors/AudioPlaybackChild.jsm index 78541da6f67f..458aba62157e 100644 --- a/toolkit/actors/AudioPlaybackChild.jsm +++ b/toolkit/actors/AudioPlaybackChild.jsm @@ -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; } } } diff --git a/toolkit/modules/ActorManagerParent.jsm b/toolkit/modules/ActorManagerParent.jsm index 23aa7ce5ccb3..7b88e6878af2 100644 --- a/toolkit/modules/ActorManagerParent.jsm +++ b/toolkit/modules/ActorManagerParent.jsm @@ -106,7 +106,6 @@ let ACTORS = { module: "resource://gre/actors/AudioPlaybackChild.jsm", messages: [ "AudioPlayback", - "TemporaryPermissionChanged", ], observers: [ "audio-playback",