Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsSound.h" |
michael@0 | 8 | #include "nsObjCExceptions.h" |
michael@0 | 9 | #include "nsNetUtil.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsIURL.h" |
michael@0 | 12 | #include "nsString.h" |
michael@0 | 13 | |
michael@0 | 14 | #import <Cocoa/Cocoa.h> |
michael@0 | 15 | |
michael@0 | 16 | NS_IMPL_ISUPPORTS(nsSound, nsISound, nsIStreamLoaderObserver) |
michael@0 | 17 | |
michael@0 | 18 | nsSound::nsSound() |
michael@0 | 19 | { |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | nsSound::~nsSound() |
michael@0 | 23 | { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | NS_IMETHODIMP |
michael@0 | 27 | nsSound::Beep() |
michael@0 | 28 | { |
michael@0 | 29 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 30 | |
michael@0 | 31 | NSBeep(); |
michael@0 | 32 | return NS_OK; |
michael@0 | 33 | |
michael@0 | 34 | NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | NS_IMETHODIMP |
michael@0 | 38 | nsSound::OnStreamComplete(nsIStreamLoader *aLoader, |
michael@0 | 39 | nsISupports *context, |
michael@0 | 40 | nsresult aStatus, |
michael@0 | 41 | uint32_t dataLen, |
michael@0 | 42 | const uint8_t *data) |
michael@0 | 43 | { |
michael@0 | 44 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 45 | |
michael@0 | 46 | NSData *value = [NSData dataWithBytes:data length:dataLen]; |
michael@0 | 47 | |
michael@0 | 48 | NSSound *sound = [[NSSound alloc] initWithData:value]; |
michael@0 | 49 | |
michael@0 | 50 | [sound play]; |
michael@0 | 51 | |
michael@0 | 52 | [sound autorelease]; |
michael@0 | 53 | |
michael@0 | 54 | return NS_OK; |
michael@0 | 55 | |
michael@0 | 56 | NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | NS_IMETHODIMP |
michael@0 | 60 | nsSound::Play(nsIURL *aURL) |
michael@0 | 61 | { |
michael@0 | 62 | nsCOMPtr<nsIURI> uri(do_QueryInterface(aURL)); |
michael@0 | 63 | nsCOMPtr<nsIStreamLoader> loader; |
michael@0 | 64 | return NS_NewStreamLoader(getter_AddRefs(loader), uri, this); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | NS_IMETHODIMP |
michael@0 | 68 | nsSound::Init() |
michael@0 | 69 | { |
michael@0 | 70 | return NS_OK; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | NS_IMETHODIMP |
michael@0 | 74 | nsSound::PlaySystemSound(const nsAString &aSoundAlias) |
michael@0 | 75 | { |
michael@0 | 76 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 77 | |
michael@0 | 78 | if (NS_IsMozAliasSound(aSoundAlias)) { |
michael@0 | 79 | NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead"); |
michael@0 | 80 | // Mac doesn't have system sound settings for each user actions. |
michael@0 | 81 | return NS_OK; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | NSString *name = [NSString stringWithCharacters:reinterpret_cast<const unichar*>(aSoundAlias.BeginReading()) |
michael@0 | 85 | length:aSoundAlias.Length()]; |
michael@0 | 86 | NSSound *sound = [NSSound soundNamed:name]; |
michael@0 | 87 | if (sound) { |
michael@0 | 88 | [sound stop]; |
michael@0 | 89 | [sound play]; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | return NS_OK; |
michael@0 | 93 | |
michael@0 | 94 | NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | NS_IMETHODIMP |
michael@0 | 98 | nsSound::PlayEventSound(uint32_t aEventId) |
michael@0 | 99 | { |
michael@0 | 100 | // Mac doesn't have system sound settings for each user actions. |
michael@0 | 101 | return NS_OK; |
michael@0 | 102 | } |