Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

6.0 KB
Raw Blame
diff --git a/cef/libcef/browser/browser_contents_delegate.cc b/cef/libcef/browser/browser_contents_delegate.cc
index 72dd7c5..12186c2 100644
--- a/cef/libcef/browser/browser_contents_delegate.cc
+++ b/cef/libcef/browser/browser_contents_delegate.cc
@@ -11,6 +11,7 @@
 #include "cef/libcef/browser/native/cursor_util.h"
 #include "cef/libcef/common/api_version_util.h"
 #include "cef/libcef/common/frame_util.h"
+#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
 #include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
 #include "chrome/common/chrome_result_codes.h"
 #include "components/input/native_web_keyboard_event.h"
@@ -86,7 +87,14 @@ class CefWidgetHostInterceptor
 
 CefBrowserContentsDelegate::CefBrowserContentsDelegate(
     scoped_refptr<CefBrowserInfo> browser_info)
-    : browser_info_(browser_info) {}
+    : browser_info_(browser_info) {
+  // Cra: Chrome's tab recording indicator. CEF's OnMediaAccessChange only
+  // fires for streams CEF's own permission flow allowed; Chrome-style pages
+  // that get the camera or microphone through Chrome's flow never report it.
+  capture_observation_.Observe(MediaCaptureDevicesDispatcher::GetInstance()
+                                   ->GetMediaStreamCaptureIndicator()
+                                   .get());
+}
 
 void CefBrowserContentsDelegate::ObserveWebContents(
     content::WebContents* new_contents) {
@@ -613,6 +621,56 @@ void CefBrowserContentsDelegate::DidFinishLoad(
   OnLoadEnd(frame, validated_url, http_status_code);
 }
 
+// Cra: Chromium's audible state (Chrome's tab speaker icon), which CEF has no
+// callback for. Delivered as a "Cra.audible" message from PID_BROWSER whose
+// only argument is the new state.
+void CefBrowserContentsDelegate::OnAudioStateChanged(bool audible) {
+  auto c = client();
+  auto b = browser();
+  if (!c || !b) {
+    return;
+  }
+  CefRefPtr<CefProcessMessage> message =
+      CefProcessMessage::Create("Cra.audible");
+  message->GetArgumentList()->SetBool(0, audible);
+  c->OnProcessMessageReceived(b, b->GetMainFrame(), PID_BROWSER, message);
+}
+
+// Cra: whether the page uses the camera and the microphone, as Chrome's tab
+// recording indicator (MediaStreamCaptureIndicator) counts them. Delivered as a
+// "Cra.capture" message from PID_BROWSER with the camera and microphone states.
+void CefBrowserContentsDelegate::OnIsCapturingVideoChanged(
+    content::WebContents* web_contents,
+    bool is_capturing_video) {
+  if (web_contents == this->web_contents()) {
+    SendCaptureState();
+  }
+}
+
+void CefBrowserContentsDelegate::OnIsCapturingAudioChanged(
+    content::WebContents* web_contents,
+    bool is_capturing_audio) {
+  if (web_contents == this->web_contents()) {
+    SendCaptureState();
+  }
+}
+
+void CefBrowserContentsDelegate::SendCaptureState() {
+  auto c = client();
+  auto b = browser();
+  auto wc = web_contents();
+  if (!c || !b || !wc) {
+    return;
+  }
+  auto indicator =
+      MediaCaptureDevicesDispatcher::GetInstance()->GetMediaStreamCaptureIndicator();
+  CefRefPtr<CefProcessMessage> message =
+      CefProcessMessage::Create("Cra.capture");
+  message->GetArgumentList()->SetBool(0, indicator->IsCapturingVideo(wc));
+  message->GetArgumentList()->SetBool(1, indicator->IsCapturingAudio(wc));
+  c->OnProcessMessageReceived(b, b->GetMainFrame(), PID_BROWSER, message);
+}
+
 void CefBrowserContentsDelegate::TitleWasSet(content::NavigationEntry* entry) {
   // |entry| may be NULL if a popup is created via window.open and never
   // navigated.
diff --git a/cef/libcef/browser/browser_contents_delegate.h b/cef/libcef/browser/browser_contents_delegate.h
index ae50fee..1e99f05 100644
--- a/cef/libcef/browser/browser_contents_delegate.h
+++ b/cef/libcef/browser/browser_contents_delegate.h
@@ -10,7 +10,9 @@
 
 #include "base/callback_list.h"
 #include "base/observer_list.h"
+#include "base/scoped_observation.h"
 #include "cef/libcef/browser/frame_host_impl.h"
+#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
 #include "content/public/browser/web_contents_delegate.h"
 #include "content/public/browser/web_contents_observer.h"
 
@@ -45,8 +47,10 @@ constexpr inline CefBrowserContentsState operator|(
 // Tracks state and executes client callbacks based on WebContents callbacks.
 // Includes functionality that is shared by Alloy and Chrome styles. Only
 // accessed on the UI thread.
-class CefBrowserContentsDelegate : public content::WebContentsDelegate,
-                                   public content::WebContentsObserver {
+class CefBrowserContentsDelegate
+    : public content::WebContentsDelegate,
+      public content::WebContentsObserver,
+      public MediaStreamCaptureIndicator::Observer {
  public:
   using State = CefBrowserContentsState;
 
@@ -134,6 +138,14 @@ class CefBrowserContentsDelegate : public content::WebContentsDelegate,
   void PrimaryMainDocumentElementAvailable() override;
   void LoadProgressChanged(double progress) override;
   void DidStopLoading() override;
+  void OnAudioStateChanged(bool audible) override;
+
+  // MediaStreamCaptureIndicator::Observer methods (Cra: camera and microphone
+  // use, see SendCaptureState).
+  void OnIsCapturingVideoChanged(content::WebContents* web_contents,
+                                 bool is_capturing_video) override;
+  void OnIsCapturingAudioChanged(content::WebContents* web_contents,
+                                 bool is_capturing_audio) override;
   void DidFinishNavigation(
       content::NavigationHandle* navigation_handle) override;
   void DidFailLoad(content::RenderFrameHost* render_frame_host,
@@ -177,6 +189,10 @@ class CefBrowserContentsDelegate : public content::WebContentsDelegate,
   bool OnSetFocus(cef_focus_source_t source);
 
  private:
+  void SendCaptureState();
+  base::ScopedObservation<MediaStreamCaptureIndicator,
+                          MediaStreamCaptureIndicator::Observer>
+      capture_observation_{this};
   CefRefPtr<CefClient> client() const;
   CefRefPtr<CefBrowser> browser() const;
   CefBrowserPlatformDelegate* platform_delegate() const;