[MediaStream][Mac] Revoke sandbox extensions when capture ends
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Dec 2016 02:25:57 +0000 (02:25 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Dec 2016 02:25:57 +0000 (02:25 +0000)
commit6fbc6a8f90b76b89886bd14c87d7397d51b281c3
tree2931a2abb0eb12d5d88508a336fdf3157fc5a79f
parent813c1e62a835e44a20b357c02a4f41595a974fa9
[MediaStream][Mac] Revoke sandbox extensions when capture ends
https://bugs.webkit.org/show_bug.cgi?id=165476

Reviewed by Brady Eidson.
Source/WebKit2:

Track media capture by process so it is possible to revoke the sandbox extensions issued to
a web process when capture stops. Allocate WK2 user media permission manager lazily rather
than every time a page is created as most pages won't need one.

* CMakeLists.txt: Add new files.

* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::UserMediaPermissionRequestManagerProxy::UserMediaPermissionRequestManagerProxy): Register
  with process manager.
(WebKit::UserMediaPermissionRequestManagerProxy::~UserMediaPermissionRequestManagerProxy):
(WebKit::UserMediaPermissionRequestManagerProxy::userMediaAccessWasGranted): Move sandbox
  extension code to the process manager.
(WebKit::UserMediaPermissionRequestManagerProxy::stopCapture): New.
(WebKit::UserMediaPermissionRequestManagerProxy::startedCaptureSession): New, report state
  change to the process manager.
(WebKit::UserMediaPermissionRequestManagerProxy::endedCaptureSession): Ditto.
* UIProcess/UserMediaPermissionRequestManagerProxy.h:

* UIProcess/UserMediaProcessManager.cpp: Added.
(WebKit::ProcessState::ProcessState):
(WebKit::ProcessState::managers):
(WebKit::ProcessState::sandboxExtensionsGranted):
(WebKit::ProcessState::setSandboxExtensionsGranted):
(WebKit::stateMap):
(WebKit::processState):
(WebKit::ProcessState::addRequestManager):
(WebKit::ProcessState::removeRequestManager):
(WebKit::UserMediaProcessManager::singleton):
(WebKit::UserMediaProcessManager::addUserMediaPermissionRequestManagerProxy):
(WebKit::UserMediaProcessManager::removeUserMediaPermissionRequestManagerProxy):
(WebKit::UserMediaProcessManager::willCreateMediaStream):
(WebKit::UserMediaProcessManager::startedCaptureSession):
(WebKit::UserMediaProcessManager::endedCaptureSession):
* UIProcess/UserMediaProcessManager.h: Added.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy): Don't allocate m_userMediaPermissionRequestManager.
(WebKit::WebPageProxy::resetState): Set m_userMediaPermissionRequestManager to null.
(WebKit::WebPageProxy::userMediaPermissionRequestManager): Allocate m_userMediaPermissionRequestManager
  lazily as most pages don't need it.
(WebKit::WebPageProxy::requestUserMediaPermissionForFrame): Call userMediaPermissionRequestManager().
(WebKit::WebPageProxy::enumerateMediaDevicesForFrame): Ditto.
(WebKit::WebPageProxy::clearUserMediaState): Ditto.
(WebKit::WebPageProxy::isPlayingMediaDidChange): Report capture state changes to the request
  manager proxy.
* UIProcess/WebPageProxy.h:

* WebKit2.xcodeproj/project.pbxproj: Add new files.

* WebProcess/MediaStream/MediaDeviceSandboxExtensions.cpp: Added.
(WebKit::MediaDeviceSandboxExtensions::MediaDeviceSandboxExtensions):
(WebKit::MediaDeviceSandboxExtensions::encode):
(WebKit::MediaDeviceSandboxExtensions::decode):
(WebKit::MediaDeviceSandboxExtensions::operator[]):
(WebKit::MediaDeviceSandboxExtensions::size):
* WebProcess/MediaStream/MediaDeviceSandboxExtensions.h: Added.

* WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:
(WebKit::UserMediaPermissionRequestManager::~UserMediaPermissionRequestManager): Sandbox extension
  is now in a HashMap, not a Vector.
(WebKit::UserMediaPermissionRequestManager::grantUserMediaDeviceSandboxExtensions): Record
  IDs with extensions so they can be revoked later.
(WebKit::UserMediaPermissionRequestManager::revokeUserMediaDeviceSandboxExtensions): New.
(WebKit::UserMediaPermissionRequestManager::grantUserMediaDevicesSandboxExtension): Deleted.
* WebProcess/MediaStream/UserMediaPermissionRequestManager.h:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::grantUserMediaDeviceSandboxExtensions):
(WebKit::WebPage::revokeUserMediaDeviceSandboxExtensions):
(WebKit::WebPage::grantUserMediaDevicesSandboxExtension): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

Add a test which loads a page that calls navigator.mediaDevices.enumerateDevices, kills the
page, and loads the same page again to ensure that the WK2 UserMediaPermissionRequestManagerProxy
is reset and recreated when a web page exits and is reloaded.

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/EnumerateMediaDevices.cpp: Added.
(TestWebKitAPI::checkUserMediaPermissionCallback):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2/enumerateMediaDevices.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209512 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.h
Source/WebKit2/UIProcess/UserMediaProcessManager.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/UserMediaProcessManager.h [new file with mode: 0644]
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/MediaStream/MediaDeviceSandboxExtensions.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/MediaStream/MediaDeviceSandboxExtensions.h [new file with mode: 0644]
Source/WebKit2/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp
Source/WebKit2/WebProcess/MediaStream/UserMediaPermissionRequestManager.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/EnumerateMediaDevices.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/enumerateMediaDevices.html [new file with mode: 0644]