2015-04-09 20:25:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-04-07 00:54:09 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
Bug 1600545 - Remove useless inclusions of header files generated from IDL files in modules/, netwerk/, parser/, security/, startupcache/, storage/, toolkit/, tools/, uriloader/, widget/, xpcom/ and xpfe/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.
find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
if [ -n "$interfaces" ]; then
if [[ "$interfaces" == *$'\n'* ]]; then
regexp="\("
for i in $interfaces; do regexp="$regexp$i\|"; done
regexp="${regexp%%\\\|}\)"
else
regexp="$interfaces"
fi
interface=$(basename "$path")
rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
if [ $hits -eq 0 ]; then
echo "Removing ${interface} from ${path2}"
grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
mv -f "$path2".tmp "$path2"
fi
done
fi
done
Differential Revision: https://phabricator.services.mozilla.com/D55444
--HG--
extra : moz-landing-system : lando
2019-12-06 12:17:57 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2020-02-05 01:09:34 +03:00
|
|
|
#include "nsContentUtils.h"
|
2015-06-16 21:58:04 +03:00
|
|
|
#include "nsIConsoleService.h"
|
1999-04-07 00:54:09 +04:00
|
|
|
#include "nsIObserverService.h"
|
2005-11-30 21:51:27 +03:00
|
|
|
#include "nsIObserver.h"
|
2015-06-16 21:58:04 +03:00
|
|
|
#include "nsIScriptError.h"
|
1999-04-07 00:54:09 +04:00
|
|
|
#include "nsObserverService.h"
|
|
|
|
#include "nsObserverList.h"
|
2015-06-16 21:58:04 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2006-08-08 22:18:50 +04:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2015-04-11 04:25:58 +03:00
|
|
|
#include "xpcpublic.h"
|
2012-11-08 05:24:27 +04:00
|
|
|
#include "mozilla/net/NeckoCommon.h"
|
2018-11-12 13:04:17 +03:00
|
|
|
#include "mozilla/ResultExtensions.h"
|
2017-05-29 22:42:42 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsString.h"
|
2017-06-15 01:58:25 +03:00
|
|
|
#include "GeckoProfiler.h"
|
2001-10-20 06:07:33 +04:00
|
|
|
|
2017-05-29 22:42:42 +03:00
|
|
|
static const uint32_t kMinTelemetryNotifyObserversLatencyMs = 1;
|
|
|
|
|
2001-10-23 02:01:27 +04:00
|
|
|
// Log module for nsObserverService logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
2016-05-26 01:26:10 +03:00
|
|
|
// set MOZ_LOG=ObserverService:5
|
|
|
|
// set MOZ_LOG_FILE=service.log
|
2001-10-23 02:01:27 +04:00
|
|
|
//
|
2016-05-26 01:26:10 +03:00
|
|
|
// This enables LogLevel::Debug level information and places all output in
|
|
|
|
// the file service.log.
|
2015-10-19 22:50:14 +03:00
|
|
|
static mozilla::LazyLogModule sObserverServiceLog("ObserverService");
|
|
|
|
#define LOG(x) MOZ_LOG(sObserverServiceLog, mozilla::LogLevel::Debug, x)
|
1999-04-07 00:54:09 +04:00
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2015-07-10 02:49:32 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObserverService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData, bool aAnonymize) {
|
|
|
|
struct SuspectObserver {
|
|
|
|
SuspectObserver(const char* aTopic, size_t aReferentCount)
|
|
|
|
: mTopic(aTopic), mReferentCount(aReferentCount) {}
|
|
|
|
const char* mTopic;
|
|
|
|
size_t mReferentCount;
|
|
|
|
};
|
2014-07-09 19:15:21 +04:00
|
|
|
|
2015-07-13 01:55:27 +03:00
|
|
|
size_t totalNumStrong = 0;
|
|
|
|
size_t totalNumWeakAlive = 0;
|
|
|
|
size_t totalNumWeakDead = 0;
|
2015-07-10 02:49:32 +03:00
|
|
|
nsTArray<SuspectObserver> suspectObservers;
|
|
|
|
|
|
|
|
for (auto iter = mObserverTopicTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsObserverList* observerList = iter.Get();
|
|
|
|
if (!observerList) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
|
2015-07-13 01:55:27 +03:00
|
|
|
size_t topicNumStrong = 0;
|
|
|
|
size_t topicNumWeakAlive = 0;
|
|
|
|
size_t topicNumWeakDead = 0;
|
|
|
|
|
2018-11-12 13:04:17 +03:00
|
|
|
nsMaybeWeakPtrArray<nsIObserver>& observers = observerList->mObservers;
|
2015-07-10 02:49:32 +03:00
|
|
|
for (uint32_t i = 0; i < observers.Length(); i++) {
|
2018-11-12 13:04:17 +03:00
|
|
|
if (observers[i].IsWeak()) {
|
|
|
|
nsCOMPtr<nsIObserver> ref = observers[i].GetValue();
|
|
|
|
if (ref) {
|
2015-07-13 01:55:27 +03:00
|
|
|
topicNumWeakAlive++;
|
2015-07-10 02:49:32 +03:00
|
|
|
} else {
|
2015-07-13 01:55:27 +03:00
|
|
|
topicNumWeakDead++;
|
2015-07-10 02:49:32 +03:00
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
} else {
|
2015-07-13 01:55:27 +03:00
|
|
|
topicNumStrong++;
|
2014-07-09 19:15:21 +04:00
|
|
|
}
|
2013-08-26 22:56:23 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 01:55:27 +03:00
|
|
|
totalNumStrong += topicNumStrong;
|
|
|
|
totalNumWeakAlive += topicNumWeakAlive;
|
|
|
|
totalNumWeakDead += topicNumWeakDead;
|
|
|
|
|
2015-07-10 02:49:32 +03:00
|
|
|
// Keep track of topics that have a suspiciously large number
|
|
|
|
// of referents (symptom of leaks).
|
2015-07-13 01:55:27 +03:00
|
|
|
size_t topicTotal = topicNumStrong + topicNumWeakAlive + topicNumWeakDead;
|
|
|
|
if (topicTotal > kSuspectReferentCount) {
|
|
|
|
SuspectObserver suspect(observerList->GetKey(), topicTotal);
|
2015-07-10 02:49:32 +03:00
|
|
|
suspectObservers.AppendElement(suspect);
|
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
}
|
2013-08-26 22:56:23 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
// These aren't privacy-sensitive and so don't need anonymizing.
|
2015-07-10 02:49:32 +03:00
|
|
|
for (uint32_t i = 0; i < suspectObservers.Length(); i++) {
|
|
|
|
SuspectObserver& suspect = suspectObservers[i];
|
|
|
|
nsPrintfCString suspectPath("observer-service-suspect/referent(topic=%s)",
|
|
|
|
suspect.mTopic);
|
2016-08-24 08:23:45 +03:00
|
|
|
aHandleReport->Callback(
|
2015-07-10 02:49:32 +03:00
|
|
|
/* process */ EmptyCString(), suspectPath, KIND_OTHER, UNITS_COUNT,
|
|
|
|
suspect.mReferentCount,
|
2020-07-01 11:29:29 +03:00
|
|
|
nsLiteralCString("A topic with a suspiciously large number of "
|
|
|
|
"referents. This may be symptomatic of a leak "
|
|
|
|
"if the number of referents is high with "
|
|
|
|
"respect to the number of windows."),
|
2014-07-09 19:15:21 +04:00
|
|
|
aData);
|
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
MOZ_COLLECT_REPORT(
|
|
|
|
"observer-service/referent/strong", KIND_OTHER, UNITS_COUNT,
|
|
|
|
totalNumStrong,
|
|
|
|
"The number of strong references held by the observer service.");
|
|
|
|
|
|
|
|
MOZ_COLLECT_REPORT(
|
|
|
|
"observer-service/referent/weak/alive", KIND_OTHER, UNITS_COUNT,
|
|
|
|
totalNumWeakAlive,
|
|
|
|
"The number of weak references held by the observer service that are "
|
|
|
|
"still alive.");
|
|
|
|
|
|
|
|
MOZ_COLLECT_REPORT(
|
|
|
|
"observer-service/referent/weak/dead", KIND_OTHER, UNITS_COUNT,
|
|
|
|
totalNumWeakDead,
|
|
|
|
"The number of weak references held by the observer service that are "
|
|
|
|
"dead.");
|
2014-07-09 19:15:21 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2013-08-26 22:56:23 +04:00
|
|
|
}
|
|
|
|
|
1999-04-07 00:54:09 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsObserverService Implementation
|
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsObserverService, nsIObserverService, nsObserverService,
|
|
|
|
nsIMemoryReporter)
|
1999-04-07 00:54:09 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
nsObserverService::nsObserverService() : mShuttingDown(false) {}
|
1999-04-07 00:54:09 +04:00
|
|
|
|
|
|
|
nsObserverService::~nsObserverService(void) { Shutdown(); }
|
2006-03-21 17:43:56 +03:00
|
|
|
|
2013-08-26 22:56:23 +04:00
|
|
|
void nsObserverService::RegisterReporter() { RegisterWeakMemoryReporter(this); }
|
|
|
|
|
2006-03-21 17:43:56 +03:00
|
|
|
void nsObserverService::Shutdown() {
|
2018-11-12 13:04:17 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-26 22:56:23 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
mShuttingDown = true;
|
2018-11-12 13:04:17 +03:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2014-07-09 19:15:21 +04:00
|
|
|
mObserverTopicTable.Clear();
|
1999-04-07 00:54:09 +04:00
|
|
|
}
|
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
nsresult nsObserverService::Create(nsISupports* aOuter, const nsIID& aIID,
|
|
|
|
void** aInstancePtr) {
|
|
|
|
LOG(("nsObserverService::Create()"));
|
2001-10-23 02:01:27 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsObserverService> os = new nsObserverService();
|
2006-03-21 17:43:56 +03:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
// The memory reporter can not be immediately registered here because
|
|
|
|
// the nsMemoryReporterManager may attempt to get the nsObserverService
|
|
|
|
// during initialization, causing a recursive GetService.
|
2017-06-12 22:34:10 +03:00
|
|
|
NS_DispatchToCurrentThread(
|
|
|
|
NewRunnableMethod("nsObserverService::RegisterReporter", os,
|
|
|
|
&nsObserverService::RegisterReporter));
|
2013-08-26 22:56:23 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
return os->QueryInterface(aIID, aInstancePtr);
|
1999-07-30 11:58:55 +04:00
|
|
|
}
|
|
|
|
|
2018-11-12 13:04:17 +03:00
|
|
|
nsresult nsObserverService::EnsureValidCall() const {
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
MOZ_CRASH("Using observer service off the main thread!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2006-11-23 11:43:28 +03:00
|
|
|
|
2018-11-12 13:04:17 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
NS_ERROR("Using observer service after XPCOM shutdown!");
|
|
|
|
return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
|
2014-07-09 19:15:21 +04:00
|
|
|
}
|
1999-04-20 18:50:47 +04:00
|
|
|
|
2018-11-12 13:04:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsObserverService::FilterHttpOnTopics(const char* aTopic) {
|
2017-09-01 12:55:37 +03:00
|
|
|
// Specifically allow http-on-opening-request and http-on-stop-request in the
|
|
|
|
// child process; see bug 1269765.
|
2016-05-30 02:24:00 +03:00
|
|
|
if (mozilla::net::IsNeckoChild() && !strncmp(aTopic, "http-on-", 8) &&
|
2019-04-26 13:59:41 +03:00
|
|
|
strcmp(aTopic, "http-on-failed-opening-request") &&
|
2017-09-01 12:55:37 +03:00
|
|
|
strcmp(aTopic, "http-on-opening-request") &&
|
|
|
|
strcmp(aTopic, "http-on-stop-request")) {
|
2015-06-16 21:58:04 +03:00
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
nsCOMPtr<nsIScriptError> error(
|
|
|
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
2020-07-01 11:29:29 +03:00
|
|
|
error->Init(u"http-on-* observers only work in the parent process"_ns,
|
2015-06-16 21:58:04 +03:00
|
|
|
EmptyString(), EmptyString(), 0, 0, nsIScriptError::warningFlag,
|
2019-04-02 01:42:34 +03:00
|
|
|
"chrome javascript", false /* from private window */,
|
|
|
|
true /* from chrome context */);
|
2015-06-16 21:58:04 +03:00
|
|
|
console->LogMessage(error);
|
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2012-11-08 05:24:27 +04:00
|
|
|
|
2018-11-12 13:04:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObserverService::AddObserver(nsIObserver* aObserver, const char* aTopic,
|
|
|
|
bool aOwnsWeak) {
|
|
|
|
LOG(("nsObserverService::AddObserver(%p: %s, %s)", (void*)aObserver, aTopic,
|
|
|
|
aOwnsWeak ? "weak" : "strong"));
|
|
|
|
|
|
|
|
MOZ_TRY(EnsureValidCall());
|
|
|
|
if (NS_WARN_IF(!aObserver) || NS_WARN_IF(!aTopic)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_TRY(FilterHttpOnTopics(aTopic));
|
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
nsObserverList* observerList = mObserverTopicTable.PutEntry(aTopic);
|
|
|
|
if (!observerList) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2006-03-09 06:14:32 +03:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
return observerList->AddObserver(aObserver, aOwnsWeak);
|
1999-04-20 18:50:47 +04:00
|
|
|
}
|
|
|
|
|
2006-03-21 17:43:56 +03:00
|
|
|
NS_IMETHODIMP
|
2014-07-09 19:15:21 +04:00
|
|
|
nsObserverService::RemoveObserver(nsIObserver* aObserver, const char* aTopic) {
|
|
|
|
LOG(("nsObserverService::RemoveObserver(%p: %s)", (void*)aObserver, aTopic));
|
2018-11-12 13:04:17 +03:00
|
|
|
|
2019-03-06 11:55:35 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
// The service is shutting down. Let's ignore this call.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-12 13:04:17 +03:00
|
|
|
MOZ_TRY(EnsureValidCall());
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!aObserver) || NS_WARN_IF(!aTopic)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsObserverList* observerList = mObserverTopicTable.GetEntry(aTopic);
|
|
|
|
if (!observerList) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return observerList->RemoveObserver(aObserver);
|
2006-03-09 06:14:32 +03:00
|
|
|
}
|
|
|
|
|
2006-03-21 17:43:56 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObserverService::EnumerateObservers(const char* aTopic,
|
|
|
|
nsISimpleEnumerator** anEnumerator) {
|
2018-11-12 13:04:17 +03:00
|
|
|
LOG(("nsObserverService::EnumerateObservers(%s)", aTopic));
|
|
|
|
|
|
|
|
MOZ_TRY(EnsureValidCall());
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!anEnumerator) || NS_WARN_IF(!aTopic)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2006-03-09 06:14:32 +03:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
nsObserverList* observerList = mObserverTopicTable.GetEntry(aTopic);
|
|
|
|
if (!observerList) {
|
|
|
|
return NS_NewEmptyEnumerator(anEnumerator);
|
|
|
|
}
|
2006-03-09 06:14:32 +03:00
|
|
|
|
2016-04-28 10:11:17 +03:00
|
|
|
observerList->GetObserverList(anEnumerator);
|
|
|
|
return NS_OK;
|
1999-04-20 18:50:47 +04:00
|
|
|
}
|
1999-04-07 00:54:09 +04:00
|
|
|
|
1999-05-29 04:51:17 +04:00
|
|
|
// Enumerate observers of aTopic and call Observe on each.
|
2014-07-09 19:15:21 +04:00
|
|
|
NS_IMETHODIMP nsObserverService::NotifyObservers(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const char16_t* aSomeData) {
|
|
|
|
LOG(("nsObserverService::NotifyObservers(%s)", aTopic));
|
2006-11-23 11:43:28 +03:00
|
|
|
|
2018-11-12 13:04:17 +03:00
|
|
|
MOZ_TRY(EnsureValidCall());
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!aTopic)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2005-01-14 14:25:05 +03:00
|
|
|
|
2017-05-29 22:42:42 +03:00
|
|
|
mozilla::TimeStamp start = TimeStamp::Now();
|
|
|
|
|
2019-02-14 08:10:14 +03:00
|
|
|
AUTO_PROFILER_TEXT_MARKER_CAUSE("NotifyObservers", nsDependentCString(aTopic),
|
2020-01-20 21:53:09 +03:00
|
|
|
OTHER, Nothing(), profiler_get_backtrace());
|
2019-11-11 23:27:44 +03:00
|
|
|
AUTO_PROFILER_LABEL_DYNAMIC_CSTR_NONSENSITIVE(
|
|
|
|
"nsObserverService::NotifyObservers", OTHER, aTopic);
|
2017-06-15 01:58:25 +03:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
nsObserverList* observerList = mObserverTopicTable.GetEntry(aTopic);
|
|
|
|
if (observerList) {
|
|
|
|
observerList->NotifyObservers(aSubject, aTopic, aSomeData);
|
|
|
|
}
|
2006-03-04 17:04:05 +03:00
|
|
|
|
2017-05-29 22:42:42 +03:00
|
|
|
uint32_t latencyMs = round((TimeStamp::Now() - start).ToMilliseconds());
|
|
|
|
if (latencyMs >= kMinTelemetryNotifyObserversLatencyMs) {
|
|
|
|
Telemetry::Accumulate(Telemetry::NOTIFY_OBSERVERS_LATENCY_MS,
|
|
|
|
nsDependentCString(aTopic), latencyMs);
|
|
|
|
}
|
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
return NS_OK;
|
1999-05-29 04:51:17 +04:00
|
|
|
}
|
1999-04-07 00:54:09 +04:00
|
|
|
|
2012-04-30 23:01:11 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObserverService::UnmarkGrayStrongObservers() {
|
2018-11-12 13:04:17 +03:00
|
|
|
MOZ_TRY(EnsureValidCall());
|
2012-04-30 23:01:11 +04:00
|
|
|
|
2015-04-09 03:16:30 +03:00
|
|
|
nsCOMArray<nsIObserver> strongObservers;
|
2015-07-10 02:49:32 +03:00
|
|
|
for (auto iter = mObserverTopicTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsObserverList* aObserverList = iter.Get();
|
|
|
|
if (aObserverList) {
|
|
|
|
aObserverList->AppendStrongObservers(strongObservers);
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 03:16:30 +03:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < strongObservers.Length(); ++i) {
|
|
|
|
xpc_TryUnmarkWrappedGrayObject(strongObservers[i]);
|
|
|
|
}
|
2012-04-30 23:01:11 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
return NS_OK;
|
2012-04-30 23:01:11 +04:00
|
|
|
}
|
2020-02-05 01:09:34 +03:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class NotifyWhenScriptSafeRunnable : public mozilla::Runnable {
|
|
|
|
public:
|
|
|
|
NotifyWhenScriptSafeRunnable(nsIObserverService* aObs, nsISupports* aSubject,
|
|
|
|
const char* aTopic, const char16_t* aData)
|
|
|
|
: mozilla::Runnable("NotifyWhenScriptSafeRunnable"),
|
|
|
|
mObs(aObs),
|
|
|
|
mSubject(aSubject),
|
|
|
|
mTopic(aTopic) {
|
|
|
|
if (aData) {
|
|
|
|
mData.Assign(aData);
|
|
|
|
} else {
|
|
|
|
mData.SetIsVoid(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
const char16_t* data = mData.IsVoid() ? nullptr : mData.get();
|
|
|
|
return mObs->NotifyObservers(mSubject, mTopic.get(), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIObserverService> mObs;
|
|
|
|
nsCOMPtr<nsISupports> mSubject;
|
|
|
|
nsCString mTopic;
|
|
|
|
nsString mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
nsresult nsIObserverService::NotifyWhenScriptSafe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const char16_t* aData) {
|
|
|
|
if (nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
return NotifyObservers(aSubject, aTopic, aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentUtils::AddScriptRunner(MakeAndAddRef<NotifyWhenScriptSafeRunnable>(
|
|
|
|
this, aSubject, aTopic, aData));
|
|
|
|
return NS_OK;
|
|
|
|
}
|