electron/shell/common/gin_converters/frame_converter.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
3.6 KiB
C++
Raw Normal View History

// Copyright (c) 2020 Samuel Maddock <sam@samuelmaddock.com>.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/gin_converters/frame_converter.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "shell/browser/api/electron_api_web_frame_main.h"
#include "shell/common/gin_helper/accessor.h"
#include "shell/common/node_util.h"
namespace gin {
namespace {
v8::Persistent<v8::ObjectTemplate> rfh_templ;
} // namespace
// static
v8::Local<v8::Value> Converter<content::FrameTreeNodeId>::ToV8(
v8::Isolate* isolate,
const content::FrameTreeNodeId& val) {
return v8::Number::New(isolate, val.value());
}
// static
v8::Local<v8::Value> Converter<content::RenderFrameHost*>::ToV8(
v8::Isolate* isolate,
content::RenderFrameHost* val) {
if (!val)
return v8::Null(isolate);
return electron::api::WebFrameMain::From(isolate, val).ToV8();
}
// static
bool Converter<content::RenderFrameHost*>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
content::RenderFrameHost** out) {
electron::api::WebFrameMain* web_frame_main = nullptr;
if (!ConvertFromV8(isolate, val, &web_frame_main))
return false;
*out = web_frame_main->render_frame_host();
return true;
}
// static
v8::Local<v8::Value>
Converter<gin_helper::AccessorValue<content::RenderFrameHost*>>::ToV8(
v8::Isolate* isolate,
gin_helper::AccessorValue<content::RenderFrameHost*> val) {
content::RenderFrameHost* rfh = val.Value;
if (!rfh)
return v8::Null(isolate);
chore: bump chromium to 133.0.6920.0 (main) (#45055) * chore: bump chromium in DEPS to 133.0.6902.0 * chore: bump chromium in DEPS to 133.0.6903.0 * chore: update patches * Update PdfViewer Save File Picker to use showSaveFilePicker. Refs https://chromium-review.googlesource.com/c/chromium/src/+/6074308 * Code Health: Clean up stale MacWebContentsOcclusion Refs https://chromium-review.googlesource.com/c/chromium/src/+/6078344 * Change RenderProcessHost::GetID to RenderProcessHost::GetDeprecatedID Refs https://chromium-review.googlesource.com/c/chromium/src/+/6065543 * [WebRTC] Make WebRTC IP Handling policy a mojo enum Refs https://chromium-review.googlesource.com/c/chromium/src/+/6063620 * chore: gen filenames.libcxx.gni * Remove allow_unsafe_buffers pragma in //printing Refs https://chromium-review.googlesource.com/c/chromium/src/+/6092280 * refactor: to use ChildProcessId where possible Refs https://issues.chromium.org/issues/379869738 * [Win] Update TabletMode detection code Refs https://chromium-review.googlesource.com/c/chromium/src/+/6003486 * chore: bump chromium in DEPS to 133.0.6905.0 * chore: update patches * Reland "Move global shortcut listener to //ui/base" Refs https://chromium-review.googlesource.com/c/chromium/src/+/6099035 * [shared storage] Implement the batch `with_lock` option for response header Refs https://chromium-review.googlesource.com/c/chromium/src/+/6072742 * chore: bump chromium in DEPS to 133.0.6907.0 * chore: bump chromium in DEPS to 133.0.6909.0 * chore: bump chromium in DEPS to 133.0.6911.0 * chore: bump chromium in DEPS to 133.0.6912.0 * chore: update patches * WebUI: Reveal hidden deps to ui/webui/resources. Refs https://chromium-review.googlesource.com/c/chromium/src/+/6096291 * chore: bump chromium in DEPS to 133.0.6913.0 * chore: bump chromium in DEPS to 133.0.6915.0 * Code Health: Clean up stale base::Feature "AccessibilityTreeForViews" Refs https://chromium-review.googlesource.com/c/chromium/src/+/6104174 Co-authored-by: David Sanders <dsanders11@ucsbalum.com> * fix: remove fastapitypedarray usage * chore: update patches * chore: script/gen-libc++-filenames.js * Code Health: Clean up stale base::Feature "WinRetrieveSuggestionsOnlyOnDemand" Refs https://chromium-review.googlesource.com/c/chromium/src/+/6109477 * fix: empty suggestions with windows platform checker Amends the fix from https://github.com/electron/electron/pull/29690 since the feature flag is no longer available. We follow the same pattern as //chrome/browser/renderer_context_menu/spelling_menu_observer.cc to generate the suggestion list on demand when context menu action is invoked. Co-authored-by: David Sanders <dsanders11@ucsbalum.com> * fixup! fix: empty suggestions with windows platform checker * fixup! fix: empty suggestions with windows platform checker * revert: 6078344: Code Health: Clean up stale MacWebContentsOcclusion | https://chromium-review.googlesource.com/c/chromium/src/+/6078344 * Revert "revert: 6078344: Code Health: Clean up stale MacWebContentsOcclusion | https://chromium-review.googlesource.com/c/chromium/src/+/6078344" This reverts commit 9cacda452ed5a072351e8f5a35b009d91843a08c. * chore: bump to 133.0.6920.0, update patches * Revert "6078344: Code Health: Clean up stale MacWebContentsOcclusion" Refs: https://chromium-review.googlesource.com/c/chromium/src/+/6078344 * fixup! Update PdfViewer Save File Picker to use showSaveFilePicker. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com>
2025-01-10 10:52:34 -06:00
const int32_t process_id = rfh->GetProcess()->GetID().GetUnsafeValue();
const int routing_id = rfh->GetRoutingID();
if (rfh_templ.IsEmpty()) {
v8::EscapableHandleScope inner(isolate);
v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(isolate);
local->SetInternalFieldCount(2);
rfh_templ.Reset(isolate, inner.Escape(local));
}
v8::Local<v8::Object> rfh_obj =
v8::Local<v8::ObjectTemplate>::New(isolate, rfh_templ)
->NewInstance(isolate->GetCurrentContext())
.ToLocalChecked();
rfh_obj->SetInternalField(0, v8::Number::New(isolate, process_id));
rfh_obj->SetInternalField(1, v8::Number::New(isolate, routing_id));
return rfh_obj;
}
// static
bool Converter<gin_helper::AccessorValue<content::RenderFrameHost*>>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
gin_helper::AccessorValue<content::RenderFrameHost*>* out) {
v8::Local<v8::Object> rfh_obj;
if (!ConvertFromV8(isolate, val, &rfh_obj))
return false;
if (rfh_obj->InternalFieldCount() != 2)
return false;
chore: bump chromium to 119.0.6006.0 (main) (#39774) * chore: bump chromium in DEPS to 119.0.5994.0 * chore: update patches * Add some more debugging for navigation origin & process lock mismatch https://chromium-review.googlesource.com/c/chromium/src/+/4829483 * chore: bump chromium in DEPS to 119.0.5996.2 * chore: bump chromium in DEPS to 119.0.5997.0 * chore: bump chromium in DEPS to 119.0.6000.0 * chore: bump chromium in DEPS to 119.0.6002.0 * 4781766: Port remaining control color ids to the color pipeline https://chromium-review.googlesource.com/c/chromium/src/+/4781766 * 4846057: Preloading: Move prefetch_prefs to chrome/browser/preloading/ https://chromium-review.googlesource.com/c/chromium/src/+/4846057 * chore: fixup patch indices * 4848108: Pass v8::Isolate into FromV8Value calls on blink API https://chromium-review.googlesource.com/c/chromium/src/+/4848108 * 4834471: Reland "[api] allow v8::Data as internal field" https://chromium-review.googlesource.com/c/v8/v8/+/4834471 * 4808884: Major overhaul of ExceptionState in the v8 bindings https://chromium-review.googlesource.com/c/chromium/src/+/4808884 * 4791643: [sandbox] Add a TRUSTED_SPACE and TRUSTED_LO_SPACE to the V8 heap https://chromium-review.googlesource.com/c/v8/v8/+/4791643 * chore: bump chromium in DEPS to 119.0.6005.0 * 4776268: [v8][etw] Enables filtering of ETW tracing by URL https://chromium-review.googlesource.com/c/chromium/src/+/4776268 * chore: fixup patch indices * 4673258: WebSQL: Disable WebSQL by default https://chromium-review.googlesource.com/c/chromium/src/+/4673258 * chore: bump chromium in DEPS to 119.0.6006.0 * chore: update patches * 4854732: Reland^2 "[iterator-helpers] Unship due to incompat" https://chromium-review.googlesource.com/c/v8/v8/+/4854732 * 4794133: [AWC] Add `display-state` CSS @media feature https://chromium-review.googlesource.com/c/chromium/src/+/4794133 * fixup! Add some more debugging for navigation origin & process lock mismatch * Revert "fixup! Add some more debugging for navigation origin & process lock mismatch" This reverts commit 38fef075fc5690f7db6d4bbcabbe877a1618a964. * 4858437: Revert "[iOS] Delete GN flags for mach absolute time ticks" https://chromium-review.googlesource.com/c/chromium/src/+/4858437 * refactor: fix_crash_loading_non-standard_schemes_in_iframes.patch (#39879) * chore: 4869108: handle absolute and relative gn imports in autoninja https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4869108 * chore: set GOMA_DIR for autoninja * Revert "chore: 4869108: handle absolute and relative gn imports in autoninja" This reverts commit d94c7720bab96d1de25499383948da2cb8862d90. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Robo <hop2deep@gmail.com>
2023-09-18 16:44:09 -04:00
v8::Local<v8::Value> process_id_wrapper =
rfh_obj->GetInternalField(0).As<v8::Value>();
v8::Local<v8::Value> routing_id_wrapper =
rfh_obj->GetInternalField(1).As<v8::Value>();
if (process_id_wrapper.IsEmpty() || !process_id_wrapper->IsNumber() ||
routing_id_wrapper.IsEmpty() || !routing_id_wrapper->IsNumber())
return false;
const int process_id = process_id_wrapper.As<v8::Number>()->Value();
const int routing_id = routing_id_wrapper.As<v8::Number>()->Value();
auto* rfh = content::RenderFrameHost::FromID(process_id, routing_id);
if (!rfh) {
// Lazily evaluted property accessed after RFH has been destroyed.
// Continue to return nullptr, but emit warning to inform developers
// what occurred.
electron::util::EmitWarning(
isolate,
"Frame property was accessed after it navigated or was destroyed. "
"Avoid asynchronous tasks prior to indexing.",
"electron");
}
out->Value = rfh;
return true;
}
} // namespace gin