common.cc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/services/quarantine/common.h"
  5. #include "url/origin.h"
  6. #include "url/url_canon.h"
  7. namespace quarantine {
  8. GURL SanitizeUrlForQuarantine(const GURL& source_url) {
  9. // Invalid URLs and 'data' URLs don't confer an authority.
  10. if (!source_url.is_valid() || source_url.SchemeIs("data")) {
  11. return GURL();
  12. }
  13. // The full content of these URLs are only meaningful within the confines of
  14. // the browser. Origin extracts the inner URL for both of these schemes.
  15. if (source_url.SchemeIsBlob() || source_url.SchemeIsFileSystem()) {
  16. return url::Origin::Create(source_url).GetURL();
  17. }
  18. if (!source_url.SchemeIsHTTPOrHTTPS() && !source_url.SchemeIsWSOrWSS()) {
  19. return source_url;
  20. }
  21. GURL::Replacements replacements;
  22. replacements.ClearUsername();
  23. replacements.ClearPassword();
  24. return source_url.ReplaceComponents(replacements);
  25. }
  26. } // namespace quarantine