Skip to content

Commit

Permalink
Merge autoland to mozilla-central. a=merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Marian-Vasile Laza committed Feb 8, 2022
2 parents f2383d7 + 0541c7f commit b697834
Show file tree
Hide file tree
Showing 87 changed files with 8,295 additions and 668 deletions.
7 changes: 3 additions & 4 deletions accessible/base/TextAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,9 @@ FontWeight TextAttrsMgr::FontWeightTextAttr::GetFontWeight(nsIFrame* aFrame) {

// When there doesn't exist a bold font in the family and so the rendering of
// a non-bold font face is changed so that the user sees what looks like a
// bold font, i.e. synthetic bolding is used. IsSyntheticBold method is only
// needed on Mac, but it is "safe" to use on all platforms. (For non-Mac
// platforms it always return false.)
if (font->IsSyntheticBold()) {
// bold font, i.e. synthetic bolding is used. (Simply returns false on any
// platforms that don't use the multi-strike synthetic bolding.)
if (font->ApplySyntheticBold()) {
return FontWeight::Bold();
}

Expand Down
1 change: 1 addition & 0 deletions browser/app/profile/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,7 @@ pref("devtools.command-button-errorcount.enabled", true);
// Enable the Inspector
pref("devtools.inspector.enabled", true);
// What was the last active sidebar in the inspector
pref("devtools.inspector.selectedSidebar", "layoutview");
pref("devtools.inspector.activeSidebar", "layoutview");
pref("devtools.inspector.remote", false);

Expand Down
76 changes: 53 additions & 23 deletions browser/components/places/SnapshotGroups.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,7 @@ const SnapshotGroups = new (class SnapshotGroups {
);
id = row[0].getResultByIndex(0);

// Construct the sql parameters for the urls
let params = {};
let SQLInFragment = [];
let i = 0;
for (let url of urls) {
params[`url${i}`] = url;
SQLInFragment.push(`hash(:url${i})`);
i++;
}
params.id = id;

await db.execute(
`
INSERT INTO moz_places_metadata_groups_to_snapshots (group_id, place_id)
SELECT :id, s.place_id
FROM moz_places h
JOIN moz_places_metadata_snapshots s
ON h.id = s.place_id
WHERE h.url_hash IN (${SQLInFragment.join(",")})
`,
params
);
await this.#insertUrls(db, id, urls);
}
);

Expand Down Expand Up @@ -148,14 +127,30 @@ const SnapshotGroups = new (class SnapshotGroups {

/**
* Modifies the urls for a snapshot group.
* Note: This API does not manage deleting of groups if the number of urls is
* 0. If there are no urls in the group, consider calling `delete()` instead.
*
* @param {number} id
* The id of the group to modify.
* @param {string[]} [urls]
* An array of snapshot urls for the group. If the urls do not have associated snapshots, then they are ignored.
*/
async updateUrls(id, urls) {
// TODO
await PlacesUtils.withConnectionWrapper(
"SnapshotsGroups.jsm:updateUrls",
async db => {
// Some entries need removing, others modifying or adding. The easiest
// way to do this is to remove the existing group information first and
// then add only what we need.
await db.executeCached(
`DELETE FROM moz_places_metadata_groups_to_snapshots WHERE group_id = :id`,
{ id }
);

await this.#insertUrls(db, id, urls);
}
);

Services.obs.notifyObservers(null, "places-snapshot-group-updated");
}

Expand Down Expand Up @@ -306,6 +301,41 @@ const SnapshotGroups = new (class SnapshotGroups {
return snapshots;
}

/**
* Inserts a set of urls into the database for a given snapshot group.
*
* @param {object} db
* The database connection to use.
* @param {number} id
* The id of the group to add the urls to.
* @param {string[]} urls
* An array of urls to insert for the group.
*/
async #insertUrls(db, id, urls) {
// Construct the sql parameters for the urls
let params = {};
let SQLInFragment = [];
let i = 0;
for (let url of urls) {
params[`url${i}`] = url;
SQLInFragment.push(`hash(:url${i})`);
i++;
}
params.id = id;

await db.execute(
`
INSERT INTO moz_places_metadata_groups_to_snapshots (group_id, place_id)
SELECT :id, s.place_id
FROM moz_places h
JOIN moz_places_metadata_snapshots s
ON h.id = s.place_id
WHERE h.url_hash IN (${SQLInFragment.join(",")})
`,
params
);
}

/**
* Translates a snapshot group database row to a SnapshotGroup.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ async function addGroupTest(shouldRebuild) {
title: "example",
builder: "domain",
builderMetadata: { domain: "example.com" },
urls: TEST_URLS,
});

let urls = await SnapshotGroups.getUrls({ id: groups[0].id });
Assert.deepEqual(
urls.sort(),
TEST_URLS.sort(),
"Should have inserted the expected URLs"
);
}

async function modifyGroupTest(shouldRebuild) {
Expand All @@ -84,10 +90,13 @@ async function modifyGroupTest(shouldRebuild) {
title: "example",
builder: "domain",
builderMetadata: { domain: "example.com" },
// TODO: Replace when updateUrls API has been implemented.
urls: TEST_URLS,
// urls: [...TEST_URLS, TEST_URLS_EXTRA],
});
let urls = await SnapshotGroups.getUrls({ id: groups[0].id });
Assert.deepEqual(
urls.sort(),
[...TEST_URLS, TEST_URLS_EXTRA].sort(),
"Should have inserted the expected URLs"
);
}

async function deleteGroupTest(shouldRebuild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const TEST_URL1 = "https://example.com/";
const TEST_URL2 = "https://example.com/12345";
const TEST_URL3 = "https://example.com/67890";
const TEST_URL4 = "https://example.com/135246";
const TEST_URL5 = "https://example.com/531246";

async function delete_all_groups() {
let groups = await SnapshotGroups.query({ skipMinimum: true });
Expand Down Expand Up @@ -159,6 +160,30 @@ add_task(async function test_update_metadata() {
});
});

add_task(async function test_update_urls() {
let groups = await SnapshotGroups.query({ skipMinimum: true });
Assert.equal(groups.length, 1, "Should return 1 snapshot group");
Assert.equal(
groups[0].title,
"Modified title",
"SnapshotGroup title should be retrieved"
);

await SnapshotGroups.updateUrls(groups[0].id, [
TEST_URL5,
TEST_URL3,
TEST_URL1,
]);

let updated_groups = await SnapshotGroups.query({ skipMinimum: true });
Assert.equal(updated_groups.length, 1, "Should return 1 SnapshotGroup");
assertSnapshotGroup(groups[0], {
title: "Modified title",
builder: "pinned",
snapshotCount: [TEST_URL5, TEST_URL3, TEST_URL1].length,
});
});

add_task(async function test_delete_group() {
let groups = await SnapshotGroups.query({ skipMinimum: true });
Assert.equal(groups.length, 1, "Should return 1 SnapshotGroup");
Expand Down Expand Up @@ -268,22 +293,19 @@ add_task(async function test_get_snapshots_startIndex() {
});

add_task(async function test_minimum_size() {
let newGroup = { title: "Test Group 2", builder: "domain" };
let urls = [TEST_URL1, TEST_URL2, TEST_URL3];
let groupId = await SnapshotGroups.add(newGroup, urls);

let groups = await SnapshotGroups.query();
Assert.equal(
groups.length,
0,
"Should return no groups when they are under the snapshot size limit."
);

// TODO: Ideally this would use `updateUrls` to update 'Test Group' but that
// api is not implemented yet.
let newGroup = { title: "Test Group 2", builder: "domain" };
await SnapshotGroups.add(newGroup, [
TEST_URL1,
TEST_URL2,
TEST_URL3,
TEST_URL4,
]);
urls.push(TEST_URL4);
await SnapshotGroups.updateUrls(groupId, urls);

groups = await SnapshotGroups.query();
Assert.equal(
Expand Down
37 changes: 35 additions & 2 deletions caps/NullPrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "nsIClassInfoImpl.h"
#include "nsNetCID.h"
#include "nsError.h"
#include "nsEscape.h"
#include "ContentPrincipal.h"
#include "nsScriptSecurityManager.h"
#include "pratom.h"
Expand Down Expand Up @@ -76,6 +77,25 @@ already_AddRefed<NullPrincipal> NullPrincipal::CreateWithoutOriginAttributes() {
return NullPrincipal::Create(OriginAttributes(), nullptr);
}

static void EscapePrecursorQuery(nsACString& aPrecursorQuery) {
// origins should not contain existing escape sequences, so set `esc_Forced`
// to force any `%` in the input to be escaped in addition to non-ascii,
// control characters and DEL.
nsCString modified;
if (NS_EscapeURLSpan(aPrecursorQuery, esc_OnlyNonASCII | esc_Forced,
modified)) {
aPrecursorQuery.Assign(std::move(modified));
}
}

static void UnescapePrecursorQuery(nsACString& aPrecursorQuery) {
nsCString modified;
if (NS_UnescapeURL(aPrecursorQuery.BeginReading(), aPrecursorQuery.Length(),
/* aFlags */ 0, modified)) {
aPrecursorQuery.Assign(std::move(modified));
}
}

already_AddRefed<nsIURI> NullPrincipal::CreateURI(
nsIPrincipal* aPrecursor, const nsID* aNullPrincipalID) {
nsCOMPtr<nsIURIMutator> iMutator;
Expand All @@ -95,15 +115,27 @@ already_AddRefed<nsIURI> NullPrincipal::CreateURI(
if (aPrecursor) {
nsAutoCString precursorOrigin;
switch (BasePrincipal::Cast(aPrecursor)->Kind()) {
case eNullPrincipal:
case eNullPrincipal: {
// If the precursor null principal has a precursor, inherit it.
if (nsCOMPtr<nsIURI> nullPrecursorURI = aPrecursor->GetURI()) {
MOZ_ALWAYS_SUCCEEDS(nullPrecursorURI->GetQuery(precursorOrigin));
}
break;
case eContentPrincipal:
}
case eContentPrincipal: {
MOZ_ALWAYS_SUCCEEDS(aPrecursor->GetOriginNoSuffix(precursorOrigin));
#ifdef DEBUG
nsAutoCString original(precursorOrigin);
#endif
EscapePrecursorQuery(precursorOrigin);
#ifdef DEBUG
nsAutoCString unescaped(precursorOrigin);
UnescapePrecursorQuery(unescaped);
MOZ_ASSERT(unescaped == original,
"cannot recover original precursor origin after escape");
#endif
break;
}

// For now, we won't track expanded or system principal precursors. We may
// want to track expanded principal precursors in the future, but it's
Expand Down Expand Up @@ -304,6 +336,7 @@ NullPrincipal::GetPrecursorPrincipal(nsIPrincipal** aPrincipal) {
if (NS_FAILED(mURI->GetQuery(query)) || query.IsEmpty()) {
return NS_OK;
}
UnescapePrecursorQuery(query);

nsCOMPtr<nsIURI> precursorURI;
if (NS_FAILED(NS_NewURI(getter_AddRefs(precursorURI), query))) {
Expand Down
1 change: 1 addition & 0 deletions devtools/client/inspector/fonts/test/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Services.scriptloader.loadSubScript(
Services.prefs.setCharPref("devtools.inspector.activeSidebar", "fontinspector");
registerCleanupFunction(() => {
Services.prefs.clearUserPref("devtools.inspector.activeSidebar");
Services.prefs.clearUserPref("devtools.inspector.selectedSidebar");
});

var nodeConstants = require("devtools/shared/dom-node-constants");
Expand Down
Loading

0 comments on commit b697834

Please sign in to comment.