// 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 "ui/base/clipboard/file_info.h" #include <string_view> #include "base/strings/escape.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" namespace ui { namespace { constexpr char kFileUrlPrefix[] = …; constexpr char kFileSchemePrefix[] = …; constexpr char kURIListSeparator[] = …; // Returns true if path starts with a letter, followed by a colon, followed // by a path separator. bool StartsWithDriveLetter(std::string_view path) { … } // We implement our own URLToPath() and PathToURL() rather than use // net::FileUrlToFilePath() or net::FilePathToFileURL() since //net code works // differently on each platform and is overly strict. In particular, it doesn't // allow Windows network paths such as //ChromeOS/MyFiles on OS_CHROMEOS. // // This code is a little different in nature to most other path handling in that // we expect this code to roundtrip both posix and windows paths (local or // network) when running on either platform. // // Convert file:// |url| to a FilePath. Returns empty if |url| is invalid. // This function expects an absolute path since it is not possible to encode // a relative path as a file:// URL. The third slash in 'file:///' is not // mandatory, but without it, the path is considered a network path // (file://host/path). If a drive letter followed by colon and slash is detected // (file:///C:/path), the path is assumed to be windows path 'C:/path', but // without the slash (file:///C:path), the path is assumed to posix '/C:path' // rather than windows relative path 'C:path'. base::FilePath URLToPath(std::string_view url) { … } } // namespace FileInfo::FileInfo() = default; FileInfo::FileInfo(const base::FilePath& path, const base::FilePath& display_name) : … { … } FileInfo::~FileInfo() = default; bool FileInfo::operator==(const FileInfo& other) const { … } std::vector<FileInfo> URIListToFileInfos(std::string_view uri_list) { … } std::string FilePathToFileURL(const base::FilePath& file_path) { … } std::string FileInfosToURIList(const std::vector<FileInfo>& filenames) { … } } // namespace ui