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

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

Issue 200025: Allow the default browser check to return "unknown" and reflect that in the UI. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
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 NSBundle* mainBundle = mac_util::MainAppBundle();
14 NSString* identifier = [mainBundle bundleIdentifier]; 14 NSString* identifier = [mainBundle bundleIdentifier];
15 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; 15 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier];
16 return true; 16 return true;
17 } 17 }
18 18
19 namespace { 19 namespace {
20 20
21 // Returns true if |identifier| is the bundle id of the default browser. 21 // Returns true if |identifier| is the bundle id of the default browser.
22 bool IsIdentifierDefaultBrowser(NSString* identifier) { 22 bool IsIdentifierDefaultBrowser(NSString* identifier) {
23 NSString* defaultBrowser = 23 NSString* defaultBrowser =
24 [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier]; 24 [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier];
25 if (!identifier || !defaultBrowser) 25 if (!defaultBrowser)
26 return false; 26 return false;
27 // We need to ensure we do the comparison case-insensitive as LS doesn't 27 // We need to ensure we do the comparison case-insensitive as LS doesn't
28 // persist the case of our bundle id. 28 // persist the case of our bundle id.
29 NSComparisonResult result = 29 NSComparisonResult result =
30 [defaultBrowser caseInsensitiveCompare:identifier]; 30 [defaultBrowser caseInsensitiveCompare:identifier];
31 return result == NSOrderedSame; 31 return result == NSOrderedSame;
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 // Returns true if this instance of Chromium is the default browser. (Defined 36 // Attempt to determine if this instance of Chrome is the default browser and
37 // as being the handler for the http/https protocols... we don't want to 37 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS
38 // report false here if the user has simply chosen to open HTML files in a 38 // protocols; we don't want to report "no" here if the user has simply chosen
39 // text editor and ftp links with a FTP client). 39 // to open HTML files in a text editor and FTP links with an FTP client.)
40 bool ShellIntegration::IsDefaultBrowser() { 40 ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() {
41 NSBundle* mainBundle = mac_util::MainAppBundle(); 41 NSBundle* mainBundle = mac_util::MainAppBundle();
42 NSString* myIdentifier = [mainBundle bundleIdentifier]; 42 NSString* myIdentifier = [mainBundle bundleIdentifier];
Evan Martin 2009/09/04 22:46:15 Why can this return null now after your change?
Mike Mammarella 2009/09/04 22:56:27 Presumably it could have before as well; I just mo
43 return IsIdentifierDefaultBrowser(myIdentifier); 43 if (!myIdentifier)
44 return UNKNOWN_DEFAULT_BROWSER;
45 return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_BROWSER
46 : NOT_DEFAULT_BROWSER;
44 } 47 }
45 48
46 // Returns true if Firefox is the default browser for the current user. 49 // Returns true if Firefox is the default browser for the current user.
47 bool ShellIntegration::IsFirefoxDefaultBrowser() { 50 bool ShellIntegration::IsFirefoxDefaultBrowser() {
48 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); 51 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox");
49 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698