X Tutup
Skip to content

Commit 8007d01

Browse files
feat: add support for the U2F Web API (electron#30438)
* feat: add support for the U2F Web API * chore: fix lint * chore: fix tests * build: disable src caching * Revert "build: disable src caching" This reverts commit c4c8a60. * chore: update per feedback * chore: consistent code removal
1 parent c2da4ec commit 8007d01

17 files changed

+579
-3
lines changed

electron_resources.grd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<includes>
2020
<include name="IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE" file="${target_gen_dir}/shell_devtools_discovery_page.html" use_base_dir="false" type="BINDATA" />
2121
<include name="IDR_PDF_MANIFEST" file="../chrome/browser/resources/pdf/manifest.json" type="BINDATA" />
22+
<include name="IDR_CRYPTOTOKEN_MANIFEST" file="../chrome/browser/resources/cryptotoken/manifest.json" type="BINDATA" />
2223
</includes>
2324
</release>
2425
</grit>

filenames.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ filenames = {
677677
lib_sources_extensions = [
678678
"shell/browser/extensions/api/i18n/i18n_api.cc",
679679
"shell/browser/extensions/api/i18n/i18n_api.h",
680+
"shell/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc",
681+
"shell/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.h",
680682
"shell/browser/extensions/api/management/electron_management_api_delegate.cc",
681683
"shell/browser/extensions/api/management/electron_management_api_delegate.h",
682684
"shell/browser/extensions/api/resources_private/resources_private_api.cc",

patches/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ disable_use_lld_for_macos.patch
107107
fix_media_key_usage_with_globalshortcuts.patch
108108
feat_expose_raw_response_headers_from_urlloader.patch
109109
revert_roll_clang_llvmorg-14-init-1002-gb5e470aa-1.patch
110+
chore_do_not_use_chrome_windows_in_cryptotoken_webrequestsender.patch
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Samuel Attard <samuel.r.attard@gmail.com>
3+
Date: Fri, 6 Aug 2021 03:36:57 -0700
4+
Subject: chore: do not use chrome.windows in cryptotoken webrequestsender
5+
6+
Electron does not support chrome.windows which this method depends on. It also does not need to, the method's goal is to determine if the webContents that triggered the cryptotoken request is still "active". In Chrome this means active tab in the tab strip === this tab + the window owning that tab strip is focused.
7+
8+
In Electron that can be simplified to webContents.isFocused() which maps to "is the webContents view focused and is the owning window the key window". We map tab.active to that IsFocused() value and we can remove the chrome.windows logic here.
9+
10+
This can't be upstreamed but the patch is minimal.
11+
12+
diff --git a/chrome/browser/resources/cryptotoken/webrequestsender.js b/chrome/browser/resources/cryptotoken/webrequestsender.js
13+
index 734abbbf3132d245c2c39bbe9b7780acbea196b0..adff416286eaa10a099be83aaf07e56ec323fe3d 100644
14+
--- a/chrome/browser/resources/cryptotoken/webrequestsender.js
15+
+++ b/chrome/browser/resources/cryptotoken/webrequestsender.js
16+
@@ -134,10 +134,11 @@ function tabInForeground(tabId) {
17+
reject();
18+
return;
19+
}
20+
- if (!chrome.windows || !chrome.windows.get) {
21+
- reject();
22+
- return;
23+
- }
24+
+ // Electron does not support chrome.windows
25+
+ // if (!chrome.windows || !chrome.windows.get) {
26+
+ // reject();
27+
+ // return;
28+
+ // }
29+
chrome.tabs.get(tabId, function(tab) {
30+
if (chrome.runtime.lastError) {
31+
resolve(false);
32+
@@ -147,9 +148,13 @@ function tabInForeground(tabId) {
33+
resolve(false);
34+
return;
35+
}
36+
- chrome.windows.get(tab.windowId, function(aWindow) {
37+
- resolve(aWindow && aWindow.focused);
38+
- });
39+
+ // tab.active in Electron maps to the "focused" state of the view
40+
+ // which is only true when both the webContents and the window are
41+
+ // focused.
42+
+ resolve(true);
43+
+ // chrome.windows.get(tab.windowId, function(aWindow) {
44+
+ // resolve(aWindow && aWindow.focused);
45+
+ // });
46+
});
47+
});
48+
}

shell/browser/electron_browser_client.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
#include "extensions/browser/api/mime_handler_private/mime_handler_private.h"
143143
#include "extensions/browser/api/web_request/web_request_api.h"
144144
#include "extensions/browser/browser_context_keyed_api_factory.h"
145+
#include "extensions/browser/event_router.h"
145146
#include "extensions/browser/extension_host.h"
146147
#include "extensions/browser/extension_message_filter.h"
147148
#include "extensions/browser/extension_navigation_throttle.h"
@@ -163,6 +164,7 @@
163164
#include "shell/browser/extensions/electron_extension_message_filter.h"
164165
#include "shell/browser/extensions/electron_extension_system.h"
165166
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
167+
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
166168
#endif
167169

168170
#if BUILDFLAG(ENABLE_PLUGINS)
@@ -1551,6 +1553,16 @@ void BindBeforeUnloadControl(
15511553
}
15521554
#endif
15531555

1556+
void ElectronBrowserClient::ExposeInterfacesToRenderer(
1557+
service_manager::BinderRegistry* registry,
1558+
blink::AssociatedInterfaceRegistry* associated_registry,
1559+
content::RenderProcessHost* render_process_host) {
1560+
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
1561+
associated_registry->AddInterface(base::BindRepeating(
1562+
&extensions::EventRouter::BindForRenderer, render_process_host->GetID()));
1563+
#endif
1564+
}
1565+
15541566
void ElectronBrowserClient::RegisterBrowserInterfaceBindersForFrame(
15551567
content::RenderFrameHost* render_frame_host,
15561568
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) {

shell/browser/electron_browser_client.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
6969
void BindHostReceiverForRenderer(
7070
content::RenderProcessHost* render_process_host,
7171
mojo::GenericPendingReceiver receiver) override;
72+
void ExposeInterfacesToRenderer(
73+
service_manager::BinderRegistry* registry,
74+
blink::AssociatedInterfaceRegistry* associated_registry,
75+
content::RenderProcessHost* render_process_host) override;
7276
void RegisterBrowserInterfaceBindersForFrame(
7377
content::RenderFrameHost* render_frame_host,
7478
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) override;

shell/browser/extensions/api/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ assert(enable_extensions,
1010

1111
function_registration("api_registration") {
1212
sources = [
13+
"//electron/shell/common/extensions/api/cryptotoken_private.idl",
1314
"//electron/shell/common/extensions/api/extension.json",
1415
"//electron/shell/common/extensions/api/i18n.json",
1516
"//electron/shell/common/extensions/api/resources_private.idl",

0 commit comments

Comments
 (0)
X Tutup