Add support for muting audio in the browser (issue #1806)
This commit is contained in:
parent
8d1453fd24
commit
ba8b4e8b9d
|
@ -33,7 +33,7 @@
|
|||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
// $hash=faac9d17d7efae3a72c4cc44474071027596c843$
|
||||
// $hash=f99ba0878f8b6313adc7a43ad1fa295304fa9bcb$
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_CAPI_H_
|
||||
|
@ -844,6 +844,18 @@ typedef struct _cef_browser_host_t {
|
|||
// cef_request_tContext::LoadExtension for details.
|
||||
///
|
||||
int(CEF_CALLBACK* is_background_host)(struct _cef_browser_host_t* self);
|
||||
|
||||
///
|
||||
// Set whether the browser's audio is muted.
|
||||
///
|
||||
void(CEF_CALLBACK* set_audio_muted)(struct _cef_browser_host_t* self,
|
||||
int mute);
|
||||
|
||||
///
|
||||
// Returns true (1) if the browser's audio is muted. This function can only
|
||||
// be called on the UI thread.
|
||||
///
|
||||
int(CEF_CALLBACK* is_audio_muted)(struct _cef_browser_host_t* self);
|
||||
} cef_browser_host_t;
|
||||
|
||||
///
|
||||
|
|
|
@ -865,6 +865,19 @@ class CefBrowserHost : public virtual CefBaseRefCounted {
|
|||
///
|
||||
/*--cef()--*/
|
||||
virtual bool IsBackgroundHost() = 0;
|
||||
|
||||
///
|
||||
// Set whether the browser's audio is muted.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void SetAudioMuted(bool mute) = 0;
|
||||
|
||||
///
|
||||
// Returns true if the browser's audio is muted. This method can only be
|
||||
// called on the UI thread.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool IsAudioMuted() = 0;
|
||||
};
|
||||
|
||||
#endif // CEF_INCLUDE_CEF_BROWSER_H_
|
||||
|
|
|
@ -2204,6 +2204,27 @@ void CefBrowserHostImpl::DragSourceEndedAt(
|
|||
platform_delegate_->DragSourceEndedAt(x, y, op);
|
||||
}
|
||||
|
||||
void CefBrowserHostImpl::SetAudioMuted(bool mute) {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT,
|
||||
base::Bind(&CefBrowserHostImpl::SetAudioMuted, this, mute));
|
||||
return;
|
||||
}
|
||||
if (!web_contents())
|
||||
return;
|
||||
web_contents()->SetAudioMuted(mute);
|
||||
}
|
||||
|
||||
bool CefBrowserHostImpl::IsAudioMuted() {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
NOTREACHED() << "called on invalid thread";
|
||||
return false;
|
||||
}
|
||||
if (!web_contents())
|
||||
return false;
|
||||
return web_contents()->IsAudioMuted();
|
||||
}
|
||||
|
||||
// content::WebContentsDelegate methods.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -245,6 +245,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
void DragTargetDrop(const CefMouseEvent& event) override;
|
||||
void DragSourceSystemDragEnded() override;
|
||||
void DragSourceEndedAt(int x, int y, DragOperationsMask op) override;
|
||||
void SetAudioMuted(bool mute) override;
|
||||
bool IsAudioMuted() override;
|
||||
CefRefPtr<CefNavigationEntry> GetVisibleNavigationEntry() override;
|
||||
void SetAccessibilityState(cef_state_t accessibility_state) override;
|
||||
void SetAutoResizeEnabled(bool enabled,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=1a1e9d55adac010523c7c8fdd2de03d9d081ba85$
|
||||
// $hash=db01cea0d5a144e6998c6f897df832b992034646$
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/browser_host_cpptoc.h"
|
||||
|
@ -1200,6 +1200,36 @@ browser_host_is_background_host(struct _cef_browser_host_t* self) {
|
|||
return _retval;
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_host_set_audio_muted(struct _cef_browser_host_t* self,
|
||||
int mute) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
// Execute
|
||||
CefBrowserHostCppToC::Get(self)->SetAudioMuted(mute ? true : false);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK browser_host_is_audio_muted(struct _cef_browser_host_t* self) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
|
||||
// Execute
|
||||
bool _retval = CefBrowserHostCppToC::Get(self)->IsAudioMuted();
|
||||
|
||||
// Return type: bool
|
||||
return _retval;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
@ -1272,6 +1302,8 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() {
|
|||
GetStruct()->set_auto_resize_enabled = browser_host_set_auto_resize_enabled;
|
||||
GetStruct()->get_extension = browser_host_get_extension;
|
||||
GetStruct()->is_background_host = browser_host_is_background_host;
|
||||
GetStruct()->set_audio_muted = browser_host_set_audio_muted;
|
||||
GetStruct()->is_audio_muted = browser_host_is_audio_muted;
|
||||
}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=846e281b136abb262dd052316ea58288ae002a86$
|
||||
// $hash=5774cd86b6aa84a3e3e4982d578200c11fdde391$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/browser_host_ctocpp.h"
|
||||
|
@ -950,8 +950,8 @@ void CefBrowserHostCToCpp::DragSourceSystemDragEnded() {
|
|||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
CefRefPtr<CefNavigationEntry>
|
||||
CefBrowserHostCToCpp::GetVisibleNavigationEntry() {
|
||||
CefRefPtr<
|
||||
CefNavigationEntry> CefBrowserHostCToCpp::GetVisibleNavigationEntry() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_browser_host_t* _struct = GetStruct();
|
||||
|
@ -1032,6 +1032,35 @@ NO_SANITIZE("cfi-icall") bool CefBrowserHostCToCpp::IsBackgroundHost() {
|
|||
return _retval ? true : false;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall") void CefBrowserHostCToCpp::SetAudioMuted(bool mute) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_browser_host_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, set_audio_muted))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
_struct->set_audio_muted(_struct, mute);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall") bool CefBrowserHostCToCpp::IsAudioMuted() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_browser_host_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, is_audio_muted))
|
||||
return false;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
int _retval = _struct->is_audio_muted(_struct);
|
||||
|
||||
// Return type: bool
|
||||
return _retval ? true : false;
|
||||
}
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefBrowserHostCToCpp::CefBrowserHostCToCpp() {}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=afb348f0b0421d4d4202fac43edc2378c5a2d92c$
|
||||
// $hash=14cebadd19516a54e746345f42adc90fbeed0a2d$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_BROWSER_HOST_CTOCPP_H_
|
||||
|
@ -127,6 +127,8 @@ class CefBrowserHostCToCpp : public CefCToCppRefCounted<CefBrowserHostCToCpp,
|
|||
const CefSize& max_size) OVERRIDE;
|
||||
CefRefPtr<CefExtension> GetExtension() OVERRIDE;
|
||||
bool IsBackgroundHost() OVERRIDE;
|
||||
void SetAudioMuted(bool mute) OVERRIDE;
|
||||
bool IsAudioMuted() OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_DLL_CTOCPP_BROWSER_HOST_CTOCPP_H_
|
||||
|
|
|
@ -40,7 +40,9 @@
|
|||
#define ID_TESTS_OSR_FPS 32713
|
||||
#define ID_TESTS_OSR_DSF 32714
|
||||
#define ID_TESTS_PRINT_TO_PDF 32715
|
||||
#define ID_TESTS_LAST 32715
|
||||
#define ID_TESTS_MUTE_AUDIO 32716
|
||||
#define ID_TESTS_UNMUTE_AUDIO 32717
|
||||
#define ID_TESTS_LAST 32717
|
||||
#define IDC_STATIC -1
|
||||
#define IDS_BINDING_HTML 1000
|
||||
#define IDS_DIALOGS_HTML 1001
|
||||
|
|
|
@ -879,6 +879,8 @@ GtkWidget* RootWindowGtk::CreateMenuBar() {
|
|||
AddMenuEntry(test_menu, "End Tracing", ID_TESTS_TRACING_END);
|
||||
AddMenuEntry(test_menu, "Print", ID_TESTS_PRINT);
|
||||
AddMenuEntry(test_menu, "Print to PDF", ID_TESTS_PRINT_TO_PDF);
|
||||
AddMenuEntry(test_menu, "Mute Audio", ID_TESTS_MUTE_AUDIO);
|
||||
AddMenuEntry(test_menu, "Unmute Audio", ID_TESTS_UNMUTE_AUDIO);
|
||||
AddMenuEntry(test_menu, "Other Tests", ID_TESTS_OTHER_TESTS);
|
||||
|
||||
return menu_bar;
|
||||
|
|
|
@ -415,6 +415,11 @@ void PrintToPDF(CefRefPtr<CefBrowser> browser) {
|
|||
new Client(browser);
|
||||
}
|
||||
|
||||
void MuteAudio(CefRefPtr<CefBrowser> browser, bool mute) {
|
||||
CefRefPtr<CefBrowserHost> host = browser->GetHost();
|
||||
host->SetAudioMuted(mute);
|
||||
}
|
||||
|
||||
void RunOtherTests(CefRefPtr<CefBrowser> browser) {
|
||||
browser->GetMainFrame()->LoadURL("http://tests/other_tests");
|
||||
}
|
||||
|
@ -538,6 +543,12 @@ void RunTest(CefRefPtr<CefBrowser> browser, int id) {
|
|||
case ID_TESTS_PRINT_TO_PDF:
|
||||
PrintToPDF(browser);
|
||||
break;
|
||||
case ID_TESTS_MUTE_AUDIO:
|
||||
MuteAudio(browser, true);
|
||||
break;
|
||||
case ID_TESTS_UNMUTE_AUDIO:
|
||||
MuteAudio(browser, false);
|
||||
break;
|
||||
case ID_TESTS_OTHER_TESTS:
|
||||
RunOtherTests(browser);
|
||||
break;
|
||||
|
|
|
@ -86,6 +86,8 @@ void AddTestMenuItems(CefRefPtr<CefMenuModel> test_menu) {
|
|||
test_menu->AddItem(ID_TESTS_TRACING_END, "End Tracing");
|
||||
test_menu->AddItem(ID_TESTS_PRINT, "Print");
|
||||
test_menu->AddItem(ID_TESTS_PRINT_TO_PDF, "Print to PDF");
|
||||
test_menu->AddItem(ID_TESTS_MUTE_AUDIO, "Mute Audio");
|
||||
test_menu->AddItem(ID_TESTS_UNMUTE_AUDIO, "Unmute Audio");
|
||||
test_menu->AddItem(ID_TESTS_OTHER_TESTS, "Other Tests");
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ NSMenuItem* GetMenuItemWithAction(NSMenu* menu, SEL action_selector) {
|
|||
} // namespace
|
||||
|
||||
// Receives notifications from the application. Will delete itself when done.
|
||||
@interface ClientAppDelegate : NSObject<NSApplicationDelegate> {
|
||||
@interface ClientAppDelegate : NSObject <NSApplicationDelegate> {
|
||||
@private
|
||||
bool with_controls_;
|
||||
bool with_osr_;
|
||||
|
@ -65,12 +65,14 @@ NSMenuItem* GetMenuItemWithAction(NSMenu* menu, SEL action_selector) {
|
|||
- (IBAction)menuTestsTracingEnd:(id)sender;
|
||||
- (IBAction)menuTestsPrint:(id)sender;
|
||||
- (IBAction)menuTestsPrintToPdf:(id)sender;
|
||||
- (IBAction)menuTestsMuteAudio:(id)sender;
|
||||
- (IBAction)menuTestsUnmuteAudio:(id)sender;
|
||||
- (IBAction)menuTestsOtherTests:(id)sender;
|
||||
- (void)enableAccessibility:(bool)bEnable;
|
||||
@end
|
||||
|
||||
// Provide the CefAppProtocol implementation required by CEF.
|
||||
@interface ClientApplication : NSApplication<CefAppProtocol> {
|
||||
@interface ClientApplication : NSApplication <CefAppProtocol> {
|
||||
@private
|
||||
BOOL handlingSendEvent_;
|
||||
}
|
||||
|
@ -308,6 +310,14 @@ NSMenuItem* GetMenuItemWithAction(NSMenu* menu, SEL action_selector) {
|
|||
[self testsItemSelected:ID_TESTS_PRINT_TO_PDF];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsMuteAudio:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_MUTE_AUDIO];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsUnmuteAudio:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_UNMUTE_AUDIO];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsOtherTests:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_OTHER_TESTS];
|
||||
}
|
||||
|
|
|
@ -103,6 +103,8 @@ BEGIN
|
|||
MENUITEM "End Tracing", ID_TESTS_TRACING_END
|
||||
MENUITEM "Print", ID_TESTS_PRINT
|
||||
MENUITEM "Print to PDF", ID_TESTS_PRINT_TO_PDF
|
||||
MENUITEM "Mute Audio", ID_TESTS_MUTE_AUDIO
|
||||
MENUITEM "Unmute Audio", ID_TESTS_UNMUTE_AUDIO
|
||||
MENUITEM "Other Tests", ID_TESTS_OTHER_TESTS
|
||||
END
|
||||
END
|
||||
|
|
Loading…
Reference in New Issue