From 2c7c5a81f0bd0caabb6e1166cdca8d20b97aa20a Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 22 Mar 2021 20:12:16 +0000 Subject: [PATCH] Bug 1581859: Part 3b - Update existing GetPropertyAsInterface callers to use typesafe do_GetProperty instead. r=mccr8,necko-reviewers Differential Revision: https://phabricator.services.mozilla.com/D103211 --- docshell/base/nsDocShell.cpp | 19 ++++++++-------- dom/base/Document.cpp | 10 +++------ dom/base/nsGlobalWindowOuter.cpp | 22 +++++++------------ netwerk/base/nsNetUtil.cpp | 10 ++++----- .../extensions/webrequest/ChannelWrapper.cpp | 5 +---- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index a08c0c45f2a6..0a87890c5f6a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -12240,22 +12240,23 @@ nsDocShell::MakeEditable(bool aInWaitForUriLoad) { return; } - nsresult rv = props->GetPropertyAsInterface(u"docshell.previousURI"_ns, - NS_GET_IID(nsIURI), - reinterpret_cast(aURI)); + nsresult rv; + nsCOMPtr uri(do_GetProperty(props, u"docshell.previousURI"_ns, &rv)); + if (NS_SUCCEEDED(rv)) { + uri.forget(aURI); - if (NS_FAILED(rv)) { - // There is no last visit for this channel, so this must be the first - // link. Link the visit to the referrer of this request, if any. - // Treat referrer as null if there is an error getting it. - (void)NS_GetReferrerFromChannel(aChannel, aURI); - } else { rv = props->GetPropertyAsUint32(u"docshell.previousFlags"_ns, aChannelRedirectFlags); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "Could not fetch previous flags, URI will be treated like referrer"); + + } else { + // There is no last visit for this channel, so this must be the first + // link. Link the visit to the referrer of this request, if any. + // Treat referrer as null if there is an error getting it. + NS_GetReferrerFromChannel(aChannel, aURI); } } diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 43c79bb5ca54..23438e1bd41f 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -2698,13 +2698,9 @@ void Document::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) { // timeline will have the same global clock time as the old one. mDocumentTimeline = nullptr; - nsCOMPtr bag = do_QueryInterface(aChannel); - if (bag) { - nsCOMPtr baseURI; - bag->GetPropertyAsInterface(u"baseURI"_ns, NS_GET_IID(nsIURI), - getter_AddRefs(baseURI)); - if (baseURI) { - mDocumentBaseURI = baseURI; + if (nsCOMPtr bag = do_QueryInterface(aChannel)) { + if (nsCOMPtr baseURI = do_GetProperty(bag, u"baseURI"_ns)) { + mDocumentBaseURI = baseURI.forget(); mChromeXHRDocBaseURI = nullptr; } } diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 653c8c03fbdc..a81eab2727bb 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -1257,21 +1257,15 @@ already_AddRefed nsOuterWindowProxy::GetNoPDFJSPrincipal( return nullptr; } - Document* doc = inner->GetExtantDoc(); - if (!doc) { - return nullptr; + if (Document* doc = inner->GetExtantDoc()) { + if (nsCOMPtr propBag = + do_QueryInterface(doc->GetChannel())) { + nsCOMPtr principal( + do_GetProperty(propBag, u"noPDFJSPrincipal"_ns)); + return principal.forget(); + } } - - nsCOMPtr propBag(do_QueryInterface(doc->GetChannel())); - if (!propBag) { - return nullptr; - } - - nsCOMPtr principal; - propBag->GetPropertyAsInterface(u"noPDFJSPrincipal"_ns, - NS_GET_IID(nsIPrincipal), - getter_AddRefs(principal)); - return principal.forget(); + return nullptr; } const nsOuterWindowProxy nsOuterWindowProxy::singleton; diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 59a0dca87f5f..6511d11edd1a 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -1167,15 +1167,15 @@ nsresult NS_GetURLSpecFromDir(nsIFile* file, nsACString& url, void NS_GetReferrerFromChannel(nsIChannel* channel, nsIURI** referrer) { *referrer = nullptr; - nsCOMPtr props(do_QueryInterface(channel)); - if (props) { + if (nsCOMPtr props = do_QueryInterface(channel)) { // We have to check for a property on a property bag because the // referrer may be empty for security reasons (for example, when loading // an http page with an https referrer). - nsresult rv = props->GetPropertyAsInterface( - u"docshell.internalReferrer"_ns, NS_GET_IID(nsIURI), - reinterpret_cast(referrer)); + nsresult rv; + nsCOMPtr uri( + do_GetProperty(props, u"docshell.internalReferrer"_ns, &rv)); if (NS_SUCCEEDED(rv)) { + uri.forget(referrer); return; } } diff --git a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp index 6dc55356edb9..af82ab3e3fe7 100644 --- a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp +++ b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp @@ -145,10 +145,7 @@ already_AddRefed ChannelWrapper::Get(const GlobalObject& global, nsCOMPtr props = do_QueryInterface(channel); if (props) { - Unused << props->GetPropertyAsInterface(CHANNELWRAPPER_PROP_KEY, - NS_GET_IID(ChannelWrapper), - getter_AddRefs(wrapper)); - + wrapper = do_GetProperty(props, CHANNELWRAPPER_PROP_KEY); if (wrapper) { // Assume cached attributes may have changed at this point. wrapper->ClearCachedAttributes();