Bug 152087 - [MediaStream] Expose media capture devices persistent permissions to WebCore
Summary: [MediaStream] Expose media capture devices persistent permissions to WebCore
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Eric Carlson
URL:
Keywords:
Depends on:
Blocks: 152000
  Show dependency treegraph
 
Reported: 2015-12-09 11:41 PST by Eric Carlson
Modified: 2015-12-10 20:08 PST (History)
2 users (show)

See Also:


Attachments
Preliminary patch for the bots. (97.31 KB, patch)
2015-12-09 15:30 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch. (98.21 KB, patch)
2015-12-09 17:04 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Updated patch. (99.40 KB, patch)
2015-12-10 06:37 PST, Eric Carlson
cdumez: review+
cdumez: commit-queue-
Details | Formatted Diff | Diff
Patch for landing. (112.65 KB, patch)
2015-12-10 11:51 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Another updated patch for landing. (112.64 KB, patch)
2015-12-10 13:02 PST, Eric Carlson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Carlson 2015-12-09 11:41:02 PST
Make it possible for WebCore to check to see if persistent permission to access media capture devices has been granted to the page's origin.
Comment 1 Eric Carlson 2015-12-09 15:30:56 PST
Created attachment 267052 [details]
Preliminary patch for the bots.

Patch without useful ChangeLog entries for the bots to mull over.
Comment 2 WebKit Commit Bot 2015-12-09 15:32:08 PST
Attachment 267052 [details] did not pass style-queue:


ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 1 in 44 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Eric Carlson 2015-12-09 17:04:16 PST
Created attachment 267056 [details]
Patch.
Comment 4 Simon Fraser (smfr) 2015-12-09 17:12:49 PST
Comment on attachment 267056 [details]
Patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=267056&action=review

> Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp:86
> +    m_hasUserMediaPermission = access;

Is storing in m_hasUserMediaPermission thread-safe given the callOnMainThread() below?

> Source/WebCore/Modules/mediastream/UserMediaController.h:67
> +inline void UserMediaController::checkUserMediaPermission(Ref<UserMediaPermissionCheck>&& request)

I don't really like this model of a "check" function taking ownership of the UserMediaPermissionCheck passed in.

> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.cpp:43
> +RefPtr<UserMediaPermissionCheck> UserMediaPermissionCheck::create(Document& document, UserMediaPermissionCheckClient& client)

This should return a Ref<>

> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.cpp:81
> +    m_protector = this;

Weird. Why doesn't someone own this explicitly?

> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.h:69
> +    RefPtr<UserMediaPermissionCheck> m_protector;

Odd to have this here.
Comment 5 Eric Carlson 2015-12-09 17:30:17 PST
Comment on attachment 267056 [details]
Patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=267056&action=review

>> Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp:86
>> +    m_hasUserMediaPermission = access;
> 
> Is storing in m_hasUserMediaPermission thread-safe given the callOnMainThread() below?

Yes, this is the callback from the permission checker so it is called exactly once.

>> Source/WebCore/Modules/mediastream/UserMediaController.h:67
>> +inline void UserMediaController::checkUserMediaPermission(Ref<UserMediaPermissionCheck>&& request)
> 
> I don't really like this model of a "check" function taking ownership of the UserMediaPermissionCheck passed in.

The check function doesn't take ownership, it passes it along to the client (the WK1 or WK2 WebUserMediaClient ) which stores it in a map and calls the UI delegate (WK1) or page proxy (WK2).

>> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.cpp:43
>> +RefPtr<UserMediaPermissionCheck> UserMediaPermissionCheck::create(Document& document, UserMediaPermissionCheckClient& client)
> 
> This should return a Ref<>

Oops, will fix.

>> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.cpp:81
>> +    m_protector = this;
> 
> Weird. Why doesn't someone own this explicitly?

Actually, the checker is owned by a MediaDevicesRequest so this isn't necessary. Will remove.
Comment 6 Darin Adler 2015-12-09 19:26:52 PST
Comment on attachment 267056 [details]
Patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=267056&action=review

>>> Source/WebCore/Modules/mediastream/UserMediaController.h:67
>>> +inline void UserMediaController::checkUserMediaPermission(Ref<UserMediaPermissionCheck>&& request)
>> 
>> I don't really like this model of a "check" function taking ownership of the UserMediaPermissionCheck passed in.
> 
> The check function doesn't take ownership, it passes it along to the client (the WK1 or WK2 WebUserMediaClient ) which stores it in a map and calls the UI delegate (WK1) or page proxy (WK2).

So the argument type should just be UserMediaPermissionCheck& instead of Ref&&. Same for requestUserMediaAccess.
Comment 7 Eric Carlson 2015-12-10 06:36:54 PST
(In reply to comment #6)
> Comment on attachment 267056 [details]
> Patch.
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=267056&action=review
> 
> >>> Source/WebCore/Modules/mediastream/UserMediaController.h:67
> >>> +inline void UserMediaController::checkUserMediaPermission(Ref<UserMediaPermissionCheck>&& request)
> >> 
> >> I don't really like this model of a "check" function taking ownership of the UserMediaPermissionCheck passed in.
> > 
> > The check function doesn't take ownership, it passes it along to the client (the WK1 or WK2 WebUserMediaClient ) which stores it in a map and calls the UI delegate (WK1) or page proxy (WK2).
> 
> So the argument type should just be UserMediaPermissionCheck& instead of
> Ref&&. Same for requestUserMediaAccess.

OK, fixed.
Comment 8 Eric Carlson 2015-12-10 06:37:24 PST
Created attachment 267102 [details]
Updated patch.
Comment 9 Chris Dumez 2015-12-10 10:19:59 PST
Comment on attachment 267102 [details]
Updated patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=267102&action=review

r=me with comments.

> Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp:84
> +void MediaDevicesRequest::didCompleteCheck(bool access)

nit: I think we usually name booleans so that they start with something like is/can/should for clarity.

> Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp:91
> +    RefPtr<MediaDevicesRequest> protectedThis(this);

Hmm, this looks unsafe. MediaDevicesRequest is not ThreadSafeRefCounted.

> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.cpp:75
> +    Document* document = downcast<Document>(scriptExecutionContext());

nit: I would prefer:
auto& document = downcast<Document>(*scriptExecutionContext());

> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.h:50
> +class UserMediaPermissionCheck : public ContextDestructionObserver, public RefCounted<UserMediaPermissionCheck> {

Could be final ?

> Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.h:41
> +    static PassRefPtr<UserMediaPermissionCheckProxy> create(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID)

We don't use PassRefPtr anymore. This should return a Ref<>

> Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:63
> +PassRefPtr<UserMediaPermissionCheckProxy> UserMediaPermissionRequestManagerProxy::createUserMediaPermissionCheck(uint64_t userMediaID)

Should return a Ref<>.

> Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:65
> +    RefPtr<UserMediaPermissionCheckProxy> request = UserMediaPermissionCheckProxy::create(*this, userMediaID);

Ref<>

> Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:66
> +    m_pendingDeviceRequests.add(userMediaID, request.get());

request.ptr()

> Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.h:40
> +    PassRefPtr<UserMediaPermissionCheckProxy> createUserMediaPermissionCheck(uint64_t userMediaID);

Ref<>

> Source/WebKit2/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:90
> +void UserMediaPermissionRequestManager::startUserMediaPermissionCheck(WebCore::UserMediaPermissionCheck& request)

You don't need the WebCore::

> Source/WebKit2/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:92
> +    Document* document = downcast<Document>(request.scriptExecutionContext());

auto*

> Source/WebKit/mac/WebCoreSupport/WebUserMediaClient.mm:84
> +    DEPRECATED_DEFINE_STATIC_LOCAL(UserMediaCheckMap, requests, ());

static NeverDestroyed<> ?

> Source/WebKit/mac/WebCoreSupport/WebUserMediaClient.mm:119
> +void WebUserMediaClient::requestUserMediaAccess(UserMediaRequest& prpRequest)

We should get rid of the prp prefix

> Source/WebKit/mac/WebCoreSupport/WebUserMediaClient.mm:123
> +    UserMediaRequest* request = &prpRequest;

We don't really need this local variable anymore I believe.

> Source/WebKit/mac/WebCoreSupport/WebUserMediaClient.mm:153
> +void WebUserMediaClient::checkUserMediaPermission(UserMediaPermissionCheck& prpRequest)

We should drop the prp prefix

> Source/WebKit/mac/WebCoreSupport/WebUserMediaClient.mm:157
> +    UserMediaPermissionCheck* request = &prpRequest;

Not needed?

> Tools/WebKitTestRunner/TestController.h:289
> +    typedef Vector<std::pair<WKRetainPtr<WKSecurityOriginRef>, WKRetainPtr<WKUserMediaPermissionRequestRef>>> PermissionRequestMap;

Calling this "Map" is a tad confusing. Maybe List or Vector?
Comment 10 Chris Dumez 2015-12-10 10:22:12 PST
Comment on attachment 267102 [details]
Updated patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=267102&action=review

> Source/WebCore/Modules/mediastream/UserMediaPermissionCheck.h:34
> +#include <wtf/PassRefPtr.h>

Useless include.

> Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.h:31
> +#include <wtf/PassRefPtr.h>

Useless include.
Comment 11 Eric Carlson 2015-12-10 11:51:01 PST
Created attachment 267116 [details]
Patch for landing.
Comment 12 WebKit Commit Bot 2015-12-10 11:52:08 PST
Attachment 267116 [details] did not pass style-queue:


ERROR: Source/WebCore/ChangeLog:25:  Need whitespace between colon and description  [changelog/filechangedescriptionwhitespace] [5]
Total errors found: 1 in 45 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Eric Carlson 2015-12-10 13:02:08 PST
Created attachment 267121 [details]
Another updated patch for landing.
Comment 14 Eric Carlson 2015-12-10 20:08:04 PST
Committed r193944: https://trac.webkit.org/r193944