filename_util_internal.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2014 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. // Functions used internally by filename_util, and filename_util_icu.
  5. #ifndef NET_BASE_FILENAME_UTIL_INTERNAL_H_
  6. #define NET_BASE_FILENAME_UTIL_INTERNAL_H_
  7. #include <string>
  8. #include "base/files/file_path.h"
  9. class GURL;
  10. namespace net {
  11. using ReplaceIllegalCharactersFunction =
  12. void (*)(base::FilePath::StringType* file_name, char replace_char);
  13. void SanitizeGeneratedFileName(base::FilePath::StringType* filename,
  14. bool replace_trailing);
  15. bool IsShellIntegratedExtension(const base::FilePath::StringType& extension);
  16. void EnsureSafeExtension(const std::string& mime_type,
  17. bool ignore_extension,
  18. base::FilePath* file_name);
  19. bool FilePathToString16(const base::FilePath& path, std::u16string* converted);
  20. // Similar to GetSuggestedFilename(), but takes a function to replace illegal
  21. // characters. If |should_replace_extension| is true, the file extension
  22. // extracted from a URL will always be considered unreliable and the file
  23. // extension will be determined by |mime_type|.
  24. std::u16string GetSuggestedFilenameImpl(
  25. const GURL& url,
  26. const std::string& content_disposition,
  27. const std::string& referrer_charset,
  28. const std::string& suggested_name,
  29. const std::string& mime_type,
  30. const std::string& default_name,
  31. bool should_replace_extension,
  32. ReplaceIllegalCharactersFunction replace_illegal_characters_function);
  33. // Similar to GenerateFileName(), but takes a function to replace illegal
  34. // characters. If |should_replace_extension| is true, the file extension
  35. // extracted from a URL will always be considered unreliable and the file
  36. // extension will be determined by |mime_type|.
  37. base::FilePath GenerateFileNameImpl(
  38. const GURL& url,
  39. const std::string& content_disposition,
  40. const std::string& referrer_charset,
  41. const std::string& suggested_name,
  42. const std::string& mime_type,
  43. const std::string& default_name,
  44. bool should_replace_extension,
  45. ReplaceIllegalCharactersFunction replace_illegal_characters_function);
  46. } // namespace net
  47. #endif // NET_BASE_FILENAME_UTIL_INTERNAL_H_