diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 20:49:39 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 20:49:39 +0000 |
commit | c9b6eb6902766de9edf75921151d225572079a53 (patch) | |
tree | ccc35901d698f4c45ec080ec68f8ecef948f0769 | |
parent | f92cf517a42dd20517370d5cb0a9b61574477f29 (diff) | |
download | chromium_src-c9b6eb6902766de9edf75921151d225572079a53.zip chromium_src-c9b6eb6902766de9edf75921151d225572079a53.tar.gz chromium_src-c9b6eb6902766de9edf75921151d225572079a53.tar.bz2 |
content: Make tab_contents_drag_source not depend on download_util.h
This adds a method to the ContentBrowserClient to get what is otherwise localized resources. Most of this patch changes the interface to net::GenerateFileName() to take a utf8 string instead of a utf16 one (which was immediately changed to a utf8 one in implementation.)
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8113012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106124 0039d316-1c4b-4281-b951-d872f2087c98
19 files changed, 49 insertions, 27 deletions
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc index e3fb174..d24f0e6 100644 --- a/chrome/browser/bookmarks/bookmark_utils.cc +++ b/chrome/browser/bookmarks/bookmark_utils.cc @@ -462,7 +462,7 @@ bool CanPasteFromClipboard(const BookmarkNode* node) { string16 GetNameForURL(const GURL& url) { if (url.is_valid()) { - return net::GetSuggestedFilename(url, "", "", "", "", string16()); + return net::GetSuggestedFilename(url, "", "", "", "", std::string()); } else { return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); } diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 27df907..eafe4e4 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -67,9 +67,11 @@ #include "content/browser/tab_contents/tab_contents_view.h" #include "content/browser/worker_host/worker_process_host.h" #include "content/common/desktop_notification_messages.h" +#include "grit/generated_resources.h" #include "grit/ui_resources.h" #include "net/base/cookie_monster.h" #include "net/base/cookie_options.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #if defined(OS_CHROMEOS) @@ -908,6 +910,10 @@ FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { return download_util::GetDefaultDownloadDirectory(); } +std::string ChromeContentBrowserClient::GetDefaultDownloadName() { + return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); +} + #if defined(OS_LINUX) int ChromeContentBrowserClient::GetCrashSignalFD( const CommandLine& command_line) { diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index c43f352..edfb42e 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -123,6 +123,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { virtual void ClearCache(RenderViewHost* rvh) OVERRIDE; virtual void ClearCookies(RenderViewHost* rvh) OVERRIDE; virtual FilePath GetDefaultDownloadDirectory() OVERRIDE; + virtual std::string GetDefaultDownloadName() OVERRIDE; #if defined(OS_POSIX) && !defined(OS_MACOSX) virtual int GetCrashSignalFD(const CommandLine& command_line) OVERRIDE; diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index f0db7f2..c77b8af 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -97,8 +97,8 @@ void GenerateFileNameInternal(const GURL& url, const std::string& suggested_name, const std::string& mime_type, FilePath* generated_name) { - string16 default_file_name( - l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME)); + std::string default_file_name( + l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); *generated_name = net::GenerateFileName(url, content_disposition, referrer_charset, suggested_name, diff --git a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm index 3e8cfc4..a282fab 100644 --- a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm +++ b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm @@ -71,7 +71,7 @@ FilePath GetFileNameFromDragData(const WebDropData& drop_data) { if (file_name.empty()) { // Retrieve the name from the URL. string16 suggested_filename = - net::GetSuggestedFilename(drop_data.url, "", "", "", "", string16()); + net::GetSuggestedFilename(drop_data.url, "", "", "", "", std::string()); file_name = FilePathFromFilename(suggested_filename); } diff --git a/chrome/browser/ui/gtk/tab_contents_drag_source.cc b/chrome/browser/ui/gtk/tab_contents_drag_source.cc index 6719ede..c29dfa3 100644 --- a/chrome/browser/ui/gtk/tab_contents_drag_source.cc +++ b/chrome/browser/ui/gtk/tab_contents_drag_source.cc @@ -10,7 +10,7 @@ #include "base/mime_util.h" #include "base/threading/thread_restrictions.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/download/download_util.h" +#include "content/browser/content_browser_client.h" #include "content/browser/download/drag_download_file.h" #include "content/browser/download/drag_download_util.h" #include "content/browser/renderer_host/render_view_host.h" @@ -289,12 +289,15 @@ void TabContentsDragSource::OnDragBegin(GtkWidget* sender, GdkDragContext* drag_context) { if (!download_url_.is_empty()) { // Generate the file name based on both mime type and proposed file name. - FilePath generated_download_file_name; - download_util::GenerateFileNameFromSuggestedName( - download_url_, - download_file_name_.value(), - UTF16ToUTF8(wide_download_mime_type_), - &generated_download_file_name); + std::string default_name = + content::GetContentClient()->browser()->GetDefaultDownloadName(); + FilePath generated_download_file_name = + net::GenerateFileName(download_url_, + std::string(), + std::string(), + download_file_name_.value(), + UTF16ToUTF8(wide_download_mime_type_), + default_name); // Pass the file name to the drop target by setting the source window's // XdndDirectSave0 property. diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc index 6ca50a4..7857c4b 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc @@ -232,7 +232,8 @@ void TabContentsDragWin::PrepareDragForFileContents( if (file_name.value().empty()) { // Retrieve the name from the URL. file_name = FilePath( - net::GetSuggestedFilename(drop_data.url, "", "", "", "", string16())); + net::GetSuggestedFilename(drop_data.url, "", "", "", "", + std::string())); if (file_name.value().size() + drop_data.file_extension.size() + 1 > MAX_PATH) { file_name = FilePath(file_name.value().substr( diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h index 29d386e..6715ef8 100644 --- a/content/browser/content_browser_client.h +++ b/content/browser/content_browser_client.h @@ -322,6 +322,10 @@ class ContentBrowserClient { // This can be called on any thread. virtual FilePath GetDefaultDownloadDirectory() = 0; + // Returns the default filename used in downloads when we have no idea what + // else we should do with the file. + virtual std::string GetDefaultDownloadName() = 0; + #if defined(OS_POSIX) && !defined(OS_MACOSX) // Can return an optional fd for crash handling, otherwise returns -1. The // passed |command_line| will be used to start the process in question. diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc index 2574232..308eff2 100644 --- a/content/browser/download/save_package.cc +++ b/content/browser/download/save_package.cc @@ -364,7 +364,7 @@ bool SavePackage::GenerateFileName(const std::string& disposition, // TODO(jungshik): Figure out the referrer charset when having one // makes sense and pass it to GenerateFileName. FilePath file_path = net::GenerateFileName(url, disposition, "", "", "", - ASCIIToUTF16(kDefaultSaveName)); + kDefaultSaveName); DCHECK(!file_path.empty()); FilePath::StringType pure_file_name = diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index f9a49cb..9f6316d 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -278,6 +278,10 @@ FilePath MockContentBrowserClient::GetDefaultDownloadDirectory() { return download_dir_.path(); } +std::string MockContentBrowserClient::GetDefaultDownloadName() { + return std::string(); +} + #if defined(OS_POSIX) && !defined(OS_MACOSX) int MockContentBrowserClient::GetCrashSignalFD( const CommandLine& command_line) { diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index e52956e..c46c4e6 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -130,6 +130,7 @@ class MockContentBrowserClient : public ContentBrowserClient { virtual void ClearCache(RenderViewHost* rvh) OVERRIDE; virtual void ClearCookies(RenderViewHost* rvh) OVERRIDE; virtual FilePath GetDefaultDownloadDirectory() OVERRIDE; + virtual std::string GetDefaultDownloadName() OVERRIDE; #if defined(OS_POSIX) && !defined(OS_MACOSX) virtual int GetCrashSignalFD(const CommandLine& command_line) OVERRIDE; diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 5b60e7f..a97abf5 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -287,6 +287,10 @@ FilePath ShellContentBrowserClient::GetDefaultDownloadDirectory() { return FilePath(); } +std::string ShellContentBrowserClient::GetDefaultDownloadName() { + return "download"; +} + #if defined(OS_POSIX) && !defined(OS_MACOSX) int ShellContentBrowserClient::GetCrashSignalFD( const CommandLine& command_line) { diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index 0fd85db..77aa5df 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -143,6 +143,7 @@ class ShellContentBrowserClient : public ContentBrowserClient virtual void ClearCache(RenderViewHost* rvh) OVERRIDE; virtual void ClearCookies(RenderViewHost* rvh) OVERRIDE; virtual FilePath GetDefaultDownloadDirectory() OVERRIDE; + virtual std::string GetDefaultDownloadName() OVERRIDE; #if defined(OS_POSIX) && !defined(OS_MACOSX) virtual int GetCrashSignalFD(const CommandLine& command_line) OVERRIDE; diff --git a/content/shell/shell_download_manager_delegate.cc b/content/shell/shell_download_manager_delegate.cc index a023d78..3b14c89 100644 --- a/content/shell/shell_download_manager_delegate.cc +++ b/content/shell/shell_download_manager_delegate.cc @@ -53,7 +53,7 @@ bool ShellDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { download->referrer_charset(), download->suggested_filename(), download->mime_type(), - string16(UTF8ToUTF16("download"))); + "download"); // Since we have no download UI, show the user a dialog always. state.prompt_user_for_save_location = true; diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 7ebf0c4..f34f980 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1457,7 +1457,7 @@ string16 GetSuggestedFilename(const GURL& url, const std::string& referrer_charset, const std::string& suggested_name, const std::string& mime_type, - const string16& default_name) { + const std::string& default_name) { // TODO: this function to be updated to match the httpbis recommendations. // Talk to abarth for the latest news. @@ -1507,7 +1507,7 @@ string16 GetSuggestedFilename(const GURL& url, } #if defined(OS_WIN) - string16 path = (filename.empty())? default_name : UTF8ToUTF16(filename); + string16 path = UTF8ToUTF16(filename.empty() ? default_name : filename); // On Windows we want to preserve or replace all characters including // whitespace to prevent file extension obfuscation on trusted websites // e.g. Gmail might think evil.exe. is safe, so we don't want it to become @@ -1521,7 +1521,7 @@ string16 GetSuggestedFilename(const GURL& url, GenerateSafeFileName(mime_type, overwrite_extension, &result); return result.value(); #else - std::string path = (filename.empty())? UTF16ToUTF8(default_name) : filename; + std::string path = filename.empty() ? default_name : filename; file_util::ReplaceIllegalCharactersInPath(&path, '-'); FilePath result(path); GenerateSafeFileName(mime_type, overwrite_extension, &result); @@ -1534,7 +1534,7 @@ FilePath GenerateFileName(const GURL& url, const std::string& referrer_charset, const std::string& suggested_name, const std::string& mime_type, - const string16& default_file_name) { + const std::string& default_file_name) { string16 file_name = GetSuggestedFilename(url, content_disposition, referrer_charset, diff --git a/net/base/net_util.h b/net/base/net_util.h index 2e7a8f0..97406c7 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -276,7 +276,7 @@ NET_EXPORT string16 GetSuggestedFilename(const GURL& url, const std::string& referrer_charset, const std::string& suggested_name, const std::string& mime_type, - const string16& default_name); + const std::string& default_name); // Similar to GetSuggestedFilename(), but returns a FilePath. NET_EXPORT FilePath GenerateFileName(const GURL& url, @@ -284,7 +284,7 @@ NET_EXPORT FilePath GenerateFileName(const GURL& url, const std::string& referrer_charset, const std::string& suggested_name, const std::string& mime_type, - const string16& default_name); + const std::string& default_name); // Ensures that the filename and extension is safe to use in the filesystem. // diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index 414f28d..e971573 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -513,11 +513,7 @@ std::string DumpIPNumber(const IPAddressNumber& v) { void RunGenerateFileNameTestCase(const GenerateFilenameCase* test_case, size_t iteration, const char* suite) { -#if defined(OS_WIN) - string16 default_filename(test_case->default_filename); -#else - string16 default_filename(WideToUTF16(test_case->default_filename)); -#endif + std::string default_filename(WideToUTF8(test_case->default_filename)); FilePath file_path = GenerateFileName( GURL(test_case->url), test_case->content_disp_header, test_case->referrer_charset, test_case->suggested_filename, diff --git a/ui/base/dragdrop/os_exchange_data_provider_win.cc b/ui/base/dragdrop/os_exchange_data_provider_win.cc index ad6d308..17f43f1 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_win.cc +++ b/ui/base/dragdrop/os_exchange_data_provider_win.cc @@ -871,7 +871,8 @@ static void CreateValidFileNameFromTitle(const GURL& url, string16* validated) { if (title.empty()) { if (url.is_valid()) { - *validated = net::GetSuggestedFilename(url, "", "", "", "", string16()); + *validated = net::GetSuggestedFilename(url, "", "", "", "", + std::string()); } else { // Nothing else can be done, just use a default. *validated = diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc index ad28f41..7b4ec9b 100644 --- a/webkit/glue/weburlloader_impl.cc +++ b/webkit/glue/weburlloader_impl.cc @@ -226,7 +226,7 @@ void PopulateURLResponse( std::string value; if (headers->EnumerateHeader(NULL, "content-disposition", &value)) { response->setSuggestedFileName( - net::GetSuggestedFilename(url, value, "", "", "", string16())); + net::GetSuggestedFilename(url, value, "", "", "", std::string())); } Time time_val; |