feat: add webContents.getMediaSourceId() method (#31204)
* feat: add webContents.getMediaSourceId() method * fix: account for null frame_hosts in webContents.getMediaSourceId() * fix: move webContents.getMediaSourceId definition to be more organised * fix: move webContents.getMediaSourceId implementation * fix: move webContents.getMediaSourceId docs
This commit is contained in:
parent
63eed52626
commit
23cdf65c53
4 changed files with 47 additions and 0 deletions
|
@ -38,6 +38,8 @@
|
|||
#include "content/browser/renderer_host/render_widget_host_view_base.h" // nogncheck
|
||||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "content/public/browser/context_menu_params.h"
|
||||
#include "content/public/browser/desktop_media_id.h"
|
||||
#include "content/public/browser/desktop_streams_registry.h"
|
||||
#include "content/public/browser/download_request_utils.h"
|
||||
#include "content/public/browser/favicon_status.h"
|
||||
#include "content/public/browser/file_select_listener.h"
|
||||
|
@ -2198,6 +2200,33 @@ void WebContents::SetWebRTCIPHandlingPolicy(
|
|||
web_contents()->SyncRendererPrefs();
|
||||
}
|
||||
|
||||
std::string WebContents::GetMediaSourceID(
|
||||
content::WebContents* request_web_contents) {
|
||||
auto* frame_host = web_contents()->GetMainFrame();
|
||||
if (!frame_host)
|
||||
return std::string();
|
||||
|
||||
content::DesktopMediaID media_id(
|
||||
content::DesktopMediaID::TYPE_WEB_CONTENTS,
|
||||
content::DesktopMediaID::kNullId,
|
||||
content::WebContentsMediaCaptureId(frame_host->GetProcess()->GetID(),
|
||||
frame_host->GetRoutingID()));
|
||||
|
||||
auto* request_frame_host = request_web_contents->GetMainFrame();
|
||||
if (!request_frame_host)
|
||||
return std::string();
|
||||
|
||||
std::string id =
|
||||
content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
|
||||
request_frame_host->GetProcess()->GetID(),
|
||||
request_frame_host->GetRoutingID(),
|
||||
url::Origin::Create(
|
||||
request_frame_host->GetLastCommittedURL().GetOrigin()),
|
||||
media_id, "", content::kRegistryStreamTypeTab);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
bool WebContents::IsCrashed() const {
|
||||
return web_contents()->IsCrashed();
|
||||
}
|
||||
|
@ -3875,6 +3904,7 @@ v8::Local<v8::ObjectTemplate> WebContents::FillObjectTemplate(
|
|||
.SetMethod("isBeingCaptured", &WebContents::IsBeingCaptured)
|
||||
.SetMethod("setWebRTCIPHandlingPolicy",
|
||||
&WebContents::SetWebRTCIPHandlingPolicy)
|
||||
.SetMethod("getMediaSourceId", &WebContents::GetMediaSourceID)
|
||||
.SetMethod("getWebRTCIPHandlingPolicy",
|
||||
&WebContents::GetWebRTCIPHandlingPolicy)
|
||||
.SetMethod("takeHeapSnapshot", &WebContents::TakeHeapSnapshot)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue