file_name.cc 835 B

12345678910111213141516171819202122232425
  1. // Copyright 2021 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. #include "pdf/ui/file_name.h"
  5. #include <string>
  6. #include "base/strings/utf_string_conversions.h"
  7. #include "net/base/filename_util.h"
  8. #include "url/gurl.h"
  9. namespace chrome_pdf {
  10. std::string GetFileNameForSaveFromUrl(const std::string& url) {
  11. // Generate a file name. Unfortunately, MIME type can't be provided, since it
  12. // requires IO.
  13. std::u16string file_name = net::GetSuggestedFilename(
  14. GURL(url), /*content_disposition=*/std::string(),
  15. /*referrer_charset=*/std::string(), /*suggested_name=*/std::string(),
  16. /*mime_type=*/std::string(), /*default_name=*/std::string());
  17. return base::UTF16ToUTF8(file_name);
  18. }
  19. } // namespace chrome_pdf