Home | History | Annotate | Download | only in app
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "content/shell/app/paths_mac.h"
      6 
      7 #include "base/mac/bundle_locations.h"
      8 #include "base/mac/foundation_util.h"
      9 #include "base/path_service.h"
     10 #include "content/public/common/content_paths.h"
     11 
     12 namespace {
     13 
     14 base::FilePath GetContentsPath() {
     15   // Start out with the path to the running executable.
     16   base::FilePath path;
     17   PathService::Get(base::FILE_EXE, &path);
     18 
     19   // Up to Contents.
     20   if (base::mac::IsBackgroundOnlyProcess()) {
     21     // The running executable is the helper. Go up five steps:
     22     // Contents/Frameworks/Helper.app/Contents/MacOS/Helper
     23     // ^ to here                                     ^ from here
     24     path = path.DirName().DirName().DirName().DirName().DirName();
     25   } else {
     26     // One step up to MacOS, another to Contents.
     27     path = path.DirName().DirName();
     28   }
     29   DCHECK_EQ("Contents", path.BaseName().value());
     30 
     31   return path;
     32 }
     33 
     34 base::FilePath GetFrameworksPath() {
     35   return GetContentsPath().Append("Frameworks");
     36 }
     37 
     38 }  // namespace
     39 
     40 void OverrideFrameworkBundlePath() {
     41   base::FilePath helper_path =
     42       GetFrameworksPath().Append("Content Shell Framework.framework");
     43 
     44   base::mac::SetOverrideFrameworkBundlePath(helper_path);
     45 }
     46 
     47 void OverrideChildProcessPath() {
     48   base::FilePath helper_path =
     49       GetFrameworksPath().Append("Content Shell Helper.app")
     50                                             .Append("Contents")
     51                                             .Append("MacOS")
     52                                             .Append("Content Shell Helper");
     53 
     54   PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
     55 }
     56 
     57 base::FilePath GetResourcesPakFilePath() {
     58   NSString* pak_path =
     59       [base::mac::FrameworkBundle() pathForResource:@"content_shell"
     60                                              ofType:@"pak"];
     61 
     62   return base::FilePath([pak_path fileSystemRepresentation]);
     63 }
     64 
     65 base::FilePath GetInfoPlistPath() {
     66   return GetContentsPath().Append("Info.plist");
     67 }
     68