diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:40:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:40:47 +0000 |
commit | 46db793222dee55d0b846c6ba99a39e2d969c52a (patch) | |
tree | d95f8ea0fb9c9c4eb9ae55c70faa2bc02a7bcea4 /toolkit/components | |
parent | Adding upstream version 115.9.1esr. (diff) | |
download | firefox-esr-46db793222dee55d0b846c6ba99a39e2d969c52a.tar.xz firefox-esr-46db793222dee55d0b846c6ba99a39e2d969c52a.zip |
Adding upstream version 115.10.0esr.upstream/115.10.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components')
11 files changed, 288 insertions, 37 deletions
diff --git a/toolkit/components/glean/bindings/private/TimingDistribution.cpp b/toolkit/components/glean/bindings/private/TimingDistribution.cpp index 78aad6d4cd..5a1a6d3daf 100644 --- a/toolkit/components/glean/bindings/private/TimingDistribution.cpp +++ b/toolkit/components/glean/bindings/private/TimingDistribution.cpp @@ -25,7 +25,7 @@ extern "C" NS_EXPORT void GIFFT_TimingDistributionStart( auto mirrorId = mozilla::glean::HistogramIdForMetric(aMetricId); if (mirrorId) { mozilla::glean::GetTimerIdToStartsLock().apply([&](auto& lock) { - auto tuple = std::make_tuple(aMetricId, aTimerId); + auto tuple = mozilla::glean::MetricTimerTuple{aMetricId, aTimerId}; // It should be all but impossible for anyone to have already inserted // this timer for this metric given the monotonicity of timer ids. (void)NS_WARN_IF(lock.ref()->Remove(tuple)); @@ -40,7 +40,8 @@ extern "C" NS_EXPORT void GIFFT_TimingDistributionStopAndAccumulate( auto mirrorId = mozilla::glean::HistogramIdForMetric(aMetricId); if (mirrorId) { mozilla::glean::GetTimerIdToStartsLock().apply([&](auto& lock) { - auto optStart = lock.ref()->Extract(std::make_tuple(aMetricId, aTimerId)); + auto tuple = mozilla::glean::MetricTimerTuple{aMetricId, aTimerId}; + auto optStart = lock.ref()->Extract(tuple); // The timer might not be in the map to be removed if it's already been // cancelled or stop_and_accumulate'd. if (!NS_WARN_IF(!optStart)) { @@ -67,8 +68,8 @@ extern "C" NS_EXPORT void GIFFT_TimingDistributionCancel( mozilla::glean::GetTimerIdToStartsLock().apply([&](auto& lock) { // The timer might not be in the map to be removed if it's already been // cancelled or stop_and_accumulate'd. - (void)NS_WARN_IF( - !lock.ref()->Remove(std::make_tuple(aMetricId, aTimerId))); + auto tuple = mozilla::glean::MetricTimerTuple{aMetricId, aTimerId}; + (void)NS_WARN_IF(!lock.ref()->Remove(tuple)); }); } } diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/gifft.jinja2 b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/gifft.jinja2 index 4a58ef5411..9d0c10cdf6 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/gifft.jinja2 +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/gifft.jinja2 @@ -35,7 +35,10 @@ using Telemetry::{{ probe_type }}ID; using MetricId = uint32_t; // Same type as in api/src/private/mod.rs using TimerId = uint64_t; // Same as in TimingDistribution.h. -using MetricTimerTuple = std::tuple<MetricId, TimerId>; +struct MetricTimerTuple { + MetricId mMetricId; + TimerId mTimerId; +}; class MetricTimerTupleHashKey : public PLDHashEntryHdr { public: using KeyType = const MetricTimerTuple&; @@ -49,15 +52,17 @@ class MetricTimerTupleHashKey : public PLDHashEntryHdr { KeyType GetKey() const { return mValue; } bool KeyEquals(KeyTypePointer aKey) const { - return std::get<0>(*aKey) == std::get<0>(mValue) && std::get<1>(*aKey) == std::get<1>(mValue); + return aKey->mMetricId == mValue.mMetricId && + aKey->mTimerId == mValue.mTimerId; } static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } static PLDHashNumber HashKey(KeyTypePointer aKey) { // Chosen because this is how nsIntegralHashKey does it. - return HashGeneric(std::get<0>(*aKey), std::get<1>(*aKey)); + return HashGeneric(aKey->mMetricId, aKey->mTimerId); } enum { ALLOW_MEMMOVE = true }; + static_assert(std::is_trivially_copyable_v<MetricTimerTuple>); private: const MetricTimerTuple mValue; @@ -170,6 +175,7 @@ class ScalarIDHashKey : public PLDHashEntryHdr { return static_cast<std::underlying_type<ScalarID>::type>(*aKey); } enum { ALLOW_MEMMOVE = true }; + static_assert(std::is_trivially_copyable_v<ScalarID>); private: const ScalarID mValue; diff --git a/toolkit/components/glean/tests/pytest/gifft_output_Histogram b/toolkit/components/glean/tests/pytest/gifft_output_Histogram index b13df96594..f0e4c3d047 100644 --- a/toolkit/components/glean/tests/pytest/gifft_output_Histogram +++ b/toolkit/components/glean/tests/pytest/gifft_output_Histogram @@ -28,7 +28,10 @@ using Telemetry::HistogramID; using MetricId = uint32_t; // Same type as in api/src/private/mod.rs using TimerId = uint64_t; // Same as in TimingDistribution.h. -using MetricTimerTuple = std::tuple<MetricId, TimerId>; +struct MetricTimerTuple { + MetricId mMetricId; + TimerId mTimerId; +}; class MetricTimerTupleHashKey : public PLDHashEntryHdr { public: using KeyType = const MetricTimerTuple&; @@ -42,15 +45,17 @@ class MetricTimerTupleHashKey : public PLDHashEntryHdr { KeyType GetKey() const { return mValue; } bool KeyEquals(KeyTypePointer aKey) const { - return std::get<0>(*aKey) == std::get<0>(mValue) && std::get<1>(*aKey) == std::get<1>(mValue); + return aKey->mMetricId == mValue.mMetricId && + aKey->mTimerId == mValue.mTimerId; } static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } static PLDHashNumber HashKey(KeyTypePointer aKey) { // Chosen because this is how nsIntegralHashKey does it. - return HashGeneric(std::get<0>(*aKey), std::get<1>(*aKey)); + return HashGeneric(aKey->mMetricId, aKey->mTimerId); } enum { ALLOW_MEMMOVE = true }; + static_assert(std::is_trivially_copyable_v<MetricTimerTuple>); private: const MetricTimerTuple mValue; diff --git a/toolkit/components/glean/tests/pytest/gifft_output_Scalar b/toolkit/components/glean/tests/pytest/gifft_output_Scalar index 66d25a2629..1ea7517407 100644 --- a/toolkit/components/glean/tests/pytest/gifft_output_Scalar +++ b/toolkit/components/glean/tests/pytest/gifft_output_Scalar @@ -92,6 +92,7 @@ class ScalarIDHashKey : public PLDHashEntryHdr { return static_cast<std::underlying_type<ScalarID>::type>(*aKey); } enum { ALLOW_MEMMOVE = true }; + static_assert(std::is_trivially_copyable_v<ScalarID>); private: const ScalarID mValue; diff --git a/toolkit/components/normandy/actions/ShowHeartbeatAction.sys.mjs b/toolkit/components/normandy/actions/ShowHeartbeatAction.sys.mjs index d571e46167..1f6be470aa 100644 --- a/toolkit/components/normandy/actions/ShowHeartbeatAction.sys.mjs +++ b/toolkit/components/normandy/actions/ShowHeartbeatAction.sys.mjs @@ -76,10 +76,7 @@ export class ShowHeartbeatAction extends BaseAction { learnMoreUrl, postAnswerUrl: await this.generatePostAnswerURL(recipe), flowId: lazy.NormandyUtils.generateUuid(), - // Recipes coming from Nimbus won't have a revision_id. - ...(Object.hasOwn(recipe, "revision_id") - ? { surveyVersion: recipe.revision_id } - : {}), + surveyVersion: recipe.revision_id, }); heartbeat.eventEmitter.once( diff --git a/toolkit/components/normandy/lib/LegacyHeartbeat.sys.mjs b/toolkit/components/normandy/lib/LegacyHeartbeat.sys.mjs index 501c9f70af..93c24faf5d 100644 --- a/toolkit/components/normandy/lib/LegacyHeartbeat.sys.mjs +++ b/toolkit/components/normandy/lib/LegacyHeartbeat.sys.mjs @@ -43,6 +43,7 @@ export const LegacyHeartbeat = { capabilities: ["action.show-heartbeat"], filter_expression: "true", use_only_baseline_capabilities: true, + revision_id: "1", // Required for the Heartbeat telemetry ping. }; }, }; diff --git a/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js b/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js index 465e5c1040..a40fa7350e 100644 --- a/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js +++ b/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js @@ -9,6 +9,9 @@ const { BaseAction } = ChromeUtils.importESModule( const { ClientEnvironment } = ChromeUtils.importESModule( "resource://normandy/lib/ClientEnvironment.sys.mjs" ); +const { EventEmitter } = ChromeUtils.importESModule( + "resource://normandy/lib/EventEmitter.sys.mjs" +); const { Heartbeat } = ChromeUtils.importESModule( "resource://normandy/lib/Heartbeat.sys.mjs" ); @@ -27,6 +30,9 @@ const { RecipeRunner } = ChromeUtils.importESModule( const { RemoteSettings } = ChromeUtils.importESModule( "resource://services-settings/remote-settings.sys.mjs" ); +const { JsonSchema } = ChromeUtils.importESModule( + "resource://gre/modules/JsonSchema.sys.mjs" +); const SURVEY = { surveyId: "a survey", @@ -39,9 +45,80 @@ const SURVEY = { repeatOption: "once", }; +// See properties.payload in +// https://github.com/mozilla-services/mozilla-pipeline-schemas/blob/main/schemas/telemetry/heartbeat/heartbeat.4.schema.json + +const PAYLOAD_SCHEMA = { + additionalProperties: false, + anyOf: [ + { + required: ["closedTS"], + }, + { + required: ["windowClosedTS"], + }, + ], + properties: { + closedTS: { + minimum: 0, + type: "integer", + }, + engagedTS: { + minimum: 0, + type: "integer", + }, + expiredTS: { + minimum: 0, + type: "integer", + }, + flowId: { + pattern: + "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$", + type: "string", + }, + learnMoreTS: { + minimum: 0, + type: "integer", + }, + offeredTS: { + minimum: 0, + type: "integer", + }, + score: { + minimum: 1, + type: "integer", + }, + surveyId: { + type: "string", + }, + surveyVersion: { + pattern: "^([0-9]+|[a-fA-F0-9]{64})$", + type: "string", + }, + testing: { + type: "boolean", + }, + version: { + maximum: 1, + minimum: 1, + type: "number", + }, + votedTS: { + minimum: 0, + type: "integer", + }, + windowClosedTS: { + minimum: 0, + type: "integer", + }, + }, + required: ["version", "flowId", "offeredTS", "surveyId", "surveyVersion"], + type: "object", +}; + function assertSurvey(actual, expected) { for (const key of Object.keys(actual)) { - if (["postAnswerUrl", "flowId"].includes(key)) { + if (["flowId", "postAnswerUrl", "surveyVersion"].includes(key)) { continue; } @@ -52,6 +129,7 @@ function assertSurvey(actual, expected) { ); } + Assert.equal(actual.surveyVersion, "1"); Assert.ok(actual.postAnswerUrl.startsWith(expected.postAnswerUrl)); } @@ -86,3 +164,62 @@ decorate_task( } } ); + +decorate_task( + withClearStorage(), + async function testLegacyHeartbeatPingPayload() { + const sandbox = sinon.createSandbox(); + + const cleanupEnrollment = await ExperimentFakes.enrollWithFeatureConfig({ + featureId: "legacyHeartbeat", + value: { + survey: SURVEY, + }, + }); + + const client = RemoteSettings("normandy-recipes-capabilities"); + sandbox.stub(client, "get").resolves([]); + + // Override Heartbeat so we can get the instance and manipulate it directly. + let resolveHeartbeatPromise; + const heartbeatPromise = new Promise(resolve => { + resolveHeartbeatPromise = resolve; + }); + class TestHeartbeat extends Heartbeat { + constructor(...args) { + super(...args); + resolveHeartbeatPromise(this); + } + } + ShowHeartbeatAction.overrideHeartbeatForTests(TestHeartbeat); + + try { + await RecipeRunner.run(); + const heartbeat = await heartbeatPromise; + // We are going to simulate the timer timing out, so we do not want it to + // *actually* time out. + heartbeat.endTimerIfPresent("surveyEndTimer"); + + const telemetrySentPromise = new Promise(resolve => { + heartbeat.eventEmitter.once("TelemetrySent", payload => + resolve(payload) + ); + }); + + // This method would be triggered when the timer timed out. This will + // trigger telemetry to be submitted. + heartbeat.close(); + + const payload = await telemetrySentPromise; + + const result = JsonSchema.validate(payload, PAYLOAD_SCHEMA); + Assert.ok(result.valid); + Assert.equal(payload.surveyVersion, "1"); + + await cleanupEnrollment(); + } finally { + ShowHeartbeatAction.overrideHeartbeatForTests(); + sandbox.restore(); + } + } +); diff --git a/toolkit/components/pdfjs/content/build/pdf.js b/toolkit/components/pdfjs/content/build/pdf.js index f59bc41651..017a45914e 100644 --- a/toolkit/components/pdfjs/content/build/pdf.js +++ b/toolkit/components/pdfjs/content/build/pdf.js @@ -9375,11 +9375,13 @@ exports.FreeTextEditor = void 0; var _util = __w_pdfjs_require__(1); var _tools = __w_pdfjs_require__(5); var _editor = __w_pdfjs_require__(4); +const EOL_PATTERN = /\r\n?|\n/g; class FreeTextEditor extends _editor.AnnotationEditor { #boundEditorDivBlur = this.editorDivBlur.bind(this); #boundEditorDivFocus = this.editorDivFocus.bind(this); #boundEditorDivInput = this.editorDivInput.bind(this); #boundEditorDivKeydown = this.editorDivKeydown.bind(this); + #boundEditorDivPaste = this.editorDivPaste.bind(this); #color; #content = ""; #editorDivId = `${this.id}-editor`; @@ -9495,6 +9497,7 @@ class FreeTextEditor extends _editor.AnnotationEditor { this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus); this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur); this.editorDiv.addEventListener("input", this.#boundEditorDivInput); + this.editorDiv.addEventListener("paste", this.#boundEditorDivPaste); } disableEditMode() { if (!this.isInEditMode()) { @@ -9510,6 +9513,7 @@ class FreeTextEditor extends _editor.AnnotationEditor { this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus); this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur); this.editorDiv.removeEventListener("input", this.#boundEditorDivInput); + this.editorDiv.removeEventListener("paste", this.#boundEditorDivPaste); this.div.focus({ preventScroll: true }); @@ -9539,13 +9543,10 @@ class FreeTextEditor extends _editor.AnnotationEditor { super.remove(); } #extractText() { - const divs = this.editorDiv.getElementsByTagName("div"); - if (divs.length === 0) { - return this.editorDiv.innerText; - } const buffer = []; - for (const div of divs) { - buffer.push(div.innerText.replace(/\r\n?|\n/, "")); + this.editorDiv.normalize(); + for (const child of this.editorDiv.childNodes) { + buffer.push(FreeTextEditor.#getNodeContent(child)); } return buffer.join("\n"); } @@ -9658,6 +9659,102 @@ class FreeTextEditor extends _editor.AnnotationEditor { } return this.div; } + static #getNodeContent(node) { + return (node.nodeType === Node.TEXT_NODE ? node.nodeValue : node.innerText).replaceAll(EOL_PATTERN, ""); + } + editorDivPaste(event) { + const clipboardData = event.clipboardData || window.clipboardData; + const { + types + } = clipboardData; + if (types.length === 1 && types[0] === "text/plain") { + return; + } + event.preventDefault(); + const paste = FreeTextEditor.#deserializeContent(clipboardData.getData("text") || "").replaceAll(EOL_PATTERN, "\n"); + if (!paste) { + return; + } + const selection = window.getSelection(); + if (!selection.rangeCount) { + return; + } + this.editorDiv.normalize(); + selection.deleteFromDocument(); + const range = selection.getRangeAt(0); + if (!paste.includes("\n")) { + range.insertNode(document.createTextNode(paste)); + this.editorDiv.normalize(); + selection.collapseToStart(); + return; + } + const { + startContainer, + startOffset + } = range; + const bufferBefore = []; + const bufferAfter = []; + if (startContainer.nodeType === Node.TEXT_NODE) { + const parent = startContainer.parentElement; + bufferAfter.push(startContainer.nodeValue.slice(startOffset).replaceAll(EOL_PATTERN, "")); + if (parent !== this.editorDiv) { + let buffer = bufferBefore; + for (const child of this.editorDiv.childNodes) { + if (child === parent) { + buffer = bufferAfter; + continue; + } + buffer.push(FreeTextEditor.#getNodeContent(child)); + } + } + bufferBefore.push(startContainer.nodeValue.slice(0, startOffset).replaceAll(EOL_PATTERN, "")); + } else if (startContainer === this.editorDiv) { + let buffer = bufferBefore; + let i = 0; + for (const child of this.editorDiv.childNodes) { + if (i++ === startOffset) { + buffer = bufferAfter; + } + buffer.push(FreeTextEditor.#getNodeContent(child)); + } + } + this.#content = `${bufferBefore.join("\n")}${paste}${bufferAfter.join("\n")}`; + this.#setContent(); + const newRange = new Range(); + let beforeLength = bufferBefore.reduce((acc, line) => acc + line.length, 0); + for (const { + firstChild + } of this.editorDiv.childNodes) { + if (firstChild.nodeType === Node.TEXT_NODE) { + const length = firstChild.nodeValue.length; + if (beforeLength <= length) { + newRange.setStart(firstChild, beforeLength); + newRange.setEnd(firstChild, beforeLength); + break; + } + beforeLength -= length; + } + } + selection.removeAllRanges(); + selection.addRange(newRange); + } + #setContent() { + this.editorDiv.replaceChildren(); + if (!this.#content) { + return; + } + for (const line of this.#content.split("\n")) { + const div = document.createElement("div"); + div.append(line ? document.createTextNode(line) : document.createElement("br")); + this.editorDiv.append(div); + } + } + #serializeContent() { + return this.#content.replaceAll("\xa0", " "); + } + static #deserializeContent(content) { + return content.replaceAll(" ", "\xa0"); + } get contentDiv() { return this.editorDiv; } diff --git a/toolkit/components/prompts/src/PromptUtils.sys.mjs b/toolkit/components/prompts/src/PromptUtils.sys.mjs index 7a15802b84..8c1b0ff992 100644 --- a/toolkit/components/prompts/src/PromptUtils.sys.mjs +++ b/toolkit/components/prompts/src/PromptUtils.sys.mjs @@ -76,6 +76,12 @@ export var EnableDelayHelper = function ({ this.focusTarget.addEventListener("keydown", this, true); this.focusTarget.document.addEventListener("unload", this); + // If we're not part of the active window, don't even start the timer yet. + let topWin = focusTarget.browsingContext.top.window; + if (topWin != Services.focus.activeWindow) { + return; + } + this.startOnFocusDelay(); }; diff --git a/toolkit/components/reputationservice/ApplicationReputation.cpp b/toolkit/components/reputationservice/ApplicationReputation.cpp index cc4045d5ad..8973fc85bb 100644 --- a/toolkit/components/reputationservice/ApplicationReputation.cpp +++ b/toolkit/components/reputationservice/ApplicationReputation.cpp @@ -519,20 +519,20 @@ const char* const ApplicationReputationService::kBinaryFileExtensions[] = { ".xlam", // MS Excel ".xldm", // MS Excel //".xll", exec // MS Excel - ".xlm", // MS Excel - ".xls", // MS Excel - ".xlsb", // MS Excel - ".xlsm", // MS Excel - ".xlsx", // MS Excel - ".xlt", // MS Excel - ".xltm", // MS Excel - ".xltx", // MS Excel - ".xlw", // MS Excel - ".xml", // MS Excel - ".xnk", // MS Exchange - ".xrm-ms", // Windows - ".xsd", // XML schema definition - ".xsl", // XML Stylesheet + ".xlm", // MS Excel + ".xls", // MS Excel + ".xlsb", // MS Excel + ".xlsm", // MS Excel + ".xlsx", // MS Excel + ".xlt", // MS Excel + ".xltm", // MS Excel + ".xltx", // MS Excel + ".xlw", // MS Excel + ".xml", // MS Excel + ".xnk", // MS Exchange + //".xrm-ms", exec // Windows + ".xsd", // XML schema definition + ".xsl", // XML Stylesheet //".xxe", ".xz", // Linux archive (xz) ".z", // InstallShield diff --git a/toolkit/components/reputationservice/ApplicationReputation.h b/toolkit/components/reputationservice/ApplicationReputation.h index f708c6eb71..5ea5b825f7 100644 --- a/toolkit/components/reputationservice/ApplicationReputation.h +++ b/toolkit/components/reputationservice/ApplicationReputation.h @@ -27,9 +27,9 @@ class ApplicationReputationService final public: static const char* const kNonBinaryExecutables[5]; #ifdef XP_WIN - static const char* const kBinaryFileExtensions[185]; -#else static const char* const kBinaryFileExtensions[184]; +#else + static const char* const kBinaryFileExtensions[183]; #endif static already_AddRefed<ApplicationReputationService> GetSingleton(); |