mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* chore: bump chromium in DEPS to 85.0.4165.1 * chore: bump chromium in DEPS to 85.0.4166.1 * chore: bump chromium in DEPS to 85.0.4166.2 * chore: bump chromium in DEPS to 85.0.4166.3 * update patches * fixup! Revert "[printing] Mojofy PrintHostMsg_CheckForCancel" (cherry picked from commit 2cc1caf5d7d716ceefb23d5228a79544a2e91206) * update patches * Revert "[printing] Mojofy PrintHostMsg_CheckForCancel" (cherry picked from commit c2b389957836ad77eb8e977872e6a8590666f3da) * Remove WebImeTextSpan https://chromium-review.googlesource.com/c/chromium/src/+/2225240 (cherry picked from commit d839261d71b156c972d3878f16f971e6b6d98f45) * Remove PDFAnnotations flag altogether. https://chromium-review.googlesource.com/c/chromium/src/+/2229317 (cherry picked from commit 50384ed12602d4a9da3209eacfca4faae78f9986) * Rework find-from-selection so it's synchronous -- fixes flaky tests https://chromium-review.googlesource.com/c/chromium/src/+/2181570 (cherry picked from commit 3e9241560390fb18969393beda425afc63f5a151) * Use ExtensionSystem::is_ready() instead of ExtensionService::is_ready() https://chromium-review.googlesource.com/c/chromium/src/+/2207499 (cherry picked from commit 2424589454a9a2ef9cc89c232b4ee87b0bf400cc) * update sysroots (cherry picked from commit b5ea653e602152dde00303d1cfb915d4df320983) * chore: bump chromium in DEPS to 85.0.4167.1 * Take RFH as a parameter for DidUpdateFavicon/ManifestURL https://chromium-review.googlesource.com/c/chromium/src/+/2224745 (cherry picked from commit ad40668221732e28bcc8b9b270ab4686c42e956a) * update patches * update patches * Rename net::cookie_util::StripStatuses to StripAccessResults https://chromium-review.googlesource.com/c/chromium/src/+/2212697 (cherry picked from commit bf3de1fe1cbb17feb46b40c81f0eb13b1e7b6412) * use net::CookieAccessResultList instead of net::CookieAccessResultList (cherry picked from commit 400da79504da2310b7c1177b4b3f9f83a3f2b305) * chore: bump chromium in DEPS to 85.0.4168.1 * fix mas_no_private_api patch https://chromium-review.googlesource.com/c/chromium/src/+/2230281 (cherry picked from commit 9b127147e0ba7ef1d4454099effe49327b1a5ab6) * Update patches * fix: add new navigation state REUSE_SITE_INSTANCE To fix the new set of state checks added in https://chromium-review.googlesource.com/c/chromium/src/+/2215141 (cherry picked from commit 3a91b684efdc7742e7c5efa65263f80e8a24ec4a) * chore: bump chromium in DEPS to 85.0.4169.1 * update patches * chore: bump chromium in DEPS to 85.0.4170.1 * chore: bump chromium in DEPS to 85.0.4171.1 * chore: bump chromium in DEPS to 85.0.4172.1 * chore: bump chromium in DEPS to 85.0.4173.1 * chore: bump chromium in DEPS to 85.0.4174.1 * chore: bump chromium in DEPS to 85.0.4175.3 * chore: bump chromium in DEPS to 85.0.4176.1 * chore: bump chromium in DEPS to 85.0.4177.2 * chore: bump chromium in DEPS to 85.0.4178.1 * chore: bump chromium in DEPS to 85.0.4178.3 * refactor: MessageLoop, you are terminated \o/ Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2246173 (cherry picked from commit0368131d60) * chore: bump chromium in DEPS to 85.0.4178.4 * update patches * update lib_src_switch_buffer_kmaxlength_to_size_t.patch (cherry picked from commitc5efbdd166) * [v8] Allow for 4GB TypedArrays https: //chromium-review.googlesource.com/c/v8/v8/+/2249668 (cherry picked from commit2c1d6bfd9d) Co-Authored-By: Robo <hop2deep@gmail.com> * Cleanup usages of old mojo types and remove unused code https://chromium-review.googlesource.com/c/chromium/src/+/2235699 (cherry picked from commite89cb21e8e) * refactor: plumb DownloadSchedule to DownloadItem Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2242202 (cherry picked from commit4d549ae2b0) * chore: fix variable typo in IPC (cherry picked from commit7251b1e6c5) * chore: s/BindPipeAndPassReceiver/BindNewPipeAndPassReceiver (cherry picked from commite89bd6c639) * chore: XEvent becomes x11::Event Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2240355 (cherry picked from commit4d832da740) * fixup! refactor: MessageLoop, you are terminated \o/ (cherry picked from commit902d72d740) * fixup! chore: XEvent becomes x11::Event (cherry picked from commit27043549f3) * chore: fix windows build (cherry picked from commit4977098eb3) * chore: disable SameSite-by-default changes https://chromium-review.googlesource.com/c/chromium/src/+/2231445 (cherry picked from commitd8318aafff) * update printing.patch (cherry picked from commite2037f527f) * Convert WidgetHostMsg_SelectionBoundsChanged/TextInputStateChanged https://chromium-review.googlesource.com/c/chromium/src/+/2243531 (cherry picked from commit60ff2e067d) * [XProto] Replace usages of XID and ::Window with x11::Window https://chromium-review.googlesource.com/c/chromium/src/+/2249389 (cherry picked from commit97f5b59e06) * Update VideoFrameMetadata to use base::Optionals https://chromium-review.googlesource.com/c/chromium/src/+/2231706 https://chromium-review.googlesource.com/c/chromium/src/+/2238361 (cherry picked from commit4787e1f541) * --disable-dev-shm-usage for gpu process crash (cherry picked from commit207d8a380a) * update patches * fixup: Cleanup usages of old mojo types and remove unused code * update patches * chore: bump chromium in DEPS to 85.0.4180.1 * build: update v8 headers (cherry picked from commit4808975f75) * Update patches * fixup: build: update v8 headers * Fixup ssl_security_state_tab_helper.patch * Add missing headers * Adds icon loading service with sandbox for Windows. https://chromium-review.googlesource.com/c/chromium/src/+/1987273 * disable app.getGPUInfo spec on linux (cherry picked from commitb7ea16c4b7) * Add missing headers for Linux and Windows * Fixup Adds icon loading service with sandbox for Windows * chore: bump chromium in DEPS to 85.0.4181.1 * update patches * Fixup: (for real) Adds icon loading service with sandbox for Windows * No more Vulkan info collection for UMA on Windows https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * extensions: Rename SharedUserScriptMaster to SharedUserScriptManager https://chromium-review.googlesource.com/c/chromium/src/+/2258357 * Add missing headers * fixup: extensions: Rename SharedUserScriptMaster to SharedUserScriptManager * fixup: No more Vulkan info collection for UMA on Windows * Add missing header * Add resource for IDS_UTILITY_PROCESS_UTILITY_WIN_NAME * fix build on windows * fix gn check Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
167 lines
6.0 KiB
C++
167 lines
6.0 KiB
C++
// Copyright (c) 2017 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/renderer/electron_render_frame_observer.h"
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "base/command_line.h"
|
|
#include "base/strings/string_number_conversions.h"
|
|
#include "base/trace_event/trace_event.h"
|
|
#include "content/public/renderer/render_frame.h"
|
|
#include "content/public/renderer/render_view.h"
|
|
#include "electron/buildflags/buildflags.h"
|
|
#include "electron/shell/common/api/api.mojom.h"
|
|
#include "ipc/ipc_message_macros.h"
|
|
#include "net/base/net_module.h"
|
|
#include "net/grit/net_resources.h"
|
|
#include "services/service_manager/public/cpp/interface_provider.h"
|
|
#include "shell/common/options_switches.h"
|
|
#include "shell/common/world_ids.h"
|
|
#include "third_party/blink/public/platform/web_isolated_world_info.h"
|
|
#include "third_party/blink/public/web/blink.h"
|
|
#include "third_party/blink/public/web/web_document.h"
|
|
#include "third_party/blink/public/web/web_draggable_region.h"
|
|
#include "third_party/blink/public/web/web_element.h"
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
|
#include "third_party/blink/public/web/web_script_source.h"
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
namespace electron {
|
|
|
|
namespace {
|
|
|
|
scoped_refptr<base::RefCountedMemory> NetResourceProvider(int key) {
|
|
if (key == IDR_DIR_HEADER_HTML) {
|
|
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
|
IDR_DIR_HEADER_HTML);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
ElectronRenderFrameObserver::ElectronRenderFrameObserver(
|
|
content::RenderFrame* frame,
|
|
RendererClientBase* renderer_client)
|
|
: content::RenderFrameObserver(frame),
|
|
render_frame_(frame),
|
|
renderer_client_(renderer_client) {
|
|
// Initialise resource for directory listing.
|
|
net::NetModule::SetResourceProvider(NetResourceProvider);
|
|
}
|
|
|
|
void ElectronRenderFrameObserver::DidClearWindowObject() {
|
|
renderer_client_->DidClearWindowObject(render_frame_);
|
|
}
|
|
|
|
void ElectronRenderFrameObserver::DidInstallConditionalFeatures(
|
|
v8::Handle<v8::Context> context,
|
|
int world_id) {
|
|
if (ShouldNotifyClient(world_id))
|
|
renderer_client_->DidCreateScriptContext(context, render_frame_);
|
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
bool use_context_isolation = renderer_client_->isolated_world();
|
|
// This logic matches the EXPLAINED logic in electron_renderer_client.cc
|
|
// to avoid explaining it twice go check that implementation in
|
|
// DidCreateScriptContext();
|
|
bool is_main_world = IsMainWorld(world_id);
|
|
bool is_main_frame = render_frame_->IsMainFrame();
|
|
bool reuse_renderer_processes_enabled =
|
|
command_line->HasSwitch(switches::kDisableElectronSiteInstanceOverrides);
|
|
bool is_not_opened =
|
|
!render_frame_->GetWebFrame()->Opener() ||
|
|
command_line->HasSwitch(switches::kEnableNodeLeakageInRenderers);
|
|
bool allow_node_in_sub_frames =
|
|
command_line->HasSwitch(switches::kNodeIntegrationInSubFrames);
|
|
bool should_create_isolated_context =
|
|
use_context_isolation && is_main_world &&
|
|
(is_main_frame || allow_node_in_sub_frames) &&
|
|
(is_not_opened || reuse_renderer_processes_enabled);
|
|
|
|
if (should_create_isolated_context) {
|
|
CreateIsolatedWorldContext();
|
|
if (!renderer_client_->IsWebViewFrame(context, render_frame_))
|
|
renderer_client_->SetupMainWorldOverrides(context, render_frame_);
|
|
}
|
|
|
|
#if !BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
if (world_id >= WorldIDs::ISOLATED_WORLD_ID_EXTENSIONS &&
|
|
world_id <= WorldIDs::ISOLATED_WORLD_ID_EXTENSIONS_END) {
|
|
renderer_client_->SetupExtensionWorldOverrides(context, render_frame_,
|
|
world_id);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void ElectronRenderFrameObserver::DraggableRegionsChanged() {
|
|
blink::WebVector<blink::WebDraggableRegion> webregions =
|
|
render_frame_->GetWebFrame()->GetDocument().DraggableRegions();
|
|
std::vector<mojom::DraggableRegionPtr> regions;
|
|
for (auto& webregion : webregions) {
|
|
auto region = mojom::DraggableRegion::New();
|
|
render_frame_->ConvertViewportToWindow(&webregion.bounds);
|
|
region->bounds = webregion.bounds;
|
|
region->draggable = webregion.draggable;
|
|
regions.push_back(std::move(region));
|
|
}
|
|
|
|
mojo::Remote<mojom::ElectronBrowser> browser_remote;
|
|
render_frame_->GetRemoteInterfaces()->GetInterface(
|
|
browser_remote.BindNewPipeAndPassReceiver());
|
|
browser_remote->UpdateDraggableRegions(std::move(regions));
|
|
}
|
|
|
|
void ElectronRenderFrameObserver::WillReleaseScriptContext(
|
|
v8::Local<v8::Context> context,
|
|
int world_id) {
|
|
if (ShouldNotifyClient(world_id))
|
|
renderer_client_->WillReleaseScriptContext(context, render_frame_);
|
|
}
|
|
|
|
void ElectronRenderFrameObserver::OnDestruct() {
|
|
delete this;
|
|
}
|
|
|
|
void ElectronRenderFrameObserver::CreateIsolatedWorldContext() {
|
|
auto* frame = render_frame_->GetWebFrame();
|
|
blink::WebIsolatedWorldInfo info;
|
|
// This maps to the name shown in the context combo box in the Console tab
|
|
// of the dev tools.
|
|
info.human_readable_name =
|
|
blink::WebString::FromUTF8("Electron Isolated Context");
|
|
// Setup document's origin policy in isolated world
|
|
info.security_origin = frame->GetDocument().GetSecurityOrigin();
|
|
frame->SetIsolatedWorldInfo(WorldIDs::ISOLATED_WORLD_ID, info);
|
|
|
|
// Create initial script context in isolated world
|
|
blink::WebScriptSource source("void 0");
|
|
frame->ExecuteScriptInIsolatedWorld(WorldIDs::ISOLATED_WORLD_ID, source);
|
|
}
|
|
|
|
bool ElectronRenderFrameObserver::IsMainWorld(int world_id) {
|
|
return world_id == WorldIDs::MAIN_WORLD_ID;
|
|
}
|
|
|
|
bool ElectronRenderFrameObserver::IsIsolatedWorld(int world_id) {
|
|
return world_id == WorldIDs::ISOLATED_WORLD_ID;
|
|
}
|
|
|
|
bool ElectronRenderFrameObserver::ShouldNotifyClient(int world_id) {
|
|
bool allow_node_in_sub_frames =
|
|
base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
switches::kNodeIntegrationInSubFrames);
|
|
if (renderer_client_->isolated_world() &&
|
|
(render_frame_->IsMainFrame() || allow_node_in_sub_frames))
|
|
return IsIsolatedWorld(world_id);
|
|
else
|
|
return IsMainWorld(world_id);
|
|
}
|
|
|
|
} // namespace electron
|