Bug 1455649 - DocumentL10n, part 3 - Plug DocumentL10n life cycle into DOM hooks. draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Mon, 25 Jun 2018 10:05:03 -0700
changeset 826338 abdfcf5b962b7beced7b2df3207e845b621252f7
parent 826337 1d1ac90ae9d0a59829fd66aa9da436a150360c70
child 826339 d1218cf21860b261aaaa9d25ce2adb037c2732fa
push id118298
push userbmo:gandalf@aviary.pl
push dateFri, 03 Aug 2018 17:04:21 +0000
bugs1455649
milestone63.0a1
Bug 1455649 - DocumentL10n, part 3 - Plug DocumentL10n life cycle into DOM hooks. Adds hooks to XULDocument, HTMLLinkElement etc. to trigger DocumentL10n lifecycle. MozReview-Commit-ID: JpPSWHkl558
dom/html/HTMLLinkElement.cpp
dom/xul/XULDocument.cpp
--- a/dom/html/HTMLLinkElement.cpp
+++ b/dom/html/HTMLLinkElement.cpp
@@ -141,16 +141,24 @@ HTMLLinkElement::BindToTree(nsIDocument*
     doc->RegisterPendingLinkUpdate(this);
     TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender();
   }
 
   void (HTMLLinkElement::*update)() = &HTMLLinkElement::UpdateStyleSheetInternal;
   nsContentUtils::AddScriptRunner(
     NewRunnableMethod("dom::HTMLLinkElement::BindToTree", this, update));
 
+  if (aDocument) {
+    nsAutoString rel;
+    GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
+    if (rel.EqualsLiteral("localization")) {
+      aDocument->LocalizationLinkAdded(this);
+    }
+  }
+
   CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded"));
 
   return rv;
 }
 
 void
 HTMLLinkElement::LinkAdded()
 {
@@ -177,16 +185,23 @@ HTMLLinkElement::UnbindFromTree(bool aDe
   // be under a different xml:base, so forget the cached state now.
   Link::ResetLinkState(false, Link::ElementHasHref());
 
   // If this is reinserted back into the document it will not be
   // from the parser.
   nsIDocument* oldDoc = GetUncomposedDoc();
   ShadowRoot* oldShadowRoot = GetContainingShadow();
 
+  if (oldDoc) {
+    nsAutoString rel;
+    GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
+    if (rel.EqualsLiteral("localization"))
+      oldDoc->LocalizationLinkRemoved(this);
+  }
+
   CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved"));
   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
 
   Unused << UpdateStyleSheetInternal(oldDoc, oldShadowRoot);
 }
 
 bool
 HTMLLinkElement::ParseAttribute(int32_t aNamespaceID,
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -1158,16 +1158,18 @@ XULDocument::AddElementToDocumentPost(El
     if (aElement == GetRootElement()) {
         ResetDocumentDirection();
     }
 
     // We need to pay special attention to the keyset tag to set up a listener
     if (aElement->NodeInfo()->Equals(nsGkAtoms::keyset, kNameSpaceID_XUL)) {
         // Create our XUL key listener and hook it up.
         nsXBLService::AttachGlobalKeyHandler(aElement);
+    } else if (aElement->IsXULElement(nsGkAtoms::linkset)) {
+        OnL10nResourceContainerParsed();
     }
 
     return NS_OK;
 }
 
 nsresult
 XULDocument::AddSubtreeToDocument(nsIContent* aContent)
 {
@@ -1964,16 +1966,18 @@ XULDocument::DoneWalking()
         NotifyPossibleTitleChange(false);
 
         nsContentUtils::DispatchTrustedEvent(
             this,
             static_cast<nsIDocument*>(this),
             NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
             CanBubble::eYes,
             Cancelable::eNo);
+        OnL10nResourceContainerParsed();
+        OnDocumentParsed();
 
         // Before starting layout, check whether we're a toplevel chrome
         // window.  If we are, setup some state so that we don't have to restyle
         // the whole tree after StartLayout.
         if (nsCOMPtr<nsIXULWindow> win = GetXULWindowIfToplevelChrome()) {
             // We're the chrome document!
             win->BeforeStartLayout();
         }