diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 19:41:37 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 19:41:37 +0000 |
commit | cd63ef62b897937521c6943b554608b3f9349d27 (patch) | |
tree | c79b4ff66eb7d1553095a6389c41f85bca9f2051 /chrome/browser/shell_integration_mac.mm | |
parent | 8e80744e557dd436dd174b7f7203b4409b90c6e4 (diff) | |
download | chromium_src-cd63ef62b897937521c6943b554608b3f9349d27.zip chromium_src-cd63ef62b897937521c6943b554608b3f9349d27.tar.gz chromium_src-cd63ef62b897937521c6943b554608b3f9349d27.tar.bz2 |
Implement most of the "basics" pref panel on Mac, including code to set the default browser. Fix up some related comments around the code.
Review URL: http://codereview.chromium.org/113032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15445 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/shell_integration_mac.mm')
-rw-r--r-- | chrome/browser/shell_integration_mac.mm | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm new file mode 100644 index 0000000..28fdd8c --- /dev/null +++ b/chrome/browser/shell_integration_mac.mm @@ -0,0 +1,49 @@ +// Copyright (c) 2006-2008 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. + +#include "chrome/browser/shell_integration.h" + +#include "base/mac_util.h" +#import "third_party/mozilla/include/NSWorkspace+Utils.h" + +// Sets Chromium as default browser (only for current user). Returns false if +// this operation fails (which we can't check for). +bool ShellIntegration::SetAsDefaultBrowser() { + NSBundle* mainBundle = mac_util::MainAppBundle(); + NSString* identifier = [mainBundle bundleIdentifier]; + [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; + return true; +} + +namespace { + +// Returns true if |identifier| is the bundle id of the default browser. +bool IsIdentifierDefaultBrowser(NSString* identifier) { + NSString* defaultBrowser = + [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier]; + if (!identifier || !defaultBrowser) + return false; + // We need to ensure we do the comparison case-insensitive as LS doesn't + // persist the case of our bundle id. + NSComparisonResult result = + [defaultBrowser caseInsensitiveCompare:identifier]; + return result == NSOrderedSame; +} + +} // namespace + +// Returns true if this instance of Chromium is the default browser. (Defined +// as being the handler for the http/https protocols... we don't want to +// report false here if the user has simply chosen to open HTML files in a +// text editor and ftp links with a FTP client). +bool ShellIntegration::IsDefaultBrowser() { + NSBundle* mainBundle = mac_util::MainAppBundle(); + NSString* myIdentifier = [mainBundle bundleIdentifier]; + return IsIdentifierDefaultBrowser(myIdentifier); +} + +// Returns true if Firefox is the default browser for the current user. +bool ShellIntegration::IsFirefoxDefaultBrowser() { + return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); +} |