Skip to content
Permalink
Browse files
[macOS] System sounds should be played in the UI process
https://bugs.webkit.org/show_bug.cgi?id=218405
Source/WebCore:

<rdar://problem/70898846>

Reviewed by Darin Adler.

In preparation of blocking the system sound server in the WebContent process, system sounds should be played in the UI process.
This patch creates a system sound manager, which delegates the sound request if a delegate is present, otherwise the function
PAL::systemBeep will be called.

API test: WebKit.SystemBeep

* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/Editor.cpp:
(WebCore::Editor::cut):
(WebCore::Editor::copy):
(WebCore::Editor::performDelete):
* editing/EditorCommand.cpp:
(WebCore::executeSelectToMark):
(WebCore::executeSwapWithMark):
* editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::takeFindStringFromSelection):
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::beep):
* platform/SystemSoundDelegate.h: Added.
(WebCore::SystemSoundDelegate::~SystemSoundDelegate):
(WebCore::SystemSoundDelegate::systemBeep):
* platform/SystemSoundManager.cpp: Added.
(WebCore::SystemSoundManager::singleton):
(WebCore::SystemSoundManager::setSystemSoundDelegate):
(WebCore::SystemSoundManager::systemBeep):
* platform/SystemSoundManager.h: Added.
* platform/audio/StereoPanner.cpp:
* testing/Internals.cpp:
(WebCore::Internals::systemBeep):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

<rdar://problem/70898846>

Reviewed by Darin Adler.

Subclass SystemSoundDelegate, which will forward system sound requests to the UI process.

* Sources.txt:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::systemBeep):
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebSystemSoundDelegate.cpp: Added.
(WebKit::WebSystemSoundDelegate::systemBeep):
* WebProcess/WebSystemSoundDelegate.h: Added.
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Tools:

Reviewed by Darin Adler.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/SystemBeep.mm: Added.
(TEST):


Canonical link: https://commits.webkit.org/231384@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269593 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pvollan committed Nov 9, 2020
1 parent 305a5d8 commit 2835a7911e024e94db68bfa235dbb89bb2e7b422
Showing 27 changed files with 395 additions and 10 deletions.
@@ -1,3 +1,45 @@
2020-11-09 Per Arne Vollan <pvollan@apple.com>

[macOS] System sounds should be played in the UI process
https://bugs.webkit.org/show_bug.cgi?id=218405
<rdar://problem/70898846>

Reviewed by Darin Adler.

In preparation of blocking the system sound server in the WebContent process, system sounds should be played in the UI process.
This patch creates a system sound manager, which delegates the sound request if a delegate is present, otherwise the function
PAL::systemBeep will be called.

API test: WebKit.SystemBeep

* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/Editor.cpp:
(WebCore::Editor::cut):
(WebCore::Editor::copy):
(WebCore::Editor::performDelete):
* editing/EditorCommand.cpp:
(WebCore::executeSelectToMark):
(WebCore::executeSwapWithMark):
* editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::takeFindStringFromSelection):
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::beep):
* platform/SystemSoundDelegate.h: Added.
(WebCore::SystemSoundDelegate::~SystemSoundDelegate):
(WebCore::SystemSoundDelegate::systemBeep):
* platform/SystemSoundManager.cpp: Added.
(WebCore::SystemSoundManager::singleton):
(WebCore::SystemSoundManager::setSystemSoundDelegate):
(WebCore::SystemSoundManager::systemBeep):
* platform/SystemSoundManager.h: Added.
* platform/audio/StereoPanner.cpp:
* testing/Internals.cpp:
(WebCore::Internals::systemBeep):
* testing/Internals.h:
* testing/Internals.idl:

2020-11-09 Wenson Hsieh <wenson_hsieh@apple.com>

Clean up some code after inline display list refactoring
@@ -1057,6 +1057,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/SleepDisablerIdentifier.h
platform/SuddenTermination.h
platform/Supplementable.h
platform/SystemSoundDelegate.h
platform/ThemeTypes.h
platform/ThreadCheck.h
platform/ThreadGlobalData.h
@@ -1820,6 +1820,7 @@ platform/SharedBufferChunkReader.cpp
platform/SharedStringHash.cpp
platform/SleepDisabler.cpp
platform/SleepDisablerClient.cpp
platform/SystemSoundManager.cpp
platform/StaticPasteboard.cpp
platform/Theme.cpp
platform/ThemeTypes.cpp
@@ -5005,6 +5005,8 @@
E3B2F0EE1D7F4CA900B0C9D1 /* LoadableScriptClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E3B2F0E81D7F35EC00B0C9D1 /* LoadableScriptClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
E3B2F0F01D7F4CB500B0C9D1 /* LoadableClassicScript.h in Headers */ = {isa = PBXBuildFile; fileRef = E3B2F0E41D7F35EC00B0C9D1 /* LoadableClassicScript.h */; settings = {ATTRIBUTES = (Private, ); }; };
E3BBC24723835526006EC39F /* CSSValueKey.h in Headers */ = {isa = PBXBuildFile; fileRef = E3BBC2452383551A006EC39F /* CSSValueKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
E3C0412F254CA29B0021D0E6 /* SystemSoundManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C0412D254CA29B0021D0E6 /* SystemSoundManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
E3C04138254CB30D0021D0E6 /* SystemSoundDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C04131254CA6660021D0E6 /* SystemSoundDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
E3C99A091DC3D41C00794AD3 /* DOMJITCheckDOM.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C99A081DC3D41700794AD3 /* DOMJITCheckDOM.h */; };
E3C9AECB2113149900419B92 /* JSMicrotaskCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C9AEC92113147400419B92 /* JSMicrotaskCallback.h */; };
E3E4E2A81E3B17100023BB8A /* ScriptElementCachedScriptFetcher.h in Headers */ = {isa = PBXBuildFile; fileRef = E3E4E2A61E3B16FC0023BB8A /* ScriptElementCachedScriptFetcher.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -16017,6 +16019,9 @@
E3BF19E522AF2FF4009C9926 /* BeforeLoadEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BeforeLoadEvent.cpp; sourceTree = "<group>"; };
E3BF19E622AF302A009C9926 /* HashChangeEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HashChangeEvent.cpp; sourceTree = "<group>"; };
E3BF19E722AF309F009C9926 /* SecurityPolicyViolationEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityPolicyViolationEvent.cpp; sourceTree = "<group>"; };
E3C0412D254CA29B0021D0E6 /* SystemSoundManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemSoundManager.h; sourceTree = "<group>"; };
E3C04131254CA6660021D0E6 /* SystemSoundDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemSoundDelegate.h; sourceTree = "<group>"; };
E3C04132254CA7110021D0E6 /* SystemSoundManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SystemSoundManager.cpp; sourceTree = "<group>"; };
E3C99A081DC3D41700794AD3 /* DOMJITCheckDOM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITCheckDOM.h; sourceTree = "<group>"; };
E3C9AEC92113147400419B92 /* JSMicrotaskCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMicrotaskCallback.h; sourceTree = "<group>"; };
E3D049931DADC04500718F3C /* NodeConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeConstants.h; sourceTree = "<group>"; };
@@ -27367,6 +27372,9 @@
F433E9021DBBDBA200EF0D14 /* StaticPasteboard.h */,
93B2D8150F9920D2006AE6B2 /* SuddenTermination.h */,
97627B9714FB5424002CDCA1 /* Supplementable.h */,
E3C04131254CA6660021D0E6 /* SystemSoundDelegate.h */,
E3C04132254CA7110021D0E6 /* SystemSoundManager.cpp */,
E3C0412D254CA29B0021D0E6 /* SystemSoundManager.h */,
7CC564B618BABEA6001B9652 /* TelephoneNumberDetector.h */,
BCE65D310EAD1211007E4533 /* Theme.cpp */,
BCE658FE0EA9248A007E4533 /* Theme.h */,
@@ -34604,6 +34612,8 @@
C1692DD523D23E08006E88F7 /* SystemBattery.h in Headers */,
E4E8B4EC216B79E500B8834D /* SystemFontDatabaseCoreText.h in Headers */,
0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */,
E3C04138254CB30D0021D0E6 /* SystemSoundDelegate.h in Headers */,
E3C0412F254CA29B0021D0E6 /* SystemSoundManager.h in Headers */,
5D5975B319635F1100D00878 /* SystemVersion.h in Headers */,
A8CFF0510A154F09000A4234 /* TableLayout.h in Headers */,
6F17264F2470C60B00518C96 /* TableWrapperBlockFormattingContext.h in Headers */,
@@ -103,6 +103,7 @@
#include "SpellingCorrectionCommand.h"
#include "StaticPasteboard.h"
#include "StyleProperties.h"
#include "SystemSoundManager.h"
#include "TelephoneNumberDetector.h"
#include "Text.h"
#include "TextCheckerClient.h"
@@ -115,7 +116,6 @@
#include "VisibleUnits.h"
#include "markup.h"
#include <pal/FileSizeFormatter.h>
#include <pal/system/Sound.h>
#include <pal/text/KillRing.h>
#include <wtf/SetForScope.h>
#include <wtf/unicode/CharacterNames.h>
@@ -1366,7 +1366,7 @@ void Editor::cut(FromMenuOrKeyBinding fromMenuOrKeyBinding)
if (tryDHTMLCut())
return; // DHTML did the whole operation
if (!canCut()) {
PAL::systemBeep();
SystemSoundManager::singleton().systemBeep();
return;
}

@@ -1379,7 +1379,7 @@ void Editor::copy(FromMenuOrKeyBinding fromMenuOrKeyBinding)
if (tryDHTMLCopy())
return; // DHTML did the whole operation
if (!canCopy()) {
PAL::systemBeep();
SystemSoundManager::singleton().systemBeep();
return;
}

@@ -1516,7 +1516,7 @@ void Editor::quoteFragmentForPasting(DocumentFragment& fragment)
void Editor::performDelete()
{
if (!canDelete()) {
PAL::systemBeep();
SystemSoundManager::singleton().systemBeep();
return;
}

@@ -56,12 +56,12 @@
#include "Scrollbar.h"
#include "Settings.h"
#include "StyleProperties.h"
#include "SystemSoundManager.h"
#include "TypingCommand.h"
#include "UnlinkCommand.h"
#include "UserGestureIndicator.h"
#include "UserTypingGestureIndicator.h"
#include "markup.h"
#include <pal/system/Sound.h>
#include <pal/text/KillRing.h>
#include <wtf/text/AtomString.h>

@@ -1043,7 +1043,7 @@ static bool executeSelectToMark(Frame& frame, Event*, EditorCommandSource, const
auto markRange = editor.mark().toNormalizedRange();
auto selectionRange = selection.selection().toNormalizedRange();
if (!markRange || !selectionRange) {
PAL::systemBeep();
SystemSoundManager::singleton().systemBeep();
return false;
}
selection.setSelectedRange(unionRange(*markRange, *selectionRange), Affinity::Downstream, FrameSelection::ShouldCloseTyping::Yes);
@@ -1103,7 +1103,7 @@ static bool executeSwapWithMark(Frame& frame, Event*, EditorCommandSource, const
const VisibleSelection& mark = frame.editor().mark();
const VisibleSelection& selection = frame.selection().selection();
if (mark.isNone() || selection.isNone()) {
PAL::systemBeep();
SystemSoundManager::singleton().systemBeep();
return false;
}
frame.selection().setSelection(mark);
@@ -53,12 +53,12 @@
#import "RenderElement.h"
#import "RenderStyle.h"
#import "Settings.h"
#import "SystemSoundManager.h"
#import "Text.h"
#import "UTIUtilities.h"
#import "WebContentReader.h"
#import "markup.h"
#import <pal/spi/cocoa/NSAttributedStringSPI.h>
#import <pal/system/Sound.h>
#import <wtf/BlockObjCExceptions.h>
#import <wtf/cocoa/NSURLExtras.h>

@@ -239,7 +239,7 @@
void Editor::takeFindStringFromSelection()
{
if (!canCopyExcludingStandaloneImages()) {
PAL::systemBeep();
SystemSoundManager::singleton().systemBeep();
return;
}

@@ -56,6 +56,7 @@
#include "Pasteboard.h"
#include "ScriptState.h"
#include "Settings.h"
#include "SystemSoundManager.h"
#include "UserGestureIndicator.h"
#include <JavaScriptCore/ScriptFunctionCall.h>
#include <pal/system/Sound.h>
@@ -555,7 +556,7 @@ void InspectorFrontendHost::unbufferedLog(const String& message)

void InspectorFrontendHost::beep()
{
PAL::systemBeep();
SystemSoundManager::singleton().systemBeep();
}

void InspectorFrontendHost::inspectInspector()
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

namespace WebCore {

class SystemSoundDelegate {
public:
virtual ~SystemSoundDelegate() { }

virtual void systemBeep() { }
};

} // namespace WebCore
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "SystemSoundManager.h"

#include "SystemSoundDelegate.h"

#include <pal/system/Sound.h>

namespace WebCore {

SystemSoundManager& SystemSoundManager::singleton()
{
static NeverDestroyed<SystemSoundManager> systemSoundManager;
return systemSoundManager;
}

void SystemSoundManager::setSystemSoundDelegate(std::unique_ptr<SystemSoundDelegate>&& delegate)
{
m_delegate = WTFMove(delegate);
}

void SystemSoundManager::systemBeep()
{
if (m_delegate) {
m_delegate->systemBeep();
return;
}
PAL::systemBeep();
}

} // namespace WebCore
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include <wtf/NeverDestroyed.h>

namespace WebCore {

class SystemSoundDelegate;

class SystemSoundManager {
friend NeverDestroyed<SystemSoundManager>;
public:
WEBCORE_EXPORT static SystemSoundManager& singleton();

WEBCORE_EXPORT void setSystemSoundDelegate(std::unique_ptr<SystemSoundDelegate>&&);

WEBCORE_EXPORT void systemBeep();

private:
SystemSoundManager() = default;

std::unique_ptr<SystemSoundDelegate> m_delegate;
};

} // namespace WebCore
@@ -29,6 +29,7 @@

#if ENABLE(WEB_AUDIO)

#include "SharedBuffer.h"
#include "VectorMath.h"
#include <wtf/MathExtras.h>

@@ -192,6 +192,7 @@
#include "StyleRule.h"
#include "StyleScope.h"
#include "StyleSheetContents.h"
#include "SystemSoundManager.h"
#include "TextIterator.h"
#include "TextPlaceholderElement.h"
#include "TreeScope.h"
@@ -4729,6 +4730,10 @@ ExceptionOr<String> Internals::pathStringWithShrinkWrappedRects(const Vector<dou
return builder.result();
}

void Internals::systemBeep()
{
SystemSoundManager::singleton().systemBeep();
}

String Internals::getCurrentMediaControlsStatusForElement(HTMLMediaElement& mediaElement)
{
@@ -1070,6 +1070,8 @@ class Internals final : public RefCounted<Internals>, private ContextDestruction
bool rangeContainsNode(const AbstractRange&, Node&, TreeType);
bool rangeContainsRange(const AbstractRange&, const AbstractRange&, TreeType);

void systemBeep();

private:
explicit Internals(Document&);
Document* contextDocument() const;

0 comments on commit 2835a79

Please sign in to comment.