Bug 1516366 - Move base classes from nsDocument to nsIDocument. r=smaug

This is a big step in order to merge both.

Also allows to remove some very silly casts, though it causes us to add some
ToSupports around to deal with ambiguity of casts from nsIDocument to
nsISupports, and add a dummy nsISupports implementation that will go away later
in the series.

Differential Revision: https://phabricator.services.mozilla.com/D15352
This commit is contained in:
Emilio Cobos Álvarez 2018-12-26 03:32:55 +01:00
parent ecc88f298e
commit f131713362
36 changed files with 185 additions and 195 deletions

View File

@ -11066,14 +11066,7 @@ nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
}
} else {
// It's a file:// URI
nsCOMPtr<nsIScriptObjectPrincipal> docScriptObj =
do_QueryInterface(document);
if (!docScriptObj) {
return NS_ERROR_DOM_SECURITY_ERR;
}
nsCOMPtr<nsIPrincipal> principal = docScriptObj->GetPrincipal();
nsCOMPtr<nsIPrincipal> principal = document->GetPrincipal();
if (!principal ||
NS_FAILED(principal->CheckMayLoad(newURI, true, false))) {

View File

@ -41,7 +41,7 @@ class AnimationEffect : public nsISupports, public nsWrapperCache {
return nullptr;
}
nsISupports* GetParentObject() const { return mDocument; }
nsISupports* GetParentObject() const { return ToSupports(mDocument); }
bool IsCurrent() const;
bool IsInEffect() const;

View File

@ -911,11 +911,6 @@ nsresult nsContentSink::SelectDocAppCache(
*aAction = CACHE_SELECTION_NONE;
nsCOMPtr<nsIApplicationCacheContainer> applicationCacheDocument =
do_QueryInterface(mDocument);
NS_ASSERTION(applicationCacheDocument,
"mDocument must implement nsIApplicationCacheContainer.");
if (aLoadApplicationCache) {
nsCOMPtr<nsIURI> groupURI;
rv = aLoadApplicationCache->GetManifestURI(getter_AddRefs(groupURI));
@ -944,7 +939,7 @@ nsresult nsContentSink::SelectDocAppCache(
clientID.get(), docURISpec.get()));
#endif
rv = applicationCacheDocument->SetApplicationCache(aLoadApplicationCache);
rv = mDocument->SetApplicationCache(aLoadApplicationCache);
NS_ENSURE_SUCCESS(rv, rv);
// Document will be added as implicit entry to the cache as part of
@ -981,11 +976,6 @@ nsresult nsContentSink::SelectDocAppCacheNoManifest(
if (aLoadApplicationCache) {
// The document was loaded from an application cache, use that
// application cache as the document's application cache.
nsCOMPtr<nsIApplicationCacheContainer> applicationCacheDocument =
do_QueryInterface(mDocument);
NS_ASSERTION(applicationCacheDocument,
"mDocument must implement nsIApplicationCacheContainer.");
#ifdef DEBUG
nsAutoCString docURISpec, clientID;
mDocumentURI->GetAsciiSpec(docURISpec);
@ -996,7 +986,7 @@ nsresult nsContentSink::SelectDocAppCacheNoManifest(
clientID.get(), docURISpec.get()));
#endif
rv = applicationCacheDocument->SetApplicationCache(aLoadApplicationCache);
rv = mDocument->SetApplicationCache(aLoadApplicationCache);
NS_ENSURE_SUCCESS(rv, rv);
// Return the uri and invoke the update process for the selected
@ -1563,13 +1553,13 @@ void nsContentSink::NotifyDocElementCreated(nsIDocument* aDoc) {
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(aDoc, "document-element-inserted",
EmptyString().get());
observerService->NotifyObservers(
ToSupports(aDoc), "document-element-inserted", EmptyString().get());
}
nsContentUtils::DispatchChromeEvent(
aDoc, aDoc, NS_LITERAL_STRING("DOMDocElementInserted"), CanBubble::eYes,
Cancelable::eNo);
aDoc, ToSupports(aDoc), NS_LITERAL_STRING("DOMDocElementInserted"),
CanBubble::eYes, Cancelable::eNo);
}
NS_IMETHODIMP

View File

@ -792,7 +792,7 @@ void nsExternalResourceMap::Traverse(
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCallback,
"mExternalResourceMap.mMap entry"
"->mDocument");
aCallback->NoteXPCOMChild(resource->mDocument);
aCallback->NoteXPCOMChild(ToSupports(resource->mDocument));
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCallback,
"mExternalResourceMap.mMap entry"
@ -899,7 +899,8 @@ nsresult nsExternalResourceMap::AddExternalResource(
const nsTArray<nsCOMPtr<nsIObserver>>& obs = load->Observers();
for (uint32_t i = 0; i < obs.Length(); ++i) {
obs[i]->Observe(doc, "external-resource-document-created", nullptr);
obs[i]->Observe(ToSupports(doc), "external-resource-document-created",
nullptr);
}
return rv;
@ -1624,6 +1625,20 @@ nsDocument::~nsDocument() {
mPlugins.Clear();
}
// In practice these three are always overriden by the nsDocument version, we
// just need them to avoid making nsIDocument::AddRef / Release ambiguous.
//
// We can get rid of these once we merge nsIDocument and nsDocument.
NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::Release() {
MOZ_CRASH("Should never be reachable");
}
NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::AddRef() {
MOZ_CRASH("Should never be reachable");
}
NS_IMETHODIMP nsIDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
MOZ_CRASH("Should never be reachable");
}
NS_INTERFACE_TABLE_HEAD(nsDocument)
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
NS_INTERFACE_TABLE_BEGIN
@ -1804,7 +1819,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
cb.NoteXPCOMChild(entry->mKey);
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
"mSubDocuments entry->mSubDocument");
cb.NoteXPCOMChild(entry->mSubDocument);
cb.NoteXPCOMChild(ToSupports(entry->mSubDocument));
}
}
@ -3008,8 +3023,6 @@ void nsIDocument::RemoveFromIdTable(Element* aElement, nsAtom* aId) {
}
}
nsIPrincipal* nsDocument::GetPrincipal() { return NodePrincipal(); }
extern bool sDisablePrefetchHTTPSPref;
void nsIDocument::SetPrincipal(nsIPrincipal* aNewPrincipal) {
@ -3096,16 +3109,14 @@ bool nsIDocument::IsScriptTracking(const nsACString& aURL) const {
}
NS_IMETHODIMP
nsDocument::GetApplicationCache(nsIApplicationCache** aApplicationCache) {
nsIDocument::GetApplicationCache(nsIApplicationCache** aApplicationCache) {
NS_IF_ADDREF(*aApplicationCache = mApplicationCache);
return NS_OK;
}
NS_IMETHODIMP
nsDocument::SetApplicationCache(nsIApplicationCache* aApplicationCache) {
nsIDocument::SetApplicationCache(nsIApplicationCache* aApplicationCache) {
mApplicationCache = aApplicationCache;
return NS_OK;
}
@ -4094,7 +4105,7 @@ void nsIDocument::NotifyStyleSheetApplicableStateChanged() {
mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(
this, "style-sheet-applicable-state-changed", nullptr);
ToSupports(this), "style-sheet-applicable-state-changed", nullptr);
}
}
@ -4706,7 +4717,7 @@ void nsIDocument::DispatchContentLoadedEvents() {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
nsIPrincipal* principal = NodePrincipal();
os->NotifyObservers(this,
os->NotifyObservers(ToSupports(this),
nsContentUtils::IsSystemPrincipal(principal)
? "chrome-document-interactive"
: "content-document-interactive",
@ -4716,7 +4727,7 @@ void nsIDocument::DispatchContentLoadedEvents() {
// Fire a DOM event notifying listeners that this document has been
// loaded (excluding images and other loads initiated by this
// document).
nsContentUtils::DispatchTrustedEvent(this, this,
nsContentUtils::DispatchTrustedEvent(this, ToSupports(this),
NS_LITERAL_STRING("DOMContentLoaded"),
CanBubble::eYes, Cancelable::eNo);
@ -4787,11 +4798,9 @@ void nsIDocument::DispatchContentLoadedEvents() {
if (innerEvent) {
nsEventStatus status = nsEventStatus_eIgnore;
RefPtr<nsPresContext> context = parent->GetPresContext();
if (context) {
EventDispatcher::Dispatch(parent, context, innerEvent, event,
&status);
if (RefPtr<nsPresContext> context = parent->GetPresContext()) {
EventDispatcher::Dispatch(ToSupports(parent), context, innerEvent,
event, &status);
}
}
}
@ -4805,7 +4814,7 @@ void nsIDocument::DispatchContentLoadedEvents() {
Element* root = GetRootElement();
if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::manifest)) {
nsContentUtils::DispatchChromeEvent(
this, this, NS_LITERAL_STRING("MozApplicationManifest"),
this, ToSupports(this), NS_LITERAL_STRING("MozApplicationManifest"),
CanBubble::eYes, Cancelable::eYes);
}
@ -5920,7 +5929,7 @@ void nsIDocument::DoNotifyPossibleTitleChange() {
}
// Fire a DOM event for the title change.
nsContentUtils::DispatchChromeEvent(this, static_cast<nsIDocument*>(this),
nsContentUtils::DispatchChromeEvent(this, ToSupports(this),
NS_LITERAL_STRING("DOMTitleChanged"),
CanBubble::eYes, Cancelable::eYes);
}
@ -6491,7 +6500,7 @@ nsINode* nsIDocument::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv) {
// canonical scope. But we try to pass something sane anyway.
JSAutoRealm ar(cx, GetScopeObject()->GetGlobalJSObject());
JS::Rooted<JS::Value> v(cx);
rv = nsContentUtils::WrapNative(cx, this, this, &v,
rv = nsContentUtils::WrapNative(cx, ToSupports(this), this, &v,
/* aAllowWrapping = */ false);
if (rv.Failed()) return nullptr;
newScope = &v.toObject();
@ -7823,7 +7832,7 @@ void nsIDocument::OnPageShow(bool aPersisted, EventTarget* aDispatchStartTarget,
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
nsIPrincipal* principal = NodePrincipal();
os->NotifyObservers(this,
os->NotifyObservers(ToSupports(this),
nsContentUtils::IsSystemPrincipal(principal)
? "chrome-page-shown"
: "content-page-shown",
@ -7920,7 +7929,7 @@ void nsIDocument::OnPageHide(bool aPersisted, EventTarget* aDispatchStartTarget,
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
nsIPrincipal* principal = NodePrincipal();
os->NotifyObservers(this,
os->NotifyObservers(ToSupports(this),
nsContentUtils::IsSystemPrincipal(principal)
? "chrome-page-hidden"
: "content-page-hidden",
@ -10886,7 +10895,7 @@ void nsIDocument::UpdateVisibilityState() {
dom::VisibilityState oldState = mVisibilityState;
mVisibilityState = ComputeVisibilityState();
if (oldState != mVisibilityState) {
nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
nsContentUtils::DispatchTrustedEvent(this, ToSupports(this),
NS_LITERAL_STRING("visibilitychange"),
CanBubble::eYes, Cancelable::eNo);
EnumerateActivityObservers(NotifyActivityChanged, nullptr);
@ -12531,14 +12540,7 @@ bool nsIDocument::IsThirdParty() {
}
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();
nsCOMPtr<nsIPrincipal> parentPrincipal = parentDocument->GetPrincipal();
bool principalsMatch = false;
rv = principal->Equals(parentPrincipal, &principalsMatch);

View File

@ -17,7 +17,6 @@
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsCRT.h"
#include "nsIWeakReferenceUtils.h"
#include "nsTArray.h"
#include "nsIdentifierMapEntry.h"
#include "nsStubDocumentObserver.h"
@ -28,8 +27,6 @@
#include "nsBindingManager.h"
#include "nsRefPtrHashtable.h"
#include "nsJSThingHashtable.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIRadioGroupContainer.h"
#include "nsILayoutHistoryState.h"
#include "nsIRequest.h"
#include "nsILoadGroup.h"
@ -95,12 +92,7 @@ class nsOnloadBlocker final : public nsIRequest {
};
// Base class for our document implementations.
class nsDocument : public nsIDocument,
public nsSupportsWeakReference,
public nsIScriptObjectPrincipal,
public nsIRadioGroupContainer,
public nsIApplicationCacheContainer,
public nsStubMutationObserver {
class nsDocument : public nsIDocument {
friend class nsIDocument;
public:
@ -135,53 +127,7 @@ class nsDocument : public nsIDocument,
virtual void BeginLoad() override;
virtual void EndLoad() override;
// nsIRadioGroupContainer
NS_IMETHOD WalkRadioGroup(const nsAString& aName, nsIRadioVisitor* aVisitor,
bool aFlushContent) override {
return DocumentOrShadowRoot::WalkRadioGroup(aName, aVisitor, aFlushContent);
}
virtual void SetCurrentRadioButton(
const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override {
DocumentOrShadowRoot::SetCurrentRadioButton(aName, aRadio);
}
virtual mozilla::dom::HTMLInputElement* GetCurrentRadioButton(
const nsAString& aName) override {
return DocumentOrShadowRoot::GetCurrentRadioButton(aName);
}
NS_IMETHOD
GetNextRadioButton(const nsAString& aName, const bool aPrevious,
mozilla::dom::HTMLInputElement* aFocusedRadio,
mozilla::dom::HTMLInputElement** aRadioOut) override {
return DocumentOrShadowRoot::GetNextRadioButton(aName, aPrevious,
aFocusedRadio, aRadioOut);
}
virtual void AddToRadioGroup(
const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override {
DocumentOrShadowRoot::AddToRadioGroup(aName, aRadio);
}
virtual void RemoveFromRadioGroup(
const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override {
DocumentOrShadowRoot::RemoveFromRadioGroup(aName, aRadio);
}
virtual uint32_t GetRequiredRadioCount(
const nsAString& aName) const override {
return DocumentOrShadowRoot::GetRequiredRadioCount(aName);
}
virtual void RadioRequiredWillChange(const nsAString& aName,
bool aRequiredAdded) override {
DocumentOrShadowRoot::RadioRequiredWillChange(aName, aRequiredAdded);
}
virtual bool GetValueMissingState(const nsAString& aName) const override {
return DocumentOrShadowRoot::GetValueMissingState(aName);
}
virtual void SetValueMissingState(const nsAString& aName,
bool aValue) override {
return DocumentOrShadowRoot::SetValueMissingState(aName, aValue);
}
// Check whether shadow DOM is enabled for the document this node belongs to.
// Same as above, but also checks that the caller is either chrome or some
// addon.
// Checks that the caller is either chrome or some addon.
static bool IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject);
public:
@ -196,12 +142,6 @@ class nsDocument : public nsIDocument,
virtual mozilla::EventListenerManager* GetExistingListenerManager()
const override;
// nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal() override;
// nsIApplicationCacheContainer
NS_DECL_NSIAPPLICATIONCACHECONTAINER
virtual nsresult Init();
virtual void Destroy() override;
@ -211,7 +151,7 @@ class nsDocument : public nsIDocument,
virtual void UnblockOnload(bool aFireSync) override;
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument,
nsIDocument)
nsINode)
void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; }
void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData) {
@ -268,10 +208,6 @@ class nsDocument : public nsIDocument,
friend class nsCallRequestFullscreen;
// 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;
private:

View File

@ -1687,7 +1687,8 @@ bool nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear,
// that the check is made for suppressed documents. Check to ensure that
// the document isn't null in case someone closed it during the blur above
nsIDocument* doc = window->GetExtantDoc();
if (doc) SendFocusOrBlurEvent(eBlur, presShell, doc, doc, 1, false);
if (doc)
SendFocusOrBlurEvent(eBlur, presShell, doc, ToSupports(doc), 1, false);
if (mFocusedWindow == nullptr)
SendFocusOrBlurEvent(eBlur, presShell, doc,
window->GetCurrentInnerWindow(), 1, false);
@ -1804,7 +1805,7 @@ void nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow, Element* aElement,
GetFocusMoveActionCause(aFlags));
}
if (doc) {
SendFocusOrBlurEvent(eFocus, presShell, doc, doc,
SendFocusOrBlurEvent(eFocus, presShell, doc, ToSupports(doc),
aFlags & FOCUSMETHOD_MASK, aWindowRaised);
}
if (mFocusedWindow == aWindow && mFocusedElement == nullptr) {

View File

@ -2059,7 +2059,7 @@ void nsGlobalWindowOuter::DispatchDOMWindowCreated() {
}
// Fire DOMWindowCreated at chrome event listeners
nsContentUtils::DispatchChromeEvent(mDoc, mDoc,
nsContentUtils::DispatchChromeEvent(mDoc, ToSupports(mDoc),
NS_LITERAL_STRING("DOMWindowCreated"),
CanBubble::eYes, Cancelable::eNo);

View File

@ -25,6 +25,8 @@
#include "nsIPresShell.h"
#include "nsIChannelEventSink.h"
#include "nsIProgressEventSink.h"
#include "nsIRadioGroupContainer.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsISecurityEventSink.h"
#include "nsIScriptGlobalObject.h" // for member (in nsCOMPtr)
#include "nsIServiceManager.h"
@ -35,6 +37,7 @@
#include "nsPIDOMWindow.h" // for use in inline functions
#include "nsPropertyTable.h" // for member
#include "nsStringFwd.h"
#include "nsStubMutationObserver.h"
#include "nsTHashtable.h" // for member
#include "nsURIHashKey.h"
#include "mozilla/net/ReferrerPolicy.h" // for member
@ -434,6 +437,11 @@ class PrincipalFlashClassifier;
// Gecko.
class nsIDocument : public nsINode,
public mozilla::dom::DocumentOrShadowRoot,
public nsSupportsWeakReference,
public nsIRadioGroupContainer,
public nsIScriptObjectPrincipal,
public nsIApplicationCacheContainer,
public nsStubMutationObserver,
public mozilla::dom::DispatcherTrait {
typedef mozilla::dom::GlobalObject GlobalObject;
@ -450,11 +458,63 @@ class nsIDocument : public nsINode,
typedef mozilla::dom::SVGElement SVGElement;
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
NS_DECL_ISUPPORTS_INHERITED
#ifdef MOZILLA_INTERNAL_API
nsIDocument();
#endif
// nsIApplicationCacheContainer
NS_DECL_NSIAPPLICATIONCACHECONTAINER
// nsIRadioGroupContainer
NS_IMETHOD WalkRadioGroup(const nsAString& aName, nsIRadioVisitor* aVisitor,
bool aFlushContent) final {
return DocumentOrShadowRoot::WalkRadioGroup(aName, aVisitor, aFlushContent);
}
void SetCurrentRadioButton(const nsAString& aName,
mozilla::dom::HTMLInputElement* aRadio) final {
DocumentOrShadowRoot::SetCurrentRadioButton(aName, aRadio);
}
mozilla::dom::HTMLInputElement* GetCurrentRadioButton(
const nsAString& aName) final {
return DocumentOrShadowRoot::GetCurrentRadioButton(aName);
}
NS_IMETHOD
GetNextRadioButton(const nsAString& aName, const bool aPrevious,
mozilla::dom::HTMLInputElement* aFocusedRadio,
mozilla::dom::HTMLInputElement** aRadioOut) final {
return DocumentOrShadowRoot::GetNextRadioButton(aName, aPrevious,
aFocusedRadio, aRadioOut);
}
void AddToRadioGroup(const nsAString& aName,
mozilla::dom::HTMLInputElement* aRadio) final {
DocumentOrShadowRoot::AddToRadioGroup(aName, aRadio);
}
void RemoveFromRadioGroup(const nsAString& aName,
mozilla::dom::HTMLInputElement* aRadio) final {
DocumentOrShadowRoot::RemoveFromRadioGroup(aName, aRadio);
}
uint32_t GetRequiredRadioCount(const nsAString& aName) const final {
return DocumentOrShadowRoot::GetRequiredRadioCount(aName);
}
void RadioRequiredWillChange(const nsAString& aName,
bool aRequiredAdded) final {
DocumentOrShadowRoot::RadioRequiredWillChange(aName, aRequiredAdded);
}
bool GetValueMissingState(const nsAString& aName) const final {
return DocumentOrShadowRoot::GetValueMissingState(aName);
}
void SetValueMissingState(const nsAString& aName, bool aValue) final {
return DocumentOrShadowRoot::SetValueMissingState(aName, aValue);
}
// nsIScriptObjectPrincipal
nsIPrincipal* GetPrincipal() final { return NodePrincipal(); }
// This helper class must be set when we dispatch beforeunload and unload
// events in order to avoid unterminate sync XHRs.
class MOZ_RAII PageUnloadingEventTimeStamp {
@ -3323,6 +3383,10 @@ class nsIDocument : public nsINode,
nsTArray<nsString> mL10nResources;
// The application cache that this document is associated with, if
// any. This can change during the lifetime of the document.
nsCOMPtr<nsIApplicationCache> mApplicationCache;
public:
bool IsThirdParty();
@ -4497,4 +4561,8 @@ inline const nsIDocument* nsINode::AsDocument() const {
return static_cast<const nsIDocument*>(this);
}
inline nsISupports* ToSupports(nsIDocument* aDoc) {
return static_cast<nsINode*>(aDoc);
}
#endif /* nsIDocument_h___ */

View File

@ -788,8 +788,8 @@ nsImageLoadingContent::LoadImageWithChannel(nsIChannel* aChannel,
// Do the load.
RefPtr<imgRequestProxy>& req = PrepareNextRequest(eImageLoadType_Normal);
nsresult rv = loader->LoadImageWithChannel(aChannel, this, doc, aListener,
getter_AddRefs(req));
nsresult rv = loader->LoadImageWithChannel(aChannel, this, ToSupports(doc),
aListener, getter_AddRefs(req));
if (NS_SUCCEEDED(rv)) {
CloneScriptedRequests(req);
TrackImage(req);

View File

@ -262,7 +262,7 @@ class nsSimplePluginEvent : public Runnable {
nsSimplePluginEvent(nsIDocument* aTarget, const nsAString& aEvent)
: mozilla::Runnable("nsSimplePluginEvent"),
mTarget(aTarget),
mTarget(ToSupports(aTarget)),
mDocument(aTarget),
mEvent(aEvent) {
MOZ_ASSERT(aTarget);

View File

@ -425,7 +425,7 @@ enum class ReflectionScope { Content, XBL, UAWidget };
struct MOZ_STACK_CLASS ParentObject {
template <class T>
MOZ_IMPLICIT ParentObject(T* aObject)
: mObject(aObject),
: mObject(ToSupports(aObject)),
mWrapperCache(GetWrapperCache(aObject)),
mReflectionScope(ReflectionScope::Content) {}

View File

@ -2102,7 +2102,7 @@ void EventStateManager::DoScrollZoom(nsIFrame* aTargetFrame,
ChangeTextSize(change);
}
nsContentUtils::DispatchChromeEvent(
mDocument, static_cast<nsIDocument*>(mDocument),
mDocument, ToSupports(mDocument),
NS_LITERAL_STRING("ZoomChangeUsingMouseWheel"), CanBubble::eYes,
Cancelable::eYes);
}

View File

@ -131,7 +131,7 @@ NS_IMETHODIMP
ImageListener::OnStopRequest(nsIRequest* aRequest, nsISupports* aCtxt,
nsresult aStatus) {
ImageDocument* imgDoc = static_cast<ImageDocument*>(mDocument.get());
nsContentUtils::DispatchChromeEvent(imgDoc, static_cast<nsIDocument*>(imgDoc),
nsContentUtils::DispatchChromeEvent(imgDoc, ToSupports(imgDoc),
NS_LITERAL_STRING("ImageContentLoaded"),
CanBubble::eYes, Cancelable::eYes);
return MediaDocumentStreamListener::OnStopRequest(aRequest, aCtxt, aStatus);

View File

@ -950,7 +950,7 @@ void HTMLContentSink::SetDocumentCharset(NotNull<const Encoding*> aEncoding) {
MOZ_ASSERT_UNREACHABLE("<meta charset> case doesn't occur with about:blank");
}
nsISupports* HTMLContentSink::GetTarget() { return mDocument; }
nsISupports* HTMLContentSink::GetTarget() { return ToSupports(mDocument); }
bool HTMLContentSink::IsScriptExecuting() { return IsScriptExecutingImpl(); }

View File

@ -444,7 +444,7 @@ TabChild::Observe(nsISupports* aSubject, const char* aTopic,
nsCOMPtr<nsIDocument> subject(do_QueryInterface(aSubject));
nsCOMPtr<nsIDocument> doc(GetDocument());
if (SameCOMIdentity(subject, doc)) {
if (subject == doc) {
nsCOMPtr<nsIPresShell> shell(doc->GetShell());
if (shell) {
shell->SetIsFirstPaint(true);

View File

@ -709,7 +709,8 @@ void XMLHttpRequestMainThread::GetResponse(
return;
}
aRv = nsContentUtils::WrapNative(aCx, mResponseXML, aResponse);
aRv =
nsContentUtils::WrapNative(aCx, ToSupports(mResponseXML), aResponse);
return;
}
case XMLHttpRequestResponseType::Json: {

View File

@ -545,7 +545,7 @@ void XMLDocument::EndLoad() {
// document was loaded as pure data without any presentation
// attached to it.
WidgetEvent event(true, eLoad);
EventDispatcher::Dispatch(static_cast<nsIDocument*>(this), nullptr, &event);
EventDispatcher::Dispatch(ToSupports(this), nullptr, &event);
}
}

View File

@ -737,7 +737,7 @@ void nsXMLContentSink::SetDocumentCharset(NotNull<const Encoding*> aEncoding) {
}
}
nsISupports* nsXMLContentSink::GetTarget() { return mDocument; }
nsISupports* nsXMLContentSink::GetTarget() { return ToSupports(mDocument); }
bool nsXMLContentSink::IsScriptExecuting() { return IsScriptExecutingImpl(); }

View File

@ -168,7 +168,9 @@ void nsXMLFragmentContentSink::SetDocumentCharset(
MOZ_ASSERT_UNREACHABLE("fragments shouldn't set charset");
}
nsISupports* nsXMLFragmentContentSink::GetTarget() { return mTargetDocument; }
nsISupports* nsXMLFragmentContentSink::GetTarget() {
return ToSupports(mTargetDocument);
}
////////////////////////////////////////////////////////////////////////

View File

@ -989,9 +989,8 @@ nsresult XULDocument::DoneWalking() {
mDocumentL10n, true, false);
nsContentUtils::DispatchTrustedEvent(
this, static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("MozBeforeInitialXULLayout"), CanBubble::eYes,
Cancelable::eNo);
this, ToSupports(this), NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
CanBubble::eYes, Cancelable::eNo);
RemoveEventListener(NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
mDocumentL10n, true);

View File

@ -232,7 +232,7 @@ void XULContentSinkImpl::SetDocumentCharset(
nsISupports* XULContentSinkImpl::GetTarget() {
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
return doc;
return ToSupports(doc);
}
//----------------------------------------------------------------------

View File

@ -2155,11 +2155,11 @@ nsresult imgLoader::LoadImage(
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
bool newChannelCreated = false;
if (ValidateEntry(entry, aURI, aInitialDocumentURI, aReferrerURI,
aReferrerPolicy, aLoadGroup, aObserver, aLoadingDocument,
aLoadingDocument, requestFlags, aContentPolicyType, true,
&newChannelCreated, _retval, aTriggeringPrincipal,
corsmode)) {
if (ValidateEntry(
entry, aURI, aInitialDocumentURI, aReferrerURI, aReferrerPolicy,
aLoadGroup, aObserver, ToSupports(aLoadingDocument),
aLoadingDocument, requestFlags, aContentPolicyType, true,
&newChannelCreated, _retval, aTriggeringPrincipal, corsmode)) {
request = entry->GetRequest();
// If this entry has no proxies, its request has no reference to the
@ -2185,9 +2185,10 @@ nsresult imgLoader::LoadImage(
// - we don't have cache. We are not in this if() stmt. A new channel is
// created and that triggers the CSP checks.
// - We have a cache entry and this is blocked by CSP directives.
DebugOnly<bool> shouldLoad = ShouldLoadCachedImage(
request, aLoadingDocument, aTriggeringPrincipal, aContentPolicyType,
/* aSendCSPViolationReports */ true);
DebugOnly<bool> shouldLoad =
ShouldLoadCachedImage(request, ToSupports(aLoadingDocument),
aTriggeringPrincipal, aContentPolicyType,
/* aSendCSPViolationReports */ true);
MOZ_ASSERT(shouldLoad);
}
} else {
@ -2244,8 +2245,9 @@ nsresult imgLoader::LoadImage(
nsCOMPtr<nsILoadGroup> channelLoadGroup;
newChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup));
rv = request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false,
channelLoadGroup, newChannel, entry, aLoadingDocument,
aTriggeringPrincipal, corsmode, aReferrerPolicy);
channelLoadGroup, newChannel, entry,
ToSupports(aLoadingDocument), aTriggeringPrincipal,
corsmode, aReferrerPolicy);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}

View File

@ -157,12 +157,12 @@ static nsRect GetBoxRectForFrame(nsIFrame** aFrame, CSSBoxType aType) {
class AccumulateQuadCallback : public nsLayoutUtils::BoxCallback {
public:
AccumulateQuadCallback(nsISupports* aParentObject,
AccumulateQuadCallback(nsIDocument* aParentObject,
nsTArray<RefPtr<DOMQuad> >& aResult,
nsIFrame* aRelativeToFrame,
const nsPoint& aRelativeToBoxTopLeft,
CSSBoxType aBoxType)
: mParentObject(aParentObject),
: mParentObject(ToSupports(aParentObject)),
mResult(aResult),
mRelativeToFrame(aRelativeToFrame),
mRelativeToBoxTopLeft(aRelativeToBoxTopLeft),

View File

@ -159,7 +159,7 @@ MobileViewportManager::HandleEvent(dom::Event* event) {
NS_IMETHODIMP
MobileViewportManager::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (SameCOMIdentity(aSubject, mDocument) &&
if (SameCOMIdentity(aSubject, ToSupports(mDocument)) &&
BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) {
MVM_LOG("%p: got a before-first-paint event\n", this);
if (!mPainted) {

View File

@ -520,8 +520,8 @@ class nsBeforeFirstPaintDispatcher : public Runnable {
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(mDocument, "before-first-paint",
nullptr);
observerService->NotifyObservers(ToSupports(mDocument),
"before-first-paint", nullptr);
}
return NS_OK;
}
@ -1444,7 +1444,7 @@ void nsIPresShell::SetAuthorStyleDisabled(bool aStyleDisabled) {
mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(
mDocument, "author-style-disabled-changed", nullptr);
ToSupports(mDocument), "author-style-disabled-changed", nullptr);
}
}
}

View File

@ -144,7 +144,7 @@ ZoomConstraintsClient::HandleEvent(dom::Event* event) {
NS_IMETHODIMP
ZoomConstraintsClient::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (SameCOMIdentity(aSubject, mDocument) &&
if (SameCOMIdentity(aSubject, ToSupports(mDocument)) &&
BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) {
ZCC_LOG("Got a before-first-paint event in %p\n", this);
RefreshZoomConstraints();

View File

@ -1086,7 +1086,7 @@ nsDocumentViewer::LoadComplete(nsresult aStatus) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
nsIPrincipal* principal = d->NodePrincipal();
os->NotifyObservers(d,
os->NotifyObservers(ToSupports(d),
nsContentUtils::IsSystemPrincipal(principal)
? "chrome-document-loaded"
: "content-document-loaded",
@ -2852,9 +2852,9 @@ nsDocumentViewer::SetTextZoom(float aTextZoom) {
// Dispatch TextZoomChange event only if text zoom value has changed.
if (textZoomChange) {
nsContentUtils::DispatchChromeEvent(
mDocument, static_cast<nsIDocument*>(mDocument),
NS_LITERAL_STRING("TextZoomChange"), CanBubble::eYes, Cancelable::eYes);
nsContentUtils::DispatchChromeEvent(mDocument, ToSupports(mDocument),
NS_LITERAL_STRING("TextZoomChange"),
CanBubble::eYes, Cancelable::eYes);
}
return NS_OK;
@ -2969,9 +2969,9 @@ nsDocumentViewer::SetFullZoom(float aFullZoom) {
// Dispatch FullZoomChange event only if fullzoom value really was been
// changed
if (fullZoomChange) {
nsContentUtils::DispatchChromeEvent(
mDocument, static_cast<nsIDocument*>(mDocument),
NS_LITERAL_STRING("FullZoomChange"), CanBubble::eYes, Cancelable::eYes);
nsContentUtils::DispatchChromeEvent(mDocument, ToSupports(mDocument),
NS_LITERAL_STRING("FullZoomChange"),
CanBubble::eYes, Cancelable::eYes);
}
return NS_OK;
@ -4382,7 +4382,8 @@ nsDocumentShownDispatcher::Run() {
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(mDocument, "document-shown", nullptr);
observerService->NotifyObservers(ToSupports(mDocument), "document-shown",
nullptr);
}
return NS_OK;
}

View File

@ -8572,8 +8572,8 @@ void MaybeSetupTransactionIdAllocator(layers::LayerManager* aManager,
if (nsIDocument* doc = aShell->GetDocument()) {
WidgetEvent event(true, eVoidEvent);
nsTArray<EventTarget*> targets;
nsresult rv = EventDispatcher::Dispatch(doc, nullptr, &event, nullptr,
nullptr, nullptr, &targets);
nsresult rv = EventDispatcher::Dispatch(
ToSupports(doc), nullptr, &event, nullptr, nullptr, nullptr, &targets);
NS_ENSURE_SUCCESS(rv, false);
for (size_t i = 0; i < targets.Length(); i++) {
if (targets[i]->IsApzAware()) {

View File

@ -4914,9 +4914,9 @@ void ScrollFrameHelper::FireScrollEvent() {
mozilla::layers::ScrollLinkedEffectDetector detector(
content->GetComposedDoc());
if (mIsRoot) {
nsIDocument* doc = content->GetUncomposedDoc();
if (doc) {
EventDispatcher::Dispatch(doc, prescontext, &event, nullptr, &status);
if (nsIDocument* doc = content->GetUncomposedDoc()) {
EventDispatcher::Dispatch(ToSupports(doc), prescontext, &event, nullptr,
&status);
}
} else {
// scroll events fired at elements don't bubble (although scroll events
@ -6195,10 +6195,8 @@ void ScrollFrameHelper::FireScrolledAreaEvent() {
nsIContent* content = mOuter->GetContent();
event.mArea = mScrolledFrame->GetScrollableOverflowRectRelativeToParent();
nsIDocument* doc = content->GetUncomposedDoc();
if (doc) {
EventDispatcher::Dispatch(doc, prescontext, &event, nullptr);
if (nsIDocument* doc = content->GetUncomposedDoc()) {
EventDispatcher::Dispatch(ToSupports(doc), prescontext, &event, nullptr);
}
}

View File

@ -143,7 +143,9 @@ void MediaQueryList::RecomputeMatches() {
mMatchesValid = true;
}
nsISupports* MediaQueryList::GetParentObject() const { return mDocument; }
nsISupports* MediaQueryList::GetParentObject() const {
return ToSupports(mDocument);
}
JSObject* MediaQueryList::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {

View File

@ -234,7 +234,9 @@ void nsHtml5TreeOpExecutor::FlushPendingNotifications(FlushType aType) {
}
}
nsISupports* nsHtml5TreeOpExecutor::GetTarget() { return mDocument; }
nsISupports* nsHtml5TreeOpExecutor::GetTarget() {
return ToSupports(mDocument);
}
nsresult nsHtml5TreeOpExecutor::MarkAsBroken(nsresult aReason) {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");

View File

@ -887,7 +887,7 @@ nsWebBrowser::SaveDocument(nsISupports* aDocumentish, nsISupports* aFile,
} else {
nsCOMPtr<nsIDocument> domDoc;
GetDocument(getter_AddRefs(domDoc));
doc = domDoc.forget();
doc = already_AddRefed<nsISupports>(ToSupports(domDoc.forget().take()));
}
if (!doc) {
return NS_ERROR_FAILURE;

View File

@ -134,12 +134,8 @@ nsresult OfflineCacheUpdateChild::AssociateDocument(
// Check that the document that requested this update was
// previously associated with an application cache. If not, it
// should be associated with the new one.
nsCOMPtr<nsIApplicationCacheContainer> container =
do_QueryInterface(aDocument);
if (!container) return NS_OK;
nsCOMPtr<nsIApplicationCache> existingCache;
nsresult rv = container->GetApplicationCache(getter_AddRefs(existingCache));
nsresult rv = aDocument->GetApplicationCache(getter_AddRefs(existingCache));
NS_ENSURE_SUCCESS(rv, rv);
if (!existingCache) {
@ -152,7 +148,7 @@ nsresult OfflineCacheUpdateChild::AssociateDocument(
clientID.get(), aDocument));
}
rv = container->SetApplicationCache(aApplicationCache);
rv = aDocument->SetApplicationCache(aApplicationCache);
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@ -183,12 +183,12 @@ OfflineCacheUpdateGlue::ApplicationCacheAvailable(
// Check that the document that requested this update was
// previously associated with an application cache. If not, it
// should be associated with the new one.
nsCOMPtr<nsIApplicationCacheContainer> container =
do_QueryInterface(mDocument);
if (!container) return NS_OK;
if (!mDocument) {
return NS_OK;
}
nsCOMPtr<nsIApplicationCache> existingCache;
nsresult rv = container->GetApplicationCache(getter_AddRefs(existingCache));
nsresult rv = mDocument->GetApplicationCache(getter_AddRefs(existingCache));
NS_ENSURE_SUCCESS(rv, rv);
if (!existingCache) {
@ -201,7 +201,7 @@ OfflineCacheUpdateGlue::ApplicationCacheAvailable(
clientID.get(), mDocument.get()));
}
rv = container->SetApplicationCache(aApplicationCache);
rv = mDocument->SetApplicationCache(aApplicationCache);
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@ -166,9 +166,7 @@ nsOfflineCachePendingUpdate::OnStateChange(nsIWebProgress *aWebProgress,
nsPIDOMWindowInner *innerWindow = outerWindow->GetCurrentInnerWindow();
nsCOMPtr<nsIDocument> progressDoc = outerWindow->GetDoc();
if (!progressDoc) return NS_OK;
if (!SameCOMIdentity(progressDoc, updateDoc)) {
if (!progressDoc || progressDoc != updateDoc) {
return NS_OK;
}

View File

@ -649,8 +649,7 @@ NS_IMETHODIMP nsContentTreeOwner::SetTitle(const nsAString& aTitle) {
//
nsCOMPtr<nsIDocShellTreeItem> dsitem;
GetPrimaryContentShell(getter_AddRefs(dsitem));
nsCOMPtr<nsIScriptObjectPrincipal> doc =
do_QueryInterface(dsitem ? dsitem->GetDocument() : nullptr);
nsCOMPtr<nsIDocument> doc = dsitem ? dsitem->GetDocument() : nullptr;
if (doc) {
nsCOMPtr<nsIURI> uri;
nsIPrincipal* principal = doc->GetPrincipal();