1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * Simon Fraser <smfr@smfr.org>
24 * Josh Aas <josh@mozilla.com>
25 * Nick Kreeger <nick.kreeger@park.edu>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #import "NSWorkspace+Utils.h"
43 @implementation NSWorkspace(CaminoDefaultBrowserAdditions)
45 - (NSArray*)installedBrowserIdentifiers
47 NSArray* apps = [(NSArray*)LSCopyAllHandlersForURLScheme(CFSTR("https")) autorelease];
49 // add the default if it isn't there
50 NSString* defaultHandler = [self defaultBrowserIdentifier];
51 if (defaultHandler && ([apps indexOfObject:defaultHandler] == NSNotFound))
52 apps = [apps arrayByAddingObject:defaultHandler];
57 - (NSArray*)installedFeedViewerIdentifiers
59 NSArray* apps = [(NSArray*)LSCopyAllHandlersForURLScheme(CFSTR("feed")) autorelease];
61 // add the default if it isn't there
62 NSString* defaultHandler = [self defaultFeedViewerIdentifier];
63 if (defaultHandler && ([apps indexOfObject:defaultHandler] == NSNotFound))
64 apps = [apps arrayByAddingObject:defaultHandler];
69 - (NSString*)defaultBrowserIdentifier
71 NSString* defaultBundleId = [(NSString*)LSCopyDefaultHandlerForURLScheme(CFSTR("http")) autorelease];
72 // Sometimes LaunchServices likes to pretend there's no default browser.
73 // If that happens, we'll assume it's probably Safari.
75 defaultBundleId = @"com.apple.safari";
76 return defaultBundleId;
79 - (NSString*)defaultFeedViewerIdentifier
81 return [(NSString*)LSCopyDefaultHandlerForURLScheme(CFSTR("feed")) autorelease];
84 - (NSURL*)defaultBrowserURL
86 NSString* defaultBundleId = [self defaultBrowserIdentifier];
88 return [self urlOfApplicationWithIdentifier:defaultBundleId];
92 - (NSURL*)defaultFeedViewerURL
94 NSString* defaultBundleId = [self defaultFeedViewerIdentifier];
96 return [self urlOfApplicationWithIdentifier:defaultBundleId];
100 - (void)setDefaultBrowserWithIdentifier:(NSString*)bundleID
102 LSSetDefaultHandlerForURLScheme(CFSTR("http"), (CFStringRef)bundleID);
103 LSSetDefaultHandlerForURLScheme(CFSTR("https"), (CFStringRef)bundleID);
104 LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesViewer, (CFStringRef)bundleID);
105 LSSetDefaultRoleHandlerForContentType(kUTTypeURL, kLSRolesViewer, (CFStringRef)bundleID);
108 - (void)setDefaultFeedViewerWithIdentifier:(NSString*)bundleID
110 LSSetDefaultHandlerForURLScheme(CFSTR("feed"), (CFStringRef)bundleID);
113 - (NSURL*)urlOfApplicationWithIdentifier:(NSString*)bundleID
118 if (LSFindApplicationForInfo(kLSUnknownCreator, (CFStringRef)bundleID, NULL, NULL, (CFURLRef*)&appURL) == noErr)
119 return [appURL autorelease];
124 - (NSString*)identifierForBundle:(NSURL*)inBundleURL
126 if (!inBundleURL) return nil;
128 NSBundle* tmpBundle = [NSBundle bundleWithPath:[[inBundleURL path] stringByStandardizingPath]];
131 NSString* tmpBundleID = [tmpBundle bundleIdentifier];
132 if (tmpBundleID && ([tmpBundleID length] > 0)) {
139 - (NSString*)displayNameForFile:(NSURL*)inFileURL
142 LSCopyDisplayNameForURL((CFURLRef)inFileURL, (CFStringRef *)&name);
143 return [name autorelease];
149 // Returns the system version string from
150 // /System/Library/CoreServices/SystemVersion.plist
151 // (as recommended by Apple).
153 + (NSString*)osVersionString
155 NSDictionary* versionInfo = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
156 return [versionInfo objectForKey:@"ProductVersion"];
162 // Returns the host's OS version as returned by the 'sysv' gestalt selector,
163 // 10.x.y = 0x000010xy
165 + (long)systemVersion
167 static SInt32 sSystemVersion = 0;
169 Gestalt(gestaltSystemVersion, &sSystemVersion);
170 return (long)sSystemVersion;
174 // +isLeopardOrHigher
176 // returns YES if we're on 10.5 or better
178 + (BOOL)isLeopardOrHigher
180 #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
183 return [self systemVersion] >= 0x1050;