browser/components/shell/src/nsMacShellService.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsDirectoryServiceDefs.h"
michael@0 7 #include "nsIDOMElement.h"
michael@0 8 #include "nsIDOMHTMLImageElement.h"
michael@0 9 #include "nsIImageLoadingContent.h"
michael@0 10 #include "nsIDocument.h"
michael@0 11 #include "nsIContent.h"
michael@0 12 #include "nsILocalFileMac.h"
michael@0 13 #include "nsIObserverService.h"
michael@0 14 #include "nsIPrefService.h"
michael@0 15 #include "nsIServiceManager.h"
michael@0 16 #include "nsIStringBundle.h"
michael@0 17 #include "nsIURL.h"
michael@0 18 #include "nsIWebBrowserPersist.h"
michael@0 19 #include "nsMacShellService.h"
michael@0 20 #include "nsNetUtil.h"
michael@0 21 #include "nsShellService.h"
michael@0 22 #include "nsStringAPI.h"
michael@0 23 #include "nsIDocShell.h"
michael@0 24 #include "nsILoadContext.h"
michael@0 25
michael@0 26 #include <CoreFoundation/CoreFoundation.h>
michael@0 27 #include <ApplicationServices/ApplicationServices.h>
michael@0 28
michael@0 29 #define NETWORK_PREFPANE NS_LITERAL_CSTRING("/System/Library/PreferencePanes/Network.prefPane")
michael@0 30 #define DESKTOP_PREFPANE NS_LITERAL_CSTRING("/System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane")
michael@0 31
michael@0 32 #define SAFARI_BUNDLE_IDENTIFIER "com.apple.Safari"
michael@0 33
michael@0 34 NS_IMPL_ISUPPORTS(nsMacShellService, nsIMacShellService, nsIShellService, nsIWebProgressListener)
michael@0 35
michael@0 36 NS_IMETHODIMP
michael@0 37 nsMacShellService::IsDefaultBrowser(bool aStartupCheck,
michael@0 38 bool aForAllTypes,
michael@0 39 bool* aIsDefaultBrowser)
michael@0 40 {
michael@0 41 *aIsDefaultBrowser = false;
michael@0 42
michael@0 43 CFStringRef firefoxID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
michael@0 44 if (!firefoxID) {
michael@0 45 // CFBundleGetIdentifier is expected to return nullptr only if the specified
michael@0 46 // bundle doesn't have a bundle identifier in its plist. In this case, that
michael@0 47 // means a failure, since our bundle does have an identifier.
michael@0 48 return NS_ERROR_FAILURE;
michael@0 49 }
michael@0 50
michael@0 51 // Get the default http handler's bundle ID (or nullptr if it has not been
michael@0 52 // explicitly set)
michael@0 53 CFStringRef defaultBrowserID = ::LSCopyDefaultHandlerForURLScheme(CFSTR("http"));
michael@0 54 if (defaultBrowserID) {
michael@0 55 *aIsDefaultBrowser = ::CFStringCompare(firefoxID, defaultBrowserID, 0) == kCFCompareEqualTo;
michael@0 56 ::CFRelease(defaultBrowserID);
michael@0 57 }
michael@0 58
michael@0 59 // If this is the first browser window, maintain internal state that we've
michael@0 60 // checked this session (so that subsequent window opens don't show the
michael@0 61 // default browser dialog).
michael@0 62 if (aStartupCheck)
michael@0 63 mCheckedThisSession = true;
michael@0 64
michael@0 65 return NS_OK;
michael@0 66 }
michael@0 67
michael@0 68 NS_IMETHODIMP
michael@0 69 nsMacShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
michael@0 70 {
michael@0 71 // Note: We don't support aForAllUsers on Mac OS X.
michael@0 72
michael@0 73 CFStringRef firefoxID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
michael@0 74 if (!firefoxID) {
michael@0 75 return NS_ERROR_FAILURE;
michael@0 76 }
michael@0 77
michael@0 78 if (::LSSetDefaultHandlerForURLScheme(CFSTR("http"), firefoxID) != noErr) {
michael@0 79 return NS_ERROR_FAILURE;
michael@0 80 }
michael@0 81 if (::LSSetDefaultHandlerForURLScheme(CFSTR("https"), firefoxID) != noErr) {
michael@0 82 return NS_ERROR_FAILURE;
michael@0 83 }
michael@0 84
michael@0 85 if (aClaimAllTypes) {
michael@0 86 if (::LSSetDefaultHandlerForURLScheme(CFSTR("ftp"), firefoxID) != noErr) {
michael@0 87 return NS_ERROR_FAILURE;
michael@0 88 }
michael@0 89 if (::LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesAll, firefoxID) != noErr) {
michael@0 90 return NS_ERROR_FAILURE;
michael@0 91 }
michael@0 92 }
michael@0 93
michael@0 94 return NS_OK;
michael@0 95 }
michael@0 96
michael@0 97 NS_IMETHODIMP
michael@0 98 nsMacShellService::GetShouldCheckDefaultBrowser(bool* aResult)
michael@0 99 {
michael@0 100 // If we've already checked, the browser has been started and this is a
michael@0 101 // new window open, and we don't want to check again.
michael@0 102 if (mCheckedThisSession) {
michael@0 103 *aResult = false;
michael@0 104 return NS_OK;
michael@0 105 }
michael@0 106
michael@0 107 nsCOMPtr<nsIPrefBranch> prefs;
michael@0 108 nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
michael@0 109 if (pserve)
michael@0 110 pserve->GetBranch("", getter_AddRefs(prefs));
michael@0 111
michael@0 112 prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult);
michael@0 113
michael@0 114 return NS_OK;
michael@0 115 }
michael@0 116
michael@0 117 NS_IMETHODIMP
michael@0 118 nsMacShellService::SetShouldCheckDefaultBrowser(bool aShouldCheck)
michael@0 119 {
michael@0 120 nsCOMPtr<nsIPrefBranch> prefs;
michael@0 121 nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
michael@0 122 if (pserve)
michael@0 123 pserve->GetBranch("", getter_AddRefs(prefs));
michael@0 124
michael@0 125 prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck);
michael@0 126
michael@0 127 return NS_OK;
michael@0 128 }
michael@0 129
michael@0 130 NS_IMETHODIMP
michael@0 131 nsMacShellService::GetCanSetDesktopBackground(bool* aResult)
michael@0 132 {
michael@0 133 *aResult = true;
michael@0 134 return NS_OK;
michael@0 135 }
michael@0 136
michael@0 137 NS_IMETHODIMP
michael@0 138 nsMacShellService::SetDesktopBackground(nsIDOMElement* aElement,
michael@0 139 int32_t aPosition)
michael@0 140 {
michael@0 141 // Note: We don't support aPosition on OS X.
michael@0 142
michael@0 143 // Get the image URI:
michael@0 144 nsresult rv;
michael@0 145 nsCOMPtr<nsIImageLoadingContent> imageContent = do_QueryInterface(aElement,
michael@0 146 &rv);
michael@0 147 NS_ENSURE_SUCCESS(rv, rv);
michael@0 148 nsCOMPtr<nsIURI> imageURI;
michael@0 149 rv = imageContent->GetCurrentURI(getter_AddRefs(imageURI));
michael@0 150 NS_ENSURE_SUCCESS(rv, rv);
michael@0 151
michael@0 152 // We need the referer URI for nsIWebBrowserPersist::saveURI
michael@0 153 nsCOMPtr<nsIContent> content = do_QueryInterface(aElement, &rv);
michael@0 154 NS_ENSURE_SUCCESS(rv, rv);
michael@0 155
michael@0 156 nsIURI *docURI = content->OwnerDoc()->GetDocumentURI();
michael@0 157 if (!docURI)
michael@0 158 return NS_ERROR_FAILURE;
michael@0 159
michael@0 160 // Get the desired image file name
michael@0 161 nsCOMPtr<nsIURL> imageURL(do_QueryInterface(imageURI));
michael@0 162 if (!imageURL) {
michael@0 163 // XXXmano (bug 300293): Non-URL images (e.g. the data: protocol) are not
michael@0 164 // yet supported. What filename should we take here?
michael@0 165 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 166 }
michael@0 167
michael@0 168 nsAutoCString fileName;
michael@0 169 imageURL->GetFileName(fileName);
michael@0 170 nsCOMPtr<nsIProperties> fileLocator
michael@0 171 (do_GetService("@mozilla.org/file/directory_service;1", &rv));
michael@0 172 NS_ENSURE_SUCCESS(rv, rv);
michael@0 173
michael@0 174 // Get the current user's "Pictures" folder (That's ~/Pictures):
michael@0 175 fileLocator->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, NS_GET_IID(nsIFile),
michael@0 176 getter_AddRefs(mBackgroundFile));
michael@0 177 if (!mBackgroundFile)
michael@0 178 return NS_ERROR_OUT_OF_MEMORY;
michael@0 179
michael@0 180 nsAutoString fileNameUnicode;
michael@0 181 CopyUTF8toUTF16(fileName, fileNameUnicode);
michael@0 182
michael@0 183 // and add the imgage file name itself:
michael@0 184 mBackgroundFile->Append(fileNameUnicode);
michael@0 185
michael@0 186 // Download the image; the desktop background will be set in OnStateChange()
michael@0 187 nsCOMPtr<nsIWebBrowserPersist> wbp
michael@0 188 (do_CreateInstance("@mozilla.org/embedding/browser/nsWebBrowserPersist;1", &rv));
michael@0 189 NS_ENSURE_SUCCESS(rv, rv);
michael@0 190
michael@0 191 uint32_t flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
michael@0 192 nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES |
michael@0 193 nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
michael@0 194
michael@0 195 wbp->SetPersistFlags(flags);
michael@0 196 wbp->SetProgressListener(this);
michael@0 197
michael@0 198 nsCOMPtr<nsILoadContext> loadContext;
michael@0 199 nsCOMPtr<nsISupports> container = content->OwnerDoc()->GetContainer();
michael@0 200 nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
michael@0 201 if (docShell) {
michael@0 202 loadContext = do_QueryInterface(docShell);
michael@0 203 }
michael@0 204
michael@0 205 return wbp->SaveURI(imageURI, nullptr, docURI, nullptr, nullptr,
michael@0 206 mBackgroundFile, loadContext);
michael@0 207 }
michael@0 208
michael@0 209 NS_IMETHODIMP
michael@0 210 nsMacShellService::OnProgressChange(nsIWebProgress* aWebProgress,
michael@0 211 nsIRequest* aRequest,
michael@0 212 int32_t aCurSelfProgress,
michael@0 213 int32_t aMaxSelfProgress,
michael@0 214 int32_t aCurTotalProgress,
michael@0 215 int32_t aMaxTotalProgress)
michael@0 216 {
michael@0 217 return NS_OK;
michael@0 218 }
michael@0 219
michael@0 220 NS_IMETHODIMP
michael@0 221 nsMacShellService::OnLocationChange(nsIWebProgress* aWebProgress,
michael@0 222 nsIRequest* aRequest,
michael@0 223 nsIURI* aLocation,
michael@0 224 uint32_t aFlags)
michael@0 225 {
michael@0 226 return NS_OK;
michael@0 227 }
michael@0 228
michael@0 229 NS_IMETHODIMP
michael@0 230 nsMacShellService::OnStatusChange(nsIWebProgress* aWebProgress,
michael@0 231 nsIRequest* aRequest,
michael@0 232 nsresult aStatus,
michael@0 233 const char16_t* aMessage)
michael@0 234 {
michael@0 235 return NS_OK;
michael@0 236 }
michael@0 237
michael@0 238 NS_IMETHODIMP
michael@0 239 nsMacShellService::OnSecurityChange(nsIWebProgress* aWebProgress,
michael@0 240 nsIRequest* aRequest,
michael@0 241 uint32_t aState)
michael@0 242 {
michael@0 243 return NS_OK;
michael@0 244 }
michael@0 245
michael@0 246 NS_IMETHODIMP
michael@0 247 nsMacShellService::OnStateChange(nsIWebProgress* aWebProgress,
michael@0 248 nsIRequest* aRequest,
michael@0 249 uint32_t aStateFlags,
michael@0 250 nsresult aStatus)
michael@0 251 {
michael@0 252 if (aStateFlags & STATE_STOP) {
michael@0 253 nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
michael@0 254 if (os)
michael@0 255 os->NotifyObservers(nullptr, "shell:desktop-background-changed", nullptr);
michael@0 256
michael@0 257 bool exists = false;
michael@0 258 mBackgroundFile->Exists(&exists);
michael@0 259 if (!exists)
michael@0 260 return NS_OK;
michael@0 261
michael@0 262 nsAutoCString nativePath;
michael@0 263 mBackgroundFile->GetNativePath(nativePath);
michael@0 264
michael@0 265 AEDesc tAEDesc = { typeNull, nil };
michael@0 266 OSErr err = noErr;
michael@0 267 AliasHandle aliasHandle = nil;
michael@0 268 FSRef pictureRef;
michael@0 269 OSStatus status;
michael@0 270
michael@0 271 // Convert the path into a FSRef
michael@0 272 status = ::FSPathMakeRef((const UInt8*)nativePath.get(), &pictureRef,
michael@0 273 nullptr);
michael@0 274 if (status == noErr) {
michael@0 275 err = ::FSNewAlias(nil, &pictureRef, &aliasHandle);
michael@0 276 if (err == noErr && aliasHandle == nil)
michael@0 277 err = paramErr;
michael@0 278
michael@0 279 if (err == noErr) {
michael@0 280 // We need the descriptor (based on the picture file reference)
michael@0 281 // for the 'Set Desktop Picture' apple event.
michael@0 282 char handleState = ::HGetState((Handle)aliasHandle);
michael@0 283 ::HLock((Handle)aliasHandle);
michael@0 284 err = ::AECreateDesc(typeAlias, *aliasHandle,
michael@0 285 GetHandleSize((Handle)aliasHandle), &tAEDesc);
michael@0 286 // unlock the alias handler
michael@0 287 ::HSetState((Handle)aliasHandle, handleState);
michael@0 288 ::DisposeHandle((Handle)aliasHandle);
michael@0 289 }
michael@0 290 if (err == noErr) {
michael@0 291 AppleEvent tAppleEvent;
michael@0 292 OSType sig = 'MACS';
michael@0 293 AEBuildError tAEBuildError;
michael@0 294 // Create a 'Set Desktop Pictue' Apple Event
michael@0 295 err = ::AEBuildAppleEvent(kAECoreSuite, kAESetData, typeApplSignature,
michael@0 296 &sig, sizeof(OSType), kAutoGenerateReturnID,
michael@0 297 kAnyTransactionID, &tAppleEvent, &tAEBuildError,
michael@0 298 "'----':'obj '{want:type (prop),form:prop" \
michael@0 299 ",seld:type('dpic'),from:'null'()},data:(@)",
michael@0 300 &tAEDesc);
michael@0 301 if (err == noErr) {
michael@0 302 AppleEvent reply = { typeNull, nil };
michael@0 303 // Sent the event we built, the reply event isn't necessary
michael@0 304 err = ::AESend(&tAppleEvent, &reply, kAENoReply, kAENormalPriority,
michael@0 305 kNoTimeOut, nil, nil);
michael@0 306 ::AEDisposeDesc(&tAppleEvent);
michael@0 307 }
michael@0 308 }
michael@0 309 }
michael@0 310 }
michael@0 311
michael@0 312 return NS_OK;
michael@0 313 }
michael@0 314
michael@0 315 NS_IMETHODIMP
michael@0 316 nsMacShellService::OpenApplication(int32_t aApplication)
michael@0 317 {
michael@0 318 nsresult rv = NS_OK;
michael@0 319 CFURLRef appURL = nil;
michael@0 320 OSStatus err = noErr;
michael@0 321
michael@0 322 switch (aApplication) {
michael@0 323 case nsIShellService::APPLICATION_MAIL:
michael@0 324 {
michael@0 325 CFURLRef tempURL = ::CFURLCreateWithString(kCFAllocatorDefault,
michael@0 326 CFSTR("mailto:"), nullptr);
michael@0 327 err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, nullptr, &appURL);
michael@0 328 ::CFRelease(tempURL);
michael@0 329 }
michael@0 330 break;
michael@0 331 case nsIShellService::APPLICATION_NEWS:
michael@0 332 {
michael@0 333 CFURLRef tempURL = ::CFURLCreateWithString(kCFAllocatorDefault,
michael@0 334 CFSTR("news:"), nullptr);
michael@0 335 err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, nullptr, &appURL);
michael@0 336 ::CFRelease(tempURL);
michael@0 337 }
michael@0 338 break;
michael@0 339 case nsIMacShellService::APPLICATION_KEYCHAIN_ACCESS:
michael@0 340 err = ::LSGetApplicationForInfo('APPL', 'kcmr', nullptr, kLSRolesAll,
michael@0 341 nullptr, &appURL);
michael@0 342 break;
michael@0 343 case nsIMacShellService::APPLICATION_NETWORK:
michael@0 344 {
michael@0 345 nsCOMPtr<nsIFile> lf;
michael@0 346 rv = NS_NewNativeLocalFile(NETWORK_PREFPANE, true, getter_AddRefs(lf));
michael@0 347 NS_ENSURE_SUCCESS(rv, rv);
michael@0 348 bool exists;
michael@0 349 lf->Exists(&exists);
michael@0 350 if (!exists)
michael@0 351 return NS_ERROR_FILE_NOT_FOUND;
michael@0 352 return lf->Launch();
michael@0 353 }
michael@0 354 break;
michael@0 355 case nsIMacShellService::APPLICATION_DESKTOP:
michael@0 356 {
michael@0 357 nsCOMPtr<nsIFile> lf;
michael@0 358 rv = NS_NewNativeLocalFile(DESKTOP_PREFPANE, true, getter_AddRefs(lf));
michael@0 359 NS_ENSURE_SUCCESS(rv, rv);
michael@0 360 bool exists;
michael@0 361 lf->Exists(&exists);
michael@0 362 if (!exists)
michael@0 363 return NS_ERROR_FILE_NOT_FOUND;
michael@0 364 return lf->Launch();
michael@0 365 }
michael@0 366 break;
michael@0 367 }
michael@0 368
michael@0 369 if (appURL && err == noErr) {
michael@0 370 err = ::LSOpenCFURLRef(appURL, nullptr);
michael@0 371 rv = err != noErr ? NS_ERROR_FAILURE : NS_OK;
michael@0 372
michael@0 373 ::CFRelease(appURL);
michael@0 374 }
michael@0 375
michael@0 376 return rv;
michael@0 377 }
michael@0 378
michael@0 379 NS_IMETHODIMP
michael@0 380 nsMacShellService::GetDesktopBackgroundColor(uint32_t *aColor)
michael@0 381 {
michael@0 382 // This method and |SetDesktopBackgroundColor| has no meaning on Mac OS X.
michael@0 383 // The mac desktop preferences UI uses pictures for the few solid colors it
michael@0 384 // supports.
michael@0 385 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 386 }
michael@0 387
michael@0 388 NS_IMETHODIMP
michael@0 389 nsMacShellService::SetDesktopBackgroundColor(uint32_t aColor)
michael@0 390 {
michael@0 391 // This method and |GetDesktopBackgroundColor| has no meaning on Mac OS X.
michael@0 392 // The mac desktop preferences UI uses pictures for the few solid colors it
michael@0 393 // supports.
michael@0 394 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 395 }
michael@0 396
michael@0 397 NS_IMETHODIMP
michael@0 398 nsMacShellService::OpenApplicationWithURI(nsIFile* aApplication, const nsACString& aURI)
michael@0 399 {
michael@0 400 nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(aApplication));
michael@0 401 CFURLRef appURL;
michael@0 402 nsresult rv = lfm->GetCFURL(&appURL);
michael@0 403 if (NS_FAILED(rv))
michael@0 404 return rv;
michael@0 405
michael@0 406 const nsCString spec(aURI);
michael@0 407 const UInt8* uriString = (const UInt8*)spec.get();
michael@0 408 CFURLRef uri = ::CFURLCreateWithBytes(nullptr, uriString, aURI.Length(),
michael@0 409 kCFStringEncodingUTF8, nullptr);
michael@0 410 if (!uri)
michael@0 411 return NS_ERROR_OUT_OF_MEMORY;
michael@0 412
michael@0 413 CFArrayRef uris = ::CFArrayCreate(nullptr, (const void**)&uri, 1, nullptr);
michael@0 414 if (!uris) {
michael@0 415 ::CFRelease(uri);
michael@0 416 return NS_ERROR_OUT_OF_MEMORY;
michael@0 417 }
michael@0 418
michael@0 419 LSLaunchURLSpec launchSpec;
michael@0 420 launchSpec.appURL = appURL;
michael@0 421 launchSpec.itemURLs = uris;
michael@0 422 launchSpec.passThruParams = nullptr;
michael@0 423 launchSpec.launchFlags = kLSLaunchDefaults;
michael@0 424 launchSpec.asyncRefCon = nullptr;
michael@0 425
michael@0 426 OSErr err = ::LSOpenFromURLSpec(&launchSpec, nullptr);
michael@0 427
michael@0 428 ::CFRelease(uris);
michael@0 429 ::CFRelease(uri);
michael@0 430
michael@0 431 return err != noErr ? NS_ERROR_FAILURE : NS_OK;
michael@0 432 }
michael@0 433
michael@0 434 NS_IMETHODIMP
michael@0 435 nsMacShellService::GetDefaultFeedReader(nsIFile** _retval)
michael@0 436 {
michael@0 437 nsresult rv = NS_ERROR_FAILURE;
michael@0 438 *_retval = nullptr;
michael@0 439
michael@0 440 CFStringRef defaultHandlerID = ::LSCopyDefaultHandlerForURLScheme(CFSTR("feed"));
michael@0 441 if (!defaultHandlerID) {
michael@0 442 defaultHandlerID = ::CFStringCreateWithCString(kCFAllocatorDefault,
michael@0 443 SAFARI_BUNDLE_IDENTIFIER,
michael@0 444 kCFStringEncodingASCII);
michael@0 445 }
michael@0 446
michael@0 447 CFURLRef defaultHandlerURL = nullptr;
michael@0 448 OSStatus status = ::LSFindApplicationForInfo(kLSUnknownCreator,
michael@0 449 defaultHandlerID,
michael@0 450 nullptr, // inName
michael@0 451 nullptr, // outAppRef
michael@0 452 &defaultHandlerURL);
michael@0 453
michael@0 454 if (status == noErr && defaultHandlerURL) {
michael@0 455 nsCOMPtr<nsILocalFileMac> defaultReader =
michael@0 456 do_CreateInstance("@mozilla.org/file/local;1", &rv);
michael@0 457 if (NS_SUCCEEDED(rv)) {
michael@0 458 rv = defaultReader->InitWithCFURL(defaultHandlerURL);
michael@0 459 if (NS_SUCCEEDED(rv)) {
michael@0 460 NS_ADDREF(*_retval = defaultReader);
michael@0 461 rv = NS_OK;
michael@0 462 }
michael@0 463 }
michael@0 464
michael@0 465 ::CFRelease(defaultHandlerURL);
michael@0 466 }
michael@0 467
michael@0 468 ::CFRelease(defaultHandlerID);
michael@0 469
michael@0 470 return rv;
michael@0 471 }

mercurial