diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-24 20:40:44 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-24 20:40:44 +0000 |
commit | 1a9e11dc906e39de6436a4a60ae80db9b3ec47a8 (patch) | |
tree | e54cc697681f4ea68e5228182458952c1f9cccc8 | |
parent | 0e1b3fb0be8e113a3863017340900e4874d4eb4b (diff) | |
download | chromium_src-1a9e11dc906e39de6436a4a60ae80db9b3ec47a8.zip chromium_src-1a9e11dc906e39de6436a4a60ae80db9b3ec47a8.tar.gz chromium_src-1a9e11dc906e39de6436a4a60ae80db9b3ec47a8.tar.bz2 |
Implement basic ShowItemInFolder for linux.
Note that this only works if you are using a gnome or kde session. Support for other sessions will be added in the future.
Review URL: http://codereview.chromium.org/52034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12395 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/download_file.cc | 10 | ||||
-rw-r--r-- | chrome/browser/download/save_file_manager.cc | 12 | ||||
-rw-r--r-- | chrome/chrome.gyp | 4 | ||||
-rw-r--r-- | chrome/common/common.scons | 7 | ||||
-rw-r--r-- | chrome/common/common.vcproj | 8 | ||||
-rw-r--r-- | chrome/common/platform_util.h | 17 | ||||
-rw-r--r-- | chrome/common/platform_util_linux.cc | 28 | ||||
-rw-r--r-- | chrome/common/platform_util_mac.mm | 16 | ||||
-rw-r--r-- | chrome/common/platform_util_win.cc | 78 | ||||
-rw-r--r-- | chrome/common/win_util.cc | 66 | ||||
-rw-r--r-- | chrome/common/win_util.h | 3 |
11 files changed, 163 insertions, 86 deletions
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc index e70615a..5411662 100644 --- a/chrome/browser/download/download_file.cc +++ b/chrome/browser/download/download_file.cc @@ -16,6 +16,7 @@ #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/platform_util.h" #include "chrome/common/stl_util-inl.h" #include "googleurl/src/gurl.h" #include "net/base/io_buffer.h" @@ -517,17 +518,12 @@ void DownloadFileManager::OnDownloadUrl(const GURL& url, // Actions from the UI thread and run on the download thread -// Open a download, or show it in a Windows Explorer window. We run on this +// Open a download, or show it in a file explorer window. We run on this // thread to avoid blocking the UI with (potentially) slow Shell operations. // TODO(paulg): File 'stat' operations. void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { -#if defined(OS_WIN) DCHECK(MessageLoop::current() == file_loop_); - win_util::ShowItemInFolder(full_path.value()); -#else - // TODO(port) implement me. - NOTREACHED(); -#endif + platform_util::ShowItemInFolder(full_path); } // Launches the selected download using ShellExecute 'open' verb. If there is diff --git a/chrome/browser/download/save_file_manager.cc b/chrome/browser/download/save_file_manager.cc index 9f444c50..9e8e885 100644 --- a/chrome/browser/download/save_file_manager.cc +++ b/chrome/browser/download/save_file_manager.cc @@ -17,6 +17,7 @@ #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/platform_util.h" #include "chrome/common/stl_util-inl.h" #include "googleurl/src/gurl.h" #include "net/base/net_util.h" @@ -24,10 +25,6 @@ #include "net/url_request/url_request_context.h" #if defined(OS_WIN) -#include "chrome/common/win_util.h" -#endif - -#if defined(OS_WIN) // TODO(port): port these headers to posix. #include "chrome/browser/tab_contents/tab_contents.h" #elif defined(OS_POSIX) @@ -521,12 +518,7 @@ void SaveFileManager::OnDeleteDirectoryOrFile(const FilePath& full_path, // We run on this thread to avoid blocking the UI with slow Shell operations. void SaveFileManager::OnShowSavedFileInShell(const FilePath full_path) { DCHECK(MessageLoop::current() == GetSaveLoop()); - // TODO(port): make an equivalent call on mac/linux. -#if defined(OS_WIN) - win_util::ShowItemInFolder(full_path.value()); -#elif defined(OS_POSIX) - NOTIMPLEMENTED(); -#endif + platform_util::ShowItemInFolder(full_path); } void SaveFileManager::RenameAllFiles( diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index c420d01..1d686e1 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -231,6 +231,10 @@ 'common/owned_widget_gtk.h', 'common/page_transition_types.h', 'common/page_zoom.h', + 'common/platform_util.h', + 'common/platform_util_linux.cc', + 'common/platform_util_mac.mm', + 'common/platform_util_win.cc', 'common/plugin_messages.h', 'common/plugin_messages_internal.h', 'common/pref_member.cc', diff --git a/chrome/common/common.scons b/chrome/common/common.scons index 11c5619..a816ca1 100644 --- a/chrome/common/common.scons +++ b/chrome/common/common.scons @@ -178,6 +178,10 @@ input_files = ChromeFileList([ 'owned_widget_gtk.h', 'page_transition_types.h', 'page_zoom.h', + 'platform_util.h', + 'platform_util_linux.cc', + 'platform_util_mac.mm', + 'platform_util_win.cc', '$CHROME_DIR/tools/build/win/precompiled$OBJSUFFIX', '$CHROME_DIR/tools/build/win/precompiled.h', 'pref_member.cc', @@ -257,6 +261,7 @@ if not env.Bit('windows'): 'gfx/chrome_font_win.cc', 'gfx/path_win.cc', 'ipc_channel_win.cc', + 'platform_util_win.cc', 'resource_bundle_win.cc', 'win_safe_util.cc', 'win_util.cc', @@ -273,6 +278,7 @@ if not env.Bit('linux'): 'gfx/path_gtk.cc', 'owned_widget_gtk.cc', 'owned_widget_gtk.h', + 'platform_util_linux.cc', 'resource_bundle_linux.cc', ) @@ -280,6 +286,7 @@ if not env.Bit('mac'): # Mac specific files input_files.Remove( 'chrome_paths_mac.cc', + 'platform_util_mac.mm', ) if not env.Bit('posix'): diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj index 548bea4..c5ea93a 100644 --- a/chrome/common/common.vcproj +++ b/chrome/common/common.vcproj @@ -614,6 +614,14 @@ > </File> <File + RelativePath=".\platform_util.h" + > + </File> + <File + RelativePath=".\platform_util_win.cc" + > + </File> + <File RelativePath="..\tools\build\win\precompiled.cc" > <FileConfiguration diff --git a/chrome/common/platform_util.h b/chrome/common/platform_util.h new file mode 100644 index 0000000..27ef5c4 --- /dev/null +++ b/chrome/common/platform_util.h @@ -0,0 +1,17 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_PLATFORM_UTIL_H_ +#define CHROME_COMMON_PLATFORM_UTIL_H_ + +class FilePath; + +namespace platform_util { + +// Show the given file in a file manager. If possible, select the file. +void ShowItemInFolder(const FilePath& full_path); + +} + +#endif // CHROME_COMMON_PLATFORM_UTIL_H_ diff --git a/chrome/common/platform_util_linux.cc b/chrome/common/platform_util_linux.cc new file mode 100644 index 0000000..de06f04 --- /dev/null +++ b/chrome/common/platform_util_linux.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/platform_util.h" + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/process_util.h" + +namespace platform_util { + +// TODO(estade): It would be nice to be able to select the file in the file +// manager, but that probably requires extending xdg-open. For now just +// show the folder. +void ShowItemInFolder(const FilePath& full_path) { + FilePath dir = full_path.DirName(); + if (!file_util::DirectoryExists(dir)) + return; + + std::vector<std::string> argv; + argv.push_back("xdg-open"); + argv.push_back(dir.value()); + base::file_handle_mapping_vector no_files; + base::LaunchApp(argv, no_files, false, NULL); +} + +} // namespace platform_util diff --git a/chrome/common/platform_util_mac.mm b/chrome/common/platform_util_mac.mm new file mode 100644 index 0000000..ea8474d --- /dev/null +++ b/chrome/common/platform_util_mac.mm @@ -0,0 +1,16 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/platform_util.h" + +#include "base/file_path.h" +#include "base/logging.h" + +namespace platform_util { + +void ShowItemInFolder(const FilePath& full_path) { + NOTIMPLEMENTED(); +} + +} // namespace platform_util diff --git a/chrome/common/platform_util_win.cc b/chrome/common/platform_util_win.cc new file mode 100644 index 0000000..dd27526 --- /dev/null +++ b/chrome/common/platform_util_win.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/platform_util.h" + +#include <atlbase.h> + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "chrome/common/win_util.h" + +namespace platform_util { + +void ShowItemInFolder(const FilePath& full_path) { + FilePath dir = full_path.DirName(); + // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". + if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) + return; + + typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( + PCIDLIST_ABSOLUTE pidl_Folder, + UINT cidl, + PCUITEMID_CHILD_ARRAY pidls, + DWORD flags); + + static SHOpenFolderAndSelectItemsFuncPtr open_folder_and_select_itemsPtr = + NULL; + static bool initialize_open_folder_proc = true; + if (initialize_open_folder_proc) { + initialize_open_folder_proc = false; + // The SHOpenFolderAndSelectItems API is exposed by shell32 version 6 + // and does not exist in Win2K. We attempt to retrieve this function export + // from shell32 and if it does not exist, we just invoke ShellExecute to + // open the folder thus losing the functionality to select the item in + // the process. + HMODULE shell32_base = GetModuleHandle(L"shell32.dll"); + if (!shell32_base) { + NOTREACHED(); + return; + } + open_folder_and_select_itemsPtr = + reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr> + (GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems")); + } + if (!open_folder_and_select_itemsPtr) { + ShellExecute(NULL, _T("open"), dir.value().c_str(), NULL, NULL, SW_SHOW); + return; + } + + CComPtr<IShellFolder> desktop; + HRESULT hr = SHGetDesktopFolder(&desktop); + if (FAILED(hr)) + return; + + win_util::CoMemReleaser<ITEMIDLIST> dir_item; + hr = desktop->ParseDisplayName(NULL, NULL, + const_cast<wchar_t *>(dir.value().c_str()), + NULL, &dir_item, NULL); + if (FAILED(hr)) + return; + + win_util::CoMemReleaser<ITEMIDLIST> file_item; + hr = desktop->ParseDisplayName(NULL, NULL, + const_cast<wchar_t *>(full_path.value().c_str()), + NULL, &file_item, NULL); + if (FAILED(hr)) + return; + + const ITEMIDLIST* highlight[] = { + {file_item}, + }; + (*open_folder_and_select_itemsPtr)(dir_item, arraysize(highlight), + highlight, NULL); +} + +} // namespace platform_util diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc index 9569b00..adf775d 100644 --- a/chrome/common/win_util.cc +++ b/chrome/common/win_util.cc @@ -159,72 +159,6 @@ bool ShouldUseVistaFrame() { return !!f; } -void ShowItemInFolder(const std::wstring& full_path) { - std::wstring dir = file_util::GetDirectoryFromPath(full_path); - if (dir == L"" || !file_util::PathExists(full_path)) - return; - - // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". - FilePath dir_path(dir); - file_util::EnsureEndsWithSeparator(&dir_path); - dir = dir_path.value(); - - typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( - PCIDLIST_ABSOLUTE pidl_Folder, - UINT cidl, - PCUITEMID_CHILD_ARRAY pidls, - DWORD flags); - - static SHOpenFolderAndSelectItemsFuncPtr open_folder_and_select_itemsPtr = - NULL; - static bool initialize_open_folder_proc = true; - if (initialize_open_folder_proc) { - initialize_open_folder_proc = false; - // The SHOpenFolderAndSelectItems API is exposed by shell32 version 6 - // and does not exist in Win2K. We attempt to retrieve this function export - // from shell32 and if it does not exist, we just invoke ShellExecute to - // open the folder thus losing the functionality to select the item in - // the process. - HMODULE shell32_base = GetModuleHandle(L"shell32.dll"); - if (!shell32_base) { - NOTREACHED(); - return; - } - open_folder_and_select_itemsPtr = - reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr> - (GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems")); - } - if (!open_folder_and_select_itemsPtr) { - ShellExecute(NULL, _T("open"), dir.c_str(), NULL, NULL, SW_SHOW); - return; - } - - CComPtr<IShellFolder> desktop; - HRESULT hr = SHGetDesktopFolder(&desktop); - if (FAILED(hr)) - return; - - CoMemReleaser<ITEMIDLIST> dir_item; - hr = desktop->ParseDisplayName(NULL, NULL, - const_cast<wchar_t *>(dir.c_str()), - NULL, &dir_item, NULL); - if (FAILED(hr)) - return; - - CoMemReleaser<ITEMIDLIST> file_item; - hr = desktop->ParseDisplayName(NULL, NULL, - const_cast<wchar_t *>(full_path.c_str()), - NULL, &file_item, NULL); - if (FAILED(hr)) - return; - - const ITEMIDLIST* highlight[] = { - {file_item}, - }; - (*open_folder_and_select_itemsPtr)(dir_item, arraysize(highlight), - highlight, NULL); -} - // Open an item via a shell execute command. Error code checking and casting // explanation: http://msdn2.microsoft.com/en-us/library/ms647732.aspx bool OpenItemViaShell(const FilePath& full_path, bool ask_for_app) { diff --git a/chrome/common/win_util.h b/chrome/common/win_util.h index 8e703cb..8884960 100644 --- a/chrome/common/win_util.h +++ b/chrome/common/win_util.h @@ -115,9 +115,6 @@ bool IsDrag(const POINT& origin, const POINT& current); // Returns true if we are on Windows Vista and composition is enabled bool ShouldUseVistaFrame(); -// Open a Windows explorer window with the specified file highlighted. -void ShowItemInFolder(const std::wstring& full_path); - // Open or run a file via the Windows shell. In the event that there is no // default application registered for the file specified by 'full_path', // ask the user, via the Windows "Open With" dialog, for an application to use |