Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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 "nsObjCExceptions.h"
9 #include "nsNetUtil.h"
10 #include "nsCOMPtr.h"
11 #include "nsIURL.h"
12 #include "nsString.h"
14 #import <Cocoa/Cocoa.h>
16 NS_IMPL_ISUPPORTS(nsSound, nsISound, nsIStreamLoaderObserver)
18 nsSound::nsSound()
19 {
20 }
22 nsSound::~nsSound()
23 {
24 }
26 NS_IMETHODIMP
27 nsSound::Beep()
28 {
29 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
31 NSBeep();
32 return NS_OK;
34 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
35 }
37 NS_IMETHODIMP
38 nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
39 nsISupports *context,
40 nsresult aStatus,
41 uint32_t dataLen,
42 const uint8_t *data)
43 {
44 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
46 NSData *value = [NSData dataWithBytes:data length:dataLen];
48 NSSound *sound = [[NSSound alloc] initWithData:value];
50 [sound play];
52 [sound autorelease];
54 return NS_OK;
56 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
57 }
59 NS_IMETHODIMP
60 nsSound::Play(nsIURL *aURL)
61 {
62 nsCOMPtr<nsIURI> uri(do_QueryInterface(aURL));
63 nsCOMPtr<nsIStreamLoader> loader;
64 return NS_NewStreamLoader(getter_AddRefs(loader), uri, this);
65 }
67 NS_IMETHODIMP
68 nsSound::Init()
69 {
70 return NS_OK;
71 }
73 NS_IMETHODIMP
74 nsSound::PlaySystemSound(const nsAString &aSoundAlias)
75 {
76 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
78 if (NS_IsMozAliasSound(aSoundAlias)) {
79 NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
80 // Mac doesn't have system sound settings for each user actions.
81 return NS_OK;
82 }
84 NSString *name = [NSString stringWithCharacters:reinterpret_cast<const unichar*>(aSoundAlias.BeginReading())
85 length:aSoundAlias.Length()];
86 NSSound *sound = [NSSound soundNamed:name];
87 if (sound) {
88 [sound stop];
89 [sound play];
90 }
92 return NS_OK;
94 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
95 }
97 NS_IMETHODIMP
98 nsSound::PlayEventSound(uint32_t aEventId)
99 {
100 // Mac doesn't have system sound settings for each user actions.
101 return NS_OK;
102 }