1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
// Copyright (c) 2012 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/chrome_paths.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "base/version.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/widevine_cdm_constants.h"
#include "components/breakpad/common/breakpad_paths.h"
#include "ui/base/ui_base_paths.h"
#if defined(OS_ANDROID)
#include "base/android/path_utils.h"
#endif
#if defined(OS_MACOSX)
#include "base/mac/foundation_util.h"
#endif
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
namespace {
// File name of the internal Flash plugin on different platforms.
const base::FilePath::CharType kInternalFlashPluginFileName[] =
#if defined(OS_MACOSX)
FILE_PATH_LITERAL("Flash Player Plugin for Chrome.plugin");
#elif defined(OS_WIN)
FILE_PATH_LITERAL("gcswf32.dll");
#else // OS_LINUX, etc.
FILE_PATH_LITERAL("libgcflashplayer.so");
#endif
// The Pepper Flash plugins are in a directory with this name.
const base::FilePath::CharType kPepperFlashBaseDirectory[] =
FILE_PATH_LITERAL("PepperFlash");
// File name of the internal PDF plugin on different platforms.
const base::FilePath::CharType kInternalPDFPluginFileName[] =
#if defined(OS_WIN)
FILE_PATH_LITERAL("pdf.dll");
#elif defined(OS_MACOSX)
FILE_PATH_LITERAL("PDF.plugin");
#else // Linux and Chrome OS
FILE_PATH_LITERAL("libpdf.so");
#endif
// File name of the internal NaCl plugin on different platforms.
const base::FilePath::CharType kInternalNaClPluginFileName[] =
#if defined(OS_WIN)
FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.dll");
#elif defined(OS_MACOSX)
// TODO(noelallen) Please verify this extention name is correct.
FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.plugin");
#else // Linux and Chrome OS
FILE_PATH_LITERAL("libppGoogleNaClPluginChrome.so");
#endif
#if defined(OS_POSIX) && !defined(OS_MACOSX)
const base::FilePath::CharType kO3DPluginFileName[] =
FILE_PATH_LITERAL("pepper/libppo3dautoplugin.so");
const base::FilePath::CharType kO1DPluginFileName[] =
FILE_PATH_LITERAL("pepper/libppo1d.so");
const base::FilePath::CharType kGTalkPluginFileName[] =
FILE_PATH_LITERAL("pepper/libppgoogletalk.so");
#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
#if defined(OS_LINUX)
// The path to the external extension <id>.json files.
// /usr/share seems like a good choice, see: http://www.pathname.com/fhs/
const base::FilePath::CharType kFilepathSinglePrefExtensions[] =
#if defined(GOOGLE_CHROME_BUILD)
FILE_PATH_LITERAL("/usr/share/google-chrome/extensions");
#else
FILE_PATH_LITERAL("/usr/share/chromium/extensions");
#endif // defined(GOOGLE_CHROME_BUILD)
#endif // defined(OS_LINUX)
} // namespace
namespace chrome {
// Gets the path for internal plugins.
bool GetInternalPluginsDirectory(base::FilePath* result) {
#if defined(OS_MACOSX) && !defined(OS_IOS)
// If called from Chrome, get internal plugins from a subdirectory of the
// framework.
if (base::mac::AmIBundled()) {
*result = chrome::GetFrameworkBundlePath();
DCHECK(!result->empty());
*result = result->Append("Internet Plug-Ins");
return true;
}
// In tests, just look in the module directory (below).
#endif
// The rest of the world expects plugins in the module directory.
return PathService::Get(base::DIR_MODULE, result);
}
bool PathProvider(int key, base::FilePath* result) {
// Some keys are just aliases...
switch (key) {
case chrome::DIR_APP:
return PathService::Get(base::DIR_MODULE, result);
case chrome::DIR_LOGS:
#ifdef NDEBUG
// Release builds write to the data dir
return PathService::Get(chrome::DIR_USER_DATA, result);
#else
// Debug builds write next to the binary (in the build tree)
#if defined(OS_MACOSX)
if (!PathService::Get(base::DIR_EXE, result))
return false;
if (base::mac::AmIBundled()) {
// If we're called from chrome, dump it beside the app (outside the
// app bundle), if we're called from a unittest, we'll already
// outside the bundle so use the exe dir.
// exe_dir gave us .../Chromium.app/Contents/MacOS/Chromium.
*result = result->DirName();
*result = result->DirName();
*result = result->DirName();
}
return true;
#else
return PathService::Get(base::DIR_EXE, result);
#endif // defined(OS_MACOSX)
#endif // NDEBUG
case chrome::FILE_RESOURCE_MODULE:
return PathService::Get(base::FILE_MODULE, result);
}
// Assume that we will not need to create the directory if it does not exist.
// This flag can be set to true for the cases where we want to create it.
bool create_dir = false;
base::FilePath cur;
switch (key) {
case chrome::DIR_USER_DATA:
if (!GetDefaultUserDataDirectory(&cur)) {
NOTREACHED();
return false;
}
create_dir = true;
break;
case chrome::DIR_USER_DOCUMENTS:
if (!GetUserDocumentsDirectory(&cur))
return false;
create_dir = true;
break;
case chrome::DIR_USER_MUSIC:
if (!GetUserMusicDirectory(&cur))
return false;
break;
case chrome::DIR_USER_PICTURES:
if (!GetUserPicturesDirectory(&cur))
return false;
break;
case chrome::DIR_USER_VIDEOS:
if (!GetUserVideosDirectory(&cur))
return false;
break;
case chrome::DIR_DEFAULT_DOWNLOADS_SAFE:
#if defined(OS_WIN) || defined(OS_LINUX)
if (!GetUserDownloadsDirectorySafe(&cur))
return false;
break;
#else
// Fall through for all other platforms.
#endif
case chrome::DIR_DEFAULT_DOWNLOADS:
#if defined(OS_ANDROID)
if (!base::android::GetDownloadsDirectory(&cur))
return false;
#else
if (!GetUserDownloadsDirectory(&cur))
return false;
// Do not create the download directory here, we have done it twice now
// and annoyed a lot of users.
#endif
break;
case chrome::DIR_RESOURCES:
#if defined(OS_MACOSX)
cur = base::mac::FrameworkBundlePath();
cur = cur.Append(FILE_PATH_LITERAL("Resources"));
#else
if (!PathService::Get(chrome::DIR_APP, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("resources"));
#endif
break;
case chrome::DIR_INSPECTOR:
if (!PathService::Get(chrome::DIR_RESOURCES, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("inspector"));
break;
case chrome::DIR_APP_DICTIONARIES:
#if defined(OS_POSIX)
// We can't write into the EXE dir on Linux, so keep dictionaries
// alongside the safe browsing database in the user data dir.
// And we don't want to write into the bundle on the Mac, so push
// it to the user data dir there also.
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
#else
if (!PathService::Get(base::DIR_EXE, &cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("Dictionaries"));
create_dir = true;
break;
case chrome::DIR_INTERNAL_PLUGINS:
if (!GetInternalPluginsDirectory(&cur))
return false;
break;
case chrome::DIR_PEPPER_FLASH_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kPepperFlashBaseDirectory);
break;
case chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(kPepperFlashBaseDirectory);
break;
case chrome::FILE_LOCAL_STATE:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(chrome::kLocalStateFilename);
break;
case chrome::FILE_RECORDED_SCRIPT:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("script.log"));
break;
case chrome::FILE_FLASH_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kInternalFlashPluginFileName);
break;
case chrome::FILE_PEPPER_FLASH_PLUGIN:
if (!PathService::Get(chrome::DIR_PEPPER_FLASH_PLUGIN, &cur))
return false;
cur = cur.Append(chrome::kPepperFlashPluginFilename);
break;
case chrome::FILE_PDF_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kInternalPDFPluginFileName);
break;
case chrome::FILE_NACL_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kInternalNaClPluginFileName);
break;
// PNaCl is currenly installable via the component updater or by being
// simply built-in. DIR_PNACL_BASE is used as the base directory for
// installation via component updater. DIR_PNACL_COMPONENT will be
// the final location of pnacl, which is a subdir of DIR_PNACL_BASE.
case chrome::DIR_PNACL_BASE:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("pnacl"));
break;
// Where PNaCl files are ultimately located. The default finds the files
// inside the InternalPluginsDirectory / build directory, as if it
// was shipped along with chrome. The value can be overridden
// if it is installed via component updater.
case chrome::DIR_PNACL_COMPONENT:
#if defined(OS_MACOSX)
// PNaCl really belongs in the InternalPluginsDirectory but actually
// copying it there would result in the files also being shipped, which
// we don't want yet. So for now, just find them in the directory where
// they get built.
if (!PathService::Get(base::DIR_EXE, &cur))
return false;
if (base::mac::AmIBundled()) {
// If we're called from chrome, it's beside the app (outside the
// app bundle), if we're called from a unittest, we'll already be
// outside the bundle so use the exe dir.
// exe_dir gave us .../Chromium.app/Contents/MacOS/Chromium.
cur = cur.DirName();
cur = cur.DirName();
cur = cur.DirName();
}
#else
if (!GetInternalPluginsDirectory(&cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("pnacl"));
break;
#if defined(OS_POSIX) && !defined(OS_MACOSX)
case chrome::FILE_O3D_PLUGIN:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(kO3DPluginFileName);
break;
case chrome::FILE_O1D_PLUGIN:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(kO1DPluginFileName);
break;
case chrome::FILE_GTALK_PLUGIN:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(kGTalkPluginFileName);
break;
#endif
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
#if defined(WIDEVINE_CDM_IS_COMPONENT)
case chrome::DIR_COMPONENT_WIDEVINE_CDM:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(kWidevineCdmBaseDirectory);
break;
#endif // defined(WIDEVINE_CDM_IS_COMPONENT)
// TODO(xhwang): FILE_WIDEVINE_CDM_ADAPTER has different meanings.
// In the component case, this is the source adapter. Otherwise, it is the
// actual Pepper module that gets loaded.
case chrome::FILE_WIDEVINE_CDM_ADAPTER:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.AppendASCII(kWidevineCdmAdapterFileName);
break;
#endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
case chrome::FILE_RESOURCES_PACK:
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::AmIBundled()) {
cur = base::mac::FrameworkBundlePath();
cur = cur.Append(FILE_PATH_LITERAL("Resources"))
.Append(FILE_PATH_LITERAL("resources.pak"));
break;
}
#elif defined(OS_ANDROID)
if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
return false;
#else
// If we're not bundled on mac or Android, resources.pak should be next
// to the binary (e.g., for unit tests).
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("resources.pak"));
break;
case chrome::DIR_RESOURCES_EXTENSION:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("resources"))
.Append(FILE_PATH_LITERAL("extension"));
break;
#if defined(OS_CHROMEOS)
case chrome::DIR_CHROMEOS_WALLPAPERS:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("wallpapers"));
break;
case chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("wallpaper_thumbnails"));
break;
case chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("custom_wallpapers"));
break;
#endif
#if defined(ENABLE_MANAGED_USERS)
case chrome::DIR_MANAGED_USERS_DEFAULT_APPS:
if (!PathService::Get(chrome::DIR_EXTERNAL_EXTENSIONS, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("managed_users"));
break;
#endif
// The following are only valid in the development environment, and
// will fail if executed from an installed executable (because the
// generated path won't exist).
case chrome::DIR_GEN_TEST_DATA:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("test_data"));
if (!file_util::PathExists(cur)) // We don't want to create this.
return false;
break;
case chrome::DIR_TEST_DATA:
if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("chrome"));
cur = cur.Append(FILE_PATH_LITERAL("test"));
cur = cur.Append(FILE_PATH_LITERAL("data"));
if (!file_util::PathExists(cur)) // We don't want to create this.
return false;
break;
case chrome::DIR_TEST_TOOLS:
if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("chrome"));
cur = cur.Append(FILE_PATH_LITERAL("tools"));
cur = cur.Append(FILE_PATH_LITERAL("test"));
if (!file_util::PathExists(cur)) // We don't want to create this
return false;
break;
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
case chrome::DIR_POLICY_FILES: {
#if defined(GOOGLE_CHROME_BUILD)
cur = base::FilePath(FILE_PATH_LITERAL("/etc/opt/chrome/policies"));
#else
cur = base::FilePath(FILE_PATH_LITERAL("/etc/chromium/policies"));
#endif
break;
}
#endif
#if defined(OS_MACOSX) && !defined(OS_IOS)
case chrome::DIR_MANAGED_PREFS: {
if (!GetLocalLibraryDirectory(&cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("Managed Preferences"));
char* login = getlogin();
if (!login)
return false;
cur = cur.AppendASCII(login);
if (!file_util::PathExists(cur)) // We don't want to create this.
return false;
break;
}
#endif
#if defined(OS_CHROMEOS) || (defined(OS_MACOSX) && !defined(OS_IOS))
case chrome::DIR_USER_EXTERNAL_EXTENSIONS: {
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("External Extensions"));
break;
}
#endif
#if defined(OS_LINUX)
case chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS: {
cur = base::FilePath(kFilepathSinglePrefExtensions);
break;
}
#endif
case chrome::DIR_EXTERNAL_EXTENSIONS:
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (!chrome::GetGlobalApplicationSupportDirectory(&cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("Google"))
.Append(FILE_PATH_LITERAL("Chrome"))
.Append(FILE_PATH_LITERAL("External Extensions"));
create_dir = false;
#else
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("extensions"));
create_dir = true;
#endif
break;
case chrome::DIR_DEFAULT_APPS:
#if defined(OS_MACOSX)
cur = base::mac::FrameworkBundlePath();
cur = cur.Append(FILE_PATH_LITERAL("Default Apps"));
#else
if (!PathService::Get(chrome::DIR_APP, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("default_apps"));
#endif
break;
case breakpad::DIR_CRASH_DUMPS:
#if defined(OS_CHROMEOS)
// ChromeOS uses a separate directory. See http://crosbug.com/25089
cur = base::FilePath("/var/log/chrome");
#elif defined(OS_ANDROID)
if (!base::android::GetCacheDirectory(&cur))
return false;
#else
// The crash reports are always stored relative to the default user data
// directory. This avoids the problem of having to re-initialize the
// exception handler after parsing command line options, which may
// override the location of the app's profile directory.
if (!GetDefaultUserDataDirectory(&cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("Crash Reports"));
create_dir = true;
break;
default:
return false;
}
if (create_dir && !file_util::PathExists(cur) &&
!file_util::CreateDirectory(cur))
return false;
*result = cur;
return true;
}
// This cannot be done as a static initializer sadly since Visual Studio will
// eliminate this object file if there is no direct entry point into it.
void RegisterPathProvider() {
PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
PathService::RegisterProvider(
PathProvider, breakpad::PATH_START, breakpad::PATH_END);
}
} // namespace chrome
|