Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / widget / cocoa / nsSound.mm
blobcbaad44be7a35471b7b36dfa54aefc1e802f498a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
7 #include "nsSound.h"
8 #include "nsContentUtils.h"
9 #include "nsObjCExceptions.h"
10 #include "nsNetUtil.h"
11 #include "nsCOMPtr.h"
12 #include "nsIURL.h"
13 #include "nsString.h"
15 #import <Cocoa/Cocoa.h>
17 NS_IMPL_ISUPPORTS(nsSound, nsISound, nsIStreamLoaderObserver)
19 nsSound::nsSound() {}
21 nsSound::~nsSound() {}
23 NS_IMETHODIMP
24 nsSound::Beep() {
25   NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
27   NSBeep();
28   return NS_OK;
30   NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
33 NS_IMETHODIMP
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];
43   [sound play];
45   [sound autorelease];
47   return NS_OK;
49   NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
52 NS_IMETHODIMP
53 nsSound::Play(nsIURL* aURL) {
54   nsCOMPtr<nsIURI> uri(aURL);
55   nsCOMPtr<nsIStreamLoader> loader;
56   return NS_NewStreamLoader(
57       getter_AddRefs(loader), uri,
58       this,  // aObserver
59       nsContentUtils::GetSystemPrincipal(),
60       nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
61       nsIContentPolicy::TYPE_OTHER);
64 NS_IMETHODIMP
65 nsSound::Init() { return NS_OK; }
67 NS_IMETHODIMP
68 nsSound::PlayEventSound(uint32_t aEventId) {
69   // Mac doesn't have system sound settings for each user actions.
70   return NS_OK;