1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Functions used internally by filename_util, and filename_util_icu. 6 7 #ifndef NET_BASE_FILENAME_UTIL_INTERNAL_H_ 8 #define NET_BASE_FILENAME_UTIL_INTERNAL_H_ 9 10 #include <string> 11 12 #include "base/files/file_path.h" 13 14 class GURL; 15 16 namespace net { 17 18 using ReplaceIllegalCharactersFunction = 19 void (*)(base::FilePath::StringType* file_name, char replace_char); 20 21 void SanitizeGeneratedFileName(base::FilePath::StringType* filename, 22 bool replace_trailing); 23 24 bool IsShellIntegratedExtension(const base::FilePath::StringType& extension); 25 26 void EnsureSafeExtension(const std::string& mime_type, 27 bool ignore_extension, 28 base::FilePath* file_name); 29 30 bool FilePathToString16(const base::FilePath& path, std::u16string* converted); 31 32 // Similar to GetSuggestedFilename(), but takes a function to replace illegal 33 // characters. If |should_replace_extension| is true, the file extension 34 // extracted from a URL will always be considered unreliable and the file 35 // extension will be determined by |mime_type|. 36 std::u16string GetSuggestedFilenameImpl( 37 const GURL& url, 38 const std::string& content_disposition, 39 const std::string& referrer_charset, 40 const std::string& suggested_name, 41 const std::string& mime_type, 42 const std::string& default_name, 43 bool should_replace_extension, 44 ReplaceIllegalCharactersFunction replace_illegal_characters_function); 45 46 // Similar to GenerateFileName(), but takes a function to replace illegal 47 // characters. If |should_replace_extension| is true, the file extension 48 // extracted from a URL will always be considered unreliable and the file 49 // extension will be determined by |mime_type|. 50 base::FilePath GenerateFileNameImpl( 51 const GURL& url, 52 const std::string& content_disposition, 53 const std::string& referrer_charset, 54 const std::string& suggested_name, 55 const std::string& mime_type, 56 const std::string& default_name, 57 bool should_replace_extension, 58 ReplaceIllegalCharactersFunction replace_illegal_characters_function); 59 60 } // namespace net 61 62 #endif // NET_BASE_FILENAME_UTIL_INTERNAL_H_ 63