--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -352,17 +352,17 @@ public:
PrincipalFlashClassifier();
// Fire async classification based on the given principal.
void AsyncClassify(nsIPrincipal* aPrincipal);
// Would block if the result hasn't come out.
mozilla::dom::FlashClassification ClassifyMaybeSync(nsIPrincipal* aPrincipal,
- bool aIsThirdParty);
+ bool aIsThirdParty);
private:
~PrincipalFlashClassifier() = default;
void Reset();
bool EnsureUriClassifier();
mozilla::dom::FlashClassification CheckIfClassifyNeeded(nsIPrincipal* aPrincipal);
mozilla::dom::FlashClassification Resolve(bool aIsThirdParty);
@@ -1418,16 +1418,19 @@ nsIDocument::nsIDocument()
mBlockAllMixedContentPreloads(false),
mUpgradeInsecureRequests(false),
mUpgradeInsecurePreloads(false),
mCharacterSet(WINDOWS_1252_ENCODING),
mCharacterSetSource(0),
mParentDocument(nullptr),
mCachedRootElement(nullptr),
mNodeInfoManager(nullptr),
+#ifdef DEBUG
+ mStyledLinksCleared(false),
+#endif
mBidiEnabled(false),
mMathMLEnabled(false),
mIsInitialDocumentInWindow(false),
mIgnoreDocGroupMismatches(false),
mLoadedAsData(false),
mLoadedAsInteractiveData(false),
mMayStartLayout(true),
mHaveFiredTitleChange(false),
@@ -1481,16 +1484,17 @@ nsIDocument::nsIDocument()
mIsSVGGlyphsDocument(false),
mAllowUnsafeHTML(false),
mInDestructor(false),
mIsGoingAway(false),
mInXBLUpdate(false),
mNeedsReleaseAfterStackRefCntRelease(false),
mStyleSetFilled(false),
mSSApplicableStateNotificationPending(false),
+ mMayHaveTitleElement(false),
mIsScopedStyleEnabled(eScopedStyle_Unknown),
mCompatMode(eCompatibility_FullStandards),
mReadyState(ReadyState::READYSTATE_UNINITIALIZED),
mStyleBackendType(StyleBackendType::None),
#ifdef MOZILLA_INTERNAL_API
mVisibilityState(dom::VisibilityState::Hidden),
#else
mDummy(0),
@@ -1515,51 +1519,47 @@ nsIDocument::nsIDocument()
mUseCounters(0),
mChildDocumentUseCounters(0),
mNotifiedPageForUseCounter(0),
mIncCounters(),
mUserHasInteracted(false),
mUserHasActivatedInteraction(false),
mStackRefCnt(0),
mUpdateNestLevel(0),
+ mViewportType(Unknown),
+ mSubDocuments(nullptr),
+ mHeaderData(nullptr),
+ mFlashClassification(FlashClassification::Unclassified),
mServoRestyleRootDirtyBits(0),
mThrowOnDynamicMarkupInsertionCounter(0),
mIgnoreOpensDuringUnloadCounter(0)
{
SetIsInDocument();
for (auto& cnt : mIncCounters) {
cnt = 0;
}
}
nsDocument::nsDocument(const char* aContentType)
: nsIDocument()
- , mSubDocuments(nullptr)
- , mFlashClassification(FlashClassification::Unclassified)
- , mHeaderData(nullptr)
- , mMayHaveTitleElement(false)
, mHasWarnedAboutBoxObjects(false)
, mDelayFrameLoaderInitialization(false)
, mSynchronousDOMContentLoaded(false)
, mParserAborted(false)
, mCurrentOrientationAngle(0)
, mCurrentOrientationType(OrientationType::Portrait_primary)
, mReportedUseCounters(false)
, mPendingFullscreenRequests(0)
, mXMLDeclarationBits(0)
, mBoxObjectTable(nullptr)
, mOnloadBlockCount(0)
, mAsyncOnloadBlockCount(0)
-#ifdef DEBUG
- , mStyledLinksCleared(false)
-#endif
, mPreloadPictureDepth(0)
, mScrolledToRefAlready(0)
, mChangeScrollPosWhenScrollingToRef(0)
- , mViewportType(Unknown)
, mValidWidth(false)
, mValidHeight(false)
, mAutoSize(false)
, mAllowZoom(false)
, mAllowDoubleTapZoom(false)
, mValidScaleFloat(false)
, mValidMaxScale(false)
, mScaleStrEmpty(false)
@@ -2862,32 +2862,32 @@ nsDocument::SendToConsole(nsCOMArray<nsI
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_ConvertUTF16toUTF8(category),
this, nsContentUtils::eSECURITY_PROPERTIES,
NS_ConvertUTF16toUTF8(messageTag).get());
}
}
void
-nsDocument::ApplySettingsFromCSP(bool aSpeculative)
+nsIDocument::ApplySettingsFromCSP(bool aSpeculative)
{
nsresult rv = NS_OK;
if (!aSpeculative) {
// 1) apply settings from regular CSP
nsCOMPtr<nsIContentSecurityPolicy> csp;
rv = NodePrincipal()->GetCsp(getter_AddRefs(csp));
NS_ENSURE_SUCCESS_VOID(rv);
if (csp) {
// Set up any Referrer Policy specified by CSP
bool hasReferrerPolicy = false;
uint32_t referrerPolicy = mozilla::net::RP_Unset;
rv = csp->GetReferrerPolicy(&referrerPolicy, &hasReferrerPolicy);
NS_ENSURE_SUCCESS_VOID(rv);
if (hasReferrerPolicy) {
- mReferrerPolicy = static_cast<ReferrerPolicy>(referrerPolicy);
+ mReferrerPolicy = static_cast<enum ReferrerPolicy>(referrerPolicy);
mReferrerPolicySet = true;
}
// Set up 'block-all-mixed-content' if not already inherited
// from the parent context or set by any other CSP.
if (!mBlockAllMixedContent) {
rv = csp->GetBlockAllMixedContent(&mBlockAllMixedContent);
NS_ENSURE_SUCCESS_VOID(rv);
@@ -3077,17 +3077,17 @@ nsDocument::StopDocumentLoad()
{
if (mParser) {
mParserAborted = true;
mParser->Terminate();
}
}
void
-nsDocument::SetDocumentURI(nsIURI* aURI)
+nsIDocument::SetDocumentURI(nsIURI* aURI)
{
nsCOMPtr<nsIURI> oldBase = GetDocBaseURI();
mDocumentURI = NS_TryToMakeImmutable(aURI);
nsIURI* newBase = GetDocBaseURI();
bool equalBases = false;
// Changing just the ref of a URI does not change how relative URIs would
// resolve wrt to it, so we can treat the bases as equal as long as they're
@@ -3106,28 +3106,16 @@ nsDocument::SetDocumentURI(nsIURI* aURI)
// If changing the document's URI changed the base URI of the document, we
// need to refresh the hrefs of all the links on the page.
if (!equalBases) {
RefreshLinkHrefs();
}
}
-void
-nsDocument::SetChromeXHRDocURI(nsIURI* aURI)
-{
- mChromeXHRDocURI = aURI;
-}
-
-void
-nsDocument::SetChromeXHRDocBaseURI(nsIURI* aURI)
-{
- mChromeXHRDocBaseURI = aURI;
-}
-
static void
GetFormattedTimeString(PRTime aTime, nsAString& aFormattedTimeString)
{
PRExplodedTime prtime;
PR_ExplodeTime(aTime, PR_LocalTimeParameters, &prtime);
// "MM/DD/YYYY hh:mm:ss"
char formatedTime[24];
if (SprintfLiteral(formatedTime, "%02d/%02d/%04d %02d:%02d:%02d",
@@ -3232,17 +3220,17 @@ nsIPrincipal*
nsDocument::GetPrincipal()
{
return NodePrincipal();
}
extern bool sDisablePrefetchHTTPSPref;
void
-nsDocument::SetPrincipal(nsIPrincipal *aNewPrincipal)
+nsIDocument::SetPrincipal(nsIPrincipal *aNewPrincipal)
{
if (aNewPrincipal && mAllowDNSPrefetch && sDisablePrefetchHTTPSPref) {
nsCOMPtr<nsIURI> uri;
aNewPrincipal->GetURI(getter_AddRefs(uri));
bool isHTTPS;
if (!uri || NS_FAILED(uri->SchemeIs("https", &isHTTPS)) ||
isHTTPS) {
mAllowDNSPrefetch = false;
@@ -3355,17 +3343,17 @@ nsIDocument::GetContentType(nsAString& a
void
nsDocument::SetContentType(const nsAString& aContentType)
{
SetContentTypeInternal(NS_ConvertUTF16toUTF8(aContentType));
}
bool
-nsDocument::GetAllowPlugins()
+nsIDocument::GetAllowPlugins()
{
// First, we ask our docshell if it allows plugins.
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell) {
bool allowPlugins = false;
docShell->GetAllowPlugins(&allowPlugins);
if (!allowPlugins) {
@@ -3687,17 +3675,17 @@ nsIDocument::GetBaseURI(bool aTryUseXHRD
} else {
uri = GetDocBaseURI();
}
return uri.forget();
}
void
-nsDocument::SetBaseURI(nsIURI* aURI)
+nsIDocument::SetBaseURI(nsIURI* aURI)
{
if (!aURI && !mDocumentBaseURI) {
return;
}
// Don't do anything if the URI wasn't actually changed.
if (aURI && mDocumentBaseURI) {
bool equalBases = false;
@@ -3732,22 +3720,16 @@ nsIDocument::DefaultStyleAttrURLData()
return mCachedURLData;
#else
MOZ_CRASH("Should not be called for non-stylo build");
return nullptr;
#endif
}
void
-nsDocument::GetBaseTarget(nsAString &aBaseTarget)
-{
- aBaseTarget = mBaseTarget;
-}
-
-void
nsDocument::SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding)
{
if (mCharacterSet != aEncoding) {
mCharacterSet = aEncoding;
if (nsPresContext* context = GetPresContext()) {
context->DispatchCharSetChange(aEncoding);
}
@@ -3756,32 +3738,32 @@ nsDocument::SetDocumentCharacterSet(NotN
void
nsIDocument::GetSandboxFlagsAsString(nsAString& aFlags)
{
nsContentUtils::SandboxFlagsToString(mSandboxFlags, aFlags);
}
void
-nsDocument::GetHeaderData(nsAtom* aHeaderField, nsAString& aData) const
+nsIDocument::GetHeaderData(nsAtom* aHeaderField, nsAString& aData) const
{
aData.Truncate();
const nsDocHeaderData* data = mHeaderData;
while (data) {
if (data->mField == aHeaderField) {
aData = data->mData;
break;
}
data = data->mNext;
}
}
void
-nsDocument::SetHeaderData(nsAtom* aHeaderField, const nsAString& aData)
+nsIDocument::SetHeaderData(nsAtom* aHeaderField, const nsAString& aData)
{
if (!aHeaderField) {
NS_ERROR("null headerField");
return;
}
if (!mHeaderData) {
if (!aData.IsEmpty()) { // don't bother storing empty string
@@ -3862,29 +3844,29 @@ nsDocument::SetHeaderData(nsAtom* aHeade
aHeaderField == nsGkAtoms::viewport_height ||
aHeaderField == nsGkAtoms::viewport_width ||
aHeaderField == nsGkAtoms::viewport_user_scalable) {
mViewportType = Unknown;
}
// Referrer policy spec says to ignore any empty referrer policies.
if (aHeaderField == nsGkAtoms::referrer && !aData.IsEmpty()) {
- ReferrerPolicy policy = mozilla::net::ReferrerPolicyFromString(aData);
+ enum ReferrerPolicy policy = mozilla::net::ReferrerPolicyFromString(aData);
// If policy is not the empty string, then set element's node document's
// referrer policy to policy
if (policy != mozilla::net::RP_Unset) {
// Referrer policy spec (section 6.1) says that we always use the newest
// referrer policy we find
mReferrerPolicy = policy;
mReferrerPolicySet = true;
}
}
if (aHeaderField == nsGkAtoms::headerReferrerPolicy && !aData.IsEmpty()) {
- ReferrerPolicy policy = nsContentUtils::GetReferrerPolicyFromHeader(aData);
+ enum ReferrerPolicy policy = nsContentUtils::GetReferrerPolicyFromHeader(aData);
if (policy != mozilla::net::RP_Unset) {
mReferrerPolicy = policy;
mReferrerPolicySet = true;
}
}
}
void
@@ -4103,17 +4085,17 @@ nsDocument::AllowPaymentRequest() const
void
nsDocument::SetAllowPaymentRequest(bool aAllowPaymentRequest)
{
mAllowPaymentRequest = aAllowPaymentRequest;
}
nsresult
-nsDocument::SetSubDocumentFor(Element* aElement, nsIDocument* aSubDoc)
+nsIDocument::SetSubDocumentFor(Element* aElement, nsIDocument* aSubDoc)
{
NS_ENSURE_TRUE(aElement, NS_ERROR_UNEXPECTED);
if (!aSubDoc) {
// aSubDoc is nullptr, remove the mapping
if (mSubDocuments) {
nsIDocument* subDoc = GetSubDocumentFor(aElement);
@@ -4176,32 +4158,32 @@ nsDocument::SetSubDocumentFor(Element* a
aSubDoc->SetParentDocument(this);
}
return NS_OK;
}
nsIDocument*
-nsDocument::GetSubDocumentFor(nsIContent *aContent) const
+nsIDocument::GetSubDocumentFor(nsIContent *aContent) const
{
if (mSubDocuments && aContent->IsElement()) {
auto entry = static_cast<SubDocMapEntry*>
(mSubDocuments->Search(aContent->AsElement()));
if (entry) {
return entry->mSubDocument;
}
}
return nullptr;
}
Element*
-nsDocument::FindContentForSubDocument(nsIDocument *aDocument) const
+nsIDocument::FindContentForSubDocument(nsIDocument *aDocument) const
{
NS_ENSURE_TRUE(aDocument, nullptr);
if (!mSubDocuments) {
return nullptr;
}
for (auto iter = mSubDocuments->Iter(); !iter.Done(); iter.Next()) {
@@ -5096,17 +5078,17 @@ nsDocument::GetWindowInternal() const
ScriptLoader*
nsDocument::ScriptLoader()
{
return mScriptLoader;
}
bool
-nsDocument::InternalAllowXULXBL()
+nsIDocument::InternalAllowXULXBL()
{
if (nsContentUtils::AllowXULXBLForPrincipal(NodePrincipal())) {
mAllowXULXBL = eTriTrue;
return true;
}
mAllowXULXBL = eTriFalse;
return false;
@@ -5211,81 +5193,81 @@ nsDocument::BeginLoad()
if (mScriptLoader) {
mScriptLoader->BeginDeferringScripts();
}
NS_DOCUMENT_NOTIFY_OBSERVERS(BeginLoad, (this));
}
void
-nsDocument::ReportEmptyGetElementByIdArg()
+nsIDocument::ReportEmptyGetElementByIdArg()
{
nsContentUtils::ReportEmptyGetElementByIdArg(this);
}
Element*
-nsDocument::AddIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
+nsIDocument::AddIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
void* aData, bool aForImage)
{
nsDependentAtomString id(aID);
if (!CheckGetElementByIdArg(id))
return nullptr;
nsIdentifierMapEntry* entry = mIdentifierMap.PutEntry(aID);
NS_ENSURE_TRUE(entry, nullptr);
entry->AddContentChangeCallback(aObserver, aData, aForImage);
return aForImage ? entry->GetImageIdElement() : entry->GetIdElement();
}
void
-nsDocument::RemoveIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
+nsIDocument::RemoveIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
void* aData, bool aForImage)
{
nsDependentAtomString id(aID);
if (!CheckGetElementByIdArg(id))
return;
nsIdentifierMapEntry* entry = mIdentifierMap.GetEntry(aID);
if (!entry) {
return;
}
entry->RemoveContentChangeCallback(aObserver, aData, aForImage);
}
void
-nsDocument::MozSetImageElement(const nsAString& aImageElementId,
+nsIDocument::MozSetImageElement(const nsAString& aImageElementId,
Element* aElement)
{
if (aImageElementId.IsEmpty())
return;
// Hold a script blocker while calling SetImageElement since that can call
// out to id-observers
nsAutoScriptBlocker scriptBlocker;
- nsIdentifierMapEntry *entry = mIdentifierMap.PutEntry(aImageElementId);
+ nsIdentifierMapEntry* entry = mIdentifierMap.PutEntry(aImageElementId);
if (entry) {
entry->SetImageElement(aElement);
if (entry->IsEmpty()) {
mIdentifierMap.RemoveEntry(entry);
}
}
}
Element*
-nsDocument::LookupImageElement(const nsAString& aId)
+nsIDocument::LookupImageElement(const nsAString& aId)
{
if (aId.IsEmpty())
return nullptr;
- nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(aId);
+ nsIdentifierMapEntry* entry = mIdentifierMap.GetEntry(aId);
return entry ? entry->GetImageIdElement() : nullptr;
}
void
nsDocument::DispatchContentLoadedEvents()
{
// If you add early returns from this method, make sure you're
// calling UnblockOnload properly.
@@ -5299,17 +5281,17 @@ nsDocument::DispatchContentLoadedEvents(
if (mTiming) {
mTiming->NotifyDOMContentLoadedStart(nsIDocument::GetDocumentURI());
}
// Dispatch observer notification to notify observers document is interactive.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
- nsIPrincipal *principal = GetPrincipal();
+ nsIPrincipal* principal = GetPrincipal();
os->NotifyObservers(static_cast<nsIDocument*>(this),
nsContentUtils::IsSystemPrincipal(principal) ?
"chrome-document-interactive" :
"content-document-interactive",
nullptr);
}
// Fire a DOM event notifying listeners that this document has been
@@ -6357,17 +6339,17 @@ nsIDocument::SetBody(nsGenericHTMLElemen
if (currentBody) {
root->ReplaceChild(*newBody, *currentBody, rv);
} else {
root->AppendChild(*newBody, rv);
}
}
Element*
-nsDocument::GetTitleElement()
+nsIDocument::GetTitleElement()
{
// mMayHaveTitleElement will have been set to true if any HTML or SVG
// <title> element has been bound to this document. So if it's false,
// we know there is nothing to do here. This avoids us having to search
// the whole DOM if someone calls document.title on a large document
// without a title.
if (!mMayHaveTitleElement)
return nullptr;
@@ -6394,17 +6376,17 @@ nsDocument::GetTitleElement()
/* aLiveList = */ false);
nsIContent* first = list->Item(0, false);
return first ? first->AsElement() : nullptr;
}
void
-nsDocument::GetTitle(nsAString& aTitle)
+nsIDocument::GetTitle(nsAString& aTitle)
{
aTitle.Truncate();
Element* rootElement = GetRootElement();
if (!rootElement) {
return;
}
@@ -6423,17 +6405,17 @@ nsDocument::GetTitle(nsAString& aTitle)
nsContentUtils::GetNodeTextContent(title, false, tmp);
}
tmp.CompressWhitespace();
aTitle = tmp;
}
void
-nsDocument::SetTitle(const nsAString& aTitle, ErrorResult& aRv)
+nsIDocument::SetTitle(const nsAString& aTitle, ErrorResult& aRv)
{
Element* rootElement = GetRootElement();
if (!rootElement) {
return;
}
#ifdef MOZ_XUL
if (rootElement->IsXULElement()) {
@@ -6481,43 +6463,43 @@ nsDocument::SetTitle(const nsAString& aT
} else {
return;
}
aRv = nsContentUtils::SetNodeTextContent(title, aTitle, false);
}
void
-nsDocument::NotifyPossibleTitleChange(bool aBoundTitleElement)
+nsIDocument::NotifyPossibleTitleChange(bool aBoundTitleElement)
{
NS_ASSERTION(!mInUnlinkOrDeletion || !aBoundTitleElement,
"Setting a title while unlinking or destroying the element?");
if (mInUnlinkOrDeletion) {
return;
}
if (aBoundTitleElement) {
mMayHaveTitleElement = true;
}
if (mPendingTitleChangeEvent.IsPending())
return;
MOZ_RELEASE_ASSERT(NS_IsMainThread());
- RefPtr<nsRunnableMethod<nsDocument, void, false>> event =
- NewNonOwningRunnableMethod("nsDocument::DoNotifyPossibleTitleChange",
+ RefPtr<nsRunnableMethod<nsIDocument, void, false>> event =
+ NewNonOwningRunnableMethod("nsIDocument::DoNotifyPossibleTitleChange",
this,
- &nsDocument::DoNotifyPossibleTitleChange);
+ &nsIDocument::DoNotifyPossibleTitleChange);
nsresult rv = Dispatch(TaskCategory::Other, do_AddRef(event));
if (NS_SUCCEEDED(rv)) {
mPendingTitleChangeEvent = Move(event);
}
}
void
-nsDocument::DoNotifyPossibleTitleChange()
+nsIDocument::DoNotifyPossibleTitleChange()
{
mPendingTitleChangeEvent.Forget();
mHaveFiredTitleChange = true;
nsAutoString title;
GetTitle(title);
nsCOMPtr<nsIPresShell> shell = GetShell();
@@ -8788,52 +8770,28 @@ nsDocument::MutationEventDispatched(nsIN
InternalMutationEvent mutation(true, eLegacySubtreeModified);
(new AsyncEventDispatcher(realTargets[k], mutation))->
RunDOMEventWhenSafe();
}
}
}
void
-nsDocument::AddStyleRelevantLink(Link* aLink)
-{
- NS_ASSERTION(aLink, "Passing in a null link. Expect crashes RSN!");
-#ifdef DEBUG
- nsPtrHashKey<Link>* entry = mStyledLinks.GetEntry(aLink);
- NS_ASSERTION(!entry, "Document already knows about this Link!");
- mStyledLinksCleared = false;
-#endif
- (void)mStyledLinks.PutEntry(aLink);
-}
-
-void
-nsDocument::ForgetLink(Link* aLink)
-{
- NS_ASSERTION(aLink, "Passing in a null link. Expect crashes RSN!");
-#ifdef DEBUG
- nsPtrHashKey<Link>* entry = mStyledLinks.GetEntry(aLink);
- NS_ASSERTION(entry || mStyledLinksCleared,
- "Document knows nothing about this Link!");
-#endif
- mStyledLinks.RemoveEntry(aLink);
-}
-
-void
nsDocument::DestroyElementMaps()
{
#ifdef DEBUG
mStyledLinksCleared = true;
#endif
mStyledLinks.Clear();
mIdentifierMap.Clear();
++mExpandoAndGeneration.generation;
}
void
-nsDocument::RefreshLinkHrefs()
+nsIDocument::RefreshLinkHrefs()
{
// Get a list of all links we know about. We will reset them, which will
// remove them from the document, so we need a copy of what is in the
// hashtable.
LinkArray linksToNotify(mStyledLinks.Count());
for (auto iter = mStyledLinks.ConstIter(); !iter.Done(); iter.Next()) {
linksToNotify.AppendElement(iter.Get()->GetKey());
}
@@ -12863,20 +12821,20 @@ nsIDocument::GetSameTypeParentDocument()
* the classification lists. We perform AsyncInitFlashClassification on
* StartDocumentLoad() and the result may not be initialized when this function
* gets called. In that case, We can only unfortunately have a blocking wait.
*
* For more information, see
* toolkit/components/url-classifier/flash-block-lists.rst
*/
FlashClassification
-nsDocument::PrincipalFlashClassification()
+nsIDocument::PrincipalFlashClassification()
{
MOZ_ASSERT(mPrincipalFlashClassifier);
- return mPrincipalFlashClassifier->ClassifyMaybeSync(GetPrincipal(),
+ return mPrincipalFlashClassifier->ClassifyMaybeSync(NodePrincipal(),
IsThirdParty());
}
/**
* Helper function for |nsDocument::PrincipalFlashClassification|
*
* Adds a table name string to a table list (a comma separated string). The
* table will not be added if the name is an empty string.
@@ -13267,17 +13225,17 @@ PrincipalFlashClassifier::AsyncClassifyI
return FlashClassification::Denied;
}
}
return FlashClassification::Unclassified;
}
FlashClassification
-nsDocument::ComputeFlashClassification()
+nsIDocument::ComputeFlashClassification()
{
nsCOMPtr<nsIDocShellTreeItem> current = this->GetDocShell();
if (!current) {
return FlashClassification::Denied;
}
nsCOMPtr<nsIDocShellTreeItem> parent;
DebugOnly<nsresult> rv = current->GetSameTypeParent(getter_AddRefs(parent));
MOZ_ASSERT(NS_SUCCEEDED(rv),
@@ -13316,17 +13274,17 @@ nsDocument::ComputeFlashClassification()
* Retrieves the classification of plugins in this document. This is dependent
* on the classification of this document and all parent documents.
* This function is infallible - It must return some classification that
* callers can act on.
*
* This function will NOT return FlashClassification::Unclassified
*/
FlashClassification
-nsDocument::DocumentFlashClassification()
+nsIDocument::DocumentFlashClassification()
{
if (mFlashClassification == FlashClassification::Unclassified) {
FlashClassification result = ComputeFlashClassification();
mFlashClassification = result;
MOZ_ASSERT(result != FlashClassification::Unclassified,
"nsDocument::GetPluginClassification should never return Unclassified");
}
@@ -13344,17 +13302,17 @@ nsDocument::DocumentFlashClassification(
* - The document has a different scheme (http/https) than its parent document
* - The document's domain and subdomain do not match those of its parent
* document.
*
* If there is an error in determining whether the document is Third-Party,
* it will be assumed to be Third-Party for security reasons.
*/
bool
-nsDocument::IsThirdParty()
+nsIDocument::IsThirdParty()
{
if (mIsThirdParty.isSome()) {
return mIsThirdParty.value();
}
nsCOMPtr<nsIDocShellTreeItem> docshell = this->GetDocShell();
if (!docshell) {
mIsThirdParty.emplace(true);
@@ -13379,17 +13337,17 @@ nsDocument::IsThirdParty()
return mIsThirdParty.value();
}
if (parentDocument->IsThirdParty()) {
mIsThirdParty.emplace(true);
return mIsThirdParty.value();
}
- nsCOMPtr<nsIPrincipal> principal = GetPrincipal();
+ nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(parentDocument,
&rv);
if (NS_WARN_IF(NS_FAILED(rv) || !sop)) {
// Failure
mIsThirdParty.emplace(true);
return mIsThirdParty.value();
}
nsCOMPtr<nsIPrincipal> parentPrincipal = sop->GetPrincipal();
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -124,34 +124,16 @@ public:
// request in a subdocument in different process, whereupon the caller
// need to send some notification itself with the real origin.
bool mShouldNotifyNewOrigin = true;
};
} // namespace dom
} // namespace mozilla
-class nsDocHeaderData
-{
-public:
- nsDocHeaderData(nsAtom* aField, const nsAString& aData)
- : mField(aField), mData(aData), mNext(nullptr)
- {
- }
-
- ~nsDocHeaderData(void)
- {
- delete mNext;
- }
-
- RefPtr<nsAtom> mField;
- nsString mData;
- nsDocHeaderData* mNext;
-};
-
class nsOnloadBlocker final : public nsIRequest
{
public:
nsOnloadBlocker() {}
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
@@ -310,19 +292,16 @@ protected:
nsILoadGroup* aLoadGroup,
nsIDocument* aDisplayDocument);
nsClassHashtable<nsURIHashKey, ExternalResource> mMap;
nsRefPtrHashtable<nsURIHashKey, PendingLoad> mPendingLoads;
bool mHaveShutDown;
};
-// For classifying a flash document based on its principal.
-class PrincipalFlashClassifier;
-
// Base class for our document implementations.
class nsDocument : public nsIDocument,
public nsIDOMDocument,
public nsSupportsWeakReference,
public nsIScriptObjectPrincipal,
public nsIRadioGroupContainer,
public nsIApplicationCacheContainer,
public nsStubMutationObserver
@@ -351,92 +330,51 @@ public:
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
nsIStreamListener **aDocListener,
bool aReset = true,
nsIContentSink* aContentSink = nullptr) override = 0;
virtual void StopDocumentLoad() override;
- virtual void NotifyPossibleTitleChange(bool aBoundTitleElement) override;
-
- virtual void SetDocumentURI(nsIURI* aURI) override;
-
- virtual void SetChromeXHRDocURI(nsIURI* aURI) override;
-
- virtual void SetChromeXHRDocBaseURI(nsIURI* aURI) override;
-
- virtual void ApplySettingsFromCSP(bool aSpeculative) override;
-
- /**
- * Set the principal responsible for this document.
- */
- virtual void SetPrincipal(nsIPrincipal *aPrincipal) override;
-
/**
* Set the Content-Type of this document.
*/
virtual void SetContentType(const nsAString& aContentType) override;
- virtual void SetBaseURI(nsIURI* aURI) override;
-
- /**
- * Get/Set the base target of a link in a document.
- */
- virtual void GetBaseTarget(nsAString &aBaseTarget) override;
-
/**
* Set the document's character encoding. This will
* trigger a startDocumentLoad if necessary to answer the question.
*/
virtual void
SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding) override;
- virtual Element* AddIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
- void* aData, bool aForImage) override;
- virtual void RemoveIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
- void* aData, bool aForImage) override;
-
- /**
- * Access HTTP header data (this may also get set from other sources, like
- * HTML META tags).
- */
- virtual void GetHeaderData(nsAtom* aHeaderField, nsAString& aData) const override;
- virtual void SetHeaderData(nsAtom* aheaderField,
- const nsAString& aData) override;
-
/**
* Create a new presentation shell that will use aContext for
* its presentation context (presentation contexts <b>must not</b> be
* shared among multiple presentation shells).
*/
already_AddRefed<nsIPresShell> CreateShell(nsPresContext* aContext,
nsViewManager* aViewManager,
mozilla::StyleSetHandle aStyleSet)
final;
virtual void DeleteShell() override;
- virtual bool GetAllowPlugins() override;
-
static bool CallerIsTrustedAboutPage(JSContext* aCx, JSObject* aObject);
static bool IsElementAnimateEnabled(JSContext* aCx, JSObject* aObject);
static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject);
static bool IsWebAnimationsEnabled(mozilla::dom::CallerType aCallerType);
virtual mozilla::dom::DocumentTimeline* Timeline() override;
virtual void GetAnimations(
nsTArray<RefPtr<mozilla::dom::Animation>>& aAnimations) override;
mozilla::LinkedList<mozilla::dom::DocumentTimeline>& Timelines() override
{
return mTimelines;
}
- virtual nsresult SetSubDocumentFor(Element* aContent,
- nsIDocument* aSubDoc) override;
- virtual nsIDocument* GetSubDocumentFor(nsIContent* aContent) const override;
- virtual Element* FindContentForSubDocument(nsIDocument *aDocument) const override;
virtual Element* GetRootElementInternal() const override;
virtual nsIChannel* GetChannel() const override {
return mChannel;
}
virtual nsIChannel* GetFailedChannel() const override {
return mFailedChannel;
@@ -610,19 +548,16 @@ public:
virtual bool CanSavePresentation(nsIRequest *aNewRequest) override;
virtual void Destroy() override;
virtual void RemovedFromDocShell() override;
virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const override;
virtual void BlockOnload() override;
virtual void UnblockOnload(bool aFireSync) override;
- virtual void AddStyleRelevantLink(mozilla::dom::Link* aLink) override;
- virtual void ForgetLink(mozilla::dom::Link* aLink) override;
-
virtual void ClearBoxObjectFor(nsIContent* aContent) override;
virtual already_AddRefed<mozilla::dom::BoxObject>
GetBoxObjectFor(mozilla::dom::Element* aElement,
mozilla::ErrorResult& aRv) override;
virtual Element*
GetAnonymousElementByAttribute(nsIContent* aElement,
@@ -671,18 +606,16 @@ public:
UpdateFrameRequestCallbackSchedulingState();
}
virtual nsIDocument* GetTemplateContentsOwner() override;
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument,
nsIDocument)
- void DoNotifyPossibleTitleChange();
-
nsExternalResourceMap& ExternalResourceMap()
{
return mExternalResourceMap;
}
void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; }
void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData)
{
@@ -729,20 +662,16 @@ public:
virtual void SetAutoFocusElement(Element* aAutoFocusElement) override;
virtual void TriggerAutoFocus() override;
virtual void SetScrollToRef(nsIURI *aDocumentURI) override;
virtual void ScrollToRef() override;
virtual void ResetScrolledToRefAlready() override;
virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) override;
- virtual Element* LookupImageElement(const nsAString& aElementId) override;
- virtual void MozSetImageElement(const nsAString& aImageElementId,
- Element* aElement) override;
-
// AddPlugin adds a plugin-related element to mPlugins when the element is
// added to the tree.
virtual nsresult AddPlugin(nsIObjectLoadingContent* aPlugin) override;
// RemovePlugin removes a plugin-related element to mPlugins when the
// element is removed from the tree.
virtual void RemovePlugin(nsIObjectLoadingContent* aPlugin) override;
// GetPlugins returns the plugin-related elements from
// the frame and any subframes.
@@ -873,87 +802,51 @@ public:
const mozilla::dom::ElementCreationOptionsOrString& aOptions,
mozilla::ErrorResult& rv) override;
virtual void UnblockDOMContentLoaded() override;
protected:
friend class nsNodeUtils;
- /**
- * Check that aId is not empty and log a message to the console
- * service if it is.
- * @returns true if aId looks correct, false otherwise.
- */
- inline bool CheckGetElementByIdArg(const nsAString& aId)
- {
- if (aId.IsEmpty()) {
- ReportEmptyGetElementByIdArg();
- return false;
- }
- return true;
- }
-
- void ReportEmptyGetElementByIdArg();
-
void DispatchContentLoadedEvents();
void RetrieveRelevantHeaders(nsIChannel *aChannel);
void TryChannelCharset(nsIChannel *aChannel,
int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding,
nsHtml5TreeOpExecutor* aExecutor);
// Call this before the document does something that will unbind all content.
// That will stop us from doing a lot of work as each element is removed.
void DestroyElementMaps();
- // Refreshes the hrefs of all the links in the document.
- void RefreshLinkHrefs();
-
nsIContent* GetFirstBaseNodeWithHref();
nsresult SetFirstBaseNodeWithHref(nsIContent *node);
- /**
- * Returns the title element of the document as defined by the HTML
- * specification, or null if there isn't one. For documents whose root
- * element is an <svg:svg>, this is the first <svg:title> element that's a
- * child of the root. For other documents, it's the first HTML title element
- * in the document.
- */
- Element* GetTitleElement();
-
public:
- // Get our title
- virtual void GetTitle(nsAString& aTitle) override;
- // Set our title
- virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) override;
js::ExpandoAndGeneration mExpandoAndGeneration;
bool ContainsEMEContent();
bool ContainsMSEContent();
protected:
void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget,
const nsAString& aType,
bool aPersisted);
virtual nsPIDOMWindowOuter* GetWindowInternal() const override;
virtual nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const override;
- virtual bool InternalAllowXULXBL() override;
void UpdateScreenOrientation();
- virtual mozilla::dom::FlashClassification DocumentFlashClassification() override;
- virtual bool IsThirdParty() override;
-
#define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_) do { \
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \
func_, params_); \
/* FIXME(emilio): Apparently we can keep observing from the BFCache? That \
looks bogus. */ \
if (nsIPresShell* shell = GetObservingShell()) { \
shell->func_ params_; \
} \
@@ -968,26 +861,16 @@ protected:
void EnsureOnloadBlocker();
// Apply the fullscreen state to the document, and trigger related
// events. It returns false if the fullscreen element ready check
// fails and nothing gets changed.
bool ApplyFullscreen(const FullscreenRequest& aRequest);
- // Retrieves the classification of the Flash plugins in the document based on
- // the classification lists.
- mozilla::dom::FlashClassification PrincipalFlashClassification();
-
- // Attempts to determine the Flash classification of this page based on the
- // the classification lists and the classification of parent documents.
- mozilla::dom::FlashClassification ComputeFlashClassification();
-
- PLDHashTable *mSubDocuments;
-
// Array of owning references to all children
nsAttrAndChildArray mChildren;
// Array of intersection observers
nsTHashtable<nsPtrHashKey<mozilla::dom::DOMIntersectionObserver>>
mIntersectionObservers;
// Tracker for animations that are waiting to start.
@@ -1003,36 +886,25 @@ protected:
// full-screen element onto this stack, and when we cancel full-screen we
// pop one off this stack, restoring the previous full-screen state
nsTArray<nsWeakPtr> mFullScreenStack;
// The root of the doc tree in which this document is in. This is only
// non-null when this document is in fullscreen mode.
nsWeakPtr mFullscreenRoot;
- RefPtr<PrincipalFlashClassifier> mPrincipalFlashClassifier;
- mozilla::dom::FlashClassification mFlashClassification;
- // Do not use this value directly. Call the |IsThirdParty()| method, which
- // caches its result here.
- mozilla::Maybe<bool> mIsThirdParty;
-
public:
RefPtr<mozilla::EventListenerManager> mListenerManager;
RefPtr<mozilla::dom::ScriptLoader> mScriptLoader;
- nsDocHeaderData* mHeaderData;
nsClassHashtable<nsStringHashKey, nsRadioGroupStruct> mRadioGroups;
// Recorded time of change to 'loading' state.
mozilla::TimeStamp mLoadingTimeStamp;
- // True if this document has ever had an HTML or SVG <title> element
- // bound to it
- bool mMayHaveTitleElement:1;
-
bool mHasWarnedAboutBoxObjects:1;
bool mDelayFrameLoaderInitialization:1;
bool mSynchronousDOMContentLoaded:1;
// Parser aborted. True if the parser of this document was forcibly
// terminated instead of letting it finish at its own pace.
@@ -1098,49 +970,37 @@ private:
nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
// Currently active onload blockers
uint32_t mOnloadBlockCount;
// Onload blockers which haven't been activated yet
uint32_t mAsyncOnloadBlockCount;
nsCOMPtr<nsIRequest> mOnloadBlocker;
- // A hashtable of styled links keyed by address pointer.
- nsTHashtable<nsPtrHashKey<mozilla::dom::Link> > mStyledLinks;
-#ifdef DEBUG
- // Indicates whether mStyledLinks was cleared or not. This is used to track
- // state so we can provide useful assertions to consumers of ForgetLink and
- // AddStyleRelevantLink.
- bool mStyledLinksCleared;
-#endif
-
// A set of responsive images keyed by address pointer.
nsTHashtable< nsPtrHashKey<nsIContent> > mResponsiveContent;
nsTArray<RefPtr<nsFrameLoader> > mInitializableFrameLoaders;
nsTArray<nsCOMPtr<nsIRunnable> > mFrameLoaderFinalizers;
RefPtr<nsRunnableMethod<nsDocument> > mFrameLoaderRunner;
nsCOMPtr<nsIRunnable> mMaybeEndOutermostXBLUpdateRunner;
- nsRevocableEventPtr<nsRunnableMethod<nsDocument, void, false> >
- mPendingTitleChangeEvent;
-
nsExternalResourceMap mExternalResourceMap;
// All images in process of being preloaded. This is a hashtable so
// we can remove them as the real image loads start; that way we
// make sure to not keep the image load going when no one cares
// about it anymore.
nsRefPtrHashtable<nsURIHashKey, imgIRequest> mPreloadingImages;
// A list of preconnects initiated by the preloader. This prevents
// the same uri from being used more than once, and allows the dom
// builder to not repeat the work of the preloader.
- nsDataHashtable< nsURIHashKey, bool> mPreloadedPreconnects;
+ nsDataHashtable<nsURIHashKey, bool> mPreloadedPreconnects;
// Current depth of picture elements from parser
int32_t mPreloadPictureDepth;
// Set if we've found a URL for the current picture
nsString mPreloadPictureFoundSource;
RefPtr<mozilla::dom::DOMImplementation> mDOMImplementation;
@@ -1154,24 +1014,16 @@ private:
uint8_t mChangeScrollPosWhenScrollingToRef : 1;
// Tracking for plugins in the document.
nsTHashtable< nsPtrHashKey<nsIObjectLoadingContent> > mPlugins;
RefPtr<mozilla::dom::DocumentTimeline> mDocumentTimeline;
mozilla::LinkedList<mozilla::dom::DocumentTimeline> mTimelines;
- enum ViewportType {
- DisplayWidthHeight,
- Specified,
- Unknown
- };
-
- ViewportType mViewportType;
-
// These member variables cache information about the viewport so we don't have to
// recalculate it each time.
bool mValidWidth, mValidHeight;
mozilla::LayoutDeviceToScreenScale mScaleMinFloat;
mozilla::LayoutDeviceToScreenScale mScaleMaxFloat;
mozilla::LayoutDeviceToScreenScale mScaleFloat;
mozilla::CSSToLayoutDeviceScale mPixelRatio;
bool mAutoSize, mAllowZoom, mAllowDoubleTapZoom, mValidScaleFloat, mValidMaxScale, mScaleStrEmpty, mWidthStrEmpty;
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -208,18 +208,39 @@ enum DocumentFlavor {
#define NS_DOCUMENT_STATE_RTL_LOCALE NS_DEFINE_EVENT_STATE_MACRO(0)
// Window activation status
#define NS_DOCUMENT_STATE_WINDOW_INACTIVE NS_DEFINE_EVENT_STATE_MACRO(1)
// Some function forward-declarations
class nsContentList;
class nsDocumentOnStack;
+class nsDocHeaderData
+{
+public:
+ nsDocHeaderData(nsAtom* aField, const nsAString& aData)
+ : mField(aField), mData(aData), mNext(nullptr)
+ {
+ }
+
+ ~nsDocHeaderData(void)
+ {
+ delete mNext;
+ }
+
+ RefPtr<nsAtom> mField;
+ nsString mData;
+ nsDocHeaderData* mNext;
+};
+
//----------------------------------------------------------------------
+// For classifying a flash document based on its principal.
+class PrincipalFlashClassifier;
+
// Document interface. This is implemented by all document objects in
// Gecko.
class nsIDocument : public nsINode,
public mozilla::dom::DocumentOrShadowRoot,
public mozilla::dom::DispatcherTrait
{
typedef mozilla::dom::GlobalObject GlobalObject;
@@ -314,17 +335,17 @@ public:
virtual bool SuppressParserErrorConsoleMessages() { return false; }
/**
* Signal that the document title may have changed
* (see nsDocument::GetTitle).
* @param aBoundTitleElement true if an HTML or SVG <title> element
* has just been bound to the document.
*/
- virtual void NotifyPossibleTitleChange(bool aBoundTitleElement) = 0;
+ void NotifyPossibleTitleChange(bool aBoundTitleElement);
/**
* Return the URI for the document. May return null.
*
* The value returned corresponds to the "document's address" in
* HTML5. As such, it may change over the lifetime of the document, for
* instance as a result of the user navigating to a fragment identifier on
* the page, or as a result to a call to pushState() or replaceState().
@@ -351,34 +372,40 @@ public:
{
return mOriginalURI;
}
/**
* Set the URI for the document. This also sets the document's original URI,
* if it's null.
*/
- virtual void SetDocumentURI(nsIURI* aURI) = 0;
+ void SetDocumentURI(nsIURI* aURI);
/**
* Set the URI for the document loaded via XHR, when accessed from
* chrome privileged script.
*/
- virtual void SetChromeXHRDocURI(nsIURI* aURI) = 0;
+ void SetChromeXHRDocURI(nsIURI* aURI)
+ {
+ mChromeXHRDocURI = aURI;
+ }
/**
* Set the base URI for the document loaded via XHR, when accessed from
* chrome privileged script.
*/
- virtual void SetChromeXHRDocBaseURI(nsIURI* aURI) = 0;
+ void SetChromeXHRDocBaseURI(nsIURI* aURI)
+ {
+ mChromeXHRDocBaseURI = aURI;
+ }
/**
* Set referrer policy and upgrade-insecure-requests flags
*/
- virtual void ApplySettingsFromCSP(bool aSpeculative) = 0;
+ void ApplySettingsFromCSP(bool aSpeculative);
already_AddRefed<nsIParser> CreatorParserOrNull()
{
nsCOMPtr<nsIParser> parser = mParser;
return parser.forget();
}
/**
@@ -429,17 +456,17 @@ public:
void SetReferrer(const nsACString& aReferrer) {
mReferrer = aReferrer;
}
/**
* Set the principal responsible for this document. Chances are,
* you do not want to be using this.
*/
- virtual void SetPrincipal(nsIPrincipal *aPrincipal) = 0;
+ void SetPrincipal(nsIPrincipal* aPrincipal);
/**
* Get the list of ancestor principals for a document. This is the same as
* the ancestor list for the document's docshell the last time SetContainer()
* was called with a non-null argument. See the documentation for the
* corresponding getter in docshell for how this list is determined. We store
* a copy of the list, because we may lose the ability to reach our docshell
* before people stop asking us for this information.
@@ -490,33 +517,38 @@ public:
*/
nsIURI* GetDocBaseURI() const
{
if (mDocumentBaseURI) {
return mDocumentBaseURI;
}
return GetFallbackBaseURI();
}
- virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override;
-
- virtual void SetBaseURI(nsIURI* aURI) = 0;
+
+ already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const final;
+
+ void SetBaseURI(nsIURI* aURI);
/**
* Return the URL data which style system needs for resolving url value.
* This method attempts to use the cached object in mCachedURLData, but
* if the base URI, document URI, or principal has changed since last
* call to this function, or the function is called the first time for
* the document, a new one is created.
*/
mozilla::URLExtraData* DefaultStyleAttrURLData();
/**
* Get/Set the base target of a link in a document.
*/
- virtual void GetBaseTarget(nsAString &aBaseTarget) = 0;
+ void GetBaseTarget(nsAString& aBaseTarget) const
+ {
+ aBaseTarget = mBaseTarget;
+ }
+
void SetBaseTarget(const nsString& aBaseTarget) {
mBaseTarget = aBaseTarget;
}
/**
* Return a standard name for the document's character set.
*/
NotNull<const Encoding*> GetDocumentCharacterSet() const
@@ -558,24 +590,40 @@ public:
* in the future. If aForImage is true, mozSetImageElement can override
* what content is associated with the ID. In that case the IDTargetObserver
* will be notified at those times when the result of LookupImageElement
* changes.
* At most one (aObserver, aData, aForImage) triple can be
* registered for each ID.
* @return the content currently associated with the ID.
*/
- virtual Element* AddIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
- void* aData, bool aForImage) = 0;
+ Element* AddIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
+ void* aData, bool aForImage);
/**
* Remove the (aObserver, aData, aForImage) triple for a specific ID, if
* registered.
*/
- virtual void RemoveIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
- void* aData, bool aForImage) = 0;
+ void RemoveIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
+ void* aData, bool aForImage);
+
+ /**
+ * Check that aId is not empty and log a message to the console
+ * service if it is.
+ * @returns true if aId looks correct, false otherwise.
+ */
+ inline bool CheckGetElementByIdArg(const nsAString& aId)
+ {
+ if (aId.IsEmpty()) {
+ ReportEmptyGetElementByIdArg();
+ return false;
+ }
+ return true;
+ }
+
+ void ReportEmptyGetElementByIdArg();
/**
* Get the Content-Type of this document.
*/
void GetContentType(nsAString& aContentType);
/**
* Set the Content-Type of this document.
@@ -888,18 +936,18 @@ public:
{
mEncodingMenuDisabled = true;
}
/**
* Access HTTP header data (this may also get set from other
* sources, like HTML META tags).
*/
- virtual void GetHeaderData(nsAtom* aHeaderField, nsAString& aData) const = 0;
- virtual void SetHeaderData(nsAtom* aheaderField, const nsAString& aData) = 0;
+ void GetHeaderData(nsAtom* aHeaderField, nsAString& aData) const;
+ void SetHeaderData(nsAtom* aheaderField, const nsAString& aData);
/**
* Create a new presentation shell that will use aContext for its
* presentation context (presentation contexts <b>must not</b> be
* shared among multiple presentation shells). The caller of this
* method is responsible for calling BeginObservingDocument() on the
* presshell if the presshell should observe document mutations.
*/
@@ -979,33 +1027,32 @@ public:
if (aParent) {
mIgnoreDocGroupMismatches = aParent->mIgnoreDocGroupMismatches;
}
}
/**
* Are plugins allowed in this document ?
*/
- virtual bool GetAllowPlugins () = 0;
+ bool GetAllowPlugins ();
/**
* Set the sub document for aContent to aSubDoc.
*/
- virtual nsresult SetSubDocumentFor(Element* aContent,
- nsIDocument* aSubDoc) = 0;
+ nsresult SetSubDocumentFor(Element* aContent, nsIDocument* aSubDoc);
/**
* Get the sub document for aContent
*/
- virtual nsIDocument *GetSubDocumentFor(nsIContent *aContent) const = 0;
+ nsIDocument* GetSubDocumentFor(nsIContent* aContent) const;
/**
* Find the content node for which aDocument is a sub document.
*/
- virtual Element* FindContentForSubDocument(nsIDocument* aDocument) const = 0;
+ Element* FindContentForSubDocument(nsIDocument* aDocument) const;
/**
* Return the doctype for this document.
*/
mozilla::dom::DocumentType* GetDoctype() const;
/**
* Return the root element for this document.
@@ -1126,17 +1173,18 @@ public:
// Resolve all SVG pres attrs scheduled in ScheduleSVGForPresAttrEvaluation
void ResolveScheduledSVGPresAttrs();
mozilla::Maybe<mozilla::dom::ClientInfo> GetClientInfo() const;
mozilla::Maybe<mozilla::dom::ClientState> GetClientState() const;
mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController() const;
protected:
- virtual Element *GetRootElementInternal() const = 0;
+ virtual Element* GetRootElementInternal() const = 0;
+ void DoNotifyPossibleTitleChange();
void SetPageUnloadingEventTimeStamp()
{
MOZ_ASSERT(!mPageUnloadingEventTimeStamp);
mPageUnloadingEventTimeStamp = mozilla::TimeStamp::NowLoRes();
}
void CleanUnloadEventsTimeStamp()
@@ -2058,24 +2106,46 @@ public:
/*
* We record the set of links in the document that are relevant to
* style.
*/
/**
* Notification that an element is a link that is relevant to style.
*/
- virtual void AddStyleRelevantLink(mozilla::dom::Link* aLink) = 0;
+ void AddStyleRelevantLink(mozilla::dom::Link* aLink)
+ {
+ NS_ASSERTION(aLink, "Passing in a null link. Expect crashes RSN!");
+#ifdef DEBUG
+ nsPtrHashKey<mozilla::dom::Link>* entry = mStyledLinks.GetEntry(aLink);
+ NS_ASSERTION(!entry, "Document already knows about this Link!");
+ mStyledLinksCleared = false;
+#endif
+ mStyledLinks.PutEntry(aLink);
+ }
+
/**
* Notification that an element is a link and its URI might have been
* changed or the element removed. If the element is still a link relevant
* to style, then someone must ensure that AddStyleRelevantLink is
* (eventually) called on it again.
*/
- virtual void ForgetLink(mozilla::dom::Link* aLink) = 0;
+ void ForgetLink(mozilla::dom::Link* aLink)
+ {
+ NS_ASSERTION(aLink, "Passing in a null link. Expect crashes RSN!");
+#ifdef DEBUG
+ nsPtrHashKey<mozilla::dom::Link>* entry = mStyledLinks.GetEntry(aLink);
+ NS_ASSERTION(entry || mStyledLinksCleared,
+ "Document knows nothing about this Link!");
+#endif
+ mStyledLinks.RemoveEntry(aLink);
+ }
+
+ // Refreshes the hrefs of all the links in the document.
+ void RefreshLinkHrefs();
/**
* Resets and removes a box object from the document's box object cache
*
* @param aElement canonical nsIContent pointer of the box object's element
*/
virtual void ClearBoxObjectFor(nsIContent *aContent) = 0;
@@ -2105,17 +2175,18 @@ public:
nsCompatibility GetCompatibilityMode() const {
return mCompatMode;
}
/**
* Check whether we've ever fired a DOMTitleChanged event for this
* document.
*/
- bool HaveFiredDOMTitleChange() const {
+ bool HaveFiredDOMTitleChange() const
+ {
return mHaveFiredTitleChange;
}
virtual Element*
GetAnonymousElementByAttribute(nsIContent* aElement,
nsAtom* aAttrName,
const nsAString& aAttrValue) const = 0;
@@ -2651,17 +2722,17 @@ public:
/**
* Lookup an image element using its associated ID, which is usually provided
* by |-moz-element()|. Similar to GetElementById, with the difference that
* elements set using mozSetImageElement have higher priority.
* @param aId the ID associated the element we want to lookup
* @return the element associated with |aId|
*/
- virtual Element* LookupImageElement(const nsAString& aElementId) = 0;
+ Element* LookupImageElement(const nsAString& aElementId);
virtual mozilla::dom::DocumentTimeline* Timeline() = 0;
virtual mozilla::LinkedList<mozilla::dom::DocumentTimeline>& Timelines() = 0;
virtual void GetAnimations(
nsTArray<RefPtr<mozilla::dom::Animation>>& aAnimations) = 0;
mozilla::dom::SVGSVGElement* GetSVGRootElement() const;
@@ -2892,18 +2963,18 @@ public:
already_AddRefed<mozilla::dom::Location> GetLocation() const;
void GetReferrer(nsAString& aReferrer) const;
void GetLastModified(nsAString& aLastModified) const;
void GetReadyState(nsAString& aReadyState) const;
already_AddRefed<mozilla::dom::AboutCapabilities> GetAboutCapabilities(
ErrorResult& aRv);
- virtual void GetTitle(nsAString& aTitle) = 0;
- virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) = 0;
+ void GetTitle(nsAString& aTitle);
+ void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv);
void GetDir(nsAString& aDirection) const;
void SetDir(const nsAString& aDirection);
already_AddRefed<nsContentList> GetElementsByName(const nsAString& aName)
{
return GetFuncStringContentList<nsCachableElementsByNameNodeList>(this,
MatchNameAttribute,
nullptr,
UseExistingNameString,
@@ -2919,18 +2990,17 @@ public:
void SetLastFocusTime(const mozilla::TimeStamp& aFocusTime);
// Event handlers are all on nsINode already
bool MozSyntheticDocument() const
{
return IsSyntheticDocument();
}
Element* GetCurrentScript();
void ReleaseCapture() const;
- virtual void MozSetImageElement(const nsAString& aImageElementId,
- Element* aElement) = 0;
+ void MozSetImageElement(const nsAString& aImageElementId, Element* aElement);
nsIURI* GetDocumentURIObject() const;
// Not const because all the full-screen goop is not const
virtual bool FullscreenEnabled(mozilla::dom::CallerType aCallerType) = 0;
virtual Element* FullScreenStackTop() = 0;
bool Fullscreen()
{
return !!GetFullscreenElement();
}
@@ -3138,18 +3208,18 @@ public:
// The URLs passed to these functions should match what
// JS::DescribeScriptedCaller() returns, since these APIs are used to
// determine whether some code is being called from a tracking script.
void NoteScriptTrackingStatus(const nsACString& aURL, bool isTracking);
bool IsScriptTracking(const nsACString& aURL) const;
// For more information on Flash classification, see
// toolkit/components/url-classifier/flash-block-lists.rst
- virtual mozilla::dom::FlashClassification DocumentFlashClassification() = 0;
- virtual bool IsThirdParty() = 0;
+ mozilla::dom::FlashClassification DocumentFlashClassification();
+ bool IsThirdParty();
bool IsScopedStyleEnabled();
nsINode* GetServoRestyleRoot() const
{
return mServoRestyleRoot;
}
@@ -3217,16 +3287,33 @@ public:
* anonymous. Otherwise, when aFrame is in a subdocument, we use the frame
* element containing the subdocument containing aFrame, and/or find the
* nearest non-anonymous ancestor in this document.
* Returns null if there is no such element.
*/
nsIContent* GetContentInThisDocument(nsIFrame* aFrame) const;
protected:
+ /**
+ * Returns the title element of the document as defined by the HTML
+ * specification, or null if there isn't one. For documents whose root
+ * element is an <svg:svg>, this is the first <svg:title> element that's a
+ * child of the root. For other documents, it's the first HTML title element
+ * in the document.
+ */
+ Element* GetTitleElement();
+
+ // Retrieves the classification of the Flash plugins in the document based on
+ // the classification lists.
+ mozilla::dom::FlashClassification PrincipalFlashClassification();
+
+ // Attempts to determine the Flash classification of this page based on the
+ // the classification lists and the classification of parent documents.
+ mozilla::dom::FlashClassification ComputeFlashClassification();
+
bool GetUseCounter(mozilla::UseCounter aUseCounter)
{
return mUseCounters[aUseCounter];
}
void SetChildDocumentUseCounter(mozilla::UseCounter aUseCounter)
{
if (!mChildDocumentUseCounters[aUseCounter]) {
@@ -3291,17 +3378,17 @@ protected:
// Never ever call this. Only call GetWindow!
virtual nsPIDOMWindowOuter* GetWindowInternal() const = 0;
// Never ever call this. Only call GetScriptHandlingObject!
virtual nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const = 0;
// Never ever call this. Only call AllowXULXBL!
- virtual bool InternalAllowXULXBL() = 0;
+ bool InternalAllowXULXBL();
/**
* These methods should be called before and after dispatching
* a mutation event.
* To make this easy and painless, use the mozAutoSubtreeModified helper class.
*/
virtual void WillDispatchMutationEvent(nsINode* aTarget) = 0;
virtual void MutationEventDispatched(nsINode* aTarget) = 0;
@@ -3399,16 +3486,25 @@ protected:
// The set of all object, embed, video/audio elements or
// nsIObjectLoadingContent or nsIDocumentActivity for which this is the owner
// document. (They might not be in the document.)
//
// These are non-owning pointers, the elements are responsible for removing
// themselves when they go away.
nsAutoPtr<nsTHashtable<nsPtrHashKey<nsISupports> > > mActivityObservers;
+ // A hashtable of styled links keyed by address pointer.
+ nsTHashtable<nsPtrHashKey<mozilla::dom::Link>> mStyledLinks;
+#ifdef DEBUG
+ // Indicates whether mStyledLinks was cleared or not. This is used to track
+ // state so we can provide useful assertions to consumers of ForgetLink and
+ // AddStyleRelevantLink.
+ bool mStyledLinksCleared;
+#endif
+
// The array of all links that need their status resolved. Links must add themselves
// to this set by calling RegisterPendingLinkUpdate when added to a document.
static const size_t kSegmentSize = 128;
typedef mozilla::SegmentedVector<nsCOMPtr<mozilla::dom::Link>,
kSegmentSize,
InfallibleAllocPolicy>
LinksToUpdateList;
@@ -3632,16 +3728,20 @@ protected:
// Whether we have filled our pres shell's style set with the document's
// additional sheets and sheets from the nsStyleSheetService.
bool mStyleSetFilled: 1;
// Keeps track of whether we have a pending
// 'style-sheet-applicable-state-changed' notification.
bool mSSApplicableStateNotificationPending: 1;
+ // True if this document has ever had an HTML or SVG <title> element
+ // bound to it
+ bool mMayHaveTitleElement: 1;
+
// Whether <style scoped> support is enabled in this document.
enum { eScopedStyle_Unknown, eScopedStyle_Disabled, eScopedStyle_Enabled };
unsigned int mIsScopedStyleEnabled : 2;
// Compatibility mode
nsCompatibility mCompatMode;
// Our readyState
@@ -3834,16 +3934,37 @@ protected:
// Weak reference to our sink for in case we no longer have a parser. This
// will allow us to flush out any pending stuff from the sink even if
// EndLoad() has already happened.
nsWeakPtr mWeakSink;
// Our update nesting level
uint32_t mUpdateNestLevel;
+ enum ViewportType {
+ DisplayWidthHeight,
+ Specified,
+ Unknown
+ };
+
+ ViewportType mViewportType;
+
+ PLDHashTable* mSubDocuments;
+
+ nsDocHeaderData* mHeaderData;
+
+ RefPtr<PrincipalFlashClassifier> mPrincipalFlashClassifier;
+ mozilla::dom::FlashClassification mFlashClassification;
+ // Do not use this value directly. Call the |IsThirdParty()| method, which
+ // caches its result here.
+ mozilla::Maybe<bool> mIsThirdParty;
+
+ nsRevocableEventPtr<nsRunnableMethod<nsIDocument, void, false>>
+ mPendingTitleChangeEvent;
+
nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
// Member to store out last-selected stylesheet set.
nsString mLastStyleSheetSet;
RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
// We lazily calculate declaration blocks for SVG elements with mapped
--- a/dom/base/nsNodeInfoManager.h
+++ b/dom/base/nsNodeInfoManager.h
@@ -130,17 +130,17 @@ public:
return mMathMLEnabled == eTriTrue
? true
: mMathMLEnabled == eTriFalse ? false : InternalMathMLEnabled();
}
void AddSizeOfIncludingThis(nsWindowSizes& aSizes) const;
protected:
- friend class nsDocument;
+ friend class nsIDocument;
friend class nsXULPrototypeDocument;
friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** ,
nsNodeInfoManager *,
nsAtom *,
const nsAString& ,
const nsAString& ,
const nsAString& );