40 #include "nsDirectoryServiceDefs.h"
41 #include "nsIDOMElement.h"
42 #include "nsIDOMHTMLImageElement.h"
43 #include "nsIImageLoadingContent.h"
44 #include "nsIDocument.h"
45 #include "nsIContent.h"
46 #include "nsILocalFileMac.h"
47 #include "nsIObserverService.h"
48 #include "nsIPrefService.h"
49 #include "nsIServiceManager.h"
50 #include "nsIStringBundle.h"
52 #include "nsIWebBrowserPersist.h"
54 #include "nsNetUtil.h"
56 #include "nsStringAPI.h"
58 #include <CoreFoundation/CoreFoundation.h>
59 #include <Carbon/Carbon.h>
61 #define NETWORK_PREFPANE NS_LITERAL_CSTRING("/System/Library/PreferencePanes/Network.prefPane")
62 #define DESKTOP_PREFPANE NS_LITERAL_CSTRING("/System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane")
64 #define SAFARI_BUNDLE_IDENTIFIER "com.apple.Safari"
69 nsMacShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser)
71 *aIsDefaultBrowser = PR_FALSE;
73 CFStringRef firefoxID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
78 return NS_ERROR_FAILURE;
82 CFStringRef defaultBrowserID = ::LSCopyDefaultHandlerForURLScheme(CFSTR(
"http"));
83 if (defaultBrowserID) {
84 *aIsDefaultBrowser = ::CFStringCompare(firefoxID, defaultBrowserID, 0) == kCFCompareEqualTo;
85 ::CFRelease(defaultBrowserID);
92 mCheckedThisSession = PR_TRUE;
98 nsMacShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers)
102 CFStringRef firefoxID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
104 return NS_ERROR_FAILURE;
107 if (::LSSetDefaultHandlerForURLScheme(CFSTR(
"http"), firefoxID) != noErr) {
108 return NS_ERROR_FAILURE;
110 if (::LSSetDefaultHandlerForURLScheme(CFSTR(
"https"), firefoxID) != noErr) {
111 return NS_ERROR_FAILURE;
114 if (aClaimAllTypes) {
115 if (::LSSetDefaultHandlerForURLScheme(CFSTR(
"ftp"), firefoxID) != noErr) {
116 return NS_ERROR_FAILURE;
118 if (::LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesAll, firefoxID) != noErr) {
119 return NS_ERROR_FAILURE;
127 nsMacShellService::GetShouldCheckDefaultBrowser(PRBool* aResult)
131 if (mCheckedThisSession) {
136 nsCOMPtr<nsIPrefBranch>
prefs;
139 pserve->GetBranch(
"", getter_AddRefs(prefs));
147 nsMacShellService::SetShouldCheckDefaultBrowser(PRBool aShouldCheck)
149 nsCOMPtr<nsIPrefBranch>
prefs;
152 pserve->GetBranch(
"", getter_AddRefs(prefs));
160 nsMacShellService::SetDesktopBackground(nsIDOMElement* aElement,
167 nsCOMPtr<nsIImageLoadingContent> imageContent = do_QueryInterface(aElement,
169 NS_ENSURE_SUCCESS(rv, rv);
170 nsCOMPtr<nsIURI> imageURI;
171 rv = imageContent->GetCurrentURI(getter_AddRefs(imageURI));
172 NS_ENSURE_SUCCESS(rv, rv);
175 nsCOMPtr<nsIContent> content = do_QueryInterface(aElement, &rv);
176 NS_ENSURE_SUCCESS(rv, rv);
177 nsCOMPtr<nsIDocument>
doc;
178 doc = content->GetOwnerDoc();
180 return NS_ERROR_FAILURE;
182 nsIURI *docURI = doc->GetDocumentURI();
184 return NS_ERROR_FAILURE;
187 nsCOMPtr<nsIURL> imageURL(do_QueryInterface(imageURI));
191 return NS_ERROR_NOT_IMPLEMENTED;
194 nsCAutoString fileName;
195 imageURL->GetFileName(fileName);
196 nsCOMPtr<nsIProperties> fileLocator
197 (do_GetService(
"@mozilla.org/file/directory_service;1", &rv));
198 NS_ENSURE_SUCCESS(rv, rv);
201 fileLocator->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, NS_GET_IID(nsILocalFile),
202 getter_AddRefs(mBackgroundFile));
203 if (!mBackgroundFile)
204 return NS_ERROR_OUT_OF_MEMORY;
206 nsAutoString fileNameUnicode;
207 CopyUTF8toUTF16(fileName, fileNameUnicode);
210 mBackgroundFile->Append(fileNameUnicode);
213 nsCOMPtr<nsIWebBrowserPersist> wbp
214 (do_CreateInstance(
"@mozilla.org/embedding/browser/nsWebBrowserPersist;1", &rv));
215 NS_ENSURE_SUCCESS(rv, rv);
217 PRUint32
flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
218 nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES |
219 nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
221 wbp->SetPersistFlags(flags);
222 wbp->SetProgressListener(
this);
224 return wbp->SaveURI(imageURI, nsnull, docURI, nsnull, nsnull,
229 nsMacShellService::OnProgressChange(nsIWebProgress* aWebProgress,
230 nsIRequest* aRequest,
231 PRInt32 aCurSelfProgress,
232 PRInt32 aMaxSelfProgress,
233 PRInt32 aCurTotalProgress,
234 PRInt32 aMaxTotalProgress)
240 nsMacShellService::OnLocationChange(nsIWebProgress* aWebProgress,
241 nsIRequest* aRequest,
248 nsMacShellService::OnStatusChange(nsIWebProgress* aWebProgress,
249 nsIRequest* aRequest,
251 const PRUnichar* aMessage)
257 nsMacShellService::OnSecurityChange(nsIWebProgress* aWebProgress,
258 nsIRequest* aRequest,
265 nsMacShellService::OnStateChange(nsIWebProgress* aWebProgress,
266 nsIRequest* aRequest,
267 PRUint32 aStateFlags,
270 if (aStateFlags & STATE_STOP) {
271 nsCOMPtr<nsIObserverService>
os(do_GetService(
"@mozilla.org/observer-service;1"));
273 os->NotifyObservers(nsnull,
"shell:desktop-background-changed", nsnull);
275 PRBool exists = PR_FALSE;
276 mBackgroundFile->Exists(&exists);
280 nsCAutoString nativePath;
281 mBackgroundFile->GetNativePath(nativePath);
283 AEDesc tAEDesc = { typeNull, nil };
285 AliasHandle aliasHandle = nil;
290 status = ::FSPathMakeRef((
const UInt8*)nativePath.get(), &pictureRef, NULL);
291 if (status == noErr) {
292 err = ::FSNewAlias(nil, &pictureRef, &aliasHandle);
293 if (err == noErr && aliasHandle == nil)
299 char handleState = ::HGetState((Handle)aliasHandle);
300 ::HLock((Handle)aliasHandle);
301 err = ::AECreateDesc(typeAlias, *aliasHandle,
302 GetHandleSize((Handle)aliasHandle), &tAEDesc);
304 ::HSetState((Handle)aliasHandle, handleState);
305 ::DisposeHandle((Handle)aliasHandle);
308 AppleEvent tAppleEvent;
310 AEBuildError tAEBuildError;
312 err = ::AEBuildAppleEvent(kAECoreSuite, kAESetData, typeApplSignature,
313 &sig,
sizeof(OSType), kAutoGenerateReturnID,
314 kAnyTransactionID, &tAppleEvent, &tAEBuildError,
315 "'----':'obj '{want:type (prop),form:prop" \
316 ",seld:type('dpic'),from:'null'()},data:(@)",
319 AppleEvent reply = { typeNull, nil };
321 err = ::AESend(&tAppleEvent, &reply, kAENoReply, kAENormalPriority,
322 kNoTimeOut, nil, nil);
323 ::AEDisposeDesc(&tAppleEvent);
333 nsMacShellService::OpenApplication(PRInt32 aApplication)
336 CFURLRef appURL = nil;
337 OSStatus err = noErr;
339 switch (aApplication) {
342 CFURLRef tempURL = ::CFURLCreateWithString(kCFAllocatorDefault,
343 CFSTR(
"mailto:"), NULL);
344 err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, NULL, &appURL);
345 ::CFRelease(tempURL);
350 CFURLRef tempURL = ::CFURLCreateWithString(kCFAllocatorDefault,
351 CFSTR(
"news:"), NULL);
352 err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, NULL, &appURL);
353 ::CFRelease(tempURL);
357 err = ::LSGetApplicationForInfo(
'APPL',
'kcmr', NULL, kLSRolesAll, NULL,
362 nsCOMPtr<nsILocalFile> lf;
364 NS_ENSURE_SUCCESS(rv, rv);
368 return NS_ERROR_FILE_NOT_FOUND;
374 nsCOMPtr<nsILocalFile> lf;
376 NS_ENSURE_SUCCESS(rv, rv);
380 return NS_ERROR_FILE_NOT_FOUND;
386 if (appURL && err == noErr) {
387 err = ::LSOpenCFURLRef(appURL, NULL);
388 rv = err != noErr ? NS_ERROR_FAILURE :
NS_OK;
397 nsMacShellService::GetDesktopBackgroundColor(PRUint32 *aColor)
402 return NS_ERROR_NOT_IMPLEMENTED;
406 nsMacShellService::SetDesktopBackgroundColor(PRUint32 aColor)
411 return NS_ERROR_NOT_IMPLEMENTED;
415 nsMacShellService::OpenApplicationWithURI(nsILocalFile* aApplication,
const nsACString& aURI)
417 nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(aApplication));
419 nsresult rv = lfm->GetCFURL(&appURL);
423 const nsCString spec(aURI);
424 const UInt8* uriString = (
const UInt8*)spec.get();
425 CFURLRef
uri = ::CFURLCreateWithBytes(NULL, uriString, aURI.Length(),
426 kCFStringEncodingUTF8, NULL);
428 return NS_ERROR_OUT_OF_MEMORY;
430 CFArrayRef
uris = ::CFArrayCreate(NULL, (
const void**)&uri, 1, NULL);
433 return NS_ERROR_OUT_OF_MEMORY;
436 LSLaunchURLSpec launchSpec;
437 launchSpec.appURL = appURL;
438 launchSpec.itemURLs =
uris;
439 launchSpec.passThruParams = NULL;
440 launchSpec.launchFlags = kLSLaunchDefaults;
441 launchSpec.asyncRefCon = NULL;
443 OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL);
448 return err != noErr ? NS_ERROR_FAILURE :
NS_OK;
452 nsMacShellService::GetDefaultFeedReader(nsILocalFile** _retval)
454 nsresult rv = NS_ERROR_FAILURE;
457 CFStringRef defaultHandlerID = ::LSCopyDefaultHandlerForURLScheme(CFSTR(
"feed"));
458 if (!defaultHandlerID) {
459 defaultHandlerID = ::CFStringCreateWithCString(kCFAllocatorDefault,
461 kCFStringEncodingASCII);
464 CFURLRef defaultHandlerURL = NULL;
465 OSStatus status = ::LSFindApplicationForInfo(kLSUnknownCreator,
471 if (status == noErr && defaultHandlerURL) {
472 nsCOMPtr<nsILocalFileMac> defaultReader =
473 do_CreateInstance(
"@mozilla.org/file/local;1", &rv);
474 if (NS_SUCCEEDED(rv)) {
475 rv = defaultReader->InitWithCFURL(defaultHandlerURL);
476 if (NS_SUCCEEDED(rv)) {
477 NS_ADDREF(*_retval = defaultReader);
482 ::CFRelease(defaultHandlerURL);
485 ::CFRelease(defaultHandlerID);
const long APPLICATION_NEWS
const long APPLICATION_MAIL
const NS_PREFSERVICE_CONTRACTID
function doc() browser.contentDocument
sbDeviceFirmwareAutoCheckForUpdate prototype flags
const long APPLICATION_KEYCHAIN_ACCESS
#define PREF_CHECKDEFAULTBROWSER
const long APPLICATION_DESKTOP
#define SAFARI_BUNDLE_IDENTIFIER
NS_IMPL_ISUPPORTS3(sbLibraryConstraint, sbILibraryConstraint, nsISerializable, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER3(sbLibraryConstraint
const long APPLICATION_NETWORK