Bug 1526615 - Part 1: Add support for RealPort and Directory to MozURL; r=nika

Differential Revision: https://phabricator.services.mozilla.com/D19282
This commit is contained in:
Jan Varga 2019-02-10 10:20:09 +01:00
Родитель 1ee1cd1c2d
Коммит aa63590c8e
3 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -49,6 +49,7 @@ class MozURL final {
nsDependentCSubstring Host() const { return mozurl_host(this); }
// Will return the port number, if specified, or -1
int32_t Port() const { return mozurl_port(this); }
int32_t RealPort() const { return mozurl_real_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
@ -58,6 +59,7 @@ class MozURL final {
nsDependentCSubstring Query() const { return mozurl_query(this); }
nsDependentCSubstring Ref() const { return mozurl_fragment(this); }
bool HasFragment() const { return mozurl_has_fragment(this); }
nsDependentCSubstring Directory() const { return mozurl_directory(this); }
// WARNING: This does not match the definition of origins in nsIPrincipal for
// all URIs.

Просмотреть файл

@ -49,6 +49,7 @@ MozURLSpecSlice mozurl_username(const mozilla::net::MozURL*);
MozURLSpecSlice mozurl_password(const mozilla::net::MozURL*);
MozURLSpecSlice mozurl_host(const mozilla::net::MozURL*);
int32_t mozurl_port(const mozilla::net::MozURL*);
int32_t mozurl_real_port(const mozilla::net::MozURL*);
MozURLSpecSlice mozurl_host_port(const mozilla::net::MozURL*);
MozURLSpecSlice mozurl_filepath(const mozilla::net::MozURL*);
MozURLSpecSlice mozurl_path(const mozilla::net::MozURL*);
@ -56,6 +57,7 @@ MozURLSpecSlice mozurl_query(const mozilla::net::MozURL*);
MozURLSpecSlice mozurl_fragment(const mozilla::net::MozURL*);
bool mozurl_has_fragment(const mozilla::net::MozURL*);
MozURLSpecSlice mozurl_directory(const mozilla::net::MozURL*);
void mozurl_origin(const mozilla::net::MozURL*, nsACString* aResult);
nsresult mozurl_common_base(const mozilla::net::MozURL* aUrl1,

Просмотреть файл

@ -197,6 +197,14 @@ pub extern "C" fn mozurl_port(url: &MozURL) -> i32 {
url.port().map(|p| p as i32).unwrap_or(-1)
}
#[no_mangle]
pub extern "C" fn mozurl_real_port(url: &MozURL) -> i32 {
url.port()
.or_else(|| default_port(url.scheme()))
.map(|p| p as i32)
.unwrap_or(-1)
}
#[no_mangle]
pub extern "C" fn mozurl_host_port(url: &MozURL) -> SpecSlice {
(&url[Position::BeforeHost..Position::BeforePath]).into()
@ -227,6 +235,15 @@ pub extern "C" fn mozurl_has_fragment(url: &MozURL) -> bool {
url.fragment().is_some()
}
#[no_mangle]
pub extern "C" fn mozurl_directory(url: &MozURL) -> SpecSlice {
if let Some(position) = url.path().rfind('/') {
url.path()[..position + 1].into()
} else {
url.path().into()
}
}
#[no_mangle]
pub extern "C" fn mozurl_origin(url: &MozURL, origin: &mut nsACString) {
// NOTE: Try to re-use the allocation we got from rust-url, and transfer