File: paths_mac.mm

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 3,370 bytes parent folder | download | duplicates (2)
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
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/shell/app/paths_mac.h"

#include "base/apple/bundle_locations.h"
#include "base/apple/foundation_util.h"
#include "base/base_paths.h"
#include "base/path_service.h"
#include "base/strings/sys_string_conversions.h"
#include "content/public/common/content_paths.h"

namespace {

base::FilePath GetContentsPath() {
  // Start out with the path to the running executable.
  base::FilePath path;
  base::PathService::Get(base::FILE_EXE, &path);

  // Up to Contents.
  if (base::apple::IsBackgroundOnlyProcess()) {
    // The running executable is the helper, located at:
    // Content Shell.app/Contents/Frameworks/
    // Content Shell Framework.framework/Versions/C/Helpers/Content Shell
    // Helper.app/ Contents/MacOS/Content Shell Helper. Go up nine steps to get
    // to the main bundle's Contents directory.
    path = path.DirName()
               .DirName()
               .DirName()
               .DirName()
               .DirName()
               .DirName()
               .DirName()
               .DirName()
               .DirName();
  } else {
    // One step up to MacOS, another to Contents.
    path = path.DirName().DirName();
  }
  DCHECK_EQ("Contents", path.BaseName().value());

  return path;
}

base::FilePath GetFrameworksPath() {
  return GetContentsPath().Append("Frameworks");
}

}  // namespace

void OverrideFrameworkBundlePath() {
  base::FilePath helper_path =
      GetFrameworksPath().Append("Content Shell Framework.framework");

  base::apple::SetOverrideFrameworkBundlePath(helper_path);
}

void OverrideOuterBundlePath() {
  base::FilePath path = GetContentsPath().DirName();

  base::apple::SetOverrideOuterBundlePath(path);
}

void OverrideChildProcessPath() {
  base::FilePath helper_path = base::apple::FrameworkBundlePath()
                                   .Append("Helpers")
                                   .Append("Content Shell Helper.app")
                                   .Append("Contents")
                                   .Append("MacOS")
                                   .Append("Content Shell Helper");

  base::PathService::OverrideAndCreateIfNeeded(
      content::CHILD_PROCESS_EXE, helper_path, /*is_absolute=*/true,
      /*create=*/false);
}

void OverrideSourceRootPath() {
  // The base implementation to get base::DIR_SRC_TEST_DATA_ROOT assumes the
  // current process path is the top level app path, not a nested one.
  //
  // Going up 5 levels is needed, since frameworks path looks something like
  // src/out/foo/Content Shell.app/Contents/Framework/
  base::PathService::Override(
      base::DIR_SRC_TEST_DATA_ROOT,
      GetFrameworksPath().DirName().DirName().DirName().DirName().DirName());
}

base::FilePath GetResourcesPakFilePath() {
  NSString* pak_path =
      [base::apple::FrameworkBundle() pathForResource:@"content_shell"
                                               ofType:@"pak"];

  return base::FilePath([pak_path fileSystemRepresentation]);
}

base::FilePath GetInfoPlistPath() {
  return GetContentsPath().Append("Info.plist");
}

void OverrideBundleID() {
  NSBundle* bundle = base::apple::OuterBundle();
  base::apple::SetBaseBundleIDOverride(
      base::SysNSStringToUTF8(bundle.bundleIdentifier));
}