Commit 308c8646 authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE-in-Workers: Passkey-restrict STMSAttachment ctor

Uses a util::PassKey<URLMediaSource> instance to statically ensure that
only a URLMediaSource can construct that passkey, and therefore can
control that it is the only creator of a
SameThreadMediaSourceAttachment.

BUG=878133

Change-Id: I50bd7669a68113478b42950e74a59c9112623794
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2427207
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Reviewed-by: default avatarWill Cassella <cassew@google.com>
Cr-Commit-Position: refs/heads/master@{#809960}
parent f6c1b8e5
...@@ -32,7 +32,8 @@ blink::HTMLMediaElement* GetMediaElement(blink::MediaSourceTracer* tracer) { ...@@ -32,7 +32,8 @@ blink::HTMLMediaElement* GetMediaElement(blink::MediaSourceTracer* tracer) {
namespace blink { namespace blink {
SameThreadMediaSourceAttachment::SameThreadMediaSourceAttachment( SameThreadMediaSourceAttachment::SameThreadMediaSourceAttachment(
MediaSource* media_source) MediaSource* media_source,
util::PassKey<URLMediaSource> /* passkey */)
: MediaSourceAttachmentSupplement(media_source), : MediaSourceAttachmentSupplement(media_source),
recent_element_time_(0.0), recent_element_time_(0.0),
element_has_error_(false), element_has_error_(false),
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
#include <memory> #include <memory>
#include "base/util/type_safety/pass_key.h"
#include "third_party/blink/public/platform/web_time_range.h" #include "third_party/blink/public/platform/web_time_range.h"
#include "third_party/blink/renderer/modules/mediasource/media_source.h" #include "third_party/blink/renderer/modules/mediasource/media_source.h"
#include "third_party/blink/renderer/modules/mediasource/media_source_attachment_supplement.h" #include "third_party/blink/renderer/modules/mediasource/media_source_attachment_supplement.h"
#include "third_party/blink/renderer/modules/mediasource/url_media_source.h"
namespace blink { namespace blink {
...@@ -18,9 +20,11 @@ class SameThreadMediaSourceAttachment final ...@@ -18,9 +20,11 @@ class SameThreadMediaSourceAttachment final
: public MediaSourceAttachmentSupplement { : public MediaSourceAttachmentSupplement {
public: public:
// The only intended caller of this constructor is // The only intended caller of this constructor is
// URLMediaSource::createObjectUrl. The raw pointer is then adopted into a // URLMediaSource::createObjectUrl, made more clear by using the PassKey. The
// scoped_refptr in SameThreadMediaSourceRegistry::RegisterURL. // raw pointer is then adopted into a scoped_refptr in
explicit SameThreadMediaSourceAttachment(MediaSource* media_source); // SameThreadMediaSourceRegistry::RegisterURL.
SameThreadMediaSourceAttachment(MediaSource* media_source,
util::PassKey<URLMediaSource>);
// MediaSourceAttachmentSupplement // MediaSourceAttachmentSupplement
void NotifyDurationChanged(MediaSourceTracer* tracer, double duration) final; void NotifyDurationChanged(MediaSourceTracer* tracer, double duration) final;
......
...@@ -60,11 +60,12 @@ String URLMediaSource::createObjectURL(ScriptState* script_state, ...@@ -60,11 +60,12 @@ String URLMediaSource::createObjectURL(ScriptState* script_state,
// immediately. It will be adopted into a scoped_refptr in // immediately. It will be adopted into a scoped_refptr in
// MediaSourceRegistryImpl::RegisterURL. See also MediaSourceAttachment (and // MediaSourceRegistryImpl::RegisterURL. See also MediaSourceAttachment (and
// usage in HTMLMediaElement, MediaSourceRegistry{Impl}, and MediaSource) for // usage in HTMLMediaElement, MediaSourceRegistry{Impl}, and MediaSource) for
// further detail. // further detail. Passkey usage statically ensures that only we can call the
// attachment constructor.
// TODO(https://crbug.com/878133): Support creation of a cross-thread // TODO(https://crbug.com/878133): Support creation of a cross-thread
// attachment. // attachment.
MediaSourceAttachment* attachment = MediaSourceAttachment* attachment =
new SameThreadMediaSourceAttachment(source); new SameThreadMediaSourceAttachment(source, PassKey());
DCHECK(attachment->HasOneRef()); DCHECK(attachment->HasOneRef());
String url = DOMURL::CreatePublicURL(execution_context, attachment); String url = DOMURL::CreatePublicURL(execution_context, attachment);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASOURCE_URL_MEDIA_SOURCE_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASOURCE_URL_MEDIA_SOURCE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASOURCE_URL_MEDIA_SOURCE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASOURCE_URL_MEDIA_SOURCE_H_
#include "base/util/type_safety/pass_key.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
...@@ -43,6 +44,7 @@ class URLMediaSource { ...@@ -43,6 +44,7 @@ class URLMediaSource {
STATIC_ONLY(URLMediaSource); STATIC_ONLY(URLMediaSource);
public: public:
using PassKey = util::PassKey<URLMediaSource>;
static String createObjectURL(ScriptState*, MediaSource*); static String createObjectURL(ScriptState*, MediaSource*);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment