chromium/components/url_formatter/elide_url.cc

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

#include "components/url_formatter/elide_url.h"

#include <stddef.h>

#include <string_view>

#include "base/check_op.h"
#include "base/i18n/rtl.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/robolectric_buildflags.h"
#include "components/url_formatter/url_formatter.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_ROBOLECTRIC)
#include "ui/gfx/text_constants.h"  // nogncheck
#include "ui/gfx/text_elider.h"     // nogncheck
#include "ui/gfx/text_utils.h"      // nogncheck
#endif

namespace {

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_ROBOLECTRIC)
const char16_t kDot =;

// Build a path from the first |num_components| elements in |path_elements|.
// Prepends |path_prefix|, appends |filename|, inserts ellipsis if appropriate.
std::u16string BuildPathFromComponents(
    const std::u16string& path_prefix,
    const std::vector<std::u16string>& path_elements,
    const std::u16string& filename,
    size_t num_components) {}

// Takes a prefix (Domain, or Domain+subdomain) and a collection of path
// components and elides if possible. Returns a string containing the longest
// possible elided path, or an empty string if elision is not possible.
std::u16string ElideComponentizedPath(
    const std::u16string& url_path_prefix,
    const std::vector<std::u16string>& url_path_elements,
    const std::u16string& url_filename,
    const std::u16string& url_query,
    const gfx::FontList& font_list,
    float available_pixel_width) {}

#endif  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_ROBOLECTRIC)

bool ShouldShowScheme(std::string_view scheme,
                      const url_formatter::SchemeDisplay scheme_display) {}

// TODO(jshin): Come up with a way to show Bidi URLs 'safely' (e.g. wrap up
// the entire url with {LSI, PDI} and individual domain labels with {FSI, PDI}).
// See http://crbug.com/650760 . For now, fall back to punycode if there's a
// strong RTL character.
std::u16string HostForDisplay(std::string_view host_in_puny) {}

}  // namespace

namespace url_formatter {

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_ROBOLECTRIC)

// TODO(pkasting): http://crbug.com/77883 This whole function gets
// kerning/ligatures/etc. issues potentially wrong by assuming that the width of
// a rendered string is always the sum of the widths of its substrings.  Also I
// suspect it could be made simpler.
std::u16string ElideUrl(const GURL& url,
                        const gfx::FontList& font_list,
                        float available_pixel_width) {}

std::u16string ElideHost(const GURL& url,
                         const gfx::FontList& font_list,
                         float available_pixel_width) {}

#endif  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_ROBOLECTRIC)

std::u16string FormatUrlForSecurityDisplay(const GURL& url,
                                           const SchemeDisplay scheme_display) {}

std::u16string FormatOriginForSecurityDisplay(
    const url::Origin& origin,
    const SchemeDisplay scheme_display) {}

std::u16string FormatUrlForDisplayOmitSchemePathAndTrivialSubdomains(
    const GURL& url) {}

#if BUILDFLAG(IS_IOS)
std::u16string
FormatUrlForDisplayOmitSchemePathTrivialSubdomainsAndMobilePrefix(
    const GURL& url) {
  return url_formatter::FormatUrl(
      url,
      url_formatter::kFormatUrlOmitDefaults |
          url_formatter::kFormatUrlTrimAfterHost |
          url_formatter::kFormatUrlOmitHTTPS |
          url_formatter::kFormatUrlOmitTrivialSubdomains |
          url_formatter::kFormatUrlOmitMobilePrefix,
      base::UnescapeRule::SPACES, nullptr, nullptr, nullptr);
}
#endif

void SplitHost(const GURL& url,
               std::u16string* url_host,
               std::u16string* url_domain,
               std::u16string* url_subdomain) {}

}  // namespace url_formatter