summaryrefslogtreecommitdiff
path: root/chromium/qtwebengine/browser/extensions/api
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2020-10-29 10:01:00 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-03-16 15:21:53 +0100
commita0cbfced7f87d3845c4283fcb2a1a91c7d6e36f4 (patch)
tree80c0b642ee3602bb77ea94cb95a2ea45a76e4a23 /chromium/qtwebengine/browser/extensions/api
parent922cf977666f21c3a2b3b6ffb6fb8f40e63cb651 (diff)
downloadqtwebengine-chromium-a0cbfced7f87d3845c4283fcb2a1a91c7d6e36f4.tar.gz
Add minimal webrtcdesktopcapture api for hangout services extension
The hangout services extension is required for meet.google.com. The extension is only able to capture the primary screen without audio with this fix. Change-Id: Ic5563ebe4e0b8f1e8bfa83ca0830f180281a1f8c Fixes: QTBUG-85731 Task-number: QTBUG-51185 Task-number: QTBUG-61676 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/qtwebengine/browser/extensions/api')
-rw-r--r--chromium/qtwebengine/browser/extensions/api/BUILD.gn33
-rw-r--r--chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.cc196
-rw-r--r--chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.h120
3 files changed, 349 insertions, 0 deletions
diff --git a/chromium/qtwebengine/browser/extensions/api/BUILD.gn b/chromium/qtwebengine/browser/extensions/api/BUILD.gn
new file mode 100644
index 00000000000..13baddb25af
--- /dev/null
+++ b/chromium/qtwebengine/browser/extensions/api/BUILD.gn
@@ -0,0 +1,33 @@
+import("//extensions/buildflags/buildflags.gni")
+import("//qtwebengine/common/extensions/api/schema.gni")
+import("//tools/json_schema_compiler/json_schema_api.gni")
+
+assert(enable_extensions,
+ "Cannot depend on extensions because enable_extensions=false.")
+
+source_set("webrtc_desktop_capture_private") {
+ sources = [
+ "webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.cc",
+ "webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.h",
+ ]
+
+ deps = [
+ "//content/public/browser",
+ ]
+}
+
+function_registration("api_registration") {
+ sources = webengine_extensions_api_schema_files
+
+ impl_dir = "//qtwebengine/browser/extensions/api"
+ bundle_name = "QtWebEngine"
+ root_namespace = webengine_extensions_api_root_namespace
+
+ deps = [
+ ":webrtc_desktop_capture_private",
+ "//extensions/common/api",
+
+ # Required due to generated mojom headers
+ "//skia"
+ ]
+}
diff --git a/chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.cc b/chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.cc
new file mode 100644
index 00000000000..9499437130b
--- /dev/null
+++ b/chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.cc
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// based on //chrome/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.cc
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.h"
+
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/desktop_media_id.h"
+#include "content/public/browser/desktop_streams_registry.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/media_stream_request.h"
+#include "content/public/common/origin_util.h"
+#include "extensions/browser/extension_host.h"
+#include "extensions/browser/process_manager.h"
+#include "qtwebengine/common/extensions/api/webrtc_desktop_capture_private.h"
+#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
+
+using extensions::api::webrtc_desktop_capture_private::Options;
+using extensions::api::webrtc_desktop_capture_private::ChooseDesktopMedia::Results::Create;
+
+namespace extensions {
+
+namespace {
+
+const char kTargetNotFoundError[] = "The specified target is not found.";
+
+} // namespace
+
+WebrtcDesktopCapturePrivateChooseDesktopMediaFunction::
+ WebrtcDesktopCapturePrivateChooseDesktopMediaFunction() {
+}
+
+WebrtcDesktopCapturePrivateChooseDesktopMediaFunction::
+ ~WebrtcDesktopCapturePrivateChooseDesktopMediaFunction() {
+}
+
+ExtensionFunction::ResponseAction
+WebrtcDesktopCapturePrivateChooseDesktopMediaFunction::Run() {
+ using Params =
+ extensions::api::webrtc_desktop_capture_private::ChooseDesktopMedia
+ ::Params;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetSize() > 0);
+
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &request_id_));
+ DesktopCaptureRequestsRegistry::GetInstance()->AddRequest(source_process_id(),
+ request_id_, this);
+
+ args_->Remove(0, NULL);
+
+ std::unique_ptr<Params> params = Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
+ params->request.guest_process_id,
+ params->request.guest_render_frame_id);
+
+ if (!rfh) {
+ return RespondNow(Error(kTargetNotFoundError));
+ }
+
+ GURL origin = rfh->GetLastCommittedURL().GetOrigin();
+ content::WebContents* web_contents =
+ content::WebContents::FromRenderFrameHost(rfh);
+ if (!web_contents) {
+ return RespondNow(Error(kTargetNotFoundError));
+ }
+
+ content::RenderFrameHost* const main_frame = web_contents->GetMainFrame();
+ content::MediaStreamRequest request(main_frame->GetProcess()->GetID() /* render_process_id */,
+ main_frame->GetRoutingID() /* render_frame_id */,
+ request_id_ /* page_request_id */,
+ origin /* security_origin */,
+ true /* user_gesture */,
+ blink::MediaStreamRequestType::MEDIA_DEVICE_ACCESS /* request_type */,
+ "" /* requested_audio_device_id */,
+ "" /* requested_video_device_id */,
+ blink::mojom::MediaStreamType::GUM_DESKTOP_AUDIO_CAPTURE /* audio_type */,
+ blink::mojom::MediaStreamType::GUM_DESKTOP_VIDEO_CAPTURE /* video_type */,
+ true /* disable_local_echo */,
+ false /* request_pan_tilt_zoom_permission */);
+
+ extensions::ExtensionHost *host = extensions::ProcessManager::Get(browser_context())->GetBackgroundHostForExtension(extension_id());
+ host->RequestMediaAccessPermission(web_contents, request,
+ base::BindOnce(&WebrtcDesktopCapturePrivateChooseDesktopMediaFunction::ProcessAccessRequestResponse,
+ weak_factory_.GetWeakPtr(), main_frame, origin));
+
+ return RespondLater();
+}
+
+void WebrtcDesktopCapturePrivateChooseDesktopMediaFunction::ProcessAccessRequestResponse(
+ content::RenderFrameHost* const main_frame,
+ const GURL &origin,
+ const blink::MediaStreamDevices& devices,
+ blink::mojom::MediaStreamRequestResult stream_request_result,
+ std::unique_ptr<content::MediaStreamUI> stream_ui)
+{
+ if (stream_request_result != blink::mojom::MediaStreamRequestResult::OK) {
+ Respond(ArgumentList(Create(std::string(), Options())));
+ return;
+ }
+
+ DCHECK(!devices.empty());
+
+ content::DesktopMediaID source = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, 0);
+ blink::MediaStreamDevices::const_iterator it = devices.begin();
+ for (; it != devices.end(); ++it) {
+ content::DesktopMediaID id = content::DesktopMediaID::Parse(it->id);
+ if (id.type == content::DesktopMediaID::TYPE_SCREEN) {
+ source = id;
+ break;
+ }
+ }
+
+ std::string result = content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
+ main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(),
+ url::Origin::Create(origin), source, extension()->name(),
+ content::kRegistryStreamTypeDesktop);
+
+ Options options;
+ options.can_request_audio_track = source.audio_share;
+ Respond(ArgumentList(Create(result, options)));
+}
+
+DesktopCaptureRequestsRegistry::RequestId::RequestId(int process_id,
+ int request_id)
+ : process_id(process_id), request_id(request_id) {}
+
+bool DesktopCaptureRequestsRegistry::RequestId::operator<(
+ const RequestId& other) const {
+ return std::tie(process_id, request_id) <
+ std::tie(other.process_id, other.request_id);
+}
+
+DesktopCaptureRequestsRegistry::DesktopCaptureRequestsRegistry() {}
+DesktopCaptureRequestsRegistry::~DesktopCaptureRequestsRegistry() {}
+
+// static
+DesktopCaptureRequestsRegistry* DesktopCaptureRequestsRegistry::GetInstance() {
+ return base::Singleton<DesktopCaptureRequestsRegistry>::get();
+}
+
+void DesktopCaptureRequestsRegistry::AddRequest(
+ int process_id,
+ int request_id,
+ WebrtcDesktopCapturePrivateChooseDesktopMediaFunction* handler) {
+ requests_.insert(
+ RequestsMap::value_type(RequestId(process_id, request_id), handler));
+}
+
+void DesktopCaptureRequestsRegistry::RemoveRequest(int process_id,
+ int request_id) {
+ requests_.erase(RequestId(process_id, request_id));
+}
+
+} // namespace extensions
diff --git a/chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.h b/chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.h
new file mode 100644
index 00000000000..f057d211939
--- /dev/null
+++ b/chromium/qtwebengine/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.h
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// based on //chrome/browser/extensions/api/webrtc_desktop_capture_private/webrtc_desktop_capture_private_api.h
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBENGINE_BROWSER_EXTENSIONS_API_WEBRTC_DESKTOP_CAPTURE_PRIVATE_WEBRTC_DESKTOP_CAPTURE_PRIVATE_API_H_
+#define WEBENGINE_BROWSER_EXTENSIONS_API_WEBRTC_DESKTOP_CAPTURE_PRIVATE_WEBRTC_DESKTOP_CAPTURE_PRIVATE_API_H_
+
+#include <map>
+
+#include "base/macros.h"
+#include "base/memory/singleton.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/media_stream_request.h"
+#include "extensions/browser/extension_function.h"
+#include "third_party/blink/public/common/mediastream/media_stream_request.h"
+
+namespace content {
+class RenderFrameHost;
+}
+
+namespace extensions {
+
+class WebrtcDesktopCapturePrivateChooseDesktopMediaFunction : public ExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("webrtcDesktopCapturePrivate.chooseDesktopMedia",
+ WEBRTCDESKTOPCAPTUREPRIVATE_CHOOSEDESKTOPMEDIA)
+ WebrtcDesktopCapturePrivateChooseDesktopMediaFunction();
+
+ private:
+ ~WebrtcDesktopCapturePrivateChooseDesktopMediaFunction() override;
+ void ProcessAccessRequestResponse(
+ content::RenderFrameHost* const main_frame,
+ const GURL &origin,
+ const blink::MediaStreamDevices& devices,
+ blink::mojom::MediaStreamRequestResult stream_request_result,
+ std::unique_ptr<content::MediaStreamUI> stream_ui);
+
+ // ExtensionFunction overrides.
+ ResponseAction Run() override;
+
+ int request_id_;
+ base::WeakPtrFactory<WebrtcDesktopCapturePrivateChooseDesktopMediaFunction> weak_factory_{this};
+};
+
+class DesktopCaptureRequestsRegistry {
+ public:
+ DesktopCaptureRequestsRegistry();
+ ~DesktopCaptureRequestsRegistry();
+
+ static DesktopCaptureRequestsRegistry* GetInstance();
+
+ void AddRequest(int process_id,
+ int request_id,
+ WebrtcDesktopCapturePrivateChooseDesktopMediaFunction* handler);
+ void RemoveRequest(int process_id, int request_id);
+
+ private:
+ friend struct base::DefaultSingletonTraits<DesktopCaptureRequestsRegistry>;
+
+ struct RequestId {
+ RequestId(int process_id, int request_id);
+
+ // Need to use RequestId as a key in std::map<>.
+ bool operator<(const RequestId& other) const;
+
+ int process_id;
+ int request_id;
+ };
+
+ using RequestsMap =
+ std::map<RequestId, WebrtcDesktopCapturePrivateChooseDesktopMediaFunction*>;
+
+ RequestsMap requests_;
+
+ DISALLOW_COPY_AND_ASSIGN(DesktopCaptureRequestsRegistry);
+};
+
+} // namespace extensions
+
+#endif // WEBENGINE_BROWSER_EXTENSIONS_API_WEBRTC_DESKTOP_CAPTURE_PRIVATE_WEBRTC_DESKTOP_CAPTURE_PRIVATE_API_H_