chromium/components/url_formatter/url_fixer.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/url_formatter/url_fixer.h"

#include <stddef.h>

#include <string_view>

#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/i18n/char_iterator.h"
#include "base/ranges/algorithm.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/url_formatter/url_formatter.h"
#include "net/base/filename_util.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_file.h"
#include "url/url_util.h"

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include "base/path_service.h"
#endif

namespace url_formatter {

const char* home_directory_override =;

namespace {

// Hardcode these constants to avoid dependences on //chrome and //content.
const char kChromeUIScheme[] =;
const char kDevToolsScheme[] =;
const char kChromeUIDefaultHost[] =;
const char kViewSourceScheme[] =;
const size_t kMaxFixupURLDepth =;

// TODO(estade): Remove these ugly, ugly functions. They are only used in
// SegmentURL. A url::Parsed object keeps track of a bunch of indices into
// a url string, and these need to be updated when the URL is converted from
// UTF8 to UTF16. Instead of this after-the-fact adjustment, we should parse it
// in the correct string format to begin with.
url::Component UTF8ComponentToUTF16Component(
    const std::string& text_utf8,
    const url::Component& component_utf8) {}

void UTF8PartsToUTF16Parts(const std::string& text_utf8,
                           const url::Parsed& parts_utf8,
                           url::Parsed* parts) {}

base::TrimPositions TrimWhitespace(const std::u16string& input,
                                   base::TrimPositions positions,
                                   std::string* output) {}

base::TrimPositions TrimWhitespaceUTF8(const std::string& input,
                                       base::TrimPositions positions,
                                       std::string* output) {}

// does some basic fixes for input that we want to test for file-ness
void PrepareStringForFileOps(const base::FilePath& text, std::string* output) {}

// Tries to create a full path from |text|.  If the result is valid and the
// file exists, returns true and sets |full_path| to the result.  Otherwise,
// returns false and leaves |full_path| unchanged.
bool ValidPathForFile(const std::string& text, base::FilePath* full_path) {}

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// Given a path that starts with ~, return a path that starts with an
// expanded-out /user/foobar directory.
std::string FixupHomedir(const std::string& text) {}
#endif

// Tries to create a file: URL from |text| if it looks like a filename, even if
// it doesn't resolve as a valid path or to an existing file.  Returns a
// (possibly invalid) file: URL in |fixed_up_url| for input beginning
// with a drive specifier or "\\".  Returns the unchanged input in other cases
// (including file: URLs: these don't look like filenames).
std::string FixupPath(const std::string& text) {}

// Checks |domain| to see if a valid TLD is already present.  If not, appends
// |desired_tld| to the domain, and prepends "www." unless it's already present.
void AddDesiredTLD(const std::string& desired_tld, std::string* domain) {}

inline void FixupUsername(const std::string& text,
                          const url::Component& part,
                          std::string* url) {}

inline void FixupPassword(const std::string& text,
                          const url::Component& part,
                          std::string* url) {}

void FixupHost(const std::string& text,
               const url::Component& part,
               bool has_scheme,
               const std::string& desired_tld,
               std::string* url) {}

void FixupPort(const std::string& text,
               const url::Component& part,
               std::string* url) {}

inline void FixupPath(const std::string& text,
                      const url::Component& part,
                      std::string* url) {}

inline void FixupQuery(const std::string& text,
                       const url::Component& part,
                       std::string* url) {}

inline void FixupRef(const std::string& text,
                     const url::Component& part,
                     std::string* url) {}

bool HasPort(const std::string& original_text,
             const url::Component& scheme_component) {}

// Try to extract a valid scheme from the beginning of |text|.
// If successful, set |scheme_component| to the text range where the scheme
// was located, and fill |canon_scheme| with its canonicalized form.
// Otherwise, return false and leave the outputs in an indeterminate state.
bool GetValidScheme(const std::string& text,
                    url::Component* scheme_component,
                    std::string* canon_scheme) {}

// Performs the work for url_formatter::SegmentURL. |text| may be modified on
// output on success: a semicolon following a valid scheme is replaced with a
// colon.
std::string SegmentURLInternal(std::string* text, url::Parsed* parts) {}

}  // namespace

std::string SegmentURL(const std::string& text, url::Parsed* parts) {}

std::u16string SegmentURL(const std::u16string& text, url::Parsed* parts) {}

GURL FixupURLInternal(const std::string& text,
                      const std::string& desired_tld,
                      size_t depth) {}

GURL FixupURL(const std::string& text, const std::string& desired_tld) {}

// The rules are different here than for regular fixup, since we need to
// handle input like "hello.html" and know to look in the current directory.
// Regular fixup will look for cues that it is actually a file path before
// trying to figure out what file it is.  If our logic doesn't work, we will
// fall back on regular fixup.
GURL FixupRelativeFile(const base::FilePath& base_dir,
                       const base::FilePath& text) {}

void OffsetComponent(int offset, url::Component* part) {}

bool IsEquivalentScheme(const std::string& scheme1,
                        const std::string& scheme2) {}

}  // namespace url_formatter