void
HTMLLinkElement::UpdateImport()
{
  // 1. link node should be attached to the document.
  nsCOMPtr<nsIDocument> doc = GetCurrentDoc();
  if (!doc) {
    // We might have been just removed from the document, so
    // let's remove ourself from the list of link nodes of
    // the import and reset mImportLoader.
    if (mImportLoader) {
      mImportLoader->RemoveLinkElement(this);
      mImportLoader = nullptr;
    }
    return;
  }

  // Until the script execution order is not sorted out for nested cases
  // let's not allow them.
  if (!doc->IsMasterDocument()) {
    nsContentUtils::LogSimpleConsoleError(
      NS_LITERAL_STRING("Nested imports are not supported yet"),
      "Imports");
    return;
  }

  // 2. rel type should be import.
  nsAutoString rel;
  GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
  uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel);
  if (!(linkTypes & eHTMLIMPORT)) {
    mImportLoader = nullptr;
    return;
  }

  nsCOMPtr<nsIURI> uri = GetHrefURI();
  if (!uri) {
    mImportLoader = nullptr;
    return;
  }

  if (!nsStyleLinkElement::IsImportEnabled()) {
    // For now imports are hidden behind a pref...
    return;
  }

  nsRefPtr<ImportManager> manager = doc->ImportManager();
  MOZ_ASSERT(manager, "ImportManager should be created lazily when needed");

  {
    // The load even might fire sooner than we could set mImportLoader so
    // we must use async event and a scriptBlocker here.
    nsAutoScriptBlocker scriptBlocker;
    // CORS check will happen at the start of the load.
    mImportLoader = manager->Get(uri, this, doc);
  }
}
Example #2
0
void
HTMLLinkElement::UpdateImport()
{
  // 1. link node should be attached to the document.
  nsCOMPtr<nsIDocument> doc = GetUncomposedDoc();
  if (!doc) {
    // We might have been just removed from the document, so
    // let's remove ourself from the list of link nodes of
    // the import and reset mImportLoader.
    if (mImportLoader) {
      mImportLoader->RemoveLinkElement(this);
      mImportLoader = nullptr;
    }
    return;
  }

  // 2. rel type should be import.
  nsAutoString rel;
  GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
  uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
  if (!(linkTypes & eHTMLIMPORT)) {
    mImportLoader = nullptr;
    return;
  }

  nsCOMPtr<nsIURI> uri = GetHrefURI();
  if (!uri) {
    mImportLoader = nullptr;
    return;
  }

  if (!nsStyleLinkElement::IsImportEnabled()) {
    // For now imports are hidden behind a pref...
    return;
  }

  nsRefPtr<ImportManager> manager = doc->ImportManager();
  MOZ_ASSERT(manager, "ImportManager should be created lazily when needed");

  {
    // The load even might fire sooner than we could set mImportLoader so
    // we must use async event and a scriptBlocker here.
    nsAutoScriptBlocker scriptBlocker;
    // CORS check will happen at the start of the load.
    mImportLoader = manager->Get(uri, this, doc);
  }
}
Example #3
0
void
HTMLLinkElement::UpdatePreconnect()
{
  // rel type should be preconnect
  nsAutoString rel;
  if (!GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel)) {
    return;
  }

  uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
  if (!(linkTypes & ePRECONNECT)) {
    return;
  }

  nsIDocument *owner = OwnerDoc();
  if (owner) {
    nsCOMPtr<nsIURI> uri = GetHrefURI();
    if (uri) {
        owner->MaybePreconnect(uri, GetCORSMode());
    }
  }
}
Example #4
0
void
HTMLLinkElement::UpdatePreconnect()
{
  // rel type should be preconnect
  nsAutoString rel;
  if (!GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel)) {
    return;
  }

  uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
  if (!(linkTypes & ePRECONNECT)) {
    return;
  }

  nsCOMPtr<nsISpeculativeConnect>
    speculator(do_QueryInterface(nsContentUtils::GetIOService()));
  if (speculator) {
    nsCOMPtr<nsIURI> uri = GetHrefURI();
    if (uri) {
      speculator->SpeculativeConnect(uri, nullptr);
    }
  }
}