summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 04:15:13 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 04:15:13 +0000
commit151c4a6e282f4282669fb7360dbcbb59c25b92fa (patch)
treeaced67734d49ef99cbe82508f8f6c544a5dd1b3c /chrome
parent55397fc328afa661889e11bfac71617667bd3b69 (diff)
downloadchromium_src-151c4a6e282f4282669fb7360dbcbb59c25b92fa.zip
chromium_src-151c4a6e282f4282669fb7360dbcbb59c25b92fa.tar.gz
chromium_src-151c4a6e282f4282669fb7360dbcbb59c25b92fa.tar.bz2
Use the real Mac browser app's bundle identifier everywhere that a base
bundle identifier is needed on the Mac. This means that everything will use up using org.chromium.Chromium, com.google.Chrome, or com.google.Chrome.canary when it's important to get the base bundle identifier. .helper and .framework will not be appended. Note, however, that things that run inside the helper and use CFPreferences or NSUserDefaults will continue to write their defaults as org.chromium.Chromium.helper or com.google.Chrome.helper. Mostly this just affects the Flash plug-in's settings for the NSNav open dialog. There is no com.google.Chrome.canary.helper, but that's not expected to be a problem. This change ensures that Chromes, canaries, and Chromiums don't get in each other's way. BUG=79814 TEST=none Review URL: http://codereview.chromium.org/6896003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/app_mode_loader_mac.mm16
-rw-r--r--chrome/app/chrome_main.cc4
-rw-r--r--chrome/app/chrome_main.h7
-rw-r--r--chrome/app/chrome_main_mac.mm7
-rw-r--r--chrome/browser/app_controller_mac.mm11
-rw-r--r--chrome/browser/background_mode_manager_mac.mm1
-rw-r--r--chrome/browser/mach_broker_mac.cc15
-rw-r--r--chrome/common/app_mode_common_mac.h8
-rw-r--r--chrome/common/app_mode_common_mac.mm9
-rw-r--r--chrome/common/chrome_paths_internal.h14
-rw-r--r--chrome/common/chrome_paths_mac.mm10
11 files changed, 69 insertions, 33 deletions
diff --git a/chrome/app/app_mode_loader_mac.mm b/chrome/app/app_mode_loader_mac.mm
index 9ffb697..003ce19 100644
--- a/chrome/app/app_mode_loader_mac.mm
+++ b/chrome/app/app_mode_loader_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -60,12 +60,21 @@ int main(int argc, char** argv) {
// needed.
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ // Get the current main bundle, i.e., that of the app loader that's running.
+ NSBundle* app_bundle = [NSBundle mainBundle];
+ CHECK_MSG(app_bundle, "couldn't get loader bundle");
+
+ // Get the bundle ID of the browser that created this app bundle.
+ NSString* cr_bundle_id = [app_bundle
+ objectForInfoDictionaryKey:(NSString*)app_mode::kBrowserBundleIDKey];
+ CHECK_MSG(cr_bundle_id, "couldn't get browser bundle ID");
+
// Get the browser bundle path.
// TODO(viettrungluu): more fun
NSString* cr_bundle_path =
[(NSString*)CFPreferencesCopyAppValue(
app_mode::kLastRunAppBundlePathPrefsKey,
- app_mode::kAppPrefsID) autorelease];
+ (CFStringRef)cr_bundle_id) autorelease];
CHECK_MSG(cr_bundle_path, "couldn't get browser bundle path");
// Get the browser bundle.
@@ -91,9 +100,6 @@ int main(int argc, char** argv) {
// And copy it, since |cr_versioned_path| will go away with the pool.
info.chrome_versioned_path = NSStringToFSCString(cr_versioned_path);
- // Get the current main bundle, i.e., that of the app loader that's running.
- NSBundle* app_bundle = [NSBundle mainBundle];
- CHECK_MSG(app_bundle, "couldn't get loader bundle");
// Optional, so okay if it's NULL.
info.app_mode_bundle_path = NSStringToFSCString([app_bundle bundlePath]);
diff --git a/chrome/app/chrome_main.cc b/chrome/app/chrome_main.cc
index eb4f631..aac380a 100644
--- a/chrome/app/chrome_main.cc
+++ b/chrome/app/chrome_main.cc
@@ -527,6 +527,10 @@ int ChromeMain(int argc, char** argv) {
chromeos::BootTimesLoader::Get()->SaveChromeMainStats();
#endif
+#if defined(OS_MACOSX)
+ chrome_main::SetUpBaseBundleID();
+#endif
+
CommandLine::Init(argc, argv);
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
diff --git a/chrome/app/chrome_main.h b/chrome/app/chrome_main.h
index 7fc8bfb..0ecf06a 100644
--- a/chrome/app/chrome_main.h
+++ b/chrome/app/chrome_main.h
@@ -31,6 +31,13 @@ void LowLevelShutdown();
// |user_data_dir| parameter. If no policy is set the parameter is not changed.
void CheckUserDataDirPolicy(FilePath* user_data_dir);
+#if defined(OS_MACOSX)
+// Sets the base bundle ID to the proper value based on the running
+// application. The base bundle ID is the outer browser application's bundle
+// ID even when running in a non-browser (helper) process.
+void SetUpBaseBundleID();
+#endif
+
} // namespace chrome_main
#endif // CHROME_APP_CHROME_MAIN_H_
diff --git a/chrome/app/chrome_main_mac.mm b/chrome/app/chrome_main_mac.mm
index e27face..b3d19a3 100644
--- a/chrome/app/chrome_main_mac.mm
+++ b/chrome/app/chrome_main_mac.mm
@@ -11,8 +11,10 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/logging.h"
+#include "base/mac/foundation_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/policy/policy_path_parser.h"
+#include "chrome/common/chrome_paths_internal.h"
#include "policy/policy_constants.h"
namespace chrome_main {
@@ -32,4 +34,9 @@ void CheckUserDataDirPolicy(FilePath* user_data_dir) {
}
}
+void SetUpBaseBundleID() {
+ NSBundle* base_bundle = chrome::OuterAppBundle();
+ base::mac::SetBaseBundleID([[base_bundle bundleIdentifier] UTF8String]);
+}
+
} // namespace chrome_main
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 3be6c92..c2d284b 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -7,6 +7,7 @@
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/file_path.h"
+#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
@@ -109,6 +110,12 @@ Browser* ActivateOrCreateBrowser(Profile* profile) {
return CreateBrowser(profile);
}
+CFStringRef BaseBundleID_CFString() {
+ NSString* base_bundle_id =
+ [NSString stringWithUTF8String:base::mac::BaseBundleID()];
+ return base::mac::NSToCFCast(base_bundle_id);
+}
+
// This task synchronizes preferences (under "org.chromium.Chromium" or
// "com.google.Chrome"), in particular, writes them out to disk.
class PrefsSyncTask : public Task {
@@ -116,7 +123,7 @@ class PrefsSyncTask : public Task {
PrefsSyncTask() {}
virtual ~PrefsSyncTask() {}
virtual void Run() {
- if (!CFPreferencesAppSynchronize(app_mode::kAppPrefsID))
+ if (!CFPreferencesAppSynchronize(BaseBundleID_CFString()))
LOG(WARNING) << "Error recording application bundle path.";
}
};
@@ -133,7 +140,7 @@ void RecordLastRunAppBundlePath() {
chrome::GetVersionedDirectory().DirName().DirName().DirName();
CFPreferencesSetAppValue(app_mode::kLastRunAppBundlePathPrefsKey,
base::SysUTF8ToCFStringRef(appBundlePath.value()),
- app_mode::kAppPrefsID);
+ BaseBundleID_CFString());
// Sync after a delay avoid I/O contention on startup; 1500 ms is plenty.
BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
diff --git a/chrome/browser/background_mode_manager_mac.mm b/chrome/browser/background_mode_manager_mac.mm
index 1c47ae9..f7fad87 100644
--- a/chrome/browser/background_mode_manager_mac.mm
+++ b/chrome/browser/background_mode_manager_mac.mm
@@ -7,7 +7,6 @@
#include "chrome/browser/background_mode_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/common/app_mode_common_mac.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/browser/browser_thread.h"
diff --git a/chrome/browser/mach_broker_mac.cc b/chrome/browser/mach_broker_mac.cc
index f7707c7..10cfa55 100644
--- a/chrome/browser/mach_broker_mac.cc
+++ b/chrome/browser/mach_broker_mac.cc
@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/mac/foundation_util.h"
#include "base/mach_ipc_mac.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
@@ -227,18 +228,10 @@ void MachBroker::Observe(NotificationType type,
// static
std::string MachBroker::GetMachPortName() {
- static const char kFormatString[] =
-#if defined(GOOGLE_CHROME_BUILD)
- "com.google.Chrome"
-#else
- "org.chromium.Chromium"
-#endif
- ".rohitfork.%d";
-
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- const bool is_child = command_line.HasSwitch(switches::kProcessType);
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ const bool is_child = command_line->HasSwitch(switches::kProcessType);
// In non-browser (child) processes, use the parent's pid.
const pid_t pid = is_child ? getppid() : getpid();
- return StringPrintf(kFormatString, pid);
+ return StringPrintf("%s.rohitfork.%d", base::mac::BaseBundleID(), pid);
}
diff --git a/chrome/common/app_mode_common_mac.h b/chrome/common/app_mode_common_mac.h
index 130fe8a..9f74427 100644
--- a/chrome/common/app_mode_common_mac.h
+++ b/chrome/common/app_mode_common_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,9 +13,9 @@
namespace app_mode {
-// The ID under which app mode preferences will be recorded
-// ("org.chromium.Chromium" or "com.google.Chrome").
-extern const CFStringRef kAppPrefsID;
+// The key under which the browser's bundle ID will be stored in the
+// app mode launcher bundle's Info.plist.
+extern const CFStringRef kBrowserBundleIDKey;
// The key under which to record the path to the (user-visible) application
// bundle; this key is recorded under the ID given by |kAppPrefsID|.
diff --git a/chrome/common/app_mode_common_mac.mm b/chrome/common/app_mode_common_mac.mm
index 3705c34..781ff2f 100644
--- a/chrome/common/app_mode_common_mac.mm
+++ b/chrome/common/app_mode_common_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,12 +6,7 @@
namespace app_mode {
-#if defined(GOOGLE_CHROME_BUILD)
-const CFStringRef kAppPrefsID = CFSTR("com.google.Chrome");
-#else
-const CFStringRef kAppPrefsID = CFSTR("org.chromium.Chromium");
-#endif
-
+const CFStringRef kBrowserBundleIDKey = CFSTR("CrBundleIdentifier");
const CFStringRef kLastRunAppBundlePathPrefsKey = CFSTR("LastRunAppBundlePath");
} // namespace app_mode
diff --git a/chrome/common/chrome_paths_internal.h b/chrome/common/chrome_paths_internal.h
index dfe927d..baf5777 100644
--- a/chrome/common/chrome_paths_internal.h
+++ b/chrome/common/chrome_paths_internal.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,14 @@
#include "build/build_config.h"
+#if defined(OS_MACOSX)
+#if defined(__OBJC__)
+@class NSBundle;
+#else
+class NSBundle;
+#endif
+#endif
+
class FilePath;
namespace chrome {
@@ -68,6 +76,10 @@ FilePath GetFrameworkBundlePath();
// Get the local library directory.
bool GetLocalLibraryDirectory(FilePath* result);
+// Returns the NSBundle for the outer browser application, even when running
+// inside the helper. In unbundled applications, such as tests, returns nil.
+NSBundle* OuterAppBundle();
+
#endif // OS_MACOSX
} // namespace chrome
diff --git a/chrome/common/chrome_paths_mac.mm b/chrome/common/chrome_paths_mac.mm
index f88fe2a..6054532 100644
--- a/chrome/common/chrome_paths_mac.mm
+++ b/chrome/common/chrome_paths_mac.mm
@@ -21,7 +21,7 @@ namespace {
const FilePath* g_override_versioned_directory = NULL;
-NSBundle* OuterAppBundle() {
+NSBundle* OuterAppBundleInternal() {
if (!base::mac::AmIBundled()) {
// If unbundled (as in a test), there's no app bundle.
return nil;
@@ -53,7 +53,7 @@ const char* ProductDirNameInternal() {
// should not be accessed from non-browser processes, but those processes do
// attempt to get the profile directory, so direct them to look in the outer
// browser .app's Info.plist for the CrProductDirName key.
- NSBundle* bundle = OuterAppBundle();
+ NSBundle* bundle = chrome::OuterAppBundle();
NSString* product_dir_name_ns =
[bundle objectForInfoDictionaryKey:@"CrProductDirName"];
const char* product_dir_name = [product_dir_name_ns fileSystemRepresentation];
@@ -183,4 +183,10 @@ bool GetLocalLibraryDirectory(FilePath* result) {
return base::mac::GetLocalDirectory(NSLibraryDirectory, result);
}
+NSBundle* OuterAppBundle() {
+ // Cache this. Foundation leaks it anyway.
+ static NSBundle* bundle = [OuterAppBundleInternal() retain];
+ return bundle;
+}
+
} // namespace chrome