diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h index 322989709..b6b4863d6 100644 --- a/include/capi/cef_browser_capi.h +++ b/include/capi/cef_browser_capi.h @@ -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; /// diff --git a/include/cef_browser.h b/include/cef_browser.h index 8b438e5fd..f32ab2409 100644 --- a/include/cef_browser.h +++ b/include/cef_browser.h @@ -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_ diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 64c2cd5c0..406fb35af 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -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. // ----------------------------------------------------------------------------- diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index 7acd8df2c..5c65eea03 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -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 GetVisibleNavigationEntry() override; void SetAccessibilityState(cef_state_t accessibility_state) override; void SetAutoResizeEnabled(bool enabled, diff --git a/libcef_dll/cpptoc/browser_host_cpptoc.cc b/libcef_dll/cpptoc/browser_host_cpptoc.cc index 190ad59bb..a095f3fda 100644 --- a/libcef_dll/cpptoc/browser_host_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_host_cpptoc.cc @@ -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. diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.cc b/libcef_dll/ctocpp/browser_host_ctocpp.cc index fdbc179b0..f35f5b2bc 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_host_ctocpp.cc @@ -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 -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() {} diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.h b/libcef_dll/ctocpp/browser_host_ctocpp.h index 3ccbe9982..540be4f56 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.h +++ b/libcef_dll/ctocpp/browser_host_ctocpp.h @@ -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 GetExtension() OVERRIDE; bool IsBackgroundHost() OVERRIDE; + void SetAudioMuted(bool mute) OVERRIDE; + bool IsAudioMuted() OVERRIDE; }; #endif // CEF_LIBCEF_DLL_CTOCPP_BROWSER_HOST_CTOCPP_H_ diff --git a/tests/cefclient/browser/resource.h b/tests/cefclient/browser/resource.h index 55e661e36..7102b4eb0 100644 --- a/tests/cefclient/browser/resource.h +++ b/tests/cefclient/browser/resource.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 diff --git a/tests/cefclient/browser/root_window_gtk.cc b/tests/cefclient/browser/root_window_gtk.cc index 02451a28a..45a1bf2c8 100644 --- a/tests/cefclient/browser/root_window_gtk.cc +++ b/tests/cefclient/browser/root_window_gtk.cc @@ -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; diff --git a/tests/cefclient/browser/test_runner.cc b/tests/cefclient/browser/test_runner.cc index 935a5885c..cfa64ee00 100644 --- a/tests/cefclient/browser/test_runner.cc +++ b/tests/cefclient/browser/test_runner.cc @@ -415,6 +415,11 @@ void PrintToPDF(CefRefPtr browser) { new Client(browser); } +void MuteAudio(CefRefPtr browser, bool mute) { + CefRefPtr host = browser->GetHost(); + host->SetAudioMuted(mute); +} + void RunOtherTests(CefRefPtr browser) { browser->GetMainFrame()->LoadURL("http://tests/other_tests"); } @@ -538,6 +543,12 @@ void RunTest(CefRefPtr 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; diff --git a/tests/cefclient/browser/views_window.cc b/tests/cefclient/browser/views_window.cc index 2316d07dc..619541169 100644 --- a/tests/cefclient/browser/views_window.cc +++ b/tests/cefclient/browser/views_window.cc @@ -86,6 +86,8 @@ void AddTestMenuItems(CefRefPtr 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"); } diff --git a/tests/cefclient/cefclient_mac.mm b/tests/cefclient/cefclient_mac.mm index b61389a8d..a1c56f7a8 100644 --- a/tests/cefclient/cefclient_mac.mm +++ b/tests/cefclient/cefclient_mac.mm @@ -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 { +@interface ClientAppDelegate : NSObject { @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 { +@interface ClientApplication : NSApplication { @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]; } diff --git a/tests/cefclient/resources/win/cefclient.rc b/tests/cefclient/resources/win/cefclient.rc index 06605d43f..3ff2e1a21 100644 --- a/tests/cefclient/resources/win/cefclient.rc +++ b/tests/cefclient/resources/win/cefclient.rc @@ -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