From ff0c36b465b3c5e0fc0e369a2795ce1794af1d8e Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 29 Apr 2020 15:01:09 -0400 Subject: [PATCH] Add CefMediaSink::GetIconType (see issue #2900) This attribute is useful for identifying different classes of cast devices without first requiring a connection (CAST, CAST_AUDIO, CAST_AUDIO_GROUP, etc). --- include/capi/cef_media_router_capi.h | 8 +++- include/cef_api_hash.h | 10 ++--- include/cef_media_router.h | 8 ++++ include/internal/cef_types.h | 22 ++++++++-- .../browser/media_router/media_sink_impl.cc | 9 +++++ libcef/browser/media_router/media_sink_impl.h | 1 + libcef_dll/cpptoc/media_sink_cpptoc.cc | 21 +++++++++- libcef_dll/ctocpp/media_sink_ctocpp.cc | 19 ++++++++- libcef_dll/ctocpp/media_sink_ctocpp.h | 3 +- tests/cefclient/browser/media_router_test.cc | 1 + tests/cefclient/resources/media_router.html | 40 +++++++++++++++++-- 11 files changed, 126 insertions(+), 16 deletions(-) diff --git a/include/capi/cef_media_router_capi.h b/include/capi/cef_media_router_capi.h index a07da63da..9bcf16b82 100644 --- a/include/capi/cef_media_router_capi.h +++ b/include/capi/cef_media_router_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=a7070419332ec8f6d6e4df898c8eb666b988970a$ +// $hash=aa1310919932145744d5347d449d6ee10a3a0813$ // #ifndef CEF_INCLUDE_CAPI_CEF_MEDIA_ROUTER_CAPI_H_ @@ -264,6 +264,12 @@ typedef struct _cef_media_sink_t { cef_string_userfree_t(CEF_CALLBACK* get_description)( struct _cef_media_sink_t* self); + /// + // Returns the icon type for this sink. + /// + cef_media_sink_icon_type_t(CEF_CALLBACK* get_icon_type)( + struct _cef_media_sink_t* self); + /// // Returns true (1) if this sink accepts content via Cast. /// diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 5d817b344..dcdd7a8a5 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -34,7 +34,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=af15b08731cc133c3974ceb18002b146a53b9c9e$ +// $hash=fd013f5bdcf2333b1f0fb452442d300dffe598e5$ // #ifndef CEF_INCLUDE_API_HASH_H_ @@ -47,13 +47,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "f76dc8c40e454ef26318d0f83312dadaf909e4c5" +#define CEF_API_HASH_UNIVERSAL "c80d4c5f1dc72279ac7a44d7b174fb80cf728abc" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "831ef33853bb8575bcd097ba65851d4d98a08db8" +#define CEF_API_HASH_PLATFORM "bde71fdc88914ed7353ee7308d060cd6b4f8c8af" #elif defined(OS_MACOSX) -#define CEF_API_HASH_PLATFORM "0944363458590a23d84e99eb1b81372be6784b97" +#define CEF_API_HASH_PLATFORM "2fb3e42a6d2e594aa55792b5852d7f57524ab011" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "dfd012193a93782cd4b041f4cd71e1e8f2ca401e" +#define CEF_API_HASH_PLATFORM "222824f83536a111c6480dba64833251c01cd6fd" #endif #ifdef __cplusplus diff --git a/include/cef_media_router.h b/include/cef_media_router.h index 1d107c42b..3234d3ef2 100644 --- a/include/cef_media_router.h +++ b/include/cef_media_router.h @@ -221,6 +221,8 @@ class CefMediaRouteCreateCallback : public virtual CefBaseRefCounted { /*--cef(source=library)--*/ class CefMediaSink : public virtual CefBaseRefCounted { public: + typedef cef_media_sink_icon_type_t IconType; + /// // Returns the ID for this sink. /// @@ -245,6 +247,12 @@ class CefMediaSink : public virtual CefBaseRefCounted { /*--cef()--*/ virtual CefString GetDescription() = 0; + /// + // Returns the icon type for this sink. + /// + /*--cef(default_retval=CEF_MSIT_GENERIC)--*/ + virtual IconType GetIconType() = 0; + /// // Returns true if this sink accepts content via Cast. /// diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 412cee154..b86af1be4 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -3004,9 +3004,8 @@ typedef struct _cef_composition_underline_t { } cef_composition_underline_t; /// -// Result codes for CefMediaRouter::CreateRoute. These constants match -// their equivalents in Chromium's route_request_result.h and should not be -// renumbered. +// Result codes for CefMediaRouter::CreateRoute. Should be kept in sync with +// Chromium's media_router::RouteRequestResult::ResultCode type. /// typedef enum { CEF_MRCR_UNKNOWN_ERROR = 0, @@ -3033,6 +3032,23 @@ typedef enum { CEF_MRCS_TERMINATED, } cef_media_route_connection_state_t; +/// +// Icon types for a MediaSink object. Should be kept in sync with Chromium's +// media_router::SinkIconType type. +/// +typedef enum { + CEF_MSIT_CAST, + CEF_MSIT_CAST_AUDIO_GROUP, + CEF_MSIT_CAST_AUDIO, + CEF_MSIT_MEETING, + CEF_MSIT_HANGOUT, + CEF_MSIT_EDUCATION, + CEF_MSIT_WIRED_DISPLAY, + CEF_MSIT_GENERIC, + + CEF_MSIT_TOTAL_COUNT, // The total number of values. +} cef_media_sink_icon_type_t; + #ifdef __cplusplus } #endif diff --git a/libcef/browser/media_router/media_sink_impl.cc b/libcef/browser/media_router/media_sink_impl.cc index 20ddb3d40..0743e3c19 100644 --- a/libcef/browser/media_router/media_sink_impl.cc +++ b/libcef/browser/media_router/media_sink_impl.cc @@ -27,6 +27,15 @@ CefString CefMediaSinkImpl::GetDescription() { return sink_.description().value_or(""); } +CefMediaSink::IconType CefMediaSinkImpl::GetIconType() { + // Verify that our enum matches Chromium's values. + static_assert(static_cast(CEF_MSIT_TOTAL_COUNT) == + static_cast(media_router::SinkIconType::TOTAL_COUNT), + "enum mismatch"); + + return static_cast(sink_.icon_type()); +} + bool CefMediaSinkImpl::IsCastSink() { return sink_.provider_id() == media_router::CAST; } diff --git a/libcef/browser/media_router/media_sink_impl.h b/libcef/browser/media_router/media_sink_impl.h index 139f948b8..adaef2459 100644 --- a/libcef/browser/media_router/media_sink_impl.h +++ b/libcef/browser/media_router/media_sink_impl.h @@ -22,6 +22,7 @@ class CefMediaSinkImpl : public CefMediaSink { bool IsValid() override; CefString GetName() override; CefString GetDescription() override; + IconType GetIconType() override; bool IsCastSink() override; bool IsDialSink() override; bool IsCompatibleWith(CefRefPtr source) override; diff --git a/libcef_dll/cpptoc/media_sink_cpptoc.cc b/libcef_dll/cpptoc/media_sink_cpptoc.cc index 13e82df7b..beddb9568 100644 --- a/libcef_dll/cpptoc/media_sink_cpptoc.cc +++ b/libcef_dll/cpptoc/media_sink_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=cbbac244f39cc1d644b0db80a3f7234399286368$ +// $hash=3a295e7d6703e2e8effd94da8e97d8b7f451dc32$ // #include "libcef_dll/cpptoc/media_sink_cpptoc.h" @@ -87,6 +87,24 @@ media_sink_get_description(struct _cef_media_sink_t* self) { return _retval.DetachToUserFree(); } +cef_media_sink_icon_type_t CEF_CALLBACK +media_sink_get_icon_type(struct _cef_media_sink_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return CEF_MSIT_GENERIC; + + // Execute + cef_media_sink_icon_type_t _retval = + CefMediaSinkCppToC::Get(self)->GetIconType(); + + // Return type: simple + return _retval; +} + int CEF_CALLBACK media_sink_is_cast_sink(struct _cef_media_sink_t* self) { shutdown_checker::AssertNotShutdown(); @@ -151,6 +169,7 @@ CefMediaSinkCppToC::CefMediaSinkCppToC() { GetStruct()->is_valid = media_sink_is_valid; GetStruct()->get_name = media_sink_get_name; GetStruct()->get_description = media_sink_get_description; + GetStruct()->get_icon_type = media_sink_get_icon_type; GetStruct()->is_cast_sink = media_sink_is_cast_sink; GetStruct()->is_dial_sink = media_sink_is_dial_sink; GetStruct()->is_compatible_with = media_sink_is_compatible_with; diff --git a/libcef_dll/ctocpp/media_sink_ctocpp.cc b/libcef_dll/ctocpp/media_sink_ctocpp.cc index 9b5f85106..749642c6e 100644 --- a/libcef_dll/ctocpp/media_sink_ctocpp.cc +++ b/libcef_dll/ctocpp/media_sink_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=bb39ec5e546482b707c1e01a83fc1b064d96a4e6$ +// $hash=63071af2d949b451ad0e7273ca0f5d7bfec425db$ // #include "libcef_dll/ctocpp/media_sink_ctocpp.h" @@ -88,6 +88,23 @@ NO_SANITIZE("cfi-icall") CefString CefMediaSinkCToCpp::GetDescription() { return _retvalStr; } +NO_SANITIZE("cfi-icall") +CefMediaSink::IconType CefMediaSinkCToCpp::GetIconType() { + shutdown_checker::AssertNotShutdown(); + + cef_media_sink_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, get_icon_type)) + return CEF_MSIT_GENERIC; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_media_sink_icon_type_t _retval = _struct->get_icon_type(_struct); + + // Return type: simple + return _retval; +} + NO_SANITIZE("cfi-icall") bool CefMediaSinkCToCpp::IsCastSink() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/media_sink_ctocpp.h b/libcef_dll/ctocpp/media_sink_ctocpp.h index c6b302ffa..f3bd084fb 100644 --- a/libcef_dll/ctocpp/media_sink_ctocpp.h +++ b/libcef_dll/ctocpp/media_sink_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=d69c0bdadc802bc7cb970c316f3a0ed8529c5f9c$ +// $hash=c57a82e66fdcd26f70a69fbd92554ca8aa38495c$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_MEDIA_SINK_CTOCPP_H_ @@ -38,6 +38,7 @@ class CefMediaSinkCToCpp : public CefCToCppRefCounted source) OVERRIDE; diff --git a/tests/cefclient/browser/media_router_test.cc b/tests/cefclient/browser/media_router_test.cc index 6a2e0ac08..587469d6b 100644 --- a/tests/cefclient/browser/media_router_test.cc +++ b/tests/cefclient/browser/media_router_test.cc @@ -161,6 +161,7 @@ class MediaObserver : public CefMediaObserver { sink_dict->SetString("id", sink_id); sink_dict->SetString("name", sink->GetName()); sink_dict->SetString("desc", sink->GetDescription()); + sink_dict->SetInt("icon", sink->GetIconType()); sink_dict->SetString( "type", sink->IsCastSink() ? "cast" : sink->IsDialSink() ? "dial" : "unknown"); diff --git a/tests/cefclient/resources/media_router.html b/tests/cefclient/resources/media_router.html index 66d13ea3d..3860082dc 100644 --- a/tests/cefclient/resources/media_router.html +++ b/tests/cefclient/resources/media_router.html @@ -112,6 +112,32 @@ function getStateLabel(state) { return "UNKNOWN"; } +// Values from cef_media_sink_icon_type_t. +var CEF_MSIT_CAST = 0; +var CEF_MSIT_CAST_AUDIO_GROUP = 1; +var CEF_MSIT_CAST_AUDIO = 2; +var CEF_MSIT_MEETING = 3; +var CEF_MSIT_HANGOUT = 4; +var CEF_MSIT_EDUCATION = 5; +var CEF_MSIT_WIRED_DISPLAY = 6; +var CEF_MSIT_GENERIC = 7; + +function getIconTypeLabel(type) { + switch (type) { + case CEF_MSIT_CAST: return "CAST"; + case CEF_MSIT_CAST_AUDIO_GROUP: return "CAST_AUDIO_GROUP"; + case CEF_MSIT_CAST_AUDIO: return "CAST_AUDIO"; + case CEF_MSIT_MEETING: return "MEETING"; + case CEF_MSIT_HANGOUT: return "HANGOUT"; + case CEF_MSIT_EDUCATION: return "EDUCATION"; + case CEF_MSIT_WIRED_DISPLAY: return "WIRED_DISPLAY"; + case CEF_MSIT_GENERIC: return "GENERIC"; + default: break; + } + return "UNKNOWN"; +} + + /// // Manage show/hide of default text for form elements. /// @@ -213,7 +239,9 @@ Expected format for |sinks| is: { name: string, type: string ('cast' or 'dial'), - id: string + id: string, + desc: string, + icon: int }, ... ] */ @@ -248,7 +276,7 @@ function updateSinks(sinks) { if (oldValues.includes(sink.id)) continue; var opt = document.createElement('option'); - opt.innerHTML = sink.name + ' (' + sink.type + ')'; + opt.innerHTML = sink.name + ' (' + sink.type + ', ' + getIconTypeLabel(sink.icon) + ')'; opt.value = sink.id; sinksSelect.appendChild(opt); } @@ -476,12 +504,16 @@ function initDemoMode() { { name: 'Sink 1', type: 'cast', - id: 'sink1' + id: 'sink1', + desc: 'My cast device', + icon: CEF_MSIT_CAST }, { name: 'Sink 2', type: 'dial', - id: 'sink2' + id: 'sink2', + desc: 'My dial device', + icon: CEF_MSIT_GENERIC } ]; updateSinks(sinks);