Bug 1608587 [wpt PR 21137] - Update wpt metadata, a=testonly
[gecko.git] / widget / nsSoundProxy.cpp
blobbbd1234f19556cdc5229de9a5132e1421fb14c10
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/dom/ContentChild.h"
6 #include "mozilla/ipc/URIUtils.h"
7 #include "nsIURL.h"
8 #include "nsIURI.h"
9 #include "nsSoundProxy.h"
11 using namespace mozilla;
12 using namespace mozilla::dom;
14 NS_IMPL_ISUPPORTS(nsSoundProxy, nsISound)
16 NS_IMETHODIMP
17 nsSoundProxy::Play(nsIURL* aURL) {
18 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
20 nsCOMPtr<nsIURI> soundURI(aURL);
21 // Only allow playing a chrome:// URL from the content process.
22 if (!soundURI || !soundURI->SchemeIs("chrome")) {
23 return NS_ERROR_FAILURE;
26 mozilla::ipc::URIParams soundParams;
27 mozilla::ipc::SerializeURI(soundURI, soundParams);
28 ContentChild::GetSingleton()->SendPlaySound(soundParams);
29 return NS_OK;
32 NS_IMETHODIMP
33 nsSoundProxy::Beep() {
34 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
36 ContentChild::GetSingleton()->SendBeep();
37 return NS_OK;
40 NS_IMETHODIMP
41 nsSoundProxy::Init() {
42 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
43 MOZ_DIAGNOSTIC_ASSERT(false, "Only called by XUL in the parent process.");
44 return NS_ERROR_NOT_IMPLEMENTED;
47 NS_IMETHODIMP
48 nsSoundProxy::PlayEventSound(uint32_t aEventId) {
49 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
51 ContentChild::GetSingleton()->SendPlayEventSound(aEventId);
52 return NS_OK;