Skip to content

Commit

Permalink
SmartCard: ChromeOsSmartCardDelegate
Browse files Browse the repository at this point in the history
Provide a SmartCardDelegate implementation on ChromeOS

On ChromeOS, smart cards are provided by an extension,
via the chrome.smartCardProviderPrivate extension API.

go/web-smart-card-hld

Low-Coverage-Reason: There are tests for the part above SmartCardDelegate (SmartCardService, SmartCardReaderTracker, Web API) and the part below it (SmartCardProviderPrivateApi). This CL connects parts together.

Bug: 1386175
Change-Id: I439a45019ce10402e66e6926037668c05ebc0e94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4353054
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Daniel d'Andrada <dandrader@google.com>
Cr-Commit-Position: refs/heads/main@{#1122444}
  • Loading branch information
dandrader authored and Chromium LUCI CQ committed Mar 27, 2023
1 parent e4aa717 commit 6ac3d85
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions chrome/browser/BUILD.gn
Expand Up @@ -4361,6 +4361,7 @@ static_library("browser") {
"//chrome/browser/resource_coordinator:intervention_policy_database_proto",
"//chrome/browser/resources:component_extension_resources",
"//chrome/browser/share/proto:proto",
"//chrome/browser/smart_card",
"//chrome/browser/support_tool:support_tool_proto",
"//chrome/browser/ui/color:color_headers",
"//chrome/browser/ui/webui/access_code_cast:mojo_bindings",
Expand Down
11 changes: 11 additions & 0 deletions chrome/browser/chrome_content_browser_client.cc
Expand Up @@ -466,6 +466,7 @@
#include "chrome/browser/chromeos/tablet_mode/chrome_content_browser_client_tablet_mode_part.h"
#include "chrome/browser/policy/networking/policy_cert_service.h"
#include "chrome/browser/policy/networking/policy_cert_service_factory.h"
#include "chrome/browser/smart_card/chromeos_smart_card_delegate.h"
#include "chrome/common/chromeos/extensions/chromeos_system_extension_info.h"
#include "components/crash/core/app/breakpad_linux.h"
#include "third_party/cros_system_api/switches/chrome_switches.h"
Expand Down Expand Up @@ -6569,6 +6570,16 @@ bool ChromeContentBrowserClient::HandleWebUI(
return true;
}

#if BUILDFLAG(IS_CHROMEOS)
content::SmartCardDelegate* ChromeContentBrowserClient::GetSmartCardDelegate(
content::BrowserContext* browser_context) {
if (!smart_card_delegate_) {
smart_card_delegate_ = std::make_unique<ChromeOsSmartCardDelegate>();
}
return smart_card_delegate_.get();
}
#endif

bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
content::BrowserContext* browser_context,
const GURL& url,
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/chrome_content_browser_client.h
Expand Up @@ -646,6 +646,10 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
std::unique_ptr<content::AuthenticatorRequestClientDelegate>
GetWebAuthenticationRequestDelegate(
content::RenderFrameHost* render_frame_host) override;
#endif
#if BUILDFLAG(IS_CHROMEOS)
content::SmartCardDelegate* GetSmartCardDelegate(
content::BrowserContext* browser_context) override;
#endif
bool ShowPaymentHandlerWindow(
content::BrowserContext* browser_context,
Expand Down Expand Up @@ -979,6 +983,10 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
std::unique_ptr<permissions::BluetoothDelegateImpl> bluetooth_delegate_;
std::unique_ptr<ChromeUsbDelegate> usb_delegate_;

#if BUILDFLAG(IS_CHROMEOS)
std::unique_ptr<content::SmartCardDelegate> smart_card_delegate_;
#endif

#if BUILDFLAG(ENABLE_VR)
std::unique_ptr<vr::ChromeXrIntegrationClient> xr_integration_client_;
#endif
Expand Down
Expand Up @@ -298,6 +298,14 @@ SmartCardProviderPrivateAPI::SmartCardProviderPrivateAPI(

SmartCardProviderPrivateAPI::~SmartCardProviderPrivateAPI() = default;

mojo::PendingRemote<device::mojom::SmartCardContextFactory>
SmartCardProviderPrivateAPI::GetSmartCardContextFactory() {
mojo::PendingRemote<device::mojom::SmartCardContextFactory> pending_remote;
context_factory_receivers_.Add(
this, pending_remote.InitWithNewPipeAndPassReceiver());
return pending_remote;
}

void SmartCardProviderPrivateAPI::CreateContext(
CreateContextCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Expand Down
Expand Up @@ -12,6 +12,7 @@
#include "base/types/id_type.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/device/public/mojom/smart_card.mojom.h"
Expand Down Expand Up @@ -49,6 +50,9 @@ class SmartCardProviderPrivateAPI

~SmartCardProviderPrivateAPI() override;

mojo::PendingRemote<device::mojom::SmartCardContextFactory>
GetSmartCardContextFactory();

// device::mojom::SmartCardContextFactory overrides:
void CreateContext(CreateContextCallback) override;

Expand Down Expand Up @@ -174,6 +178,9 @@ class SmartCardProviderPrivateAPI
const raw_ref<content::BrowserContext> browser_context_;
const raw_ref<EventRouter> event_router_;

mojo::ReceiverSet<device::mojom::SmartCardContextFactory>
context_factory_receivers_;

mojo::ReceiverSet<device::mojom::SmartCardContext, ContextId>
context_receivers_;

Expand Down
17 changes: 17 additions & 0 deletions chrome/browser/smart_card/BUILD.gn
@@ -0,0 +1,17 @@
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("smart_card") {
if (is_chromeos) {
sources = [
"chromeos_smart_card_delegate.cc",
"chromeos_smart_card_delegate.h",
]
deps = [
"//chrome/browser/chromeos/extensions/smart_card_provider_private",
"//content/public/browser:browser",
]
}
# TODO(crbug.com/1386175): Add chrome_smart_card_delegate.* for Win/Mac/Linux
}
11 changes: 11 additions & 0 deletions chrome/browser/smart_card/DIR_METADATA
@@ -0,0 +1,11 @@
# Metadata information for this directory.
#
# For more information on DIR_METADATA files, see:
# https://source.chromium.org/chromium/infra/infra/+/main:go/src/infra/tools/dirmd/README.md
#
# For the schema of this file, see Metadata message:
# https://source.chromium.org/chromium/infra/infra/+/main:go/src/infra/tools/dirmd/proto/dir_metadata.proto

monorail {
component: "Blink>SmartCard"
}
1 change: 1 addition & 0 deletions chrome/browser/smart_card/OWNERS
@@ -0,0 +1 @@
file://third_party/blink/renderer/modules/smart_card/OWNERS
20 changes: 20 additions & 0 deletions chrome/browser/smart_card/chromeos_smart_card_delegate.cc
@@ -0,0 +1,20 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/smart_card/chromeos_smart_card_delegate.h"
#include "chrome/browser/chromeos/extensions/smart_card_provider_private/smart_card_provider_private_api.h"

ChromeOsSmartCardDelegate::ChromeOsSmartCardDelegate() = default;

mojo::PendingRemote<device::mojom::SmartCardContextFactory>
ChromeOsSmartCardDelegate::GetSmartCardContextFactory(
content::BrowserContext& browser_context) {
return extensions::SmartCardProviderPrivateAPI::Get(browser_context)
.GetSmartCardContextFactory();
}

bool ChromeOsSmartCardDelegate::SupportsReaderAddedRemovedNotifications()
const {
return true;
}
20 changes: 20 additions & 0 deletions chrome/browser/smart_card/chromeos_smart_card_delegate.h
@@ -0,0 +1,20 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SMART_CARD_CHROMEOS_SMART_CARD_DELEGATE_H_
#define CHROME_BROWSER_SMART_CARD_CHROMEOS_SMART_CARD_DELEGATE_H_

#include "content/public/browser/smart_card_delegate.h"

class ChromeOsSmartCardDelegate : public content::SmartCardDelegate {
public:
ChromeOsSmartCardDelegate();

// `content::SmartCardDelegate` overrides:
mojo::PendingRemote<device::mojom::SmartCardContextFactory>
GetSmartCardContextFactory(content::BrowserContext& browser_context) override;
bool SupportsReaderAddedRemovedNotifications() const override;
};

#endif // CHROME_BROWSER_SMART_CARD_CHROMEOS_SMART_CARD_DELEGATE_H_

0 comments on commit 6ac3d85

Please sign in to comment.