mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1444151 - Part 4: Remove the now-unnecessary xpcom-style segment getters, r=valentin
This commit is contained in:
parent
4f380cfe7d
commit
da7423dfa5
7
dom/cache/DBSchema.cpp
vendored
7
dom/cache/DBSchema.cpp
vendored
@ -2122,15 +2122,12 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
|
|||||||
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
|
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
nsCString scheme;
|
nsDependentCSubstring scheme = url->Scheme();
|
||||||
rv = url->GetScheme(scheme);
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
|
|
||||||
MOZ_ASSERT(scheme == "http" || scheme == "https" || scheme == "file");
|
MOZ_ASSERT(scheme == "http" || scheme == "https" || scheme == "file");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsCString origin;
|
nsCString origin;
|
||||||
rv = url->GetOrigin(origin);
|
url->Origin(origin);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
|
|
||||||
|
|
||||||
aSavedResponseOut->mValue.principalInfo() =
|
aSavedResponseOut->mValue.principalInfo() =
|
||||||
mozilla::ipc::ContentPrincipalInfo(attrs, origin, specNoSuffix);
|
mozilla::ipc::ContentPrincipalInfo(attrs, origin, specNoSuffix);
|
||||||
|
@ -49,12 +49,10 @@ ClientIsValidPrincipalInfo(const PrincipalInfo& aPrincipalInfo)
|
|||||||
NS_ENSURE_SUCCESS(rv, false);
|
NS_ENSURE_SUCCESS(rv, false);
|
||||||
|
|
||||||
nsAutoCString originOrigin;
|
nsAutoCString originOrigin;
|
||||||
rv = originURL->GetOrigin(originOrigin);
|
originURL->Origin(originOrigin);
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
nsAutoCString specOrigin;
|
nsAutoCString specOrigin;
|
||||||
rv = specURL->GetOrigin(specOrigin);
|
specURL->Origin(specOrigin);
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
// For now require Clients to have a principal where both its
|
// For now require Clients to have a principal where both its
|
||||||
// originNoSuffix and spec have the same origin. This will
|
// originNoSuffix and spec have the same origin. This will
|
||||||
@ -101,12 +99,10 @@ ClientIsValidCreationURL(const PrincipalInfo& aPrincipalInfo,
|
|||||||
NS_ENSURE_SUCCESS(rv, false);
|
NS_ENSURE_SUCCESS(rv, false);
|
||||||
|
|
||||||
nsAutoCString origin;
|
nsAutoCString origin;
|
||||||
rv = url->GetOrigin(origin);
|
url->Origin(origin);
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
nsAutoCString principalOrigin;
|
nsAutoCString principalOrigin;
|
||||||
rv = principalURL->GetOrigin(principalOrigin);
|
principalURL->Origin(principalOrigin);
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
// The vast majority of sites should simply result in the same principal
|
// The vast majority of sites should simply result in the same principal
|
||||||
// and URL origin.
|
// and URL origin.
|
||||||
@ -114,9 +110,7 @@ ClientIsValidCreationURL(const PrincipalInfo& aPrincipalInfo,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString scheme;
|
nsDependentCSubstring scheme = url->Scheme();
|
||||||
rv = url->GetScheme(scheme);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
// Generally any origin can also open javascript: windows and workers.
|
// Generally any origin can also open javascript: windows and workers.
|
||||||
if (scheme.LowerCaseEqualsLiteral("javascript")) {
|
if (scheme.LowerCaseEqualsLiteral("javascript")) {
|
||||||
@ -130,10 +124,6 @@ ClientIsValidCreationURL(const PrincipalInfo& aPrincipalInfo,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString principalScheme;
|
|
||||||
rv = principalURL->GetScheme(principalScheme);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
// Otherwise don't support this URL type in the clients sub-system for
|
// Otherwise don't support this URL type in the clients sub-system for
|
||||||
// now. This will exclude a variety of internal browser clients, but
|
// now. This will exclude a variety of internal browser clients, but
|
||||||
// currently we don't need to support those. This function can be
|
// currently we don't need to support those. This function can be
|
||||||
@ -142,9 +132,7 @@ ClientIsValidCreationURL(const PrincipalInfo& aPrincipalInfo,
|
|||||||
}
|
}
|
||||||
case PrincipalInfo::TSystemPrincipalInfo:
|
case PrincipalInfo::TSystemPrincipalInfo:
|
||||||
{
|
{
|
||||||
nsAutoCString scheme;
|
nsDependentCSubstring scheme = url->Scheme();
|
||||||
rv = url->GetScheme(scheme);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
// While many types of documents can be created with a system principal,
|
// While many types of documents can be created with a system principal,
|
||||||
// there are only a few that can reasonably become windows. We attempt
|
// there are only a few that can reasonably become windows. We attempt
|
||||||
|
@ -66,11 +66,7 @@ GetOrigin(const nsACString& aURL, nsACString& aOrigin)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = url->GetOrigin(aOrigin);
|
url->Origin(aOrigin);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +54,18 @@ public:
|
|||||||
nsDependentCSubstring Password() const {
|
nsDependentCSubstring Password() const {
|
||||||
return mozurl_password(this);
|
return mozurl_password(this);
|
||||||
}
|
}
|
||||||
|
// Will return the hostname of URL. If the hostname is an IPv6 address,
|
||||||
|
// it will be enclosed in square brackets, such as `[::1]`
|
||||||
nsDependentCSubstring Host() const {
|
nsDependentCSubstring Host() const {
|
||||||
return mozurl_host(this);
|
return mozurl_host(this);
|
||||||
}
|
}
|
||||||
|
// Will return the port number, if specified, or -1
|
||||||
int32_t Port() const {
|
int32_t Port() const {
|
||||||
return mozurl_port(this);
|
return mozurl_port(this);
|
||||||
}
|
}
|
||||||
|
// If the URL's port number is equal to the default port, will only return the
|
||||||
|
// hostname, otherwise it will return a string of the form `{host}:{port}`
|
||||||
|
// See: https://url.spec.whatwg.org/#default-port
|
||||||
nsDependentCSubstring HostPort() const {
|
nsDependentCSubstring HostPort() const {
|
||||||
return mozurl_host_port(this);
|
return mozurl_host_port(this);
|
||||||
}
|
}
|
||||||
@ -93,58 +99,6 @@ public:
|
|||||||
return mozurl_relative(this, aOther, aRelative);
|
return mozurl_relative(this, aOther, aRelative);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy XPCOM-style getters
|
|
||||||
nsresult GetScheme(nsACString& aScheme) const {
|
|
||||||
aScheme.Assign(Scheme());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
nsresult GetSpec(nsACString& aSpec) const {
|
|
||||||
aSpec.Assign(Spec());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
nsresult GetUsername(nsACString& aUser) const {
|
|
||||||
aUser.Assign(Username());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
nsresult GetPassword(nsACString& aPassword) const {
|
|
||||||
aPassword.Assign(Password());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
// Will return the hostname of URL. If the hostname is an IPv6 address,
|
|
||||||
// it will be enclosed in square brackets, such as `[::1]`
|
|
||||||
nsresult GetHostname(nsACString& aHost) const {
|
|
||||||
aHost.Assign(Host());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
// If the URL's port number is equal to the default port, will only return the
|
|
||||||
// hostname, otherwise it will return a string of the form `{host}:{port}`
|
|
||||||
// See: https://url.spec.whatwg.org/#default-port
|
|
||||||
nsresult GetHostPort(nsACString& aHostPort) const {
|
|
||||||
aHostPort.Assign(HostPort());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
// Will return the port number, if specified, or -1
|
|
||||||
nsresult GetPort(int32_t* aPort) const {
|
|
||||||
*aPort = Port();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
nsresult GetFilePath(nsACString& aPath) const {
|
|
||||||
aPath.Assign(FilePath());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
nsresult GetQuery(nsACString& aQuery) const {
|
|
||||||
aQuery.Assign(Query());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
nsresult GetRef(nsACString& aRef) const {
|
|
||||||
aRef.Assign(Ref());
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
nsresult GetOrigin(nsACString& aOrigin) const {
|
|
||||||
Origin(aOrigin);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MOZ_STACK_CLASS Mutator
|
class MOZ_STACK_CLASS Mutator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -12,31 +12,21 @@ TEST(TestMozURL, Getters)
|
|||||||
RefPtr<MozURL> url;
|
RefPtr<MozURL> url;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
||||||
|
|
||||||
nsAutoCString out;
|
ASSERT_TRUE(url->Scheme().EqualsLiteral("http"));
|
||||||
|
|
||||||
ASSERT_EQ(url->GetScheme(out), NS_OK);
|
ASSERT_TRUE(url->Spec() == href);
|
||||||
ASSERT_TRUE(out.EqualsLiteral("http"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetSpec(out), NS_OK);
|
ASSERT_TRUE(url->Username().EqualsLiteral("user"));
|
||||||
ASSERT_TRUE(out == href);
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetUsername(out), NS_OK);
|
ASSERT_TRUE(url->Password().EqualsLiteral("pass"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("user"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetPassword(out), NS_OK);
|
ASSERT_TRUE(url->Host().EqualsLiteral("example.com"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("pass"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetHostname(out), NS_OK);
|
ASSERT_TRUE(url->FilePath().EqualsLiteral("/path"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("example.com"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetFilePath(out), NS_OK);
|
ASSERT_TRUE(url->Query().EqualsLiteral("query"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("/path"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetQuery(out), NS_OK);
|
ASSERT_TRUE(url->Ref().EqualsLiteral("ref"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("query"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetRef(out), NS_OK);
|
|
||||||
ASSERT_TRUE(out.EqualsLiteral("ref"));
|
|
||||||
|
|
||||||
url = nullptr;
|
url = nullptr;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), NS_LITERAL_CSTRING("")),
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), NS_LITERAL_CSTRING("")),
|
||||||
@ -61,8 +51,7 @@ TEST(TestMozURL, MutatorChain)
|
|||||||
.SetRef(NS_LITERAL_CSTRING("huh"))
|
.SetRef(NS_LITERAL_CSTRING("huh"))
|
||||||
.Finalize(getter_AddRefs(url2)), NS_OK);
|
.Finalize(getter_AddRefs(url2)), NS_OK);
|
||||||
|
|
||||||
ASSERT_EQ(url2->GetSpec(out), NS_OK);
|
ASSERT_TRUE(url2->Spec().EqualsLiteral("https://newuser:newpass@test/new/file/path?bla#huh"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("https://newuser:newpass@test/new/file/path?bla#huh"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestMozURL, MutatorFinalizeTwice)
|
TEST(TestMozURL, MutatorFinalizeTwice)
|
||||||
@ -76,8 +65,7 @@ TEST(TestMozURL, MutatorFinalizeTwice)
|
|||||||
MozURL::Mutator mut = url->Mutate();
|
MozURL::Mutator mut = url->Mutate();
|
||||||
mut.SetScheme(NS_LITERAL_CSTRING("https")); // Change the scheme to https
|
mut.SetScheme(NS_LITERAL_CSTRING("https")); // Change the scheme to https
|
||||||
ASSERT_EQ(mut.Finalize(getter_AddRefs(url2)), NS_OK);
|
ASSERT_EQ(mut.Finalize(getter_AddRefs(url2)), NS_OK);
|
||||||
ASSERT_EQ(url2->GetSpec(out), NS_OK);
|
ASSERT_TRUE(url2->Spec().EqualsLiteral("https://user:pass@example.com/path?query#ref"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("https://user:pass@example.com/path?query#ref"));
|
|
||||||
|
|
||||||
// Test that a second call to Finalize will result in an error code
|
// Test that a second call to Finalize will result in an error code
|
||||||
url2 = nullptr;
|
url2 = nullptr;
|
||||||
@ -107,17 +95,14 @@ TEST(TestMozURL, InitWithBase)
|
|||||||
nsAutoCString href("https://example.net/a/b.html");
|
nsAutoCString href("https://example.net/a/b.html");
|
||||||
RefPtr<MozURL> url;
|
RefPtr<MozURL> url;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
||||||
nsAutoCString out;
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetSpec(out), NS_OK);
|
ASSERT_TRUE(url->Spec().EqualsLiteral("https://example.net/a/b.html"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("https://example.net/a/b.html"));
|
|
||||||
|
|
||||||
RefPtr<MozURL> url2;
|
RefPtr<MozURL> url2;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url2), NS_LITERAL_CSTRING("c.png"),
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url2), NS_LITERAL_CSTRING("c.png"),
|
||||||
url), NS_OK);
|
url), NS_OK);
|
||||||
|
|
||||||
ASSERT_EQ(url2->GetSpec(out), NS_OK);
|
ASSERT_TRUE(url2->Spec().EqualsLiteral("https://example.net/a/c.png"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("https://example.net/a/c.png"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestMozURL, Path)
|
TEST(TestMozURL, Path)
|
||||||
@ -125,16 +110,12 @@ TEST(TestMozURL, Path)
|
|||||||
nsAutoCString href("about:blank");
|
nsAutoCString href("about:blank");
|
||||||
RefPtr<MozURL> url;
|
RefPtr<MozURL> url;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
||||||
nsAutoCString out;
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetSpec(out), NS_OK);
|
ASSERT_TRUE(url->Spec().EqualsLiteral("about:blank"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("about:blank"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetScheme(out), NS_OK);
|
ASSERT_TRUE(url->Scheme().EqualsLiteral("about"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("about"));
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetFilePath(out), NS_OK);
|
ASSERT_TRUE(url->FilePath().EqualsLiteral("blank"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("blank"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestMozURL, HostPort)
|
TEST(TestMozURL, HostPort)
|
||||||
@ -142,27 +123,20 @@ TEST(TestMozURL, HostPort)
|
|||||||
nsAutoCString href("https://user:pass@example.net:1234/path?query#ref");
|
nsAutoCString href("https://user:pass@example.net:1234/path?query#ref");
|
||||||
RefPtr<MozURL> url;
|
RefPtr<MozURL> url;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
||||||
nsAutoCString out;
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetHostPort(out), NS_OK);
|
ASSERT_TRUE(url->HostPort().EqualsLiteral("example.net:1234"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("example.net:1234"));
|
|
||||||
|
|
||||||
RefPtr<MozURL> url2;
|
RefPtr<MozURL> url2;
|
||||||
url->Mutate().SetHostPort(NS_LITERAL_CSTRING("test:321"))
|
url->Mutate().SetHostPort(NS_LITERAL_CSTRING("test:321"))
|
||||||
.Finalize(getter_AddRefs(url2));
|
.Finalize(getter_AddRefs(url2));
|
||||||
|
|
||||||
ASSERT_EQ(url2->GetHostPort(out), NS_OK);
|
ASSERT_TRUE(url2->HostPort().EqualsLiteral("test:321"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("test:321"));
|
ASSERT_TRUE(url2->Spec().EqualsLiteral("https://user:pass@test:321/path?query#ref"));
|
||||||
ASSERT_EQ(url2->GetSpec(out), NS_OK);
|
|
||||||
ASSERT_TRUE(out.EqualsLiteral("https://user:pass@test:321/path?query#ref"));
|
|
||||||
|
|
||||||
href.Assign("https://user:pass@example.net:443/path?query#ref");
|
href.Assign("https://user:pass@example.net:443/path?query#ref");
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
||||||
ASSERT_EQ(url->GetHostPort(out), NS_OK);
|
ASSERT_TRUE(url->HostPort().EqualsLiteral("example.net"));
|
||||||
ASSERT_TRUE(out.EqualsLiteral("example.net"));
|
ASSERT_EQ(url->Port(), -1);
|
||||||
int32_t port;
|
|
||||||
ASSERT_EQ(url->GetPort(&port), NS_OK);
|
|
||||||
ASSERT_EQ(port, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestMozURL, Origin)
|
TEST(TestMozURL, Origin)
|
||||||
@ -170,14 +144,14 @@ TEST(TestMozURL, Origin)
|
|||||||
nsAutoCString href("https://user:pass@example.net:1234/path?query#ref");
|
nsAutoCString href("https://user:pass@example.net:1234/path?query#ref");
|
||||||
RefPtr<MozURL> url;
|
RefPtr<MozURL> url;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
|
||||||
nsAutoCString out;
|
|
||||||
|
|
||||||
ASSERT_EQ(url->GetOrigin(out), NS_OK);
|
nsAutoCString out;
|
||||||
|
url->Origin(out);
|
||||||
ASSERT_TRUE(out.EqualsLiteral("https://example.net:1234"));
|
ASSERT_TRUE(out.EqualsLiteral("https://example.net:1234"));
|
||||||
|
|
||||||
RefPtr<MozURL> url2;
|
RefPtr<MozURL> url2;
|
||||||
ASSERT_EQ(MozURL::Init(getter_AddRefs(url2),
|
ASSERT_EQ(MozURL::Init(getter_AddRefs(url2),
|
||||||
NS_LITERAL_CSTRING("file:///tmp/foo")), NS_OK);
|
NS_LITERAL_CSTRING("file:///tmp/foo")), NS_OK);
|
||||||
ASSERT_EQ(url2->GetOrigin(out), NS_OK);
|
url2->Origin(out);
|
||||||
ASSERT_TRUE(out.EqualsLiteral("null"));
|
ASSERT_TRUE(out.EqualsLiteral("null"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user