summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/chrome_paths_internal.h9
-rw-r--r--chrome/common/chrome_paths_mac.mm27
2 files changed, 34 insertions, 2 deletions
diff --git a/chrome/common/chrome_paths_internal.h b/chrome/common/chrome_paths_internal.h
index f1f0fa9..54b9870 100644
--- a/chrome/common/chrome_paths_internal.h
+++ b/chrome/common/chrome_paths_internal.h
@@ -7,7 +7,7 @@
#include "build/build_config.h"
-class FilePath;
+#include "base/file_path.h"
namespace chrome {
@@ -29,6 +29,13 @@ bool GetUserDownloadsDirectory(FilePath* result);
// The path to the user's desktop.
bool GetUserDesktop(FilePath* result);
+#if defined(OS_MACOSX)
+// Retrieves the browser bundle path. It is only valid to call this from a
+// helper process, as it makes assumptions about the location of the enclosing
+// bundle on disk.
+FilePath GetBrowserBundlePath();
+#endif // defined(OS_MACOSX)
+
} // namespace chrome
diff --git a/chrome/common/chrome_paths_mac.mm b/chrome/common/chrome_paths_mac.mm
index 618dd4f..82dbb3c 100644
--- a/chrome/common/chrome_paths_mac.mm
+++ b/chrome/common/chrome_paths_mac.mm
@@ -7,7 +7,6 @@
#import <Cocoa/Cocoa.h>
#import "base/base_paths.h"
-#import "base/file_path.h"
#import "base/logging.h"
#import "base/path_service.h"
@@ -72,4 +71,30 @@ bool GetUserDesktop(FilePath* result) {
return success;
}
+FilePath GetBrowserBundlePath() {
+ NSBundle* running_app_bundle = [NSBundle mainBundle];
+ NSString* running_app_bundle_path = [running_app_bundle bundlePath];
+ DCHECK(running_app_bundle_path) << "failed to get the main bundle path";
+
+ // Are we the helper or the browser (main bundle)?
+ if (![[[running_app_bundle infoDictionary]
+ objectForKey:@"LSUIElement"] boolValue]) {
+ // We aren't a LSUIElement, so this must be the browser, return it's path.
+ return FilePath([running_app_bundle_path fileSystemRepresentation]);
+ }
+
+ // Helper lives at ...app/Contents/Resources/...Helper.app
+ NSArray* components = [running_app_bundle_path pathComponents];
+ DCHECK_GE([components count], static_cast<NSUInteger>(4))
+ << "too few path components for this bundle to be within another bundle";
+ components =
+ [components subarrayWithRange:NSMakeRange(0, [components count] - 3)];
+
+ NSString* browser_path = [NSString pathWithComponents:components];
+ DCHECK([[browser_path pathExtension] isEqualToString:@"app"])
+ << "we weren't within another app?";
+
+ return FilePath([browser_path fileSystemRepresentation]);
+}
+
} // namespace chrome