Bug 1323950 - Use MOZ_MUST_USE in netwerk/protocol/wyciwyg r?valentin
MozReview-Commit-ID: 6P4XIXnxGbm
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -488,18 +488,20 @@ nsHTMLDocument::TryFallback(int32_t& aCh
void
nsHTMLDocument::SetDocumentCharacterSet(const nsACString& aCharSetID)
{
nsDocument::SetDocumentCharacterSet(aCharSetID);
// Make sure to stash this charset on our channel as needed if it's a wyciwyg
// channel.
nsCOMPtr<nsIWyciwygChannel> wyciwygChannel = do_QueryInterface(mChannel);
if (wyciwygChannel) {
- wyciwygChannel->SetCharsetAndSource(GetDocumentCharacterSetSource(),
- aCharSetID);
+ DebugOnly<nsresult> rv =
+ wyciwygChannel->SetCharsetAndSource(GetDocumentCharacterSetSource(),
+ aCharSetID);
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
}
}
nsresult
nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
@@ -1882,21 +1884,27 @@ nsHTMLDocument::WriteCommon(JSContext *c
"Open() succeeded but JS exception is pending");
}
static NS_NAMED_LITERAL_STRING(new_line, "\n");
// Save the data in cache if the write isn't from within the doc
if (mWyciwygChannel && !key) {
if (!aText.IsEmpty()) {
- mWyciwygChannel->WriteToCacheEntry(aText);
+ rv = mWyciwygChannel->WriteToCacheEntry(aText);
+ if (NS_FAILED(rv)) {
+ NS_WARNING("failed to write cache entry");
+ }
}
if (aNewlineTerminate) {
- mWyciwygChannel->WriteToCacheEntry(new_line);
+ rv = mWyciwygChannel->WriteToCacheEntry(new_line);
+ if (NS_FAILED(rv)) {
+ NS_WARNING("failed to write cache entry");
+ }
}
}
++mWriteLevel;
// This could be done with less code, but for performance reasons it
// makes sense to have the code for two separate Parse() calls here
// since the concatenation of strings costs more than we like. And
@@ -2313,23 +2321,27 @@ nsHTMLDocument::CreateAndAddWyciwygChann
nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL,
nsIContentPolicy::TYPE_OTHER);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
loadInfo->SetPrincipalToInherit(NodePrincipal());
mWyciwygChannel = do_QueryInterface(channel);
- mWyciwygChannel->SetSecurityInfo(mSecurityInfo);
+ rv = mWyciwygChannel->SetSecurityInfo(mSecurityInfo);
+ if (NS_FAILED(rv)) {
+ NS_WARNING("failed to set securityinfo to the wyciwyg channel");
+ }
// Note: we want to treat this like a "previous document" hint so that,
// e.g. a <meta> tag in the document.write content can override it.
SetDocumentCharacterSetSource(kCharsetFromHintPrevDoc);
- mWyciwygChannel->SetCharsetAndSource(kCharsetFromHintPrevDoc,
- GetDocumentCharacterSet());
+ rv = mWyciwygChannel->SetCharsetAndSource(kCharsetFromHintPrevDoc,
+ GetDocumentCharacterSet());
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
// Inherit load flags from the original document's channel
channel->SetLoadFlags(mLoadFlags);
nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
// Use the Parent document's loadgroup to trigger load notifications
if (loadGroup && channel) {
@@ -2353,17 +2365,21 @@ nsHTMLDocument::CreateAndAddWyciwygChann
nsresult
nsHTMLDocument::RemoveWyciwygChannel(void)
{
nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
// note there can be a write request without a load group if
// this is a synchronously constructed about:blank document
if (loadGroup && mWyciwygChannel) {
- mWyciwygChannel->CloseCacheEntry(NS_OK);
+ nsresult rv = mWyciwygChannel->CloseCacheEntry(NS_OK);
+ if (NS_FAILED(rv)) {
+ NS_WARNING("nsHTMLDocument::RemoveWyciwygChannel "
+ "failed to close cache entry");
+ }
loadGroup->RemoveRequest(mWyciwygChannel, nullptr, NS_OK);
}
mWyciwygChannel = nullptr;
return NS_OK;
}
--- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.h
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.h
@@ -46,17 +46,17 @@ public:
NS_DECL_NSICHANNEL
NS_DECL_NSIWYCIWYGCHANNEL
WyciwygChannelChild();
void AddIPDLReference();
void ReleaseIPDLReference();
- nsresult Init(nsIURI *uri);
+ MOZ_MUST_USE nsresult Init(nsIURI *uri);
bool IsSuspended();
protected:
virtual ~WyciwygChannelChild();
mozilla::ipc::IPCResult RecvOnStartRequest(const nsresult& statusCode,
const int64_t& contentLength,
--- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
@@ -253,49 +253,61 @@ WyciwygChannelParent::RecvAsyncOpen(cons
mozilla::ipc::IPCResult
WyciwygChannelParent::RecvWriteToCacheEntry(const nsString& data)
{
if (!mReceivedAppData) {
printf_stderr("WyciwygChannelParent::RecvWriteToCacheEntry: FATAL ERROR: didn't receive app data\n");
return IPC_FAIL_NO_REASON(this);
}
- if (mChannel)
- mChannel->WriteToCacheEntry(data);
+ if (mChannel) {
+ nsresult rv = mChannel->WriteToCacheEntry(data);
+ if (NS_FAILED(rv)) {
+ LOG(("WyciwygChannelParent::RecvWriteToCacheEntry: WARNING: failed to write cache entry\n"));
+ }
+ }
return IPC_OK();
}
mozilla::ipc::IPCResult
WyciwygChannelParent::RecvCloseCacheEntry(const nsresult& reason)
{
if (mChannel) {
- mChannel->CloseCacheEntry(reason);
+ nsresult rv = mChannel->CloseCacheEntry(reason);
+ if (NS_FAILED(rv)) {
+ LOG(("WyciwygChannelParent::RecvCloseCacheEntry: WARNING: failed to close cache entry\n"));
+ }
}
return IPC_OK();
}
mozilla::ipc::IPCResult
WyciwygChannelParent::RecvSetCharsetAndSource(const int32_t& aCharsetSource,
const nsCString& aCharset)
{
- if (mChannel)
- mChannel->SetCharsetAndSource(aCharsetSource, aCharset);
+ if (mChannel) {
+ DebugOnly<nsresult> rv = mChannel->SetCharsetAndSource(aCharsetSource, aCharset);
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
+ }
return IPC_OK();
}
mozilla::ipc::IPCResult
WyciwygChannelParent::RecvSetSecurityInfo(const nsCString& aSecurityInfo)
{
if (mChannel) {
nsCOMPtr<nsISupports> securityInfo;
NS_DeserializeObject(aSecurityInfo, getter_AddRefs(securityInfo));
- mChannel->SetSecurityInfo(securityInfo);
+ nsresult rv = mChannel->SetSecurityInfo(securityInfo);
+ if (NS_FAILED(rv)) {
+ LOG(("WyciwygChannelParent::RecvSetSecurityInfo: WARNING: failed to set security info\n"));
+ }
}
return IPC_OK();
}
mozilla::ipc::IPCResult
WyciwygChannelParent::RecvCancel(const nsresult& aStatusCode)
{
@@ -321,17 +333,20 @@ WyciwygChannelParent::OnStartRequest(nsI
nsresult status;
chan->GetStatus(&status);
int64_t contentLength = -1;
chan->GetContentLength(&contentLength);
int32_t charsetSource = kCharsetUninitialized;
nsAutoCString charset;
- chan->GetCharsetAndSource(&charsetSource, charset);
+ rv = chan->GetCharsetAndSource(&charsetSource, charset);
+ if (NS_FAILED(rv)) {
+ LOG(("failed to get charset and source (0x%08x)\n", rv));
+ }
nsCOMPtr<nsISupports> securityInfo;
chan->GetSecurityInfo(getter_AddRefs(securityInfo));
nsCString secInfoStr;
if (securityInfo) {
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(securityInfo);
if (serializable)
NS_SerializeToString(serializable, secInfoStr);
--- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.h
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.h
@@ -51,18 +51,18 @@ protected:
const nsCString& charset) override;
virtual mozilla::ipc::IPCResult RecvSetSecurityInfo(const nsCString& securityInfo) override;
virtual mozilla::ipc::IPCResult RecvCancel(const nsresult& statusCode) override;
virtual mozilla::ipc::IPCResult RecvAppData(const IPC::SerializedLoadContext& loadContext,
const PBrowserOrId &parent) override;
virtual void ActorDestroy(ActorDestroyReason why) override;
- bool SetupAppData(const IPC::SerializedLoadContext& loadContext,
- const PBrowserOrId &aParent);
+ MOZ_MUST_USE bool SetupAppData(const IPC::SerializedLoadContext& loadContext,
+ const PBrowserOrId &aParent);
nsCOMPtr<nsIWyciwygChannel> mChannel;
bool mIPCClosed;
bool mReceivedAppData;
nsCOMPtr<nsILoadContext> mLoadContext;
};
} // namespace net
--- a/netwerk/protocol/wyciwyg/nsIWyciwygChannel.idl
+++ b/netwerk/protocol/wyciwyg/nsIWyciwygChannel.idl
@@ -13,33 +13,33 @@
*/
[scriptable, uuid (8b8f3341-46da-40f5-a16f-41a91f5d25dd)]
interface nsIWyciwygChannel : nsIChannel
{
/**
* Append data to the cache entry; opens the cache entry if necessary.
*/
- void writeToCacheEntry(in AString aData);
+ [must_use] void writeToCacheEntry(in AString aData);
/**
* Close the cache entry; subsequent writes have undefined behavior.
*/
- void closeCacheEntry(in nsresult reason);
+ [must_use] void closeCacheEntry(in nsresult reason);
/**
* Set the wyciwyg channels security info
*/
- void setSecurityInfo(in nsISupports aSecurityInfo);
+ [must_use] void setSecurityInfo(in nsISupports aSecurityInfo);
/**
* Store and read a charset and charset source on the wyciwyg channel. These
* are opaque values to the channel; consumers who set them should know what
* they mean.
*/
- void setCharsetAndSource(in long aSource, in ACString aCharset);
+ [must_use] void setCharsetAndSource(in long aSource, in ACString aCharset);
/**
* The return value is the charset. Throws if either the charset or the
* source cannot be retrieved. This is guaranteed to return a nonzero source
* and a nonempty charset if it does not throw.
*/
- ACString getCharsetAndSource(out long aSource);
+ [must_use] ACString getCharsetAndSource(out long aSource);
};
--- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
+++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
@@ -60,31 +60,37 @@ public:
class nsWyciwygWriteEvent : public nsWyciwygAsyncEvent {
public:
nsWyciwygWriteEvent(nsWyciwygChannel *aChannel, const nsAString &aData)
: nsWyciwygAsyncEvent(aChannel), mData(aData) {}
NS_IMETHOD Run() override
{
- mChannel->WriteToCacheEntryInternal(mData);
+ nsresult rv = mChannel->WriteToCacheEntryInternal(mData);
+ if (NS_FAILED(rv)) {
+ LOG(("WriteToCacheEntryInternal failed (0x%08x)\n", rv));
+ }
return NS_OK;
}
private:
nsString mData;
};
class nsWyciwygCloseEvent : public nsWyciwygAsyncEvent {
public:
nsWyciwygCloseEvent(nsWyciwygChannel *aChannel, nsresult aReason)
: nsWyciwygAsyncEvent(aChannel), mReason(aReason) {}
NS_IMETHOD Run() override
{
- mChannel->CloseCacheEntryInternal(mReason);
+ nsresult rv = mChannel->CloseCacheEntryInternal(mReason);
+ if (NS_FAILED(rv)) {
+ LOG(("CloseCacheEntryInternal failed (0x%08x)\n", rv));
+ }
return NS_OK;
}
private:
nsresult mReason;
};
// nsWyciwygChannel methods
@@ -690,17 +696,20 @@ nsWyciwygChannel::OnCacheEntryAvailable(
rv = mStatus;
}
else if (!aNew) { // advance to the next state...
rv = ReadFromCache();
}
// a failure from Connect means that we have to abort the channel.
if (NS_FAILED(rv)) {
- CloseCacheEntry(rv);
+ rv = CloseCacheEntry(rv);
+ if (NS_FAILED(rv)) {
+ LOG(("failed close cache entry [this=%p rv=%x]\n", this, rv));
+ }
if (!aNew) {
// Since OnCacheEntryAvailable can be called directly from AsyncOpen
// we must dispatch.
NS_DispatchToCurrentThread(mozilla::NewRunnableMethod(
this, &nsWyciwygChannel::NotifyListener));
}
}
@@ -757,17 +766,20 @@ nsWyciwygChannel::OnStopRequest(nsIReque
mListener->OnStopRequest(this, mListenerContext, mStatus);
mListener = nullptr;
mListenerContext = nullptr;
if (mLoadGroup)
mLoadGroup->RemoveRequest(this, nullptr, mStatus);
- CloseCacheEntry(mStatus);
+ nsresult rv = CloseCacheEntry(mStatus);
+ if (NS_FAILED(rv)) {
+ LOG(("failed to close cache entry (0x%08x)\n", rv));
+ }
mPump = nullptr;
mIsPending = false;
// Drop notification callbacks to prevent cycles.
mCallbacks = nullptr;
mProgressSink = nullptr;
return NS_OK;
--- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.h
+++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.h
@@ -46,28 +46,28 @@ public:
friend class nsWyciwygSetCharsetandSourceEvent;
friend class nsWyciwygWriteEvent;
friend class nsWyciwygCloseEvent;
// nsWyciwygChannel methods:
nsWyciwygChannel();
- nsresult Init(nsIURI *uri);
+ MOZ_MUST_USE nsresult Init(nsIURI *uri);
protected:
virtual ~nsWyciwygChannel();
- nsresult WriteToCacheEntryInternal(const nsAString& aData);
+ MOZ_MUST_USE nsresult WriteToCacheEntryInternal(const nsAString& aData);
void SetCharsetAndSourceInternal();
- nsresult CloseCacheEntryInternal(nsresult reason);
+ MOZ_MUST_USE nsresult CloseCacheEntryInternal(nsresult reason);
- nsresult ReadFromCache();
- nsresult EnsureWriteCacheEntry();
- nsresult OpenCacheEntry(nsIURI *aURI, uint32_t aOpenFlags);
+ MOZ_MUST_USE nsresult ReadFromCache();
+ MOZ_MUST_USE nsresult EnsureWriteCacheEntry();
+ MOZ_MUST_USE nsresult OpenCacheEntry(nsIURI *aURI, uint32_t aOpenFlags);
void WriteCharsetAndSourceToCache(int32_t aSource,
const nsCString& aCharset);
void NotifyListener();
bool IsOnCacheIOThread();
friend class mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>;