Commit 7fe15d1a authored by Jessica Jong's avatar Jessica Jong
Browse files

Bug 1422931 - Part 2: Make webcomponents preference per-doc. r=smaug

This is to fix the case where preference is restore to false when a testcase
ends, but nsDocument::DeleteShell is called afterwards. So, we make the
preference per-doc and set it when the document is created. The value does not
change for the lifetime of the document.
parent b519c97d
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -12,6 +12,7 @@
#include "nsIAnonymousContentCreator.h"
#include "nsIAnonymousContentCreator.h"
#include "nsIFrame.h"
#include "nsIFrame.h"
#include "nsCSSAnonBoxes.h"
#include "nsCSSAnonBoxes.h"
#include "nsDocument.h"


namespace mozilla {
namespace mozilla {
namespace dom {
namespace dom {
@@ -66,7 +67,7 @@ ExplicitChildIterator::ExplicitChildIterator(const nsIContent* aParent,
    mIsFirst(aStartAtBeginning),
    mIsFirst(aStartAtBeginning),
    mIndexInInserted(0)
    mIndexInInserted(0)
{
{
  mParentAsSlot = nsContentUtils::IsWebComponentsEnabled() ?
  mParentAsSlot = nsDocument::IsWebComponentsEnabled(mParent) ?
    HTMLSlotElement::FromContent(mParent) : nullptr;
    HTMLSlotElement::FromContent(mParent) : nullptr;
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -7534,7 +7534,7 @@ nsContentUtils::IsContentInsertionPoint(nsIContent* aContent)
bool
bool
nsContentUtils::HasDistributedChildren(nsIContent* aContent)
nsContentUtils::HasDistributedChildren(nsIContent* aContent)
{
{
  if (!IsWebComponentsEnabled() || !aContent) {
  if (!aContent || !nsDocument::IsWebComponentsEnabled(aContent)) {
    return false;
    return false;
  }
  }


+28 −0
Original line number Original line Diff line number Diff line
@@ -1581,6 +1581,10 @@ nsIDocument::nsIDocument()
  for (auto& cnt : mIncCounters) {
  for (auto& cnt : mIncCounters) {
    cnt = 0;
    cnt = 0;
  }
  }

  // Set this when document is created and value stays the same for the lifetime
  // of the document.
  mIsWebComponentsEnabled = nsContentUtils::IsWebComponentsEnabled();
}
}


nsDocument::nsDocument(const char* aContentType)
nsDocument::nsDocument(const char* aContentType)
@@ -2720,6 +2724,30 @@ nsDocument::IsSynthesized() {
  return synthesized;
  return synthesized;
}
}


bool
nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject)
{
  JS::Rooted<JSObject*> obj(aCx, aObject);

  JSAutoCompartment ac(aCx, obj);
  JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, obj));
  nsCOMPtr<nsPIDOMWindowInner> window =
    do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global));

  nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
  if (!doc) {
    return false;
  }

  return doc->IsWebComponentsEnabled();
}

bool
nsDocument::IsWebComponentsEnabled(const nsINode* aNode)
{
  return aNode->OwnerDoc()->IsWebComponentsEnabled();
}

nsresult
nsresult
nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
                              nsILoadGroup* aLoadGroup,
                              nsILoadGroup* aLoadGroup,
+5 −0
Original line number Original line Diff line number Diff line
@@ -665,6 +665,11 @@ public:
  virtual void ResolveScheduledSVGPresAttrs() override;
  virtual void ResolveScheduledSVGPresAttrs() override;
  bool IsSynthesized();
  bool IsSynthesized();


  // Check whether web components are enabled for the global of aObject.
  static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject);
  // Check whether web components are enabled for the document this node belongs
  // to.
  static bool IsWebComponentsEnabled(const nsINode* aNode);
private:
private:
  void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
  void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
  void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages);
  void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages);
+8 −0
Original line number Original line Diff line number Diff line
@@ -3256,6 +3256,11 @@ public:
  virtual bool AllowPaymentRequest() const = 0;
  virtual bool AllowPaymentRequest() const = 0;
  virtual void SetAllowPaymentRequest(bool aAllowPaymentRequest) = 0;
  virtual void SetAllowPaymentRequest(bool aAllowPaymentRequest) = 0;


  bool IsWebComponentsEnabled() const
  {
    return mIsWebComponentsEnabled;
  }

protected:
protected:
  bool GetUseCounter(mozilla::UseCounter aUseCounter)
  bool GetUseCounter(mozilla::UseCounter aUseCounter)
  {
  {
@@ -3612,6 +3617,9 @@ protected:
  // True if the encoding menu should be disabled.
  // True if the encoding menu should be disabled.
  bool mEncodingMenuDisabled : 1;
  bool mEncodingMenuDisabled : 1;


  // True if dom.webcomponents.enabled pref is set when document is created.
  bool mIsWebComponentsEnabled : 1;

  // Whether <style scoped> support is enabled in this document.
  // Whether <style scoped> support is enabled in this document.
  enum { eScopedStyle_Unknown, eScopedStyle_Disabled, eScopedStyle_Enabled };
  enum { eScopedStyle_Unknown, eScopedStyle_Disabled, eScopedStyle_Enabled };
  unsigned int mIsScopedStyleEnabled : 2;
  unsigned int mIsScopedStyleEnabled : 2;
Loading