chore: bump chromium to 105.0.5129.0 (main) (#34403)

* chore: bump chromium in DEPS to 104.0.5096.0

* 3651284: Use the entry settings object for window.open navigation

3651284

* 3644598: Make RenderFrameHost used for notification permission decision

3644598

* 3642842: Window Placement: Prototype Fullscreen Capability Delegation - Part 2

3642842

* 3652785: [sandbox] Enable sandboxed pointers on sanitizer builds

3652785

* 3611967: webhid: Migrate HidDelegate to use BrowserContext and Origin

3611967

* 3665762: Remove RenderFrameHost::IsRenderFrameCreated from //content/.

3665762

* 3659375: Fold x509_util_ios and most of x509_util_mac into x509_util_apple

3659375

* 3656234: [CodeHealth] Remove uses of base::ListValue::Append() (Final, take 2)

3656234

* chore: update patch indices

* chore: fix lint

* 3644598: Make RenderFrameHost used for notification permission decision

3644598

* webhid: Migrate HidDelegate to use BrowserContext and Origin

This is a temporary fix for  3611967 to get the build compiling, but we need to either patch around  3611967 or move our device permissioning to BrowserContext

* chore: fix lint

* build: run electron/script/gen-libc++-filenames.js

fixes gn check

* chore: bump chromium in DEPS to 104.0.5098.0

* chore: disable flaking tests

* 3682394: Change pipes surrounding code references in comments to backticks

3682394

* 3652749: Delete GLRenderer and related classes

3652749

* chore: fixup patch indices

* 3671199: Remove ContentMainDelegate::PostFieldTrialInitialization

3671199

* 3607963: hid: Do not exclude HID device with no collections

3607963

* refactor: use ElectronBrowserContext instead of WebContents to persist devices

due to changes like 3611967,
we can no longer use WebContents to store device permissions so this commit
moves device permission storage to live in memory in ElectronBrowserContext
instead.

* 3557253: Deprecate some signature checks

3557253

* chore: bump chromium in DEPS to 104.0.5100.0

* 3680781: Add policy for Renderer App Container.

3680781

* chore: update patch indices

* 3675465: Update NetLog network service API to use mojom::DictionaryValue.

3675465

* chore: bump chromium in DEPS to 104.0.5102.0

* chore: update patches

* chore: bump chromium in DEPS to 104.0.5103.0

* chore: update patches

* chore: bump chromium in DEPS to 104.0.5104.0

* chore: update patches

* fix: add patch for DCHECK in fullscreen test

* build: fix nan build

* build: make the nan spec runner work on macOS

* chore: bump chromium in DEPS to 104.0.5106.0

* chore: update patches

* chore: bump chromium in DEPS to 104.0.5108.0

* chore: update patches

* chore: bump chromium in DEPS to 104.0.5110.0

* chore: update patches

* chore: bump chromium in DEPS to 104.0.5112.0

* chore: bump chromium in DEPS to 105.0.5113.0

* chore: bump chromium in DEPS to 105.0.5115.0

* chore: bump chromium in DEPS to 105.0.5117.0

* chore: update patches

* chore: update libcpp patch

* 3693745: Delete base::LowerCaseEqualsASCII()

Ref: 3693745

* 3669226: Remove printing PostTask usage of IO thread

Ref: 3669226

* 3687395: Remove DictionaryValue::HasKey().

Ref: 3687395

* 3691014: Prevent unsafe narrowing: ui/accessibility, part 2

Ref: 3691014

* 3560567: [MSC] Porting GenerateStreams clients to handle stream vectors.

Ref: 3560567

* 3684873: [Bluetooth][Win/Linux] Add bluetooth pair confirmation prompt

3684873

* chore: bump chromium in DEPS to 105.0.5119.0

* chore: missing includes in desktop_notification_controller

* chore: update patches

* 3685951: Reland "Make sure screen object is created once in tests."

3685951

* fixup: Reland "Make sure screen object is created once in tests."

* 3646014: [API] Deprecate LegacyOOMErrorCallback

Ref: 3646014

* chore: bump chromium in DEPS to 105.0.5121.0

* chore: update patches

* 3699085: [cleanup] update PrintBackend::EnumeratePrinters to use reference

Ref: 3699085

* chore: bump chromium in DEPS to 105.0.5123.0

* chore: update patches

* chore: bump chromium in DEPS to 105.0.5125.0

* chore: update patches

* 3630082: [sandbox] Also enable the sandbox outside of Chromium builds

Ref: 3630082

* chore: bump chromium in DEPS to 105.0.5127.0

* chore: update patches

* chore: bump chromium in DEPS to 105.0.5129.0

* chore: update patches

* 3703741: Remove WebContents::GetMainFrame.

3703741

* chore: update patches

* fixup! 3703741: Remove WebContents::GetMainFrame.

* fix lint

* more lint

* chore: document breaking change

* 3687671: [v8] Freeze flags after initialization

3687671

* fixup! 3560567: [MSC] Porting GenerateStreams clients to handle stream vectors.

* use the v8 allocator for node serdes

* chore: update patches

* remove faulty non-v8-sandbox-compatible code

* make NodeArrayBufferAllocator use the v8 allocator under the hood

* fixup! 3560567: [MSC] Porting GenerateStreams clients to handle stream vectors.

* fix build on windows

* 3691954: [Reland][Extensions Bindings] Validate arguments sent to API events

3691954

* chore: remove deprecated AccessorSignatures

https://github.com/nodejs/nan/pull/941

* Update patches/chromium/notification_provenance.patch

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* remove chore_expose_v8_initialization_isolate_callbacks.patch

* add link to nodejs/nan#941

* 52026: Do not allow md4 or md5 based signatures in X.509 certificates.

https://boringssl-review.googlesource.com/c/boringssl/+/52026

* chore: update patches

* disable nan buffer-test

* disable sandboxed pointers for now

* force sandboxed pointers off

* improve node allocation patch

* restore accidentally dropped node crypto test patch

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <sattard@salesforce.com>
Co-authored-by: Keeley Hammond <khammond@slack-corp.com>
Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
Co-authored-by: VerteDinde <vertedinde@electronjs.org>
Co-authored-by: Jeremy Rose <jeremya@chromium.org>
Co-authored-by: Jeremy Rose <japthorp@slack-corp.com>
This commit is contained in:
electron-roller[bot] 2022-06-27 15:50:08 -05:00 committed by GitHub
parent 032e1d9bef
commit e86d1cba75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
144 changed files with 1906 additions and 1231 deletions

View file

@ -460,8 +460,8 @@ ElectronMainDelegate::RunProcess(
return std::move(main_function_params);
}
bool ElectronMainDelegate::ShouldCreateFeatureList() {
return false;
bool ElectronMainDelegate::ShouldCreateFeatureList(InvokedIn invoked_in) {
return invoked_in == InvokedIn::kChildProcess;
}
bool ElectronMainDelegate::ShouldLockSchemeRegistry() {

View file

@ -43,7 +43,7 @@ class ElectronMainDelegate : public content::ContentMainDelegate {
absl::variant<int, content::MainFunctionParams> RunProcess(
const std::string& process_type,
content::MainFunctionParams main_function_params) override;
bool ShouldCreateFeatureList() override;
bool ShouldCreateFeatureList(InvokedIn invoked_in) override;
bool ShouldLockSchemeRegistry() override;
#if BUILDFLAG(IS_LINUX)
void ZygoteForked() override;

View file

@ -103,40 +103,20 @@ class DataPipeReader {
}
void OnSuccess() {
// Pass the buffer to JS.
//
// Note that the lifetime of the native buffer belongs to us, and we will
// free memory when JS buffer gets garbage collected.
// Copy the buffer to JS.
// TODO(nornagon): make this zero-copy by allocating the array buffer
// inside the sandbox
v8::HandleScope handle_scope(promise_.isolate());
#if defined(V8_SANDBOX)
v8::Local<v8::Value> buffer =
node::Buffer::Copy(promise_.isolate(), &buffer_.front(), buffer_.size())
.ToLocalChecked();
promise_.Resolve(buffer);
#else
v8::Local<v8::Value> buffer =
node::Buffer::New(promise_.isolate(), &buffer_.front(), buffer_.size(),
&DataPipeReader::FreeBuffer, this)
.ToLocalChecked();
promise_.Resolve(buffer);
#endif
// Destroy data pipe.
handle_watcher_.Cancel();
#if defined(V8_SANDBOX)
delete this;
#else
data_pipe_.reset();
data_pipe_getter_.reset();
#endif
}
#if !defined(V8_SANDBOX)
static void FreeBuffer(char* data, void* self) {
delete static_cast<DataPipeReader*>(self);
}
#endif
gin_helper::Promise<v8::Local<v8::Value>> promise_;
mojo::Remote<network::mojom::DataPipeGetter> data_pipe_getter_;

View file

@ -132,9 +132,8 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
auto command_line_string =
base::CommandLine::ForCurrentProcess()->GetCommandLineString();
auto channel_string = std::string("Electron " ELECTRON_VERSION);
base::Value custom_constants =
base::Value::FromUniquePtrValue(net_log::GetPlatformConstantsForNetLog(
command_line_string, channel_string));
base::Value::Dict custom_constants = net_log::GetPlatformConstantsForNetLog(
command_line_string, channel_string);
auto* network_context =
browser_context_->GetDefaultStoragePartition()->GetNetworkContext();
@ -156,7 +155,7 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
void NetLog::StartNetLogAfterCreateFile(net::NetLogCaptureMode capture_mode,
uint64_t max_file_size,
base::Value custom_constants,
base::Value::Dict custom_constants,
base::File output_file) {
if (!net_log_exporter_) {
// Theoretically the mojo pipe could have been closed by the time we get
@ -204,7 +203,7 @@ v8::Local<v8::Promise> NetLog::StopLogging(gin::Arguments* args) {
// pointer lives long enough to resolve the promise. Moving it into the
// callback will cause the instance variable to become empty.
net_log_exporter_->Stop(
base::Value(base::Value::Type::DICTIONARY),
base::Value::Dict(),
base::BindOnce(
[](mojo::Remote<network::mojom::NetLogExporter>,
gin_helper::Promise<void> promise, int32_t error) {

View file

@ -57,7 +57,7 @@ class NetLog : public gin::Wrappable<NetLog> {
void StartNetLogAfterCreateFile(net::NetLogCaptureMode capture_mode,
uint64_t max_file_size,
base::Value custom_constants,
base::Value::Dict custom_constants,
base::File output_file);
void NetLogStarted(int32_t error);

View file

@ -55,7 +55,7 @@ printing::PrinterList GetPrinterList(v8::Isolate* isolate) {
{
base::ThreadRestrictions::ScopedAllowIO allow_io;
printing::mojom::ResultCode code =
print_backend->EnumeratePrinters(&printers);
print_backend->EnumeratePrinters(printers);
if (code != printing::mojom::ResultCode::kSuccess)
LOG(INFO) << "Failed to enumerate printers";
}
@ -73,7 +73,7 @@ v8::Local<v8::Promise> GetPrinterListAsync(v8::Isolate* isolate) {
auto print_backend = printing::PrintBackend::CreateInstance(
g_browser_process->GetApplicationLocale());
printing::mojom::ResultCode code =
print_backend->EnumeratePrinters(&printers);
print_backend->EnumeratePrinters(printers);
if (code != printing::mojom::ResultCode::kSuccess)
LOG(INFO) << "Failed to enumerate printers";
return printers;

View file

@ -451,7 +451,7 @@ std::pair<std::string, std::u16string> GetDefaultPrinterAsync() {
// Check for existing printers and pick the first one should it exist.
if (printer_name.empty()) {
printing::PrinterList printers;
if (print_backend->EnumeratePrinters(&printers) !=
if (print_backend->EnumeratePrinters(printers) !=
printing::mojom::ResultCode::kSuccess)
return std::make_pair("Failed to enumerate printers", std::u16string());
if (!printers.empty())
@ -944,12 +944,6 @@ void WebContents::InitWithWebContents(
}
WebContents::~WebContents() {
// clear out objects that have been granted permissions so that when
// WebContents::RenderFrameDeleted is called as a result of WebContents
// destruction it doesn't try to clear out a granted_devices_
// on a destructed object.
granted_devices_.clear();
if (!inspectable_web_contents_) {
WebContentsDestroyed();
return;
@ -1557,11 +1551,6 @@ void WebContents::RenderFrameDeleted(
// is swapped by content::RenderFrameHostManager.
//
// clear out objects that have been granted permissions
if (!granted_devices_.empty()) {
granted_devices_.erase(render_frame_host->GetFrameTreeNodeId());
}
// WebFrameMain::FromRenderFrameHost(rfh) will use the RFH's FrameTreeNode ID
// to find an existing instance of WebFrameMain. During a cross-origin
// navigation, the deleted RFH will be the old host which was swapped out. In
@ -1771,7 +1760,7 @@ void WebContents::Invoke(
void WebContents::OnFirstNonEmptyLayout(
content::RenderFrameHost* render_frame_host) {
if (render_frame_host == web_contents()->GetMainFrame()) {
if (render_frame_host == web_contents()->GetPrimaryMainFrame()) {
Emit("ready-to-show");
}
}
@ -2088,7 +2077,7 @@ bool WebContents::GetBackgroundThrottling() const {
void WebContents::SetBackgroundThrottling(bool allowed) {
background_throttling_ = allowed;
auto* rfh = web_contents()->GetMainFrame();
auto* rfh = web_contents()->GetPrimaryMainFrame();
if (!rfh)
return;
@ -2110,12 +2099,15 @@ void WebContents::SetBackgroundThrottling(bool allowed) {
}
int WebContents::GetProcessID() const {
return web_contents()->GetMainFrame()->GetProcess()->GetID();
return web_contents()->GetPrimaryMainFrame()->GetProcess()->GetID();
}
base::ProcessId WebContents::GetOSProcessID() const {
base::ProcessHandle process_handle =
web_contents()->GetMainFrame()->GetProcess()->GetProcess().Handle();
base::ProcessHandle process_handle = web_contents()
->GetPrimaryMainFrame()
->GetProcess()
->GetProcess()
.Handle();
return base::GetProcId(process_handle);
}
@ -2311,7 +2303,7 @@ void WebContents::SetWebRTCIPHandlingPolicy(
std::string WebContents::GetMediaSourceID(
content::WebContents* request_web_contents) {
auto* frame_host = web_contents()->GetMainFrame();
auto* frame_host = web_contents()->GetPrimaryMainFrame();
if (!frame_host)
return std::string();
@ -2321,7 +2313,7 @@ std::string WebContents::GetMediaSourceID(
content::WebContentsMediaCaptureId(frame_host->GetProcess()->GetID(),
frame_host->GetRoutingID()));
auto* request_frame_host = request_web_contents->GetMainFrame();
auto* request_frame_host = request_web_contents->GetPrimaryMainFrame();
if (!request_frame_host)
return std::string();
@ -2453,7 +2445,7 @@ void WebContents::EnableDeviceEmulation(
return;
DCHECK(web_contents());
auto* frame_host = web_contents()->GetMainFrame();
auto* frame_host = web_contents()->GetPrimaryMainFrame();
if (frame_host) {
auto* widget_host_impl = static_cast<content::RenderWidgetHostImpl*>(
frame_host->GetView()->GetRenderWidgetHost());
@ -2469,7 +2461,7 @@ void WebContents::DisableDeviceEmulation() {
return;
DCHECK(web_contents());
auto* frame_host = web_contents()->GetMainFrame();
auto* frame_host = web_contents()->GetPrimaryMainFrame();
if (frame_host) {
auto* widget_host_impl = static_cast<content::RenderWidgetHostImpl*>(
frame_host->GetView()->GetRenderWidgetHost());
@ -2632,7 +2624,7 @@ void WebContents::OnGetDefaultPrinter(
auto* focused_frame = web_contents()->GetFocusedFrame();
auto* rfh = focused_frame && focused_frame->HasSelection()
? focused_frame
: web_contents()->GetMainFrame();
: web_contents()->GetPrimaryMainFrame();
print_view_manager->PrintNow(rfh, silent, std::move(print_settings),
std::move(print_callback));
@ -2839,10 +2831,10 @@ v8::Local<v8::Promise> WebContents::PrintToPDF(const base::Value& settings) {
absl::variant<printing::mojom::PrintPagesParamsPtr, std::string>
print_pages_params = print_to_pdf::GetPrintPagesParams(
web_contents()->GetMainFrame()->GetLastCommittedURL(), landscape,
display_header_footer, print_background, scale, paper_width,
paper_height, margin_top, margin_bottom, margin_left, margin_right,
absl::make_optional(header_template),
web_contents()->GetPrimaryMainFrame()->GetLastCommittedURL(),
landscape, display_header_footer, print_background, scale,
paper_width, paper_height, margin_top, margin_bottom, margin_left,
margin_right, absl::make_optional(header_template),
absl::make_optional(footer_template), prefer_css_page_size);
if (absl::holds_alternative<std::string>(print_pages_params)) {
@ -2861,7 +2853,7 @@ v8::Local<v8::Promise> WebContents::PrintToPDF(const base::Value& settings) {
absl::get<printing::mojom::PrintPagesParamsPtr>(print_pages_params));
params->params->document_cookie = unique_id.value_or(0);
manager->PrintToPdf(web_contents()->GetMainFrame(), page_ranges,
manager->PrintToPdf(web_contents()->GetPrimaryMainFrame(), page_ranges,
std::move(params),
base::BindOnce(&WebContents::OnPDFCreated, GetWeakPtr(),
std::move(promise)));
@ -2993,7 +2985,7 @@ void WebContents::ShowDefinitionForSelection() {
}
void WebContents::CopyImageAt(int x, int y) {
auto* const host = web_contents()->GetMainFrame();
auto* const host = web_contents()->GetPrimaryMainFrame();
if (host)
host->CopyImageAt(x, y);
}
@ -3159,7 +3151,7 @@ v8::Local<v8::Promise> WebContents::CapturePage(gin::Arguments* args) {
// If the view's renderer is suspended this may fail on Windows/Linux -
// bail if so. See CopyFromSurface in
// content/public/browser/render_widget_host_view.h.
auto* rfh = web_contents()->GetMainFrame();
auto* rfh = web_contents()->GetPrimaryMainFrame();
if (rfh &&
rfh->GetVisibilityState() == blink::mojom::PageVisibilityState::kHidden) {
promise.Resolve(gfx::Image());
@ -3437,11 +3429,11 @@ v8::Local<v8::Value> WebContents::Debugger(v8::Isolate* isolate) {
}
content::RenderFrameHost* WebContents::MainFrame() {
return web_contents()->GetMainFrame();
return web_contents()->GetPrimaryMainFrame();
}
void WebContents::NotifyUserActivation() {
content::RenderFrameHost* frame = web_contents()->GetMainFrame();
content::RenderFrameHost* frame = web_contents()->GetPrimaryMainFrame();
if (frame)
frame->NotifyUserActivation(
blink::mojom::UserActivationNotificationType::kInteraction);
@ -3457,7 +3449,7 @@ v8::Local<v8::Promise> WebContents::GetProcessMemoryInfo(v8::Isolate* isolate) {
gin_helper::Promise<gin_helper::Dictionary> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
auto* frame_host = web_contents()->GetMainFrame();
auto* frame_host = web_contents()->GetPrimaryMainFrame();
if (!frame_host) {
promise.RejectWithErrorMessage("Failed to create memory dump");
return handle;
@ -3487,13 +3479,13 @@ v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
return handle;
}
auto* frame_host = web_contents()->GetMainFrame();
auto* frame_host = web_contents()->GetPrimaryMainFrame();
if (!frame_host) {
promise.RejectWithErrorMessage("takeHeapSnapshot failed");
return handle;
}
if (!frame_host->IsRenderFrameCreated()) {
if (!frame_host->IsRenderFrameLive()) {
promise.RejectWithErrorMessage("takeHeapSnapshot failed");
return handle;
}
@ -3521,132 +3513,6 @@ v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
return handle;
}
void WebContents::GrantDevicePermission(
const url::Origin& origin,
const base::Value* device,
blink::PermissionType permission_type,
content::RenderFrameHost* render_frame_host) {
granted_devices_[render_frame_host->GetFrameTreeNodeId()][permission_type]
[origin]
.push_back(
std::make_unique<base::Value>(device->Clone()));
}
void WebContents::RevokeDevicePermission(
const url::Origin& origin,
const base::Value* device,
blink::PermissionType permission_type,
content::RenderFrameHost* render_frame_host) {
const auto& devices_for_frame_host_it =
granted_devices_.find(render_frame_host->GetFrameTreeNodeId());
if (devices_for_frame_host_it == granted_devices_.end())
return;
const auto& current_devices_it =
devices_for_frame_host_it->second.find(permission_type);
if (current_devices_it == devices_for_frame_host_it->second.end())
return;
const auto& origin_devices_it = current_devices_it->second.find(origin);
if (origin_devices_it == current_devices_it->second.end())
return;
for (auto it = origin_devices_it->second.begin();
it != origin_devices_it->second.end();) {
if (DoesDeviceMatch(device, it->get(), permission_type)) {
it = origin_devices_it->second.erase(it);
} else {
++it;
}
}
}
bool WebContents::DoesDeviceMatch(const base::Value* device,
const base::Value* device_to_compare,
blink::PermissionType permission_type) {
if (permission_type ==
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::HID)) {
if (device->GetDict().FindInt(kHidVendorIdKey) !=
device_to_compare->GetDict().FindInt(kHidVendorIdKey) ||
device->GetDict().FindInt(kHidProductIdKey) !=
device_to_compare->GetDict().FindInt(kHidProductIdKey)) {
return false;
}
const auto* serial_number =
device_to_compare->GetDict().FindString(kHidSerialNumberKey);
const auto* device_serial_number =
device->GetDict().FindString(kHidSerialNumberKey);
if (serial_number && device_serial_number &&
*device_serial_number == *serial_number)
return true;
} else if (permission_type ==
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::SERIAL)) {
#if BUILDFLAG(IS_WIN)
const auto* instance_id =
device->GetDict().FindString(kDeviceInstanceIdKey);
const auto* port_instance_id =
device_to_compare->GetDict().FindString(kDeviceInstanceIdKey);
if (instance_id && port_instance_id && *instance_id == *port_instance_id)
return true;
#else
const auto* serial_number = device->GetDict().FindString(kSerialNumberKey);
const auto* port_serial_number =
device_to_compare->GetDict().FindString(kSerialNumberKey);
if (device->GetDict().FindInt(kVendorIdKey) !=
device_to_compare->GetDict().FindInt(kVendorIdKey) ||
device->GetDict().FindInt(kProductIdKey) !=
device_to_compare->GetDict().FindInt(kProductIdKey) ||
(serial_number && port_serial_number &&
*port_serial_number != *serial_number)) {
return false;
}
#if BUILDFLAG(IS_MAC)
const auto* usb_driver_key = device->GetDict().FindString(kUsbDriverKey);
const auto* port_usb_driver_key =
device_to_compare->GetDict().FindString(kUsbDriverKey);
if (usb_driver_key && port_usb_driver_key &&
*usb_driver_key != *port_usb_driver_key) {
return false;
}
#endif // BUILDFLAG(IS_MAC)
return true;
#endif // BUILDFLAG(IS_WIN)
}
return false;
}
bool WebContents::CheckDevicePermission(
const url::Origin& origin,
const base::Value* device,
blink::PermissionType permission_type,
content::RenderFrameHost* render_frame_host) {
const auto& devices_for_frame_host_it =
granted_devices_.find(render_frame_host->GetFrameTreeNodeId());
if (devices_for_frame_host_it == granted_devices_.end())
return false;
const auto& current_devices_it =
devices_for_frame_host_it->second.find(permission_type);
if (current_devices_it == devices_for_frame_host_it->second.end())
return false;
const auto& origin_devices_it = current_devices_it->second.find(origin);
if (origin_devices_it == current_devices_it->second.end())
return false;
for (const auto& device_to_compare : origin_devices_it->second) {
if (DoesDeviceMatch(device, device_to_compare.get(), permission_type))
return true;
}
return false;
}
void WebContents::UpdatePreferredSize(content::WebContents* web_contents,
const gfx::Size& pref_size) {
Emit("preferred-size-changed", pref_size);
@ -3784,7 +3650,8 @@ void WebContents::DevToolsRequestFileSystems() {
base::ListValue file_system_value;
for (const auto& file_system : file_systems)
file_system_value.Append(CreateFileSystemValue(file_system));
file_system_value.Append(
base::Value::FromUniquePtrValue(CreateFileSystemValue(file_system)));
inspectable_web_contents_->CallClientFunction(
"DevToolsAPI.fileSystemsLoaded", &file_system_value, nullptr, nullptr);
}

View file

@ -42,7 +42,6 @@
#include "shell/common/gin_helper/constructible.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/pinnable.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "ui/base/models/image_model.h"
#include "ui/gfx/image/image.h"
@ -95,11 +94,6 @@ class OffScreenWebContentsView;
namespace api {
using DevicePermissionMap = std::map<
int,
std::map<blink::PermissionType,
std::map<url::Origin, std::vector<std::unique_ptr<base::Value>>>>>;
// Wrapper around the content::WebContents.
class WebContents : public ExclusiveAccessContext,
public gin::Wrappable<WebContents>,
@ -438,28 +432,6 @@ class WebContents : public ExclusiveAccessContext,
void SetImageAnimationPolicy(const std::string& new_policy);
// Grants |origin| access to |device|.
// To be used in place of ObjectPermissionContextBase::GrantObjectPermission.
void GrantDevicePermission(const url::Origin& origin,
const base::Value* device,
blink::PermissionType permissionType,
content::RenderFrameHost* render_frame_host);
// Revokes |origin| access to |device|.
// To be used in place of ObjectPermissionContextBase::RevokeObjectPermission.
void RevokeDevicePermission(const url::Origin& origin,
const base::Value* device,
blink::PermissionType permission_type,
content::RenderFrameHost* render_frame_host);
// Returns the list of devices that |origin| has been granted permission to
// access. To be used in place of
// ObjectPermissionContextBase::GetGrantedObjects.
bool CheckDevicePermission(const url::Origin& origin,
const base::Value* device,
blink::PermissionType permissionType,
content::RenderFrameHost* render_frame_host);
// disable copy
WebContents(const WebContents&) = delete;
WebContents& operator=(const WebContents&) = delete;
@ -755,10 +727,6 @@ class WebContents : public ExclusiveAccessContext,
// Update the html fullscreen flag in both browser and renderer.
void UpdateHtmlApiFullscreen(bool fullscreen);
bool DoesDeviceMatch(const base::Value* device,
const base::Value* device_to_compare,
blink::PermissionType permission_type);
v8::Global<v8::Value> session_;
v8::Global<v8::Value> devtools_web_contents_;
v8::Global<v8::Value> debugger_;
@ -843,9 +811,6 @@ class WebContents : public ExclusiveAccessContext,
// Stores the frame thats currently in fullscreen, nullptr if there is none.
content::RenderFrameHost* fullscreen_frame_ = nullptr;
// In-memory cache that holds objects that have been granted permissions.
DevicePermissionMap granted_devices_;
base::WeakPtrFactory<WebContents> weak_factory_{this};
};

View file

@ -206,7 +206,7 @@ void WebFrameMain::MaybeSetupMojoConnection() {
// Wait for RenderFrame to be created in renderer before accessing remote.
if (pending_receiver_ && render_frame_ &&
render_frame_->IsRenderFrameCreated()) {
render_frame_->IsRenderFrameLive()) {
render_frame_->GetRemoteInterfaces()->GetInterface(
std::move(pending_receiver_));
}

View file

@ -49,13 +49,13 @@ void GPUInfoEnumerator::EndGPUDevice() {
auto& top_value = value_stack.top();
// GPUDevice can be more than one. So create a list of all.
// The first one is the active GPU device.
if (top_value->HasKey(kGPUDeviceKey)) {
if (top_value->FindKey(kGPUDeviceKey)) {
base::ListValue* list;
top_value->GetList(kGPUDeviceKey, &list);
list->Append(std::move(current));
list->Append(base::Value::FromUniquePtrValue(std::move(current)));
} else {
auto gpus = std::make_unique<base::ListValue>();
gpus->Append(std::move(current));
std::unique_ptr<base::ListValue> gpus(new base::ListValue());
gpus->Append(base::Value::FromUniquePtrValue(std::move(current)));
top_value->SetList(kGPUDeviceKey, std::move(gpus));
}
current = std::move(top_value);

View file

@ -138,4 +138,11 @@ ElectronBluetoothDelegate::GetPermittedDevices(
return permitted_devices;
}
void ElectronBluetoothDelegate::ShowDevicePairConfirmPrompt(
RenderFrameHost* frame,
const std::u16string& device_identifier,
PairConfirmCallback callback) {
NOTIMPLEMENTED();
}
} // namespace electron

View file

@ -55,6 +55,9 @@ class ElectronBluetoothDelegate : public content::BluetoothDelegate {
void ShowDeviceCredentialsPrompt(content::RenderFrameHost* frame,
const std::u16string& device_identifier,
CredentialsCallback callback) override;
void ShowDevicePairConfirmPrompt(content::RenderFrameHost* frame,
const std::u16string& device_identifier,
PairConfirmCallback callback) override;
blink::WebBluetoothDeviceId GetWebBluetoothDeviceId(
content::RenderFrameHost* frame,
const std::string& device_address) override;

View file

@ -46,12 +46,13 @@ void AutofillDriver::ShowAutofillPopup(
gfx::RectF popup_bounds(bounds);
content::RenderFrameHost* embedder_frame_host = nullptr;
if (embedder) {
auto* embedder_view = embedder->web_contents()->GetMainFrame()->GetView();
auto* view = web_contents->web_contents()->GetMainFrame()->GetView();
auto* embedder_view =
embedder->web_contents()->GetPrimaryMainFrame()->GetView();
auto* view = web_contents->web_contents()->GetPrimaryMainFrame()->GetView();
auto offset = view->GetViewBounds().origin() -
embedder_view->GetViewBounds().origin();
popup_bounds.Offset(offset);
embedder_frame_host = embedder->web_contents()->GetMainFrame();
embedder_frame_host = embedder->web_contents()->GetPrimaryMainFrame();
}
autofill_popup_->CreateView(render_frame_host_, embedder_frame_host, osr,

View file

@ -80,7 +80,7 @@ AutofillDriver* AutofillDriverFactory::DriverForFrame(
// 3. `SomeOtherWebContentsObserver::RenderFrameDeleted(render_frame_host)`
// calls `DriverForFrame(render_frame_host)`.
// 5. `render_frame_host->~RenderFrameHostImpl()` finishes.
if (render_frame_host->IsRenderFrameCreated()) {
if (render_frame_host->IsRenderFrameLive()) {
driver = std::make_unique<AutofillDriver>(render_frame_host);
DCHECK_EQ(driver_map_.find(render_frame_host)->second.get(),
driver.get());

View file

@ -1560,7 +1560,7 @@ void ElectronBrowserClient::
if (contents) {
auto* prefs = WebContentsPreferences::From(contents);
if (render_frame_host.GetFrameTreeNodeId() ==
contents->GetMainFrame()->GetFrameTreeNodeId() ||
contents->GetPrimaryMainFrame()->GetFrameTreeNodeId() ||
(prefs && prefs->AllowsNodeIntegrationInSubFrames())) {
associated_registry.AddInterface(base::BindRepeating(
[](content::RenderFrameHost* render_frame_host,

View file

@ -46,6 +46,7 @@
#include "shell/browser/protocol_registry.h"
#include "shell/browser/special_storage_policy.h"
#include "shell/browser/ui/inspectable_web_contents.h"
#include "shell/browser/web_contents_permission_helper.h"
#include "shell/browser/web_view_manager.h"
#include "shell/browser/zoom_level_delegate.h"
#include "shell/common/application_info.h"
@ -416,6 +417,115 @@ void ElectronBrowserContext::SetSSLConfigClient(
ssl_config_client_ = std::move(client);
}
void ElectronBrowserContext::GrantDevicePermission(
const url::Origin& origin,
const base::Value& device,
blink::PermissionType permission_type) {
granted_devices_[permission_type][origin].push_back(
std::make_unique<base::Value>(device.Clone()));
}
void ElectronBrowserContext::RevokeDevicePermission(
const url::Origin& origin,
const base::Value& device,
blink::PermissionType permission_type) {
const auto& current_devices_it = granted_devices_.find(permission_type);
if (current_devices_it == granted_devices_.end())
return;
const auto& origin_devices_it = current_devices_it->second.find(origin);
if (origin_devices_it == current_devices_it->second.end())
return;
for (auto it = origin_devices_it->second.begin();
it != origin_devices_it->second.end();) {
if (DoesDeviceMatch(device, it->get(), permission_type)) {
it = origin_devices_it->second.erase(it);
} else {
++it;
}
}
}
bool ElectronBrowserContext::DoesDeviceMatch(
const base::Value& device,
const base::Value* device_to_compare,
blink::PermissionType permission_type) {
if (permission_type ==
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::HID)) {
if (device.GetDict().FindInt(kHidVendorIdKey) !=
device_to_compare->GetDict().FindInt(kHidVendorIdKey) ||
device.GetDict().FindInt(kHidProductIdKey) !=
device_to_compare->GetDict().FindInt(kHidProductIdKey)) {
return false;
}
const auto* serial_number =
device_to_compare->GetDict().FindString(kHidSerialNumberKey);
const auto* device_serial_number =
device.GetDict().FindString(kHidSerialNumberKey);
if (serial_number && device_serial_number &&
*device_serial_number == *serial_number)
return true;
} else if (permission_type ==
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::SERIAL)) {
#if BUILDFLAG(IS_WIN)
const auto* instance_id = device.GetDict().FindString(kDeviceInstanceIdKey);
const auto* port_instance_id =
device_to_compare->GetDict().FindString(kDeviceInstanceIdKey);
if (instance_id && port_instance_id && *instance_id == *port_instance_id)
return true;
#else
const auto* serial_number = device.GetDict().FindString(kSerialNumberKey);
const auto* port_serial_number =
device_to_compare->GetDict().FindString(kSerialNumberKey);
if (device.GetDict().FindInt(kVendorIdKey) !=
device_to_compare->GetDict().FindInt(kVendorIdKey) ||
device.GetDict().FindInt(kProductIdKey) !=
device_to_compare->GetDict().FindInt(kProductIdKey) ||
(serial_number && port_serial_number &&
*port_serial_number != *serial_number)) {
return false;
}
#if BUILDFLAG(IS_MAC)
const auto* usb_driver_key = device.GetDict().FindString(kUsbDriverKey);
const auto* port_usb_driver_key =
device_to_compare->GetDict().FindString(kUsbDriverKey);
if (usb_driver_key && port_usb_driver_key &&
*usb_driver_key != *port_usb_driver_key) {
return false;
}
#endif // BUILDFLAG(IS_MAC)
return true;
#endif // BUILDFLAG(IS_WIN)
}
return false;
}
bool ElectronBrowserContext::CheckDevicePermission(
const url::Origin& origin,
const base::Value& device,
blink::PermissionType permission_type) {
const auto& current_devices_it = granted_devices_.find(permission_type);
if (current_devices_it == granted_devices_.end())
return false;
const auto& origin_devices_it = current_devices_it->second.find(origin);
if (origin_devices_it == current_devices_it->second.end())
return false;
for (const auto& device_to_compare : origin_devices_it->second) {
if (DoesDeviceMatch(device, device_to_compare.get(), permission_type))
return true;
}
return false;
}
// static
ElectronBrowserContext* ElectronBrowserContext::From(
const std::string& partition,

View file

@ -8,6 +8,7 @@
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "chrome/browser/predictors/preconnect_manager.h"
@ -18,6 +19,7 @@
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "shell/browser/media/media_device_id_salt.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
class PrefService;
class ValueMapPrefStore;
@ -38,6 +40,10 @@ class ElectronExtensionSystem;
namespace electron {
using DevicePermissionMap =
std::map<blink::PermissionType,
std::map<url::Origin, std::vector<std::unique_ptr<base::Value>>>>;
class ElectronBrowserContext;
class ElectronDownloadManagerDelegate;
class ElectronPermissionManager;
@ -149,6 +155,25 @@ class ElectronBrowserContext : public content::BrowserContext {
~ElectronBrowserContext() override;
// Grants |origin| access to |device|.
// To be used in place of ObjectPermissionContextBase::GrantObjectPermission.
void GrantDevicePermission(const url::Origin& origin,
const base::Value& device,
blink::PermissionType permissionType);
// Revokes |origin| access to |device|.
// To be used in place of ObjectPermissionContextBase::RevokeObjectPermission.
void RevokeDevicePermission(const url::Origin& origin,
const base::Value& device,
blink::PermissionType permission_type);
// Returns the list of devices that |origin| has been granted permission to
// access. To be used in place of
// ObjectPermissionContextBase::GetGrantedObjects.
bool CheckDevicePermission(const url::Origin& origin,
const base::Value& device,
blink::PermissionType permissionType);
private:
ElectronBrowserContext(const std::string& partition,
bool in_memory,
@ -157,6 +182,10 @@ class ElectronBrowserContext : public content::BrowserContext {
// Initialize pref registry.
void InitPrefs();
bool DoesDeviceMatch(const base::Value& device,
const base::Value* device_to_compare,
blink::PermissionType permission_type);
ValueMapPrefStore* in_memory_pref_store_ = nullptr;
std::unique_ptr<content::ResourceContext> resource_context_;
@ -188,6 +217,9 @@ class ElectronBrowserContext : public content::BrowserContext {
network::mojom::SSLConfigPtr ssl_config_;
mojo::Remote<network::mojom::SSLConfigClient> ssl_config_client_;
// In-memory cache that holds objects that have been granted permissions.
DevicePermissionMap granted_devices_;
base::WeakPtrFactory<ElectronBrowserContext> weak_factory_{this};
};

View file

@ -219,6 +219,9 @@ int ElectronBrowserMainParts::PreEarlyInitialization() {
#if BUILDFLAG(IS_LINUX)
ui::OzonePlatform::PreEarlyInitialization();
#endif
#if BUILDFLAG(IS_MAC)
screen_ = std::make_unique<display::ScopedNativeScreen>();
#endif
return GetExitCode();
}
@ -275,8 +278,9 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
int ElectronBrowserMainParts::PreCreateThreads() {
#if defined(USE_AURA)
screen_ = views::CreateDesktopScreen();
display::Screen::SetScreenInstance(screen_.get());
if (!display::Screen::GetScreen()) {
screen_ = views::CreateDesktopScreen();
}
#endif
if (!views::LayoutProvider::Get())

View file

@ -16,6 +16,7 @@
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/geolocation_control.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/display/screen.h"
#include "ui/views/layout/layout_provider.h"
class BrowserProcessImpl;
@ -169,6 +170,7 @@ class ElectronBrowserMainParts : public content::BrowserMainParts {
#if BUILDFLAG(IS_MAC)
std::unique_ptr<device::GeolocationManager> geolocation_manager_;
std::unique_ptr<display::ScopedNativeScreen> screen_;
#endif
static ElectronBrowserMainParts* self_;

View file

@ -14,7 +14,7 @@ ElectronPDFWebContentsHelperClient::~ElectronPDFWebContentsHelperClient() =
content::RenderFrameHost* ElectronPDFWebContentsHelperClient::FindPdfFrame(
content::WebContents* contents) {
content::RenderFrameHost* main_frame = contents->GetMainFrame();
content::RenderFrameHost* main_frame = contents->GetPrimaryMainFrame();
content::RenderFrameHost* pdf_frame =
pdf_frame_util::FindPdfChildFrame(main_frame);
return pdf_frame ? pdf_frame : main_frame;

View file

@ -307,25 +307,17 @@ bool ElectronPermissionManager::CheckPermissionWithDetails(
bool ElectronPermissionManager::CheckDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
api::WebContents* api_web_contents = api::WebContents::From(web_contents);
const base::Value& device,
ElectronBrowserContext* browser_context) const {
if (device_permission_handler_.is_null()) {
if (api_web_contents) {
return api_web_contents->CheckDevicePermission(origin, device, permission,
render_frame_host);
}
return false;
return browser_context->CheckDevicePermission(origin, device, permission);
} else {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Object> details = gin::DataObjectBuilder(isolate)
.Set("deviceType", permission)
.Set("origin", origin.Serialize())
.Set("device", device->Clone())
.Set("frame", render_frame_host)
.Set("device", device.Clone())
.Build();
return device_permission_handler_.Run(details);
}
@ -334,29 +326,19 @@ bool ElectronPermissionManager::CheckDevicePermission(
void ElectronPermissionManager::GrantDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const {
const base::Value& device,
ElectronBrowserContext* browser_context) const {
if (device_permission_handler_.is_null()) {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
api::WebContents* api_web_contents = api::WebContents::From(web_contents);
if (api_web_contents)
api_web_contents->GrantDevicePermission(origin, device, permission,
render_frame_host);
browser_context->GrantDevicePermission(origin, device, permission);
}
}
void ElectronPermissionManager::RevokeDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
api::WebContents* api_web_contents = api::WebContents::From(web_contents);
if (api_web_contents)
api_web_contents->RevokeDevicePermission(origin, device, permission,
render_frame_host);
const base::Value& device,
ElectronBrowserContext* browser_context) const {
browser_context->RevokeDevicePermission(origin, device, permission);
}
blink::mojom::PermissionStatus

View file

@ -12,6 +12,7 @@
#include "base/containers/id_map.h"
#include "content/public/browser/permission_controller_delegate.h"
#include "gin/dictionary.h"
#include "shell/browser/electron_browser_context.h"
namespace base {
class DictionaryValue;
@ -91,19 +92,18 @@ class ElectronPermissionManager : public content::PermissionControllerDelegate {
bool CheckDevicePermission(blink::PermissionType permission,
const url::Origin& origin,
const base::Value* object,
content::RenderFrameHost* render_frame_host) const;
const base::Value& object,
ElectronBrowserContext* browser_context) const;
void GrantDevicePermission(blink::PermissionType permission,
const url::Origin& origin,
const base::Value* object,
content::RenderFrameHost* render_frame_host) const;
const base::Value& object,
ElectronBrowserContext* browser_context) const;
void RevokeDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* object,
content::RenderFrameHost* render_frame_host) const;
void RevokeDevicePermission(blink::PermissionType permission,
const url::Origin& origin,
const base::Value& object,
ElectronBrowserContext* browser_context) const;
protected:
void OnPermissionResponse(int request_id,

View file

@ -255,18 +255,18 @@ CryptotokenPrivateCanAppIdGetAttestationFunction::Run() {
return RespondNow(Error("no PermissionRequestManager"));
// }
// // The created AttestationPermissionRequest deletes itself once complete.
// permission_request_manager->AddRequest(
// web_contents->GetMainFrame(), // Extension API targets a particular
// tab,
// // so select the current main frame to
// // handle the request.
// NewAttestationPermissionRequest(
// origin,
// base::BindOnce(
// &CryptotokenPrivateCanAppIdGetAttestationFunction::Complete,
// this)));
// return RespondLater();
#if 0 // TODO(MarshallOfSound): why is this commented out?
// The created AttestationPermissionRequest deletes itself once complete.
permission_request_manager->AddRequest(
web_contents->GetPrimaryMainFrame(),
tab,
NewAttestationPermissionRequest(
origin,
base::BindOnce(
&CryptotokenPrivateCanAppIdGetAttestationFunction::Complete,
this)));
return RespondLater();
#endif
#endif
}

View file

@ -15,6 +15,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "electron/shell/common/extensions/api/tabs.h"
#include "extensions/browser/api/messaging/extension_message_port.h"
#include "extensions/browser/api/messaging/native_message_host.h"
#include "extensions/browser/extension_api_frame_id_map.h"
@ -44,17 +45,13 @@ ElectronMessagingDelegate::MaybeGetTabInfo(content::WebContents* web_contents) {
if (web_contents) {
auto* api_contents = electron::api::WebContents::From(web_contents);
if (api_contents) {
auto tab = std::make_unique<base::DictionaryValue>();
tab->SetWithoutPathExpansion(
"id", std::make_unique<base::Value>(api_contents->ID()));
tab->SetWithoutPathExpansion(
"url", std::make_unique<base::Value>(api_contents->GetURL().spec()));
tab->SetWithoutPathExpansion(
"title", std::make_unique<base::Value>(api_contents->GetTitle()));
tab->SetWithoutPathExpansion(
"audible",
std::make_unique<base::Value>(api_contents->IsCurrentlyAudible()));
return tab;
api::tabs::Tab tab;
tab.id = std::make_unique<int>(api_contents->ID());
tab.url = std::make_unique<std::string>(api_contents->GetURL().spec());
tab.title = std::make_unique<std::string>(
base::UTF16ToUTF8(api_contents->GetTitle()));
tab.audible = std::make_unique<bool>(api_contents->IsCurrentlyAudible());
return tab.ToValue();
}
}
return nullptr;
@ -84,7 +81,7 @@ std::unique_ptr<MessagePort> ElectronMessagingDelegate::CreateReceiverForTab(
content::RenderFrameHost* receiver_rfh = nullptr;
if (include_child_frames) {
// The target is the active outermost main frame of the WebContents.
receiver_rfh = receiver_contents->GetMainFrame();
receiver_rfh = receiver_contents->GetPrimaryMainFrame();
} else if (!receiver_document_id.empty()) {
ExtensionApiFrameIdMap::DocumentId document_id =
ExtensionApiFrameIdMap::DocumentIdFromString(receiver_document_id);

View file

@ -10,17 +10,17 @@
#include "base/command_line.h"
#include "content/public/browser/web_contents.h"
#include "services/device/public/cpp/hid/hid_switches.h"
#include "shell/browser/electron_permission_manager.h"
#include "shell/browser/hid/hid_chooser_context.h"
#include "shell/browser/hid/hid_chooser_context_factory.h"
#include "shell/browser/hid/hid_chooser_controller.h"
#include "shell/browser/web_contents_permission_helper.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
namespace {
electron::HidChooserContext* GetChooserContext(
content::RenderFrameHost* frame) {
auto* web_contents = content::WebContents::FromRenderFrameHost(frame);
auto* browser_context = web_contents->GetBrowserContext();
content::BrowserContext* browser_context) {
return electron::HidChooserContextFactory::GetForBrowserContext(
browser_context);
}
@ -38,8 +38,9 @@ std::unique_ptr<content::HidChooser> ElectronHidDelegate::RunChooser(
std::vector<blink::mojom::HidDeviceFilterPtr> filters,
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
content::HidChooser::Callback callback) {
electron::HidChooserContext* chooser_context =
GetChooserContext(render_frame_host);
DCHECK(render_frame_host);
auto* chooser_context =
GetChooserContext(render_frame_host->GetBrowserContext());
if (!device_observation_.IsObserving())
device_observation_.Observe(chooser_context);
@ -58,65 +59,61 @@ std::unique_ptr<content::HidChooser> ElectronHidDelegate::RunChooser(
}
bool ElectronHidDelegate::CanRequestDevicePermission(
content::RenderFrameHost* render_frame_host) {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
return permission_helper->CheckHIDAccessPermission(
web_contents->GetMainFrame()->GetLastCommittedOrigin());
content::BrowserContext* browser_context,
const url::Origin& origin) {
base::DictionaryValue details;
details.SetString("securityOrigin", origin.GetURL().spec());
auto* permission_manager = static_cast<ElectronPermissionManager*>(
browser_context->GetPermissionControllerDelegate());
return permission_manager->CheckPermissionWithDetails(
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::HID),
nullptr, origin.GetURL(), &details);
}
bool ElectronHidDelegate::HasDevicePermission(
content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) {
auto* chooser_context = GetChooserContext(render_frame_host);
const auto& origin =
render_frame_host->GetMainFrame()->GetLastCommittedOrigin();
return chooser_context->HasDevicePermission(origin, device,
render_frame_host);
return GetChooserContext(browser_context)
->HasDevicePermission(origin, device);
}
void ElectronHidDelegate::RevokeDevicePermission(
content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) {
auto* chooser_context = GetChooserContext(render_frame_host);
const auto& origin =
render_frame_host->GetMainFrame()->GetLastCommittedOrigin();
return chooser_context->RevokeDevicePermission(origin, device,
render_frame_host);
return GetChooserContext(browser_context)
->RevokeDevicePermission(origin, device);
}
device::mojom::HidManager* ElectronHidDelegate::GetHidManager(
content::RenderFrameHost* render_frame_host) {
auto* chooser_context = GetChooserContext(render_frame_host);
return chooser_context->GetHidManager();
content::BrowserContext* browser_context) {
return GetChooserContext(browser_context)->GetHidManager();
}
void ElectronHidDelegate::AddObserver(
content::RenderFrameHost* render_frame_host,
Observer* observer) {
void ElectronHidDelegate::AddObserver(content::BrowserContext* browser_context,
Observer* observer) {
observer_list_.AddObserver(observer);
auto* chooser_context = GetChooserContext(render_frame_host);
auto* chooser_context = GetChooserContext(browser_context);
if (!device_observation_.IsObserving())
device_observation_.Observe(chooser_context);
}
void ElectronHidDelegate::RemoveObserver(
content::RenderFrameHost* render_frame_host,
content::HidDelegate::Observer* observer) {
observer_list_.RemoveObserver(observer);
}
const device::mojom::HidDeviceInfo* ElectronHidDelegate::GetDeviceInfo(
content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context,
const std::string& guid) {
auto* chooser_context = GetChooserContext(render_frame_host);
auto* chooser_context = GetChooserContext(browser_context);
return chooser_context->GetDeviceInfo(guid);
}
bool ElectronHidDelegate::IsFidoAllowedForOrigin(
content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context,
const url::Origin& origin) {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableHidBlocklist);

View file

@ -33,23 +33,24 @@ class ElectronHidDelegate : public content::HidDelegate,
std::vector<blink::mojom::HidDeviceFilterPtr> filters,
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
content::HidChooser::Callback callback) override;
bool CanRequestDevicePermission(
content::RenderFrameHost* render_frame_host) override;
bool HasDevicePermission(content::RenderFrameHost* render_frame_host,
bool CanRequestDevicePermission(content::BrowserContext* browser_context,
const url::Origin& origin) override;
bool HasDevicePermission(content::BrowserContext* browser_context,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) override;
void RevokeDevicePermission(
content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) override;
device::mojom::HidManager* GetHidManager(
content::RenderFrameHost* render_frame_host) override;
void AddObserver(content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context) override;
void AddObserver(content::BrowserContext* browser_context,
content::HidDelegate::Observer* observer) override;
void RemoveObserver(content::RenderFrameHost* render_frame_host,
content::HidDelegate::Observer* observer) override;
void RemoveObserver(content::HidDelegate::Observer* observer) override;
const device::mojom::HidDeviceInfo* GetDeviceInfo(
content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context,
const std::string& guid) override;
bool IsFidoAllowedForOrigin(content::RenderFrameHost* render_frame_host,
bool IsFidoAllowedForOrigin(content::BrowserContext* browser_context,
const url::Origin& origin) override;
// HidChooserContext::DeviceObserver:

View file

@ -20,12 +20,15 @@
#include "services/device/public/cpp/hid/hid_blocklist.h"
#include "services/device/public/cpp/hid/hid_switches.h"
#include "shell/browser/api/electron_api_session.h"
#include "shell/browser/electron_permission_manager.h"
#include "shell/browser/web_contents_permission_helper.h"
#include "shell/common/gin_converters/content_converter.h"
#include "shell/common/gin_converters/frame_converter.h"
#include "shell/common/gin_converters/hid_device_info_converter.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "ui/base/l10n/l10n_util.h"
namespace electron {
@ -90,16 +93,16 @@ base::Value HidChooserContext::DeviceInfoToValue(
void HidChooserContext::GrantDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host) {
const device::mojom::HidDeviceInfo& device) {
DCHECK(base::Contains(devices_, device.guid));
if (CanStorePersistentEntry(device)) {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
permission_helper->GrantHIDDevicePermission(
origin, DeviceInfoToValue(device), render_frame_host);
auto* permission_manager = static_cast<ElectronPermissionManager*>(
browser_context_->GetPermissionControllerDelegate());
permission_manager->GrantDevicePermission(
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::HID),
origin, DeviceInfoToValue(device), browser_context_);
} else {
ephemeral_devices_[origin].insert(device.guid);
}
@ -107,40 +110,34 @@ void HidChooserContext::GrantDevicePermission(
void HidChooserContext::RevokeDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host) {
const device::mojom::HidDeviceInfo& device) {
DCHECK(base::Contains(devices_, device.guid));
if (CanStorePersistentEntry(device)) {
RevokePersistentDevicePermission(origin, device, render_frame_host);
RevokePersistentDevicePermission(origin, device);
} else {
RevokeEphemeralDevicePermission(origin, device);
}
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
api::Session* session =
api::Session::FromBrowserContext(web_contents->GetBrowserContext());
api::Session* session = api::Session::FromBrowserContext(browser_context_);
if (session) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::Dictionary details =
gin_helper::Dictionary::CreateEmpty(isolate);
details.Set("device", device.Clone());
details.SetGetter("frame", render_frame_host);
details.Set("origin", origin.Serialize());
session->Emit("hid-device-revoked", details);
}
}
void HidChooserContext::RevokePersistentDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host) {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
permission_helper->RevokeHIDDevicePermission(
origin, DeviceInfoToValue(device), render_frame_host);
const device::mojom::HidDeviceInfo& device) {
auto* permission_manager = static_cast<ElectronPermissionManager*>(
browser_context_->GetPermissionControllerDelegate());
permission_manager->RevokeDevicePermission(
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::HID),
origin, DeviceInfoToValue(device), browser_context_);
RevokeEphemeralDevicePermission(origin, device);
}
@ -167,11 +164,10 @@ void HidChooserContext::RevokeEphemeralDevicePermission(
bool HidChooserContext::HasDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host) {
const device::mojom::HidDeviceInfo& device) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableHidBlocklist) &&
device::HidBlocklist::IsDeviceExcluded(device))
device.is_excluded_by_blocklist)
return false;
auto it = ephemeral_devices_.find(origin);
@ -180,12 +176,12 @@ bool HidChooserContext::HasDevicePermission(
return true;
}
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
return permission_helper->CheckHIDDevicePermission(
origin, DeviceInfoToValue(device), render_frame_host);
auto* permission_manager = static_cast<ElectronPermissionManager*>(
browser_context_->GetPermissionControllerDelegate());
return permission_manager->CheckDevicePermission(
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::HID),
origin, DeviceInfoToValue(device), browser_context_);
}
void HidChooserContext::AddDeviceObserver(DeviceObserver* observer) {

View file

@ -16,7 +16,6 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/unguessable_token.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
@ -74,14 +73,11 @@ class HidChooserContext : public KeyedService,
// HID-specific interface for granting and checking permissions.
void GrantDevicePermission(const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host);
const device::mojom::HidDeviceInfo& device);
void RevokeDevicePermission(const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host);
const device::mojom::HidDeviceInfo& device);
bool HasDevicePermission(const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host);
const device::mojom::HidDeviceInfo& device);
// For ScopedObserver.
void AddDeviceObserver(DeviceObserver* observer);
@ -117,8 +113,7 @@ class HidChooserContext : public KeyedService,
// HID-specific interface for revoking device permissions.
void RevokePersistentDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
content::RenderFrameHost* render_frame_host);
const device::mojom::HidDeviceInfo& device);
void RevokeEphemeralDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device);

View file

@ -86,7 +86,7 @@ HidChooserController::HidChooserController(
exclusion_filters_(std::move(exclusion_filters)),
callback_(std::move(callback)),
origin_(content::WebContents::FromRenderFrameHost(render_frame_host)
->GetMainFrame()
->GetPrimaryMainFrame()
->GetLastCommittedOrigin()),
frame_tree_node_id_(render_frame_host->GetFrameTreeNodeId()),
hid_delegate_(hid_delegate),
@ -196,8 +196,7 @@ void HidChooserController::OnDeviceChosen(gin::Arguments* args) {
std::vector<device::mojom::HidDeviceInfoPtr> devices;
devices.reserve(device_infos.size());
for (auto& device : device_infos) {
chooser_context_->GrantDevicePermission(origin_, *device,
web_contents()->GetMainFrame());
chooser_context_->GrantDevicePermission(origin_, *device);
devices.push_back(device->Clone());
}
RunCallback(std::move(devices));
@ -262,7 +261,7 @@ bool HidChooserController::DisplayDevice(
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableHidBlocklist)) {
// Do not pass the device to the chooser if it is excluded by the blocklist.
if (device::HidBlocklist::IsDeviceExcluded(device))
if (device.is_excluded_by_blocklist)
return false;
// Do not pass the device to the chooser if it has a top-level collection

View file

@ -45,7 +45,7 @@ MediaStreamDevicesController::MediaStreamDevicesController(
MediaStreamDevicesController::~MediaStreamDevicesController() {
if (!callback_.is_null()) {
std::move(callback_).Run(
blink::mojom::StreamDevices(),
blink::mojom::StreamDevicesSet(),
blink::mojom::MediaStreamRequestResult::FAILED_DUE_TO_SHUTDOWN,
std::unique_ptr<content::MediaStreamUI>());
}
@ -77,7 +77,13 @@ bool MediaStreamDevicesController::TakeAction() {
void MediaStreamDevicesController::Accept() {
// Get the default devices for the request.
blink::mojom::StreamDevices stream_devices;
blink::mojom::StreamDevicesSetPtr stream_devices_set =
blink::mojom::StreamDevicesSet::New();
stream_devices_set->stream_devices.emplace_back(
blink::mojom::StreamDevices::New());
blink::mojom::StreamDevices& stream_devices =
*stream_devices_set->stream_devices[0];
if (microphone_requested_ || webcam_requested_) {
switch (request_.request_type) {
case blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY: {
@ -164,19 +170,23 @@ void MediaStreamDevicesController::Accept() {
}
}
std::move(callback_).Run(stream_devices,
std::move(callback_).Run(*stream_devices_set,
blink::mojom::MediaStreamRequestResult::OK,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::Deny(
blink::mojom::MediaStreamRequestResult result) {
std::move(callback_).Run(blink::mojom::StreamDevices(), result,
std::move(callback_).Run(blink::mojom::StreamDevicesSet(), result,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::HandleUserMediaRequest() {
blink::mojom::StreamDevices devices;
blink::mojom::StreamDevicesSetPtr stream_devices_set =
blink::mojom::StreamDevicesSet::New();
stream_devices_set->stream_devices.emplace_back(
blink::mojom::StreamDevices::New());
blink::mojom::StreamDevices& devices = *stream_devices_set->stream_devices[0];
if (request_.audio_type ==
blink::mojom::MediaStreamType::GUM_TAB_AUDIO_CAPTURE) {
@ -215,7 +225,7 @@ void MediaStreamDevicesController::HandleUserMediaRequest() {
bool empty =
!devices.audio_device.has_value() && !devices.video_device.has_value();
std::move(callback_).Run(
devices,
*stream_devices_set,
empty ? blink::mojom::MediaStreamRequestResult::NO_HARDWARE
: blink::mojom::MediaStreamRequestResult::OK,
std::unique_ptr<content::MediaStreamUI>());

View file

@ -13,6 +13,7 @@
#include "shell/browser/notifications/win/win32_desktop_notifications/desktop_notification_controller.h"
#include <windowsx.h>
#include <algorithm>
#include <utility>
#include "base/check.h"
@ -238,7 +239,7 @@ void DesktopNotificationController::AnimateAll() {
it = stable_partition(it, it2, is_alive);
// purge the dead items
for_each(it, it2, [this](auto&& inst) { DestroyToast(&inst); });
std::for_each(it, it2, [this](auto&& inst) { DestroyToast(&inst); });
if (it2 == instances_.end()) {
instances_.erase(it, it2);

View file

@ -117,7 +117,7 @@ void PrintPreviewMessageHandler::DidPrepareDocumentForPreview(
auto* focused_frame = web_contents_->GetFocusedFrame();
auto* rfh = focused_frame && focused_frame->HasSelection()
? focused_frame
: web_contents_->GetMainFrame();
: web_contents_->GetPrimaryMainFrame();
client->DoPrepareForDocumentToPdf(
document_cookie, rfh,
@ -179,7 +179,7 @@ void PrintPreviewMessageHandler::DidPreviewPage(
auto* focused_frame = web_contents_->GetFocusedFrame();
auto* rfh = focused_frame && focused_frame->HasSelection()
? focused_frame
: web_contents_->GetMainFrame();
: web_contents_->GetPrimaryMainFrame();
// Use utility process to convert skia metafile to pdf.
client->DoCompositePageToPdf(
@ -217,7 +217,7 @@ void PrintPreviewMessageHandler::PrintToPDF(
auto* focused_frame = web_contents_->GetFocusedFrame();
auto* rfh = focused_frame && focused_frame->HasSelection()
? focused_frame
: web_contents_->GetMainFrame();
: web_contents_->GetPrimaryMainFrame();
if (!print_render_frame_.is_bound()) {
rfh->GetRemoteAssociatedInterfaces()->GetInterface(&print_render_frame_);

View file

@ -49,7 +49,7 @@ bool ElectronSerialDelegate::CanRequestPortPermission(
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
return permission_helper->CheckSerialAccessPermission(
web_contents->GetMainFrame()->GetLastCommittedOrigin());
web_contents->GetPrimaryMainFrame()->GetLastCommittedOrigin());
}
bool ElectronSerialDelegate::HasPortPermission(
@ -60,7 +60,8 @@ bool ElectronSerialDelegate::HasPortPermission(
auto* chooser_context =
SerialChooserContextFactory::GetForBrowserContext(browser_context);
return chooser_context->HasPortPermission(
web_contents->GetMainFrame()->GetLastCommittedOrigin(), port, frame);
web_contents->GetPrimaryMainFrame()->GetLastCommittedOrigin(), port,
frame);
}
device::mojom::SerialPortManager* ElectronSerialDelegate::GetPortManager(

View file

@ -15,6 +15,7 @@
#include "content/public/browser/device_service.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "shell/browser/electron_permission_manager.h"
#include "shell/browser/web_contents_permission_helper.h"
namespace electron {
@ -86,7 +87,8 @@ base::Value PortInfoToValue(const device::mojom::SerialPortInfo& port) {
return value;
}
SerialChooserContext::SerialChooserContext() = default;
SerialChooserContext::SerialChooserContext(ElectronBrowserContext* context)
: browser_context_(context) {}
SerialChooserContext::~SerialChooserContext() = default;
@ -99,26 +101,24 @@ void SerialChooserContext::GrantPortPermission(
const url::Origin& origin,
const device::mojom::SerialPortInfo& port,
content::RenderFrameHost* render_frame_host) {
base::Value value = PortInfoToValue(port);
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
permission_helper->GrantSerialPortPermission(origin, std::move(value),
render_frame_host);
auto* permission_manager = static_cast<ElectronPermissionManager*>(
browser_context_->GetPermissionControllerDelegate());
return permission_manager->GrantDevicePermission(
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::SERIAL),
origin, PortInfoToValue(port), browser_context_);
}
bool SerialChooserContext::HasPortPermission(
const url::Origin& origin,
const device::mojom::SerialPortInfo& port,
content::RenderFrameHost* render_frame_host) {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
base::Value value = PortInfoToValue(port);
return permission_helper->CheckSerialPortPermission(origin, std::move(value),
render_frame_host);
auto* permission_manager = static_cast<ElectronPermissionManager*>(
browser_context_->GetPermissionControllerDelegate());
return permission_manager->CheckDevicePermission(
static_cast<blink::PermissionType>(
WebContentsPermissionHelper::PermissionType::SERIAL),
origin, PortInfoToValue(port), browser_context_);
}
void SerialChooserContext::RevokePortPermissionWebInitiated(

View file

@ -48,7 +48,7 @@ class SerialChooserContext : public KeyedService,
public:
using PortObserver = content::SerialDelegate::Observer;
SerialChooserContext();
explicit SerialChooserContext(ElectronBrowserContext* context);
~SerialChooserContext() override;
// disable copy
@ -104,6 +104,8 @@ class SerialChooserContext : public KeyedService,
mojo::Receiver<device::mojom::SerialPortManagerClient> client_receiver_{this};
base::ObserverList<PortObserver> port_observer_list_;
ElectronBrowserContext* browser_context_;
base::WeakPtrFactory<SerialChooserContext> weak_factory_{this};
};

View file

@ -19,7 +19,9 @@ SerialChooserContextFactory::~SerialChooserContextFactory() = default;
KeyedService* SerialChooserContextFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new SerialChooserContext();
auto* browser_context =
static_cast<electron::ElectronBrowserContext*>(context);
return new SerialChooserContext(browser_context);
}
// static

View file

@ -69,7 +69,7 @@ SerialChooserController::SerialChooserController(
callback_(std::move(callback)),
serial_delegate_(serial_delegate),
render_frame_host_id_(render_frame_host->GetGlobalId()) {
origin_ = web_contents->GetMainFrame()->GetLastCommittedOrigin();
origin_ = web_contents->GetPrimaryMainFrame()->GetLastCommittedOrigin();
chooser_context_ = SerialChooserContextFactory::GetForBrowserContext(
web_contents->GetBrowserContext())

View file

@ -13,8 +13,7 @@
#include "base/strings/sys_string_conversions.h"
#include "net/cert/cert_database.h"
#include "net/cert/x509_util_ios_and_mac.h"
#include "net/cert/x509_util_mac.h"
#include "net/cert/x509_util_apple.h"
#include "shell/browser/native_window.h"
@interface TrustDelegate : NSObject {

View file

@ -400,7 +400,7 @@ content::WebContents* InspectableWebContents::GetDevToolsWebContents() const {
void InspectableWebContents::InspectElement(int x, int y) {
if (agent_host_)
agent_host_->InspectElement(web_contents_->GetMainFrame(), x, y);
agent_host_->InspectElement(web_contents_->GetPrimaryMainFrame(), x, y);
}
void InspectableWebContents::SetDelegate(
@ -532,7 +532,7 @@ void InspectableWebContents::CallClientFunction(
}
}
javascript.append(");");
GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(
GetDevToolsWebContents()->GetPrimaryMainFrame()->ExecuteJavaScript(
base::UTF8ToUTF16(javascript), base::NullCallback());
}
@ -580,7 +580,7 @@ void InspectableWebContents::LoadCompleted() {
}
std::u16string javascript = base::UTF8ToUTF16(
"UI.DockController.instance().setDockSide(\"" + dock_state_ + "\");");
GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(
GetDevToolsWebContents()->GetPrimaryMainFrame()->ExecuteJavaScript(
javascript, base::NullCallback());
}
@ -612,7 +612,7 @@ void InspectableWebContents::AddDevToolsExtensionsToClient() {
// process. Grant the devtools process the ability to request URLs from the
// extension.
content::ChildProcessSecurityPolicy::GetInstance()->GrantRequestOrigin(
web_contents_->GetMainFrame()->GetProcess()->GetID(),
web_contents_->GetPrimaryMainFrame()->GetProcess()->GetID(),
url::Origin::Create(extension->url()));
auto extension_info = std::make_unique<base::DictionaryValue>();
@ -622,7 +622,7 @@ void InspectableWebContents::AddDevToolsExtensionsToClient() {
"exposeExperimentalAPIs",
extension->permissions_data()->HasAPIPermission(
extensions::mojom::APIPermissionID::kExperimental));
results.Append(std::move(extension_info));
results.Append(base::Value::FromUniquePtrValue(std::move(extension_info)));
}
CallClientFunction("DevToolsAPI.addExtensions", &results, NULL, NULL);
@ -948,7 +948,7 @@ void InspectableWebContents::DispatchProtocolMessage(
base::EscapeJSONString(str_message, true, &param);
std::u16string javascript =
base::UTF8ToUTF16("DevToolsAPI.dispatchMessage(" + param + ");");
GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(
GetDevToolsWebContents()->GetPrimaryMainFrame()->ExecuteJavaScript(
javascript, base::NullCallback());
return;
}
@ -1032,12 +1032,12 @@ void InspectableWebContents::ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) {
if (navigation_handle->IsInMainFrame()) {
if (navigation_handle->GetRenderFrameHost() ==
GetDevToolsWebContents()->GetMainFrame() &&
GetDevToolsWebContents()->GetPrimaryMainFrame() &&
frontend_host_) {
return;
}
frontend_host_ = content::DevToolsFrontendHost::Create(
web_contents()->GetMainFrame(),
web_contents()->GetPrimaryMainFrame(),
base::BindRepeating(
&InspectableWebContents::HandleMessageFromDevToolsFrontend,
base::Unretained(this)));

View file

@ -196,7 +196,7 @@ std::string RecursiveDumpAXPlatformNodeAsString(
}
}
str += "\n";
for (int i = 0; i < node->GetDelegate()->GetChildCount(); i++) {
for (size_t i = 0; i < node->GetDelegate()->GetChildCount(); i++) {
gfx::NativeViewAccessible child = node->GetDelegate()->ChildAtIndex(i);
const ui::AXPlatformNode* child_node =
ui::AXPlatformNode::FromNativeViewAccessible(child);
@ -286,14 +286,15 @@ void HandleAccessibilityRequestCallback(
descriptor->SetBoolean(kWeb, is_web_enabled);
descriptor->SetBoolean(kLabelImages,
are_accessibility_image_labels_enabled);
rvh_list->Append(std::move(descriptor));
rvh_list->Append(base::Value::FromUniquePtrValue(std::move(descriptor)));
}
data.Set(kPagesField, std::move(rvh_list));
auto window_list = std::make_unique<base::ListValue>();
for (auto* window : electron::WindowList::GetWindows()) {
window_list->Append(BuildTargetDescriptor(window));
window_list->Append(
base::Value::FromUniquePtrValue(BuildTargetDescriptor(window)));
}
data.Set(kBrowsersField, std::move(window_list));

View file

@ -65,7 +65,7 @@ void WebContentsPermissionHelper::RequestPermission(
base::OnceCallback<void(bool)> callback,
bool user_gesture,
const base::DictionaryValue* details) {
auto* rfh = web_contents_->GetMainFrame();
auto* rfh = web_contents_->GetPrimaryMainFrame();
auto* permission_manager = static_cast<ElectronPermissionManager*>(
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
auto origin = web_contents_->GetLastCommittedURL();
@ -77,7 +77,7 @@ void WebContentsPermissionHelper::RequestPermission(
bool WebContentsPermissionHelper::CheckPermission(
blink::PermissionType permission,
const base::DictionaryValue* details) const {
auto* rfh = web_contents_->GetMainFrame();
auto* rfh = web_contents_->GetPrimaryMainFrame();
auto* permission_manager = static_cast<ElectronPermissionManager*>(
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
auto origin = web_contents_->GetLastCommittedURL();
@ -85,39 +85,6 @@ bool WebContentsPermissionHelper::CheckPermission(
details);
}
bool WebContentsPermissionHelper::CheckDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const {
auto* permission_manager = static_cast<ElectronPermissionManager*>(
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
return permission_manager->CheckDevicePermission(permission, origin, device,
render_frame_host);
}
void WebContentsPermissionHelper::GrantDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const {
auto* permission_manager = static_cast<ElectronPermissionManager*>(
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
permission_manager->GrantDevicePermission(permission, origin, device,
render_frame_host);
}
void WebContentsPermissionHelper::RevokeDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const {
auto* permission_manager = static_cast<ElectronPermissionManager*>(
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
permission_manager->RevokeDevicePermission(permission, origin, device,
render_frame_host);
}
void WebContentsPermissionHelper::RequestFullscreenPermission(
base::OnceCallback<void(bool)> callback) {
RequestPermission(
@ -197,59 +164,6 @@ bool WebContentsPermissionHelper::CheckSerialAccessPermission(
static_cast<blink::PermissionType>(PermissionType::SERIAL), &details);
}
bool WebContentsPermissionHelper::CheckSerialPortPermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const {
return CheckDevicePermission(
static_cast<blink::PermissionType>(PermissionType::SERIAL), origin,
&device, render_frame_host);
}
void WebContentsPermissionHelper::GrantSerialPortPermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const {
return GrantDevicePermission(
static_cast<blink::PermissionType>(PermissionType::SERIAL), origin,
&device, render_frame_host);
}
bool WebContentsPermissionHelper::CheckHIDAccessPermission(
const url::Origin& embedding_origin) const {
base::DictionaryValue details;
details.SetString("securityOrigin", embedding_origin.GetURL().spec());
return CheckPermission(
static_cast<blink::PermissionType>(PermissionType::HID), &details);
}
bool WebContentsPermissionHelper::CheckHIDDevicePermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const {
return CheckDevicePermission(
static_cast<blink::PermissionType>(PermissionType::HID), origin, &device,
render_frame_host);
}
void WebContentsPermissionHelper::GrantHIDDevicePermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const {
return GrantDevicePermission(
static_cast<blink::PermissionType>(PermissionType::HID), origin, &device,
render_frame_host);
}
void WebContentsPermissionHelper::RevokeHIDDevicePermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const {
return RevokeDevicePermission(
static_cast<blink::PermissionType>(PermissionType::HID), origin, &device,
render_frame_host);
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPermissionHelper);
} // namespace electron

View file

@ -51,27 +51,6 @@ class WebContentsPermissionHelper
bool CheckMediaAccessPermission(const GURL& security_origin,
blink::mojom::MediaStreamType type) const;
bool CheckSerialAccessPermission(const url::Origin& embedding_origin) const;
bool CheckSerialPortPermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const;
void GrantSerialPortPermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const;
bool CheckHIDAccessPermission(const url::Origin& embedding_origin) const;
bool CheckHIDDevicePermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const;
void GrantHIDDevicePermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const;
void RevokeHIDDevicePermission(
const url::Origin& origin,
base::Value device,
content::RenderFrameHost* render_frame_host) const;
private:
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
@ -85,22 +64,6 @@ class WebContentsPermissionHelper
bool CheckPermission(blink::PermissionType permission,
const base::DictionaryValue* details) const;
bool CheckDevicePermission(blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const;
void GrantDevicePermission(blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const;
void RevokeDevicePermission(
blink::PermissionType permission,
const url::Origin& origin,
const base::Value* device,
content::RenderFrameHost* render_frame_host) const;
// TODO(clavin): refactor to use the WebContents provided by the
// WebContentsUserData base class instead of storing a duplicate ref
content::WebContents* web_contents_;

View file

@ -327,7 +327,8 @@ content::WebContents* WebContentsPreferences::GetWebContentsFromProcessID(
int process_id) {
for (WebContentsPreferences* preferences : Instances()) {
content::WebContents* web_contents = preferences->web_contents_;
if (web_contents->GetMainFrame()->GetProcess()->GetID() == process_id)
if (web_contents->GetPrimaryMainFrame()->GetProcess()->GetID() ==
process_id)
return web_contents;
}
return nullptr;

View file

@ -46,7 +46,7 @@ void WebContentsZoomController::SetEmbedderZoomController(
}
void WebContentsZoomController::SetZoomLevel(double level) {
if (!web_contents()->GetMainFrame()->IsRenderFrameLive() ||
if (!web_contents()->GetPrimaryMainFrame()->IsRenderFrameLive() ||
blink::PageZoomValuesEqual(GetZoomLevel(), level) ||
zoom_mode_ == ZoomMode::kDisabled)
return;

View file

@ -32,7 +32,7 @@ void WebViewGuestDelegate::AttachToIframe(
embedder_web_contents_ = embedder_web_contents;
int embedder_process_id =
embedder_web_contents_->GetMainFrame()->GetProcess()->GetID();
embedder_web_contents_->GetPrimaryMainFrame()->GetProcess()->GetID();
auto* embedder_frame =
content::RenderFrameHost::FromID(embedder_process_id, embedder_frame_id);
DCHECK_EQ(embedder_web_contents_,

View file

@ -271,12 +271,6 @@ std::string NativeImage::ToDataURL(gin::Arguments* args) {
image_.AsImageSkia().GetRepresentation(scale_factor).GetBitmap());
}
#if !defined(V8_SANDBOX)
void SkUnref(char* data, void* hint) {
reinterpret_cast<SkRefCnt*>(hint)->unref();
}
#endif
v8::Local<v8::Value> NativeImage::GetBitmap(gin::Arguments* args) {
float scale_factor = GetScaleFactorFromOptions(args);
@ -285,18 +279,10 @@ v8::Local<v8::Value> NativeImage::GetBitmap(gin::Arguments* args) {
SkPixelRef* ref = bitmap.pixelRef();
if (!ref)
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
#if defined(V8_SANDBOX)
return node::Buffer::Copy(args->isolate(),
reinterpret_cast<char*>(ref->pixels()),
bitmap.computeByteSize())
.ToLocalChecked();
#else
ref->ref();
return node::Buffer::New(args->isolate(),
reinterpret_cast<char*>(ref->pixels()),
bitmap.computeByteSize(), &SkUnref, ref)
.ToLocalChecked();
#endif
}
v8::Local<v8::Value> NativeImage::GetNativeHandle(

View file

@ -395,7 +395,7 @@ std::unique_ptr<base::Value> V8ValueConverter::FromV8Array(
scope =
std::make_unique<v8::Context::Scope>(val->GetCreationContextChecked());
auto result = std::make_unique<base::ListValue>();
std::unique_ptr<base::ListValue> result(new base::ListValue());
// Only fields with integer keys are carried over to the ListValue.
for (uint32_t i = 0; i < val->Length(); ++i) {
@ -410,18 +410,19 @@ std::unique_ptr<base::Value> V8ValueConverter::FromV8Array(
if (!val->HasRealIndexedProperty(isolate->GetCurrentContext(), i)
.FromMaybe(false)) {
result->Append(std::make_unique<base::Value>());
result->Append(base::Value());
continue;
}
std::unique_ptr<base::Value> child =
FromV8ValueImpl(state, child_v8, isolate);
if (child)
result->Append(std::move(child));
else
if (child) {
result->Append(base::Value::FromUniquePtrValue(std::move(child)));
} else {
// JSON.stringify puts null in places where values don't serialize, for
// example undefined and functions. Emulate that behavior.
result->Append(std::make_unique<base::Value>());
result->Append(base::Value());
}
}
return std::move(result);
}