1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_COMMON_MAC_APP_MODE_COMMON_H_
#define CHROME_COMMON_MAC_APP_MODE_COMMON_H_
#include <CoreServices/CoreServices.h>
#include <string>
#include "base/files/file_path.h"
#include "base/macros/concat.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/strings/stringize_macros.h"
#ifdef __OBJC__
@class NSString;
#endif
// This file contains constants, interfaces, etc. which are common to the
// browser application and the app mode loader (a.k.a. shim).
// The version of the ChromeAppModeInfo struct below. If the format of the
// struct ever changes, be sure to update the APP_SHIM_VERSION_NUMBER here and
// the corresponding lines in //chrome/app/framework.order and
// //chrome/app/framework.exports .
#define APP_SHIM_VERSION_NUMBER 7
// All the other macro magic to make APP_SHIM_VERSION_NUMBER usable.
#define APP_SHIM_ENTRY_POINT_NAME \
BASE_CONCAT(ChromeAppModeStart_v, APP_SHIM_VERSION_NUMBER)
#define APP_SHIM_ENTRY_POINT_NAME_STRING STRINGIZE(APP_SHIM_ENTRY_POINT_NAME)
namespace app_mode {
// Mach message ID used by the shim to connect to Chrome.
inline constexpr mach_msg_id_t kBootstrapMsgId = 'apps';
// Name fragment of the Mach server endpoint published in the bootstrap
// namespace. The full name is "<bundle-id>.apps.<profile_path_hash>".
// <bundle-id> is the BaseBundleID() and <profile_path_hash> is an MD5 hash
// of the full profile directory path.
extern const char kAppShimBootstrapNameFragment[];
// A symlink used to store the version string of the currently running Chrome,
// along with any other necessary configuration. The shim will read this to
// determine which version of the framework to load.
extern const char kRunningChromeVersionSymlinkName[];
// A file used to store feature and field trial state of the currently or most
// recently running Chrome. The shim will read this to determine what features
// to enable if it wasn't launched by Chrome, until it can get the current state
// from Chrome.
extern const char kFeatureStateFileName[];
// The process ID of the Chrome process that launched the app shim.
// The presence of this switch instructs the app shim to send LaunchApp with
// launch_now = false. This associates the shim without launching the app.
extern const char kLaunchedByChromeProcessId[];
// The main bundle path of the Chrome process that launched the app shim.
extern const char kLaunchedByChromeBundlePath[];
// The framework bundle path of the Chrome process that launched the app shim.
extern const char kLaunchedByChromeFrameworkBundlePath[];
// The framework dylib path of the Chrome process that launched the app shim.
extern const char kLaunchedByChromeFrameworkDylibPath[];
// Indicates to the shim that it was launched for a test, so don't attempt to
// launch Chrome.
extern const char kLaunchedForTest[];
// Indicates to the shim that this Chrome has rebuilt it once already, i.e. if
// it fails to launch again, don't trigger another rebuild.
extern const char kLaunchedAfterRebuild[];
// Indicates to the shim that even if `kLaunchedByChromeProcessId` was also
// specified, this should still be considered a "normal" launch as opposed to a
// "register only" launch. This is used by tests to launch a shim as if the user
// launched it, while still making sure it connects to the correct chrome
// process.
extern const char kIsNormalLaunch[];
// Normally when running tests app shims are not supposed to try to launch
// Chrome. Pass this flag to specify the executable to launch when the app shim
// would normally launch Chrome.
extern const char kLaunchChromeForTest[];
#ifdef __OBJC__
// Keys for specifying the file types handled by an app.
extern NSString* const kCFBundleDocumentTypesKey;
extern NSString* const kCFBundleTypeExtensionsKey;
extern NSString* const kCFBundleTypeIconFileKey;
extern NSString* const kCFBundleTypeNameKey;
extern NSString* const kCFBundleTypeMIMETypesKey;
extern NSString* const kCFBundleTypeRoleKey;
extern NSString* const kCFBundleURLNameKey;
extern NSString* const kCFBundleURLSchemesKey;
extern NSString* const kCFBundleURLTypesKey;
extern NSString* const kBundleTypeRoleViewer;
// The display name of the bundle as shown in Finder and the Dock. For localized
// bundles, this overrides the bundle's file name.
extern NSString* const kCFBundleDisplayNameKey;
// When Chrome is built, any app bundles (e.g. the app shim template bundle)
// will have their CFBundleShortVersionString set to the full version string of
// that build. Since, this string is used by OSX when displaying an app bundle's
// version, we override it in app shim bundles to show the app's version
// instead.
extern NSString* const kCFBundleShortVersionStringKey;
// Key for the Chrome version that built the app shim bundle. This needs to be
// added since we override CFBundleShortVersionString with the version of the
// app.
extern NSString* const kCrBundleVersionKey;
// The key specifying whether the display name should be localized. This makes
// Finder look in localization folders in the app bundle for a display name.
// (e.g. Content/Resources/en.lproj/)
extern NSString* const kLSHasLocalizedDisplayNameKey;
// Key specifying whether or not high DPI display is supported at all. If this
// is not set to true then all graphics (including system dialogs and display
// property queries) will behave as though all displays are low DPI.
extern NSString* const kNSHighResolutionCapableKey;
// The key under which the browser's bundle ID will be stored in the
// app mode launcher bundle's Info.plist.
extern NSString* const kBrowserBundleIDKey;
// Key for the shortcut ID.
extern NSString* const kCrAppModeShortcutIDKey;
// Key for the app's name.
extern NSString* const kCrAppModeShortcutNameKey;
// Key for the app's URL.
extern NSString* const kCrAppModeShortcutURLKey;
// Key for the app user data directory.
extern NSString* const kCrAppModeUserDataDirKey;
// Key for the app's extension path.
extern NSString* const kCrAppModeProfileDirKey;
// Key for the app's profile display name.
extern NSString* const kCrAppModeProfileNameKey;
// When the Chrome browser is run, it stores its location in the defaults
// system using this key.
extern NSString* const kLastRunAppBundlePathPrefsKey;
// The key for the major and minor version of an app.
extern NSString* const kCrAppModeMajorVersionKey;
extern NSString* const kCrAppModeMinorVersionKey;
// Info.plist key that indicates whether a PWA is ad-hoc signed.
// Intended for use by `app_mode_loader` prior to checking in with the browser.
extern NSString* const kCrAppModeIsAdHocSignedKey;
// Placeholders used in the app mode loader bundle' Info.plist:
extern NSString* const kShortcutIdPlaceholder; // Extension shortcut ID.
extern NSString* const kShortcutNamePlaceholder; // Extension name.
extern NSString* const kShortcutURLPlaceholder;
// Bundle ID of the Chrome browser bundle.
extern NSString* const kShortcutBrowserBundleIDPlaceholder;
#endif // __OBJC__
// Indicates the MojoIpcz feature configuration for a launched shim process.
enum class MojoIpczConfig {
// MojoIpcz is enabled.
kEnabled,
// MojoIpcz is disabled.
kDisabled,
// The MojoIpcz configuration should be determined by feature flags on the
// CommandLine once parsed by the shim.
kUseCommandLineFeatures,
};
// The structure used to pass information from the app mode loader to the
// (browser) framework via the entry point ChromeAppModeStart_vN.
//
// As long as the name of the entry point is kept constant and
// APP_SHIM_VERSION_NUMBER does not change, the layout of this structure
// **MUST NOT CHANGE**, even across Chromium versions. This implies that no
// base/ or std:: types may be used in this structure.
//
// However, this structure *may* be changed as long as the
// APP_SHIM_VERSION_NUMBER above is updated; don't forget to also update the
// corresponding line in //chrome/app/framework.order .
struct ChromeAppModeInfo {
// Original |argc| and |argv| of the App Mode shortcut.
int argc;
// This field is not a raw_ptr<> because this struct is part of separate
// binary and must be a POD.
RAW_PTR_EXCLUSION char** argv;
// Path of the Chromium Framework, as UTF-8. This will be the input to
// SetOverrideFrameworkBundlePath().
const char* chrome_framework_path;
// Path to Chromium app bundle, as UTF-8.
const char* chrome_outer_bundle_path;
// Information about the App Mode shortcut:
// Path to the App Mode Loader application bundle that launched the process,
// as UTF-8.
const char* app_mode_bundle_path;
// Short UTF-8 ID string, preferably derived from |app_mode_short_name|.
// Should be safe for the file system.
const char* app_mode_id;
// Unrestricted (e.g., several-word) UTF-8-encoded name for the shortcut.
const char* app_mode_name;
// URL for the shortcut. Must be a valid UTF-8-encoded URL.
const char* app_mode_url;
// Path to the app's user data directory, as UTF-8.
const char* user_data_dir;
// Directory of the profile associated with the app, as UTF-8.
const char* profile_dir;
// Indicates whether MojoIpcz must be enabled in the shim.
MojoIpczConfig mojo_ipcz_config;
};
// Conveys the configuration for a connection to be established between a shim
// process and a running Chrome process.
struct ChromeConnectionConfig {
// The version of the Chromium framework to use.
std::string framework_version;
// Indicates whether or not the MojoIpcz feature must be enabled.
bool is_mojo_ipcz_enabled;
// Returns a new configuration appropriate for the calling Chrome process to
// encode and convey to a shim.
static ChromeConnectionConfig GenerateForCurrentProcess();
// Generates a path value which encodes the contents of this structure.
base::FilePath EncodeAsPath() const;
// Parses a path value into a configuration.
static ChromeConnectionConfig DecodeFromPath(const base::FilePath& path);
};
} // namespace app_mode
#endif // CHROME_COMMON_MAC_APP_MODE_COMMON_H_
|