Merge mozilla-central to autoland. a=merge CLOSED TREE

This commit is contained in:
Ciure Andrei 2018-07-05 12:53:31 +03:00
Родитель 33b95c3973 2198f99f97
Коммит 647372a88b
68 изменённых файлов: 792 добавлений и 308 удалений

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

@ -42,7 +42,6 @@ const whitelist = {
"resource://gre/modules/XPCOMUtils.jsm",
// Logging related
"resource://gre/modules/Console.jsm", // bug 1470333
"resource://gre/modules/Log.jsm",
// Session store

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

@ -98,7 +98,7 @@ AutofillProfileAutoCompleteSearch.prototype = {
let {activeInput, activeSection, activeFieldDetail, savedFieldNames} = FormAutofillContent;
this.forceStop = false;
this.log.debug("startSearch: for", searchString, "with input", activeInput);
this.debug("startSearch: for", searchString, "with input", activeInput);
let isAddressField = FormAutofillUtils.isAddressField(activeFieldDetail.fieldName);
let isInputAutofilled = activeFieldDetail.state == FIELD_STATES.AUTO_FILLED;
@ -196,7 +196,7 @@ AutofillProfileAutoCompleteSearch.prototype = {
* Promise that resolves when addresses returned from parent process.
*/
_getRecords(data) {
this.log.debug("_getRecords with data:", data);
this.debug("_getRecords with data:", data);
return new Promise((resolve) => {
Services.cpmm.addMessageListener("FormAutofill:Records", function getResult(result) {
Services.cpmm.removeMessageListener("FormAutofill:Records", getResult);
@ -222,7 +222,7 @@ let ProfileAutocomplete = {
}
FormAutofillUtils.defineLazyLogGetter(this, "ProfileAutocomplete");
this.log.debug("ensureRegistered");
this.debug("ensureRegistered");
this._factory = new AutocompleteFactory();
this._factory.register(AutofillProfileAutoCompleteSearch);
this._registered = true;
@ -235,7 +235,7 @@ let ProfileAutocomplete = {
return;
}
this.log.debug("ensureUnregistered");
this.debug("ensureUnregistered");
this._factory.unregister();
this._factory = null;
this._registered = false;
@ -275,7 +275,7 @@ let ProfileAutocomplete = {
},
_fillFromAutocompleteRow(focusedInput) {
this.log.debug("_fillFromAutocompleteRow:", focusedInput);
this.debug("_fillFromAutocompleteRow:", focusedInput);
let formDetails = FormAutofillContent.activeFormDetails;
if (!formDetails) {
// The observer notification is for a different frame.
@ -388,21 +388,21 @@ var FormAutofillContent = {
*/
notify(formElement, domWin) {
try {
this.log.debug("Notifying form early submission");
this.debug("Notifying form early submission");
if (!FormAutofillUtils.isAutofillEnabled) {
this.log.debug("Form Autofill is disabled");
this.debug("Form Autofill is disabled");
return true;
}
if (domWin && PrivateBrowsingUtils.isContentWindowPrivate(domWin)) {
this.log.debug("Ignoring submission in a private window");
this.debug("Ignoring submission in a private window");
return true;
}
let handler = this._formsDetails.get(formElement);
if (!handler) {
this.log.debug("Form element could not map to an existing handler");
this.debug("Form element could not map to an existing handler");
return true;
}
@ -530,10 +530,10 @@ var FormAutofillContent = {
},
identifyAutofillFields(element) {
this.log.debug("identifyAutofillFields:", "" + element.ownerDocument.location);
this.debug("identifyAutofillFields:", String(element.ownerDocument.location));
if (!this.savedFieldNames) {
this.log.debug("identifyAutofillFields: savedFieldNames are not known yet");
this.debug("identifyAutofillFields: savedFieldNames are not known yet");
Services.cpmm.sendAsyncMessage("FormAutofill:InitStorage");
}
@ -542,14 +542,14 @@ var FormAutofillContent = {
let formLike = FormLikeFactory.createFromField(element);
formHandler = new FormAutofillHandler(formLike);
} else if (!formHandler.updateFormIfNeeded(element)) {
this.log.debug("No control is removed or inserted since last collection.");
this.debug("No control is removed or inserted since last collection.");
return;
}
let validDetails = formHandler.collectFormFields();
this._formsDetails.set(formHandler.form.rootElement, formHandler);
this.log.debug("Adding form handler to _formsDetails:", formHandler);
this.debug("Adding form handler to _formsDetails:", formHandler);
validDetails.forEach(detail =>
this._markAsAutofillField(detail.elementWeakRef.get())

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

@ -45,6 +45,26 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(this, "CreditCard",
"resource://gre/modules/CreditCard.jsm");
XPCOMUtils.defineLazyPreferenceGetter(this, "logLevel", "extensions.formautofill.loglevel",
"Warn");
// A logging helper for debug logging to avoid creating Console objects
// or triggering expensive JS -> C++ calls when debug logging is not
// enabled.
//
// Console objects, even natively-implemented ones, can consume a lot of
// memory, and since this code may run in every content process, that
// memory can add up quickly. And, even when debug-level messages are
// being ignored, console.debug() calls can be expensive.
//
// This helper avoids both of those problems by never touching the
// console object unless debug logging is enabled.
function debug() {
if (logLevel == "debug") {
this.log.debug(...arguments);
}
}
let AddressDataLoader = {
// Status of address data loading. We'll load all the countries with basic level 1
// information while requesting conutry information, and set country to true.
@ -338,6 +358,8 @@ this.FormAutofillUtils = {
},
defineLazyLogGetter(scope, logPrefix) {
scope.debug = debug;
XPCOMUtils.defineLazyGetter(scope, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
return new ConsoleAPI({

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

@ -496,10 +496,12 @@ nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(JSContext *cx)
if (reportViolation) {
nsAutoString fileName;
unsigned lineNum = 0;
unsigned columnNum = 0;
NS_NAMED_LITERAL_STRING(scriptSample, "call to eval() or related function blocked by CSP");
JS::AutoFilename scriptFilename;
if (JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNum)) {
if (JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNum,
&columnNum)) {
if (const char *file = scriptFilename.get()) {
CopyUTF8toUTF16(nsDependentCString(file), fileName);
}
@ -510,6 +512,7 @@ nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(JSContext *cx)
fileName,
scriptSample,
lineNum,
columnNum,
EmptyString(),
EmptyString());
}

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

@ -242,6 +242,11 @@ DocumentTimeline::NotifyRefreshDriverCreated(nsRefreshDriver* aDriver)
"We should not register with the refresh driver if we are not"
" in the document's list of timelines");
ObserveRefreshDriver(aDriver);
// Although we have started observing the refresh driver, it's possible we
// could perform a paint before the first refresh driver tick happens. To
// ensure we're in a consistent state in that case we run the first tick
// manually.
MostRecentRefreshTimeUpdated();
}
}

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

@ -11949,6 +11949,7 @@ nsIDocument::InlineScriptAllowedByCSP()
true, // aParserCreated
nullptr, // FIXME get script sample (bug 1314567)
0, // aLineNumber
0, // aColumnNumber
&allowsInlineScript);
NS_ENSURE_SUCCESS(rv, true);
}

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

@ -202,6 +202,19 @@ public:
* was set
*/
virtual uint32_t GetLineNumber() = 0;
// This doesn't entirely belong here since they only make sense for
// some types of linking elements, but it's a better place than
// anywhere else.
virtual void SetColumnNumber(uint32_t aColumnNumber) = 0;
/**
* Get the column number, as previously set by SetColumnNumber.
*
* @return the column number of this element; or 1 if no column number
* was set
*/
virtual uint32_t GetColumnNumber() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleSheetLinkingElement,

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

@ -198,13 +198,15 @@ CheckCSPForEval(JSContext* aCx, nsGlobalWindowInner* aWindow, ErrorResult& aErro
// Get the calling location.
uint32_t lineNum = 0;
uint32_t columnNum = 0;
nsAutoString fileNameString;
if (!nsJSUtils::GetCallingLocation(aCx, fileNameString, &lineNum)) {
if (!nsJSUtils::GetCallingLocation(aCx, fileNameString, &lineNum,
&columnNum)) {
fileNameString.AssignLiteral("unknown");
}
csp->LogViolationDetails(nsIContentSecurityPolicy::VIOLATION_TYPE_EVAL,
fileNameString, scriptSample, lineNum,
fileNameString, scriptSample, lineNum, columnNum,
EmptyString(), EmptyString());
}

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

@ -103,10 +103,10 @@
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static const char *kPrefYoutubeRewrite = "plugins.rewrite_youtube_embeds";
static const char *kPrefBlockURIs = "browser.safebrowsing.blockedURIs.enabled";
static const char *kPrefFavorFallbackMode = "plugins.favorfallback.mode";
static const char *kPrefFavorFallbackRules = "plugins.favorfallback.rules";
static const char kPrefYoutubeRewrite[] = "plugins.rewrite_youtube_embeds";
static const char kPrefBlockURIs[] = "browser.safebrowsing.blockedURIs.enabled";
static const char kPrefFavorFallbackMode[] = "plugins.favorfallback.mode";
static const char kPrefFavorFallbackRules[] = "plugins.favorfallback.rules";
using namespace mozilla;
using namespace mozilla::dom;

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

@ -76,6 +76,7 @@ nsStyleLinkElement::nsStyleLinkElement()
: mDontLoadStyle(false)
, mUpdatesEnabled(true)
, mLineNumber(1)
, mColumnNumber(1)
{
}
@ -192,6 +193,18 @@ nsStyleLinkElement::GetLineNumber()
return mLineNumber;
}
/* virtual */ void
nsStyleLinkElement::SetColumnNumber(uint32_t aColumnNumber)
{
mColumnNumber = aColumnNumber;
}
/* virtual */ uint32_t
nsStyleLinkElement::GetColumnNumber()
{
return mColumnNumber;
}
static uint32_t ToLinkMask(const nsAString& aLink)
{
// Keep this in sync with sRelValues in HTMLLinkElement.cpp
@ -381,7 +394,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
thisContent->NodePrincipal(),
info->mTriggeringPrincipal,
doc->GetDocumentURI(),
mLineNumber, text, &rv)) {
mLineNumber, mColumnNumber, text,
&rv)) {
if (NS_FAILED(rv)) {
return Err(rv);
}

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

@ -56,6 +56,8 @@ public:
void OverrideBaseURI(nsIURI* aNewBaseURI) override;
void SetLineNumber(uint32_t aLineNumber) override;
uint32_t GetLineNumber() override;
void SetColumnNumber(uint32_t aColumnNumber) override;
uint32_t GetColumnNumber() override;
enum RelValue {
ePREFETCH = 0x00000001,
@ -136,6 +138,7 @@ protected:
bool mDontLoadStyle;
bool mUpdatesEnabled;
uint32_t mLineNumber;
uint32_t mColumnNumber;
};
#endif /* nsStyleLinkElement_h___ */

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

@ -210,7 +210,7 @@ nsStyledElement::ParseStyleAttribute(const nsAString& aValue,
if (!isNativeAnon &&
!nsStyleUtil::CSPAllowsInlineStyle(nullptr, NodePrincipal(),
aMaybeScriptedPrincipal,
doc->GetDocumentURI(), 0, aValue,
doc->GetDocumentURI(), 0, 0, aValue,
nullptr))
return;

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

@ -884,6 +884,7 @@ EventListenerManager::SetEventHandler(nsAtom* aName,
true, // aParserCreated (true because attribute event handler)
sampleIString,
0, // aLineNumber
0, // aColumnNumber
&allowsInlineScript);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -231,7 +231,7 @@ HTMLScriptElement::FreezeExecutionAttrs(nsIDocument* aOwnerDoc)
NS_LITERAL_CSTRING("HTML"), OwnerDoc(),
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceInvalidUri",
params, ArrayLength(params), nullptr,
EmptyString(), GetScriptLineNumber());
EmptyString(), GetScriptLineNumber(), GetScriptColumnNumber());
}
} else {
const char16_t* params[] = { u"src" };
@ -240,7 +240,7 @@ HTMLScriptElement::FreezeExecutionAttrs(nsIDocument* aOwnerDoc)
NS_LITERAL_CSTRING("HTML"), OwnerDoc(),
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty",
params, ArrayLength(params), nullptr,
EmptyString(), GetScriptLineNumber());
EmptyString(), GetScriptLineNumber(), GetScriptColumnNumber());
}
// At this point mUri will be null for invalid URLs.

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

@ -127,6 +127,8 @@ interface nsIContentSecurityPolicy : nsISerializable
* (and compare to the hashes listed in the policy)
* @param aLineNumber The line number of the inline resource
* (used for reporting)
* @param aColumnNumber The column number of the inline resource
* (used for reporting)
* @return
* Whether or not the effects of the inline style should be allowed
* (block the rules if false).
@ -135,7 +137,8 @@ interface nsIContentSecurityPolicy : nsISerializable
in AString aNonce,
in boolean aParserCreated,
in nsISupports aElementOrContent,
in unsigned long aLineNumber);
in unsigned long aLineNumber,
in unsigned long aColumnNumber);
/**
* whether this policy allows eval and eval-like functions
@ -175,6 +178,8 @@ interface nsIContentSecurityPolicy : nsISerializable
* sample of the violating content (to aid debugging)
* @param lineNum
* source line number of the violation (if available)
* @param columnNum
* source column number of the violation (if available)
* @param aNonce
* (optional) If this is a nonce violation, include the nonce so we can
* recheck to determine which policies were violated and send the
@ -189,6 +194,7 @@ interface nsIContentSecurityPolicy : nsISerializable
in AString sourceFile,
in AString scriptSample,
in int32_t lineNum,
in int32_t columnNum,
[optional] in AString nonce,
[optional] in AString content);

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

@ -182,6 +182,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
true, // aParserCreated
nullptr, // aContent
0, // aLineNumber
0, // aColumnNumber
&allowsInlineScript);
//return early if inline scripts are not allowed

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

@ -2016,16 +2016,11 @@ PluginOfflineObserver::Observe(nsISupports *aSubject,
return NS_OK;
}
static const char* kSettingsPrefs[] =
{"javascript.enabled",
"dom.ipc.plugins.nativeCursorSupport"};
void
PluginModuleChromeParent::RegisterSettingsCallbacks()
{
for (size_t i = 0; i < ArrayLength(kSettingsPrefs); i++) {
Preferences::RegisterCallback(CachedSettingChanged, kSettingsPrefs[i], this);
}
Preferences::RegisterCallback(CachedSettingChanged, "javascript.enabled", this);
Preferences::RegisterCallback(CachedSettingChanged, "dom.ipc.plugins.nativeCursorSupport", this);
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
@ -2037,9 +2032,8 @@ PluginModuleChromeParent::RegisterSettingsCallbacks()
void
PluginModuleChromeParent::UnregisterSettingsCallbacks()
{
for (size_t i = 0; i < ArrayLength(kSettingsPrefs); i++) {
Preferences::UnregisterCallback(CachedSettingChanged, kSettingsPrefs[i], this);
}
Preferences::UnregisterCallback(CachedSettingChanged, "javascript.enabled", this);
Preferences::UnregisterCallback(CachedSettingChanged, "dom.ipc.plugins.nativeCursorSupport", this);
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {

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

@ -1225,6 +1225,7 @@ CSPAllowsInlineScript(nsIScriptElement* aElement, nsIDocument* aDocument)
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_SCRIPT,
nonce, parserCreated, aElement,
aElement->GetScriptLineNumber(),
aElement->GetScriptColumnNumber(),
&allowInlineScript);
return allowInlineScript;
}
@ -2868,10 +2869,11 @@ ScriptLoader::VerifySRI(ScriptLoadRequest* aRequest,
nsAutoCString violationURISpec;
mDocument->GetDocumentURI()->GetAsciiSpec(violationURISpec);
uint32_t lineNo = aRequest->mElement ? aRequest->mElement->GetScriptLineNumber() : 0;
uint32_t columnNo = aRequest->mElement ? aRequest->mElement->GetScriptColumnNumber() : 0;
csp->LogViolationDetails(
nsIContentSecurityPolicy::VIOLATION_TYPE_REQUIRE_SRI_FOR_SCRIPT,
NS_ConvertUTF8toUTF16(violationURISpec),
EmptyString(), lineNo, EmptyString(), EmptyString());
EmptyString(), lineNo, columnNo, EmptyString(), EmptyString());
rv = NS_ERROR_SRI_CORRUPT;
}
}
@ -2953,12 +2955,13 @@ ScriptLoader::ReportErrorToConsole(ScriptLoadRequest *aRequest,
const char16_t* params[] = { url.get() };
uint32_t lineNo = aRequest->mElement->GetScriptLineNumber();
uint32_t columnNo = aRequest->mElement->GetScriptColumnNumber();
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("Script Loader"), mDocument,
nsContentUtils::eDOM_PROPERTIES, message,
params, ArrayLength(params), nullptr,
EmptyString(), lineNo);
EmptyString(), lineNo, columnNo);
}
void

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

@ -32,6 +32,7 @@ public:
explicit nsIScriptElement(mozilla::dom::FromParser aFromParser)
: mLineNumber(1),
mColumnNumber(1),
mAlreadyStarted(false),
mMalformed(false),
mDoneAddingChildren(aFromParser == mozilla::dom::NOT_FROM_PARSER ||
@ -146,6 +147,16 @@ public:
return mLineNumber;
}
void SetScriptColumnNumber(uint32_t aColumnNumber)
{
mColumnNumber = aColumnNumber;
}
uint32_t GetScriptColumnNumber()
{
return mColumnNumber;
}
void SetIsMalformed()
{
mMalformed = true;
@ -297,6 +308,11 @@ protected:
*/
uint32_t mLineNumber;
/**
* The start column number of the script.
*/
uint32_t mColumnNumber;
/**
* The "already started" flag per HTML5.
*/

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

@ -277,7 +277,8 @@ nsCSPContext::permitsInternal(CSPDirective aDir,
EmptyString(), /* no observer subject */
EmptyString(), /* no source file */
EmptyString(), /* no script sample */
0); /* no line number */
0, /* no line number */
0); /* no column number */
}
}
}
@ -457,7 +458,8 @@ nsCSPContext::reportInlineViolation(nsContentPolicyType aContentType,
const nsAString& aContent,
const nsAString& aViolatedDirective,
uint32_t aViolatedPolicyIndex, // TODO, use report only flag for that
uint32_t aLineNumber)
uint32_t aLineNumber,
uint32_t aColumnNumber)
{
nsString observerSubject;
// if the nonce is non empty, then we report the nonce error, otherwise
@ -499,7 +501,8 @@ nsCSPContext::reportInlineViolation(nsContentPolicyType aContentType,
observerSubject, // aObserverSubject
NS_ConvertUTF8toUTF16(sourceFile), // aSourceFile
codeSample, // aScriptSample
aLineNumber); // aLineNum
aLineNumber, // aLineNum
aColumnNumber); // aColumnNum
}
NS_IMETHODIMP
@ -508,6 +511,7 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
bool aParserCreated,
nsISupports* aElementOrContent,
uint32_t aLineNumber,
uint32_t aColumnNumber,
bool* outAllowsInline)
{
*outAllowsInline = true;
@ -565,7 +569,8 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
content,
violatedDirective,
i,
aLineNumber);
aLineNumber,
aColumnNumber);
}
}
return NS_OK;
@ -584,7 +589,8 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
* which is why we must check allows() again here.
*
* Note: This macro uses some parameters from its caller's context:
* p, mPolicies, this, aSourceFile, aScriptSample, aLineNum, selfISupports
* p, mPolicies, this, aSourceFile, aScriptSample, aLineNum, aColumnNum,
* selfISupports
*
* @param violationType: the VIOLATION_TYPE_* constant (partial symbol)
* such as INLINE_SCRIPT
@ -612,7 +618,8 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
violatedDirective); \
this->AsyncReportViolation(selfISupports, nullptr, violatedDirective, p, \
NS_LITERAL_STRING(observerTopic), \
aSourceFile, aScriptSample, aLineNum); \
aSourceFile, aScriptSample, aLineNum, \
aColumnNum); \
} \
PR_END_MACRO; \
break
@ -629,6 +636,8 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
* sample of the violating content (to aid debugging)
* @param aLineNum
* source line number of the violation (if available)
* @param aColumnNum
* source column number of the violation (if available)
* @param aNonce
* (optional) If this is a nonce violation, include the nonce so we can
* recheck to determine which policies were violated and send the
@ -644,6 +653,7 @@ nsCSPContext::LogViolationDetails(uint16_t aViolationType,
const nsAString& aSourceFile,
const nsAString& aScriptSample,
int32_t aLineNum,
int32_t aColumnNum,
const nsAString& aNonce,
const nsAString& aContent)
{
@ -860,6 +870,7 @@ nsCSPContext::GatherSecurityPolicyViolationEventData(
nsAString& aSourceFile,
nsAString& aScriptSample,
uint32_t aLineNum,
uint32_t aColumnNum,
mozilla::dom::SecurityPolicyViolationEventInit& aViolationEventInit)
{
NS_ENSURE_ARG_MAX(aViolatedPolicyIndex, mPolicies.Length() - 1);
@ -940,8 +951,7 @@ nsCSPContext::GatherSecurityPolicyViolationEventData(
aViolationEventInit.mLineNumber = aLineNum;
// column-number
// TODO: Set correct column number.
aViolationEventInit.mColumnNumber = 0;
aViolationEventInit.mColumnNumber = aColumnNum;
aViolationEventInit.mBubbles = true;
aViolationEventInit.mComposed = true;
@ -991,6 +1001,11 @@ nsCSPContext::SendReports(
report.mCsp_report.mLine_number.Value() = aViolationEventInit.mLineNumber;
}
if (aViolationEventInit.mLineNumber != 0) {
report.mCsp_report.mColumn_number.Construct();
report.mCsp_report.mColumn_number.Value() = aViolationEventInit.mColumnNumber;
}
nsString csp_report;
if (!report.ToJSON(csp_report)) {
return NS_ERROR_FAILURE;
@ -1016,7 +1031,9 @@ nsCSPContext::SendReports(
reportURICstring.get()));
logToConsole("triedToSendReport", params, ArrayLength(params),
aViolationEventInit.mSourceFile, aViolationEventInit.mSample,
aViolationEventInit.mLineNumber, 0, nsIScriptError::errorFlag);
aViolationEventInit.mLineNumber,
aViolationEventInit.mColumnNumber,
nsIScriptError::errorFlag);
continue; // don't return yet, there may be more URIs
}
@ -1060,7 +1077,9 @@ nsCSPContext::SendReports(
const char16_t* params[] = { reportURIs[r].get() };
logToConsole("reportURInotHttpsOrHttp2", params, ArrayLength(params),
aViolationEventInit.mSourceFile, aViolationEventInit.mSample,
aViolationEventInit.mLineNumber, 0, nsIScriptError::errorFlag);
aViolationEventInit.mLineNumber,
aViolationEventInit.mColumnNumber,
nsIScriptError::errorFlag);
continue;
}
@ -1126,7 +1145,9 @@ nsCSPContext::SendReports(
CSPCONTEXTLOG(("AsyncOpen failed for report URI %s", NS_ConvertUTF16toUTF8(params[0]).get()));
logToConsole("triedToSendReport", params, ArrayLength(params),
aViolationEventInit.mSourceFile, aViolationEventInit.mSample,
aViolationEventInit.mLineNumber, 0, nsIScriptError::errorFlag);
aViolationEventInit.mLineNumber,
aViolationEventInit.mColumnNumber,
nsIScriptError::errorFlag);
} else {
CSPCONTEXTLOG(("Sent violation report to URI %s", reportURICstring.get()));
}
@ -1174,6 +1195,7 @@ class CSPReportSenderRunnable final : public Runnable
const nsAString& aSourceFile,
const nsAString& aScriptSample,
uint32_t aLineNum,
uint32_t aColumnNum,
nsCSPContext* aCSPContext)
: mozilla::Runnable("CSPReportSenderRunnable")
, mBlockedContentSource(aBlockedContentSource)
@ -1184,6 +1206,7 @@ class CSPReportSenderRunnable final : public Runnable
, mSourceFile(aSourceFile)
, mScriptSample(aScriptSample)
, mLineNum(aLineNum)
, mColumnNum(aColumnNum)
, mCSPContext(aCSPContext)
{
NS_ASSERTION(!aViolatedDirective.IsEmpty(), "Can not send reports without a violated directive");
@ -1214,7 +1237,7 @@ class CSPReportSenderRunnable final : public Runnable
rv = mCSPContext->GatherSecurityPolicyViolationEventData(
blockedURI, mOriginalURI,
mViolatedDirective, mViolatedPolicyIndex,
mSourceFile, mScriptSample, mLineNum,
mSourceFile, mScriptSample, mLineNum, mColumnNum,
init);
NS_ENSURE_SUCCESS(rv, rv);
@ -1222,8 +1245,8 @@ class CSPReportSenderRunnable final : public Runnable
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
NS_ASSERTION(observerService, "needs observer service");
rv = observerService->NotifyObservers(mObserverSubject,
CSP_VIOLATION_TOPIC,
mViolatedDirective.get());
CSP_VIOLATION_TOPIC,
mViolatedDirective.get());
NS_ENSURE_SUCCESS(rv, rv);
// 2) send reports for the policy that was violated
@ -1256,7 +1279,7 @@ class CSPReportSenderRunnable final : public Runnable
mCSPContext->logToConsole(mReportOnlyFlag ? "CSPROViolationWithURI" :
"CSPViolationWithURI",
params, ArrayLength(params), mSourceFile, mScriptSample,
mLineNum, 0, nsIScriptError::errorFlag);
mLineNum, mColumnNum, nsIScriptError::errorFlag);
}
// 4) fire violation event
@ -1275,6 +1298,7 @@ class CSPReportSenderRunnable final : public Runnable
nsString mSourceFile;
nsString mScriptSample;
uint32_t mLineNum;
uint32_t mColumnNum;
RefPtr<nsCSPContext> mCSPContext;
};
@ -1302,6 +1326,8 @@ class CSPReportSenderRunnable final : public Runnable
* a sample of the violating inline script
* @param aLineNum
* source line number of the violation (if available)
* @param aColumnNum
* source column number of the violation (if available)
*/
nsresult
nsCSPContext::AsyncReportViolation(nsISupports* aBlockedContentSource,
@ -1311,7 +1337,8 @@ nsCSPContext::AsyncReportViolation(nsISupports* aBlockedContentSource,
const nsAString& aObserverSubject,
const nsAString& aSourceFile,
const nsAString& aScriptSample,
uint32_t aLineNum)
uint32_t aLineNum,
uint32_t aColumnNum)
{
NS_ENSURE_ARG_MAX(aViolatedPolicyIndex, mPolicies.Length() - 1);
@ -1325,6 +1352,7 @@ nsCSPContext::AsyncReportViolation(nsISupports* aBlockedContentSource,
aSourceFile,
aScriptSample,
aLineNum,
aColumnNum,
this);
if (XRE_IsContentProcess()) {

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

@ -76,6 +76,8 @@ class nsCSPContext : public nsIContentSecurityPolicy
* a sample of the violating inline script
* @param aLineNum
* source line number of the violation (if available)
* @param aColumnNum
* source column number of the violation (if available)
* @param aViolationEventInit
* The output
*/
@ -87,6 +89,7 @@ class nsCSPContext : public nsIContentSecurityPolicy
nsAString& aSourceFile,
nsAString& aScriptSample,
uint32_t aLineNum,
uint32_t aColumnNum,
mozilla::dom::SecurityPolicyViolationEventInit& aViolationEventInit);
nsresult SendReports(
@ -103,7 +106,8 @@ class nsCSPContext : public nsIContentSecurityPolicy
const nsAString& aObserverSubject,
const nsAString& aSourceFile,
const nsAString& aScriptSample,
uint32_t aLineNum);
uint32_t aLineNum,
uint32_t aColumnNum);
// Hands off! Don't call this method unless you know what you
// are doing. It's only supposed to be called from within
@ -134,7 +138,8 @@ class nsCSPContext : public nsIContentSecurityPolicy
const nsAString& aContent,
const nsAString& aViolatedDirective,
uint32_t aViolatedPolicyIndex,
uint32_t aLineNumber);
uint32_t aLineNumber,
uint32_t aColumnNumber);
static int32_t sScriptSampleMaxLength;

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

@ -113,7 +113,8 @@ function run_test() {
"", // aNonce
false, // aParserCreated
content, // aContent
0); // aLineNumber
0, // aLineNumber
0); // aColumnNumber
// this is not a report only policy, so it better block inline scripts
Assert.ok(!inlineOK);
@ -122,7 +123,9 @@ function run_test() {
// test that eval violations cause a report.
makeTest(1, {"blocked-uri": "",
// JSON script-sample is UTF8 encoded
"script-sample" : "\xc2\xa3\xc2\xa5\xc2\xb5\xe5\x8c\x97\xf0\xa0\x9d\xb9"}, false,
"script-sample" : "\xc2\xa3\xc2\xa5\xc2\xb5\xe5\x8c\x97\xf0\xa0\x9d\xb9",
"line-number": 1,
"column-number": 2}, false,
function(csp) {
let evalOK = true, oReportViolation = {'value': false};
evalOK = csp.getAllowsEval(oReportViolation);
@ -140,7 +143,8 @@ function run_test() {
// csp report in JSON is not cut-off, please
// note that JSON is UTF8 encoded.
"\u00a3\u00a5\u00b5\u5317\ud841\udf79",
1);
1, // line number
2); // column number
}
});
@ -163,7 +167,8 @@ function run_test() {
"", // aNonce
false, // aParserCreated
content, // aContent
0); // aLineNumber
0, // aLineNumber
0); // aColumnNumber
// this is a report only policy, so it better allow inline scripts
Assert.ok(inlineOK);
@ -185,7 +190,8 @@ function run_test() {
csp.logViolationDetails(Ci.nsIContentSecurityPolicy.VIOLATION_TYPE_INLINE_SCRIPT,
selfuri.asciiSpec,
"script sample",
4);
4, // line number
5); // column number
}
});

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

@ -523,7 +523,7 @@ nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID,
doc->NodePrincipal(),
nullptr,
doc->GetDocumentURI(),
0, aString, nullptr)) {
0, 0, aString, nullptr)) {
return;
}
@ -567,7 +567,8 @@ nsSMILCSSValueType::ValueFromAnimationValue(nsCSSPropertyID aPropID,
doc->NodePrincipal(),
nullptr,
doc->GetDocumentURI(),
0, kPlaceholderText, nullptr)) {
0, 0, kPlaceholderText,
nullptr)) {
return result;
}

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

@ -168,7 +168,7 @@ SVGScriptElement::FreezeExecutionAttrs(nsIDocument* aOwnerDoc)
NS_LITERAL_CSTRING("SVG"), OwnerDoc(),
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceInvalidUri",
params, ArrayLength(params), nullptr,
EmptyString(), GetScriptLineNumber());
EmptyString(), GetScriptLineNumber(), GetScriptColumnNumber());
}
} else {
const char16_t* params[] = { isHref ? u"href" : u"xlink:href" };
@ -177,7 +177,7 @@ SVGScriptElement::FreezeExecutionAttrs(nsIDocument* aOwnerDoc)
NS_LITERAL_CSTRING("SVG"), OwnerDoc(),
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty",
params, ArrayLength(params), nullptr,
EmptyString(), GetScriptLineNumber());
EmptyString(), GetScriptLineNumber(), GetScriptColumnNumber());
}
// At this point mUri will be null for invalid URLs.

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

@ -16,6 +16,7 @@ dictionary CSPReportProperties {
DOMString source-file;
DOMString script-sample;
long line-number;
long column-number;
};
dictionary CSPReport {

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

@ -584,14 +584,18 @@ class LogViolationDetailsRunnable final : public WorkerMainThreadRunnable
{
nsString mFileName;
uint32_t mLineNum;
uint32_t mColumnNum;
public:
LogViolationDetailsRunnable(WorkerPrivate* aWorker,
const nsString& aFileName,
uint32_t aLineNum)
uint32_t aLineNum,
uint32_t aColumnNum)
: WorkerMainThreadRunnable(aWorker,
NS_LITERAL_CSTRING("RuntimeService :: LogViolationDetails"))
, mFileName(aFileName), mLineNum(aLineNum)
, mFileName(aFileName)
, mLineNum(aLineNum)
, mColumnNum(aColumnNum)
{
MOZ_ASSERT(aWorker);
}
@ -611,16 +615,17 @@ ContentSecurityPolicyAllows(JSContext* aCx)
if (worker->GetReportCSPViolations()) {
nsString fileName;
uint32_t lineNum = 0;
uint32_t columnNum = 0;
JS::AutoFilename file;
if (JS::DescribeScriptedCaller(aCx, &file, &lineNum) && file.get()) {
if (JS::DescribeScriptedCaller(aCx, &file, &lineNum, &columnNum) && file.get()) {
fileName = NS_ConvertUTF8toUTF16(file.get());
} else {
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
}
RefPtr<LogViolationDetailsRunnable> runnable =
new LogViolationDetailsRunnable(worker, fileName, lineNum);
new LogViolationDetailsRunnable(worker, fileName, lineNum, columnNum);
ErrorResult rv;
runnable->Dispatch(Killing, rv);
@ -2620,7 +2625,7 @@ LogViolationDetailsRunnable::MainThreadRun()
"Call to eval() or related function blocked by CSP.");
if (mWorkerPrivate->GetReportCSPViolations()) {
csp->LogViolationDetails(nsIContentSecurityPolicy::VIOLATION_TYPE_EVAL,
mFileName, scriptSample, mLineNum,
mFileName, scriptSample, mLineNum, mColumnNum,
EmptyString(), EmptyString());
}
}

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

@ -1226,7 +1226,7 @@ private:
if (wcsp) {
wcsp->LogViolationDetails(
nsIContentSecurityPolicy::VIOLATION_TYPE_REQUIRE_SRI_FOR_SCRIPT,
aLoadInfo.mURL, EmptyString(), 0, EmptyString(), EmptyString());
aLoadInfo.mURL, EmptyString(), 0, 0, EmptyString(), EmptyString());
}
return NS_ERROR_SRI_CORRUPT;
}

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

@ -28,7 +28,7 @@ xhr.onload = (e) => {
worker = new Worker(uri);
worker.postMessage({ do: "eval" })
worker.onmessage = function(event) {
is(event.data, "Error: call to eval() blocked by CSP", "Eval threw");
is(event.data, "EvalError: call to eval() blocked by CSP", "Eval threw");
testDone();
}
}
@ -42,7 +42,7 @@ xhr.onload = (e) => {
worker = new Worker(uri);
worker.postMessage({ do: "nest", uri: uri, level: 3 })
worker.onmessage = function(event) {
is(event.data, "Error: call to eval() blocked by CSP", "Eval threw in nested worker");
is(event.data, "EvalError: call to eval() blocked by CSP", "Eval threw in nested worker");
testDone();
}
}

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

@ -247,10 +247,11 @@ NS_IMETHODIMP
nsXBLContentSink::HandleStartElement(const char16_t *aName,
const char16_t **aAtts,
uint32_t aAttsCount,
uint32_t aLineNumber)
uint32_t aLineNumber,
uint32_t aColumnNumber)
{
nsresult rv = nsXMLContentSink::HandleStartElement(aName, aAtts, aAttsCount,
aLineNumber);
aLineNumber, aColumnNumber);
if (NS_FAILED(rv))
return rv;
@ -850,7 +851,8 @@ nsXBLContentSink::ConstructParameter(const char16_t **aAtts)
nsresult
nsXBLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
mozilla::dom::NodeInfo* aNodeInfo,
uint32_t aLineNumber, uint32_t aColumnNumber,
nsIContent** aResult, bool* aAppendContent,
FromParser aFromParser)
{
@ -858,7 +860,7 @@ nsXBLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
if (!aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
#endif
return nsXMLContentSink::CreateElement(aAtts, aAttsCount, aNodeInfo,
aLineNumber, aResult,
aLineNumber, aColumnNumber, aResult,
aAppendContent, aFromParser);
#ifdef MOZ_XUL
}

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

@ -68,7 +68,8 @@ public:
NS_IMETHOD HandleStartElement(const char16_t *aName,
const char16_t **aAtts,
uint32_t aAttsCount,
uint32_t aLineNumber) override;
uint32_t aLineNumber,
uint32_t aColumnNumber) override;
NS_IMETHOD HandleEndElement(const char16_t *aName) override;
@ -88,7 +89,8 @@ protected:
bool NotifyForDocElement() override { return false; }
nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
mozilla::dom::NodeInfo* aNodeInfo,
uint32_t aLineNumber, uint32_t aColumnNumber,
nsIContent** aResult, bool* aAppendContent,
mozilla::dom::FromParser aFromParser) override;

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

@ -481,7 +481,8 @@ FindIsAttrValue(const char16_t** aAtts, const char16_t** aResult)
nsresult
nsXMLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
mozilla::dom::NodeInfo* aNodeInfo,
uint32_t aLineNumber, uint32_t aColumnNumber,
nsIContent** aResult, bool* aAppendContent,
FromParser aFromParser)
{
@ -512,6 +513,7 @@ nsXMLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(content);
if (sele) {
sele->SetScriptLineNumber(aLineNumber);
sele->SetScriptColumnNumber(aColumnNumber);
sele->SetCreatorParser(GetParser());
} else {
MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled, "Node didn't QI to script, but SVG wasn't disabled.");
@ -549,6 +551,7 @@ nsXMLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
}
if (!aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML)) {
ssle->SetLineNumber(aFromParser ? aLineNumber : 0);
ssle->SetColumnNumber(aFromParser ? aColumnNumber : 0);
}
}
}
@ -988,10 +991,11 @@ NS_IMETHODIMP
nsXMLContentSink::HandleStartElement(const char16_t *aName,
const char16_t **aAtts,
uint32_t aAttsCount,
uint32_t aLineNumber)
uint32_t aLineNumber,
uint32_t aColumnNumber)
{
return HandleStartElement(aName, aAtts, aAttsCount, aLineNumber,
true);
aColumnNumber, true);
}
nsresult
@ -999,6 +1003,7 @@ nsXMLContentSink::HandleStartElement(const char16_t *aName,
const char16_t **aAtts,
uint32_t aAttsCount,
uint32_t aLineNumber,
uint32_t aColumnNumber,
bool aInterruptable)
{
MOZ_ASSERT(aAttsCount % 2 == 0, "incorrect aAttsCount");
@ -1033,7 +1038,7 @@ nsXMLContentSink::HandleStartElement(const char16_t *aName,
nsINode::ELEMENT_NODE);
result = CreateElement(aAtts, aAttsCount, nodeInfo, aLineNumber,
getter_AddRefs(content), &appendContent,
aColumnNumber, getter_AddRefs(content), &appendContent,
FROM_PARSER_NETWORK);
NS_ENSURE_SUCCESS(result, result);

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

@ -117,7 +117,8 @@ protected:
nsIContent *aContent);
virtual bool NotifyForDocElement() { return true; }
virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
mozilla::dom::NodeInfo* aNodeInfo,
uint32_t aLineNumber, uint32_t aColumnNumber,
nsIContent** aResult, bool* aAppendContent,
mozilla::dom::FromParser aFromParser);
@ -181,7 +182,7 @@ protected:
nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts,
uint32_t aAttsCount, uint32_t aLineNumber,
bool aInterruptable);
uint32_t aColumnNumber, bool aInterruptable);
nsresult HandleEndElement(const char16_t *aName, bool aInterruptable);
nsresult HandleCharacterData(const char16_t *aData, uint32_t aLength,
bool aInterruptable);

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

@ -82,7 +82,8 @@ protected:
nsAtom* aTagName,
nsIContent* aContent) override;
virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
mozilla::dom::NodeInfo* aNodeInfo,
uint32_t aLineNumber, uint32_t aColumnNumber,
nsIContent** aResult, bool* aAppendContent,
mozilla::dom::FromParser aFromParser) override;
virtual nsresult CloseElement(nsIContent* aContent) override;
@ -208,7 +209,8 @@ nsXMLFragmentContentSink::SetDocElement(int32_t aNameSpaceID,
nsresult
nsXMLFragmentContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
mozilla::dom::NodeInfo* aNodeInfo,
uint32_t aLineNumber, uint32_t aColumnNumber,
nsIContent** aResult, bool* aAppendContent,
FromParser /*aFromParser*/)
{
@ -216,6 +218,7 @@ nsXMLFragmentContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCo
// fancy CloseElement stuff.
nsresult rv = nsXMLContentSink::CreateElement(aAtts, aAttsCount,
aNodeInfo, aLineNumber,
aColumnNumber,
aResult, aAppendContent,
NOT_FROM_PARSER);

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

@ -121,7 +121,8 @@ NS_IMETHODIMP
txStylesheetSink::HandleStartElement(const char16_t *aName,
const char16_t **aAtts,
uint32_t aAttsCount,
uint32_t aLineNumber)
uint32_t aLineNumber,
uint32_t aColumnNumber)
{
MOZ_ASSERT(aAttsCount % 2 == 0, "incorrect aAttsCount");

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

@ -407,7 +407,8 @@ NS_IMETHODIMP
XULContentSinkImpl::HandleStartElement(const char16_t *aName,
const char16_t **aAtts,
uint32_t aAttsCount,
uint32_t aLineNumber)
uint32_t aLineNumber,
uint32_t aColumnNumber)
{
// XXX Hopefully the parser will flag this before we get here. If
// we're in the epilog, there should be no new elements
@ -666,7 +667,7 @@ XULContentSinkImpl::ReportError(const char16_t* aErrorText,
parsererror.Append((char16_t)0xFFFF);
parsererror.AppendLiteral("parsererror");
rv = HandleStartElement(parsererror.get(), noAtts, 0, 0);
rv = HandleStartElement(parsererror.get(), noAtts, 0, 0, 0);
NS_ENSURE_SUCCESS(rv,rv);
rv = HandleCharacterData(aErrorText, NS_strlen(aErrorText));
@ -676,7 +677,7 @@ XULContentSinkImpl::ReportError(const char16_t* aErrorText,
sourcetext.Append((char16_t)0xFFFF);
sourcetext.AppendLiteral("sourcetext");
rv = HandleStartElement(sourcetext.get(), noAtts, 0, 0);
rv = HandleStartElement(sourcetext.get(), noAtts, 0, 0, 0);
NS_ENSURE_SUCCESS(rv,rv);
rv = HandleCharacterData(aSourceText, NS_strlen(aSourceText));

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

@ -141,7 +141,7 @@ gfxPrefs::IsParentProcess()
}
void gfxPrefs::PrefAddVarCache(bool* aVariable,
const char* aPref,
const nsACString& aPref,
bool aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -149,7 +149,7 @@ void gfxPrefs::PrefAddVarCache(bool* aVariable,
}
void gfxPrefs::PrefAddVarCache(int32_t* aVariable,
const char* aPref,
const nsACString& aPref,
int32_t aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -157,7 +157,7 @@ void gfxPrefs::PrefAddVarCache(int32_t* aVariable,
}
void gfxPrefs::PrefAddVarCache(uint32_t* aVariable,
const char* aPref,
const nsACString& aPref,
uint32_t aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -165,7 +165,7 @@ void gfxPrefs::PrefAddVarCache(uint32_t* aVariable,
}
void gfxPrefs::PrefAddVarCache(float* aVariable,
const char* aPref,
const nsACString& aPref,
float aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -173,15 +173,15 @@ void gfxPrefs::PrefAddVarCache(float* aVariable,
}
void gfxPrefs::PrefAddVarCache(std::string* aVariable,
const char* aPref,
const nsCString& aPref,
std::string aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetCString(aPref, aVariable->c_str());
Preferences::SetCString(aPref.get(), aVariable->c_str());
}
void gfxPrefs::PrefAddVarCache(AtomicBool* aVariable,
const char* aPref,
const nsACString& aPref,
bool aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -189,7 +189,7 @@ void gfxPrefs::PrefAddVarCache(AtomicBool* aVariable,
}
void gfxPrefs::PrefAddVarCache(AtomicInt32* aVariable,
const char* aPref,
const nsACString& aPref,
int32_t aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -197,7 +197,7 @@ void gfxPrefs::PrefAddVarCache(AtomicInt32* aVariable,
}
void gfxPrefs::PrefAddVarCache(AtomicUint32* aVariable,
const char* aPref,
const nsACString& aPref,
uint32_t aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -281,14 +281,17 @@ OnGfxPrefChanged(const char* aPrefname, void* aClosure)
void gfxPrefs::WatchChanges(const char* aPrefname, Pref* aPref)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::RegisterCallback(OnGfxPrefChanged, aPrefname, aPref);
nsCString name;
name.AssignLiteral(aPrefname, strlen(aPrefname));
Preferences::RegisterCallback(OnGfxPrefChanged, name, aPref);
}
void gfxPrefs::UnwatchChanges(const char* aPrefname, Pref* aPref)
{
// The Preferences service can go offline before gfxPrefs is destroyed.
if (IsPrefsServiceAvailable()) {
Preferences::UnregisterCallback(OnGfxPrefChanged, aPrefname, aPref);
Preferences::UnregisterCallback(OnGfxPrefChanged, nsDependentCString(aPrefname),
aPref);
}
}

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

@ -13,6 +13,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/gfx/LoggingConstants.h"
#include "nsTArray.h"
#include "nsString.h"
// First time gfxPrefs::GetSingleton() needs to be called on the main thread,
// before any of the methods accessing the values are used, but after
@ -241,7 +242,11 @@ private:
this->mValue = PrefGet(aPreference, this->mValue);
break;
case UpdatePolicy::Live:
PrefAddVarCache(&this->mValue, aPreference, this->mValue);
{
nsCString pref;
pref.AssignLiteral(aPreference, strlen(aPreference));
PrefAddVarCache(&this->mValue, pref, this->mValue);
}
break;
default:
MOZ_CRASH("Incomplete switch");
@ -812,14 +817,14 @@ private:
static bool IsPrefsServiceAvailable();
static bool IsParentProcess();
// Creating these to avoid having to include Preferences.h in the .h
static void PrefAddVarCache(bool*, const char*, bool);
static void PrefAddVarCache(int32_t*, const char*, int32_t);
static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
static void PrefAddVarCache(float*, const char*, float);
static void PrefAddVarCache(std::string*, const char*, std::string);
static void PrefAddVarCache(AtomicBool*, const char*, bool);
static void PrefAddVarCache(AtomicInt32*, const char*, int32_t);
static void PrefAddVarCache(AtomicUint32*, const char*, uint32_t);
static void PrefAddVarCache(bool*, const nsACString&, bool);
static void PrefAddVarCache(int32_t*, const nsACString&, int32_t);
static void PrefAddVarCache(uint32_t*, const nsACString&, uint32_t);
static void PrefAddVarCache(float*, const nsACString&, float);
static void PrefAddVarCache(std::string*, const nsCString&, std::string);
static void PrefAddVarCache(AtomicBool*, const nsACString&, bool);
static void PrefAddVarCache(AtomicInt32*, const nsACString&, int32_t);
static void PrefAddVarCache(AtomicUint32*, const nsACString&, uint32_t);
static bool PrefGet(const char*, bool);
static int32_t PrefGet(const char*, int32_t);
static uint32_t PrefGet(const char*, uint32_t);

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

@ -151,7 +151,7 @@ MSG_DEF(JSMSG_PARAMETER_AFTER_REST, 0, JSEXN_SYNTAXERR, "parameter after rest
MSG_DEF(JSMSG_TOO_MANY_ARGUMENTS, 0, JSEXN_RANGEERR, "too many arguments provided for a function call")
// CSP
MSG_DEF(JSMSG_CSP_BLOCKED_EVAL, 0, JSEXN_ERR, "call to eval() blocked by CSP")
MSG_DEF(JSMSG_CSP_BLOCKED_EVAL, 0, JSEXN_EVALERR, "call to eval() blocked by CSP")
MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 0, JSEXN_ERR, "call to Function() blocked by CSP")
// Wrappers

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

@ -112,16 +112,16 @@ GetPrefsFor(EventClassID aEventClassID)
prefs->mRegistered = true;
nsPrintfCString enabledPref("ui.%s.radius.enabled", prefBranch);
Preferences::AddBoolVarCache(&prefs->mEnabled, enabledPref.get(), false);
Preferences::AddBoolVarCache(&prefs->mEnabled, enabledPref, false);
nsPrintfCString visitedWeightPref("ui.%s.radius.visitedWeight", prefBranch);
Preferences::AddUintVarCache(&prefs->mVisitedWeight, visitedWeightPref.get(), 100);
Preferences::AddUintVarCache(&prefs->mVisitedWeight, visitedWeightPref, 100);
static const char prefNames[4][9] =
{ "topmm", "rightmm", "bottommm", "leftmm" };
for (int32_t i = 0; i < 4; ++i) {
nsPrintfCString radiusPref("ui.%s.radius.%s", prefBranch, prefNames[i]);
Preferences::AddUintVarCache(&prefs->mSideRadii[i], radiusPref.get(), 0);
Preferences::AddUintVarCache(&prefs->mSideRadii[i], radiusPref, 0);
}
if (aEventClassID == eMouseEventClass) {
@ -132,7 +132,7 @@ GetPrefsFor(EventClassID aEventClassID)
}
nsPrintfCString repositionPref("ui.%s.radius.reposition", prefBranch);
Preferences::AddBoolVarCache(&prefs->mRepositionEventCoords, repositionPref.get(), false);
Preferences::AddBoolVarCache(&prefs->mRepositionEventCoords, repositionPref, false);
// These values were formerly set by ui.zoomedview preferences.
prefs->mTouchClusterDetectionEnabled = false;

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

@ -785,7 +785,7 @@ SheetLoadData::VerifySheetReadyToParse(nsresult aStatus,
csp->LogViolationDetails(
nsIContentSecurityPolicy::VIOLATION_TYPE_REQUIRE_SRI_FOR_STYLE,
NS_ConvertUTF8toUTF16(spec), EmptyString(),
0, EmptyString(), EmptyString());
0, 0, EmptyString(), EmptyString());
return NS_OK;
}
} else {

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

@ -126,8 +126,10 @@ nsCSSProps::AddRefTable(void)
prefObserversInited = true;
for (const PropertyPref* pref = kPropertyPrefTable;
pref->mPropID != eCSSProperty_UNKNOWN; pref++) {
nsCString prefName;
prefName.AssignLiteral(pref->mPref, strlen(pref->mPref));
bool* enabled = &gPropertyEnabled[pref->mPropID];
Preferences::AddBoolVarCache(enabled, pref->mPref);
Preferences::AddBoolVarCache(enabled, prefName);
}
}
}

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

@ -5523,7 +5523,9 @@ nsComputedDOMStyle::RegisterPrefChangeCallbacks()
ComputedStyleMap* data = GetComputedStyleMap();
for (const auto* p = nsCSSProps::kPropertyPrefTable;
p->mPropID != eCSSProperty_UNKNOWN; p++) {
Preferences::RegisterCallback(MarkComputedStyleMapDirty, p->mPref, data);
nsCString name;
name.AssignLiteral(p->mPref, strlen(p->mPref));
Preferences::RegisterCallback(MarkComputedStyleMapDirty, name, data);
}
}
@ -5533,6 +5535,7 @@ nsComputedDOMStyle::UnregisterPrefChangeCallbacks()
ComputedStyleMap* data = GetComputedStyleMap();
for (const auto* p = nsCSSProps::kPropertyPrefTable;
p->mPropID != eCSSProperty_UNKNOWN; p++) {
Preferences::UnregisterCallback(MarkComputedStyleMapDirty, p->mPref, data);
Preferences::UnregisterCallback(MarkComputedStyleMapDirty,
nsDependentCString(p->mPref), data);
}
}

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

@ -773,6 +773,7 @@ nsStyleUtil::CSPAllowsInlineStyle(Element* aElement,
nsIPrincipal* aTriggeringPrincipal,
nsIURI* aSourceURI,
uint32_t aLineNumber,
uint32_t aColumnNumber,
const nsAString& aStyleText,
nsresult* aRv)
{
@ -821,7 +822,7 @@ nsStyleUtil::CSPAllowsInlineStyle(Element* aElement,
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_STYLESHEET,
nonce,
false, // aParserCreated only applies to scripts
styleText, aLineNumber,
styleText, aLineNumber, aColumnNumber,
&allowInlineStyle);
NS_ENSURE_SUCCESS(rv, false);

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

@ -202,6 +202,9 @@ public:
* @param aLineNumber
* Line number of inline style element in the containing document (for
* reporting violations)
* @param aColumnNumber
* Column number of inline style element in the containing document (for
* reporting violations)
* @param aStyleText
* Contents of the inline style element (for reporting violations)
* @param aRv
@ -214,6 +217,7 @@ public:
nsIPrincipal* aTriggeringPrincipal,
nsIURI* aSourceURI,
uint32_t aLineNumber,
uint32_t aColumnNumber,
const nsAString& aStyleText,
nsresult* aRv);

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

@ -71,7 +71,7 @@ DOMTimeStamp nsMenuPopupFrame::sLastKeyTime = 0;
// if someone changes one, please also change the other.
uint32_t nsMenuPopupFrame::sTimeoutOfIncrementalSearch = 1000;
const char* kPrefIncrementalSearchTimeout =
const char kPrefIncrementalSearchTimeout[] =
"ui.menu.incremental_search.timeout";
// NS_NewMenuPopupFrame

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

@ -133,7 +133,7 @@ nsMenuChainItem::CheckForAnchorChange()
bool nsXULPopupManager::sDevtoolsDisableAutoHide = false;
const char* kPrefDevtoolsDisableAutoHide =
const char kPrefDevtoolsDisableAutoHide[] =
"ui.popup.disable_autohide";
NS_IMPL_ISUPPORTS(nsXULPopupManager,

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

@ -83,6 +83,10 @@
#include "plstr.h"
#include "prlink.h"
#ifdef MOZ_MEMORY
#include "mozmemory.h"
#endif
#ifdef XP_WIN
#include "windows.h"
#endif
@ -204,7 +208,10 @@ union PrefValue {
mStringVal = nullptr;
}
void Replace(bool aHasValue, PrefType aOldType, PrefType aNewType, PrefValue aNewValue)
void Replace(bool aHasValue,
PrefType aOldType,
PrefType aNewType,
PrefValue aNewValue)
{
if (aHasValue) {
Clear(aOldType);
@ -997,11 +1004,11 @@ public:
class CallbackNode
{
public:
CallbackNode(const char* aDomain,
CallbackNode(const nsACString& aDomain,
PrefChangedFunc aFunc,
void* aData,
Preferences::MatchKind aMatchKind)
: mDomain(moz_xstrdup(aDomain))
: mDomain(aDomain)
, mFunc(aFunc)
, mData(aData)
, mNextAndMatchKind(aMatchKind)
@ -1010,7 +1017,7 @@ public:
// mDomain is a UniquePtr<>, so any uses of Domain() should only be temporary
// borrows.
const char* Domain() const { return mDomain.get(); }
const nsCString& Domain() const { return mDomain; }
PrefChangedFunc Func() const { return mFunc; }
void ClearFunc() { mFunc = nullptr; }
@ -1039,14 +1046,15 @@ public:
void AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf, PrefsSizes& aSizes)
{
aSizes.mCallbacksObjects += aMallocSizeOf(this);
aSizes.mCallbacksDomains += aMallocSizeOf(mDomain.get());
aSizes.mCallbacksDomains +=
mDomain.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
private:
static const uintptr_t kMatchKindMask = uintptr_t(0x1);
static const uintptr_t kNextMask = ~kMatchKindMask;
UniqueFreePtr<const char> mDomain;
nsCString mDomain;
// If someone attempts to remove the node from the callback list while
// NotifyCallbacks() is running, |func| is set to nullptr. Such nodes will
@ -1236,12 +1244,13 @@ NotifyCallbacks(const char* aPrefName)
// if we haven't reentered.
gCallbacksInProgress = true;
nsDependentCString prefName(aPrefName);
for (CallbackNode* node = gFirstCallback; node; node = node->Next()) {
if (node->Func()) {
bool matches =
node->MatchKind() == Preferences::ExactMatch
? strcmp(node->Domain(), aPrefName) == 0
: strncmp(node->Domain(), aPrefName, strlen(node->Domain())) == 0;
bool matches = node->MatchKind() == Preferences::ExactMatch
? node->Domain() == prefName
: StringBeginsWith(prefName, node->Domain());
if (matches) {
(node->Func())(aPrefName, node->Data());
}
@ -1459,7 +1468,7 @@ public:
public:
// Create a PrefCallback with a strong reference to its observer.
PrefCallback(const char* aDomain,
PrefCallback(const nsACString& aDomain,
nsIObserver* aObserver,
nsPrefBranch* aBranch)
: mDomain(aDomain)
@ -1473,7 +1482,7 @@ public:
}
// Create a PrefCallback with a weak reference to its observer.
PrefCallback(const char* aDomain,
PrefCallback(const nsACString& aDomain,
nsISupportsWeakReference* aObserver,
nsPrefBranch* aBranch)
: mDomain(aDomain)
@ -1629,6 +1638,16 @@ private:
static const char* match(const nsCString& aVal) { return aVal.get(); }
};
struct CStringMatcher
{
// Note: This is a reference, not an instance. It's used to pass our outer
// method argument through to our matcher methods.
nsACString& mStr;
void match(const char* aVal) { mStr.Assign(aVal); }
void match(const nsCString& aVal) { mStr.Assign(aVal); }
};
struct LenMatcher
{
static size_t match(const char* aVal) { return strlen(aVal); }
@ -1641,6 +1660,8 @@ private:
return match(m);
}
void get(nsACString& aStr) const { match(CStringMatcher{ aStr }); }
size_t Length() const
{
static LenMatcher m;
@ -1669,7 +1690,12 @@ private:
void RemoveExpiredCallback(PrefCallback* aCallback);
PrefName GetPrefName(const char* aPrefName) const;
PrefName GetPrefName(const char* aPrefName) const
{
return GetPrefName(nsDependentCString(aPrefName));
}
PrefName GetPrefName(const nsACString& aPrefName) const;
void FreeObserverList(void);
@ -2363,15 +2389,17 @@ nsPrefBranch::GetChildList(const char* aStartingAt,
}
NS_IMETHODIMP
nsPrefBranch::AddObserver(const char* aDomain,
nsIObserver* aObserver,
bool aHoldWeak)
nsPrefBranch::AddObserverImpl(const nsACString& aDomain,
nsIObserver* aObserver,
bool aHoldWeak)
{
PrefCallback* pCallback;
NS_ENSURE_ARG(aDomain);
NS_ENSURE_ARG(aObserver);
nsCString prefName;
GetPrefName(aDomain).get(prefName);
// Hold a weak reference to the observer if so requested.
if (aHoldWeak) {
nsCOMPtr<nsISupportsWeakReference> weakRefFactory =
@ -2383,11 +2411,11 @@ nsPrefBranch::AddObserver(const char* aDomain,
}
// Construct a PrefCallback with a weak reference to the observer.
pCallback = new PrefCallback(aDomain, weakRefFactory, this);
pCallback = new PrefCallback(prefName, weakRefFactory, this);
} else {
// Construct a PrefCallback with a strong reference to the observer.
pCallback = new PrefCallback(aDomain, aObserver, this);
pCallback = new PrefCallback(prefName, aObserver, this);
}
auto p = mObservers.LookupForAdd(pCallback);
@ -2402,9 +2430,8 @@ nsPrefBranch::AddObserver(const char* aDomain,
// We must pass a fully qualified preference name to the callback
// aDomain == nullptr is the only possible failure, and we trapped it with
// NS_ENSURE_ARG above.
const PrefName& pref = GetPrefName(aDomain);
Preferences::RegisterCallback(NotifyObserver,
pref.get(),
prefName,
pCallback,
Preferences::PrefixMatch,
/* isPriority */ false);
@ -2413,9 +2440,9 @@ nsPrefBranch::AddObserver(const char* aDomain,
}
NS_IMETHODIMP
nsPrefBranch::RemoveObserver(const char* aDomain, nsIObserver* aObserver)
nsPrefBranch::RemoveObserverImpl(const nsACString& aDomain,
nsIObserver* aObserver)
{
NS_ENSURE_ARG(aDomain);
NS_ENSURE_ARG(aObserver);
nsresult rv = NS_OK;
@ -2434,14 +2461,14 @@ nsPrefBranch::RemoveObserver(const char* aDomain, nsIObserver* aObserver)
// Remove the relevant PrefCallback from mObservers and get an owning pointer
// to it. Unregister the callback first, and then let the owning pointer go
// out of scope and destroy the callback.
PrefCallback key(aDomain, aObserver, this);
nsCString prefName;
GetPrefName(aDomain).get(prefName);
PrefCallback key(prefName, aObserver, this);
nsAutoPtr<PrefCallback> pCallback;
mObservers.Remove(&key, &pCallback);
if (pCallback) {
// aDomain == nullptr is the only possible failure, trapped above.
const PrefName& pref = GetPrefName(aDomain);
rv = Preferences::UnregisterCallback(
NotifyObserver, pref.get(), pCallback, Preferences::PrefixMatch);
NotifyObserver, prefName, pCallback, Preferences::PrefixMatch);
}
return rv;
@ -2475,7 +2502,7 @@ nsPrefBranch::NotifyObserver(const char* aNewPref, void* aData)
// Remove any root this string may contain so as to not confuse the observer
// by passing them something other than what they passed us as a topic.
uint32_t len = pCallback->GetPrefBranch()->GetRootLength();
nsAutoCString suffix(aNewPref + len);
nsDependentCString suffix(aNewPref + len);
observer->Observe(static_cast<nsIPrefBranch*>(pCallback->GetPrefBranch()),
NS_PREFBRANCH_PREFCHANGE_TOPIC_ID,
@ -2508,10 +2535,8 @@ nsPrefBranch::FreeObserverList()
mFreeingObserverList = true;
for (auto iter = mObservers.Iter(); !iter.Done(); iter.Next()) {
nsAutoPtr<PrefCallback>& callback = iter.Data();
nsPrefBranch* prefBranch = callback->GetPrefBranch();
const PrefName& pref = prefBranch->GetPrefName(callback->GetDomain().get());
Preferences::UnregisterCallback(nsPrefBranch::NotifyObserver,
pref.get(),
callback->GetDomain(),
callback,
Preferences::PrefixMatch);
iter.Remove();
@ -2556,16 +2581,13 @@ nsPrefBranch::GetDefaultFromPropertiesFile(const char* aPrefName,
}
nsPrefBranch::PrefName
nsPrefBranch::GetPrefName(const char* aPrefName) const
nsPrefBranch::GetPrefName(const nsACString& aPrefName) const
{
MOZ_ASSERT(aPrefName);
// For speed, avoid strcpy if we can.
if (mPrefRoot.IsEmpty()) {
return PrefName(aPrefName);
return PrefName(PromiseFlatCString(aPrefName));
}
return PrefName(mPrefRoot + nsDependentCString(aPrefName));
return PrefName(mPrefRoot + aPrefName);
}
//----------------------------------------------------------------------------
@ -2891,6 +2913,14 @@ AssertNotAlreadyCached(const char* aPrefType, const char* aPref, void* aPtr)
#endif
}
static void
AssertNotAlreadyCached(const char* aPrefType,
const nsACString& aPref,
void* aPtr)
{
AssertNotAlreadyCached(aPrefType, PromiseFlatCString(aPref).get(), aPtr);
}
// Although this is a member of Preferences, it measures sPreferences and
// several other global structures.
/* static */ void
@ -3030,8 +3060,6 @@ PreferenceServiceReporter::CollectReports(
for (auto iter = rootBranch->mObservers.Iter(); !iter.Done(); iter.Next()) {
nsAutoPtr<PrefCallback>& callback = iter.Data();
nsPrefBranch* prefBranch = callback->GetPrefBranch();
const auto& pref = prefBranch->GetPrefName(callback->GetDomain().get());
if (callback->IsWeak()) {
nsCOMPtr<nsIObserver> callbackRef = do_QueryReferent(callback->mWeakRef);
@ -3044,16 +3072,15 @@ PreferenceServiceReporter::CollectReports(
numStrong++;
}
nsDependentCString prefString(pref.get());
uint32_t oldCount = 0;
prefCounter.Get(prefString, &oldCount);
prefCounter.Get(callback->GetDomain(), &oldCount);
uint32_t currentCount = oldCount + 1;
prefCounter.Put(prefString, currentCount);
prefCounter.Put(callback->GetDomain(), currentCount);
// Keep track of preferences that have a suspiciously large number of
// referents (a symptom of a leak).
if (currentCount == kSuspectReferentCount) {
suspectPreferences.AppendElement(prefString);
suspectPreferences.AppendElement(callback->GetDomain());
}
}
@ -4560,7 +4587,7 @@ Preferences::GetType(const char* aPrefName)
}
/* static */ nsresult
Preferences::AddStrongObserver(nsIObserver* aObserver, const char* aPref)
Preferences::AddStrongObserver(nsIObserver* aObserver, const nsACString& aPref)
{
MOZ_ASSERT(aObserver);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
@ -4568,7 +4595,7 @@ Preferences::AddStrongObserver(nsIObserver* aObserver, const char* aPref)
}
/* static */ nsresult
Preferences::AddWeakObserver(nsIObserver* aObserver, const char* aPref)
Preferences::AddWeakObserver(nsIObserver* aObserver, const nsACString& aPref)
{
MOZ_ASSERT(aObserver);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
@ -4576,7 +4603,7 @@ Preferences::AddWeakObserver(nsIObserver* aObserver, const char* aPref)
}
/* static */ nsresult
Preferences::RemoveObserver(nsIObserver* aObserver, const char* aPref)
Preferences::RemoveObserver(nsIObserver* aObserver, const nsACString& aPref)
{
MOZ_ASSERT(aObserver);
if (sShutdown) {
@ -4587,12 +4614,27 @@ Preferences::RemoveObserver(nsIObserver* aObserver, const char* aPref)
return sPreferences->mRootBranch->RemoveObserver(aPref, aObserver);
}
template<typename T>
static void
AssertNotMallocAllocated(T* aPtr)
{
#if defined(DEBUG) && defined(MOZ_MEMORY)
jemalloc_ptr_info_t info;
jemalloc_ptr_info((void*)aPtr, &info);
MOZ_ASSERT(info.tag == TagUnknown);
#endif
}
/* static */ nsresult
Preferences::AddStrongObservers(nsIObserver* aObserver, const char** aPrefs)
{
MOZ_ASSERT(aObserver);
for (uint32_t i = 0; aPrefs[i]; i++) {
nsresult rv = AddStrongObserver(aObserver, aPrefs[i]);
AssertNotMallocAllocated(aPrefs[i]);
nsCString pref;
pref.AssignLiteral(aPrefs[i], strlen(aPrefs[i]));
nsresult rv = AddStrongObserver(aObserver, pref);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
@ -4603,7 +4645,11 @@ Preferences::AddWeakObservers(nsIObserver* aObserver, const char** aPrefs)
{
MOZ_ASSERT(aObserver);
for (uint32_t i = 0; aPrefs[i]; i++) {
nsresult rv = AddWeakObserver(aObserver, aPrefs[i]);
AssertNotMallocAllocated(aPrefs[i]);
nsCString pref;
pref.AssignLiteral(aPrefs[i], strlen(aPrefs[i]));
nsresult rv = AddWeakObserver(aObserver, pref);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
@ -4620,7 +4666,7 @@ Preferences::RemoveObservers(nsIObserver* aObserver, const char** aPrefs)
NS_ENSURE_TRUE(sPreferences, NS_ERROR_NOT_AVAILABLE);
for (uint32_t i = 0; aPrefs[i]; i++) {
nsresult rv = RemoveObserver(aObserver, aPrefs[i]);
nsresult rv = RemoveObserver(aObserver, nsDependentCString(aPrefs[i]));
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
@ -4628,12 +4674,11 @@ Preferences::RemoveObservers(nsIObserver* aObserver, const char** aPrefs)
/* static */ nsresult
Preferences::RegisterCallback(PrefChangedFunc aCallback,
const char* aPrefNode,
const nsACString& aPrefNode,
void* aData,
MatchKind aMatchKind,
bool aIsPriority)
{
NS_ENSURE_ARG(aPrefNode);
NS_ENSURE_ARG(aCallback);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
@ -4663,21 +4708,21 @@ Preferences::RegisterCallback(PrefChangedFunc aCallback,
/* static */ nsresult
Preferences::RegisterCallbackAndCall(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure,
MatchKind aMatchKind)
{
MOZ_ASSERT(aCallback);
nsresult rv = RegisterCallback(aCallback, aPref, aClosure, aMatchKind);
if (NS_SUCCEEDED(rv)) {
(*aCallback)(aPref, aClosure);
(*aCallback)(PromiseFlatCString(aPref).get(), aClosure);
}
return rv;
}
/* static */ nsresult
Preferences::UnregisterCallback(PrefChangedFunc aCallback,
const char* aPrefNode,
const nsACString& aPrefNode,
void* aData,
MatchKind aMatchKind)
{
@ -4694,8 +4739,7 @@ Preferences::UnregisterCallback(PrefChangedFunc aCallback,
while (node) {
if (node->Func() == aCallback && node->Data() == aData &&
node->MatchKind() == aMatchKind &&
strcmp(node->Domain(), aPrefNode) == 0) {
node->MatchKind() == aMatchKind && node->Domain() == aPrefNode) {
if (gCallbacksInProgress) {
// Postpone the node removal until after callbacks enumeration is
// finished.
@ -4734,13 +4778,13 @@ BoolVarChanged(const char* aPref, void* aClosure)
/* static */ nsresult
Preferences::AddBoolVarCache(bool* aCache,
const char* aPref,
const nsACString& aPref,
bool aDefault,
bool aSkipAssignment)
{
AssertNotAlreadyCached("bool", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetBool(aPref, aDefault);
*aCache = GetBool(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
@ -4766,13 +4810,13 @@ AtomicBoolVarChanged(const char* aPref, void* aClosure)
template<MemoryOrdering Order>
/* static */ nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, Order>* aCache,
const char* aPref,
const nsACString& aPref,
bool aDefault,
bool aSkipAssignment)
{
AssertNotAlreadyCached("bool", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetBool(aPref, aDefault);
*aCache = GetBool(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
@ -4796,13 +4840,13 @@ IntVarChanged(const char* aPref, void* aClosure)
/* static */ nsresult
Preferences::AddIntVarCache(int32_t* aCache,
const char* aPref,
const nsACString& aPref,
int32_t aDefault,
bool aSkipAssignment)
{
AssertNotAlreadyCached("int", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetInt(aPref, aDefault);
*aCache = GetInt(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
@ -4825,13 +4869,13 @@ AtomicIntVarChanged(const char* aPref, void* aClosure)
template<MemoryOrdering Order>
/* static */ nsresult
Preferences::AddAtomicIntVarCache(Atomic<int32_t, Order>* aCache,
const char* aPref,
const nsACString& aPref,
int32_t aDefault,
bool aSkipAssignment)
{
AssertNotAlreadyCached("int", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetInt(aPref, aDefault);
*aCache = GetInt(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
@ -4855,13 +4899,13 @@ UintVarChanged(const char* aPref, void* aClosure)
/* static */ nsresult
Preferences::AddUintVarCache(uint32_t* aCache,
const char* aPref,
const nsACString& aPref,
uint32_t aDefault,
bool aSkipAssignment)
{
AssertNotAlreadyCached("uint", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetUint(aPref, aDefault);
*aCache = GetUint(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
@ -4887,13 +4931,13 @@ AtomicUintVarChanged(const char* aPref, void* aClosure)
template<MemoryOrdering Order>
/* static */ nsresult
Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Order>* aCache,
const char* aPref,
const nsACString& aPref,
uint32_t aDefault,
bool aSkipAssignment)
{
AssertNotAlreadyCached("uint", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetUint(aPref, aDefault);
*aCache = GetUint(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
@ -4912,43 +4956,43 @@ Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Order>* aCache,
// limited orders are needed and therefore implemented.
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, Relaxed>*,
const char*,
const nsACString&,
bool,
bool);
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, ReleaseAcquire>*,
const char*,
const nsACString&,
bool,
bool);
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, SequentiallyConsistent>*,
const char*,
const nsACString&,
bool,
bool);
template nsresult
Preferences::AddAtomicIntVarCache(Atomic<int32_t, Relaxed>*,
const char*,
const nsACString&,
int32_t,
bool);
template nsresult
Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Relaxed>*,
const char*,
const nsACString&,
uint32_t,
bool);
template nsresult
Preferences::AddAtomicUintVarCache(Atomic<uint32_t, ReleaseAcquire>*,
const char*,
const nsACString&,
uint32_t,
bool);
template nsresult
Preferences::AddAtomicUintVarCache(Atomic<uint32_t, SequentiallyConsistent>*,
const char*,
const nsACString&,
uint32_t,
bool);
@ -4962,13 +5006,13 @@ FloatVarChanged(const char* aPref, void* aClosure)
/* static */ nsresult
Preferences::AddFloatVarCache(float* aCache,
const char* aPref,
const nsACString& aPref,
float aDefault,
bool aSkipAssignment)
{
AssertNotAlreadyCached("float", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetFloat(aPref, aDefault);
*aCache = GetFloat(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
@ -5059,12 +5103,12 @@ SetPref_String(const char* aName, const char* aDefaultValue)
}
static void
InitVarCachePref(const char* aName,
InitVarCachePref(const nsACString& aName,
bool* aCache,
bool aDefaultValue,
bool aIsStartup)
{
SetPref_bool(aName, aDefaultValue);
SetPref_bool(PromiseFlatCString(aName).get(), aDefaultValue);
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddBoolVarCache(aCache, aName, aDefaultValue, true);
@ -5073,12 +5117,12 @@ InitVarCachePref(const char* aName,
template<MemoryOrdering Order>
static void
InitVarCachePref(const char* aName,
InitVarCachePref(const nsACString& aName,
Atomic<bool, Order>* aCache,
bool aDefaultValue,
bool aIsStartup)
{
SetPref_bool(aName, aDefaultValue);
SetPref_bool(PromiseFlatCString(aName).get(), aDefaultValue);
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddAtomicBoolVarCache(aCache, aName, aDefaultValue, true);
@ -5087,12 +5131,12 @@ InitVarCachePref(const char* aName,
// XXX: this will eventually become used
MOZ_MAYBE_UNUSED static void
InitVarCachePref(const char* aName,
InitVarCachePref(const nsACString& aName,
int32_t* aCache,
int32_t aDefaultValue,
bool aIsStartup)
{
SetPref_int32_t(aName, aDefaultValue);
SetPref_int32_t(PromiseFlatCString(aName).get(), aDefaultValue);
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddIntVarCache(aCache, aName, aDefaultValue, true);
@ -5101,12 +5145,12 @@ InitVarCachePref(const char* aName,
template<MemoryOrdering Order>
static void
InitVarCachePref(const char* aName,
InitVarCachePref(const nsACString& aName,
Atomic<int32_t, Order>* aCache,
int32_t aDefaultValue,
bool aIsStartup)
{
SetPref_int32_t(aName, aDefaultValue);
SetPref_int32_t(PromiseFlatCString(aName).get(), aDefaultValue);
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddAtomicIntVarCache(aCache, aName, aDefaultValue, true);
@ -5114,12 +5158,13 @@ InitVarCachePref(const char* aName,
}
static void
InitVarCachePref(const char* aName,
InitVarCachePref(const nsACString& aName,
uint32_t* aCache,
uint32_t aDefaultValue,
bool aIsStartup)
{
SetPref_int32_t(aName, static_cast<int32_t>(aDefaultValue));
SetPref_int32_t(PromiseFlatCString(aName).get(),
static_cast<int32_t>(aDefaultValue));
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddUintVarCache(aCache, aName, aDefaultValue, true);
@ -5128,12 +5173,13 @@ InitVarCachePref(const char* aName,
template<MemoryOrdering Order>
static void
InitVarCachePref(const char* aName,
InitVarCachePref(const nsACString& aName,
Atomic<uint32_t, Order>* aCache,
uint32_t aDefaultValue,
bool aIsStartup)
{
SetPref_int32_t(aName, static_cast<int32_t>(aDefaultValue));
SetPref_int32_t(PromiseFlatCString(aName).get(),
static_cast<int32_t>(aDefaultValue));
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddAtomicUintVarCache(aCache, aName, aDefaultValue, true);
@ -5142,12 +5188,12 @@ InitVarCachePref(const char* aName,
// XXX: this will eventually become used
MOZ_MAYBE_UNUSED static void
InitVarCachePref(const char* aName,
InitVarCachePref(const nsACString& aName,
float* aCache,
float aDefaultValue,
bool aIsStartup)
{
SetPref_float(aName, aDefaultValue);
SetPref_float(PromiseFlatCString(aName).get(), aDefaultValue);
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddFloatVarCache(aCache, aName, aDefaultValue, true);
@ -5174,7 +5220,10 @@ StaticPrefs::InitAll(bool aIsStartup)
// which prevents automatic int-to-float coercion.
#define PREF(name, cpp_type, value) SetPref_##cpp_type(name, value);
#define VARCACHE_PREF(name, id, cpp_type, value) \
InitVarCachePref(name, &StaticPrefs::sVarCache_##id, value, aIsStartup);
InitVarCachePref(NS_LITERAL_CSTRING(name), \
&StaticPrefs::sVarCache_##id, \
value, \
aIsStartup);
#include "mozilla/StaticPrefList.h"
#undef PREF
#undef VARCACHE_PREF

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

@ -237,12 +237,35 @@ public:
// Adds/Removes the observer for the root pref branch. See nsIPrefBranch.idl
// for details.
static nsresult AddStrongObserver(nsIObserver* aObserver, const char* aPref);
static nsresult AddWeakObserver(nsIObserver* aObserver, const char* aPref);
static nsresult RemoveObserver(nsIObserver* aObserver, const char* aPref);
static nsresult AddStrongObserver(nsIObserver* aObserver,
const nsACString& aPref);
static nsresult AddWeakObserver(nsIObserver* aObserver,
const nsACString& aPref);
static nsresult RemoveObserver(nsIObserver* aObserver,
const nsACString& aPref);
template<int N>
static nsresult AddStrongObserver(nsIObserver* aObserver,
const char (&aPref)[N])
{
return AddStrongObserver(aObserver, nsLiteralCString(aPref));
}
template<int N>
static nsresult AddWeakObserver(nsIObserver* aObserver,
const char (&aPref)[N])
{
return AddWeakObserver(aObserver, nsLiteralCString(aPref));
}
template<int N>
static nsresult RemoveObserver(nsIObserver* aObserver, const char (&aPref)[N])
{
return RemoveObserver(aObserver, nsLiteralCString(aPref));
}
// Adds/Removes two or more observers for the root pref branch. Pass to
// aPrefs an array of const char* whose last item is nullptr.
// Note: All preference strings *must* be statically-allocated string
// literals.
static nsresult AddStrongObservers(nsIObserver* aObserver,
const char** aPrefs);
static nsresult AddWeakObservers(nsIObserver* aObserver, const char** aPrefs);
@ -250,14 +273,14 @@ public:
// Registers/Unregisters the callback function for the aPref.
static nsresult RegisterCallback(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure = nullptr)
{
return RegisterCallback(aCallback, aPref, aClosure, ExactMatch);
}
static nsresult UnregisterCallback(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure = nullptr)
{
return UnregisterCallback(aCallback, aPref, aClosure, ExactMatch);
@ -266,7 +289,7 @@ public:
// Like RegisterCallback, but also calls the callback immediately for
// initialization.
static nsresult RegisterCallbackAndCall(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure = nullptr)
{
return RegisterCallbackAndCall(aCallback, aPref, aClosure, ExactMatch);
@ -275,7 +298,7 @@ public:
// Like RegisterCallback, but registers a callback for a prefix of multiple
// pref names, not a single pref name.
static nsresult RegisterPrefixCallback(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure = nullptr)
{
return RegisterCallback(aCallback, aPref, aClosure, PrefixMatch);
@ -284,7 +307,7 @@ public:
// Like RegisterPrefixCallback, but also calls the callback immediately for
// initialization.
static nsresult RegisterPrefixCallbackAndCall(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure = nullptr)
{
return RegisterCallbackAndCall(aCallback, aPref, aClosure, PrefixMatch);
@ -293,48 +316,166 @@ public:
// Unregister a callback registered with RegisterPrefixCallback or
// RegisterPrefixCallbackAndCall.
static nsresult UnregisterPrefixCallback(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure = nullptr)
{
return UnregisterCallback(aCallback, aPref, aClosure, PrefixMatch);
}
template<int N>
static nsresult RegisterCallback(PrefChangedFunc aCallback,
const char (&aPref)[N],
void* aClosure = nullptr)
{
return RegisterCallback(
aCallback, nsLiteralCString(aPref), aClosure, ExactMatch);
}
template<int N>
static nsresult UnregisterCallback(PrefChangedFunc aCallback,
const char (&aPref)[N],
void* aClosure = nullptr)
{
return UnregisterCallback(
aCallback, nsLiteralCString(aPref), aClosure, ExactMatch);
}
template<int N>
static nsresult RegisterCallbackAndCall(PrefChangedFunc aCallback,
const char (&aPref)[N],
void* aClosure = nullptr)
{
return RegisterCallbackAndCall(
aCallback, nsLiteralCString(aPref), aClosure, ExactMatch);
}
template<int N>
static nsresult RegisterPrefixCallback(PrefChangedFunc aCallback,
const char (&aPref)[N],
void* aClosure = nullptr)
{
return RegisterCallback(
aCallback, nsLiteralCString(aPref), aClosure, PrefixMatch);
}
template<int N>
static nsresult RegisterPrefixCallbackAndCall(PrefChangedFunc aCallback,
const char (&aPref)[N],
void* aClosure = nullptr)
{
return RegisterCallbackAndCall(
aCallback, nsLiteralCString(aPref), aClosure, PrefixMatch);
}
template<int N>
static nsresult UnregisterPrefixCallback(PrefChangedFunc aCallback,
const char (&aPref)[N],
void* aClosure = nullptr)
{
return UnregisterCallback(
aCallback, nsLiteralCString(aPref), aClosure, PrefixMatch);
}
// Adds the aVariable to cache table. |aVariable| must be a pointer for a
// static variable. The value will be modified when the pref value is changed
// but note that even if you modified it, the value isn't assigned to the
// pref.
static nsresult AddBoolVarCache(bool* aVariable,
const char* aPref,
const nsACString& aPref,
bool aDefault = false,
bool aSkipAssignment = false);
template<MemoryOrdering Order>
static nsresult AddAtomicBoolVarCache(Atomic<bool, Order>* aVariable,
const char* aPref,
const nsACString& aPref,
bool aDefault = false,
bool aSkipAssignment = false);
static nsresult AddIntVarCache(int32_t* aVariable,
const char* aPref,
const nsACString& aPref,
int32_t aDefault = 0,
bool aSkipAssignment = false);
template<MemoryOrdering Order>
static nsresult AddAtomicIntVarCache(Atomic<int32_t, Order>* aVariable,
const char* aPref,
const nsACString& aPref,
int32_t aDefault = 0,
bool aSkipAssignment = false);
static nsresult AddUintVarCache(uint32_t* aVariable,
const char* aPref,
const nsACString& aPref,
uint32_t aDefault = 0,
bool aSkipAssignment = false);
template<MemoryOrdering Order>
static nsresult AddAtomicUintVarCache(Atomic<uint32_t, Order>* aVariable,
const char* aPref,
const nsACString& aPref,
uint32_t aDefault = 0,
bool aSkipAssignment = false);
static nsresult AddFloatVarCache(float* aVariable,
const char* aPref,
const nsACString& aPref,
float aDefault = 0.0f,
bool aSkipAssignment = false);
template<int N>
static nsresult AddBoolVarCache(bool* aVariable,
const char (&aPref)[N],
bool aDefault = false,
bool aSkipAssignment = false)
{
return AddBoolVarCache(
aVariable, nsLiteralCString(aPref), aDefault, aSkipAssignment);
}
template<MemoryOrdering Order, int N>
static nsresult AddAtomicBoolVarCache(Atomic<bool, Order>* aVariable,
const char (&aPref)[N],
bool aDefault = false,
bool aSkipAssignment = false)
{
return AddAtomicBoolVarCache<Order>(
aVariable, nsLiteralCString(aPref), aDefault, aSkipAssignment);
}
template<int N>
static nsresult AddIntVarCache(int32_t* aVariable,
const char (&aPref)[N],
int32_t aDefault = 0,
bool aSkipAssignment = false)
{
return AddIntVarCache(
aVariable, nsLiteralCString(aPref), aDefault, aSkipAssignment);
}
template<MemoryOrdering Order, int N>
static nsresult AddAtomicIntVarCache(Atomic<int32_t, Order>* aVariable,
const char (&aPref)[N],
int32_t aDefault = 0,
bool aSkipAssignment = false)
{
return AddAtomicIntVarCache<Order>(
aVariable, nsLiteralCString(aPref), aDefault, aSkipAssignment);
}
template<int N>
static nsresult AddUintVarCache(uint32_t* aVariable,
const char (&aPref)[N],
uint32_t aDefault = 0,
bool aSkipAssignment = false)
{
return AddUintVarCache(
aVariable, nsLiteralCString(aPref), aDefault, aSkipAssignment);
}
template<MemoryOrdering Order, int N>
static nsresult AddAtomicUintVarCache(Atomic<uint32_t, Order>* aVariable,
const char (&aPref)[N],
uint32_t aDefault = 0,
bool aSkipAssignment = false)
{
return AddAtomicUintVarCache<Order>(
aVariable, nsLiteralCString(aPref), aDefault, aSkipAssignment);
}
template<int N>
static nsresult AddFloatVarCache(float* aVariable,
const char (&aPref)[N],
float aDefault = 0.0f,
bool aSkipAssignment = false)
{
return AddFloatVarCache(
aVariable, nsLiteralCString(aPref), aDefault, aSkipAssignment);
}
// When a content process is created these methods are used to pass changed
// prefs in bulk from the parent process, via shared memory.
static void SerializePreferences(nsCString& aStr);
@ -405,19 +546,45 @@ private:
bool aIsStartup);
static nsresult RegisterCallback(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure,
MatchKind aMatchKind,
bool aIsPriority = false);
static nsresult UnregisterCallback(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure,
MatchKind aMatchKind);
static nsresult RegisterCallbackAndCall(PrefChangedFunc aCallback,
const char* aPref,
const nsACString& aPref,
void* aClosure,
MatchKind aMatchKind);
static nsresult RegisterCallback(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
MatchKind aMatchKind,
bool aIsPriority = false)
{
return RegisterCallback(
aCallback, nsDependentCString(aPref), aClosure, aMatchKind, aIsPriority);
}
static nsresult UnregisterCallback(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
MatchKind aMatchKind)
{
return UnregisterCallback(
aCallback, nsDependentCString(aPref), aClosure, aMatchKind);
}
static nsresult RegisterCallbackAndCall(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
MatchKind aMatchKind)
{
return RegisterCallbackAndCall(
aCallback, nsDependentCString(aPref), aClosure, aMatchKind);
}
private:
nsCOMPtr<nsIFile> mCurrentFile;
bool mDirty = false;

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

@ -48,10 +48,14 @@ template<typename T>
using StripAtomic = typename StripAtomicImpl<T>::Type;
template<typename T>
struct IsAtomic : FalseType {};
struct IsAtomic : FalseType
{
};
template<typename T, MemoryOrdering Order>
struct IsAtomic<Atomic<T, Order>> : TrueType {};
struct IsAtomic<Atomic<T, Order>> : TrueType
{
};
class StaticPrefs
{
@ -70,8 +74,10 @@ class StaticPrefs
#define VARCACHE_PREF(str, id, cpp_type, default_value) \
private: \
static cpp_type sVarCache_##id; \
\
public: \
static StripAtomic<cpp_type> id() { \
static StripAtomic<cpp_type> id() \
{ \
MOZ_ASSERT(IsAtomic<cpp_type>::value || NS_IsMainThread(), \
"Non-atomic static pref '" str \
"' being accessed on background thread"); \

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

@ -5,6 +5,10 @@
#include "nsISupports.idl"
%{C++
#include "nsLiteralString.h"
%}
interface nsIObserver;
/**
@ -23,7 +27,7 @@ interface nsIObserver;
* @see nsIPrefService
*/
[scriptable, uuid(55d25e49-793f-4727-a69f-de8b15f4b985)]
[scriptable, builtinclass, uuid(55d25e49-793f-4727-a69f-de8b15f4b985)]
interface nsIPrefBranch : nsISupports
{
@ -421,7 +425,8 @@ interface nsIPrefBranch : nsISupports
* @see nsIObserver
* @see removeObserver
*/
void addObserver(in string aDomain, in nsIObserver aObserver,
[binaryname(AddObserverImpl)]
void addObserver(in ACString aDomain, in nsIObserver aObserver,
[optional] in boolean aHoldWeak);
/**
@ -438,7 +443,34 @@ interface nsIPrefBranch : nsISupports
* @see nsIObserver
* @see addObserver
*/
void removeObserver(in string aDomain, in nsIObserver aObserver);
[binaryname(RemoveObserverImpl)]
void removeObserver(in ACString aDomain, in nsIObserver aObserver);
%{C++
nsresult AddObserver(const nsACString& aDomain, nsIObserver* aObserver,
bool aHoldWeak = false)
{
return AddObserverImpl(aDomain, aObserver, aHoldWeak);
}
template <int N>
nsresult AddObserver(const char (&aDomain)[N], nsIObserver* aObserver,
bool aHoldWeak = false)
{
return AddObserverImpl(nsLiteralCString(aDomain), aObserver, aHoldWeak);
}
nsresult RemoveObserver(const nsACString& aDomain, nsIObserver* aObserver)
{
return RemoveObserverImpl(aDomain, aObserver);
}
template <int N>
nsresult RemoveObserver(const char (&aDomain)[N], nsIObserver* aObserver)
{
return RemoveObserverImpl(nsLiteralCString(aDomain), aObserver);
}
%}
};

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

@ -30,91 +30,92 @@ VarChanged(const char* aPrefName, void* aData)
}
void
SetFunc(const char* aPrefName, bool aValue)
SetFunc(const nsCString& aPrefName, bool aValue)
{
nsresult rv = Preferences::SetBool(aPrefName, aValue);
nsresult rv = Preferences::SetBool(aPrefName.get(), aValue);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
SetFunc(const char* aPrefName, int32_t aValue)
SetFunc(const nsCString& aPrefName, int32_t aValue)
{
nsresult rv = Preferences::SetInt(aPrefName, aValue);
nsresult rv = Preferences::SetInt(aPrefName.get(), aValue);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
SetFunc(const char* aPrefName, uint32_t aValue)
SetFunc(const nsCString& aPrefName, uint32_t aValue)
{
nsresult rv = Preferences::SetUint(aPrefName, aValue);
nsresult rv = Preferences::SetUint(aPrefName.get(), aValue);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
SetFunc(const char* aPrefName, float aValue)
SetFunc(const nsCString& aPrefName, float aValue)
{
nsresult rv = Preferences::SetFloat(aPrefName, aValue);
nsresult rv = Preferences::SetFloat(aPrefName.get(), aValue);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(bool* aVar, const char* aPrefName)
AddVarCacheFunc(bool* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddBoolVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(Atomic<bool, Relaxed>* aVar, const char* aPrefName)
AddVarCacheFunc(Atomic<bool, Relaxed>* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddAtomicBoolVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(Atomic<bool, ReleaseAcquire>* aVar, const char* aPrefName)
AddVarCacheFunc(Atomic<bool, ReleaseAcquire>* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddAtomicBoolVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(int32_t* aVar, const char* aPrefName)
AddVarCacheFunc(int32_t* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddIntVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(Atomic<int32_t, Relaxed>* aVar, const char* aPrefName)
AddVarCacheFunc(Atomic<int32_t, Relaxed>* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddAtomicIntVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(uint32_t* aVar, const char* aPrefName)
AddVarCacheFunc(uint32_t* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddUintVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(Atomic<uint32_t, Relaxed>* aVar, const char* aPrefName)
AddVarCacheFunc(Atomic<uint32_t, Relaxed>* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddAtomicUintVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(Atomic<uint32_t, ReleaseAcquire>* aVar, const char* aPrefName)
AddVarCacheFunc(Atomic<uint32_t, ReleaseAcquire>* aVar,
const nsCString& aPrefName)
{
nsresult rv = Preferences::AddAtomicUintVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
}
void
AddVarCacheFunc(float* aVar, const char* aPrefName)
AddVarCacheFunc(float* aVar, const nsCString& aPrefName)
{
nsresult rv = Preferences::AddFloatVarCache(aVar, aPrefName);
ASSERT_TRUE(NS_SUCCEEDED(rv));
@ -122,13 +123,16 @@ AddVarCacheFunc(float* aVar, const char* aPrefName)
template<typename T, typename U = T>
void
RunTest(const char* aPrefName1, const char* aPrefName2, T aValue1, T aValue2)
RunTest(const nsCString& aPrefName1,
const nsCString& aPrefName2,
T aValue1,
T aValue2)
{
static U var1, var2;
static Closure<T, U> closure1, closure2;
nsresult rv;
ASSERT_STRNE(aPrefName1, aPrefName2);
ASSERT_STRNE(aPrefName1.get(), aPrefName2.get());
ASSERT_NE(aValue1, aValue2);
// Call Add*VarCache first.
@ -166,52 +170,79 @@ RunTest(const char* aPrefName1, const char* aPrefName2, T aValue1, T aValue2)
TEST(CallbackAndVarCacheOrder, Bool)
{
RunTest<bool>("test_pref.bool.1", "test_pref.bool.2", false, true);
RunTest<bool>(NS_LITERAL_CSTRING("test_pref.bool.1"),
NS_LITERAL_CSTRING("test_pref.bool.2"),
false,
true);
}
TEST(CallbackAndVarCacheOrder, AtomicBoolRelaxed)
{
RunTest<bool, Atomic<bool, Relaxed>>(
"test_pref.atomic_bool.1", "test_pref.atomic_bool.2", false, true);
NS_LITERAL_CSTRING("test_pref.atomic_bool.1"),
NS_LITERAL_CSTRING("test_pref.atomic_bool.2"),
false,
true);
}
TEST(CallbackAndVarCacheOrder, AtomicBoolReleaseAcquire)
{
RunTest<bool, Atomic<bool, ReleaseAcquire>>(
"test_pref.atomic_bool.3", "test_pref.atomic_bool.4", false, true);
NS_LITERAL_CSTRING("test_pref.atomic_bool.3"),
NS_LITERAL_CSTRING("test_pref.atomic_bool.4"),
false,
true);
}
TEST(CallbackAndVarCacheOrder, Int)
{
RunTest<int32_t>("test_pref.int.1", "test_pref.int.2", -2, 3);
RunTest<int32_t>(NS_LITERAL_CSTRING("test_pref.int.1"),
NS_LITERAL_CSTRING("test_pref.int.2"),
-2,
3);
}
TEST(CallbackAndVarCacheOrder, AtomicInt)
{
RunTest<int32_t, Atomic<int32_t, Relaxed>>(
"test_pref.atomic_int.1", "test_pref.atomic_int.2", -3, 4);
NS_LITERAL_CSTRING("test_pref.atomic_int.1"),
NS_LITERAL_CSTRING("test_pref.atomic_int.2"),
-3,
4);
}
TEST(CallbackAndVarCacheOrder, Uint)
{
RunTest<uint32_t>("test_pref.uint.1", "test_pref.uint.2", 4u, 5u);
RunTest<uint32_t>(NS_LITERAL_CSTRING("test_pref.uint.1"),
NS_LITERAL_CSTRING("test_pref.uint.2"),
4u,
5u);
}
TEST(CallbackAndVarCacheOrder, AtomicUintRelaxed)
{
RunTest<uint32_t, Atomic<uint32_t, Relaxed>>(
"test_pref.atomic_uint.1", "test_pref.atomic_uint.2", 6u, 7u);
NS_LITERAL_CSTRING("test_pref.atomic_uint.1"),
NS_LITERAL_CSTRING("test_pref.atomic_uint.2"),
6u,
7u);
}
TEST(CallbackAndVarCacheOrder, AtomicUintReleaseAcquire)
{
RunTest<uint32_t, Atomic<uint32_t, ReleaseAcquire>>(
"test_pref.atomic_uint.3", "test_pref.atomic_uint.4", 8u, 9u);
NS_LITERAL_CSTRING("test_pref.atomic_uint.3"),
NS_LITERAL_CSTRING("test_pref.atomic_uint.4"),
8u,
9u);
}
TEST(CallbackAndVarCacheOrder, Float)
{
RunTest<float>("test_pref.float.1", "test_pref.float.2", -10.0f, 11.0f);
RunTest<float>(NS_LITERAL_CSTRING("test_pref.float.1"),
NS_LITERAL_CSTRING("test_pref.float.2"),
-10.0f,
11.0f);
}
} // namespace mozilla

6
netwerk/cache/nsCacheService.cpp поставляемый
Просмотреть файл

@ -339,7 +339,9 @@ nsCacheProfilePrefObserver::Install()
if (!branch) return NS_ERROR_FAILURE;
for (auto& pref : prefList) {
rv = branch->AddObserver(pref, this, false);
nsCString prefStr;
prefStr.AssignLiteral(pref, strlen(pref));
rv = branch->AddObserver(prefStr, this, false);
if (NS_FAILED(rv))
rv2 = rv;
}
@ -382,7 +384,7 @@ nsCacheProfilePrefObserver::Remove()
if (!prefs)
return;
for (auto& pref : prefList)
prefs->RemoveObserver(pref, this); // remove cache pref observers
prefs->RemoveObserver(nsDependentCString(pref), this); // remove cache pref observers
}
void

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

@ -322,7 +322,8 @@ nsExpatDriver::HandleStartElement(const char16_t *aValue,
if (mSink) {
nsresult rv = mSink->
HandleStartElement(aValue, aAtts, attrArrayLength,
XML_GetCurrentLineNumber(mExpatParser));
XML_GetCurrentLineNumber(mExpatParser),
XML_GetCurrentColumnNumber(mExpatParser));
MaybeStopParser(rv);
}

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

@ -28,11 +28,13 @@ interface nsIExpatSink : nsISupports
* present in aAtts.
* @param aAttsCount the number of elements in aAtts.
* @param aLineNumber the line number of the start tag in the data stream.
* @param aColumnNumber the column number of the start tag in the data stream.
*/
void HandleStartElement(in wstring aName,
[array, size_is(aAttsCount)] in wstring aAtts,
in unsigned long aAttsCount,
in unsigned long aLineNumber);
in unsigned long aLineNumber,
in unsigned long aColumnNumber);
/**
* Called to handle the closing tag of an element.

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

@ -79,7 +79,8 @@ NS_IMETHODIMP
nsSAXXMLReader::HandleStartElement(const char16_t *aName,
const char16_t **aAtts,
uint32_t aAttsCount,
uint32_t aLineNumber)
uint32_t aLineNumber,
uint32_t aColumnNumber)
{
if (!mContentHandler)
return NS_OK;

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

@ -101,7 +101,7 @@ def iter_readelf_symbols(target, binary):
def iter_readelf_dynamic(target, binary):
for line in get_output(target['readelf'], '-d', binary):
data = line.split(None, 2)
if data and data[0].startswith('0x'):
if data and len(data) == 3 and data[0].startswith('0x'):
yield data[1].rstrip(')').lstrip('('), data[2]

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

@ -1,4 +0,0 @@
[script-src-1_4.html]
[eval() should throw without 'unsafe-eval' keyword source in script-src directive.]
expected: FAIL

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

@ -7,7 +7,8 @@
var watcher = new EventWatcher(t, document, 'securitypolicyviolation');
watcher.wait_for('securitypolicyviolation').then(t.step_func_done(e => {
assert_equals(e.blockedURI, "eval");
assert_equals(e.lineNumber, 14);
assert_equals(e.lineNumber, 15);
assert_equals(e.columnNumber, 12);
}));
try {

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

@ -7,7 +7,8 @@
var watcher = new EventWatcher(t, document, 'securitypolicyviolation');
watcher.wait_for('securitypolicyviolation').then(t.step_func_done(e => {
assert_equals(e.blockedURI, "inline");
assert_equals(e.lineNumber, 14);
assert_equals(e.lineNumber, 15);
assert_equals(e.columnNumber, 1);
}));
}, "Inline violations have a blockedURI of 'inline'");
</script>

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

@ -35,19 +35,22 @@
}))
.then(t.step_func(e => {
assert_equals(e.blockedURI, "inline");
assert_equals(e.lineNumber, 132);
assert_equals(e.lineNumber, 135);
assert_equals(e.columnNumber, 7);
assert_equals(e.target, document, "Disconnected elements target the document");
return watcher.wait_for('securitypolicyviolation');
}))
.then(t.step_func(e => {
assert_equals(e.blockedURI, "inline");
assert_equals(e.lineNumber, 143);
assert_equals(e.lineNumber, 146);
assert_equals(e.columnNumber, 7);
assert_equals(e.target, document, "Elements disconnected after triggering target the document.");
return watcher.wait_for('securitypolicyviolation');
}))
.then(t.step_func(e => {
assert_equals(e.blockedURI, "inline");
assert_equals(e.lineNumber, 157);
assert_equals(e.lineNumber, 160);
assert_equals(e.columnNumber, 7);
assert_equals(e.target, document, "Elements in DocumentFragments target the document");
}))
.then(t.step_func_done(_ => {

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

@ -282,9 +282,9 @@ namespace {
NS_DECL_NSIOBSERVER
static already_AddRefed<AtomSetPref>
Create(const char* aPref)
Create(const nsCString& aPref)
{
RefPtr<AtomSetPref> self = new AtomSetPref(aPref);
RefPtr<AtomSetPref> self = new AtomSetPref(aPref.get());
Preferences::AddWeakObserver(self, aPref);
return self.forget();
}
@ -354,7 +354,7 @@ WebExtensionPolicy::IsRestrictedURI(const URLInfo &aURI)
{
static RefPtr<AtomSetPref> domains;
if (!domains) {
domains = AtomSetPref::Create(kRestrictedDomainPref);
domains = AtomSetPref::Create(nsLiteralCString(kRestrictedDomainPref));
ClearOnShutdown(&domains);
}

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

@ -40,13 +40,19 @@ var LoginHelper = {
return this.debug ? "debug" : "warn";
};
// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
let consoleOptions = {
maxLogLevel: getMaxLogLevel(),
prefix: aLogPrefix,
};
let logger = new ConsoleAPI(consoleOptions);
let logger;
function getConsole() {
if (!logger) {
// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
let consoleOptions = {
maxLogLevel: getMaxLogLevel(),
prefix: aLogPrefix,
};
logger = new ConsoleAPI(consoleOptions);
}
return logger;
}
// Watch for pref changes and update this.debug and the maxLogLevel for created loggers
Services.prefs.addObserver("signon.", () => {
@ -54,10 +60,31 @@ var LoginHelper = {
this.formlessCaptureEnabled = Services.prefs.getBoolPref("signon.formlessCapture.enabled");
this.schemeUpgrades = Services.prefs.getBoolPref("signon.schemeUpgrades");
this.insecureAutofill = Services.prefs.getBoolPref("signon.autofillForms.http");
logger.maxLogLevel = getMaxLogLevel();
if (logger) {
logger.maxLogLevel = getMaxLogLevel();
}
});
return logger;
return {
log: (...args) => {
if (this.debug) {
getConsole().log(...args);
}
},
error: (...args) => {
getConsole().error(...args);
},
debug: (...args) => {
if (this.debug) {
getConsole().debug(...args);
}
},
warn: (...args) => {
if (this.debug) {
getConsole().warn(...args);
}
},
};
},
/**

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

@ -30,6 +30,7 @@ static Atomic<bool> gShuttingDown(false);
static const char* kObservedPrefs[] = {
PREF_PASSWORD_ALLOW_TABLE,
nullptr,
};
// -------------------------------------------------------------------------
@ -273,9 +274,7 @@ LoginReputationService::Enable()
nsresult rv = mLoginWhitelist->Init();
Unused << NS_WARN_IF(NS_FAILED(rv));
for (const char* pref : kObservedPrefs) {
Preferences::AddStrongObserver(this, pref);
}
Preferences::AddStrongObservers(this, kObservedPrefs);
return NS_OK;
}
@ -294,9 +293,7 @@ LoginReputationService::Disable()
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
for (const char* pref : kObservedPrefs) {
prefs->RemoveObserver(pref, this);
}
Preferences::RemoveObservers(this, kObservedPrefs);
}
return NS_OK;

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

@ -1673,7 +1673,7 @@ nsUrlClassifierDBService::Init()
GETHASH_NOISE_DEFAULT);
for (uint8_t i = 0; i < kObservedPrefs.Length(); i++) {
Preferences::AddStrongObserver(this, kObservedPrefs[i].get());
Preferences::AddStrongObserver(this, kObservedPrefs[i]);
}
return NS_OK;
@ -2496,7 +2496,7 @@ nsUrlClassifierDBService::Shutdown()
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
for (uint8_t i = 0; i < kObservedPrefs.Length(); i++) {
prefs->RemoveObserver(kObservedPrefs[i].get(), this);
prefs->RemoveObserver(kObservedPrefs[i], this);
}
}

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

@ -264,7 +264,7 @@ public:
for (jni::Object::LocalRef& nameRef : nameRefArray) {
jni::String::LocalRef nameStr(std::move(nameRef));
MOZ_ALWAYS_SUCCEEDS(Preferences::AddStrongObserver(
appShell, nameStr->ToCString().get()));
appShell, nameStr->ToCString()));
}
}
@ -279,7 +279,7 @@ public:
for (jni::Object::LocalRef& nameRef : nameRefArray) {
jni::String::LocalRef nameStr(std::move(nameRef));
MOZ_ALWAYS_SUCCEEDS(Preferences::RemoveObserver(
appShell, nameStr->ToCString().get()));
appShell, nameStr->ToCString()));
}
}

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

@ -3393,7 +3393,10 @@ debug_RegisterPrefCallbacks()
if (obs) {
// Register callbacks for when these change
Preferences::AddStrongObserver(obs, debug_PrefValues[i].name);
nsCString name;
name.AssignLiteral(debug_PrefValues[i].name,
strlen(debug_PrefValues[i].name));
Preferences::AddStrongObserver(obs, name);
}
}
}

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

@ -49,7 +49,7 @@ using namespace mozilla;
// specific signal occurs.
static Atomic<int> sDumpPipeWriteFd(-1);
const char* const FifoWatcher::kPrefName =
const char FifoWatcher::kPrefName[] =
"memory_info_dumper.watch_fifo.enabled";
static void

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

@ -110,7 +110,10 @@ public:
/**
* The name of the preference used to enable/disable the FifoWatcher.
*/
static const char* const kPrefName;
// The length of this array must match the size of the string constant in
// the definition in nsDumpUtils.cpp. A mismatch will result in a compile-time
// error.
static const char kPrefName[38];
static FifoWatcher* GetSingleton();