Bug 1550214 [wpt PR 16194] - Portals: Expose portalHost in predecessor, a=testonly
[gecko.git] / widget / nsSoundProxy.cpp
blob241958dac29500a6517df122684c08207453bec4
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 bool isChrome = false;
22 // Only allow playing a chrome:// URL from the content process.
23 if (!soundURI || NS_FAILED(soundURI->SchemeIs("chrome", &isChrome)) ||
24 !isChrome) {
25 return NS_ERROR_FAILURE;
28 mozilla::ipc::URIParams soundParams;
29 mozilla::ipc::SerializeURI(soundURI, soundParams);
30 ContentChild::GetSingleton()->SendPlaySound(soundParams);
31 return NS_OK;
34 NS_IMETHODIMP
35 nsSoundProxy::Beep() {
36 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
38 ContentChild::GetSingleton()->SendBeep();
39 return NS_OK;
42 NS_IMETHODIMP
43 nsSoundProxy::Init() {
44 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
45 MOZ_DIAGNOSTIC_ASSERT(false, "Only called by XUL in the parent process.");
46 return NS_ERROR_NOT_IMPLEMENTED;
49 NS_IMETHODIMP
50 nsSoundProxy::PlayEventSound(uint32_t aEventId) {
51 MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
53 ContentChild::GetSingleton()->SendPlayEventSound(aEventId);
54 return NS_OK;