shimless_rma: Allow media requests
Allow requests for media devices such as camera and microphone. The implementation is the same as in the browser. BUG: b:316272719, b:317466651 TEST: test on local device Change-Id: I1baa64172afd422647fe44ae467050674d8e9016 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5239831 Reviewed-by: Chung-sheng Wu <chungsheng@google.com> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Reviewed-by: Ravjit Uppal <ravjit@chromium.org> Commit-Queue: Ethan Cheng <yycheng@google.com> Reviewed-by: Gavin Williams <gavinwill@chromium.org> Cr-Commit-Position: refs/heads/main@{#1291066}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
2e7840aebd
commit
dcf3dcdeb0
@ -12,11 +12,13 @@ include_rules = [
|
||||
"+ui/chromeos/strings",
|
||||
"+components/onc/onc_constants.h",
|
||||
"+components/onc/onc_pref_names.h",
|
||||
"+components/permissions/permission_request_manager.h",
|
||||
"+components/proxy_config/pref_proxy_config_tracker_impl.h",
|
||||
"+components/proxy_config/proxy_config_pref_names.h",
|
||||
"+components/qr_code_generator/qr_code_generator.h",
|
||||
"+components/sync_preferences/testing_pref_service_syncable.h",
|
||||
"+components/web_package/signed_web_bundles",
|
||||
"+third_party/blink/public/mojom/mediastream",
|
||||
]
|
||||
|
||||
specific_include_rules = {
|
||||
|
@ -37,6 +37,7 @@ static_library("backend") {
|
||||
"//chromeos/dbus/power",
|
||||
"//chromeos/services/network_config/public/mojom",
|
||||
"//chromeos/version",
|
||||
"//components/permissions:permissions",
|
||||
"//components/qr_code_generator",
|
||||
"//content/public/browser",
|
||||
"//ui/display",
|
||||
|
@ -15,8 +15,10 @@
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "components/permissions/permission_request_manager.h"
|
||||
#include "content/public/browser/console_message.h"
|
||||
#include "content/public/browser/file_select_listener.h"
|
||||
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
|
||||
#include "ui/base/ui_base_types.h"
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/display/screen.h"
|
||||
@ -153,6 +155,8 @@ ExternalAppDialog::ExternalAppDialog(const InitParams& params)
|
||||
CHECK_EQ(g_instance, nullptr);
|
||||
g_instance = this;
|
||||
|
||||
shimless_rma_delegate_ = params.shimless_rma_delegate;
|
||||
|
||||
set_can_close(true);
|
||||
set_can_resize(false);
|
||||
set_center_dialog_title_text(true);
|
||||
@ -188,7 +192,29 @@ void ExternalAppDialog::GetDialogSize(gfx::Size* size) const {
|
||||
}
|
||||
|
||||
void ExternalAppDialog::OnLoadingStateChanged(content::WebContents* source) {
|
||||
if (has_web_content_setup_) {
|
||||
return;
|
||||
}
|
||||
|
||||
permissions::PermissionRequestManager::CreateForWebContents(source);
|
||||
content::WebContentsObserver::Observe(source);
|
||||
has_web_content_setup_ = true;
|
||||
}
|
||||
|
||||
void ExternalAppDialog::RequestMediaAccessPermission(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
content::MediaResponseCallback callback) {
|
||||
if (!shimless_rma_delegate_) {
|
||||
LOG(WARNING) << "Invalid Shimless RMA Delegate";
|
||||
std::move(callback).Run(
|
||||
blink::mojom::StreamDevicesSet(),
|
||||
blink::mojom::MediaStreamRequestResult::NOT_SUPPORTED,
|
||||
/*ui=*/nullptr);
|
||||
return;
|
||||
}
|
||||
shimless_rma_delegate_->ProcessMediaAccessRequest(
|
||||
web_contents, request, std::move(callback), /*extension=*/nullptr);
|
||||
}
|
||||
|
||||
void ExternalAppDialog::OnDidAddMessageToConsole(
|
||||
|
@ -7,9 +7,11 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ash/webui/shimless_rma/backend/shimless_rma_delegate.h"
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "ui/web_dialogs/web_dialog_delegate.h"
|
||||
#include "url/gurl.h"
|
||||
@ -51,6 +53,8 @@ class ExternalAppDialog : public ui::WebDialogDelegate,
|
||||
GURL content_url;
|
||||
// Callback for handling the console log from the app.
|
||||
ConsoleLogCallback on_console_log;
|
||||
// The shimless RMA delegate for accessing //chrome functions.
|
||||
base::WeakPtr<ShimlessRmaDelegate> shimless_rma_delegate;
|
||||
};
|
||||
|
||||
// Shows the dialog. Shouldn't be called if last dialog opened by this
|
||||
@ -79,6 +83,10 @@ class ExternalAppDialog : public ui::WebDialogDelegate,
|
||||
// ui::WebDialogDelegate overrides:
|
||||
void GetDialogSize(gfx::Size* size) const override;
|
||||
void OnLoadingStateChanged(content::WebContents* source) override;
|
||||
void RequestMediaAccessPermission(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
content::MediaResponseCallback callback) override;
|
||||
|
||||
// content::WebContentsObserver overrides:
|
||||
void OnDidAddMessageToConsole(
|
||||
@ -89,10 +97,14 @@ class ExternalAppDialog : public ui::WebDialogDelegate,
|
||||
const std::u16string& source_id,
|
||||
const std::optional<std::u16string>& untrusted_stack_trace) override;
|
||||
|
||||
// Set to true once setup for webcontent is initialized.
|
||||
bool has_web_content_setup_ = false;
|
||||
// views::WebDialogView that owns this delegate.
|
||||
raw_ptr<views::WebDialogView> web_dialog_view_;
|
||||
// views::Widget that owns this delegate.
|
||||
raw_ptr<views::Widget> widget_;
|
||||
// Delegate for accessing //chrome.
|
||||
base::WeakPtr<ShimlessRmaDelegate> shimless_rma_delegate_;
|
||||
// Callback for handling the console log from the app.
|
||||
ConsoleLogCallback on_console_log_;
|
||||
};
|
||||
|
@ -36,4 +36,8 @@ bool FakeShimlessRmaDelegate::IsChromeOSSystemExtensionProvider(
|
||||
return is_chromeos_system_extension_provider_;
|
||||
}
|
||||
|
||||
base::WeakPtr<ShimlessRmaDelegate> FakeShimlessRmaDelegate::GetWeakPtr() {
|
||||
return weak_ptr_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
} // namespace ash::shimless_rma
|
||||
|
@ -11,6 +11,10 @@
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/types/expected.h"
|
||||
|
||||
namespace extensions {
|
||||
class Extension;
|
||||
}
|
||||
|
||||
namespace ash::shimless_rma {
|
||||
|
||||
class FakeShimlessRmaDelegate : public ShimlessRmaDelegate {
|
||||
@ -32,6 +36,12 @@ class FakeShimlessRmaDelegate : public ShimlessRmaDelegate {
|
||||
PrepareDiagnosticsAppBrowserContextCallback callback) override;
|
||||
bool IsChromeOSSystemExtensionProvider(
|
||||
const std::string& manufacturer) override;
|
||||
void ProcessMediaAccessRequest(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
content::MediaResponseCallback callback,
|
||||
const extensions::Extension* extension) override {}
|
||||
base::WeakPtr<ShimlessRmaDelegate> GetWeakPtr() override;
|
||||
|
||||
void set_is_chromeos_system_extension_provider(bool value) {
|
||||
is_chromeos_system_extension_provider_ = value;
|
||||
@ -52,6 +62,8 @@ class FakeShimlessRmaDelegate : public ShimlessRmaDelegate {
|
||||
base::FilePath last_load_swbn_path_;
|
||||
base::expected<PrepareDiagnosticsAppBrowserContextResult, std::string>
|
||||
prepare_diagnostics_app_result_{base::unexpected("Error")};
|
||||
|
||||
base::WeakPtrFactory<FakeShimlessRmaDelegate> weak_ptr_factory_{this};
|
||||
};
|
||||
|
||||
} // namespace ash::shimless_rma
|
||||
|
@ -11,13 +11,20 @@
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/types/expected.h"
|
||||
#include "components/web_package/signed_web_bundles/signed_web_bundle_id.h"
|
||||
#include "content/public/browser/media_stream_request.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
}
|
||||
|
||||
namespace extensions {
|
||||
class Extension;
|
||||
}
|
||||
|
||||
namespace ash::shimless_rma {
|
||||
|
||||
// A delegate which exposes browser functionality from //chrome to the Shimless
|
||||
@ -79,6 +86,17 @@ class ShimlessRmaDelegate {
|
||||
// Check if `manufacturer` provides any chromeos system extension.
|
||||
virtual bool IsChromeOSSystemExtensionProvider(
|
||||
const std::string& manufacturer) = 0;
|
||||
|
||||
// Request for media device access. `extension` is set to NULL if request was
|
||||
// made from a webpage.
|
||||
virtual void ProcessMediaAccessRequest(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
content::MediaResponseCallback callback,
|
||||
const extensions::Extension* extension) = 0;
|
||||
|
||||
// Gets a weak ptr reference to this object.
|
||||
virtual base::WeakPtr<ShimlessRmaDelegate> GetWeakPtr() = 0;
|
||||
};
|
||||
|
||||
} // namespace ash::shimless_rma
|
||||
|
@ -1633,6 +1633,7 @@ void ShimlessRmaService::Show3pDiagnosticsApp(
|
||||
params.context = shimless_app_browser_context_;
|
||||
params.app_name = shimless_3p_diag_app_name_;
|
||||
params.content_url = GURL("isolated-app://" + shimless_3p_diag_iwa_id_->id());
|
||||
params.shimless_rma_delegate = shimless_rma_delegate_->GetWeakPtr();
|
||||
ExternalAppDialog::Show(params);
|
||||
std::move(callback).Run(
|
||||
ash::shimless_rma::mojom::Show3pDiagnosticsAppResult::kOk);
|
||||
|
@ -23,6 +23,7 @@ include_rules = [
|
||||
"+chrome/browser/extensions/extension_service.h",
|
||||
"+chrome/browser/extensions/extension_service_test_base.h",
|
||||
"+chrome/browser/extensions/test_extension_system.h",
|
||||
"+chrome/browser/media/webrtc/media_capture_devices_dispatcher.h",
|
||||
"+chrome/browser/profiles",
|
||||
"+chrome/browser/ui/webui/ash",
|
||||
"+chrome/browser/web_applications/isolated_web_apps",
|
||||
|
@ -21,10 +21,12 @@
|
||||
#include "chrome/browser/ash/login/chrome_restart_request.h"
|
||||
#include "chrome/browser/ash/shimless_rma/diagnostics_app_profile_helper.h"
|
||||
#include "chrome/browser/ash/system/device_disabling_manager.h"
|
||||
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
|
||||
#include "chrome/browser/ui/webui/ash/diagnostics_dialog.h"
|
||||
#include "chrome/common/chromeos/extensions/chromeos_system_extension_info.h"
|
||||
#include "components/qr_code_generator/bitmap_generator.h"
|
||||
#include "content/public/browser/web_ui.h"
|
||||
#include "extensions/common/extension.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/codec/png_codec.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
@ -104,6 +106,19 @@ bool ChromeShimlessRmaDelegate::IsChromeOSSystemExtensionProvider(
|
||||
return chromeos::IsChromeOSSystemExtensionProvider(manufacturer);
|
||||
}
|
||||
|
||||
void ChromeShimlessRmaDelegate::ProcessMediaAccessRequest(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
content::MediaResponseCallback callback,
|
||||
const extensions::Extension* extension) {
|
||||
MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
|
||||
web_contents, request, std::move(callback), extension);
|
||||
}
|
||||
|
||||
base::WeakPtr<ShimlessRmaDelegate> ChromeShimlessRmaDelegate::GetWeakPtr() {
|
||||
return weak_ptr_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
void ChromeShimlessRmaDelegate::
|
||||
SetDiagnosticsAppProfileHelperDelegateForTesting(
|
||||
DiagnosticsAppProfileHelperDelegate* delegate) {
|
||||
|
@ -17,6 +17,10 @@ namespace content {
|
||||
class WebUI;
|
||||
} // namespace content
|
||||
|
||||
namespace extensions {
|
||||
class Extension;
|
||||
} // namespace extensions
|
||||
|
||||
namespace ash::shimless_rma {
|
||||
|
||||
class ChromeShimlessRmaDelegate : public ShimlessRmaDelegate {
|
||||
@ -42,6 +46,12 @@ class ChromeShimlessRmaDelegate : public ShimlessRmaDelegate {
|
||||
PrepareDiagnosticsAppBrowserContextCallback callback) override;
|
||||
bool IsChromeOSSystemExtensionProvider(
|
||||
const std::string& manufacturer) override;
|
||||
void ProcessMediaAccessRequest(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
content::MediaResponseCallback callback,
|
||||
const extensions::Extension* extension) override;
|
||||
base::WeakPtr<ShimlessRmaDelegate> GetWeakPtr() override;
|
||||
|
||||
void SetDiagnosticsAppProfileHelperDelegateForTesting(
|
||||
DiagnosticsAppProfileHelperDelegate* delegate);
|
||||
|
@ -285,10 +285,6 @@ TEST_F(ChromeShimlessRmaDelegatePrepareDiagnosticsAppProfileTest, Success) {
|
||||
EXPECT_TRUE(
|
||||
DiagnosticsAppProfileHelperDelegate::GetInstalledDiagnosticsAppOrigin()
|
||||
.has_value());
|
||||
EXPECT_TRUE(
|
||||
DiagnosticsAppProfileHelperDelegate::GetInstalledDiagnosticsAppOrigin()
|
||||
.value()
|
||||
.IsSameOriginWith(expected_url_origin));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user