security/sandbox/chromium/base/base_paths_win.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include <windows.h>
michael@0 6 #include <shlobj.h>
michael@0 7
michael@0 8 #include "base/base_paths.h"
michael@0 9 #include "base/files/file_path.h"
michael@0 10 #include "base/path_service.h"
michael@0 11 #include "base/win/scoped_co_mem.h"
michael@0 12 #include "base/win/windows_version.h"
michael@0 13
michael@0 14 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
michael@0 15 extern "C" IMAGE_DOS_HEADER __ImageBase;
michael@0 16
michael@0 17 using base::FilePath;
michael@0 18
michael@0 19 namespace {
michael@0 20
michael@0 21 bool GetQuickLaunchPath(bool default_user, FilePath* result) {
michael@0 22 if (default_user) {
michael@0 23 wchar_t system_buffer[MAX_PATH];
michael@0 24 system_buffer[0] = 0;
michael@0 25 // As per MSDN, passing -1 for |hToken| indicates the Default user:
michael@0 26 // http://msdn.microsoft.com/library/windows/desktop/bb762181.aspx
michael@0 27 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA,
michael@0 28 reinterpret_cast<HANDLE>(-1), SHGFP_TYPE_CURRENT,
michael@0 29 system_buffer))) {
michael@0 30 return false;
michael@0 31 }
michael@0 32 *result = FilePath(system_buffer);
michael@0 33 } else if (!PathService::Get(base::DIR_APP_DATA, result)) {
michael@0 34 // For the current user, grab the APPDATA directory directly from the
michael@0 35 // PathService cache.
michael@0 36 return false;
michael@0 37 }
michael@0 38 // According to various sources, appending
michael@0 39 // "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the only
michael@0 40 // reliable way to get the quick launch folder across all versions of Windows.
michael@0 41 // http://stackoverflow.com/questions/76080/how-do-you-reliably-get-the-quick-
michael@0 42 // http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0901.mspx
michael@0 43 *result = result->AppendASCII("Microsoft");
michael@0 44 *result = result->AppendASCII("Internet Explorer");
michael@0 45 *result = result->AppendASCII("Quick Launch");
michael@0 46 return true;
michael@0 47 }
michael@0 48
michael@0 49 } // namespace
michael@0 50
michael@0 51 namespace base {
michael@0 52
michael@0 53 bool PathProviderWin(int key, FilePath* result) {
michael@0 54 // We need to go compute the value. It would be nice to support paths with
michael@0 55 // names longer than MAX_PATH, but the system functions don't seem to be
michael@0 56 // designed for it either, with the exception of GetTempPath (but other
michael@0 57 // things will surely break if the temp path is too long, so we don't bother
michael@0 58 // handling it.
michael@0 59 wchar_t system_buffer[MAX_PATH];
michael@0 60 system_buffer[0] = 0;
michael@0 61
michael@0 62 FilePath cur;
michael@0 63 switch (key) {
michael@0 64 case base::FILE_EXE:
michael@0 65 GetModuleFileName(NULL, system_buffer, MAX_PATH);
michael@0 66 cur = FilePath(system_buffer);
michael@0 67 break;
michael@0 68 case base::FILE_MODULE: {
michael@0 69 // the resource containing module is assumed to be the one that
michael@0 70 // this code lives in, whether that's a dll or exe
michael@0 71 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
michael@0 72 GetModuleFileName(this_module, system_buffer, MAX_PATH);
michael@0 73 cur = FilePath(system_buffer);
michael@0 74 break;
michael@0 75 }
michael@0 76 case base::DIR_WINDOWS:
michael@0 77 GetWindowsDirectory(system_buffer, MAX_PATH);
michael@0 78 cur = FilePath(system_buffer);
michael@0 79 break;
michael@0 80 case base::DIR_SYSTEM:
michael@0 81 GetSystemDirectory(system_buffer, MAX_PATH);
michael@0 82 cur = FilePath(system_buffer);
michael@0 83 break;
michael@0 84 case base::DIR_PROGRAM_FILESX86:
michael@0 85 if (base::win::OSInfo::GetInstance()->architecture() !=
michael@0 86 base::win::OSInfo::X86_ARCHITECTURE) {
michael@0 87 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILESX86, NULL,
michael@0 88 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 89 return false;
michael@0 90 cur = FilePath(system_buffer);
michael@0 91 break;
michael@0 92 }
michael@0 93 // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine.
michael@0 94 case base::DIR_PROGRAM_FILES:
michael@0 95 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
michael@0 96 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 97 return false;
michael@0 98 cur = FilePath(system_buffer);
michael@0 99 break;
michael@0 100 case base::DIR_IE_INTERNET_CACHE:
michael@0 101 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL,
michael@0 102 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 103 return false;
michael@0 104 cur = FilePath(system_buffer);
michael@0 105 break;
michael@0 106 case base::DIR_COMMON_START_MENU:
michael@0 107 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL,
michael@0 108 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 109 return false;
michael@0 110 cur = FilePath(system_buffer);
michael@0 111 break;
michael@0 112 case base::DIR_START_MENU:
michael@0 113 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL,
michael@0 114 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 115 return false;
michael@0 116 cur = FilePath(system_buffer);
michael@0 117 break;
michael@0 118 case base::DIR_APP_DATA:
michael@0 119 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
michael@0 120 system_buffer)))
michael@0 121 return false;
michael@0 122 cur = FilePath(system_buffer);
michael@0 123 break;
michael@0 124 case base::DIR_COMMON_APP_DATA:
michael@0 125 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL,
michael@0 126 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 127 return false;
michael@0 128 cur = FilePath(system_buffer);
michael@0 129 break;
michael@0 130 case base::DIR_PROFILE:
michael@0 131 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT,
michael@0 132 system_buffer)))
michael@0 133 return false;
michael@0 134 cur = FilePath(system_buffer);
michael@0 135 break;
michael@0 136 case base::DIR_LOCAL_APP_DATA_LOW:
michael@0 137 if (win::GetVersion() < win::VERSION_VISTA)
michael@0 138 return false;
michael@0 139
michael@0 140 // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128
michael@0 141 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
michael@0 142 system_buffer)))
michael@0 143 return false;
michael@0 144 cur = FilePath(system_buffer).DirName().AppendASCII("LocalLow");
michael@0 145 break;
michael@0 146 case base::DIR_LOCAL_APP_DATA:
michael@0 147 if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL,
michael@0 148 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 149 return false;
michael@0 150 cur = FilePath(system_buffer);
michael@0 151 break;
michael@0 152 case base::DIR_SOURCE_ROOT: {
michael@0 153 FilePath executableDir;
michael@0 154 // On Windows, unit tests execute two levels deep from the source root.
michael@0 155 // For example: chrome/{Debug|Release}/ui_tests.exe
michael@0 156 PathService::Get(base::DIR_EXE, &executableDir);
michael@0 157 cur = executableDir.DirName().DirName();
michael@0 158 break;
michael@0 159 }
michael@0 160 case base::DIR_APP_SHORTCUTS: {
michael@0 161 if (win::GetVersion() < win::VERSION_WIN8)
michael@0 162 return false;
michael@0 163
michael@0 164 base::win::ScopedCoMem<wchar_t> path_buf;
michael@0 165 if (FAILED(SHGetKnownFolderPath(FOLDERID_ApplicationShortcuts, 0, NULL,
michael@0 166 &path_buf)))
michael@0 167 return false;
michael@0 168
michael@0 169 cur = FilePath(string16(path_buf));
michael@0 170 break;
michael@0 171 }
michael@0 172 case base::DIR_USER_DESKTOP:
michael@0 173 if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL,
michael@0 174 SHGFP_TYPE_CURRENT, system_buffer))) {
michael@0 175 return false;
michael@0 176 }
michael@0 177 cur = FilePath(system_buffer);
michael@0 178 break;
michael@0 179 case base::DIR_COMMON_DESKTOP:
michael@0 180 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL,
michael@0 181 SHGFP_TYPE_CURRENT, system_buffer))) {
michael@0 182 return false;
michael@0 183 }
michael@0 184 cur = FilePath(system_buffer);
michael@0 185 break;
michael@0 186 case base::DIR_USER_QUICK_LAUNCH:
michael@0 187 if (!GetQuickLaunchPath(false, &cur))
michael@0 188 return false;
michael@0 189 break;
michael@0 190 case base::DIR_DEFAULT_USER_QUICK_LAUNCH:
michael@0 191 if (!GetQuickLaunchPath(true, &cur))
michael@0 192 return false;
michael@0 193 break;
michael@0 194 case base::DIR_TASKBAR_PINS:
michael@0 195 if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur))
michael@0 196 return false;
michael@0 197 cur = cur.AppendASCII("User Pinned");
michael@0 198 cur = cur.AppendASCII("TaskBar");
michael@0 199 break;
michael@0 200 default:
michael@0 201 return false;
michael@0 202 }
michael@0 203
michael@0 204 *result = cur;
michael@0 205 return true;
michael@0 206 }
michael@0 207
michael@0 208 } // namespace base

mercurial