diff --git a/ohos_nweb/src/capi/nweb_download_item.h b/ohos_nweb/src/capi/nweb_download_item.h index f086ff7c6581196f9b4d98c4d279f363a213ad1d..c6fe66f4ec2b175cc8f85be3f35e0c94cf20e031 100644 --- a/ohos_nweb/src/capi/nweb_download_item.h +++ b/ohos_nweb/src/capi/nweb_download_item.h @@ -120,7 +120,7 @@ struct NWebDownloadItem { std::string original_url_ = download_item->GetOriginalUrl().ToString(); original_url = strdup(original_url_.c_str()); std::string content_disposition_ = - download_item->GetContentDisposition().ToString(); + download_item->GetContentDisposition()->GetStdString(); content_disposition = strdup(content_disposition_.c_str()); std::string mime_type_ = download_item->GetMimeType().ToString(); mime_type = strdup(mime_type_.c_str()); diff --git a/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc index 10f3fdb1c146bfae05babdeea71514b97ba498a2..62593feddf50fee5c892e682a56ebe1258483add 100644 --- a/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc @@ -132,11 +132,15 @@ std::string NWebDownloadHandlerDelegate::GenerateSuggestedFilename( // type under certain condition. std::string default_filename( l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); + std::shared_ptr nweb = NWebImpl::GetNWeb(download_item->GetNWebId()); std::string default_charset = - preference_delegate_ ? preference_delegate_->DefaultTextEncodingFormat() : "utf-8"; + preference_delegate_ ? preference_delegate_->DefaultTextEncodingFormat() : + (nweb ? nweb->GetPreference()->DefaultTextEncodingFormat() : "utf-8"); + LOG(INFO) << "GenerateSuggestedFilename mime_type: " << sniffed_mime_type + << "default_charset: " << default_charset; GURL gurl(download_item->GetURL().ToString()); base::FilePath generated_filename = net::GenerateFileName( - gurl, download_item->GetContentDisposition().ToString(), default_charset, + gurl, download_item->GetContentDisposition()->GetStdString(), default_charset, suggested_filename, sniffed_mime_type, default_filename); // If no mime type or explicitly specified a name, don't replace file @@ -146,7 +150,7 @@ std::string NWebDownloadHandlerDelegate::GenerateSuggestedFilename( // Trust content disposition header filename attribute. net::HttpContentDisposition content_disposition_header( - download_item->GetContentDisposition(), default_charset); + download_item->GetContentDisposition()->GetStdString(), default_charset); if (!content_disposition_header.filename().empty()) return generated_filename.AsUTF8Unsafe(); diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc index ae1c40555e6f510982173ad9261e97ca92020435..4d51a868ca67a5e347f44337bbd90ca5ae877d22 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc @@ -1713,7 +1713,7 @@ void NWebHandlerDelegate::OnBeforeDownload( download_listener_->OnDownloadStart( download_item->GetURL().ToString(), browser->GetHost()->DefaultUserAgent(), - download_item->GetContentDisposition().ToString(), + download_item->GetContentDisposition()->GetStdString(), download_item->GetMimeType().ToString(), download_item->GetTotalBytes()); }