OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/common/chrome_paths_internal.h" | 5 #import "chrome/common/chrome_paths_internal.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "base/base_paths.h" | 9 #import "base/base_paths.h" |
10 #import "base/file_path.h" | |
11 #import "base/logging.h" | 10 #import "base/logging.h" |
12 #import "base/path_service.h" | 11 #import "base/path_service.h" |
13 | 12 |
14 namespace chrome { | 13 namespace chrome { |
15 | 14 |
16 bool GetDefaultUserDataDirectory(FilePath* result) { | 15 bool GetDefaultUserDataDirectory(FilePath* result) { |
17 bool success = false; | 16 bool success = false; |
18 NSArray* dirs = | 17 NSArray* dirs = |
19 NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, | 18 NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, |
20 NSUserDomainMask, YES); | 19 NSUserDomainMask, YES); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, | 64 NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, |
66 NSUserDomainMask, | 65 NSUserDomainMask, |
67 YES); | 66 YES); |
68 if ([docArray count] && result) { | 67 if ([docArray count] && result) { |
69 *result = FilePath([[docArray objectAtIndex:0] fileSystemRepresentation]); | 68 *result = FilePath([[docArray objectAtIndex:0] fileSystemRepresentation]); |
70 success = true; | 69 success = true; |
71 } | 70 } |
72 return success; | 71 return success; |
73 } | 72 } |
74 | 73 |
| 74 FilePath GetBrowserBundlePath() { |
| 75 NSBundle* running_app_bundle = [NSBundle mainBundle]; |
| 76 NSString* running_app_bundle_path = [running_app_bundle bundlePath]; |
| 77 DCHECK(running_app_bundle_path) << "failed to get the main bundle path"; |
| 78 |
| 79 // Are we the helper or the browser (main bundle)? |
| 80 if (![[[running_app_bundle infoDictionary] |
| 81 objectForKey:@"LSUIElement"] boolValue]) { |
| 82 // We aren't a LSUIElement, so this must be the browser, return it's path. |
| 83 return FilePath([running_app_bundle_path fileSystemRepresentation]); |
| 84 } |
| 85 |
| 86 // Helper lives at ...app/Contents/Resources/...Helper.app |
| 87 NSArray* components = [running_app_bundle_path pathComponents]; |
| 88 DCHECK_GE([components count], static_cast<NSUInteger>(4)) |
| 89 << "too few path components for this bundle to be within another bundle"; |
| 90 components = |
| 91 [components subarrayWithRange:NSMakeRange(0, [components count] - 3)]; |
| 92 |
| 93 NSString* browser_path = [NSString pathWithComponents:components]; |
| 94 DCHECK([[browser_path pathExtension] isEqualToString:@"app"]) |
| 95 << "we weren't within another app?"; |
| 96 |
| 97 return FilePath([browser_path fileSystemRepresentation]); |
| 98 } |
| 99 |
75 } // namespace chrome | 100 } // namespace chrome |
OLD | NEW |