Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome/browser/shell_integration_mac.mm

Issue 261039: Use the real bundle identifier instead of the framework's identifier for dete... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #import "third_party/mozilla/include/NSWorkspace+Utils.h" 8 #import "third_party/mozilla/include/NSWorkspace+Utils.h"
9 9
10 // Sets Chromium as default browser (only for current user). Returns false if 10 // Sets Chromium as default browser (only for current user). Returns false if
11 // this operation fails (which we can't check for). 11 // this operation fails (which we can't check for).
12 bool ShellIntegration::SetAsDefaultBrowser() { 12 bool ShellIntegration::SetAsDefaultBrowser() {
13 NSBundle* mainBundle = mac_util::MainAppBundle(); 13 // We really do want the main bundle here, not mac_util::MainAppBundle(),
14 NSString* identifier = [mainBundle bundleIdentifier]; 14 // which is the bundle for the framework.
15 NSString* identifier = [[NSBundle mainBundle] bundleIdentifier];
15 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; 16 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier];
16 return true; 17 return true;
17 } 18 }
18 19
19 namespace { 20 namespace {
20 21
21 // Returns true if |identifier| is the bundle id of the default browser. 22 // Returns true if |identifier| is the bundle id of the default browser.
22 bool IsIdentifierDefaultBrowser(NSString* identifier) { 23 bool IsIdentifierDefaultBrowser(NSString* identifier) {
23 NSString* defaultBrowser = 24 NSString* defaultBrowser =
24 [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier]; 25 [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier];
25 if (!defaultBrowser) 26 if (!defaultBrowser)
26 return false; 27 return false;
27 // We need to ensure we do the comparison case-insensitive as LS doesn't 28 // We need to ensure we do the comparison case-insensitive as LS doesn't
28 // persist the case of our bundle id. 29 // persist the case of our bundle id.
29 NSComparisonResult result = 30 NSComparisonResult result =
30 [defaultBrowser caseInsensitiveCompare:identifier]; 31 [defaultBrowser caseInsensitiveCompare:identifier];
31 return result == NSOrderedSame; 32 return result == NSOrderedSame;
32 } 33 }
33 34
34 } // namespace 35 } // namespace
35 36
36 // Attempt to determine if this instance of Chrome is the default browser and 37 // Attempt to determine if this instance of Chrome is the default browser and
37 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS 38 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS
38 // protocols; we don't want to report "no" here if the user has simply chosen 39 // protocols; we don't want to report "no" here if the user has simply chosen
39 // to open HTML files in a text editor and FTP links with an FTP client.) 40 // to open HTML files in a text editor and FTP links with an FTP client.)
40 ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { 41 ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() {
41 NSBundle* mainBundle = mac_util::MainAppBundle(); 42 // As above, we want to use the real main bundle.
42 NSString* myIdentifier = [mainBundle bundleIdentifier]; 43 NSString* myIdentifier = [[NSBundle mainBundle] bundleIdentifier];
43 if (!myIdentifier) 44 if (!myIdentifier)
44 return UNKNOWN_DEFAULT_BROWSER; 45 return UNKNOWN_DEFAULT_BROWSER;
45 return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_BROWSER 46 return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_BROWSER
46 : NOT_DEFAULT_BROWSER; 47 : NOT_DEFAULT_BROWSER;
47 } 48 }
48 49
49 // Returns true if Firefox is the default browser for the current user. 50 // Returns true if Firefox is the default browser for the current user.
50 bool ShellIntegration::IsFirefoxDefaultBrowser() { 51 bool ShellIntegration::IsFirefoxDefaultBrowser() {
51 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); 52 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox");
52 } 53 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698