diff options
Diffstat (limited to 'chromium/qtwebengine')
7 files changed, 430 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_ diff --git a/chromium/qtwebengine/browser/qt_webengine_resources.grd b/chromium/qtwebengine/browser/qt_webengine_resources.grd index 8da8c851146..7936ec7a921 100644 --- a/chromium/qtwebengine/browser/qt_webengine_resources.grd +++ b/chromium/qtwebengine/browser/qt_webengine_resources.grd @@ -21,6 +21,9 @@ <include name="IDR_SANDBOX_INTERNALS_HTML" file="../../chrome/browser/resources/sandbox_internals/sandbox_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" compress="gzip" /> <include name="IDR_SANDBOX_INTERNALS_JS" file="../../chrome/browser/resources/sandbox_internals/sandbox_internals.js" type="BINDATA" compress="gzip" /> </if> + <if expr="enable_hangout_services_extension"> + <include name="IDR_HANGOUT_SERVICES_MANIFEST" file="../../chrome/browser/resources/hangout_services/manifest.json" type="BINDATA" /> + </if> </includes> </release> </grit> diff --git a/chromium/qtwebengine/common/extensions/api/BUILD.gn b/chromium/qtwebengine/common/extensions/api/BUILD.gn new file mode 100644 index 00000000000..92bcdcd5ae8 --- /dev/null +++ b/chromium/qtwebengine/common/extensions/api/BUILD.gn @@ -0,0 +1,41 @@ +import("//extensions/buildflags/buildflags.gni") +import("//tools/json_schema_compiler/json_features.gni") +import("//tools/json_schema_compiler/json_schema_api.gni") +import("//qtwebengine/common/extensions/api/schema.gni") + +assert(enable_extensions) + +################################################################################ +# Public Targets + +group("api") { + public_deps = [ + ":generated_api_json_strings", + ":generated_api_types", + ] +} + +################################################################################ +# Private Targets + +generated_json_strings("generated_api_json_strings") { + sources = webengine_extensions_api_schema_files + + bundle_name = "QtWebEngine" + root_namespace = webengine_extensions_api_root_namespace + + deps = [ "//extensions/common/api" ] + + visibility = [ ":api" ] +} + +generated_types("generated_api_types") { + sources = webengine_extensions_api_schema_files + + root_namespace = webengine_extensions_api_root_namespace + + deps = [ "//extensions/common/api" ] + + visibility = [ ":api" ] +} + diff --git a/chromium/qtwebengine/common/extensions/api/schema.gni b/chromium/qtwebengine/common/extensions/api/schema.gni new file mode 100644 index 00000000000..95a335c591a --- /dev/null +++ b/chromium/qtwebengine/common/extensions/api/schema.gni @@ -0,0 +1,9 @@ +webengine_extensions_api_schema_files_ = [ + "webrtc_desktop_capture_private.idl", +] + +webengine_extensions_api_schema_files = + get_path_info(webengine_extensions_api_schema_files_, "abspath") + +webengine_extensions_api_root_namespace = "extensions::api::%(namespace)s" + diff --git a/chromium/qtwebengine/common/extensions/api/webrtc_desktop_capture_private.idl b/chromium/qtwebengine/common/extensions/api/webrtc_desktop_capture_private.idl new file mode 100644 index 00000000000..644bb2125ed --- /dev/null +++ b/chromium/qtwebengine/common/extensions/api/webrtc_desktop_capture_private.idl @@ -0,0 +1,28 @@ +// based on //chrome/common/extensions/api/webrtc_desktop_capture_private.idl +// 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. + +// Use the <code>chrome.webrtcDesktopCapturePrivate</code> API to capture +// desktop media requested from a WebView. +namespace webrtcDesktopCapturePrivate { + dictionary RequestInfo { + // The guest process id for the requester. + long guestProcessId; + + // The webview render frame id for the requester. + long guestRenderFrameId; + }; + + dictionary Options { + boolean canRequestAudioTrack; + }; + + callback chooseDesktopMediaCallback = void (DOMString streamId, Options options); + + interface Functions { + // Selects primary screen for share explicitly. + static long chooseDesktopMedia(RequestInfo request, + chooseDesktopMediaCallback callback); + }; +}; |