Commit f549b3d4 authored by xhwang's avatar xhwang Committed by Commit bot

Support unprefixed EME in HTMLViewer.

Tested with:
out/GN/mojo_shell
http://<host>/LayoutTests/media/encrypted-media/encrypted-media-playback-setmediakeys-before-src.html
--args-for='mojo://html_viewer --v=3 --enable-encrypted-media'

TBR=jamesr@chromium.org
BUG=444205
TEST=See above.

Review URL: https://codereview.chromium.org/815293002

Cr-Commit-Position: refs/heads/master@{#309565}
parent 88572ab2
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "media/blink/webencryptedmediaclient_impl.h"
#include "media/cdm/default_cdm_factory.h"
#include "mojo/public/cpp/application/connect.h" #include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/interfaces/application/shell.mojom.h" #include "mojo/public/interfaces/application/shell.mojom.h"
...@@ -100,11 +103,12 @@ HTMLDocument::HTMLDocument( ...@@ -100,11 +103,12 @@ HTMLDocument::HTMLDocument(
WebMediaPlayerFactory* web_media_player_factory) WebMediaPlayerFactory* web_media_player_factory)
: response_(response.Pass()), : response_(response.Pass()),
shell_(shell), shell_(shell),
web_view_(NULL), web_view_(nullptr),
root_(NULL), root_(nullptr),
view_manager_client_factory_(shell_, this), view_manager_client_factory_(shell_, this),
compositor_thread_(compositor_thread), compositor_thread_(compositor_thread),
web_media_player_factory_(web_media_player_factory) { web_media_player_factory_(web_media_player_factory),
web_encrypted_media_client_(nullptr) {
exported_services_.AddService(this); exported_services_.AddService(this);
exported_services_.AddService(&view_manager_client_factory_); exported_services_.AddService(&view_manager_client_factory_);
WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); WeakBindToPipe(&exported_services_, provider.PassMessagePipe());
...@@ -196,8 +200,7 @@ blink::WebMediaPlayer* HTMLDocument::createMediaPlayer( ...@@ -196,8 +200,7 @@ blink::WebMediaPlayer* HTMLDocument::createMediaPlayer(
blink::WebLocalFrame* frame, blink::WebLocalFrame* frame,
const blink::WebURL& url, const blink::WebURL& url,
blink::WebMediaPlayerClient* client) { blink::WebMediaPlayerClient* client) {
return web_media_player_factory_->CreateMediaPlayer(frame, url, client, return createMediaPlayer(frame, url, client, nullptr);
shell_);
} }
blink::WebMediaPlayer* HTMLDocument::createMediaPlayer( blink::WebMediaPlayer* HTMLDocument::createMediaPlayer(
...@@ -205,7 +208,8 @@ blink::WebMediaPlayer* HTMLDocument::createMediaPlayer( ...@@ -205,7 +208,8 @@ blink::WebMediaPlayer* HTMLDocument::createMediaPlayer(
const blink::WebURL& url, const blink::WebURL& url,
blink::WebMediaPlayerClient* client, blink::WebMediaPlayerClient* client,
blink::WebContentDecryptionModule* initial_cdm) { blink::WebContentDecryptionModule* initial_cdm) {
return createMediaPlayer(frame, url, client); return web_media_player_factory_->CreateMediaPlayer(frame, url, client,
initial_cdm, shell_);
} }
blink::WebFrame* HTMLDocument::createChildFrame( blink::WebFrame* HTMLDocument::createChildFrame(
...@@ -261,6 +265,14 @@ void HTMLDocument::didNavigateWithinPage( ...@@ -261,6 +265,14 @@ void HTMLDocument::didNavigateWithinPage(
navigator_host_->DidNavigateLocally(history_item.urlString().utf8()); navigator_host_->DidNavigateLocally(history_item.urlString().utf8());
} }
blink::WebEncryptedMediaClient* HTMLDocument::encryptedMediaClient() {
if (!web_encrypted_media_client_) {
web_encrypted_media_client_ = new media::WebEncryptedMediaClientImpl(
make_scoped_ptr(new media::DefaultCdmFactory()));
}
return web_encrypted_media_client_;
}
void HTMLDocument::OnViewBoundsChanged(View* view, void HTMLDocument::OnViewBoundsChanged(View* view,
const Rect& old_bounds, const Rect& old_bounds,
const Rect& new_bounds) { const Rect& new_bounds) {
......
...@@ -28,6 +28,10 @@ namespace base { ...@@ -28,6 +28,10 @@ namespace base {
class MessageLoopProxy; class MessageLoopProxy;
} }
namespace media {
class WebEncryptedMediaClientImpl;
}
namespace mojo { namespace mojo {
class ViewManager; class ViewManager;
class View; class View;
...@@ -97,6 +101,7 @@ class HTMLDocument : public blink::WebViewClient, ...@@ -97,6 +101,7 @@ class HTMLDocument : public blink::WebViewClient,
virtual void didNavigateWithinPage(blink::WebLocalFrame* frame, virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
const blink::WebHistoryItem& history_item, const blink::WebHistoryItem& history_item,
blink::WebHistoryCommitType commit_type); blink::WebHistoryCommitType commit_type);
virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
// ViewManagerDelegate methods: // ViewManagerDelegate methods:
void OnEmbed( void OnEmbed(
...@@ -131,6 +136,9 @@ class HTMLDocument : public blink::WebViewClient, ...@@ -131,6 +136,9 @@ class HTMLDocument : public blink::WebViewClient,
scoped_refptr<base::MessageLoopProxy> compositor_thread_; scoped_refptr<base::MessageLoopProxy> compositor_thread_;
WebMediaPlayerFactory* web_media_player_factory_; WebMediaPlayerFactory* web_media_player_factory_;
// EncryptedMediaClient attached to this frame; lazily initialized.
media::WebEncryptedMediaClientImpl* web_encrypted_media_client_;
// HTMLDocument owns these pointers. // HTMLDocument owns these pointers.
std::set<AxProviderImpl*> ax_provider_impls_; std::set<AxProviderImpl*> ax_provider_impls_;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "mojo/services/html_viewer/webmediaplayer_factory.h" #include "mojo/services/html_viewer/webmediaplayer_factory.h"
#include "mojo/services/network/public/interfaces/network_service.mojom.h" #include "mojo/services/network/public/interfaces/network_service.mojom.h"
#include "third_party/WebKit/public/web/WebKit.h" #include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#if !defined(COMPONENT_BUILD) #if !defined(COMPONENT_BUILD)
#include "base/i18n/icu_util.h" #include "base/i18n/icu_util.h"
...@@ -48,6 +49,9 @@ namespace html_viewer { ...@@ -48,6 +49,9 @@ namespace html_viewer {
// media::Renderer implementation. // media::Renderer implementation.
const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer"; const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer";
// Enables support for Encrypted Media Extensions (e.g. MediaKeys).
const char kEnableEncryptedMedia[] = "enable-encrypted-media";
class HTMLViewer; class HTMLViewer;
class HTMLViewerApplication : public mojo::Application { class HTMLViewerApplication : public mojo::Application {
...@@ -174,6 +178,9 @@ class HTMLViewer : public mojo::ApplicationDelegate, ...@@ -174,6 +178,9 @@ class HTMLViewer : public mojo::ApplicationDelegate,
bool enable_mojo_media_renderer = bool enable_mojo_media_renderer =
command_line->HasSwitch(kEnableMojoMediaRenderer); command_line->HasSwitch(kEnableMojoMediaRenderer);
if (command_line->HasSwitch(kEnableEncryptedMedia))
blink::WebRuntimeFeatures::enableEncryptedMedia(true);
compositor_thread_.Start(); compositor_thread_.Start();
web_media_player_factory_.reset(new WebMediaPlayerFactory( web_media_player_factory_.reset(new WebMediaPlayerFactory(
compositor_thread_.message_loop_proxy(), enable_mojo_media_renderer)); compositor_thread_.message_loop_proxy(), enable_mojo_media_renderer));
......
...@@ -78,6 +78,7 @@ blink::WebMediaPlayer* WebMediaPlayerFactory::CreateMediaPlayer( ...@@ -78,6 +78,7 @@ blink::WebMediaPlayer* WebMediaPlayerFactory::CreateMediaPlayer(
blink::WebLocalFrame* frame, blink::WebLocalFrame* frame,
const blink::WebURL& url, const blink::WebURL& url,
blink::WebMediaPlayerClient* client, blink::WebMediaPlayerClient* client,
blink::WebContentDecryptionModule* initial_cdm,
mojo::Shell* shell) { mojo::Shell* shell) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
return nullptr; return nullptr;
...@@ -98,9 +99,10 @@ blink::WebMediaPlayer* WebMediaPlayerFactory::CreateMediaPlayer( ...@@ -98,9 +99,10 @@ blink::WebMediaPlayer* WebMediaPlayerFactory::CreateMediaPlayer(
GetAudioHardwareConfig())); GetAudioHardwareConfig()));
} }
media::WebMediaPlayerParams params( media::WebMediaPlayerParams params(media::WebMediaPlayerParams::DeferLoadCB(),
media::WebMediaPlayerParams::DeferLoadCB(), CreateAudioRendererSink(), CreateAudioRendererSink(), media_log,
media_log, GetMediaThreadTaskRunner(), compositor_task_runner_, nullptr); GetMediaThreadTaskRunner(),
compositor_task_runner_, initial_cdm);
base::WeakPtr<media::WebMediaPlayerDelegate> delegate; base::WeakPtr<media::WebMediaPlayerDelegate> delegate;
scoped_ptr<media::CdmFactory> cdm_factory(new media::DefaultCdmFactory()); scoped_ptr<media::CdmFactory> cdm_factory(new media::DefaultCdmFactory());
......
...@@ -17,6 +17,7 @@ class SingleThreadTaskRunner; ...@@ -17,6 +17,7 @@ class SingleThreadTaskRunner;
} }
namespace blink { namespace blink {
class WebContentDecryptionModule;
class WebMediaPlayer; class WebMediaPlayer;
class WebLocalFrame; class WebLocalFrame;
class WebURL; class WebURL;
...@@ -44,9 +45,11 @@ class WebMediaPlayerFactory { ...@@ -44,9 +45,11 @@ class WebMediaPlayerFactory {
bool enable_mojo_media_renderer); bool enable_mojo_media_renderer);
~WebMediaPlayerFactory(); ~WebMediaPlayerFactory();
blink::WebMediaPlayer* CreateMediaPlayer(blink::WebLocalFrame* frame, blink::WebMediaPlayer* CreateMediaPlayer(
blink::WebLocalFrame* frame,
const blink::WebURL& url, const blink::WebURL& url,
blink::WebMediaPlayerClient* client, blink::WebMediaPlayerClient* client,
blink::WebContentDecryptionModule* initial_cdm,
mojo::Shell* shell); mojo::Shell* shell);
private: private:
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "media/base/key_systems.h"
#include "media/filters/stream_parser_factory.h" #include "media/filters/stream_parser_factory.h"
#include "net/base/mime_util.h" #include "net/base/mime_util.h"
#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebString.h"
...@@ -104,8 +105,24 @@ bool WebMimeRegistryImpl::supportsEncryptedMediaMIMEType( ...@@ -104,8 +105,24 @@ bool WebMimeRegistryImpl::supportsEncryptedMediaMIMEType(
const blink::WebString& key_system, const blink::WebString& key_system,
const blink::WebString& mime_type, const blink::WebString& mime_type,
const blink::WebString& codecs) { const blink::WebString& codecs) {
NOTIMPLEMENTED(); // Only supports ASCII parameters.
if (!base::IsStringASCII(key_system) || !base::IsStringASCII(mime_type) ||
!base::IsStringASCII(codecs)) {
return false;
}
if (key_system.isEmpty())
return false; return false;
const std::string mime_type_ascii = base::UTF16ToASCII(mime_type);
std::vector<std::string> codec_vector;
bool strip_suffix = !net::IsStrictMediaMimeType(mime_type_ascii);
net::ParseCodecString(base::UTF16ToASCII(codecs), &codec_vector,
strip_suffix);
return media::IsSupportedKeySystemWithMediaMimeType(
mime_type_ascii, codec_vector, base::UTF16ToASCII(key_system));
} }
blink::WebMimeRegistry::SupportsType blink::WebMimeRegistry::SupportsType
......
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