Bug 1430317: Add memory reporter to show basic information about active WebExtensions. r=erahm
MozReview-Commit-ID: FR8F30bhhA4
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ResultExtensions.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
@@ -67,6 +68,7 @@ ExtensionPolicyService::GetSingleton()
|
||||
|
||||
if (MOZ_UNLIKELY(!sExtensionPolicyService)) {
|
||||
sExtensionPolicyService = new ExtensionPolicyService();
|
||||
RegisterWeakMemoryReporter(sExtensionPolicyService);
|
||||
ClearOnShutdown(&sExtensionPolicyService);
|
||||
}
|
||||
return *sExtensionPolicyService.get();
|
||||
@@ -82,6 +84,11 @@ ExtensionPolicyService::ExtensionPolicyService()
|
||||
RegisterObservers();
|
||||
}
|
||||
|
||||
ExtensionPolicyService::~ExtensionPolicyService()
|
||||
{
|
||||
UnregisterWeakMemoryReporter(this);
|
||||
}
|
||||
|
||||
bool
|
||||
ExtensionPolicyService::UseRemoteExtensions() const
|
||||
{
|
||||
@@ -174,6 +181,45 @@ ExtensionPolicyService::DefaultCSP(nsAString& aDefaultCSP) const
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* nsIMemoryReporter
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMETHODIMP
|
||||
ExtensionPolicyService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize)
|
||||
{
|
||||
for (auto iter = mExtensions.Iter(); !iter.Done(); iter.Next()) {
|
||||
auto& ext = iter.Data();
|
||||
|
||||
nsAtomCString id(ext->Id());
|
||||
|
||||
NS_ConvertUTF16toUTF8 name(ext->Name());
|
||||
name.ReplaceSubstring("\"", "");
|
||||
name.ReplaceSubstring("\\", "");
|
||||
|
||||
nsString url;
|
||||
MOZ_TRY_VAR(url, ext->GetURL(NS_LITERAL_STRING("")));
|
||||
|
||||
nsPrintfCString desc("Extension(id=%s, name=\"%s\", baseURL=%s)",
|
||||
id.get(), name.get(),
|
||||
NS_ConvertUTF16toUTF8(url).get());
|
||||
desc.ReplaceChar('/', '\\');
|
||||
|
||||
nsCString path("extensions/");
|
||||
path.Append(desc);
|
||||
|
||||
aHandleReport->Callback(
|
||||
EmptyCString(), path,
|
||||
KIND_NONHEAP, UNITS_COUNT, 1,
|
||||
NS_LITERAL_CSTRING("WebExtensions that are active in this session"),
|
||||
aData);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Content script management
|
||||
*****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user