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,
35 nsresult aStatus, uint32_t dataLen,
36 const uint8_t* data) {
37 NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
39 NSData* value = [NSData dataWithBytes:data length:dataLen];
41 NSSound* sound = [[NSSound alloc] initWithData:value];
49 NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
53 nsSound::Play(nsIURL* aURL) {
54 nsCOMPtr<nsIURI> uri(aURL);
55 nsCOMPtr<nsIStreamLoader> loader;
56 return NS_NewStreamLoader(
57 getter_AddRefs(loader), uri,
59 nsContentUtils::GetSystemPrincipal(),
60 nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
61 nsIContentPolicy::TYPE_OTHER);
65 nsSound::Init() { return NS_OK; }
68 nsSound::PlayEventSound(uint32_t aEventId) {
69 // Mac doesn't have system sound settings for each user actions.