• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium Embedded Framework Authors.
2// Portions copyright (c) 2011 The Chromium Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5
6#include "tests/shared/browser/resource_util.h"
7
8#import <Foundation/Foundation.h>
9#include <mach-o/dyld.h>
10#include <stdio.h>
11
12#include "include/base/cef_logging.h"
13
14namespace client {
15
16namespace {
17
18// Implementation adapted from Chromium's base/mac/foundation_util.mm
19bool UncachedAmIBundled() {
20  return [[[NSBundle mainBundle] bundlePath] hasSuffix:@".app"];
21}
22
23bool AmIBundled() {
24  static bool am_i_bundled = UncachedAmIBundled();
25  return am_i_bundled;
26}
27
28}  // namespace
29
30// Implementation adapted from Chromium's base/base_path_mac.mm
31bool GetResourceDir(std::string& dir) {
32  // Retrieve the executable directory.
33  uint32_t pathSize = 0;
34  _NSGetExecutablePath(nullptr, &pathSize);
35  if (pathSize > 0) {
36    dir.resize(pathSize);
37    _NSGetExecutablePath(const_cast<char*>(dir.c_str()), &pathSize);
38  }
39
40  if (AmIBundled()) {
41    // Trim executable name up to the last separator.
42    std::string::size_type last_separator = dir.find_last_of("/");
43    dir.resize(last_separator);
44    dir.append("/../Resources");
45    return true;
46  }
47
48  dir.append("/Resources");
49  return true;
50}
51
52}  // namespace client
53