mirror of
https://github.com/zen-browser/desktop.git
synced 2026-08-13 02:05:18 +00:00
no-bug: Make sure to clear memory on shutdown
This commit is contained in:
@@ -16,6 +16,16 @@ export class ZenBoostsParent extends JSWindowActorParent {
|
||||
"zen-boosts-disable-picker",
|
||||
];
|
||||
|
||||
// Topics the content child is allowed to forward to the observer service.
|
||||
// Anything outside this set is rejected to prevent content-triggered
|
||||
// notifications on unrelated chrome observers.
|
||||
static ALLOWED_NOTIFY_TOPICS = new Set([
|
||||
"zap-state-update",
|
||||
"zap-list-update",
|
||||
"selector-picker-state-update",
|
||||
"selector-picker-picked",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Creates a new ZenBoostsParent actor instance and sets up an observer
|
||||
* for boost update notifications.
|
||||
@@ -91,11 +101,14 @@ export class ZenBoostsParent extends JSWindowActorParent {
|
||||
break;
|
||||
}
|
||||
case "ZenBoost:Notify": {
|
||||
Services.obs.notifyObservers(
|
||||
null,
|
||||
message.data.topic,
|
||||
message.data.msg
|
||||
);
|
||||
const { topic, msg } = message.data ?? {};
|
||||
if (!ZenBoostsParent.ALLOWED_NOTIFY_TOPICS.has(topic)) {
|
||||
console.warn(
|
||||
`[ZenBoostsParent]: Rejected notify for disallowed topic: ${topic}`
|
||||
);
|
||||
break;
|
||||
}
|
||||
Services.obs.notifyObservers(null, topic, msg);
|
||||
break;
|
||||
}
|
||||
case "ZenBoost:ZapSelector": {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "nsIXULRuntime.h"
|
||||
#include "nsPresContext.h"
|
||||
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
#include "mozilla/ServoStyleConsts.h"
|
||||
@@ -266,17 +267,19 @@ inline static void GetZenBoostsDataFromBrowsingContext(
|
||||
|
||||
} // namespace
|
||||
|
||||
static mozilla::StaticAutoPtr<nsZenBoostsBackend> sZenBoostsBackend;
|
||||
|
||||
auto nsZenBoostsBackend::GetInstance() -> nsZenBoostsBackend* {
|
||||
static nsZenBoostsBackend* zenBoosts;
|
||||
if (!XRE_IsContentProcess()) {
|
||||
// Zen boosts are only supported in content, so if we're in the parent
|
||||
// process, just return null.
|
||||
return nullptr;
|
||||
}
|
||||
if (!zenBoosts) {
|
||||
zenBoosts = new nsZenBoostsBackend();
|
||||
if (!sZenBoostsBackend) {
|
||||
sZenBoostsBackend = new nsZenBoostsBackend();
|
||||
mozilla::ClearOnShutdown(&sZenBoostsBackend);
|
||||
}
|
||||
return zenBoosts;
|
||||
return sZenBoostsBackend.get();
|
||||
}
|
||||
|
||||
auto nsZenBoostsBackend::onPresShellEntered(mozilla::dom::Document* aDocument)
|
||||
@@ -284,12 +287,8 @@ auto nsZenBoostsBackend::onPresShellEntered(mozilla::dom::Document* aDocument)
|
||||
// Note that aDocument can be null when entering anonymous content frames.
|
||||
// We explicitly do this to prevent applying boosts to anonymous content, such
|
||||
// as devtools or screenshots.
|
||||
mozilla::dom::BrowsingContext* browsingContext =
|
||||
mCurrentBrowsingContext =
|
||||
aDocument ? aDocument->GetBrowsingContext() : nullptr;
|
||||
if (!browsingContext) {
|
||||
return;
|
||||
}
|
||||
mCurrentBrowsingContext = browsingContext;
|
||||
}
|
||||
|
||||
[[nodiscard]] ZEN_HOT_FUNCTION auto
|
||||
|
||||
@@ -25,6 +25,7 @@ struct nsZenAccentOklab {
|
||||
class nsZenBoostsBackend final {
|
||||
public:
|
||||
explicit nsZenBoostsBackend() = default;
|
||||
~nsZenBoostsBackend() = default;
|
||||
|
||||
/**
|
||||
* Indicates whether the current frame being rendered is for anonymous
|
||||
@@ -64,8 +65,6 @@ class nsZenBoostsBackend final {
|
||||
}
|
||||
|
||||
private:
|
||||
~nsZenBoostsBackend() = default;
|
||||
|
||||
/**
|
||||
* The presshell of the current document being rendered.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user