Пример #1
0
void GetRequestURLFromWorker(const GlobalObject& aGlobal,
                             const nsAString& aInput, nsAString& aRequestURL,
                             nsACString& aURLfragment, ErrorResult& aRv) {
  RefPtr<URL> url = ParseURLFromWorker(aGlobal, aInput, aRv);
  if (aRv.Failed()) {
    return;
  }
  nsString username;
  url->GetUsername(username);

  nsString password;
  url->GetPassword(password);

  if (!username.IsEmpty() || !password.IsEmpty()) {
    aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
    return;
  }

  // Get the fragment from URL.
  nsAutoString fragment;
  url->GetHash(fragment);

  // Note: URL::GetHash() includes the "#" and we want the fragment with out
  // the hash symbol.
  if (!fragment.IsEmpty()) {
    CopyUTF16toUTF8(Substring(fragment, 1), aURLfragment);
  }

  url->SetHash(EmptyString());
  url->Stringify(aRequestURL);
}
Пример #2
0
void
GetRequestURLFromWorker(const GlobalObject& aGlobal, const nsAString& aInput,
                        nsAString& aRequestURL, ErrorResult& aRv)
{
  RefPtr<URL> url = ParseURLFromWorker(aGlobal, aInput, aRv);
  if (aRv.Failed()) {
    return;
  }

  nsString username;
  url->GetUsername(username, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }

  nsString password;
  url->GetPassword(password, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }

  if (!username.IsEmpty() || !password.IsEmpty()) {
    aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
    return;
  }

  url->SetHash(EmptyString(), aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }

  url->Stringify(aRequestURL, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }
}