1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_APPLE_BUNDLE_LOCATIONS_H_ 6 #define BASE_APPLE_BUNDLE_LOCATIONS_H_ 7 8 #include "base/base_export.h" 9 #include "base/files/file_path.h" 10 11 #if defined(__OBJC__) 12 #import <Foundation/Foundation.h> 13 #endif // __OBJC__ 14 15 namespace base { 16 class FilePath; 17 } 18 19 // NSBundle isn't thread-safe; all functions in this file must be called on the 20 // main thread. 21 22 namespace base::apple { 23 24 // This file provides several functions to explicitly request the various 25 // component bundles of Chrome. Please use these methods rather than calling 26 // `+[NSBundle mainBundle]` or `CFBundleGetMainBundle()`. 27 // 28 // Terminology 29 // - "Outer Bundle" - This is the main bundle for Chrome; it's what 30 // `+[NSBundle mainBundle]` returns when Chrome is launched normally. 31 // 32 // - "Main Bundle" - This is the bundle from which Chrome was launched. 33 // This will be the same as the outer bundle except when Chrome is launched 34 // via an app shortcut, in which case this will return the app shortcut's 35 // bundle rather than the main Chrome bundle. 36 // 37 // - "Framework Bundle" - This is the bundle corresponding to the Chrome 38 // framework. 39 // 40 // Guidelines for use: 41 // - To access a resource, the Framework bundle should be used. 42 // - If the choice is between the Outer or Main bundles then please choose 43 // carefully. Most often the Outer bundle will be the right choice, but for 44 // cases such as adding an app to the "launch on startup" list, the Main 45 // bundle is probably the one to use. 46 47 // Methods for retrieving the various bundles. 48 BASE_EXPORT FilePath MainBundlePath(); 49 BASE_EXPORT FilePath OuterBundlePath(); 50 BASE_EXPORT FilePath FrameworkBundlePath(); 51 BASE_EXPORT std::string MainBundleIdentifier(); 52 #if defined(__OBJC__) 53 BASE_EXPORT NSBundle* MainBundle(); 54 BASE_EXPORT NSURL* MainBundleURL(); 55 BASE_EXPORT NSBundle* OuterBundle(); 56 BASE_EXPORT NSURL* OuterBundleURL(); 57 BASE_EXPORT NSBundle* FrameworkBundle(); 58 #endif // __OBJC__ 59 60 // Set the bundle that the preceding functions will return, overriding the 61 // default values. Restore the default by passing in `nil` or an empty 62 // `FilePath`. 63 BASE_EXPORT void SetOverrideOuterBundlePath(const FilePath& file_path); 64 BASE_EXPORT void SetOverrideFrameworkBundlePath(const FilePath& file_path); 65 #if defined(__OBJC__) 66 BASE_EXPORT void SetOverrideOuterBundle(NSBundle* bundle); 67 BASE_EXPORT void SetOverrideFrameworkBundle(NSBundle* bundle); 68 #endif // __OBJC__ 69 70 } // namespace base::apple 71 72 #endif // BASE_APPLE_BUNDLE_LOCATIONS_H_ 73