Commit message: None
CVE: CVE-2019-5803
CWE: CWE-20
Vulnerability description: Insufficient policy enforcement in Content Security Policy in Google Chrome prior to 73.0.3683.75 allowed a remote attacker to bypass content security policy via a crafted HTML page.

Project: Chrome

Document* Location::GetDocument() const {
  return ToLocalDOMWindow(dom_window_)->document();
}

Project: Chrome

bool Location::IsAttached() const {
  return dom_window_->GetFrame();
}

Project: Chrome

Location::Location(DOMWindow* dom_window) : dom_window_(dom_window) {}

Project: Chrome

void Location::Trace(blink::Visitor* visitor) {
  visitor->Trace(dom_window_);
  ScriptWrappable::Trace(visitor);
}

Project: Chrome

inline const KURL& Location::Url() const {
  const KURL& url = GetDocument()->Url();
  if (!url.IsValid()) {
    return BlankURL();
  }

  return url;
}

Project: Chrome

DOMStringList* Location::ancestorOrigins() const {
  DOMStringList* origins = DOMStringList::Create();
  if (!IsAttached())
    return origins;
  for (Frame* frame = dom_window_->GetFrame()->Tree().Parent(); frame;
       frame = frame->Tree().Parent()) {
    origins->Append(
        frame->GetSecurityContext()->GetSecurityOrigin()->ToString());
  }
  return origins;
}

Project: Chrome

void Location::assign(LocalDOMWindow* current_window,
                      LocalDOMWindow* entered_window,
                      const USVStringOrTrustedURL& stringOrUrl,
                      ExceptionState& exception_state) {
  if (!BindingSecurity::ShouldAllowAccessTo(current_window, this,
                                            exception_state)) {
    return;
  }

  String url = GetStringFromTrustedURL(stringOrUrl, current_window->document(),
                                       exception_state);
  if (!exception_state.HadException()) {
    SetLocation(url, current_window, entered_window, &exception_state);
  }
}

Project: Chrome

String Location::hash() const {
  return DOMURLUtilsReadOnly::hash(Url());
}

Project: Chrome

String Location::host() const {
  return DOMURLUtilsReadOnly::host(Url());
}

Project: Chrome

String Location::hostname() const {
  return DOMURLUtilsReadOnly::hostname(Url());
}

Project: Chrome

void Location::href(USVStringOrTrustedURL& result) const {
  result.SetUSVString(Url().StrippedForUseAsHref());
}

Project: Chrome

String Location::origin() const {
  return DOMURLUtilsReadOnly::origin(Url());
}

Project: Chrome

String Location::pathname() const {
  return DOMURLUtilsReadOnly::pathname(Url());
}

Project: Chrome

String Location::port() const {
  return DOMURLUtilsReadOnly::port(Url());
}

Project: Chrome

String Location::protocol() const {
  return DOMURLUtilsReadOnly::protocol(Url());
}

Project: Chrome

void Location::reload(LocalDOMWindow* current_window) {
  if (!IsAttached())
    return;
  if (GetDocument()->Url().ProtocolIsJavaScript())
    return;
  ToLocalDOMWindow(dom_window_)
      ->GetFrame()
      ->Reload(WebFrameLoadType::kReload,
               ClientRedirectPolicy::kClientRedirect);
}

Project: Chrome

String Location::search() const {
  return DOMURLUtilsReadOnly::search(Url());
}

Project: Chrome

void Location::setHash(LocalDOMWindow* current_window,
                       LocalDOMWindow* entered_window,
                       const String& hash,
                       ExceptionState& exception_state) {
  KURL url = GetDocument()->Url();
  String old_fragment_identifier = url.FragmentIdentifier();
  String new_fragment_identifier = hash;
  if (hash[0] == '#')
    new_fragment_identifier = hash.Substring(1);
  url.SetFragmentIdentifier(new_fragment_identifier);
  if (EqualIgnoringNullity(old_fragment_identifier, url.FragmentIdentifier()))
    return;
  SetLocation(url.GetString(), current_window, entered_window,
              &exception_state);
}

Project: Chrome

void Location::setHost(LocalDOMWindow* current_window,
                       LocalDOMWindow* entered_window,
                       const String& host,
                       ExceptionState& exception_state) {
  KURL url = GetDocument()->Url();
  url.SetHostAndPort(host);
  SetLocation(url.GetString(), current_window, entered_window,
              &exception_state);
}

Project: Chrome

void Location::setHref(LocalDOMWindow* current_window,
                       LocalDOMWindow* entered_window,
                       const USVStringOrTrustedURL& stringOrUrl,
                       ExceptionState& exception_state) {
  String url = GetStringFromTrustedURL(stringOrUrl, current_window->document(),
                                       exception_state);
  if (!exception_state.HadException()) {
    SetLocation(url, current_window, entered_window, &exception_state);
  }
}

Project: Chrome

void Location::setPathname(LocalDOMWindow* current_window,
                           LocalDOMWindow* entered_window,
                           const String& pathname,
                           ExceptionState& exception_state) {
  KURL url = GetDocument()->Url();
  url.SetPath(pathname);
  SetLocation(url.GetString(), current_window, entered_window,
              &exception_state);
}

Project: Chrome

void Location::setProtocol(LocalDOMWindow* current_window,
                           LocalDOMWindow* entered_window,
                           const String& protocol,
                           ExceptionState& exception_state) {
  KURL url = GetDocument()->Url();
  if (!url.SetProtocol(protocol)) {
    exception_state.ThrowDOMException(
        DOMExceptionCode::kSyntaxError,
        "'" + protocol + "' is an invalid protocol.");
    return;
  }
  SetLocation(url.GetString(), current_window, entered_window,
              &exception_state);
}

Project: Chrome

void Location::setSearch(LocalDOMWindow* current_window,
                         LocalDOMWindow* entered_window,
                         const String& search,
                         ExceptionState& exception_state) {
  KURL url = GetDocument()->Url();
  url.SetQuery(search);
  SetLocation(url.GetString(), current_window, entered_window,
              &exception_state);
}

Project: Chrome

String Location::toString() const {
  USVStringOrTrustedURL result;
  href(result);
  DCHECK(result.IsUSVString());
  return result.GetAsUSVString();
}