Backed out changeset 4f859ea95ec6 (bug 1739143) for causing failures at document_l10n/non-system-principal/browser_resource_uri.js. CLOSED TREE

This commit is contained in:
Butkovits Atila 2021-11-10 02:14:34 +02:00
parent 3a33d047e8
commit 7f1436e4bc
4 changed files with 51 additions and 103 deletions

View File

@ -11,8 +11,6 @@
#include "mozilla/dom/DocumentL10nBinding.h"
#include "mozilla/Telemetry.h"
using namespace mozilla;
using namespace mozilla::intl;
using namespace mozilla::dom;
NS_IMPL_CYCLE_COLLECTION_CLASS(DocumentL10n)
@ -66,30 +64,27 @@ class L10nReadyHandler final : public PromiseNativeHandler {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(L10nReadyHandler)
explicit L10nReadyHandler(DocumentL10n* aDocumentL10n)
: mDocumentL10n(aDocumentL10n) {}
explicit L10nReadyHandler(Promise* aPromise, DocumentL10n* aDocumentL10n)
: mPromise(aPromise), mDocumentL10n(aDocumentL10n) {}
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override {
mDocumentL10n->InitialTranslationCompleted(true);
mPromise->MaybeResolveWithUndefined();
}
void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override {
mDocumentL10n->InitialTranslationCompleted(false);
nsTArray<nsCString> errors{
"[dom/l10n] Could not complete initial document translation."_ns,
};
IgnoredErrorResult rv;
MaybeReportErrorsToGecko(errors, rv, mDocumentL10n->GetParentObject());
mPromise->MaybeRejectWithUndefined();
}
private:
~L10nReadyHandler() = default;
RefPtr<Promise> mPromise;
RefPtr<DocumentL10n> mDocumentL10n;
};
NS_IMPL_CYCLE_COLLECTION(L10nReadyHandler, mDocumentL10n)
NS_IMPL_CYCLE_COLLECTION(L10nReadyHandler, mPromise, mDocumentL10n)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(L10nReadyHandler)
NS_INTERFACE_MAP_ENTRY(nsISupports)
@ -139,7 +134,8 @@ void DocumentL10n::TriggerInitialTranslation() {
InitialTranslationCompleted(true);
mReady->MaybeResolveWithUndefined();
} else {
RefPtr<PromiseNativeHandler> l10nReadyHandler = new L10nReadyHandler(this);
RefPtr<PromiseNativeHandler> l10nReadyHandler =
new L10nReadyHandler(mReady, this);
promise->AppendNativeHandler(l10nReadyHandler);
mState = DocumentL10nState::InitialTranslationTriggered;

View File

@ -7,10 +7,7 @@
#include "L10nMutations.h"
#include "mozilla/dom/DocumentInlines.h"
#include "nsRefreshDriver.h"
#include "mozilla/intl/Localization.h"
using namespace mozilla;
using namespace mozilla::intl;
using namespace mozilla::dom;
NS_IMPL_CYCLE_COLLECTION_CLASS(L10nMutations)
@ -127,44 +124,6 @@ void L10nMutations::WillRefresh(mozilla::TimeStamp aTime) {
FlushPendingTranslations();
}
/**
* The handler for the `TranslateElements` promise used to turn
* a potential rejection into a console warning.
**/
class L10nMutationFinalizationHandler final : public PromiseNativeHandler {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(L10nMutationFinalizationHandler)
explicit L10nMutationFinalizationHandler(nsIGlobalObject* aGlobal)
: mGlobal(aGlobal) {}
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override {
}
void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override {
nsTArray<nsCString> errors{
"[dom/l10n] Errors during l10n mutation frame."_ns,
};
IgnoredErrorResult rv;
MaybeReportErrorsToGecko(errors, rv, mGlobal);
}
private:
~L10nMutationFinalizationHandler() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
};
NS_IMPL_CYCLE_COLLECTION(L10nMutationFinalizationHandler, mGlobal)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(L10nMutationFinalizationHandler)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(L10nMutationFinalizationHandler)
NS_IMPL_CYCLE_COLLECTING_RELEASE(L10nMutationFinalizationHandler)
void L10nMutations::FlushPendingTranslations() {
if (!mDOMLocalization) {
return;
@ -188,10 +147,6 @@ void L10nMutations::FlushPendingTranslations() {
mPendingElements.Clear();
RefPtr<Promise> promise = mDOMLocalization->TranslateElements(elements, rv);
RefPtr<PromiseNativeHandler> l10nMutationFinalizationHandler =
new L10nMutationFinalizationHandler(mDOMLocalization->GetParentObject());
promise->AppendNativeHandler(l10nMutationFinalizationHandler);
}
void L10nMutations::Disconnect() {

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Localization.h"
#include "nsContentUtils.h"
#include "nsIObserverService.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Preferences.h"
@ -20,6 +21,48 @@ using namespace mozilla::intl;
static const char* kObservedPrefs[] = {L10N_PSEUDO_PREF, nullptr};
// The state where the application contains incomplete localization resources
// is much more common than for other types of core resources.
//
// In result, we our localization is designed to handle missing resources
// gracefully, and we need a more fine-tuned way to communicate those problems
// to developers.
//
// In particular, we want developers and early adopters to be able to reason
// about missing translations, without bothering end user in production, where
// the user cannot react to that.
//
// We currently differentiate between nightly/dev-edition builds or automation
// where we report the errors, and beta/release, where we silence them.
static bool MaybeReportErrorsToGecko(const nsTArray<nsCString>& aErrors,
ErrorResult& aRv,
nsIGlobalObject* global) {
if (!aErrors.IsEmpty()) {
if (xpc::IsInAutomation()) {
aRv.ThrowInvalidStateError(aErrors.ElementAt(0));
return true;
}
#if defined(NIGHTLY_BUILD) || defined(MOZ_DEV_EDITION) || defined(DEBUG)
Document* doc = nullptr;
if (global) {
nsPIDOMWindowInner* innerWindow = global->AsInnerWindow();
if (innerWindow) {
doc = innerWindow->GetExtantDoc();
}
}
for (const auto& error : aErrors) {
nsContentUtils::ReportToConsoleNonLocalized(NS_ConvertUTF8toUTF16(error),
nsIScriptError::warningFlag,
"l10n"_ns, doc);
}
#endif
}
return false;
}
static nsTArray<ffi::L10nKey> ConvertFromL10nKeys(
const Sequence<OwningUTF8StringOrL10nIdArgs>& aKeys) {
nsTArray<ffi::L10nKey> l10nKeys(aKeys.Length());

View File

@ -12,9 +12,6 @@
#include "nsWeakReference.h"
#include "nsWrapperCache.h"
#include "nsWeakReference.h"
#include "nsIScriptError.h"
#include "nsContentUtils.h"
#include "nsPIDOMWindow.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/BindingDeclarations.h"
@ -25,49 +22,6 @@
namespace mozilla {
namespace intl {
// The state where the application contains incomplete localization resources
// is much more common than for other types of core resources.
//
// In result, our localization is designed to handle missing resources
// gracefully, and we need a more fine-tuned way to communicate those problems
// to developers.
//
// In particular, we want developers and early adopters to be able to reason
// about missing translations, without bothering end user in production, where
// the user cannot react to that.
//
// We currently differentiate between nightly/dev-edition builds or automation
// where we report the errors, and beta/release, where we silence them.
[[maybe_unused]] static bool MaybeReportErrorsToGecko(
const nsTArray<nsCString>& aErrors, ErrorResult& aRv,
nsIGlobalObject* aGlobal) {
if (!aErrors.IsEmpty()) {
if (xpc::IsInAutomation()) {
aRv.ThrowInvalidStateError(aErrors.ElementAt(0));
return true;
}
#if defined(NIGHTLY_BUILD) || defined(MOZ_DEV_EDITION) || defined(DEBUG)
dom::Document* doc = nullptr;
if (aGlobal) {
nsPIDOMWindowInner* innerWindow = aGlobal->AsInnerWindow();
if (innerWindow) {
doc = innerWindow->GetExtantDoc();
}
}
for (const auto& error : aErrors) {
nsContentUtils::ReportToConsoleNonLocalized(NS_ConvertUTF8toUTF16(error),
nsIScriptError::warningFlag,
"l10n"_ns, doc);
printf_stderr("%s\n", error.get());
}
#endif
}
return false;
}
class Localization : public nsIObserver,
public nsWrapperCache,
public nsSupportsWeakReference {