| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/platform_util.h" | 5 #include "chrome/browser/platform_util.h" |
| 6 | 6 |
| 7 #include <commdlg.h> | 7 #include <commdlg.h> |
| 8 #include <dwmapi.h> | 8 #include <dwmapi.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/win/registry.h" | 20 #include "base/win/registry.h" |
| 21 #include "base/win/scoped_co_mem.h" | 21 #include "base/win/scoped_co_mem.h" |
| 22 #include "base/win/scoped_comptr.h" | 22 #include "base/win/scoped_comptr.h" |
| 23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 24 #include "chrome/browser/lifetime/application_lifetime.h" | 24 #include "chrome/browser/lifetime/application_lifetime.h" |
| 25 #include "chrome/browser/platform_util_internal.h" | 25 #include "chrome/browser/platform_util_internal.h" |
| 26 #include "chrome/browser/ui/host_desktop.h" | 26 #include "chrome/browser/ui/host_desktop.h" |
| 27 #include "chrome/common/chrome_utility_messages.h" | 27 #include "chrome/common/chrome_utility_messages.h" |
| 28 #include "chrome/grit/generated_resources.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/utility_process_host.h" | 30 #include "content/public/browser/utility_process_host.h" |
| 30 #include "content/public/browser/utility_process_host_client.h" | 31 #include "content/public/browser/utility_process_host_client.h" |
| 32 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/win/shell.h" | 33 #include "ui/base/win/shell.h" |
| 32 #include "ui/gfx/native_widget_types.h" | 34 #include "ui/gfx/native_widget_types.h" |
| 33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 34 | 36 |
| 35 using content::BrowserThread; | 37 using content::BrowserThread; |
| 36 | 38 |
| 37 namespace platform_util { | 39 namespace platform_util { |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 // TODO(asanka): Move this to ui/base/win/shell.{h,cc} and invoke it from the | 43 // TODO(asanka): Move this to ui/base/win/shell.{h,cc} and invoke it from the |
| 42 // utility process. | 44 // utility process. |
| 43 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { | 45 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 45 base::FilePath dir = full_path.DirName().AsEndingWithSeparator(); | 47 base::FilePath dir = full_path.DirName().AsEndingWithSeparator(); |
| 46 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". | 48 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". |
| 47 if (dir.empty()) | 49 if (dir.empty()) |
| 48 return; | 50 return; |
| 49 | 51 |
| 50 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( | 52 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( |
| 51 PCIDLIST_ABSOLUTE pidl_Folder, | 53 PCIDLIST_ABSOLUTE pidl_Folder, |
| 52 UINT cidl, | 54 UINT cidl, |
| 53 PCUITEMID_CHILD_ARRAY pidls, | 55 PCUITEMID_CHILD_ARRAY pidls, |
| 54 DWORD flags); | 56 DWORD flags); |
| 55 | 57 |
| 56 static SHOpenFolderAndSelectItemsFuncPtr open_folder_and_select_itemsPtr = | 58 static SHOpenFolderAndSelectItemsFuncPtr open_folder_and_select_itemsPtr = |
| 57 NULL; | 59 nullptr; |
| 58 static bool initialize_open_folder_proc = true; | 60 static bool initialize_open_folder_proc = true; |
| 59 if (initialize_open_folder_proc) { | 61 if (initialize_open_folder_proc) { |
| 60 initialize_open_folder_proc = false; | 62 initialize_open_folder_proc = false; |
| 61 // The SHOpenFolderAndSelectItems API is exposed by shell32 version 6 | 63 // The SHOpenFolderAndSelectItems API is exposed by shell32 version 6 |
| 62 // and does not exist in Win2K. We attempt to retrieve this function export | 64 // and does not exist in Win2K. We attempt to retrieve this function export |
| 63 // from shell32 and if it does not exist, we just invoke ShellExecute to | 65 // from shell32 and if it does not exist, we just invoke ShellExecute to |
| 64 // open the folder thus losing the functionality to select the item in | 66 // open the folder thus losing the functionality to select the item in |
| 65 // the process. | 67 // the process. |
| 66 HMODULE shell32_base = GetModuleHandle(L"shell32.dll"); | 68 HMODULE shell32_base = GetModuleHandle(L"shell32.dll"); |
| 67 if (!shell32_base) { | 69 if (!shell32_base) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // TODO(nsylvain): we should also add a dialog to warn on errors. See | 163 // TODO(nsylvain): we should also add a dialog to warn on errors. See |
| 162 // bug 1136923. | 164 // bug 1136923. |
| 163 return; | 165 return; |
| 164 } | 166 } |
| 165 } | 167 } |
| 166 | 168 |
| 167 void OpenItemViaShellInUtilityProcess(const base::FilePath& full_path, | 169 void OpenItemViaShellInUtilityProcess(const base::FilePath& full_path, |
| 168 OpenItemType type) { | 170 OpenItemType type) { |
| 169 base::WeakPtr<content::UtilityProcessHost> utility_process_host( | 171 base::WeakPtr<content::UtilityProcessHost> utility_process_host( |
| 170 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr()); | 172 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr()); |
| 173 utility_process_host->SetName(l10n_util::GetStringUTF16( |
| 174 IDS_UTILITY_PROCESS_FILE_DIALOG_NAME)); |
| 171 utility_process_host->DisableSandbox(); | 175 utility_process_host->DisableSandbox(); |
| 172 switch (type) { | 176 switch (type) { |
| 173 case OPEN_FILE: | 177 case OPEN_FILE: |
| 174 utility_process_host->Send( | 178 utility_process_host->Send( |
| 175 new ChromeUtilityMsg_OpenFileViaShell(full_path)); | 179 new ChromeUtilityMsg_OpenFileViaShell(full_path)); |
| 176 return; | 180 return; |
| 177 | 181 |
| 178 case OPEN_FOLDER: | 182 case OPEN_FOLDER: |
| 179 utility_process_host->Send( | 183 utility_process_host->Send( |
| 180 new ChromeUtilityMsg_OpenFolderViaShell(full_path)); | 184 new ChromeUtilityMsg_OpenFolderViaShell(full_path)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 231 |
| 228 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH && | 232 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH && |
| 229 !url.SchemeIsHTTPOrHTTPS()) | 233 !url.SchemeIsHTTPOrHTTPS()) |
| 230 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); | 234 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
| 231 | 235 |
| 232 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 236 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 233 base::Bind(&OpenExternalOnFileThread, url)); | 237 base::Bind(&OpenExternalOnFileThread, url)); |
| 234 } | 238 } |
| 235 | 239 |
| 236 } // namespace platform_util | 240 } // namespace platform_util |
| OLD | NEW |