1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsContentUtils.h"
9 #include "nsObjCExceptions.h"
10 #include "nsNetUtil.h"
15 #import <Cocoa/Cocoa.h>
17 NS_IMPL_ISUPPORTS(nsSound, nsISound, nsIStreamLoaderObserver)
21 nsSound::~nsSound() {}
25 NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
30 NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
34 nsSound::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* context, nsresult aStatus,
35 uint32_t dataLen, const uint8_t* data) {
36 NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
38 NSData* value = [NSData dataWithBytes:data length:dataLen];
40 NSSound* sound = [[NSSound alloc] initWithData:value];
48 NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
52 nsSound::Play(nsIURL* aURL) {
53 nsCOMPtr<nsIURI> uri(aURL);
54 nsCOMPtr<nsIStreamLoader> loader;
55 return NS_NewStreamLoader(getter_AddRefs(loader), uri,
57 nsContentUtils::GetSystemPrincipal(),
58 nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
59 nsIContentPolicy::TYPE_OTHER);
63 nsSound::Init() { return NS_OK; }
66 nsSound::PlayEventSound(uint32_t aEventId) {
67 // Mac doesn't have system sound settings for each user actions.