gecko-dev/caps/NullPrincipal.h
Gabriele Svelto 69790bc62e Bug 1600545 - Remove useless inclusions of header files generated from IDL files in accessible/, browser/, caps/, chrome/, devtools/, docshell/, editor/, extensions/, gfx/, hal/, image/, intl/, ipc/, js/, layout/, and media/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.

find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
    interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
    if [ -n "$interfaces" ]; then
        if [[ "$interfaces" == *$'\n'* ]]; then
          regexp="\("
          for i in $interfaces; do regexp="$regexp$i\|"; done
          regexp="${regexp%%\\\|}\)"
        else
          regexp="$interfaces"
        fi
        interface=$(basename "$path")
        rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
            hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
            if [ $hits -eq 0 ]; then
                echo "Removing ${interface} from ${path2}"
                grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
                mv -f "$path2".tmp "$path2"
            fi
        done
    fi
done

Differential Revision: https://phabricator.services.mozilla.com/D55443

--HG--
extra : moz-landing-system : lando
2019-12-06 09:16:44 +00:00

119 lines
4.1 KiB
C++

/* -*- Mode: C++; tab-width: 2; 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/. */
/**
* This is the principal that has no rights and can't be accessed by
* anything other than itself and chrome; null principals are not
* same-origin with anything but themselves.
*/
#ifndef mozilla_NullPrincipal_h
#define mozilla_NullPrincipal_h
#include "nsIPrincipal.h"
#include "nsJSPrincipals.h"
#include "nsCOMPtr.h"
#include "mozilla/BasePrincipal.h"
class nsIDocShell;
class nsIURI;
namespace Json {
class Value;
}
#define NS_NULLPRINCIPAL_CID \
{ \
0xbd066e5f, 0x146f, 0x4472, { \
0x83, 0x31, 0x7b, 0xfd, 0x05, 0xb1, 0xed, 0x90 \
} \
}
#define NS_NULLPRINCIPAL_CONTRACTID "@mozilla.org/nullprincipal;1"
#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
namespace mozilla {
class NullPrincipal final : public BasePrincipal {
public:
// This should only be used by deserialization, and the factory constructor.
// Other consumers should use the Create and CreateWithInheritedAttributes
// methods.
NullPrincipal() : BasePrincipal(eNullPrincipal) {}
static PrincipalKind Kind() { return eNullPrincipal; }
NS_DECL_NSISERIALIZABLE
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
uint32_t GetHashValue() override;
NS_IMETHOD GetURI(nsIURI** aURI) override;
NS_IMETHOD GetIsOriginPotentiallyTrustworthy(bool* aResult) override;
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
nsIPrincipal* aInheritFrom);
// Create NullPrincipal with origin attributes from docshell.
// If aIsFirstParty is true, and the pref 'privacy.firstparty.isolate' is also
// enabled, the mFirstPartyDomain value of the origin attributes will be set
// to an unique value.
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
nsIDocShell* aDocShell, bool aIsFirstParty = false);
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
const OriginAttributes& aOriginAttributes, bool aIsFirstParty = false);
static already_AddRefed<NullPrincipal> Create(
const OriginAttributes& aOriginAttributes, nsIURI* aURI = nullptr);
static already_AddRefed<NullPrincipal> CreateWithoutOriginAttributes();
nsresult Init(const OriginAttributes& aOriginAttributes = OriginAttributes(),
nsIURI* aURI = nullptr);
virtual nsresult GetScriptLocation(nsACString& aStr) override;
nsresult GetSiteIdentifier(SiteIdentifier& aSite) override {
aSite.Init(this);
return NS_OK;
}
virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
// Serializable keys are the valid enum fields the serialization supports
enum SerializableKeys : uint8_t { eSpec = 0, eSuffix, eMax = eSuffix };
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
static already_AddRefed<BasePrincipal> FromProperties(
nsTArray<NullPrincipal::KeyVal>& aFields);
protected:
virtual ~NullPrincipal() = default;
bool SubsumesInternal(nsIPrincipal* aOther,
DocumentDomainConsideration aConsideration) override {
MOZ_ASSERT(aOther);
return FastEquals(aOther);
}
bool MayLoadInternal(nsIURI* aURI) override;
nsCOMPtr<nsIURI> mURI;
private:
// If aIsFirstParty is true, this NullPrincipal will be initialized based on
// the aOriginAttributes with FirstPartyDomain set to a unique value.
// This value is generated from mURI.path, with ".mozilla" appended at the
// end.
void Init(const OriginAttributes& aOriginAttributes, bool aIsFirstParty);
};
} // namespace mozilla
#endif // mozilla_NullPrincipal_h