diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-06 18:08:34 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-06 18:08:34 +0000 |
commit | 561abe688fc5ebcec902ea6cc2ccb4122441595e (patch) | |
tree | 5d5b001676b82c824d22619f0cc3a92b22648ab2 /chrome/browser | |
parent | 5ce729688e2b16ebc97decb032175ba230855c1d (diff) | |
download | chromium_src-561abe688fc5ebcec902ea6cc2ccb4122441595e.zip chromium_src-561abe688fc5ebcec902ea6cc2ccb4122441595e.tar.gz chromium_src-561abe688fc5ebcec902ea6cc2ccb4122441595e.tar.bz2 |
First pass of refactoring dialogs.
Review URL: http://codereview.chromium.org/60110
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
23 files changed, 148 insertions, 140 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 119c5aa..5d2fa70 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -282,7 +282,7 @@ void Browser::CreateBrowserWindow() { window_->GetLocationBar()->ShowFirstRunBubble(); } -#if defined(OS_WIN) +#if defined(OS_WIN) FindBar* find_bar = BrowserWindow::CreateFindBar(this); find_bar_controller_.reset(new FindBarController(find_bar)); find_bar->SetFindBarController(find_bar_controller_.get()); @@ -953,8 +953,8 @@ void Browser::OpenFile() { // TODO(beng): figure out how to juggle this. gfx::NativeWindow parent_window = window_->GetNativeHandle(); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, - std::wstring(), std::wstring(), - std::wstring(), 0, std::wstring(), + string16(), FilePath(), + std::wstring(), 0, FILE_PATH_LITERAL(""), parent_window, NULL); } #endif @@ -1952,8 +1952,8 @@ void Browser::RenderWidgetShowing() { /////////////////////////////////////////////////////////////////////////////// // Browser, SelectFileDialog::Listener implementation: -void Browser::FileSelected(const std::wstring& path, int index, void* params) { - GURL file_url = net::FilePathToFileURL(path); +void Browser::FileSelected(const FilePath& path, int index, void* params) { + GURL file_url = net::FilePathToFileURL(path.ToWStringHack()); if (!file_url.is_empty()) OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); } diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 89fb4ef..57e7171 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -449,7 +449,7 @@ class Browser : public TabStripModelDelegate, virtual void RenderWidgetShowing(); // Overridden from SelectFileDialog::Listener: - virtual void FileSelected(const std::wstring& path, int index, void* params); + virtual void FileSelected(const FilePath& path, int index, void* params); // Overridden from NotificationObserver: virtual void Observe(NotificationType type, diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index db76181..34fe0cf 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -645,9 +645,9 @@ void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { gfx::NativeWindow owning_window = contents ? platform_util::GetTopLevel(contents->GetNativeView()) : NULL; select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, - std::wstring(), - info->suggested_path.ToWStringHack(), - filter, 0, std::wstring(), + string16(), + info->suggested_path, + filter, 0, FILE_PATH_LITERAL(""), owning_window, info); } else { // No prompting for download, just continue with the suggested name. @@ -1357,9 +1357,8 @@ void DownloadManager::SaveAutoOpens() { } } -void DownloadManager::FileSelected(const std::wstring& path_string, +void DownloadManager::FileSelected(const FilePath& path, int index, void* params) { - FilePath path = FilePath::FromWStringHack(path_string); DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params); if (info->save_as) last_download_path_ = path.DirName(); diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 5712d95..37906d3 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -411,7 +411,7 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // Overridden from SelectFileDialog::Listener: // TODO(port): convert this to FilePath when SelectFileDialog gets converted. - virtual void FileSelected(const std::wstring& path, int index, void* params); + virtual void FileSelected(const FilePath& path, int index, void* params); virtual void FileSelectionCanceled(void* params); // Deletes the specified path on the file thread. diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 1504ae8..b54f060 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -997,12 +997,11 @@ void SavePackage::GetSaveInfo() { // Use "Web Page, Complete" option as default choice of saving page. int filter_index = 2; std::wstring filter; - std::wstring default_extension; + FilePath::StringType default_extension; FilePath title = FilePath::FromWStringHack(UTF16ToWideHack(web_contents_->GetTitle())); FilePath suggested_path = GetSuggestNameForSaveAs(web_contents_->profile()->GetPrefs(), title); - std::wstring suggested_name = suggested_path.ToWStringHack(); SavePackageParam* save_params = new SavePackageParam(web_contents_->contents_mime_type()); @@ -1014,10 +1013,10 @@ void SavePackage::GetSaveInfo() { filter.resize(filter.size() + 2); filter[filter.size() - 1] = L'\0'; filter[filter.size() - 2] = L'\0'; - default_extension = L"htm"; + default_extension = FILE_PATH_LITERAL("htm"); } else { #if defined(OS_WIN) - filter = win_util::GetFileFilterFromPath(suggested_name); + filter = win_util::GetFileFilterFromPath(suggested_path.ToWStringHack()); #else // TODO(port): implement this. NOTIMPLEMENTED(); @@ -1031,8 +1030,8 @@ void SavePackage::GetSaveInfo() { if (!select_file_dialog_.get()) select_file_dialog_ = SelectFileDialog::Create(this); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, - std::wstring(), - suggested_name, + string16(), + suggested_path, filter, filter_index, default_extension, @@ -1043,17 +1042,17 @@ void SavePackage::GetSaveInfo() { #endif // defined(OS_LINUX) || defined(OS_WIN) { // Just use 'suggested_name' instead of opening the dialog prompt. - ContinueSave(save_params, suggested_name, filter_index); + ContinueSave(save_params, suggested_path, filter_index); delete save_params; } } // Called after the save file dialog box returns. void SavePackage::ContinueSave(SavePackageParam* param, - const std::wstring& final_name, + const FilePath& final_name, int index) { // Ensure the filename is safe. - param->saved_main_file_path = FilePath::FromWStringHack(final_name); + param->saved_main_file_path = final_name; DownloadManager* dlm = web_contents_->profile()->GetDownloadManager(); DCHECK(dlm); dlm->GenerateSafeFilename(param->current_tab_mime_type, @@ -1142,7 +1141,7 @@ bool SavePackage::GetSafePureFileName(const FilePath& dir_path, } // SelectFileDialog::Listener interface. -void SavePackage::FileSelected(const std::wstring& path, +void SavePackage::FileSelected(const FilePath& path, int index, void* params) { SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); ContinueSave(save_params, path, index); diff --git a/chrome/browser/download/save_package.h b/chrome/browser/download/save_package.h index 5f86a98..5a42fe3 100644 --- a/chrome/browser/download/save_package.h +++ b/chrome/browser/download/save_package.h @@ -137,7 +137,7 @@ class SavePackage : public base::RefCountedThreadSafe<SavePackage>, void GetSaveInfo(); void ContinueSave(SavePackageParam* param, - const std::wstring& final_name, + const FilePath& final_name, int index); // RenderViewHostDelegate::Save ---------------------------------------------- @@ -203,7 +203,7 @@ class SavePackage : public base::RefCountedThreadSafe<SavePackage>, FilePath::StringType* pure_file_name); // SelectFileDialog::Listener interface. - virtual void FileSelected(const std::wstring& path, int index, void* params); + virtual void FileSelected(const FilePath& path, int index, void* params); virtual void FileSelectionCanceled(void* params); private: diff --git a/chrome/browser/gtk/dialogs_gtk.cc b/chrome/browser/gtk/dialogs_gtk.cc index 97b8684..d7b6350 100644 --- a/chrome/browser/gtk/dialogs_gtk.cc +++ b/chrome/browser/gtk/dialogs_gtk.cc @@ -30,11 +30,11 @@ class SelectFileDialogImpl : public SelectFileDialog { // SelectFileDialog implementation. // |params| is user data we pass back via the Listener interface. - virtual void SelectFile(Type type, const std::wstring& title, - const std::wstring& default_path, + virtual void SelectFile(Type type, const string16& title, + const FilePath& default_path, const std::wstring& filter, int filter_index, - const std::wstring& default_extension, + const FilePath::StringType& default_extension, gfx::NativeWindow parent_window, void* params); @@ -43,9 +43,8 @@ class SelectFileDialogImpl : public SelectFileDialog { void FileSelected(GtkWidget* dialog, const FilePath& path); // Notifies the listener that multiple files were chosen. - // TODO(estade): this should deal in FilePaths. void MultiFilesSelected(GtkWidget* dialog, - const std::vector<std::wstring>& files); + const std::vector<FilePath>& files); // Notifies the listener that no file was chosen (the action was canceled). // Dialog is passed so we can find that |params| pointer that was passed to @@ -119,11 +118,11 @@ void SelectFileDialogImpl::ListenerDestroyed() { // TODO(estade): use |filter|. void SelectFileDialogImpl::SelectFile( Type type, - const std::wstring& title, - const std::wstring& default_path, + const string16& title, + const FilePath& default_path, const std::wstring& filter, int filter_index, - const std::wstring& default_extension, + const FilePath::StringType& default_extension, gfx::NativeWindow parent_window, void* params) { // TODO(estade): on windows, parent_window may be null. But I'm not sure when @@ -131,10 +130,7 @@ void SelectFileDialogImpl::SelectFile( DCHECK(parent_window); parents_.insert(parent_window); - // TODO(port): get rid of these conversions when the parameter types are - // ported. - std::string title_string = WideToUTF8(title); - FilePath default_file_path = FilePath::FromWStringHack(default_path); + std::string title_string = UTF16ToUTF8(title); GtkWidget* dialog = NULL; switch (type) { @@ -147,8 +143,7 @@ void SelectFileDialogImpl::SelectFile( dialog = CreateMultiFileOpenDialog(title_string, parent_window); break; case SELECT_SAVEAS_FILE: - dialog = CreateSaveAsDialog(title_string, default_file_path, - parent_window); + dialog = CreateSaveAsDialog(title_string, default_path, parent_window); break; default: NOTIMPLEMENTED() << "Dialog type " << type << " not implemented."; @@ -164,13 +159,13 @@ void SelectFileDialogImpl::FileSelected(GtkWidget* dialog, const FilePath& path) { void* params = PopParamsForDialog(dialog); if (listener_) - listener_->FileSelected(path.ToWStringHack(), 1, params); + listener_->FileSelected(path, 1, params); RemoveParentForDialog(dialog); gtk_widget_destroy(dialog); } void SelectFileDialogImpl::MultiFilesSelected(GtkWidget* dialog, - const std::vector<std::wstring>& files) { + const std::vector<FilePath>& files) { void* params = PopParamsForDialog(dialog); if (listener_) listener_->MultiFilesSelected(files, params); @@ -285,13 +280,12 @@ void SelectFileDialogImpl::OnSelectMultiFileDialogResponse( } GSList* filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); - std::vector<std::wstring> filenames_w; + std::vector<FilePath> filenames_fp; for (GSList* iter = filenames; iter != NULL; iter = g_slist_next(iter)) { - filenames_w.push_back(base::SysNativeMBToWide( - static_cast<char*>(iter->data))); + filenames_fp.push_back(FilePath(static_cast<char*>(iter->data))); g_free(iter->data); } g_slist_free(filenames); - dialog_impl->MultiFilesSelected(dialog, filenames_w); + dialog_impl->MultiFilesSelected(dialog, filenames_fp); } diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 271df03..749f93c 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -402,7 +402,7 @@ void RenderViewHost::DragTargetDragEnter(const WebDropData& drop_data, iter(drop_data.filenames.begin()); iter != drop_data.filenames.end(); ++iter) { policy->GrantRequestURL(process()->pid(), net::FilePathToFileURL(*iter)); - policy->GrantUploadFile(process()->pid(), *iter); + policy->GrantUploadFile(process()->pid(), FilePath::FromWStringHack(*iter)); } Send(new ViewMsg_DragTargetDragEnter(routing_id(), drop_data, client_pt, screen_pt)); @@ -638,17 +638,17 @@ void RenderViewHost::InstallMissingPlugin() { Send(new ViewMsg_InstallMissingPlugin(routing_id())); } -void RenderViewHost::FileSelected(const std::wstring& path) { +void RenderViewHost::FileSelected(const FilePath& path) { RendererSecurityPolicy::GetInstance()->GrantUploadFile(process()->pid(), path); - std::vector<std::wstring> files; + std::vector<FilePath> files; files.push_back(path); Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); } void RenderViewHost::MultiFilesSelected( - const std::vector<std::wstring>& files) { - for (std::vector<std::wstring>::const_iterator file = files.begin(); + const std::vector<FilePath>& files) { + for (std::vector<FilePath>::const_iterator file = files.begin(); file != files.end(); ++file) { RendererSecurityPolicy::GetInstance()->GrantUploadFile( process()->pid(), *file); diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 68fe3c2..1923aff 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -370,11 +370,11 @@ class RenderViewHost : public RenderWidgetHost { // Notifies the RenderViewHost that a file has been chosen by the user from // an Open File dialog for the form. - void FileSelected(const std::wstring& path); + void FileSelected(const FilePath& path); // Notifies the Listener that many files have been chosen by the user from // an Open File dialog for the form. - void MultiFilesSelected(const std::vector<std::wstring>& files); + void MultiFilesSelected(const std::vector<FilePath>& files); // Notifies the RenderViewHost that its load state changed. void LoadStateChanged(const GURL& url, net::LoadState load_state); diff --git a/chrome/browser/renderer_host/renderer_security_policy.cc b/chrome/browser/renderer_host/renderer_security_policy.cc index 753dff8..fd34ef6 100644 --- a/chrome/browser/renderer_host/renderer_security_policy.cc +++ b/chrome/browser/renderer_host/renderer_security_policy.cc @@ -4,6 +4,7 @@ #include "chrome/browser/renderer_host/renderer_security_policy.h" +#include "base/file_path.h" #include "base/logging.h" #include "base/string_util.h" #include "chrome/common/url_constants.h" @@ -30,7 +31,7 @@ class RendererSecurityPolicy::SecurityState { } // Grant permission to upload the specified file to the web. - void GrantUploadFile(const std::wstring& file) { + void GrantUploadFile(const FilePath& file) { uploadable_files_.insert(file); } @@ -51,7 +52,7 @@ class RendererSecurityPolicy::SecurityState { // Determine whether permission has been granted to upload file. // Files that have not been granted default to being denied. - bool CanUploadFile(const std::wstring& file) { + bool CanUploadFile(const FilePath& file) { return uploadable_files_.find(file) != uploadable_files_.end(); } @@ -59,7 +60,7 @@ class RendererSecurityPolicy::SecurityState { private: typedef std::map<std::string, bool> SchemeMap; - typedef std::set<std::wstring> FileSet; + typedef std::set<FilePath> FileSet; // Maps URL schemes to whether permission has been granted or revoked: // |true| means the scheme has been granted. @@ -181,7 +182,7 @@ void RendererSecurityPolicy::GrantRequestURL(int renderer_id, const GURL& url) { } void RendererSecurityPolicy::GrantUploadFile(int renderer_id, - const std::wstring& file) { + const FilePath& file) { AutoLock lock(lock_); SecurityStateMap::iterator state = security_state_.find(renderer_id); @@ -266,7 +267,7 @@ bool RendererSecurityPolicy::CanRequestURL(int renderer_id, const GURL& url) { } bool RendererSecurityPolicy::CanUploadFile(int renderer_id, - const std::wstring& file) { + const FilePath& file) { AutoLock lock(lock_); SecurityStateMap::iterator state = security_state_.find(renderer_id); diff --git a/chrome/browser/renderer_host/renderer_security_policy.h b/chrome/browser/renderer_host/renderer_security_policy.h index a726d28..2064700 100644 --- a/chrome/browser/renderer_host/renderer_security_policy.h +++ b/chrome/browser/renderer_host/renderer_security_policy.h @@ -13,6 +13,7 @@ #include "base/lock.h" #include "base/singleton.h" +class FilePath; class GURL; // The RendererSecurityPolicy class is used to grant and revoke security @@ -61,7 +62,7 @@ class RendererSecurityPolicy { // Whenever the user picks a file from a <input type="file"> element, the // browser should call this function to grant the renderer the capability to // upload the file to the web. - void GrantUploadFile(int renderer_id, const std::wstring& file); + void GrantUploadFile(int renderer_id, const FilePath& file); // Whenever the browser processes commands the renderer to run web inspector, // it should call this method to grant the renderer process the capability to @@ -79,7 +80,7 @@ class RendererSecurityPolicy { // Before servicing a renderer's request to upload a file to the web, the // browser should call this method to determine whether the renderer has the // capability to upload the requested file. - bool CanUploadFile(int renderer_id, const std::wstring& file); + bool CanUploadFile(int renderer_id, const FilePath& file); // Returns true of the specified renderer_id has been granted DOMUIBindings. // The browser should check this property before assuming the renderer is diff --git a/chrome/browser/renderer_host/renderer_security_policy_unittest.cc b/chrome/browser/renderer_host/renderer_security_policy_unittest.cc index 42c90bd..464abc8 100644 --- a/chrome/browser/renderer_host/renderer_security_policy_unittest.cc +++ b/chrome/browser/renderer_host/renderer_security_policy_unittest.cc @@ -5,6 +5,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_path.h" #include "chrome/browser/renderer_host/renderer_security_policy.h" #include "chrome/common/url_constants.h" #include "net/url_request/url_request.h" @@ -189,16 +190,21 @@ TEST_F(RendererSecurityPolicyTest, CanUploadFiles) { p->Add(kRendererID); - EXPECT_FALSE(p->CanUploadFile(kRendererID, L"/etc/passwd")); - p->GrantUploadFile(kRendererID, L"/etc/passwd"); - EXPECT_TRUE(p->CanUploadFile(kRendererID, L"/etc/passwd")); - EXPECT_FALSE(p->CanUploadFile(kRendererID, L"/etc/shadow")); + EXPECT_FALSE(p->CanUploadFile(kRendererID, + FilePath(FILE_PATH_LITERAL("/etc/passwd")))); + p->GrantUploadFile(kRendererID, FilePath(FILE_PATH_LITERAL("/etc/passwd"))); + EXPECT_TRUE(p->CanUploadFile(kRendererID, + FilePath(FILE_PATH_LITERAL("/etc/passwd")))); + EXPECT_FALSE(p->CanUploadFile(kRendererID, + FilePath(FILE_PATH_LITERAL("/etc/shadow")))); p->Remove(kRendererID); p->Add(kRendererID); - EXPECT_FALSE(p->CanUploadFile(kRendererID, L"/etc/passwd")); - EXPECT_FALSE(p->CanUploadFile(kRendererID, L"/etc/shadow")); + EXPECT_FALSE(p->CanUploadFile(kRendererID, + FilePath(FILE_PATH_LITERAL("/etc/passwd")))); + EXPECT_FALSE(p->CanUploadFile(kRendererID, + FilePath(FILE_PATH_LITERAL("/etc/shadow")))); p->Remove(kRendererID); } @@ -237,7 +243,7 @@ TEST_F(RendererSecurityPolicyTest, RemoveRace) { RendererSecurityPolicy* p = RendererSecurityPolicy::GetInstance(); GURL url("file:///etc/passwd"); - std::wstring file(L"/etc/passwd"); + FilePath file(FILE_PATH_LITERAL("/etc/passwd")); p->Add(kRendererID); diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 8293a3e..b2b2c73 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -122,7 +122,8 @@ bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type, std::vector<net::UploadData::Element>::const_iterator iter; for (iter = uploads.begin(); iter != uploads.end(); ++iter) { if (iter->type() == net::UploadData::TYPE_FILE && - !policy->CanUploadFile(process_id, iter->file_path())) { + !policy->CanUploadFile(process_id, + FilePath::FromWStringHack(iter->file_path()))) { NOTREACHED() << "Denied unauthorized upload of " << iter->file_path(); return false; } diff --git a/chrome/browser/shell_dialogs.h b/chrome/browser/shell_dialogs.h index 162b45f..4975395 100644 --- a/chrome/browser/shell_dialogs.h +++ b/chrome/browser/shell_dialogs.h @@ -8,8 +8,10 @@ #include <string> #include <vector> +#include "base/file_path.h" #include "base/gfx/native_widget_types.h" #include "base/ref_counted.h" +#include "base/string16.h" class ChromeFont; @@ -51,13 +53,13 @@ class SelectFileDialog // file/folder path is in |path|. |params| is contextual passed to // SelectFile. |index| specifies the index of the filter passed to the // the initial call to SelectFile. - virtual void FileSelected(const std::wstring& path, + virtual void FileSelected(const FilePath& path, int index, void* params) = 0; // Notifies the Listener that many files have been selected. The // files are in |files|. |params| is contextual passed to SelectFile. virtual void MultiFilesSelected( - const std::vector<std::wstring>& files, void* params) {}; + const std::vector<FilePath>& files, void* params) {}; // Notifies the Listener that the file/folder selection was aborted (via // the user canceling or closing the selection dialog box, for example). @@ -95,11 +97,11 @@ class SelectFileDialog // NOTE: only one instance of any shell dialog can be shown per owning_window // at a time (for obvious reasons). virtual void SelectFile(Type type, - const std::wstring& title, - const std::wstring& default_path, + const string16& title, + const FilePath& default_path, const std::wstring& filter, int filter_index, - const std::wstring& default_extension, + const FilePath::StringType& default_extension, gfx::NativeWindow owning_window, void* params) = 0; }; diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 3ac939a..db87eb9 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -1142,8 +1142,8 @@ void WebContents::GetHistoryListCount(int* back_list_count, } void WebContents::RunFileChooser(bool multiple_files, - const std::wstring& title, - const std::wstring& default_file, + const string16& title, + const FilePath& default_file, const std::wstring& filter) { if (!select_file_dialog_.get()) select_file_dialog_ = SelectFileDialog::Create(this); @@ -1151,7 +1151,7 @@ void WebContents::RunFileChooser(bool multiple_files, multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE : SelectFileDialog::SELECT_OPEN_FILE; select_file_dialog_->SelectFile(dialog_type, title, default_file, - filter, 0, std::wstring(), + filter, 0, FILE_PATH_LITERAL(""), view_->GetTopLevelNativeWindow(), NULL); } @@ -1566,12 +1566,12 @@ bool WebContents::CanTerminate() const { return !delegate()->IsExternalTabContainer(); } -void WebContents::FileSelected(const std::wstring& path, +void WebContents::FileSelected(const FilePath& path, int index, void* params) { render_view_host()->FileSelected(path); } -void WebContents::MultiFilesSelected(const std::vector<std::wstring>& files, +void WebContents::MultiFilesSelected(const std::vector<FilePath>& files, void* params) { render_view_host()->MultiFilesSelected(files); } @@ -1579,7 +1579,7 @@ void WebContents::MultiFilesSelected(const std::vector<std::wstring>& files, void WebContents::FileSelectionCanceled(void* params) { // If the user cancels choosing a file to upload we pass back an // empty vector. - render_view_host()->MultiFilesSelected(std::vector<std::wstring>()); + render_view_host()->MultiFilesSelected(std::vector<FilePath>()); } void WebContents::BeforeUnloadFiredFromRenderManager( diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index ae40d89..7663712 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -369,8 +369,8 @@ class WebContents : public TabContents, virtual void GetHistoryListCount(int* back_list_count, int* forward_list_count); virtual void RunFileChooser(bool multiple_files, - const std::wstring& title, - const std::wstring& default_file, + const string16& title, + const FilePath& default_file, const std::wstring& filter); virtual void RunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, @@ -432,8 +432,8 @@ class WebContents : public TabContents, // SelectFileDialog::Listener ------------------------------------------------ - virtual void FileSelected(const std::wstring& path, int index, void* params); - virtual void MultiFilesSelected(const std::vector<std::wstring>& files, + virtual void FileSelected(const FilePath& path, int index, void* params); + virtual void MultiFilesSelected(const std::vector<FilePath>& files, void* params); virtual void FileSelectionCanceled(void* params); diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc index bc0b344..b9fccb1a 100644 --- a/chrome/browser/views/bookmark_manager_view.cc +++ b/chrome/browser/views/bookmark_manager_view.cc @@ -517,7 +517,7 @@ void BookmarkManagerView::ExecuteCommand(int id) { } } -void BookmarkManagerView::FileSelected(const std::wstring& path, +void BookmarkManagerView::FileSelected(const FilePath& path, int index, void* params) { int id = reinterpret_cast<int>(params); @@ -526,7 +526,7 @@ void BookmarkManagerView::FileSelected(const std::wstring& path, ImporterHost* host = new ImporterHost(); ProfileInfo profile_info; profile_info.browser_type = BOOKMARKS_HTML; - profile_info.source_path = path; + profile_info.source_path = path.ToWStringHack(); StartImportingWithUI(GetWidget()->GetNativeView(), FAVORITES, host, profile_info, profile_, new ImportObserverImpl(profile()), false); @@ -534,7 +534,7 @@ void BookmarkManagerView::FileSelected(const std::wstring& path, if (g_browser_process->io_thread()) { bookmark_html_writer::WriteBookmarks( g_browser_process->io_thread()->message_loop(), GetBookmarkModel(), - path); + path.ToWStringHack()); } } else { NOTREACHED(); @@ -718,8 +718,10 @@ void BookmarkManagerView::ShowImportBookmarksFileChooser() { win_util::GetFileFilterFromExtensions(L"*.html;*.htm", true); select_file_dialog_ = SelectFileDialog::Create(this); select_file_dialog_->SelectFile( - SelectFileDialog::SELECT_OPEN_FILE, std::wstring(), L"bookmarks.html", - filter_string, 0, std::wstring(), GetWidget()->GetNativeView(), + SelectFileDialog::SELECT_OPEN_FILE, std::wstring(), + FilePath(FILE_PATH_LITERAL("bookmarks.html")), filter_string, 0, + std::wstring(), + GetWidget()->GetNativeView(), reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_IMPORT_MENU)); } @@ -729,7 +731,8 @@ void BookmarkManagerView::ShowExportBookmarksFileChooser() { select_file_dialog_ = SelectFileDialog::Create(this); select_file_dialog_->SelectFile( - SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(), L"bookmarks.html", + SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(), + FilePath(FILE_PATH_LITERAL("bookmarks.html")), win_util::GetFileFilterFromPath(L"bookmarks.html"), 0, L"html", GetWidget()->GetNativeView(), reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU)); diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h index e9233e8..bf0826a 100644 --- a/chrome/browser/views/bookmark_manager_view.h +++ b/chrome/browser/views/bookmark_manager_view.h @@ -153,7 +153,7 @@ class BookmarkManagerView : public views::View, virtual void ExecuteCommand(int id); // SelectFileDialog::Listener. - virtual void FileSelected(const std::wstring& path, + virtual void FileSelected(const FilePath& path, int index, void* params); virtual void FileSelectionCanceled(void* params); diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc index 4072111..e6966e0 100644 --- a/chrome/browser/views/options/content_page_view.cc +++ b/chrome/browser/views/options/content_page_view.cc @@ -194,11 +194,11 @@ ContentPageView::~ContentPageView() { //////////////////////////////////////////////////////////////////////////////// // ContentPageView, SelectFileDialog::Listener implementation: -void ContentPageView::FileSelected(const std::wstring& path, +void ContentPageView::FileSelected(const FilePath& path, int index, void* params) { UserMetricsRecordAction(L"Options_SetDownloadDirectory", profile()->GetPrefs()); - default_download_location_.SetValue(path); + default_download_location_.SetValue(path.ToWStringHack()); // We need to call this manually here since because we're setting the value // through the pref member which avoids notifying the listener that set the // value. @@ -214,8 +214,9 @@ void ContentPageView::ButtonPressed(views::Button* sender) { l10n_util::GetString(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, dialog_title, - profile()->GetPrefs()->GetString( - prefs::kDownloadDefaultDirectory), + FilePath::FromWStringHack( + profile()->GetPrefs()->GetString( + prefs::kDownloadDefaultDirectory)), std::wstring(), 0, std::wstring(), GetRootWindow(), NULL); diff --git a/chrome/browser/views/options/content_page_view.h b/chrome/browser/views/options/content_page_view.h index f7b6b28..98d2030 100644 --- a/chrome/browser/views/options/content_page_view.h +++ b/chrome/browser/views/options/content_page_view.h @@ -34,7 +34,7 @@ class ContentPageView : public OptionsPageView, virtual void ButtonPressed(views::Button* sender); // SelectFileDialog::Listener implementation: - virtual void FileSelected(const std::wstring& path, int index, void* params); + virtual void FileSelected(const FilePath& path, int index, void* params); // OptionsPageView implementation: virtual bool CanClose() const; diff --git a/chrome/browser/views/shell_dialogs_win.cc b/chrome/browser/views/shell_dialogs_win.cc index 746073b..b4df9ed 100644 --- a/chrome/browser/views/shell_dialogs_win.cc +++ b/chrome/browser/views/shell_dialogs_win.cc @@ -192,11 +192,11 @@ class SelectFileDialogImpl : public SelectFileDialog, virtual ~SelectFileDialogImpl(); // SelectFileDialog implementation: - virtual void SelectFile(Type type, const std::wstring& title, - const std::wstring& default_path, + virtual void SelectFile(Type type, const string16& title, + const FilePath& default_path, const std::wstring& filter, int filter_index, - const std::wstring& default_extension, + const FilePath::StringType& default_extension, HWND owning_hwnd, void* params); virtual bool IsRunning(HWND owning_hwnd) const; @@ -207,7 +207,7 @@ class SelectFileDialogImpl : public SelectFileDialog, struct ExecuteSelectParams { ExecuteSelectParams(Type type, const std::wstring& title, - const std::wstring& default_path, + const FilePath& default_path, const std::wstring& filter, int filter_index, const std::wstring& default_extension, @@ -220,7 +220,7 @@ class SelectFileDialogImpl : public SelectFileDialog, } SelectFileDialog::Type type; std::wstring title; - std::wstring default_path; + FilePath default_path; std::wstring filter; int filter_index; std::wstring default_extension; @@ -234,11 +234,11 @@ class SelectFileDialogImpl : public SelectFileDialog, void ExecuteSelectFile(const ExecuteSelectParams& params); // Notifies the listener that a folder was chosen. Run on the ui thread. - void FileSelected(const std::wstring& path, int index, + void FileSelected(const FilePath& path, int index, void* params, RunState run_state); // Notifies listener that multiple files were chosen. Run on the ui thread. - void MultiFilesSelected(const std::vector<std::wstring>& paths, void* params, + void MultiFilesSelected(const std::vector<FilePath>& paths, void* params, RunState run_state); // Notifies the listener that no file was chosen (the action was canceled). @@ -252,21 +252,21 @@ class SelectFileDialogImpl : public SelectFileDialog, // dialog thread. bool RunSelectFolderDialog(const std::wstring& title, HWND owner, - std::wstring* path); + FilePath* path); // Runs an Open file dialog box, with similar semantics for input paramaters // as RunSelectFolderDialog. bool RunOpenFileDialog(const std::wstring& title, const std::wstring& filters, HWND owner, - std::wstring* path); + FilePath* path); // Runs an Open file dialog box that supports multi-select, with similar // semantics for input paramaters as RunOpenFileDialog. bool RunOpenMultiFileDialog(const std::wstring& title, const std::wstring& filter, HWND owner, - std::vector<std::wstring>* paths); + std::vector<FilePath>* paths); // The callback function for when the select folder dialog is opened. static int CALLBACK BrowseCallbackProc(HWND window, UINT message, @@ -287,16 +287,17 @@ SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener) SelectFileDialogImpl::~SelectFileDialogImpl() { } -void SelectFileDialogImpl::SelectFile(Type type, - const std::wstring& title, - const std::wstring& default_path, - const std::wstring& filter, - int filter_index, - const std::wstring& default_extension, - HWND owner, - void* params) { - ExecuteSelectParams execute_params(type, title, default_path, filter, - filter_index, default_extension, +void SelectFileDialogImpl::SelectFile( + Type type, + const string16& title, + const FilePath& default_path, + const std::wstring& filter, + int filter_index, + const FilePath::StringType& default_extension, + HWND owner, + void* params) { + ExecuteSelectParams execute_params(type, UTF16ToWide(title), default_path, + filter, filter_index, default_extension, BeginRun(owner), owner, params); execute_params.run_state.dialog_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &SelectFileDialogImpl::ExecuteSelectFile, @@ -315,7 +316,7 @@ void SelectFileDialogImpl::ListenerDestroyed() { void SelectFileDialogImpl::ExecuteSelectFile( const ExecuteSelectParams& params) { - std::wstring path = params.default_path; + FilePath path = params.default_path; bool success = false; unsigned filter_index = params.filter_index; if (params.type == SELECT_FOLDER) { @@ -324,14 +325,14 @@ void SelectFileDialogImpl::ExecuteSelectFile( &path); } else if (params.type == SELECT_SAVEAS_FILE) { success = win_util::SaveFileAsWithFilter(params.run_state.owner, - params.default_path, params.filter, params.default_extension, false, - &filter_index, &path); + params.default_path.ToWStringHack(), params.filter, + params.default_extension, false, &filter_index, &path.ToWStringHack()); DisableOwner(params.run_state.owner); } else if (params.type == SELECT_OPEN_FILE) { success = RunOpenFileDialog(params.title, params.filter, params.run_state.owner, &path); } else if (params.type == SELECT_OPEN_MULTI_FILE) { - std::vector<std::wstring> paths; + std::vector<FilePath> paths; if (RunOpenMultiFileDialog(params.title, params.filter, params.run_state.owner, &paths)) { ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, @@ -352,7 +353,7 @@ void SelectFileDialogImpl::ExecuteSelectFile( } } -void SelectFileDialogImpl::FileSelected(const std::wstring& selected_folder, +void SelectFileDialogImpl::FileSelected(const FilePath& selected_folder, int index, void* params, RunState run_state) { @@ -362,9 +363,9 @@ void SelectFileDialogImpl::FileSelected(const std::wstring& selected_folder, } void SelectFileDialogImpl::MultiFilesSelected( - const std::vector<std::wstring>& selected_files, - void* params, - RunState run_state) { + const std::vector<FilePath>& selected_files, + void* params, + RunState run_state) { if (listener_) listener_->MultiFilesSelected(selected_files, params); EndRun(run_state); @@ -391,7 +392,7 @@ int CALLBACK SelectFileDialogImpl::BrowseCallbackProc(HWND window, bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title, HWND owner, - std::wstring* path) { + FilePath* path) { DCHECK(path); wchar_t dir_buffer[MAX_PATH + 1]; @@ -403,9 +404,9 @@ bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title, browse_info.pszDisplayName = dir_buffer; browse_info.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS; - if (path->length()) { + if (path->value().length()) { // Highlight the current value. - browse_info.lParam = (LPARAM)path->c_str(); + browse_info.lParam = (LPARAM)path->value().c_str(); browse_info.lpfn = &BrowseCallbackProc; } @@ -420,7 +421,7 @@ bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title, HRESULT hr = shell_folder->GetDisplayNameOf(list, SHGDN_FORPARSING, &out_dir_buffer); if (SUCCEEDED(hr) && out_dir_buffer.uType == STRRET_WSTR) { - *path = out_dir_buffer.pOleStr; + *path = FilePath::FromWStringHack(out_dir_buffer.pOleStr); CoTaskMemFree(out_dir_buffer.pOleStr); result = true; } @@ -428,7 +429,7 @@ bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title, // Use old way if we don't get what we want. wchar_t old_out_dir_buffer[MAX_PATH + 1]; if (SHGetPathFromIDList(list, old_out_dir_buffer)) { - *path = old_out_dir_buffer; + *path = FilePath::FromWStringHack(old_out_dir_buffer); result = true; } } @@ -446,7 +447,7 @@ bool SelectFileDialogImpl::RunOpenFileDialog( const std::wstring& title, const std::wstring& filter, HWND owner, - std::wstring* path) { + FilePath* path) { OPENFILENAME ofn; // We must do this otherwise the ofn's FlagsEx may be initialized to random // junk in release builds which can cause the Places Bar not to show up! @@ -455,7 +456,7 @@ bool SelectFileDialogImpl::RunOpenFileDialog( ofn.hwndOwner = owner; wchar_t filename[MAX_PATH]; - base::wcslcpy(filename, path->c_str(), arraysize(filename)); + base::wcslcpy(filename, path->value().c_str(), arraysize(filename)); ofn.lpstrFile = filename; ofn.nMaxFile = MAX_PATH; @@ -469,7 +470,7 @@ bool SelectFileDialogImpl::RunOpenFileDialog( bool success = !!GetOpenFileName(&ofn); DisableOwner(owner); if (success) - *path = filename; + *path = FilePath(filename); return success; } @@ -477,7 +478,7 @@ bool SelectFileDialogImpl::RunOpenMultiFileDialog( const std::wstring& title, const std::wstring& filter, HWND owner, - std::vector<std::wstring>* paths) { + std::vector<FilePath>* paths) { OPENFILENAME ofn; // We must do this otherwise the ofn's FlagsEx may be initialized to random // junk in release builds which can cause the Places Bar not to show up! @@ -500,12 +501,12 @@ bool SelectFileDialogImpl::RunOpenMultiFileDialog( bool success = !!GetOpenFileName(&ofn); DisableOwner(owner); if (success) { - std::vector<std::wstring> files; + std::vector<FilePath> files; const wchar_t* selection = ofn.lpstrFile; while (*selection) { // Empty string indicates end of list. - files.push_back(selection); + files.push_back(FilePath(selection)); // Skip over filename and null-terminator. - selection += files.back().length() + 1; + selection += files.back().value().length() + 1; } if (files.empty()) { success = false; @@ -515,10 +516,10 @@ bool SelectFileDialogImpl::RunOpenMultiFileDialog( } else { // Otherwise, the first string is the path, and the remainder are // filenames. - std::vector<std::wstring>::iterator path = files.begin(); - for (std::vector<std::wstring>::iterator file = path + 1; + std::vector<FilePath>::iterator path = files.begin(); + for (std::vector<FilePath>::iterator file = path + 1; file != files.end(); ++file) { - paths->push_back(*path + L'\\' + *file); + paths->push_back(path->Append(*file)); } } } diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc index 650ed05..958e4ce 100644 --- a/chrome/browser/views/user_data_dir_dialog.cc +++ b/chrome/browser/views/user_data_dir_dialog.cc @@ -73,7 +73,7 @@ bool UserDataDirDialog::Accept() { HWND owning_hwnd = GetAncestor(message_box_view_->GetWidget()->GetNativeView(), GA_ROOT); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, - dialog_title, std::wstring(), std::wstring(), + dialog_title, FilePath(), std::wstring(), 0, std::wstring(), owning_hwnd, NULL); return false; } @@ -93,9 +93,9 @@ bool UserDataDirDialog::Dispatch(const MSG& msg) { return is_blocking_; } -void UserDataDirDialog::FileSelected(const std::wstring& path, +void UserDataDirDialog::FileSelected(const FilePath& path, int index, void* params) { - user_data_dir_ = path; + user_data_dir_ = path.ToWStringHack(); is_blocking_ = false; window()->Close(); } diff --git a/chrome/browser/views/user_data_dir_dialog.h b/chrome/browser/views/user_data_dir_dialog.h index ea989b8..78192ce 100644 --- a/chrome/browser/views/user_data_dir_dialog.h +++ b/chrome/browser/views/user_data_dir_dialog.h @@ -48,7 +48,7 @@ class UserDataDirDialog : public views::DialogDelegate, virtual bool Dispatch(const MSG& msg); // SelectFileDialog::Listener Methods: - virtual void FileSelected(const std::wstring& path, int index, void* params); + virtual void FileSelected(const FilePath& path, int index, void* params); virtual void FileSelectionCanceled(void* params); private: |