Commits:
-
51b4993c
by Pier Angelo Vendrame at 2025-11-26T16:14:03+01:00
Bug 1985996 - Check spoof english in XMLPrettyPrinter. r=eemeli,smaug
Differential Revision: https://phabricator.services.mozilla.com/D263100
7 changed files:
Changes:
dom/l10n/DOMLocalization.cpp
| ... |
... |
@@ -47,6 +47,12 @@ DOMLocalization::DOMLocalization(nsIGlobalObject* aGlobal, bool aIsSync, |
|
47
|
47
|
mMutations = new L10nMutations(this);
|
|
48
|
48
|
}
|
|
49
|
49
|
|
|
|
50
|
+DOMLocalization::DOMLocalization(nsIGlobalObject* aGlobal, bool aIsSync,
|
|
|
51
|
+ const nsTArray<nsCString>& aLocales)
|
|
|
52
|
+ : Localization(aGlobal, aIsSync, aLocales) {
|
|
|
53
|
+ mMutations = new L10nMutations(this);
|
|
|
54
|
+}
|
|
|
55
|
+
|
|
50
|
56
|
already_AddRefed<DOMLocalization> DOMLocalization::Constructor(
|
|
51
|
57
|
const GlobalObject& aGlobal,
|
|
52
|
58
|
const Sequence<dom::OwningUTF8StringOrResourceId>& aResourceIds,
|
dom/l10n/DOMLocalization.h
| ... |
... |
@@ -118,6 +118,8 @@ class DOMLocalization : public intl::Localization { |
|
118
|
118
|
DOMLocalization(nsIGlobalObject* aGlobal, bool aSync);
|
|
119
|
119
|
DOMLocalization(nsIGlobalObject* aGlobal, bool aIsSync,
|
|
120
|
120
|
const intl::ffi::LocalizationRc* aRaw);
|
|
|
121
|
+ DOMLocalization(nsIGlobalObject* aGlobal, bool aSync,
|
|
|
122
|
+ const nsTArray<nsCString>& aLocales);
|
|
121
|
123
|
|
|
122
|
124
|
protected:
|
|
123
|
125
|
virtual ~DOMLocalization();
|
dom/l10n/DocumentL10n.cpp
| ... |
... |
@@ -47,6 +47,19 @@ RefPtr<DocumentL10n> DocumentL10n::Create(Document* aDocument, bool aSync) { |
|
47
|
47
|
return l10n.forget();
|
|
48
|
48
|
}
|
|
49
|
49
|
|
|
|
50
|
+RefPtr<DocumentL10n> DocumentL10n::Create(Document* aDocument, bool aSync,
|
|
|
51
|
+ const nsTArray<nsCString>& aLocales) {
|
|
|
52
|
+ RefPtr<DocumentL10n> l10n = new DocumentL10n(aDocument, aSync, aLocales);
|
|
|
53
|
+
|
|
|
54
|
+ IgnoredErrorResult rv;
|
|
|
55
|
+ l10n->mReady = Promise::Create(l10n->mGlobal, rv);
|
|
|
56
|
+ if (NS_WARN_IF(rv.Failed())) {
|
|
|
57
|
+ return nullptr;
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ return l10n.forget();
|
|
|
61
|
+}
|
|
|
62
|
+
|
|
50
|
63
|
DocumentL10n::DocumentL10n(Document* aDocument, bool aSync)
|
|
51
|
64
|
: DOMLocalization(aDocument->GetScopeObject(), aSync),
|
|
52
|
65
|
mDocument(aDocument),
|
| ... |
... |
@@ -54,6 +67,14 @@ DocumentL10n::DocumentL10n(Document* aDocument, bool aSync) |
|
54
|
67
|
mContentSink = do_QueryInterface(aDocument->GetCurrentContentSink());
|
|
55
|
68
|
}
|
|
56
|
69
|
|
|
|
70
|
+DocumentL10n::DocumentL10n(Document* aDocument, bool aSync,
|
|
|
71
|
+ const nsTArray<nsCString>& aLocales)
|
|
|
72
|
+ : DOMLocalization(aDocument->GetScopeObject(), aSync, aLocales),
|
|
|
73
|
+ mDocument(aDocument),
|
|
|
74
|
+ mState(DocumentL10nState::Constructed) {
|
|
|
75
|
+ mContentSink = do_QueryInterface(aDocument->GetCurrentContentSink());
|
|
|
76
|
+}
|
|
|
77
|
+
|
|
57
|
78
|
JSObject* DocumentL10n::WrapObject(JSContext* aCx,
|
|
58
|
79
|
JS::Handle<JSObject*> aGivenProto) {
|
|
59
|
80
|
return DocumentL10n_Binding::Wrap(aCx, this, aGivenProto);
|
dom/l10n/DocumentL10n.h
| ... |
... |
@@ -47,9 +47,13 @@ class DocumentL10n final : public DOMLocalization { |
|
47
|
47
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentL10n, DOMLocalization)
|
|
48
|
48
|
|
|
49
|
49
|
static RefPtr<DocumentL10n> Create(Document* aDocument, bool aSync);
|
|
|
50
|
+ static RefPtr<DocumentL10n> Create(Document* aDocument, bool aSync,
|
|
|
51
|
+ const nsTArray<nsCString>& aLocales);
|
|
50
|
52
|
|
|
51
|
53
|
protected:
|
|
52
|
54
|
explicit DocumentL10n(Document* aDocument, bool aSync);
|
|
|
55
|
+ explicit DocumentL10n(Document* aDocument, bool aSync,
|
|
|
56
|
+ const nsTArray<nsCString>& aLocales);
|
|
53
|
57
|
virtual ~DocumentL10n() = default;
|
|
54
|
58
|
|
|
55
|
59
|
RefPtr<Document> mDocument;
|
dom/xml/nsXMLPrettyPrinter.cpp
| ... |
... |
@@ -100,7 +100,13 @@ nsresult nsXMLPrettyPrinter::PrettyPrint(Document* aDocument, |
|
100
|
100
|
|
|
101
|
101
|
// Create a DocumentL10n, as the XML document is not allowed to have one.
|
|
102
|
102
|
// Make it sync so that the test for bug 590812 does not require a setTimeout.
|
|
103
|
|
- RefPtr<DocumentL10n> l10n = DocumentL10n::Create(aDocument, true);
|
|
|
103
|
+ RefPtr<DocumentL10n> l10n;
|
|
|
104
|
+ if (aDocument->ShouldResistFingerprinting(RFPTarget::JSLocale)) {
|
|
|
105
|
+ AutoTArray<nsCString, 1> langs = {nsRFPService::GetSpoofedJSLocale()};
|
|
|
106
|
+ l10n = DocumentL10n::Create(aDocument, true, langs);
|
|
|
107
|
+ } else {
|
|
|
108
|
+ l10n = DocumentL10n::Create(aDocument, true);
|
|
|
109
|
+ }
|
|
104
|
110
|
NS_ENSURE_TRUE(l10n, NS_ERROR_UNEXPECTED);
|
|
105
|
111
|
l10n->AddResourceId("dom/XMLPrettyPrint.ftl"_ns);
|
|
106
|
112
|
|
intl/l10n/Localization.cpp
| ... |
... |
@@ -164,6 +164,14 @@ Localization::Localization(nsIGlobalObject* aGlobal, bool aIsSync, |
|
164
|
164
|
RegisterObservers();
|
|
165
|
165
|
}
|
|
166
|
166
|
|
|
|
167
|
+Localization::Localization(nsIGlobalObject* aGlobal, bool aIsSync,
|
|
|
168
|
+ const nsTArray<nsCString>& aLocales)
|
|
|
169
|
+ : mGlobal(aGlobal) {
|
|
|
170
|
+ nsTArray<ffi::GeckoResourceId> resIds;
|
|
|
171
|
+ ffi::localization_new_with_locales(&resIds, aIsSync, nullptr, &aLocales,
|
|
|
172
|
+ getter_AddRefs(mRaw));
|
|
|
173
|
+}
|
|
|
174
|
+
|
|
167
|
175
|
/* static */
|
|
168
|
176
|
bool Localization::IsAPIEnabled(JSContext* aCx, JSObject* aObject) {
|
|
169
|
177
|
JS::Rooted<JSObject*> obj(aCx, aObject);
|
intl/l10n/Localization.h
| ... |
... |
@@ -158,6 +158,9 @@ class Localization : public nsIObserver, |
|
158
|
158
|
Localization(nsIGlobalObject* aGlobal, bool aIsSync,
|
|
159
|
159
|
const ffi::LocalizationRc* aRaw);
|
|
160
|
160
|
|
|
|
161
|
+ Localization(nsIGlobalObject* aGlobal, bool aIsSync,
|
|
|
162
|
+ const nsTArray<nsCString>& aLocales);
|
|
|
163
|
+
|
|
161
|
164
|
virtual ~Localization();
|
|
162
|
165
|
|
|
163
|
166
|
void RegisterObservers();
|
|