Skip to content

Commit

Permalink
[Chromecast] Temporarily allow sync mojo API to get cdm origin
Browse files Browse the repository at this point in the history
The origin is used for storage isolation. Now the CDM service should
call a sync mojo API to get the origin from browser process.

Merge-With: eureka-internal/413835
Bug: internal b/159179276
Test: EME on x86
Change-Id: I0dc1292a207b7e05d204436e0f4d45a95857bb34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252636
Reviewed-by: Yuchen Liu <yucliu@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Sean Topping <seantopping@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
Commit-Queue: Yuchen Liu <yucliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780398}
  • Loading branch information
Yuchen Liu authored and Commit Bot committed Jun 19, 2020
1 parent 681b9b2 commit 2fe411a
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 5 deletions.
1 change: 1 addition & 0 deletions chromecast/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ cast_source_set("browser") {
"//chromecast/media:libcast_media",
"//chromecast/media/base:media_codec_support",
"//chromecast/media/base:video_plane_controller",
"//chromecast/media/cdm:cdm_origin_provider",
"//chromecast/media/service",
"//chromecast/media/service/mojom",
"//chromecast/net",
Expand Down
3 changes: 2 additions & 1 deletion chromecast/browser/cast_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "chromecast/media/audio/cast_audio_manager.h"
#include "chromecast/media/base/media_resource_tracker.h"
#include "chromecast/media/cdm/cast_cdm_factory.h"
#include "chromecast/media/cdm/cast_cdm_origin_provider.h"
#include "chromecast/media/cma/backend/cma_backend_factory_impl.h"
#include "chromecast/media/cma/backend/media_pipeline_backend_manager.h"
#include "chromecast/media/service/cast_renderer.h"
Expand Down Expand Up @@ -303,7 +304,7 @@ bool CastContentBrowserClient::OverridesAudioManager() {
std::unique_ptr<::media::CdmFactory> CastContentBrowserClient::CreateCdmFactory(
::media::mojom::FrameInterfaceFactory* frame_interfaces) {
url::Origin cdm_origin;
if(!frame_interfaces->GetCdmOrigin(&cdm_origin))
if (!CastCdmOriginProvider::GetCdmOrigin(frame_interfaces, &cdm_origin))
return nullptr;

return std::make_unique<media::CastCdmFactory>(
Expand Down
4 changes: 2 additions & 2 deletions chromecast/browser/cast_media_blocker_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class CastMediaBlockerBrowserTest : public CastBrowserTest {
query_params.push_back(std::make_pair(tag, media_file));
query_params.push_back(std::make_pair("loop", "true"));

std::string query = media::GetURLQueryString(query_params);
std::string query = ::media::GetURLQueryString(query_params);
GURL gurl = content::GetFileUrlWithQuery(
media::GetTestDataFilePath("player.html"), query);
::media::GetTestDataFilePath("player.html"), query);

web_contents_ = NavigateToURL(gurl);
WaitForLoadStop(web_contents_);
Expand Down
4 changes: 2 additions & 2 deletions chromecast/browser/test/cast_navigation_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CastNavigationBrowserTest : public CastBrowserTest {

void SetUpOnMainThread() override {
embedded_test_server()->ServeFilesFromSourceDirectory(
media::GetTestDataPath());
::media::GetTestDataPath());
ASSERT_TRUE(embedded_test_server()->Start());
}

Expand Down Expand Up @@ -70,7 +70,7 @@ class CastNavigationBrowserTest : public CastBrowserTest {
void RunMediaTestPage(const std::string& html_page,
const base::StringPairs& query_params,
const std::string& expected_title) {
std::string query = media::GetURLQueryString(query_params);
std::string query = ::media::GetURLQueryString(query_params);
GURL gurl = embedded_test_server()->GetURL("/" + html_page + "?" + query);
std::string final_title = RunTest(gurl, expected_title);
EXPECT_EQ(expected_title, final_title);
Expand Down
1 change: 1 addition & 0 deletions chromecast/media/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include_rules = [
"+media/base",
"+media/cdm",
"+media/filters",
"+media/mojo/mojom",
"+mojo/core/embedder/embedder.h",
"+mojo/public/cpp/bindings",
"+ui/gfx/geometry",
Expand Down
12 changes: 12 additions & 0 deletions chromecast/media/cdm/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ cast_source_set("cdm") {
]
}
}

cast_source_set("cdm_origin_provider") {
sources = [
"cast_cdm_origin_provider.cc",
"cast_cdm_origin_provider.h",
]

deps = [
"//media/mojo/mojom",
"//mojo/public/cpp/bindings",
]
}
20 changes: 20 additions & 0 deletions chromecast/media/cdm/cast_cdm_origin_provider.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2020 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 "chromecast/media/cdm/cast_cdm_origin_provider.h"

#include "media/mojo/mojom/frame_interface_factory.mojom.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"

namespace chromecast {

// static
bool CastCdmOriginProvider::GetCdmOrigin(
::media::mojom::FrameInterfaceFactory* interfaces,
url::Origin* cdm_origin) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call;
return interfaces->GetCdmOrigin(cdm_origin);
}

} // namespace chromecast
31 changes: 31 additions & 0 deletions chromecast/media/cdm/cast_cdm_origin_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2020 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 CHROMECAST_MEDIA_CDM_CAST_CDM_ORIGIN_PROVIDER_H_
#define CHROMECAST_MEDIA_CDM_CAST_CDM_ORIGIN_PROVIDER_H_

namespace media {
namespace mojom {
class FrameInterfaceFactory;
} // namespace mojom
} // namespace media

namespace url {
class Origin;
} // namespace url

namespace chromecast {

class CastCdmOriginProvider {
public:
// Util function to call sync mojo API to get cdm origin.
// TODO(159346933) Remove once the origin isolation logic is moved outside of
// media service.
static bool GetCdmOrigin(::media::mojom::FrameInterfaceFactory* interfaces,
url::Origin* cdm_origin);
};

} // namespace chromecast

#endif // CHROMECAST_MEDIA_CDM_CAST_CDM_ORIGIN_PROVIDER_H_
9 changes: 9 additions & 0 deletions mojo/public/cpp/bindings/sync_call_restrictions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#define ENABLE_SYNC_CALL_RESTRICTIONS 0
#endif

namespace chromecast {
class CastCdmOriginProvider;
} // namespace chromecast

namespace sync_preferences {
class PrefServiceSyncable;
}
Expand Down Expand Up @@ -82,6 +86,11 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncCallRestrictions {
// For preventing frame swaps of wrong size during resize on Windows.
// (https://crbug.com/811945)
friend class ui::Compositor;
// For calling sync mojo API to get cdm origin. The service and the client are
// running in the same process, so it won't block anything.
// TODO(159346933) Remove once the origin isolation logic is moved outside of
// cast media service.
friend class chromecast::CastCdmOriginProvider;
// END ALLOWED USAGE.

#if ENABLE_SYNC_CALL_RESTRICTIONS
Expand Down

0 comments on commit 2fe411a

Please sign in to comment.