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

This commit is contained in:
Bogdan Tara 2018-09-22 01:06:13 +03:00
Родитель 2a7a7feb5f 0eedaf7640
Коммит 3e0d3c693c
118 изменённых файлов: 502 добавлений и 891 удалений

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

@ -865,7 +865,7 @@ XPCOMUtils.defineConstant(this, "PanelUI", PanelUI);
* @return the selected locale
*/
function getLocale() {
return Services.locale.getAppLocaleAsLangTag();
return Services.locale.appLocaleAsLangTag;
}
function getNotificationFromElement(aElement) {

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

@ -82,7 +82,7 @@ DistributionCustomizer.prototype = {
},
get _locale() {
const locale = Services.locale.getRequestedLocale() || "en-US";
const locale = Services.locale.requestedLocale || "en-US";
this.__defineGetter__("_locale", () => locale);
return this._locale;
},

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

@ -13,11 +13,11 @@
//
// In the future, we should provide some way for tests to decouple their
// language selection from that of Firefox.
const avLocales = Services.locale.getAvailableLocales();
const avLocales = Services.locale.availableLocales;
Services.locale.setAvailableLocales(["en-US", "es-ES"]);
Services.locale.availableLocales = ["en-US", "es-ES"];
registerCleanupFunction(() => {
Services.locale.setAvailableLocales(avLocales);
Services.locale.availableLocales = avLocales;
});
}
@ -152,8 +152,8 @@ async function runTests(options) {
});
});
let reqLoc = Services.locale.getRequestedLocales();
Services.locale.setRequestedLocales(["es-ES"]);
let reqLoc = Services.locale.requestedLocales;
Services.locale.requestedLocales = ["es-ES"];
await extension.startup();
@ -161,7 +161,7 @@ async function runTests(options) {
await extension.unload();
Services.locale.setRequestedLocales(reqLoc);
Services.locale.requestedLocales = reqLoc;
let node = document.getElementById(pageActionId);
is(node, null, "pageAction image removed from document");

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

@ -661,7 +661,7 @@ const AutoMigrate = {
// lead to a an array with 1 empty string in it.
surveyLocales = new Set(surveyLocales.filter(str => !!str));
canDoSurveyInLocale =
surveyLocales.has(Services.locale.getAppLocaleAsLangTag());
surveyLocales.has(Services.locale.appLocaleAsLangTag);
} catch (ex) {
/* ignore exceptions and just don't do the survey. */
}

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

@ -310,7 +310,7 @@ AboutNewTabService.prototype = {
return Services.locale.negotiateLanguages(
// Fix up incorrect BCP47 that are actually lang tags as a workaround for
// bug 1479606 returning the wrong values in the content process
Services.locale.getAppLocalesAsBCP47().map(l => l.replace(/^(ja-JP-mac)$/, "$1os")),
Services.locale.appLocalesAsBCP47.map(l => l.replace(/^(ja-JP-mac)$/, "$1os")),
ACTIVITY_STREAM_BCP47,
// defaultLocale's strings aren't necessarily packaged, but en-US' are
"en-US",

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

@ -151,7 +151,7 @@ const MessageLoaderUtils = {
},
_getRemoteSettingsMessages(bucket) {
return RemoteSettings(bucket).get({filters: {locale: Services.locale.getAppLocaleAsLangTag()}});
return RemoteSettings(bucket).get({filters: {locale: Services.locale.appLocaleAsLangTag}});
},
/**

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

@ -441,7 +441,7 @@ this.ActivityStream = class ActivityStream {
this.geo = "";
}
this.locale = Services.locale.getAppLocaleAsLangTag();
this.locale = Services.locale.appLocaleAsLangTag;
// Update the pref config of those with dynamic values
for (const pref of PREFS_CONFIG.keys()) {

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

@ -328,7 +328,7 @@ this.TelemetryFeed = class TelemetryFeed {
createPing(portID) {
const ping = {
addon_version: Services.appinfo.appBuildID,
locale: Services.locale.getAppLocaleAsLangTag(),
locale: Services.locale.appLocaleAsLangTag,
user_prefs: this.userPreferences,
};
@ -412,7 +412,7 @@ this.TelemetryFeed = class TelemetryFeed {
const ping = {
client_id: "n/a",
addon_version: Services.appinfo.appBuildID,
locale: Services.locale.getAppLocaleAsLangTag(),
locale: Services.locale.appLocaleAsLangTag,
impression_id: this._impressionId,
};
if (action.data.includeClientID) {

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

@ -10,16 +10,16 @@ const DEFAULT_URL = "resource://activity-stream/prerendered/en-US/activity-strea
* Temporarily change the app locale to get the localized activity stream url
*/
async function getUrlForLocale(locale) {
const origAvailable = Services.locale.getAvailableLocales();
const origRequested = Services.locale.getRequestedLocales();
const origAvailable = Services.locale.availableLocales;
const origRequested = Services.locale.requestedLocales;
try {
Services.locale.setAvailableLocales([locale]);
Services.locale.setRequestedLocales([locale]);
Services.locale.availableLocales = [locale];
Services.locale.requestedLocales = [locale];
return aboutNewTabService.defaultURL;
} finally {
// Always clean up after returning the url
Services.locale.setAvailableLocales(origAvailable);
Services.locale.setRequestedLocales(origRequested);
Services.locale.availableLocales = origAvailable;
Services.locale.requestedLocales = origRequested;
}
}

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

@ -255,7 +255,7 @@ describe("ActivityStream", () => {
it("should be false with expected geo and unexpected locale", () => {
sandbox.stub(global.Services.prefs, "prefHasUserValue").returns(true);
sandbox.stub(global.Services.prefs, "getStringPref").returns("US");
sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("no-LOCALE");
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("no-LOCALE");
as._updateDynamicPrefs();
@ -264,7 +264,7 @@ describe("ActivityStream", () => {
it("should be true with expected geo and locale", () => {
sandbox.stub(global.Services.prefs, "prefHasUserValue").returns(true);
sandbox.stub(global.Services.prefs, "getStringPref").returns("US");
sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("en-US");
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("en-US");
as._updateDynamicPrefs();
@ -277,7 +277,7 @@ describe("ActivityStream", () => {
.returns("US")
.onSecondCall()
.returns("NOGEO");
sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("en-US");
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("en-US");
as._updateDynamicPrefs();
as._updateDynamicPrefs();
@ -308,7 +308,7 @@ describe("ActivityStream", () => {
});
it("should set true with expected geo and locale", () => {
sandbox.stub(global.Services.prefs, "getStringPref").returns("US");
sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("en-US");
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("en-US");
as._updateDynamicPrefs();
clock.tick(1);

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

@ -106,8 +106,8 @@ const TEST_GLOBAL = {
DownloadsViewUI: {DownloadElementShell},
Services: {
locale: {
getAppLocaleAsLangTag() { return "en-US"; },
getAppLocalesAsLangTags() {},
appLocaleAsLangTag: "en-US",
appLocalesAsLangtags: [],
negotiateLanguages() {},
},
urlFormatter: {formatURL: str => str, formatURLPref: str => str},

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

@ -1061,7 +1061,7 @@ BrowserGlue.prototype = {
Normandy.init();
// Initialize the default l10n resource sources for L10nRegistry.
let locales = Services.locale.getPackagedLocales();
let locales = Services.locale.packagedLocales;
const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/");
L10nRegistry.registerSource(greSource);
@ -2345,13 +2345,13 @@ BrowserGlue.prototype = {
if (Services.prefs.prefHasUserValue(MATCHOS_LOCALE_PREF) ||
Services.prefs.prefHasUserValue(SELECTED_LOCALE_PREF)) {
if (Services.prefs.getBoolPref(MATCHOS_LOCALE_PREF, false)) {
Services.locale.setRequestedLocales([]);
Services.locale.requestedLocales = [];
} else {
let locale = Services.prefs.getComplexValue(SELECTED_LOCALE_PREF,
Ci.nsIPrefLocalizedString);
if (locale) {
try {
Services.locale.setRequestedLocales([locale.data]);
Services.locale.requestedLocales = [locale.data];
} catch (e) { /* Don't panic if the value is not a valid locale code. */ }
}
}

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

@ -197,7 +197,7 @@ class SortedItemSelectList {
}
function getLocaleDisplayInfo(localeCodes) {
let packagedLocales = new Set(Services.locale.getPackagedLocales());
let packagedLocales = new Set(Services.locale.packagedLocales);
let localeNames = Services.intl.getLocaleDisplayNames(undefined, localeCodes);
return localeCodes.map((code, i) => {
return {
@ -223,9 +223,9 @@ var gBrowserLanguagesDialog = {
// Maintain the previously requested locales even if we cancel out.
this.requestedLocales = window.arguments[0];
let requested = this.requestedLocales || Services.locale.getRequestedLocales();
let requested = this.requestedLocales || Services.locale.requestedLocales;
let requestedSet = new Set(requested);
let available = Services.locale.getAvailableLocales()
let available = Services.locale.availableLocales
.filter(locale => !requestedSet.has(locale));
this.initRequestedLocales(requested);

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

@ -238,7 +238,7 @@ var promiseLoadHandlersList;
function getBundleForLocales(newLocales) {
let locales = Array.from(new Set([
...newLocales,
...Services.locale.getRequestedLocales(),
...Services.locale.requestedLocales,
Services.locale.lastFallbackLocale,
]));
function generateContexts(resourceIds) {
@ -785,7 +785,7 @@ var gMainPane = {
},
initBrowserLocale() {
let localeCodes = Services.locale.getAvailableLocales();
let localeCodes = Services.locale.availableLocales;
let localeNames = Services.intl.getLocaleDisplayNames(undefined, localeCodes);
let locales = localeCodes.map((code, i) => ({code, name: localeNames[i]}));
locales.sort((a, b) => a.name > b.name);
@ -800,7 +800,7 @@ var gMainPane = {
let menulist = document.getElementById("defaultBrowserLanguage");
let menupopup = menulist.querySelector("menupopup");
menupopup.appendChild(fragment);
menulist.value = Services.locale.getRequestedLocale();
menulist.value = Services.locale.requestedLocale;
document.getElementById("browserLanguagesBox").hidden = false;
},
@ -836,7 +836,7 @@ var gMainPane = {
return;
}
let locales = localesString.split(",");
Services.locale.setRequestedLocales(locales);
Services.locale.requestedLocales = locales;
// Restart with the new locale.
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
@ -849,13 +849,13 @@ var gMainPane = {
/* Show or hide the confirm change message bar based on the new locale. */
onBrowserLanguageChange(event) {
let locale = event.target.value;
if (locale == Services.locale.getRequestedLocale()) {
if (locale == Services.locale.requestedLocale) {
this.hideConfirmLanguageChangeMessageBar();
return;
}
let locales = Array.from(new Set([
locale,
...Services.locale.getRequestedLocales(),
...Services.locale.requestedLocales,
]).values());
this.showConfirmLanguageChangeMessageBar(locales);
},
@ -993,14 +993,14 @@ var gMainPane = {
/* Show or hide the confirm change message bar based on the updated ordering. */
browserLanguagesClosed() {
let requesting = this.gBrowserLanguagesDialog.requestedLocales;
let requested = Services.locale.getRequestedLocales();
let requested = Services.locale.requestedLocales;
let defaultBrowserLanguage = document.getElementById("defaultBrowserLanguage");
if (requesting && requesting.join(",") != requested.join(",")) {
gMainPane.showConfirmLanguageChangeMessageBar(requesting);
defaultBrowserLanguage.value = requesting[0];
return;
}
defaultBrowserLanguage.value = Services.locale.getRequestedLocale();
defaultBrowserLanguage.value = Services.locale.requestedLocale;
gMainPane.hideConfirmLanguageChangeMessageBar();
},

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

@ -8,10 +8,10 @@
SimpleTest.waitForExplicitFinish();
const originalAvailable = Services.locale.getAvailableLocales();
const originalRequested = Services.locale.getRequestedLocales();
Services.locale.setAvailableLocales(["ko-KR"]);
Services.locale.setRequestedLocales(["ko-KR"]);
const originalAvailable = Services.locale.availableLocales;
const originalRequested = Services.locale.requestedLocales;
Services.locale.availableLocales = ["ko-KR"];
Services.locale.requestedLocales = ["ko-KR"];
// First be sure we have a non-UTC timezone and a non en-US locale.
var setTimeZone = SpecialPowers.Cu.getJSTestingFunctions().setTimeZone;
@ -58,8 +58,8 @@
SimpleTest.is(options.timeZoneName, "long", "Resist Fingerprinting Intl.DateTimeFormat.format.timeZoneName");
// Cleanup
Services.locale.setRequestedLocales(originalRequested);
Services.locale.setAvailableLocales(originalAvailable);
Services.locale.requestedLocales = originalRequested;
Services.locale.availableLocales = originalAvailable;
SimpleTest.finish();
});
</script>

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

@ -22,7 +22,7 @@ function isSubObjectOf(expectedObj, actualObj, name) {
}
function getLocale() {
return Services.locale.getRequestedLocale() || undefined;
return Services.locale.requestedLocale || undefined;
}
function promiseEvent(aTarget, aEventName, aPreventDefault) {

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

@ -131,8 +131,8 @@ add_task(async function testObserver() {
"component is notified of login change");
Assert.equal(component.updatePanel.callCount, 4, "triggers panel update again");
Services.locale.setAvailableLocales(["ab-CD"]);
Services.locale.setRequestedLocales(["ab-CD"]);
Services.locale.availableLocales = ["ab-CD"];
Services.locale.requestedLocales = ["ab-CD"];
Assert.ok(component.updateDir.calledTwice, "locale change triggers UI direction update");

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

@ -29,7 +29,7 @@ var Translation = {
_defaultTargetLanguage: "",
get defaultTargetLanguage() {
if (!this._defaultTargetLanguage) {
this._defaultTargetLanguage = Services.locale.getAppLocaleAsLangTag()
this._defaultTargetLanguage = Services.locale.appLocaleAsLangTag
.split("-")[0];
}
return this._defaultTargetLanguage;

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

@ -270,7 +270,7 @@
"C\u1EA3m \u01A1n"],
};
let locale = Services.locale.getAppLocaleAsLangTag();
let locale = Services.locale.appLocaleAsLangTag;
if (!(locale in localizedStrings))
locale = "en";
let strings = localizedStrings[locale];

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

@ -53,7 +53,7 @@ function isAvailable() {
if (availablePref == "on") {
return true;
} else if (availablePref == "detect") {
let locale = Services.locale.getRequestedLocale();
let locale = Services.locale.requestedLocale;
let region = Services.prefs.getCharPref("browser.search.region", "");
let supportedCountries = Services.prefs.getCharPref("extensions.formautofill.supportedCountries")
.split(",");

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

@ -306,7 +306,7 @@ class ChromeActions {
}
getLocale() {
return Services.locale.getRequestedLocale() || "en-US";
return Services.locale.requestedLocale || "en-US";
}
getStrings(data) {

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

@ -624,7 +624,7 @@ var pktUI = (function() {
}
function getUILocale() {
return Services.locale.getAppLocaleAsLangTag();
return Services.locale.appLocaleAsLangTag;
}
/**

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

@ -246,7 +246,7 @@ var pktApi = (function() {
var url = baseAPIUrl + options.path;
var data = options.data || {};
data.locale_lang = Services.locale.getAppLocaleAsLangTag();
data.locale_lang = Services.locale.appLocaleAsLangTag;
data.consumer_key = oAuthConsumerKey;
var request = new XMLHttpRequest();
@ -358,7 +358,7 @@ var pktApi = (function() {
// Define variant for ho2
if (data.flags) {
var showHo2 = (Services.locale.getAppLocaleAsLangTag() === "en-US") ? data.flags.show_ffx_mobile_prompt : "control";
var showHo2 = (Services.locale.appLocaleAsLangTag === "en-US") ? data.flags.show_ffx_mobile_prompt : "control";
setSetting("test.ho2", showHo2);
}
data.ho2 = getSetting("test.ho2");

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

@ -143,7 +143,7 @@ class PingCentre {
}
let clientID = data.client_id || await this.telemetryClientId;
let locale = data.locale || Services.locale.getAppLocalesAsLangTags().pop();
let locale = data.locale || Services.locale.appLocaleAsLangTag;
let profileCreationDate = TelemetryEnvironment.currentEnvironment.profile.resetDate ||
TelemetryEnvironment.currentEnvironment.profile.creationDate;
const payload = Object.assign({

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

@ -25,7 +25,7 @@ function enum_to_array(strings) {
function run_test() {
// without override
Services.locale.setRequestedLocales(["de"]);
Services.locale.requestedLocales = ["de"];
Assert.equal(chromeReg.getSelectedLocale("basepack"), "en-US");
Assert.equal(chromeReg.getSelectedLocale("overpack"), "de");
Assert.deepEqual(enum_to_array(chromeReg.getLocalesForPackage("basepack")),

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

@ -80,7 +80,7 @@ const AboutDebugging = {
L10nRegistry.registerSource(temporarySource);
}
const locales = Services.locale.getAppLocalesAsBCP47();
const locales = Services.locale.appLocalesAsBCP47;
const generator =
L10nRegistry.generateContexts(locales, ["aboutdebugging.ftl"]);

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

@ -37,7 +37,7 @@ class Sidebar extends PureComponent {
id: "about-debugging-sidebar-no-devices"
}, dom.span(
{
className: "sidebar__devices__no-devices-message js-sidebar-no-devices"
className: "sidebar__devices__no-devices-message"
},
"No devices discovered"
)

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

@ -7,8 +7,7 @@ support-files =
!/devtools/client/shared/test/shared-head.js
!/devtools/client/shared/test/telemetry-test-helpers.js
[browser_aboutdebugging_connect_networklocations.js]
[browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
[browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
[browser_aboutdebugging_sidebar_network_runtimes.js]
[browser_aboutdebugging_thisfirefox.js]
[browser_aboutdebugging_connect_networklocations.js]

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

@ -1,47 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const networkLocationsModule =
require("devtools/client/aboutdebugging-new/src/modules/network-locations.js");
/**
* Test the sidebar is updated correctly when network runtimes are added/removed.
*/
add_task(async function() {
registerCleanupFunction(() => {
Services.prefs.clearUserPref("devtools.aboutdebugging.network-locations");
});
const { document, tab } = await openAboutDebugging();
const noDevicesElement = document.querySelector(".js-sidebar-no-devices");
ok(noDevicesElement, "Sidebar shows the 'no devices' element");
info("Add a network location");
networkLocationsModule.addNetworkLocation("localhost:6080");
info("Wait for 'no devices' element to disappear");
waitUntil(() => !document.querySelector(".js-sidebar-no-devices"));
ok(findSidebarItemByText("localhost:6080", document),
"Found a sidebar item for localhost:6080");
info("Remove the network location");
networkLocationsModule.removeNetworkLocation("localhost:6080");
info("Wait for 'no devices' element to reappear");
waitUntil(() => document.querySelector(".js-sidebar-no-devices"));
ok(!findSidebarItemByText("localhost:6080", document),
"Sidebar item for localhost:6080 removed");
await removeTab(tab);
});
function findSidebarItemByText(text, document) {
const sidebarItems = document.querySelectorAll(".js-sidebar-item");
return [...sidebarItems].find(element => {
return element.textContent.includes(text);
});
}

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

@ -65,7 +65,7 @@ window.Application = {
* MessageContext elements.
*/
async createMessageContexts() {
const locales = Services.locale.getAppLocalesAsBCP47();
const locales = Services.locale.appLocalesAsBCP47;
const generator =
L10nRegistry.generateContexts(locales, ["devtools/application.ftl"]);

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

@ -6,9 +6,6 @@
const { PureComponent } = require("devtools/client/shared/vendor/react");
const { div, button, p } = require("devtools/client/shared/vendor/react-dom-factories");
const { openDocLink } = require("devtools/client/shared/link");
const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
const { connect } = require("devtools/client/shared/vendor/react-redux");
const selectors = require("devtools/client/performance-new/store/selectors");
/**
* This component provides a helpful description for what is going on in the component
@ -16,10 +13,7 @@ const selectors = require("devtools/client/performance-new/store/selectors");
*/
class Description extends PureComponent {
static get propTypes() {
return {
// StateProps:
toolbox: PropTypes.object.isRequired
};
return {};
}
constructor(props) {
@ -71,8 +65,4 @@ class Description extends PureComponent {
}
}
const mapStateToProps = state => ({
toolbox: selectors.getToolbox(state)
});
module.exports = connect(mapStateToProps)(Description);
module.exports = Description;

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

@ -28,16 +28,15 @@ const {
/**
* Initialize the panel by creating a redux store, and render the root component.
*
* @param toolbox - The toolbox
* @param perfFront - The Perf actor's front. Used to start and stop recordings.
* @param preferenceFront - Used to get the recording preferences from the device.
*/
async function gInit(toolbox, perfFront, preferenceFront) {
async function gInit(perfFront, preferenceFront) {
const store = createStore(reducers);
// Do some initialization, especially with privileged things that are part of the
// the browser.
store.dispatch(actions.initializeStore({
toolbox,
perfFront,
receiveProfile,
// Pull the default recording settings from the reducer, and update them according

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

@ -35,7 +35,7 @@ class PerformancePanel {
this.isReady = true;
this.emit("ready");
this.panelWin.gInit(this.toolbox, perfFront, preferenceFront);
this.panelWin.gInit(perfFront, preferenceFront);
return this;
}

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

@ -129,7 +129,6 @@ function initializedValues(state = null, action) {
switch (action.type) {
case "INITIALIZE_STORE":
return {
toolbox: action.toolbox,
perfFront: action.perfFront,
receiveProfile: action.receiveProfile,
setRecordingPreferences: action.setRecordingPreferences

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

@ -30,7 +30,6 @@ const getInitializedValues = state => {
};
const getPerfFront = state => getInitializedValues(state).perfFront;
const getToolbox = state => getInitializedValues(state).toolbox;
const getReceiveProfileFn = state => getInitializedValues(state).receiveProfile;
const getSetRecordingPreferencesFn =
state => getInitializedValues(state).setRecordingPreferences;
@ -47,7 +46,6 @@ module.exports = {
getRecordingSettings,
getInitializedValues,
getPerfFront,
getToolbox,
getReceiveProfileFn,
getSetRecordingPreferencesFn
};

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

@ -169,7 +169,6 @@ function createPerfComponent() {
const selectors = require("devtools/client/performance-new/store/selectors");
const perfFrontMock = new MockPerfFront();
const toolboxMock = {};
const store = createStore(reducers);
const container = document.querySelector("#container");
const receiveProfileCalls = [];
@ -185,7 +184,6 @@ function createPerfComponent() {
function mountComponent() {
store.dispatch(actions.initializeStore({
toolbox: toolboxMock,
perfFront: perfFrontMock,
receiveProfile: receiveProfileMock,
recordingSettingsFromPreferences: selectors.getRecordingSettings(store.getState()),

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

@ -45,7 +45,7 @@ window.onload = function() {
geckobuildid: appInfo.platformBuildID,
geckoversion: appInfo.platformVersion,
useragent: window.navigator.userAgent,
locale: Services.locale.getAppLocaleAsLangTag(),
locale: Services.locale.appLocaleAsLangTag,
os: appInfo.OS,
processor: appInfo.XPCOMABI.split("-")[0],
compiler: appInfo.XPCOMABI.split("-")[1],

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

@ -114,7 +114,7 @@ async function getSystemInfo() {
geckoversion: geckoVersion,
// Locale used in this build
locale: Services.locale.getAppLocaleAsLangTag(),
locale: Services.locale.appLocaleAsLangTag,
/**
* Information regarding the operating system.

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

@ -32,7 +32,7 @@ var gStringBundle;
W3CTest.runner.requestLongerTimeout(2);
const { Services } = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm");
Services.locale.setRequestedLocales(["en-US"]);
Services.locale.requestedLocales = ["en-US"];
SpecialPowers.pushPrefEnv({ "set": [
// Need to set devPixelsPerPx explicitly to gain

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

@ -7299,6 +7299,12 @@ nsIDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
mValidWidth = (!widthStr.IsEmpty() && NS_SUCCEEDED(widthErrorCode) && mViewportSize.width > 0);
mValidHeight = (!heightStr.IsEmpty() && NS_SUCCEEDED(heightErrorCode) && mViewportSize.height > 0);
// If the width is set to some unrecognized value, and there is no
// height set, treat it as if device-width were specified.
if ((!mValidWidth && !widthStr.IsEmpty()) && !mValidHeight) {
mAutoSize = true;
}
mAllowZoom = true;
nsAutoString userScalable;
GetHeaderData(nsGkAtoms::viewport_user_scalable, userScalable);

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

@ -1148,10 +1148,13 @@ NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx,
}
bool
TryPreserveWrapper(JSObject* obj)
TryPreserveWrapper(JS::Handle<JSObject*> obj)
{
MOZ_ASSERT(IsDOMObject(obj));
// nsISupports objects are special cased because DOM proxies are nsISupports
// and have addProperty hooks that do more than wrapper preservation (so we
// don't want to call them).
if (nsISupports* native = UnwrapDOMObjectToISupports(obj)) {
nsWrapperCache* cache = nullptr;
CallQueryInterface(native, &cache);
@ -1161,11 +1164,25 @@ TryPreserveWrapper(JSObject* obj)
return true;
}
// If this DOMClass is not cycle collected, then it isn't wrappercached,
// so it does not need to be preserved. If it is cycle collected, then
// we can't tell if it is wrappercached or not, so we just return false.
// The addProperty hook for WebIDL classes does wrapper preservation, and
// nothing else, so call it, if present.
const DOMJSClass* domClass = GetDOMClass(obj);
return domClass && !domClass->mParticipant;
const JSClass* clasp = domClass->ToJSClass();
JSAddPropertyOp addProperty = clasp->getAddProperty();
// We expect all proxies to be nsISupports.
MOZ_RELEASE_ASSERT(!js::Valueify(clasp)->isProxy(), "Should not call addProperty for proxies.");
// The class should have an addProperty hook iff it is a CC participant.
MOZ_RELEASE_ASSERT(bool(domClass->mParticipant) == bool(addProperty));
if (!addProperty) {
return true;
}
JS::Rooted<jsid> dummyId(RootingCx());
JS::Rooted<JS::Value> dummyValue(RootingCx());
return addProperty(nullptr, obj, dummyId, dummyValue);
}
// Can only be called with a DOM JSClass.

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

@ -1518,7 +1518,7 @@ UpdateWrapper(T* p, void*, JSObject* obj, const JSObject* old)
// This operation will return false only for non-nsISupports cycle-collected
// objects, because we cannot determine if they are wrappercached or not.
bool
TryPreserveWrapper(JSObject* obj);
TryPreserveWrapper(JS::Handle<JSObject*> obj);
// Can only be called with a DOM JSClass.
bool

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

@ -148,11 +148,6 @@ public:
return mIncumbentGlobal;
}
void Reset()
{
ClearJSReferences();
}
enum ExceptionHandling {
// Report any exception and don't throw it to the caller code.
eReportExceptions,

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

@ -102,6 +102,9 @@ def idlTypeNeedsCycleCollection(type):
raise CycleCollectionUnsupported("Don't know whether to cycle-collect type %s" % type)
# TryPreserveWrapper uses the addProperty hook to preserve the wrapper of
# non-nsISupports cycle collected objects, so if wantsAddProperty is changed
# to not cover that case then TryPreserveWrapper will need to be changed.
def wantsAddProperty(desc):
return (desc.concrete and desc.wrapperCache and not desc.isGlobal())
@ -1683,6 +1686,10 @@ class CGAddPropertyHook(CGAbstractClassHook):
def generate_code(self):
assert self.descriptor.wrapperCache
# This hook is also called by TryPreserveWrapper on non-nsISupports
# cycle collected objects, so if addProperty is ever changed to do
# anything more or less than preserve the wrapper, TryPreserveWrapper
# will need to be changed.
return dedent("""
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.

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

@ -672,11 +672,16 @@ WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType,
if (aType == TrackInfo::kAudioTrack) {
isKeyframe = true;
} else if (aType == TrackInfo::kVideoTrack) {
if (packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_ENCRYPTED) {
if (packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_ENCRYPTED ||
packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_PARTITIONED) {
// Packet is encrypted, can't peek, use packet info
isKeyframe = nestegg_packet_has_keyframe(holder->Packet())
== NESTEGG_PACKET_HAS_KEYFRAME_TRUE;
} else {
MOZ_ASSERT(packetEncryption ==
NESTEGG_PACKET_HAS_SIGNAL_BYTE_UNENCRYPTED ||
packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_FALSE,
"Unencrypted packet expected");
auto sample = MakeSpan(data, length);
auto alphaSample = MakeSpan(alphaData, alphaLength);

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

@ -18,8 +18,8 @@ const localeService =
Cc["@mozilla.org/intl/localeservice;1"].getService(Ci.mozILocaleService);
const mozIntl = Cc["@mozilla.org/mozintl;1"].getService(Ci.mozIMozIntl);
let rpLocale = localeService.negotiateLanguages(localeService.getRegionalPrefsLocales(),
localeService.getAvailableLocales())[0];
let rpLocale = localeService.negotiateLanguages(localeService.regionalPrefsLocales,
localeService.availableLocales)[0];
let testData = [
{

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

@ -18,7 +18,7 @@ const localeService =
Cc["@mozilla.org/intl/localeservice;1"].getService(Ci.mozILocaleService);
let rpLocales = localeService.negotiateLanguages(window.getRegionalPrefsLocales(),
localeService.getAvailableLocales());
localeService.availableLocales);
ok(rpLocales.length > 0, "getRegionalPrefsLocales returns at least one locale.");
is(rpLocales[0], "en-US", "The first regional prefs locale should resolve to en-US.");

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

@ -913,7 +913,7 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSContext* aWorkerCx)
}
static bool
PreserveWrapper(JSContext *cx, JSObject *obj)
PreserveWrapper(JSContext *cx, JS::HandleObject obj)
{
MOZ_ASSERT(cx);
MOZ_ASSERT(obj);

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

@ -30,7 +30,7 @@ const uint32_t kWorkletStackSize = 256 * sizeof(size_t) * 1024;
// Helper functions
bool
PreserveWrapper(JSContext* aCx, JSObject* aObj)
PreserveWrapper(JSContext* aCx, JS::HandleObject aObj)
{
MOZ_ASSERT(aCx);
MOZ_ASSERT(aObj);

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

@ -57,8 +57,8 @@ InputBlockState::SetConfirmedTargetApzc(const RefPtr<AsyncPanZoomController>& aT
// a different target than the main thread. If this happens for a drag
// block created for a scrollbar drag, the consequences can be fairly
// user-unfriendly, such as the scrollbar not being draggable at all,
// or it scrolling the contents of the wrong scrollframe. In Nightly
// builds, we issue a diagnostic assert in this situation, so that the
// or it scrolling the contents of the wrong scrollframe. In debug
// builds, we assert in this situation, so that the
// underlying compositor hit testing bug can be fixed. In release builds,
// however, we just silently accept the main thread's confirmed target,
// which will produce the expected behaviour (apart from drag events
@ -68,9 +68,7 @@ InputBlockState::SetConfirmedTargetApzc(const RefPtr<AsyncPanZoomController>& aT
aState == TargetConfirmationState::eConfirmed &&
mTargetApzc && aTargetApzc &&
mTargetApzc->GetGuid() != aTargetApzc->GetGuid()) {
#ifdef NIGHTLY_BUILD
MOZ_RELEASE_ASSERT(false, "APZ and main thread confirmed scrollbar drag block with different targets");
#endif
MOZ_ASSERT(false, "APZ and main thread confirmed scrollbar drag block with different targets");
UpdateTargetApzc(aTargetApzc);
return true;
}

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

@ -1188,22 +1188,22 @@ WebRenderCommandBuilder::DoGroupingForDisplayList(nsDisplayList* aList,
GP("Property change. Deleting blob\n");
if (group.mAppUnitsPerDevPixel != appUnitsPerDevPixel) {
GP(" app unit change%d %d\n", group.mAppUnitsPerDevPixel, appUnitsPerDevPixel);
GP(" App unit change %d -> %d\n", group.mAppUnitsPerDevPixel, appUnitsPerDevPixel);
}
// The bounds have changed so we need to discard the old image and add all
// the commands again.
auto p = group.mGroupBounds;
auto q = groupBounds;
if (!group.mGroupBounds.IsEqualEdges(groupBounds)) {
GP(" Bounds change: %d %d %d %d vs %d %d %d %d\n", p.x, p.y, p.width, p.height, q.x, q.y, q.width, q.height);
GP(" Bounds change: %d %d %d %d -> %d %d %d %d\n", p.x, p.y, p.width, p.height, q.x, q.y, q.width, q.height);
}
if (group.mScale != scale) {
GP(" Scale %f %f vs %f %f\n", group.mScale.width, group.mScale.height, scale.width, scale.height);
GP(" Scale %f %f -> %f %f\n", group.mScale.width, group.mScale.height, scale.width, scale.height);
}
if (group.mResidualOffset != residualOffset) {
GP(" Residual Offset %f %f vs %f %f\n", group.mResidualOffset.x, group.mResidualOffset.y, residualOffset.x, residualOffset.y);
GP(" Residual Offset %f %f -> %f %f\n", group.mResidualOffset.x, group.mResidualOffset.y, residualOffset.x, residualOffset.y);
}
group.ClearItems();

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

@ -1288,7 +1288,7 @@ gfxPlatformFontList::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], uint32_t &aL
if (OSPreferences::GetInstance()->GetSystemLocales(sysLocales)) {
LocaleService::GetInstance()->NegotiateLanguages(
sysLocales, prefLocales, NS_LITERAL_CSTRING(""),
LocaleService::LangNegStrategy::Filtering, negLocales);
LocaleService::kLangNegStrategyFiltering, negLocales);
for (const auto& localeStr : negLocales) {
Locale locale(localeStr);

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

@ -333,8 +333,7 @@ carry different lists of available locales.
Requested Locales
=================
The list of requested locales can be read using :js:`LocaleService::GetRequestedLocales` API,
and set using :js:`LocaleService::SetRequestedLocales` API.
The list of requested locales can be read and set using :js:`LocaleService::requestedLocales` API.
Using the API will perform necessary sanity checks and canonicalize the values.
@ -349,7 +348,7 @@ The former is the current default setting for Firefox Desktop, and the latter is
default setting for Firefox for Android.
If the developer wants to programmatically request the app to follow OS locales,
they can call the :js:`SetRequestedLocales` API with no argument.
they can assign :js:`null` to :js:`requestedLocales`.
Regional Preferences
====================
@ -450,8 +449,8 @@ a legacy "ja-JP-mac" locale. The "mac" is a variant and BCP47 requires all varia
to be 5-8 character long.
Gecko supports the limitation by accepting the 3-letter variants in our APIs and also
provides a special :js:`GetAppLocalesAsLangTags` method which returns this locale in that form.
(:js:`GetAppLocalesAsBCP47` will canonicalize it and turn into `"ja-JP-macos"`).
provides a special :js:`appLocalesAsLangTags` method which returns this locale in that form.
(:js:`appLocalesAsBCP47` will canonicalize it and turn into `"ja-JP-macos"`).
Usage of language negotiation etc. shouldn't rely on this behavior.
@ -507,14 +506,14 @@ It may look like this:
L10nRegistry.registerSource(fs);
let availableLocales = Services.locale.getAvailableLocales();
let availableLocales = Services.locale.availableLocales;
assert(availableLocales.includes("ko-KR"));
assert(availableLocales.includes("ar"));
Services.locale.setRequestedLocales(["ko-KR");
Services.locale.requestedLocales = ["ko-KR"];
let appLocales = Services.locale.getAppLocalesAsBCP47();
let appLocales = Services.locale.appLocalesAsBCP47;
assert(appLocales[0], "ko-KR");
From here, a resource :js:`test.ftl` can be added to a `Localization` and for ID :js:`key`
@ -528,10 +527,10 @@ but it is also simpler:
.. code-block:: javascript
Services.locale.setAvailableLocales(["ko-KR", "ar"]);
Services.locale.setRequestedLocales(["ko-KR"]);
Services.locale.availableLocales = ["ko-KR", "ar"];
Services.locale.requestedLocales = ["ko-KR"];
let appLocales = Services.locale.getAppLocalesAsBCP47();
let appLocales = Services.locale.appLocalesAsBCP47;
assert(appLocales[0], "ko-KR");
In the future, Mozilla plans to add a third way for add-ons (`bug 1440969`_)

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

@ -581,7 +581,7 @@ class DOMLocalization extends Localization {
// This means that the DOM alternations and directionality
// are set in the same microtask.
await this.translateFragment(root);
let primaryLocale = Services.locale.getAppLocaleAsBCP47();
let primaryLocale = Services.locale.appLocaleAsBCP47;
let direction = Services.locale.isAppLocaleRTL ? "rtl" : "ltr";
root.setAttribute("lang", primaryLocale);
root.setAttribute(root.namespaceURI ===

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

@ -121,7 +121,7 @@ const L10nRegistry = {
throw new Error(`Source with name "${source.name}" already registered.`);
}
this.sources.set(source.name, source);
Services.locale.setAvailableLocales(this.getAvailableLocales());
Services.locale.availableLocales = this.getAvailableLocales();
},
/**
@ -137,7 +137,7 @@ const L10nRegistry = {
throw new Error(`Source with name "${source.name}" is not registered.`);
}
this.sources.set(source.name, source);
Services.locale.setAvailableLocales(this.getAvailableLocales());
Services.locale.availableLocales = this.getAvailableLocales();
},
/**
@ -147,7 +147,7 @@ const L10nRegistry = {
*/
removeSource(sourceName) {
this.sources.delete(sourceName);
Services.locale.setAvailableLocales(this.getAvailableLocales());
Services.locale.availableLocales = this.getAvailableLocales();
},
/**

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

@ -135,7 +135,7 @@ class CachedAsyncIterable extends CachedIterable {
* be localized into a different language - for example DevTools.
*/
function defaultGenerateMessages(resourceIds) {
const appLocales = Services.locale.getAppLocalesAsBCP47();
const appLocales = Services.locale.appLocalesAsBCP47;
return L10nRegistry.generateContexts(appLocales, resourceIds);
}
@ -335,7 +335,7 @@ class Localization {
// we want to eagerly fetch just that one.
// Otherwise, we're in a scenario where the first locale may
// be partial and we want to eagerly fetch a fallback as well.
const appLocale = Services.locale.getAppLocaleAsBCP47();
const appLocale = Services.locale.appLocaleAsBCP47;
const lastFallback = Services.locale.lastFallbackLocale;
const prefetchCount = appLocale === lastFallback ? 1 : 2;
this.ctxs.touchNext(prefetchCount);

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

@ -22,7 +22,7 @@ link =
`,
};
const originalLoad = L10nRegistry.load;
const originalRequested = Services.locale.getRequestedLocales();
const originalRequested = Services.locale.requestedLocales;
L10nRegistry.load = async function(url) {
return fs.hasOwnProperty(url) ? fs[url] : false;
@ -47,7 +47,7 @@ link =
// Cleanup
L10nRegistry.removeSource(source.name);
L10nRegistry.load = originalLoad;
Services.locale.setRequestedLocales(originalRequested);
Services.locale.requestedLocales = originalRequested;
SimpleTest.finish();
};

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

@ -21,7 +21,7 @@ subtitle = Welcome to Fluent
`,
};
const originalLoad = L10nRegistry.load;
const originalRequested = Services.locale.getRequestedLocales();
const originalRequested = Services.locale.requestedLocales;
L10nRegistry.load = async function(url) {
return fs.hasOwnProperty(url) ? fs[url] : false;
@ -46,7 +46,7 @@ subtitle = Welcome to Fluent
// Cleanup
L10nRegistry.removeSource(source.name);
L10nRegistry.load = originalLoad;
Services.locale.setRequestedLocales(originalRequested);
Services.locale.requestedLocales = originalRequested;
SimpleTest.finish();
};

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

@ -21,7 +21,7 @@ title2 = Hello Another World
`,
};
const originalLoad = L10nRegistry.load;
const originalRequested = Services.locale.getRequestedLocales();
const originalRequested = Services.locale.requestedLocales;
L10nRegistry.load = async function(url) {
return fs.hasOwnProperty(url) ? fs[url] : false;
@ -51,7 +51,7 @@ title2 = Hello Another World
// Cleanup
L10nRegistry.removeSource(source.name);
L10nRegistry.load = originalLoad;
Services.locale.setRequestedLocales(originalRequested);
Services.locale.requestedLocales = originalRequested;
SimpleTest.finish();
};

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

@ -20,7 +20,7 @@ add_task(async function test_methods_calling() {
"/localization/en-US/browser/menu.ftl": "key = [en] Value2\nkey2 = [en] Value3",
};
const originalLoad = L10nRegistry.load;
const originalRequested = Services.locale.getRequestedLocales();
const originalRequested = Services.locale.requestedLocales;
L10nRegistry.load = async function(url) {
return fs[url];
@ -44,7 +44,7 @@ add_task(async function test_methods_calling() {
L10nRegistry.sources.clear();
L10nRegistry.load = originalLoad;
Services.locale.setRequestedLocales(originalRequested);
Services.locale.requestedLocales = originalRequested;
});
add_task(async function test_builtins() {
@ -101,7 +101,7 @@ add_task(async function test_add_remove_resourceIds() {
"/localization/en-US/toolkit/menu.ftl": "key2 = Value2",
};
const originalLoad = L10nRegistry.load;
const originalRequested = Services.locale.getRequestedLocales();
const originalRequested = Services.locale.requestedLocales;
L10nRegistry.load = async function(url) {
return fs[url];
@ -137,5 +137,5 @@ add_task(async function test_add_remove_resourceIds() {
L10nRegistry.sources.clear();
L10nRegistry.load = originalLoad;
Services.locale.setRequestedLocales(originalRequested);
Services.locale.requestedLocales = originalRequested;
});

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

@ -10,7 +10,7 @@ const fs = {
"/localization/en-US/browser/menu.ftl": "key = [en] Value",
};
const originalLoad = L10nRegistry.load;
const originalRequested = Services.locale.getRequestedLocales();
const originalRequested = Services.locale.requestedLocales;
// Variable used to test for `L10nRegistry.load`
// execution count.
@ -92,5 +92,5 @@ add_task(async function test_ready() {
add_task(function cleanup() {
L10nRegistry.sources.clear();
L10nRegistry.load = originalLoad;
Services.locale.setRequestedLocales(originalRequested);
Services.locale.requestedLocales = originalRequested;
});

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

@ -17,7 +17,7 @@ key = This is a single message
.accesskey = f`,
};
originalValues.load = L10nRegistry.load;
originalValues.requested = Services.locale.getRequestedLocales();
originalValues.requested = Services.locale.requestedLocales;
L10nRegistry.load = async function(url) {
return fs[url];
@ -95,7 +95,7 @@ add_task(async function test_accented_works() {
L10nRegistry.sources.clear();
L10nRegistry.load = originalValues.load;
Services.locale.setRequestedLocales(originalValues.requested);
Services.locale.requestedLocales = originalValues.requested;
});
/**
@ -126,5 +126,5 @@ add_task(async function test_unavailable_strategy_works() {
Services.prefs.setStringPref("intl.l10n.pseudo", "");
L10nRegistry.sources.clear();
L10nRegistry.load = originalValues.load;
Services.locale.setRequestedLocales(originalValues.requested);
Services.locale.requestedLocales = originalValues.requested;
});

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

@ -97,7 +97,7 @@ SplitLocaleListStringIntoArray(nsACString& str, nsTArray<nsCString>& aRetVal)
}
}
static bool
static void
ReadRequestedLocales(nsTArray<nsCString>& aRetVal)
{
nsAutoCString str;
@ -116,13 +116,16 @@ ReadRequestedLocales(nsTArray<nsCString>& aRetVal)
} else {
SplitLocaleListStringIntoArray(str, aRetVal);
}
} else {
}
// This will happen when either the pref is not set,
// or parsing of the pref didn't produce any usable
// result.
if (aRetVal.IsEmpty()) {
nsAutoCString defaultLocale;
LocaleService::GetInstance()->GetDefaultLocale(defaultLocale);
aRetVal.AppendElement(defaultLocale);
}
return true;
}
LocaleService::LocaleService(bool aIsServer)
@ -148,7 +151,7 @@ LocaleService::NegotiateAppLocales(nsTArray<nsCString>& aRetVal)
GetRequestedLocales(requestedLocales);
NegotiateLanguages(requestedLocales, availableLocales, defaultLocale,
LangNegStrategy::Filtering, aRetVal);
kLangNegStrategyFiltering, aRetVal);
}
nsAutoCString lastFallbackLocale;
@ -202,72 +205,6 @@ LocaleService::~LocaleService()
}
}
void
LocaleService::GetAppLocalesAsLangTags(nsTArray<nsCString>& aRetVal)
{
if (mAppLocales.IsEmpty()) {
NegotiateAppLocales(mAppLocales);
}
for (uint32_t i = 0; i < mAppLocales.Length(); i++) {
nsAutoCString locale(mAppLocales[i]);
if (locale.LowerCaseEqualsASCII("ja-jp-macos")) {
aRetVal.AppendElement("ja-JP-mac");
} else {
aRetVal.AppendElement(locale);
}
}
}
void
LocaleService::GetAppLocalesAsBCP47(nsTArray<nsCString>& aRetVal)
{
if (mAppLocales.IsEmpty()) {
NegotiateAppLocales(mAppLocales);
}
aRetVal = mAppLocales;
}
void
LocaleService::GetRegionalPrefsLocales(nsTArray<nsCString>& aRetVal)
{
bool useOSLocales = Preferences::GetBool("intl.regional_prefs.use_os_locales", false);
// If the user specified that they want to use OS Regional Preferences locales,
// try to retrieve them and use.
if (useOSLocales) {
if (OSPreferences::GetInstance()->GetRegionalPrefsLocales(aRetVal)) {
return;
}
// If we fail to retrieve them, return the app locales.
GetAppLocalesAsBCP47(aRetVal);
return;
}
// Otherwise, fetch OS Regional Preferences locales and compare the first one
// to the app locale. If the language subtag matches, we can safely use
// the OS Regional Preferences locale.
//
// This facilitates scenarios such as Firefox in "en-US" and User sets
// regional prefs to "en-GB".
nsAutoCString appLocale;
AutoTArray<nsCString, 10> regionalPrefsLocales;
LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale);
if (!OSPreferences::GetInstance()->GetRegionalPrefsLocales(regionalPrefsLocales)) {
GetAppLocalesAsBCP47(aRetVal);
return;
}
if (LocaleService::LanguagesMatch(appLocale, regionalPrefsLocales[0])) {
aRetVal = regionalPrefsLocales;
return;
}
// Otherwise use the app locales.
GetAppLocalesAsBCP47(aRetVal);
}
void
LocaleService::AssignAppLocales(const nsTArray<nsCString>& aAppLocales)
{
@ -292,36 +229,6 @@ LocaleService::AssignRequestedLocales(const nsTArray<nsCString>& aRequestedLocal
}
}
bool
LocaleService::GetRequestedLocales(nsTArray<nsCString>& aRetVal)
{
if (mRequestedLocales.IsEmpty()) {
ReadRequestedLocales(mRequestedLocales);
}
aRetVal = mRequestedLocales;
return true;
}
bool
LocaleService::GetAvailableLocales(nsTArray<nsCString>& aRetVal)
{
MOZ_ASSERT(mIsServer, "This should only be called in the server mode.");
if (!mIsServer) {
return false;
}
if (mAvailableLocales.IsEmpty()) {
// If there are no available locales set, it means that L10nRegistry
// did not register its locale pool yet. The best course of action
// is to use packaged locales until that happens.
GetPackagedLocales(mAvailableLocales);
}
aRetVal = mAvailableLocales;
return true;
}
void
LocaleService::RequestedLocalesChanged()
{
@ -368,11 +275,11 @@ LocaleService::LocalesChanged()
// according to the desired negotiation strategy.
#define HANDLE_STRATEGY \
switch (aStrategy) { \
case LangNegStrategy::Lookup: \
case kLangNegStrategyLookup: \
return; \
case LangNegStrategy::Matching: \
case kLangNegStrategyMatching: \
continue; \
case LangNegStrategy::Filtering: \
case kLangNegStrategyFiltering: \
break; \
}
@ -420,7 +327,7 @@ LocaleService::LocalesChanged()
void
LocaleService::FilterMatches(const nsTArray<nsCString>& aRequested,
const nsTArray<nsCString>& aAvailable,
LangNegStrategy aStrategy,
int32_t aStrategy,
nsTArray<nsCString>& aRetVal)
{
// Local copy of the list of available locales, in Locale form for flexible
@ -434,7 +341,6 @@ LocaleService::FilterMatches(const nsTArray<nsCString>& aRequested,
for (auto& requested : aRequested) {
if (requested.IsEmpty()) {
MOZ_ASSERT(!requested.IsEmpty(), "Locale string cannot be empty.");
continue;
}
@ -466,7 +372,7 @@ LocaleService::FilterMatches(const nsTArray<nsCString>& aRequested,
aRetVal.AppendElement(aAvailable[match - availLocales.begin()]);
match->Invalidate();
foundMatch = true;
if (aStrategy != LangNegStrategy::Filtering) {
if (aStrategy != kLangNegStrategyFiltering) {
return true; // we only want the first match
}
}
@ -507,43 +413,6 @@ LocaleService::FilterMatches(const nsTArray<nsCString>& aRequested,
}
}
void
LocaleService::NegotiateLanguages(const nsTArray<nsCString>& aRequested,
const nsTArray<nsCString>& aAvailable,
const nsACString& aDefaultLocale,
LangNegStrategy aStrategy,
nsTArray<nsCString>& aRetVal)
{
MOZ_ASSERT(aDefaultLocale.IsEmpty() || Locale(aDefaultLocale).IsWellFormed(),
"If specified, default locale must be a well-formed BCP47 language tag.");
if (aStrategy == LangNegStrategy::Lookup && aDefaultLocale.IsEmpty()) {
NS_WARNING("Default locale should be specified when using lookup strategy.");
}
FilterMatches(aRequested, aAvailable, aStrategy, aRetVal);
if (aStrategy == LangNegStrategy::Lookup) {
// If the strategy is Lookup and Filtering returned no matches, use
// the default locale.
if (aRetVal.Length() == 0) {
// If the default locale is empty, we already issued a warning, so
// now we will just pick up the LocaleService's defaultLocale.
if (aDefaultLocale.IsEmpty()) {
nsAutoCString defaultLocale;
GetDefaultLocale(defaultLocale);
aRetVal.AppendElement(defaultLocale);
} else {
aRetVal.AppendElement(aDefaultLocale);
}
}
} else if (!aDefaultLocale.IsEmpty() && !aRetVal.Contains(aDefaultLocale)) {
// If it's not a Lookup strategy, add the default locale only if it's
// set and it's not in the results already.
aRetVal.AppendElement(aDefaultLocale);
}
}
bool
LocaleService::IsAppLocaleRTL()
{
@ -593,17 +462,6 @@ LocaleService::IsServer()
return mIsServer;
}
static char**
CreateOutArray(const nsTArray<nsCString>& aArray)
{
uint32_t n = aArray.Length();
char** result = static_cast<char**>(moz_xmalloc(n * sizeof(char*)));
for (uint32_t i = 0; i < n; i++) {
result[i] = moz_xstrdup(aArray[i].get());
}
return result;
}
static bool
GetGREFileContents(const char* aFilePath, nsCString* aOutString)
{
@ -673,15 +531,6 @@ LocaleService::InitPackagedLocales()
}
}
void
LocaleService::GetPackagedLocales(nsTArray<nsCString>& aRetVal)
{
if (mPackagedLocales.IsEmpty()) {
InitPackagedLocales();
}
aRetVal = mPackagedLocales;
}
/**
* mozILocaleService methods
*/
@ -723,25 +572,30 @@ LocaleService::GetLastFallbackLocale(nsACString& aRetVal)
}
NS_IMETHODIMP
LocaleService::GetAppLocalesAsLangTags(uint32_t* aCount, char*** aOutArray)
{
AutoTArray<nsCString, 32> locales;
GetAppLocalesAsLangTags(locales);
*aCount = locales.Length();
*aOutArray = CreateOutArray(locales);
return NS_OK;
}
NS_IMETHODIMP
LocaleService::GetAppLocalesAsBCP47(uint32_t* aCount, char*** aOutArray)
LocaleService::GetAppLocalesAsLangTags(nsTArray<nsCString>& aRetVal)
{
if (mAppLocales.IsEmpty()) {
NegotiateAppLocales(mAppLocales);
}
*aCount = mAppLocales.Length();
*aOutArray = CreateOutArray(mAppLocales);
for (uint32_t i = 0; i < mAppLocales.Length(); i++) {
nsAutoCString locale(mAppLocales[i]);
if (locale.LowerCaseEqualsASCII("ja-jp-macos")) {
aRetVal.AppendElement("ja-JP-mac");
} else {
aRetVal.AppendElement(locale);
}
}
return NS_OK;
}
NS_IMETHODIMP
LocaleService::GetAppLocalesAsBCP47(nsTArray<nsCString>& aRetVal)
{
if (mAppLocales.IsEmpty()) {
NegotiateAppLocales(mAppLocales);
}
aRetVal = mAppLocales;
return NS_OK;
}
@ -767,137 +621,116 @@ LocaleService::GetAppLocaleAsBCP47(nsACString& aRetVal)
}
NS_IMETHODIMP
LocaleService::GetRegionalPrefsLocales(uint32_t* aCount, char*** aOutArray)
LocaleService::GetRegionalPrefsLocales(nsTArray<nsCString>& aRetVal)
{
AutoTArray<nsCString,10> rgLocales;
bool useOSLocales = Preferences::GetBool("intl.regional_prefs.use_os_locales", false);
GetRegionalPrefsLocales(rgLocales);
// If the user specified that they want to use OS Regional Preferences locales,
// try to retrieve them and use.
if (useOSLocales) {
if (OSPreferences::GetInstance()->GetRegionalPrefsLocales(aRetVal)) {
return NS_OK;
}
*aCount = rgLocales.Length();
*aOutArray = static_cast<char**>(moz_xmalloc(*aCount * sizeof(char*)));
for (uint32_t i = 0; i < *aCount; i++) {
(*aOutArray)[i] = moz_xstrdup(rgLocales[i].get());
// If we fail to retrieve them, return the app locales.
GetAppLocalesAsBCP47(aRetVal);
return NS_OK;
}
// Otherwise, fetch OS Regional Preferences locales and compare the first one
// to the app locale. If the language subtag matches, we can safely use
// the OS Regional Preferences locale.
//
// This facilitates scenarios such as Firefox in "en-US" and User sets
// regional prefs to "en-GB".
nsAutoCString appLocale;
AutoTArray<nsCString, 10> regionalPrefsLocales;
LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale);
if (!OSPreferences::GetInstance()->GetRegionalPrefsLocales(regionalPrefsLocales)) {
GetAppLocalesAsBCP47(aRetVal);
return NS_OK;
}
if (LocaleService::LanguagesMatch(appLocale, regionalPrefsLocales[0])) {
aRetVal = regionalPrefsLocales;
return NS_OK;
}
// Otherwise use the app locales.
GetAppLocalesAsBCP47(aRetVal);
return NS_OK;
}
static LocaleService::LangNegStrategy
ToLangNegStrategy(int32_t aStrategy)
{
switch (aStrategy) {
case 1:
return LocaleService::LangNegStrategy::Matching;
case 2:
return LocaleService::LangNegStrategy::Lookup;
default:
return LocaleService::LangNegStrategy::Filtering;
}
}
NS_IMETHODIMP
LocaleService::NegotiateLanguages(const char** aRequested,
const char** aAvailable,
const char* aDefaultLocale,
LocaleService::NegotiateLanguages(const nsTArray<nsCString>& aRequested,
const nsTArray<nsCString>& aAvailable,
const nsACString& aDefaultLocale,
int32_t aStrategy,
uint32_t aRequestedCount,
uint32_t aAvailableCount,
uint32_t* aCount, char*** aRetVal)
nsTArray<nsCString>& aRetVal)
{
if (aStrategy < 0 || aStrategy > 2) {
return NS_ERROR_INVALID_ARG;
}
// Check that the given string contains only ASCII characters valid in tags
// (i.e. alphanumerics, plus '-' and '_'), and is non-empty.
auto validTagChars = [](const char* s) {
if (!s || !*s) {
return false;
}
while (*s) {
if (isalnum((unsigned char)*s) || *s == '-' || *s == '_' || *s == '*') {
s++;
MOZ_ASSERT(aDefaultLocale.IsEmpty() || Locale(aDefaultLocale).IsWellFormed(),
"If specified, default locale must be a well-formed BCP47 language tag.");
if (aStrategy == kLangNegStrategyLookup && aDefaultLocale.IsEmpty()) {
NS_WARNING("Default locale should be specified when using lookup strategy.");
}
FilterMatches(aRequested, aAvailable, aStrategy, aRetVal);
if (aStrategy == kLangNegStrategyLookup) {
// If the strategy is Lookup and Filtering returned no matches, use
// the default locale.
if (aRetVal.Length() == 0) {
// If the default locale is empty, we already issued a warning, so
// now we will just pick up the LocaleService's defaultLocale.
if (aDefaultLocale.IsEmpty()) {
nsAutoCString defaultLocale;
GetDefaultLocale(defaultLocale);
aRetVal.AppendElement(defaultLocale);
} else {
return false;
aRetVal.AppendElement(aDefaultLocale);
}
}
return true;
};
AutoTArray<nsCString, 100> requestedLocales;
for (uint32_t i = 0; i < aRequestedCount; i++) {
if (!validTagChars(aRequested[i])) {
continue;
}
requestedLocales.AppendElement(aRequested[i]);
} else if (!aDefaultLocale.IsEmpty() && !aRetVal.Contains(aDefaultLocale)) {
// If it's not a Lookup strategy, add the default locale only if it's
// set and it's not in the results already.
aRetVal.AppendElement(aDefaultLocale);
}
AutoTArray<nsCString, 100> availableLocales;
for (uint32_t i = 0; i < aAvailableCount; i++) {
if (!validTagChars(aAvailable[i])) {
continue;
}
availableLocales.AppendElement(aAvailable[i]);
}
nsAutoCString defaultLocale(aDefaultLocale);
LangNegStrategy strategy = ToLangNegStrategy(aStrategy);
AutoTArray<nsCString, 100> supportedLocales;
NegotiateLanguages(requestedLocales, availableLocales,
defaultLocale, strategy, supportedLocales);
*aRetVal =
static_cast<char**>(moz_xmalloc(sizeof(char*) * supportedLocales.Length()));
*aCount = 0;
for (const auto& supported : supportedLocales) {
(*aRetVal)[(*aCount)++] = moz_xstrdup(supported.get());
}
return NS_OK;
}
NS_IMETHODIMP
LocaleService::GetRequestedLocales(uint32_t* aCount, char*** aOutArray)
LocaleService::GetRequestedLocales(nsTArray<nsCString>& aRetVal)
{
AutoTArray<nsCString, 16> requestedLocales;
bool res = GetRequestedLocales(requestedLocales);
if (!res) {
NS_ERROR("Couldn't retrieve selected locales from prefs!");
return NS_ERROR_FAILURE;
if (mRequestedLocales.IsEmpty()) {
ReadRequestedLocales(mRequestedLocales);
}
*aCount = requestedLocales.Length();
*aOutArray = CreateOutArray(requestedLocales);
aRetVal = mRequestedLocales;
return NS_OK;
}
NS_IMETHODIMP
LocaleService::GetRequestedLocale(nsACString& aRetVal)
{
AutoTArray<nsCString, 16> requestedLocales;
bool res = GetRequestedLocales(requestedLocales);
if (!res) {
NS_ERROR("Couldn't retrieve selected locales from prefs!");
return NS_ERROR_FAILURE;
if (mRequestedLocales.IsEmpty()) {
ReadRequestedLocales(mRequestedLocales);
}
if (requestedLocales.Length() > 0) {
aRetVal = requestedLocales[0];
if (mRequestedLocales.Length() > 0) {
aRetVal = mRequestedLocales[0];
}
return NS_OK;
}
NS_IMETHODIMP
LocaleService::SetRequestedLocales(const char** aRequested,
uint32_t aRequestedCount)
LocaleService::SetRequestedLocales(const nsTArray<nsCString>& aRequested)
{
MOZ_ASSERT(mIsServer, "This should only be called in the server mode.");
if (!mIsServer) {
@ -906,14 +739,14 @@ LocaleService::SetRequestedLocales(const char** aRequested,
nsAutoCString str;
for (uint32_t i = 0; i < aRequestedCount; i++) {
nsAutoCString locale(aRequested[i]);
for (auto& req : aRequested) {
nsAutoCString locale(req);
if (!SanitizeForBCP47(locale, true)) {
NS_ERROR("Invalid language tag provided to SetRequestedLocales!");
return NS_ERROR_INVALID_ARG;
}
if (i > 0) {
if (!str.IsEmpty()) {
str.AppendLiteral(",");
}
str.Append(locale);
@ -924,18 +757,21 @@ LocaleService::SetRequestedLocales(const char** aRequested,
}
NS_IMETHODIMP
LocaleService::GetAvailableLocales(uint32_t* aCount, char*** aOutArray)
LocaleService::GetAvailableLocales(nsTArray<nsCString>& aRetVal)
{
AutoTArray<nsCString, 100> availableLocales;
bool res = GetAvailableLocales(availableLocales);
if (!res) {
NS_ERROR("Couldn't retrieve available locales!");
return NS_ERROR_FAILURE;
MOZ_ASSERT(mIsServer, "This should only be called in the server mode.");
if (!mIsServer) {
return NS_ERROR_UNEXPECTED;
}
*aCount = availableLocales.Length();
*aOutArray = CreateOutArray(availableLocales);
if (mAvailableLocales.IsEmpty()) {
// If there are no available locales set, it means that L10nRegistry
// did not register its locale pool yet. The best course of action
// is to use packaged locales until that happens.
GetPackagedLocales(mAvailableLocales);
}
aRetVal = mAvailableLocales;
return NS_OK;
}
@ -947,8 +783,7 @@ LocaleService::GetIsAppLocaleRTL(bool* aRetVal)
}
NS_IMETHODIMP
LocaleService::SetAvailableLocales(const char** aAvailable,
uint32_t aAvailableCount)
LocaleService::SetAvailableLocales(const nsTArray<nsCString>& aAvailable)
{
MOZ_ASSERT(mIsServer, "This should only be called in the server mode.");
if (!mIsServer) {
@ -957,8 +792,8 @@ LocaleService::SetAvailableLocales(const char** aAvailable,
nsTArray<nsCString> newLocales;
for (uint32_t i = 0; i < aAvailableCount; i++) {
nsAutoCString locale(aAvailable[i]);
for (auto& avail : aAvailable) {
nsAutoCString locale(avail);
if (!SanitizeForBCP47(locale, true)) {
NS_ERROR("Invalid language tag provided to SetAvailableLocales!");
return NS_ERROR_INVALID_ARG;
@ -975,14 +810,11 @@ LocaleService::SetAvailableLocales(const char** aAvailable,
}
NS_IMETHODIMP
LocaleService::GetPackagedLocales(uint32_t* aCount, char*** aOutArray)
LocaleService::GetPackagedLocales(nsTArray<nsCString>& aRetVal)
{
if (mPackagedLocales.IsEmpty()) {
InitPackagedLocales();
}
*aCount = mPackagedLocales.Length();
*aOutArray = CreateOutArray(mPackagedLocales);
aRetVal = mPackagedLocales;
return NS_OK;
}

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

@ -83,11 +83,9 @@ public:
* See the mozILocaleService.idl for detailed description of the
* strategies.
*/
enum class LangNegStrategy {
Filtering,
Matching,
Lookup
};
static const int32_t kLangNegStrategyFiltering = 0;
static const int32_t kLangNegStrategyMatching = 1;
static const int32_t kLangNegStrategyLookup = 2;
explicit LocaleService(bool aIsServer);
@ -109,45 +107,6 @@ public:
return RefPtr<LocaleService>(GetInstance()).forget();
}
/**
* Returns a list of locales that the application should be localized to.
*
* The result is a ordered list of valid locale IDs and it should be
* used for all APIs that accept list of locales, like ECMA402 and L10n APIs.
*
* This API always returns at least one locale.
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*
* Usage:
* nsTArray<nsCString> appLocales;
* LocaleService::GetInstance()->GetAppLocalesAsLangTags(appLocales);
*
* (See mozILocaleService.idl for a JS-callable version of this.)
*/
void GetAppLocalesAsLangTags(nsTArray<nsCString>& aRetVal);
void GetAppLocalesAsBCP47(nsTArray<nsCString>& aRetVal);
/**
* Returns a list of locales to use for any regional specific operations
* like date formatting, calendars, unit formatting etc.
*
* The result is a ordered list of valid locale IDs and it should be
* used for all APIs that accept list of locales, like ECMA402 and L10n APIs.
*
* This API always returns at least one locale.
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*
* Usage:
* nsTArray<nsCString> rgLocales;
* LocaleService::GetInstance()->GetRegionalPrefsLocales(rgLocales);
*
* (See mozILocaleService.idl for a JS-callable version of this.)
*/
void GetRegionalPrefsLocales(nsTArray<nsCString>& aRetVal);
/**
* This method should only be called in the client mode.
*
@ -160,53 +119,6 @@ public:
void AssignAppLocales(const nsTArray<nsCString>& aAppLocales);
void AssignRequestedLocales(const nsTArray<nsCString>& aRequestedLocales);
/**
* Returns a list of locales that the user requested the app to be
* localized to.
*
* The result is a sorted list of valid locale IDs and it should be
* used as a requestedLocales input list for languages negotiation.
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*
* Usage:
* nsTArray<nsCString> reqLocales;
* LocaleService::GetInstance()->GetRequestedLocales(reqLocales);
*
* Returns a boolean indicating if the attempt to retrieve prefs
* was successful.
*
* (See mozILocaleService.idl for a JS-callable version of this.)
*/
bool GetRequestedLocales(nsTArray<nsCString>& aRetVal);
/**
* Returns a list of available locales that can be used to
* localize the app.
*
* The result is an unsorted list of valid locale IDs and it should be
* used as a availableLocales input list for languages negotiation.
*
* Example: ["de", "en-US", "pl", "sr-Cyrl", "zh-Hans-HK"]
*
* Usage:
* nsTArray<nsCString> availLocales;
* LocaleService::GetInstance()->GetAvailableLocales(availLocales);
*
* Returns a boolean indicating if the attempt to retrieve at least
* one locale was successful.
*
* (See mozILocaleService.idl for a JS-callable version of this.)
*/
bool GetAvailableLocales(nsTArray<nsCString>& aRetVal);
/**
* Returns a list of locales packaged into the app bundle.
*
* (See mozILocaleService.idl for a JS-callable version of this.)
*/
void GetPackagedLocales(nsTArray<nsCString>& aRetVal);
/**
* Those two functions allow to trigger cache invalidation on one of the
* three cached values.
@ -223,32 +135,6 @@ public:
void RequestedLocalesChanged();
void LocalesChanged();
/**
* Negotiates the best locales out of an ordered list of requested locales and
* a list of available locales.
*
* Internally it uses the following naming scheme:
*
* Requested - locales requested by the user
* Available - locales for which the data is available
* Supported - locales negotiated by the algorithm
*
* Additionally, if defaultLocale is provided, it adds it to the end of the
* result list as a "last resort" locale.
*
* Strategy is one of the three strategies described at the top of this file.
*
* The result list is canonicalized and ordered according to the order
* of the requested locales.
*
* (See mozILocaleService.idl for a JS-callable version of this.)
*/
void NegotiateLanguages(const nsTArray<nsCString>& aRequested,
const nsTArray<nsCString>& aAvailable,
const nsACString& aDefaultLocale,
LangNegStrategy aLangNegStrategy,
nsTArray<nsCString>& aRetVal);
/**
* Returns whether the current app locale is RTL.
*/
@ -262,7 +148,7 @@ public:
private:
void FilterMatches(const nsTArray<nsCString>& aRequested,
const nsTArray<nsCString>& aAvailable,
LangNegStrategy aStrategy,
int32_t aStrategy,
nsTArray<nsCString>& aRetVal);
void NegotiateAppLocales(nsTArray<nsCString>& aRetVal);

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

@ -80,13 +80,9 @@ interface mozILocaleService : nsISupports
* use the BCP47 form.
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*
* (See LocaleService.h for a more C++-friendly version of this.)
*/
void getAppLocalesAsLangTags([optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aLocales);
void getAppLocalesAsBCP47([optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aLocales);
readonly attribute Array<ACString> appLocalesAsLangTags;
readonly attribute Array<ACString> appLocalesAsBCP47;
/**
* Returns a list of locales to use for any regional specific operations
@ -98,11 +94,8 @@ interface mozILocaleService : nsISupports
* This API always returns at least one locale.
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*
* (See LocaleService.h for a more C++-friendly version of this.)
*/
void getRegionalPrefsLocales([optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aOutArray);
readonly attribute Array<ACString> regionalPrefsLocales;
/**
* Negotiates the best locales out of a ordered list of requested locales and
@ -124,14 +117,10 @@ interface mozILocaleService : nsISupports
*
* (See LocaleService.h for a more C++-friendly version of this.)
*/
void negotiateLanguages([array, size_is(aRequestedCount)] in string aRequested,
[array, size_is(aAvailableCount)] in string aAvailable,
[optional] in string aDefaultLocale,
[optional] in long langNegStrategy,
[optional] in unsigned long aRequestedCount,
[optional] in unsigned long aAvailableCount,
[optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aLocales);
Array<ACString> negotiateLanguages(in Array<ACString> aRequested,
in Array<ACString> aAvailable,
[optional] in ACString aDefaultLocale,
[optional] in long langNegStrategy);
/**
* Returns the best locale that the application should be localized to.
@ -144,15 +133,15 @@ interface mozILocaleService : nsISupports
* When retrieving the locales for Intl API or ICU locale settings,
* use the BCP47 form.
*
* Where possible, getAppLocales*() should be preferred over this API and
* Where possible, appLocales* should be preferred over this API and
* all callsites should handle some form of "best effort" language
* negotiation to respect user preferences in case the use case does
* not have data for the first locale in the list.
*
* Example: "zh-Hans-HK"
*/
ACString getAppLocaleAsLangTag();
ACString getAppLocaleAsBCP47();
readonly attribute ACString appLocaleAsLangTag;
readonly attribute ACString appLocaleAsBCP47;
/**
* Returns a list of locales that the user requested the app to be
@ -163,32 +152,12 @@ interface mozILocaleService : nsISupports
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*/
void getRequestedLocales([optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aLocales);
attribute Array<ACString> requestedLocales;
/**
* Returns the top-requested locale from the user, or an empty string if none is set.
*/
ACString getRequestedLocale();
/**
* Sets a list of locales that the user requested the app to be
* localized to.
*
* The argument is an ordered list of locale IDs which should be
* used as a requestedLocales input list for language negotiation.
*
* The current implementation is limited to handle at most one
* locale passed to the API. In the future we'll transition to support
* whole fallback chain.
*
* If an empty list is passed, the list of requested locales will
* be picked from the operating system.
*
* Example: ["de"]
*/
void setRequestedLocales([array, size_is(aRequestedCount)] in string aRequested,
[optional] in unsigned long aRequestedCount);
readonly attribute ACString requestedLocale;
/**
* Returns a list of locales that the app can be localized to.
@ -198,37 +167,17 @@ interface mozILocaleService : nsISupports
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*/
void getAvailableLocales([optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aLocales);
attribute Array<ACString> availableLocales;
/**
* Returns whether the current app locale is RTL.
*/
readonly attribute boolean isAppLocaleRTL;
/**
* Sets a list of locales the application has resources to be localized into.
*
* The primary use of this function is to let L10nRegistry communicate all
* locale updates.
*
* The secondary use case is for testing purposes in scenarios in which the
* actual resources don't have to be available.
* It is recommended for tests to create a mock FileSource and register it in
* the L10nRegistry rather than using this call, in order to emulate full
* resource availability cycle.
*
*/
void setAvailableLocales([array, size_is(aAvailableCount)] in string aAvailable,
[optional] in unsigned long aAvailableCount);
/**
* Returns a list of locales packaged into the app bundle.
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*
* (See LocaleService.h for a more C++-friendly version of this.)
*/
void getPackagedLocales([optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aOutArray);
readonly attribute Array<ACString> packagedLocales;
};

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

@ -15,8 +15,8 @@ TEST(Intl_Locale_LocaleService, Negotiate) {
nsTArray<nsCString> availableLocales;
nsTArray<nsCString> supportedLocales;
nsAutoCString defaultLocale("en-US");
LocaleService::LangNegStrategy strategy =
LocaleService::LangNegStrategy::Filtering;
int32_t strategy =
LocaleService::kLangNegStrategyFiltering;
requestedLocales.AppendElement(NS_LITERAL_CSTRING("sr"));
@ -36,8 +36,8 @@ TEST(Intl_Locale_LocaleService, UseLSDefaultLocale) {
nsTArray<nsCString> availableLocales;
nsTArray<nsCString> supportedLocales;
nsAutoCString defaultLocale("");
LocaleService::LangNegStrategy strategy =
LocaleService::LangNegStrategy::Lookup;
int32_t strategy =
LocaleService::kLangNegStrategyLookup;
requestedLocales.AppendElement(NS_LITERAL_CSTRING("sr"));

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

@ -30,11 +30,11 @@ add_test(function test_lastFallbackLocale() {
run_next_test();
});
add_test(function test_getAppLocalesAsLangTags() {
const appLocale = localeService.getAppLocaleAsLangTag();
add_test(function test_appLocalesAsLangTags() {
const appLocale = localeService.appLocaleAsLangTag;
Assert.ok(appLocale != "", "appLocale is non-empty");
const appLocales = localeService.getAppLocalesAsLangTags();
const appLocales = localeService.appLocalesAsLangTags;
Assert.ok(Array.isArray(appLocales), "appLocales returns an array");
Assert.ok(appLocale == appLocales[0], "appLocale matches first entry in appLocales");
@ -48,8 +48,8 @@ add_test(function test_getAppLocalesAsLangTags() {
const PREF_REQUESTED_LOCALES = "intl.locale.requested";
const REQ_LOC_CHANGE_EVENT = "intl:requested-locales-changed";
add_test(function test_getRequestedLocales() {
const requestedLocales = localeService.getRequestedLocales();
add_test(function test_requestedLocales() {
const requestedLocales = localeService.requestedLocales;
Assert.ok(Array.isArray(requestedLocales), "requestedLocales returns an array");
run_next_test();
@ -61,9 +61,9 @@ add_test(function test_getRequestedLocales() {
* pref for matchOS is set to true.
*
* Then, we test that when the matchOS is set to true, we will retrieve
* OS locale from getRequestedLocales.
* OS locale from requestedLocales.
*/
add_test(function test_getRequestedLocales_matchOS() {
add_test(function test_requestedLocales_matchOS() {
do_test_pending();
Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "ar-IR");
@ -72,7 +72,7 @@ add_test(function test_getRequestedLocales_matchOS() {
observe: function (aSubject, aTopic, aData) {
switch (aTopic) {
case REQ_LOC_CHANGE_EVENT:
const reqLocs = localeService.getRequestedLocales();
const reqLocs = localeService.requestedLocales;
Assert.ok(reqLocs[0] === osPrefs.systemLocale);
Services.obs.removeObserver(observer, REQ_LOC_CHANGE_EVENT);
do_test_finished();
@ -91,7 +91,7 @@ add_test(function test_getRequestedLocales_matchOS() {
* event for requested locales change, it will be fired when the
* pref for browser UI locale changes.
*/
add_test(function test_getRequestedLocales_onChange() {
add_test(function test_requestedLocales_onChange() {
do_test_pending();
Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "ar-IR");
@ -100,7 +100,7 @@ add_test(function test_getRequestedLocales_onChange() {
observe: function (aSubject, aTopic, aData) {
switch (aTopic) {
case REQ_LOC_CHANGE_EVENT:
const reqLocs = localeService.getRequestedLocales();
const reqLocs = localeService.requestedLocales;
Assert.ok(reqLocs[0] === "sr-RU");
Services.obs.removeObserver(observer, REQ_LOC_CHANGE_EVENT);
do_test_finished();
@ -114,10 +114,10 @@ add_test(function test_getRequestedLocales_onChange() {
run_next_test();
});
add_test(function test_getRequestedLocale() {
add_test(function test_requestedLocale() {
Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "tlh");
let requestedLocale = localeService.getRequestedLocale();
let requestedLocale = localeService.requestedLocale;
Assert.ok(requestedLocale === "tlh", "requestedLocale returns the right value");
Services.prefs.clearUserPref(PREF_REQUESTED_LOCALES);
@ -125,10 +125,10 @@ add_test(function test_getRequestedLocale() {
run_next_test();
});
add_test(function test_setRequestedLocales() {
localeService.setRequestedLocales(['de-AT', 'de-DE', 'de-CH']);
add_test(function test_requestedLocales() {
localeService.requestedLocales = ['de-AT', 'de-DE', 'de-CH'];
let locales = localeService.getRequestedLocales();
let locales = localeService.requestedLocales;
Assert.ok(locales[0] === 'de-AT');
Assert.ok(locales[1] === 'de-DE');
Assert.ok(locales[2] === 'de-CH');
@ -142,22 +142,22 @@ add_test(function test_isAppLocaleRTL() {
run_next_test();
});
add_test(function test_getPackagedLocales() {
const locales = localeService.getPackagedLocales();
add_test(function test_packagedLocales() {
const locales = localeService.packagedLocales;
Assert.ok(locales.length !== 0, "Packaged locales are empty");
run_next_test();
});
add_test(function test_setAvailableLocales() {
const avLocales = localeService.getAvailableLocales();
localeService.setAvailableLocales(["und", "ar-IR"]);
add_test(function test_availableLocales() {
const avLocales = localeService.availableLocales;
localeService.availableLocales = ["und", "ar-IR"];
let locales = localeService.getAvailableLocales();
let locales = localeService.availableLocales;
Assert.ok(locales.length == 2);
Assert.ok(locales[0] === 'und');
Assert.ok(locales[1] === 'ar-IR');
localeService.setAvailableLocales(avLocales);
localeService.availableLocales = avLocales;
run_next_test();
});
@ -165,10 +165,10 @@ add_test(function test_setAvailableLocales() {
/**
* This test verifies that all values coming from the pref are sanitized.
*/
add_test(function test_getRequestedLocales_sanitize() {
add_test(function test_requestedLocales_sanitize() {
Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "de,2,#$@#,pl,ąó,!a2,DE-at,,;");
let locales = localeService.getRequestedLocales();
let locales = localeService.requestedLocales;
Assert.equal(locales[0], "de");
Assert.equal(locales[1], "pl");
Assert.equal(locales[2], "de-AT");
@ -181,27 +181,27 @@ add_test(function test_getRequestedLocales_sanitize() {
});
add_test(function test_handle_ja_JP_mac() {
const bkpAvLocales = localeService.getAvailableLocales();
const bkpAvLocales = localeService.availableLocales;
localeService.setAvailableLocales(["ja-JP-mac", "en-US"]);
localeService.availableLocales = ["ja-JP-mac", "en-US"];
localeService.setRequestedLocales(['ja-JP-mac']);
localeService.requestedLocales = ['ja-JP-mac'];
let reqLocales = localeService.getRequestedLocales();
let reqLocales = localeService.requestedLocales;
Assert.equal(reqLocales[0], 'ja-JP-macos');
let avLocales = localeService.getAvailableLocales();
let avLocales = localeService.availableLocales;
Assert.equal(avLocales[0], 'ja-JP-macos');
let appLocales = localeService.getAppLocalesAsBCP47();
let appLocales = localeService.appLocalesAsBCP47;
Assert.equal(appLocales[0], 'ja-JP-macos');
let appLocalesAsLT = localeService.getAppLocalesAsLangTags();
let appLocalesAsLT = localeService.appLocalesAsLangTags;
Assert.equal(appLocalesAsLT[0], 'ja-JP-mac');
Assert.equal(localeService.getAppLocaleAsLangTag(), "ja-JP-mac");
Assert.equal(localeService.appLocaleAsLangTag, "ja-JP-mac");
localeService.setAvailableLocales(bkpAvLocales);
localeService.availableLocales = bkpAvLocales;
run_next_test();
});

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

@ -82,23 +82,9 @@ const data = {
[["ja-JP-mac", "de-DE"], ["ja-JP-mac", "de-DE"], ["ja-JP-mac", "de-DE"]],
],
"should not crash on invalid input": [
[null, ["fr-FR"], []],
[[null], [], []],
[[undefined], [], []],
[[undefined], [null], []],
[[undefined], [undefined], []],
[[null], [null], null, null, []],
[undefined, ["fr-FR"], []],
[2, ["fr-FR"], []],
["fr-FR", ["fr-FR"], []],
[["fą-FŻ"], ["ór_Fń"], []],
[["fr-FR"], null, []],
[["fr-FR"], undefined, []],
[["fr-FR"], 2, []],
[["fr-FR"], "fr-FR", []],
[["2"], ["ąóżł"], []],
[[[]], ["fr-FR"], []],
[[[]], [[2]], []],
[[[""]], ["fr-FR"], []],
],
},
"matching": {
@ -143,4 +129,26 @@ function run_test()
}
}
}
// Verify that we error out when requested or available is not an array.
for ([req, avail] in [
[null, ["fr-FR"]],
[undefined, ["fr-FR"]],
[2, ["fr-FR"]],
["fr-FR", ["fr-FR"]],
[["fr-FR"], null],
[["fr-FR"], undefined],
[["fr-FR"], 2],
[["fr-FR"], "fr-FR"],
[[null], []],
[[undefined], []],
[[undefined], [null]],
[[undefined], [undefined]],
[[null], [null]],
[[[]], [[2]]],
]) {
Assert.throws(() => {
nl(req, avail);
}, err => err.result == Cr.NS_ERROR_XPC_CANT_CONVERT_PRIMITIVE_TO_ARRAY);
}
}

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

@ -464,7 +464,7 @@ extern JS_FRIEND_API(JS::Zone*)
GetRealmZone(JS::Realm* realm);
typedef bool
(* PreserveWrapperCallback)(JSContext* cx, JSObject* obj);
(* PreserveWrapperCallback)(JSContext* cx, JS::HandleObject obj);
typedef enum {
CollectNurseryBeforeDump,

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

@ -3511,7 +3511,7 @@ DisassWithSrc(JSContext* cx, unsigned argc, Value* vp)
/* Pretend we can always preserve wrappers for dummy DOM objects. */
static bool
DummyPreserveWrapperCallback(JSContext* cx, JSObject* obj)
DummyPreserveWrapperCallback(JSContext* cx, HandleObject obj)
{
return true;
}

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

@ -2828,7 +2828,7 @@ DestroyRealm(JSFreeOp* fop, JS::Realm* realm)
}
static bool
PreserveWrapper(JSContext* cx, JSObject* obj)
PreserveWrapper(JSContext* cx, JS::Handle<JSObject*> obj)
{
MOZ_ASSERT(cx);
MOZ_ASSERT(obj);

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

@ -43,18 +43,32 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=777385
make_live_map();
// DOMPoint is a non-nsISupports refCounted class using WebIDL bindings.
// non-nsISupports cycle-collected classes should fail as weak map keys.
let context = new DOMPoint(1, 2, 3);
let contextFail = false;
try {
live_map.set(context, 2);
} catch (e) {
contextFail = true;
// CanvasGradient is a non-nsISupports wrapper cached class using WebIDL
// bindings. If we used it as a key in a weak map, then it should not be
// removed from the weak map as long as it remains alive.
let doc = new DOMParser().parseFromString("", "text/html");
let canv = doc.createElement("canvas");
let ctx = canv.getContext("2d");
let add_non_isupports2 = function () {
let grad = ctx.createLinearGradient(0, 0, 0, 0);
ctx.strokeStyle = grad;
let gradFail = false;
try {
live_map.set(grad, 23456);
} catch (e) {
gradFail = true;
}
ok(!gradFail, "Using a wrapper cached non-nsISupports class as a weak map key should not produce an exception.");
is(live_map.get(grad), 23456, "Live map should have live DOMPoint with right value before GC.");
}
ok(contextFail, "Cycle collected non-nsISupports classes aren't allowed as weak map keys.");
add_non_isupports2();
/* Set up for running precise GC/CC then check the results. */
@ -65,10 +79,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=777385
SpecialPowers.DOMWindowUtils.garbageCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
is(ChromeUtils.nondeterministicGetWeakMapKeys(live_map).length, 1,
is(ChromeUtils.nondeterministicGetWeakMapKeys(live_map).length, 2,
"Live nsISupports new DOM bindings wrappercached native weak map key should not be removed.");
is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value after GC.");
is(live_map.get(ctx.strokeStyle), 23456, "Live map should have live gradient with right value after GC.");
SimpleTest.finish();
});

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

@ -1921,9 +1921,9 @@ RestyleManager::AnimationsWithDestroyedFrame
#ifdef DEBUG
static bool
IsAnonBox(const nsIFrame& aFrame)
IsAnonBox(const nsIFrame* aFrame)
{
return aFrame.Style()->IsAnonBox();
return aFrame->Style()->IsAnonBox();
}
static const nsIFrame*
@ -1937,15 +1937,15 @@ FirstContinuationOrPartOfIBSplit(const nsIFrame* aFrame)
}
static const nsIFrame*
ExpectedOwnerForChild(const nsIFrame& aFrame)
ExpectedOwnerForChild(const nsIFrame* aFrame)
{
const nsIFrame* parent = aFrame.GetParent();
if (aFrame.IsTableFrame()) {
const nsIFrame* parent = aFrame->GetParent();
if (aFrame->IsTableFrame()) {
MOZ_ASSERT(parent->IsTableWrapperFrame());
parent = parent->GetParent();
}
if (IsAnonBox(aFrame) && !aFrame.IsTextFrame()) {
if (IsAnonBox(aFrame) && !aFrame->IsTextFrame()) {
if (parent->IsLineFrame()) {
parent = parent->GetParent();
}
@ -1953,11 +1953,11 @@ ExpectedOwnerForChild(const nsIFrame& aFrame)
nullptr : FirstContinuationOrPartOfIBSplit(parent);
}
if (aFrame.IsBulletFrame()) {
if (aFrame->IsBulletFrame()) {
return FirstContinuationOrPartOfIBSplit(parent);
}
if (aFrame.IsLineFrame()) {
if (aFrame->IsLineFrame()) {
// A ::first-line always ends up here via its block, which is therefore the
// right expected owner. That block can be an
// anonymous box. For example, we could have a ::first-line on a columnated
@ -1967,7 +1967,7 @@ ExpectedOwnerForChild(const nsIFrame& aFrame)
return parent;
}
if (aFrame.IsLetterFrame()) {
if (aFrame->IsLetterFrame()) {
// Ditto for ::first-letter. A first-letter always arrives here via its
// direct parent, except when it's parented to a ::first-line.
if (parent->IsLineFrame()) {
@ -1987,13 +1987,13 @@ ExpectedOwnerForChild(const nsIFrame& aFrame)
// We've handled already anon boxes and bullet frames, so now we're looking at
// a frame of a DOM element or pseudo. Hop through anon and line-boxes
// generated by our DOM parent, and go find the owner frame for it.
while (parent && (IsAnonBox(*parent) || parent->IsLineFrame())) {
while (parent && (IsAnonBox(parent) || parent->IsLineFrame())) {
auto* pseudo = parent->Style()->GetPseudo();
if (pseudo == nsCSSAnonBoxes::tableWrapper()) {
const nsIFrame* tableFrame = parent->PrincipalChildList().FirstChild();
MOZ_ASSERT(tableFrame->IsTableFrame());
// Handle :-moz-table and :-moz-inline-table.
parent = IsAnonBox(*tableFrame) ? parent->GetParent() : tableFrame;
parent = IsAnonBox(tableFrame) ? parent->GetParent() : tableFrame;
} else {
// We get the in-flow parent here so that we can handle the OOF anonymous
// boxed to get the correct parent.
@ -2016,12 +2016,12 @@ ServoRestyleState::AssertOwner(const ServoRestyleState& aParent) const
// chains of ServoRestyleStates in some cases where it's just not worth it.
#ifdef DEBUG
if (aParent.mOwner) {
const nsIFrame* owner = ExpectedOwnerForChild(*mOwner);
const nsIFrame* owner = ExpectedOwnerForChild(mOwner);
if (owner != aParent.mOwner) {
MOZ_ASSERT(IsAnonBox(*owner),
MOZ_ASSERT(IsAnonBox(owner),
"Should only have expected owner weirdness when anon boxes are involved");
bool found = false;
for (; owner; owner = ExpectedOwnerForChild(*owner)) {
for (; owner; owner = ExpectedOwnerForChild(owner)) {
if (owner == aParent.mOwner) {
found = true;
break;
@ -2034,7 +2034,7 @@ ServoRestyleState::AssertOwner(const ServoRestyleState& aParent) const
}
nsChangeHint
ServoRestyleState::ChangesHandledFor(const nsIFrame& aFrame) const
ServoRestyleState::ChangesHandledFor(const nsIFrame* aFrame) const
{
if (!mOwner) {
MOZ_ASSERT(!mChangesHandled);
@ -2399,7 +2399,7 @@ public:
uint32_t equalStructs;
mComputedHint = oldStyle->CalcStyleDifference(&aNewStyle, &equalStructs);
mComputedHint = NS_RemoveSubsumedHints(
mComputedHint, mParentRestyleState.ChangesHandledFor(*aTextFrame));
mComputedHint, mParentRestyleState.ChangesHandledFor(aTextFrame));
}
if (mComputedHint) {
@ -2515,7 +2515,7 @@ UpdateOneAdditionalComputedStyle(nsIFrame* aFrame,
aOldContext.CalcStyleDifference(newStyle, &equalStructs);
if (!aFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
childHint = NS_RemoveSubsumedHints(
childHint, aRestyleState.ChangesHandledFor(*aFrame));
childHint, aRestyleState.ChangesHandledFor(aFrame));
}
if (childHint) {
@ -2685,7 +2685,7 @@ RestyleManager::ProcessPostTraversal(
} else {
maybeAnonBoxChild = primaryFrame;
changeHint = NS_RemoveSubsumedHints(
changeHint, aRestyleState.ChangesHandledFor(*styleFrame));
changeHint, aRestyleState.ChangesHandledFor(styleFrame));
}
// If the parent wasn't restyled, the styles of our anon box parents won't

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

@ -105,10 +105,10 @@ public:
#ifdef DEBUG
void AssertOwner(const ServoRestyleState& aParentState) const;
nsChangeHint ChangesHandledFor(const nsIFrame&) const;
nsChangeHint ChangesHandledFor(const nsIFrame*) const;
#else
void AssertOwner(const ServoRestyleState&) const {}
nsChangeHint ChangesHandledFor(const nsIFrame&) const
nsChangeHint ChangesHandledFor(const nsIFrame*) const
{
return mChangesHandled;
}

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

@ -10781,7 +10781,7 @@ nsIFrame::UpdateStyleOfOwnedChildFrame(
// frame tree.
if (!aChildFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
childHint = NS_RemoveSubsumedHints(
childHint, aRestyleState.ChangesHandledFor(*aChildFrame));
childHint, aRestyleState.ChangesHandledFor(aChildFrame));
}
if (childHint) {
if (childHint & nsChangeHint_ReconstructFrame) {

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

@ -55,18 +55,21 @@ static std::bitset<128> GetForbiddenSdpPayloadTypes() {
return forbidden;
}
static std::string GetRandomHex()
static std::string GetRandomHex(size_t words)
{
uint32_t rand;
SECStatus rv =
PK11_GenerateRandom(reinterpret_cast<unsigned char*>(&rand), sizeof(rand));
if (rv != SECSuccess) {
MOZ_CRASH();
return "";
}
std::ostringstream os;
os << std::hex << std::setfill('0') << std::setw(8) << rand;
for (size_t i = 0; i < words; ++i) {
uint32_t rand;
SECStatus rv =
PK11_GenerateRandom(reinterpret_cast<unsigned char*>(&rand), sizeof(rand));
if (rv != SECSuccess) {
MOZ_CRASH();
return "";
}
os << std::hex << std::setfill('0') << std::setw(8) << rand;
}
return os.str();
}
@ -88,8 +91,8 @@ JsepSessionImpl::Init()
mRunSdpComparer = Preferences::GetBool("media.peerconnection.sdp.rust.compare",
false);
mIceUfrag = GetRandomHex();
mIcePwd = GetRandomHex();
mIceUfrag = GetRandomHex(1);
mIcePwd = GetRandomHex(4);
return NS_OK;
}
@ -2390,8 +2393,8 @@ JsepSessionImpl::SetIceRestarting(bool restarting)
mOldIceUfrag = mIceUfrag;
mOldIcePwd = mIcePwd;
}
mIceUfrag = GetRandomHex();
mIcePwd = GetRandomHex();
mIceUfrag = GetRandomHex(1);
mIcePwd = GetRandomHex(4);
} else if (IsIceRestarting()) {
// restarting -> not restarting, restore old ufrag/pwd
mIceUfrag = mOldIceUfrag;

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

@ -396,7 +396,7 @@ var BrowserApp = {
]);
// Initialize the default l10n resource sources for L10nRegistry.
let locales = Services.locale.getPackagedLocales();
let locales = Services.locale.packagedLocales;
const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/");
L10nRegistry.registerSource(greSource);
@ -1698,7 +1698,7 @@ var BrowserApp = {
},
getUALocalePref: function () {
return Services.locale.getRequestedLocale() || undefined;
return Services.locale.requestedLocale || undefined;
},
getOSLocalePref: function () {
@ -1775,9 +1775,9 @@ var BrowserApp = {
case "Locale:Changed": {
if (data) {
Services.locale.setRequestedLocales([data.languageTag]);
Services.locale.requestedLocales = [data.languageTag];
} else {
Services.locale.setRequestedLocales([]);
Services.locale.requestedLocales = [];
}
console.log("Gecko display locale: " + this.getUALocalePref());

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

@ -106,7 +106,7 @@ DirectoryProvider.prototype = {
return;
let curLocale = "";
let reqLocales = Services.locale.getRequestedLocales();
let reqLocales = Services.locale.requestedLocales;
if (reqLocales.length > 0) {
curLocale = reqLocales[0];
}

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

@ -119,13 +119,13 @@ GeckoViewStartup.prototype = {
GeckoViewTelemetryController.setup();
// Initialize the default l10n resource sources for L10nRegistry.
let locales = Services.locale.getPackagedLocales();
let locales = Services.locale.packagedLocales;
const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/");
L10nRegistry.registerSource(greSource);
// Listen for global EventDispatcher messages
EventDispatcher.instance.registerListener(
(aEvent, aData, aCallback) => Services.locale.setRequestedLocales([aData.languageTag]),
(aEvent, aData, aCallback) => Services.locale.requestedLocales = [aData.languageTag],
"GeckoView:SetLocale");
break;
}

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

@ -25,7 +25,7 @@ class LocaleTest : BaseSessionTest() {
val index = sessionRule.waitForChromeJS(String.format(
"(function() {" +
" return ChromeUtils.import('resource://gre/modules/Services.jsm', {})" +
" .Services.locale.getRequestedLocales().indexOf('en-GB');" +
" .Services.locale.requestedLocales.indexOf('en-GB');" +
"})()")) as Double;
assertThat("Requested locale is found", index, greaterThanOrEqualTo(0.0));

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

@ -7,7 +7,7 @@ from __future__ import absolute_import
from setuptools import setup, find_packages
PACKAGE_NAME = 'mozrunner'
PACKAGE_VERSION = '7.0.1'
PACKAGE_VERSION = '7.0.2'
desc = """Reliable start/stop/configuration of Mozilla Applications (Firefox, Thunderbird, etc.)"""

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

@ -15,7 +15,7 @@ deps = ['httplib2 == 0.9.2',
'mozinstall == 1.16',
'mozprocess == 0.26',
'mozprofile == 2.0.0',
'mozrunner == 7.0.1',
'mozrunner == 7.0.2',
'mozversion == 1.5',
]

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

@ -1491,7 +1491,7 @@ class Extension extends ExtensionData {
}
get manifestCacheKey() {
return [this.id, this.version, Services.locale.getAppLocaleAsLangTag()];
return [this.id, this.version, Services.locale.appLocaleAsLangTag];
}
get isPrivileged() {
@ -1723,7 +1723,7 @@ class Extension extends ExtensionData {
let locales = await this.promiseLocales();
let matches = Services.locale.negotiateLanguages(
Services.locale.getAppLocalesAsLangTags(),
Services.locale.appLocalesAsLangTags,
Array.from(locales.keys()),
this.defaultLocale);

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

@ -1929,7 +1929,7 @@ LocaleData.prototype = {
get uiLocale() {
return Services.locale.getAppLocaleAsBCP47();
return Services.locale.appLocaleAsBCP47;
},
};

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

@ -11,11 +11,11 @@ server.registerDirectory("/data/", do_get_file("data"));
const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
var originalReqLocales = Services.locale.getRequestedLocales();
var originalReqLocales = Services.locale.requestedLocales;
registerCleanupFunction(() => {
Preferences.reset("intl.accept_languages");
Services.locale.setRequestedLocales(originalReqLocales);
Services.locale.requestedLocales = originalReqLocales;
});
@ -221,12 +221,12 @@ add_task(async function test_i18n_negotiation() {
//
// In the future, we should provide some way for tests to decouple their
// language selection from that of Firefox.
Services.locale.setAvailableLocales(["en-US", "fr", "jp"]);
Services.locale.availableLocales = ["en-US", "fr", "jp"];
let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
for (let [lang, msg] of [["en-US", "English."], ["jp", "\u65e5\u672c\u8a9e"]]) {
Services.locale.setRequestedLocales([lang]);
Services.locale.requestedLocales = [lang];
let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
@ -238,7 +238,7 @@ add_task(async function test_i18n_negotiation() {
await extension.unload();
}
Services.locale.setRequestedLocales(originalReqLocales);
Services.locale.requestedLocales = originalReqLocales;
await contentPage.close();
});
@ -383,7 +383,7 @@ add_task(async function test_get_ui_language() {
// We don't currently have a good way to mock this.
if (false) {
Services.locale.setRequestedLocales(["he"]);
Services.locale.requestedLocales = ["he"];
extension.sendMessage(["expect-results", "he"]);

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

@ -129,14 +129,14 @@ async function test_i18n_css(options = {}) {
// We don't wind up actually switching the chrome registry locale, since we
// don't have a chrome package for Hebrew. So just override it, and force
// RTL directionality.
const origReqLocales = Services.locale.getRequestedLocales();
Services.locale.setRequestedLocales(["he"]);
const origReqLocales = Services.locale.requestedLocales;
Services.locale.requestedLocales = ["he"];
Preferences.set(DIR, 1);
css = await fetch(baseURL + "locale.css");
equal(css, '* { content: "he rtl ltr right left" }', "CSS file localized in mochitest scope");
Services.locale.setRequestedLocales(origReqLocales);
Services.locale.requestedLocales = origReqLocales;
Preferences.reset(DIR);
}

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

@ -69,7 +69,7 @@ add_task(async function() {
//
// In the future, we should provide some way for tests to decouple their
// language selection from that of Firefox.
Services.locale.setAvailableLocales(["en-US", "fr", "jp"]);
Services.locale.availableLocales = ["en-US", "fr", "jp"];
await extension.startup();
@ -88,7 +88,7 @@ add_task(async function() {
info("Change locale to 'fr' and restart");
Services.locale.setRequestedLocales(["fr"]);
Services.locale.requestedLocales = ["fr"];
await AddonTestUtils.promiseRestartManager();
await extension.awaitStartup();
@ -106,7 +106,7 @@ add_task(async function() {
info("Change locale to 'en-US' and restart");
Services.locale.setRequestedLocales(["en-US"]);
Services.locale.requestedLocales = ["en-US"];
await AddonTestUtils.promiseRestartManager();
await extension.awaitStartup();

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

@ -22,7 +22,7 @@ const languageTagMatch = /^([a-z]{2,3}|[a-z]{4}|[a-z]{5,8})(?:[-_]([a-z]{4}))?(?
*/
function getLocales(locales) {
if (!locales) {
return Services.locale.getRegionalPrefsLocales();
return Services.locale.regionalPrefsLocales;
}
return locales;
}

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

@ -37,7 +37,7 @@ var NormandyDriver = function(sandboxManager) {
get locale() {
if (Services.locale.getAppLocaleAsLangTag) {
return Services.locale.getAppLocaleAsLangTag();
return Services.locale.getAppLocaleAsLangTag;
}
return Cc["@mozilla.org/chrome/chrome-registry;1"]

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

@ -74,14 +74,14 @@ add_task(function test_setup() {
Services.prefs.setCharPref("urlclassifier.downloadBlockTable",
"goog-badbinurl-shavar");
// SendRemoteQueryInternal needs locale preference.
let originalReqLocales = Services.locale.getRequestedLocales();
Services.locale.setRequestedLocales(["en-US"]);
let originalReqLocales = Services.locale.requestedLocales;
Services.locale.requestedLocales = ["en-US"];
registerCleanupFunction(function() {
Services.prefs.clearUserPref("browser.safebrowsing.malware.enabled");
Services.prefs.clearUserPref("browser.safebrowsing.downloads.enabled");
Services.prefs.clearUserPref("urlclassifier.downloadBlockTable");
Services.locale.setRequestedLocales(originalReqLocales);
Services.locale.requestedLocales = originalReqLocales;
});
gHttpServer = new HttpServer();

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

@ -163,15 +163,15 @@ add_task(async function test_setup() {
Services.prefs.setCharPref("urlclassifier.downloadAllowTable",
"goog-downloadwhite-digest256");
// SendRemoteQueryInternal needs locale preference.
let originalReqLocales = Services.locale.getRequestedLocales();
Services.locale.setRequestedLocales(["en-US"]);
let originalReqLocales = Services.locale.requestedLocales;
Services.locale.requestedLocales = ["en-US"];
registerCleanupFunction(function() {
Services.prefs.clearUserPref("browser.safebrowsing.malware.enabled");
Services.prefs.clearUserPref("browser.safebrowsing.downloads.enabled");
Services.prefs.clearUserPref("urlclassifier.downloadBlockTable");
Services.prefs.clearUserPref("urlclassifier.downloadAllowTable");
Services.locale.setRequestedLocales(originalReqLocales);
Services.locale.requestedLocales = originalReqLocales;
});
gHttpServer = new HttpServer();

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

@ -64,7 +64,7 @@ class _LanguagePrompt {
}
_shouldPromptForLanguagePref() {
return (Services.locale.getAppLocaleAsLangTag().substr(0, 2) !== "en")
return (Services.locale.appLocaleAsLangTag.substr(0, 2) !== "en")
&& (Services.prefs.getIntPref(kPrefSpoofEnglish) === 0);
}

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

@ -800,7 +800,7 @@ function getDir(aKey, aIFace) {
* exists in nsHttpHandler.cpp when building the UA string.
*/
function getLocale() {
return Services.locale.getRequestedLocale();
return Services.locale.requestedLocale;
}
/**
@ -3441,7 +3441,7 @@ SearchService.prototype = {
}
let searchSettings;
let locale = Services.locale.getAppLocaleAsBCP47();
let locale = Services.locale.appLocaleAsBCP47;
if ("locales" in json &&
locale in json.locales) {
searchSettings = json.locales[locale];

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

@ -234,7 +234,7 @@ function getDefaultEngineName(isUS) {
let defaultEngineName = searchSettings.default.searchDefault;
if (isUS === undefined)
isUS = Services.locale.getRequestedLocale() == "en-US" && isUSTimezone();
isUS = Services.locale.requestedLocale == "en-US" && isUSTimezone();
if (isUS && ("US" in searchSettings &&
"searchDefault" in searchSettings.US)) {
@ -253,7 +253,7 @@ function getDefaultEngineList(isUS) {
let visibleDefaultEngines = json.default.visibleDefaultEngines;
if (isUS === undefined)
isUS = Services.locale.getRequestedLocale() == "en-US" && isUSTimezone();
isUS = Services.locale.requestedLocale == "en-US" && isUSTimezone();
if (isUS) {
let searchSettings = json.locales["en-US"];

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

@ -19,8 +19,8 @@ add_task(async function test_listJSONlocale() {
.QueryInterface(Ci.nsIResProtocolHandler);
resProt.setSubstitution("search-plugins", Services.io.newURI(url));
Services.locale.setAvailableLocales(["de"]);
Services.locale.setRequestedLocales(["de"]);
Services.locale.availableLocales = ["de"];
Services.locale.requestedLocales = ["de"];
await asyncInit();
@ -35,8 +35,8 @@ add_task(async function test_listJSONlocale() {
add_task(async function test_listJSONlocaleSwitch() {
let promise = waitForSearchNotification("reinit-complete");
Services.locale.setAvailableLocales(["fr"]);
Services.locale.setRequestedLocales(["fr"]);
Services.locale.availableLocales = ["fr"];
Services.locale.requestedLocales = ["fr"];
await promise;

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

@ -34,8 +34,8 @@ add_task(async function test_paramSubstitution() {
check("{unknownOptional?}", "");
check("{unknownRequired}", "{unknownRequired}");
check("{language}", Services.locale.getRequestedLocale());
check("{language?}", Services.locale.getRequestedLocale());
check("{language}", Services.locale.requestedLocale);
check("{language?}", Services.locale.requestedLocale);
engine.wrappedJSObject._queryCharset = "UTF-8";
check("{inputEncoding}", "UTF-8");
@ -63,5 +63,5 @@ add_task(async function test_paramSubstitution() {
check("{moz:official}", "official");
Services.prefs.setBoolPref("browser.search.official", false);
check("{moz:official}", "unofficial");
check("{moz:locale}", Services.locale.getRequestedLocale());
check("{moz:locale}", Services.locale.requestedLocale);
});

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

@ -298,7 +298,7 @@ function enforceBoolean(aValue) {
*/
function getBrowserLocale() {
try {
return Services.locale.getAppLocaleAsLangTag();
return Services.locale.appLocaleAsLangTag;
} catch (e) {
return null;
}

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

@ -60,7 +60,7 @@ nsURLFormatterService.prototype = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIURLFormatter]),
_defaults: {
LOCALE: () => Services.locale.getAppLocaleAsLangTag(),
LOCALE: () => Services.locale.appLocaleAsLangTag,
REGION() {
try {
// When the geoip lookup failed to identify the region, we fallback to

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

@ -6,7 +6,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
var formatter = Services.urlFormatter;
var locale = Services.locale.getAppLocaleAsLangTag();
var locale = Services.locale.appLocaleAsLangTag;
var OSVersion = Services.sysinfo.getProperty("name") + " " +
Services.sysinfo.getProperty("version");
try {

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

@ -118,7 +118,7 @@ class ClientEnvironmentBase {
}
static get locale() {
return Services.locale.getAppLocaleAsLangTag();
return Services.locale.appLocaleAsLangTag;
}
static get doNotTrack() {

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше