Bug 1422633: Inline nsIDocument::ThreadSafeGetDocumentState(). r?smaug
It's silly to pay a function call for that, and it shows up in stylo-chrome
profiles.
MozReview-Commit-ID: 8m7ZHG1KX15
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -9868,17 +9868,17 @@ nsDocument::ForgetImagePreload(nsIURI* a
if (req) {
// Make sure to cancel the request so imagelib knows it's gone.
req->CancelAndForgetObserver(NS_BINDING_ABORTED);
}
}
}
void
-nsDocument::UpdatePossiblyStaleDocumentState()
+nsIDocument::UpdatePossiblyStaleDocumentState()
{
if (!mGotDocumentState.HasState(NS_DOCUMENT_STATE_RTL_LOCALE)) {
if (IsDocumentRightToLeft()) {
mDocumentState |= NS_DOCUMENT_STATE_RTL_LOCALE;
}
mGotDocumentState |= NS_DOCUMENT_STATE_RTL_LOCALE;
}
if (!mGotDocumentState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
@@ -9886,29 +9886,16 @@ nsDocument::UpdatePossiblyStaleDocumentS
if (shell && shell->GetPresContext() &&
shell->GetPresContext()->IsTopLevelWindowInactive()) {
mDocumentState |= NS_DOCUMENT_STATE_WINDOW_INACTIVE;
}
mGotDocumentState |= NS_DOCUMENT_STATE_WINDOW_INACTIVE;
}
}
-EventStates
-nsDocument::ThreadSafeGetDocumentState() const
-{
- return mDocumentState;
-}
-
-EventStates
-nsDocument::GetDocumentState()
-{
- UpdatePossiblyStaleDocumentState();
- return ThreadSafeGetDocumentState();
-}
-
namespace {
/**
* Stub for LoadSheet(), since all we want is to get the sheet into
* the CSSLoader's style cache
*/
class StubCSSLoaderObserver final : public nsICSSLoaderObserver {
~StubCSSLoaderObserver() {}
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -838,23 +838,16 @@ public:
ReferrerPolicy aReferrerPolicy,
const nsAString& aIntegrity) override;
virtual nsresult LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet,
RefPtr<mozilla::StyleSheet>* aSheet) override;
virtual nsISupports* GetCurrentContentSink() override;
- virtual mozilla::EventStates GetDocumentState() final;
- // GetDocumentState() mutates the state due to lazy resolution;
- // and can't be used during parallel traversal. Use this instead,
- // and ensure GetDocumentState() has been called first.
- // This will assert if the state is stale.
- virtual mozilla::EventStates ThreadSafeGetDocumentState() const final;
-
// Only BlockOnload should call this!
void AsyncBlockOnload();
virtual void SetScrollToRef(nsIURI *aDocumentURI) override;
virtual void ScrollToRef() override;
virtual void ResetScrolledToRefAlready() override;
virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) override;
@@ -1177,18 +1170,16 @@ protected:
// 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;
-private:
- void UpdatePossiblyStaleDocumentState();
public:
RefPtr<mozilla::EventListenerManager> mListenerManager;
RefPtr<mozilla::dom::StyleSheetList> mDOMStyleSheets;
RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
RefPtr<mozilla::dom::ScriptLoader> mScriptLoader;
nsDocHeaderData* mHeaderData;
/* mIdentifierMap works as follows for IDs:
@@ -1265,19 +1256,16 @@ public:
uint32_t mUpdateNestLevel;
// The application cache that this document is associated with, if
// any. This can change during the lifetime of the document.
nsCOMPtr<nsIApplicationCache> mApplicationCache;
nsCOMPtr<nsIContent> mFirstBaseNodeWithHref;
- mozilla::EventStates mDocumentState;
- mozilla::EventStates mGotDocumentState;
-
RefPtr<nsDOMNavigationTiming> mTiming;
private:
friend class nsUnblockOnloadEvent;
// Recomputes the visibility state but doesn't set the new value.
mozilla::dom::VisibilityState GetVisibilityState() const;
void NotifyStyleSheetAdded(mozilla::StyleSheet* aSheet, bool aDocumentSheet);
void NotifyStyleSheetRemoved(mozilla::StyleSheet* aSheet, bool aDocumentSheet);
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -2636,18 +2636,28 @@ public:
virtual DocumentTheme GetDocumentLWTheme() { return Doc_Theme_None; }
virtual DocumentTheme ThreadSafeGetDocumentLWTheme() const { return Doc_Theme_None; }
/**
* Returns the document state.
* Document state bits have the form NS_DOCUMENT_STATE_* and are declared in
* nsIDocument.h.
*/
- virtual mozilla::EventStates GetDocumentState() = 0;
- virtual mozilla::EventStates ThreadSafeGetDocumentState() const = 0;
+ mozilla::EventStates GetDocumentState() {
+ UpdatePossiblyStaleDocumentState();
+ return ThreadSafeGetDocumentState();
+ }
+
+ // GetDocumentState() mutates the state due to lazy resolution;
+ // and can't be used during parallel traversal. Use this instead,
+ // and ensure GetDocumentState() has been called first.
+ // This will assert if the state is stale.
+ mozilla::EventStates ThreadSafeGetDocumentState() const {
+ return mDocumentState;
+ }
virtual nsISupports* GetCurrentContentSink() = 0;
virtual void SetScrollToRef(nsIURI *aDocumentURI) = 0;
virtual void ScrollToRef() = 0;
virtual void ResetScrolledToRefAlready() = 0;
virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) = 0;
@@ -3258,16 +3268,18 @@ protected:
}
bool GetChildDocumentUseCounter(mozilla::UseCounter aUseCounter)
{
return mChildDocumentUseCounters[aUseCounter];
}
private:
+ void UpdatePossiblyStaleDocumentState();
+
mutable std::bitset<eDeprecatedOperationCount> mDeprecationWarnedAbout;
mutable std::bitset<eDocumentWarningCount> mDocWarningWarnedAbout;
// Lazy-initialization to have mDocGroup initialized in prior to the
// SelectorCaches.
// FIXME(emilio): We can use a single cache when all CSSOM methods are
// implemented for the Servo backend.
mozilla::UniquePtr<SelectorCache> mServoSelectorCache;
@@ -3417,16 +3429,19 @@ protected:
// container for per-context fonts (downloadable, SVG, etc.)
RefPtr<mozilla::dom::FontFaceSet> mFontFaceSet;
// Last time this document or a one of its sub-documents was focused. If
// focus has never occurred then mLastFocusTime.IsNull() will be true.
mozilla::TimeStamp mLastFocusTime;
+ mozilla::EventStates mDocumentState;
+ mozilla::EventStates mGotDocumentState;
+
// True if BIDI is enabled.
bool mBidiEnabled : 1;
// True if a MathML element has ever been owned by this document.
bool mMathMLEnabled : 1;
// True if this document is the initial document for a window. This should
// basically be true only for documents that exist in newly-opened windows or
// documents created to satisfy a GetDocument() on a window when there's no