Bug 1526615 - Part 1: Add support for RealPort and Directory to MozURL; r=nika
authorJan Varga <jan.varga@gmail.com>
Sun, 10 Feb 2019 10:20:09 +0100
changeset 462858 16bf9fd6ae4b46f20bd40e6aaa793729e0b271d5
parent 462857 eb1b8fcb03cb03f582c98f6b486abfe9ee6d2228
child 462859 84806a3e88b92aadc6570f59dbe12139f77d92c6
push id112345
push userjvarga@mozilla.com
push dateThu, 07 Mar 2019 18:36:03 +0000
treeherdermozilla-inbound@7e5e1c5a692d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1526615
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1526615 - Part 1: Add support for RealPort and Directory to MozURL; r=nika Differential Revision: https://phabricator.services.mozilla.com/D19282
netwerk/base/mozurl/MozURL.h
netwerk/base/mozurl/MozURL_ffi.h
netwerk/base/mozurl/src/lib.rs
--- a/netwerk/base/mozurl/MozURL.h
+++ b/netwerk/base/mozurl/MozURL.h
@@ -44,25 +44,27 @@ class MozURL final {
   nsDependentCSubstring Scheme() const { return mozurl_scheme(this); }
   nsDependentCSubstring Username() const { return mozurl_username(this); }
   nsDependentCSubstring Password() const { 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 { 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
   nsDependentCSubstring HostPort() const { return mozurl_host_port(this); }
   nsDependentCSubstring FilePath() const { return mozurl_filepath(this); }
   nsDependentCSubstring Path() const { return mozurl_path(this); }
   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.
   // XXX: Consider bringing these implementations in sync with one-another?
   void Origin(nsACString& aOrigin) const { mozurl_origin(this, &aOrigin); }
 
   nsresult GetCommonBase(const MozURL* aOther, MozURL** aCommon) const {
     return mozurl_common_base(this, aOther, aCommon);
--- a/netwerk/base/mozurl/MozURL_ffi.h
+++ b/netwerk/base/mozurl/MozURL_ffi.h
@@ -44,23 +44,25 @@ void mozurl_clone(const mozilla::net::Mo
 
 // Spec segment getters
 MozURLSpecSlice mozurl_spec(const mozilla::net::MozURL*);
 MozURLSpecSlice mozurl_scheme(const mozilla::net::MozURL*);
 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*);
 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,
                             const mozilla::net::MozURL* aUrl2,
                             mozilla::net::MozURL** aResult);
 nsresult mozurl_relative(const mozilla::net::MozURL* aUrl1,
                          const mozilla::net::MozURL* aUrl2,
                          nsACString* aResult);
--- a/netwerk/base/mozurl/src/lib.rs
+++ b/netwerk/base/mozurl/src/lib.rs
@@ -193,16 +193,24 @@ pub extern "C" fn mozurl_host(url: &MozU
 
 #[no_mangle]
 pub extern "C" fn mozurl_port(url: &MozURL) -> i32 {
   // NOTE: Gecko uses -1 to represent the default port.
   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()
 }
 
 #[no_mangle]
 pub extern "C" fn mozurl_filepath(url: &MozURL) -> SpecSlice {
   url.path().into()
 }
@@ -223,16 +231,25 @@ pub extern "C" fn mozurl_fragment(url: &
 }
 
 #[no_mangle]
 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
   // ownership of the buffer to C++.
   let mut o = nsCString::from(url.origin().ascii_serialization());
   origin.take_from(&mut o);
 }
 
 // Helper macro for debug asserting that we're the only reference to MozURL.