Skip to content

Commit

Permalink
Backed out 3 changesets (bug 1621674) for newtab perma failures. CLOS…
Browse files Browse the repository at this point in the history
…ED TREE

Backed out changeset f197d83fd8a1 (bug 1621674)
Backed out changeset 939beec809c1 (bug 1621674)
Backed out changeset a657cda5467e (bug 1621674)
  • Loading branch information
Razvan Maries committed Apr 7, 2020
1 parent 03c30f9 commit 9c1f540
Show file tree
Hide file tree
Showing 42 changed files with 227 additions and 332 deletions.
2 changes: 1 addition & 1 deletion browser/components/newtab/lib/BookmarkPanelHub.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _BookmarkPanelHub {
this._handleMessageRequest = handleMessageRequest;
this._addImpression = addImpression;
this._dispatch = dispatch;
this._l10n = new DOMLocalization([]);
this._l10n = new DOMLocalization();
this._initialized = true;
}

Expand Down
5 changes: 2 additions & 3 deletions browser/components/newtab/lib/RemoteL10n.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ class _RemoteL10n {
"browser/branding/sync-brand.ftl",
"branding/brand.ftl",
],
false,
Services.prefs.getBoolPref(USE_REMOTE_L10N_PREF, true)
? { generateBundles }
: {}
? generateBundles
: undefined
);
}

Expand Down
3 changes: 1 addition & 2 deletions browser/components/preferences/in-content/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ function getBundleForLocales(newLocales) {
}
return new Localization(
["browser/preferences/preferences.ftl", "branding/brand.ftl"],
false,
{ generateBundles }
generateBundles
);
}

Expand Down
18 changes: 6 additions & 12 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3857,7 +3857,7 @@ bool Document::GetAllowPlugins() {
return true;
}

void Document::InitializeLocalization(Sequence<nsString>& aResourceIds) {
void Document::InitializeLocalization(nsTArray<nsString>& aResourceIds) {
MOZ_ASSERT(!mDocumentL10n, "mDocumentL10n should not be initialized yet");

RefPtr<DocumentL10n> l10n = new DocumentL10n(this);
Expand Down Expand Up @@ -3891,28 +3891,22 @@ void Document::LocalizationLinkAdded(Element* aLinkElement) {
// If the link is added after the DocumentL10n instance
// has been initialized, just pass the resource ID to it.
if (mDocumentL10n) {
Sequence<nsString> resourceIds;
if (NS_WARN_IF(!resourceIds.AppendElement(href, fallible))) {
return;
}
AutoTArray<nsString, 1> resourceIds;
resourceIds.AppendElement(href);
mDocumentL10n->AddResourceIds(resourceIds, false);
} else if (mReadyState >= READYSTATE_INTERACTIVE) {
// Otherwise, if the document has already been parsed
// we need to lazily initialize the localization.
Sequence<nsString> resourceIds;
if (NS_WARN_IF(!resourceIds.AppendElement(href, fallible))) {
return;
}
AutoTArray<nsString, 1> resourceIds;
resourceIds.AppendElement(href);
InitializeLocalization(resourceIds);
mDocumentL10n->TriggerInitialDocumentTranslation();
} else {
// Otherwise, we're still parsing the document.
// In that case, add it to the pending list. This list
// will be resolved once the end of l10n resource
// container is reached.
if (NS_WARN_IF(!mL10nResources.AppendElement(href, fallible))) {
return;
}
mL10nResources.AppendElement(href);

if (!mPendingInitialTranslation) {
// Our initial translation is going to block layout start. Make sure we
Expand Down
4 changes: 2 additions & 2 deletions dom/base/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -3734,7 +3734,7 @@ class Document : public nsINode,
private:
bool IsErrorPage() const;

void InitializeLocalization(Sequence<nsString>& aResourceIds);
void InitializeLocalization(nsTArray<nsString>& aResourceIds);

// Takes the bits from mStyleUseCounters if appropriate, and sets them in
// mUseCounters.
Expand All @@ -3760,7 +3760,7 @@ class Document : public nsINode,

FlashClassification DocumentFlashClassificationInternal();

Sequence<nsString> mL10nResources;
nsTArray<nsString> mL10nResources;

// The application cache that this document is associated with, if
// any. This can change during the lifetime of the document.
Expand Down
2 changes: 1 addition & 1 deletion dom/bindings/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ DOMInterfaces = {
},

'Localization': {
'implicitJSContext': [ 'formatValue', 'formatValues', 'formatMessages', 'formatValueSync', 'formatValuesSync', 'formatMessagesSync' ],
'implicitJSContext': [ 'formatValue', 'formatValues', 'formatMessages' ],
'nativeType': 'mozilla::intl::Localization',
},

Expand Down
16 changes: 5 additions & 11 deletions dom/chrome-webidl/DOMLocalization.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@ interface DOMLocalization : Localization {
* - aResourceids - a list of localization resource URIs
* which will provide messages for this
* Localization instance.
* - aSync - Specifies if the initial state of the DOMLocalization
* and the underlying Localization API is synchronous.
* This enables a number of synchronous methods on the
* Localization API and uses it for `TranslateElements`
* making the method return a synchronusly resolved promise.
* - aBundleGenerator - an object with two methods - `generateBundles` and
* `generateBundlesSync` allowing consumers to overload the
* default generators provided by Gecko.
* - aGenerateMessages - a callback function which will be
* used to generate an iterator
* over FluentBundle instances.
*/
[Throws]
constructor(sequence<DOMString> aResourceIds,
optional boolean aSync = false,
optional BundleGenerator aBundleGenerator = {});
constructor(optional sequence<DOMString> aResourceIds,
optional GenerateMessages aGenerateMessages);

/**
* Adds a node to nodes observed for localization
Expand Down
42 changes: 9 additions & 33 deletions dom/chrome-webidl/Localization.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,7 @@ dictionary L10nMessage {
* and produces an iterator over FluentBundle objects used for
* localization with fallbacks.
*/
callback GenerateBundles = Promise<any> (sequence<DOMString> aResourceIds);
callback GenerateBundlesSync = any (sequence<DOMString> aResourceIds);

/**
* The structure provides custom methods for the Localization API that
* will be used to generate the `FluentBundle` iterator.
* This allows the consumer to overload the default Gecko generator.
*/
dictionary BundleGenerator {
GenerateBundles generateBundles;
GenerateBundlesSync generateBundlesSync;
};
callback GenerateMessages = Promise<any> (sequence<DOMString> aResourceIds);

/**
* Localization is an implementation of the Fluent Localization API.
Expand All @@ -75,20 +64,16 @@ dictionary BundleGenerator {
interface Localization {
/**
* Constructor arguments:
* - aResourceids - a list of localization resource URIs
* which will provide messages for this
* Localization instance.
* - aSync - Specifies if the initial state of the Localization API is synchronous.
* This enables a number of synchronous methods on the
* Localization API.
* - aBundleGenerator - an object with two methods - `generateBundles` and
* `generateBundlesSync` allowing consumers to overload the
* default generators provided by Gecko.
* - aResourceids - a list of localization resource URIs
* which will provide messages for this
* Localization instance.
* - aGenerateMessages - a callback function which will be
* used to generate an iterator
* over FluentBundle instances.
*/
[Throws]
constructor(sequence<DOMString> aResourceIds,
optional boolean aSync = false,
optional BundleGenerator aBundleGenerator = {});
constructor(optional sequence<DOMString> aResourceIds,
optional GenerateMessages aGenerateMessages);

/**
* A method for adding resources to the localization context.
Expand Down Expand Up @@ -152,15 +137,6 @@ interface Localization {
* ]);
*/
[NewObject] Promise<sequence<L10nMessage>> formatMessages(sequence<L10nKey> aKeys);

void setIsSync(boolean aIsSync);

[NewObject, Throws]
UTF8String? formatValueSync(UTF8String aId, optional L10nArgs aArgs);
[NewObject, Throws]
sequence<UTF8String?> formatValuesSync(sequence<L10nKey> aKeys);
[NewObject, Throws]
sequence<L10nMessage?> formatMessagesSync(sequence<L10nKey> aKeys);
};

/**
Expand Down
84 changes: 59 additions & 25 deletions dom/l10n/DOMLocalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ DOMLocalization::DOMLocalization(nsIGlobalObject* aGlobal)
}

already_AddRefed<DOMLocalization> DOMLocalization::Constructor(
const GlobalObject& aGlobal, const Sequence<nsString>& aResourceIds,
const bool aSync, const BundleGenerator& aBundleGenerator,
const GlobalObject& aGlobal,
const Optional<Sequence<nsString>>& aResourceIds,
const Optional<OwningNonNull<GenerateMessages>>& aGenerateMessages,
ErrorResult& aRv) {
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
if (!global) {
Expand All @@ -48,7 +49,20 @@ already_AddRefed<DOMLocalization> DOMLocalization::Constructor(
}

RefPtr<DOMLocalization> domLoc = new DOMLocalization(global);
domLoc->Init(aResourceIds, aSync, aBundleGenerator, aRv);
nsTArray<nsString> resourceIds;

if (aResourceIds.WasPassed()) {
resourceIds = aResourceIds.Value();
}

if (aGenerateMessages.WasPassed()) {
GenerateMessages& generateMessages = aGenerateMessages.Value();
JS::Rooted<JS::Value> generateMessagesJS(
aGlobal.Context(), JS::ObjectValue(*generateMessages.CallbackOrNull()));
domLoc->Init(resourceIds, generateMessagesJS, aRv);
} else {
domLoc->Init(resourceIds, aRv);
}

if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
Expand Down Expand Up @@ -177,7 +191,7 @@ class ElementTranslationHandler : public PromiseNativeHandler {
JS::Handle<JS::Value> aValue) override {
ErrorResult rv;

nsTArray<Nullable<L10nMessage>> l10nData;
nsTArray<L10nMessage> l10nData;
if (aValue.isObject()) {
JS::ForOfIterator iter(aCx);
if (!iter.init(aValue, JS::ForOfIterator::AllowNonIterable)) {
Expand All @@ -201,18 +215,15 @@ class ElementTranslationHandler : public PromiseNativeHandler {
break;
}

Nullable<L10nMessage>* slotPtr =
l10nData.AppendElement(mozilla::fallible);
L10nMessage* slotPtr = l10nData.AppendElement(mozilla::fallible);
if (!slotPtr) {
mReturnValuePromise->MaybeRejectWithUndefined();
return;
}

if (!temp.isNull()) {
if (!slotPtr->SetValue().Init(aCx, temp)) {
mReturnValuePromise->MaybeRejectWithUndefined();
return;
}
if (!slotPtr->Init(aCx, temp)) {
mReturnValuePromise->MaybeRejectWithUndefined();
return;
}
}
}
Expand Down Expand Up @@ -314,11 +325,39 @@ already_AddRefed<Promise> DOMLocalization::TranslateElements(
}

if (mIsSync) {
nsTArray<Nullable<L10nMessage>> l10nMessages;
nsTArray<JS::Value> jsKeys;
SequenceRooter<JS::Value> keysRooter(cx, &jsKeys);
for (auto& key : l10nKeys) {
JS::RootedValue jsKey(cx);
if (!ToJSValue(cx, key, &jsKey)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
jsKeys.AppendElement(jsKey);
}

nsTArray<JS::Value> messages;
SequenceRooter<JS::Value> messagesRooter(cx, &messages);
mLocalization->FormatMessagesSync(jsKeys, messages);
nsTArray<L10nMessage> l10nData;
SequenceRooter<L10nMessage> l10nDataRooter(cx, &l10nData);

for (auto& msg : messages) {
JS::Rooted<JS::Value> rootedMsg(cx);
rootedMsg.set(msg);
L10nMessage* slotPtr = l10nData.AppendElement(mozilla::fallible);
if (!slotPtr) {
promise->MaybeRejectWithUndefined();
return MaybeWrapPromise(promise);
}

FormatMessagesSync(cx, l10nKeys, l10nMessages, aRv);
if (!slotPtr->Init(cx, rootedMsg)) {
promise->MaybeRejectWithUndefined();
return MaybeWrapPromise(promise);
}
}

ApplyTranslations(domElements, l10nMessages, aProto, aRv);
ApplyTranslations(domElements, l10nData, aProto, aRv);
if (NS_WARN_IF(aRv.Failed())) {
promise->MaybeRejectWithUndefined();
return MaybeWrapPromise(promise);
Expand Down Expand Up @@ -442,10 +481,10 @@ void DOMLocalization::SetRootInfo(Element* aElement) {
aElement->SetAttr(kNameSpaceID_None, dirAtom, dir, true);
}

void DOMLocalization::ApplyTranslations(
nsTArray<nsCOMPtr<Element>>& aElements,
nsTArray<Nullable<L10nMessage>>& aTranslations,
nsXULPrototypeDocument* aProto, ErrorResult& aRv) {
void DOMLocalization::ApplyTranslations(nsTArray<nsCOMPtr<Element>>& aElements,
nsTArray<L10nMessage>& aTranslations,
nsXULPrototypeDocument* aProto,
ErrorResult& aRv) {
if (aElements.Length() != aTranslations.Length()) {
aRv.Throw(NS_ERROR_FAILURE);
return;
Expand All @@ -460,20 +499,15 @@ void DOMLocalization::ApplyTranslations(
nsTArray<L10nOverlaysError> errors;
for (size_t i = 0; i < aTranslations.Length(); ++i) {
Element* elem = aElements[i];
if (aTranslations[i].IsNull()) {
continue;
}
L10nOverlays::TranslateElement(*elem, aTranslations[i].Value(), errors,
aRv);
L10nOverlays::TranslateElement(*elem, aTranslations[i], errors, aRv);
if (NS_WARN_IF(aRv.Failed())) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
if (aProto) {
// We only need to rebuild deep if the translation has a value.
// Otherwise we'll only rebuild the attributes.
aProto->RebuildL10nPrototype(elem,
!aTranslations[i].Value().mValue.IsVoid());
aProto->RebuildL10nPrototype(elem, !aTranslations[i].mValue.IsVoid());
}
}

Expand Down
7 changes: 4 additions & 3 deletions dom/l10n/DOMLocalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class DOMLocalization : public intl::Localization {
explicit DOMLocalization(nsIGlobalObject* aGlobal);

static already_AddRefed<DOMLocalization> Constructor(
const GlobalObject& aGlobal, const Sequence<nsString>& aResourceIds,
const bool aSync, const BundleGenerator& aBundleGenerator,
const GlobalObject& aGlobal,
const Optional<Sequence<nsString>>& aResourceIds,
const Optional<OwningNonNull<GenerateMessages>>& aGenerateMessages,
ErrorResult& aRv);

virtual JSObject* WrapObject(JSContext* aCx,
Expand Down Expand Up @@ -86,7 +87,7 @@ class DOMLocalization : public intl::Localization {
* the localized elements.
*/
void ApplyTranslations(nsTArray<nsCOMPtr<Element>>& aElements,
nsTArray<Nullable<L10nMessage>>& aTranslations,
nsTArray<L10nMessage>& aTranslations,
nsXULPrototypeDocument* aProto, ErrorResult& aRv);

bool SubtreeRootInRoots(nsINode* aSubtreeRoot) {
Expand Down
5 changes: 2 additions & 3 deletions dom/l10n/DocumentL10n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ DocumentL10n::DocumentL10n(Document* aDocument)
}
}

void DocumentL10n::Init(Sequence<nsString>& aResourceIds, ErrorResult& aRv) {
DOMLocalization::Init(aResourceIds, mIsSync, {}, aRv);
void DocumentL10n::Init(nsTArray<nsString>& aResourceIds, ErrorResult& aRv) {
DOMLocalization::Init(aResourceIds, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

mReady = Promise::Create(mGlobal, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
Expand Down
2 changes: 1 addition & 1 deletion dom/l10n/DocumentL10n.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DocumentL10n final : public DOMLocalization {
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentL10n, DOMLocalization)

explicit DocumentL10n(Document* aDocument);
void Init(Sequence<nsString>& aResourceIds, ErrorResult& aRv);
void Init(nsTArray<nsString>& aResourceIds, ErrorResult& aRv);

protected:
virtual ~DocumentL10n() = default;
Expand Down
Loading

0 comments on commit 9c1f540

Please sign in to comment.