forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
media: Add MediaPermission interface and MediaPermissionDispatcher.
MediaPermission is the interface for media code to check/request media related permissions. MediaPermissionDispatcher is a MediaPermission implementation in content/. Plan of follow-up CL: - Use MediaPermission in ProxyDecryptor and remove current protected media identifier info bar code in the browser process (on Android and ChromeOS). BUG=446263 TEST=Tested on Android with encrypted-media-requestmediakeysystemaccess.html layout test by calling MediaPermission methods manually in webencryptedmediaclient_impl.cc. Review URL: https://codereview.chromium.org/871663003 Cr-Commit-Position: refs/heads/master@{#313303}
- Loading branch information
1 parent
8bd6f98
commit 36b1f3b
Showing
16 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "content/renderer/media/media_permission_dispatcher.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/logging.h" | ||
#include "content/public/common/service_registry.h" | ||
#include "content/public/renderer/render_frame.h" | ||
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | ||
#include "url/gurl.h" | ||
|
||
namespace content { | ||
|
||
MediaPermissionDispatcher::MediaPermissionDispatcher(RenderFrame* render_frame) | ||
: RenderFrameObserver(render_frame), next_request_id_(0) { | ||
} | ||
|
||
MediaPermissionDispatcher::~MediaPermissionDispatcher() { | ||
DCHECK(thread_checker_.CalledOnValidThread()); | ||
|
||
// Fire all pending callbacks with |false|. | ||
for (auto& request : requests_) | ||
request.second.Run(false); | ||
|
||
requests_.clear(); | ||
} | ||
|
||
void MediaPermissionDispatcher::HasPermission( | ||
Type type, | ||
const GURL& security_origin, | ||
const PermissionStatusCB& permission_status_cb) { | ||
DCHECK(thread_checker_.CalledOnValidThread()); | ||
CHECK_EQ(PROTECTED_MEDIA_IDENTIFIER, type); | ||
|
||
if (!permission_service_.get()) { | ||
render_frame()->GetServiceRegistry()->ConnectToRemoteService( | ||
&permission_service_); | ||
} | ||
|
||
uint32_t request_id = next_request_id_++; | ||
DCHECK(!requests_.count(request_id)); | ||
requests_[request_id] = permission_status_cb; | ||
|
||
DVLOG(2) << __FUNCTION__ << ": request ID " << request_id; | ||
|
||
permission_service_->HasPermission( | ||
PERMISSION_NAME_PROTECTED_MEDIA_IDENTIFIER, security_origin.spec(), | ||
base::Bind(&MediaPermissionDispatcher::OnPermissionStatus, | ||
base::Unretained(this), request_id)); | ||
} | ||
|
||
void MediaPermissionDispatcher::RequestPermission( | ||
Type type, | ||
const GURL& security_origin, | ||
const PermissionStatusCB& permission_status_cb) { | ||
DCHECK(thread_checker_.CalledOnValidThread()); | ||
CHECK_EQ(PROTECTED_MEDIA_IDENTIFIER, type); | ||
|
||
if (!permission_service_.get()) { | ||
render_frame()->GetServiceRegistry()->ConnectToRemoteService( | ||
&permission_service_); | ||
} | ||
|
||
uint32_t request_id = next_request_id_++; | ||
DCHECK(!requests_.count(request_id)); | ||
requests_[request_id] = permission_status_cb; | ||
|
||
DVLOG(2) << __FUNCTION__ << ": request ID " << request_id; | ||
|
||
permission_service_->RequestPermission( | ||
PERMISSION_NAME_PROTECTED_MEDIA_IDENTIFIER, security_origin.spec(), | ||
blink::WebUserGestureIndicator::isProcessingUserGesture(), | ||
base::Bind(&MediaPermissionDispatcher::OnPermissionStatus, | ||
base::Unretained(this), request_id)); | ||
} | ||
|
||
void MediaPermissionDispatcher::OnPermissionStatus(uint32_t request_id, | ||
PermissionStatus status) { | ||
DVLOG(2) << __FUNCTION__ << ": (" << request_id << ", " << status << ")"; | ||
DCHECK(thread_checker_.CalledOnValidThread()); | ||
|
||
RequestMap::iterator iter = requests_.find(request_id); | ||
if (iter == requests_.end()) { | ||
DVLOG(2) << "Request not found."; | ||
return; | ||
} | ||
|
||
PermissionStatusCB permission_status_cb = iter->second; | ||
requests_.erase(iter); | ||
|
||
permission_status_cb.Run(status == PERMISSION_STATUS_GRANTED); | ||
} | ||
|
||
} // namespace content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | ||
#define CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | ||
|
||
#include <map> | ||
|
||
#include "base/threading/thread_checker.h" | ||
#include "content/common/content_export.h" | ||
#include "content/common/permission_service.mojom.h" | ||
#include "content/public/renderer/render_frame_observer.h" | ||
#include "media/base/media_permission.h" | ||
|
||
namespace content { | ||
|
||
// MediaPermission implementation in content. This class is not thread safe | ||
// and should only be used on one thread. | ||
class CONTENT_EXPORT MediaPermissionDispatcher : public media::MediaPermission, | ||
public RenderFrameObserver { | ||
public: | ||
explicit MediaPermissionDispatcher(RenderFrame* render_frame); | ||
~MediaPermissionDispatcher() override; | ||
|
||
// media::MediaPermission implementation. | ||
void HasPermission(Type type, | ||
const GURL& security_origin, | ||
const PermissionStatusCB& permission_status_cb) override; | ||
void RequestPermission( | ||
Type type, | ||
const GURL& security_origin, | ||
const PermissionStatusCB& permission_status_cb) override; | ||
|
||
private: | ||
// Map of request IDs and pending PermissionStatusCBs. | ||
typedef std::map<uint32_t, PermissionStatusCB> RequestMap; | ||
|
||
// Callback for |permission_service_| calls. | ||
void OnPermissionStatus(uint32_t request_id, PermissionStatus status); | ||
|
||
uint32_t next_request_id_; | ||
RequestMap requests_; | ||
PermissionServicePtr permission_service_; | ||
|
||
base::ThreadChecker thread_checker_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); | ||
}; | ||
|
||
} // namespace content | ||
|
||
#endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "media/base/media_permission.h" | ||
|
||
namespace media { | ||
|
||
MediaPermission::MediaPermission() { | ||
} | ||
|
||
MediaPermission::~MediaPermission() { | ||
} | ||
|
||
} // namespace media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef MEDIA_BASE_MEDIA_PERMISSION_H_ | ||
#define MEDIA_BASE_MEDIA_PERMISSION_H_ | ||
|
||
#include "base/callback.h" | ||
#include "base/macros.h" | ||
#include "media/base/media_export.h" | ||
|
||
class GURL; | ||
|
||
namespace media { | ||
|
||
// Interface to handle media related permission checks and requests. | ||
class MEDIA_EXPORT MediaPermission { | ||
public: | ||
typedef base::Callback<void(bool)> PermissionStatusCB; | ||
|
||
enum Type { | ||
PROTECTED_MEDIA_IDENTIFIER, | ||
}; | ||
|
||
MediaPermission(); | ||
virtual ~MediaPermission(); | ||
|
||
// Checks whether |type| is permitted for |security_origion| without | ||
// triggering user interaction (e.g. permission prompt). The status will be | ||
// |false| if the permission has never been set. | ||
virtual void HasPermission( | ||
Type type, | ||
const GURL& security_origin, | ||
const PermissionStatusCB& permission_status_cb) = 0; | ||
|
||
// Requests |type| permission for |security_origion|. This may trigger user | ||
// interaction (e.g. permission prompt) if the permission has never been set. | ||
virtual void RequestPermission( | ||
Type type, | ||
const GURL& security_origin, | ||
const PermissionStatusCB& permission_status_cb) = 0; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(MediaPermission); | ||
}; | ||
|
||
} // namespace media | ||
|
||
#endif // MEDIA_BASE_MEDIA_PERMISSION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters