fune/netwerk/protocol/viewsource/nsViewSourceChannel.h
Valentin Gosu 1a1f42da37 Bug 1714307 - Run modernize-use-default-member-init --fix check on netwerk r=necko-reviewers,kershaw
This changeset is the result of adding modernize-use-default-member-init to
tools/clang-tidy/config.yaml then proceeding to run
`./mach static-analysis check netwerk/ --fix`
I then went through the resulting fix and manually updated all of the member
variables which were missed due to them having a non-trivial constructor.

Note that the tool was only run on Linux, so code that only runs on some
platforms may have been missed.

The member variables that are still initialized in the contructor definition
are:
  - bitfields (not all currently supported compilers allow default-member-init
  - variables that are initialized via a parameter
  - variables that use code not visible in the header file

There are a few advantages to landing this change:
- fewer lines of code - now declaration is in the same place as initialization
  this also makes it easier to see when looking at the header.
- it makes it harder to miss initializing a member when adding a new contructor
- variables that depend on an include guard look much nicer now

Additionally I removed some unnecessary reinitialization of NetAddr members
(it has a constructor that does that now), and changed nsWifiScannerDBus to
use the thread-safe strtok_r instead of strtok.

Differential Revision: https://phabricator.services.mozilla.com/D116980
2021-06-11 07:10:41 +00:00

98 lines
3.7 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsViewSourceChannel_h___
#define nsViewSourceChannel_h___
#include "mozilla/Attributes.h"
#include "mozilla/net/NeckoChannelParams.h"
#include "nsCOMPtr.h"
#include "nsICachingChannel.h"
#include "nsIChannelEventSink.h"
#include "nsIFormPOSTActionChannel.h"
#include "nsIHttpChannel.h"
#include "nsIHttpChannelInternal.h"
#include "nsIInterfaceRequestor.h"
#include "nsIStreamListener.h"
#include "nsIURI.h"
#include "nsIViewSourceChannel.h"
#include "nsIChildChannel.h"
#include "nsString.h"
class nsViewSourceChannel final : public nsIViewSourceChannel,
public nsIStreamListener,
public nsIHttpChannel,
public nsIHttpChannelInternal,
public nsICachingChannel,
public nsIFormPOSTActionChannel,
public nsIChildChannel,
public nsIInterfaceRequestor,
public nsIChannelEventSink {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIIDENTCHANNEL
NS_DECL_NSIVIEWSOURCECHANNEL
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIHTTPCHANNEL
NS_DECL_NSICHILDCHANNEL
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICHANNELEVENTSINK
NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel)
NS_FORWARD_SAFE_NSICACHINGCHANNEL(mCachingChannel)
NS_FORWARD_SAFE_NSIUPLOADCHANNEL(mUploadChannel)
NS_FORWARD_SAFE_NSIFORMPOSTACTIONCHANNEL(mPostChannel)
NS_FORWARD_SAFE_NSIHTTPCHANNELINTERNAL(mHttpChannelInternal)
// nsViewSourceChannel methods:
nsViewSourceChannel() = default;
[[nodiscard]] nsresult Init(nsIURI* uri, nsILoadInfo* aLoadInfo);
[[nodiscard]] nsresult InitSrcdoc(nsIURI* aURI, nsIURI* aBaseURI,
const nsAString& aSrcdoc,
nsILoadInfo* aLoadInfo);
// Updates or sets the result principal URI of the underlying channel's
// loadinfo to be prefixed with the "view-source:" schema as:
//
// mChannel.loadInfo.resultPrincipalURI = "view-source:" +
// (mChannel.loadInfo.resultPrincipalURI | mChannel.orignalURI);
nsresult UpdateLoadInfoResultPrincipalURI();
protected:
~nsViewSourceChannel() = default;
void ReleaseListeners();
nsTArray<mozilla::net::PreferredAlternativeDataTypeParams> mEmptyArray;
// Clones aURI and prefixes it with "view-source:" schema,
nsresult BuildViewSourceURI(nsIURI* aURI, nsIURI** aResult);
// Called to update the forwarding channel members after the `mChannel` field
// has been changed to reflect the new inner channel.
void UpdateChannelInterfaces();
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsIChannel> mChannel;
nsCOMPtr<nsIHttpChannel> mHttpChannel;
nsCOMPtr<nsIHttpChannelInternal> mHttpChannelInternal;
nsCOMPtr<nsICachingChannel> mCachingChannel;
nsCOMPtr<nsICacheInfoChannel> mCacheInfoChannel;
nsCOMPtr<nsIUploadChannel> mUploadChannel;
nsCOMPtr<nsIFormPOSTActionChannel> mPostChannel;
nsCOMPtr<nsIChildChannel> mChildChannel;
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsIURI> mBaseURI;
nsCString mContentType;
bool mIsDocument{false}; // keeps track of the LOAD_DOCUMENT_URI flag
bool mOpened{false};
bool mIsSrcdocChannel{false};
};
#endif /* nsViewSourceChannel_h___ */