electron/shell/browser/api/electron_api_web_frame_main.h
electron-roller[bot] 30fbeec036
chore: bump chromium to 131.0.6734.0 (main) (#43769)
* chore: bump chromium in DEPS to 130.0.6723.4

* chore: bump chromium in DEPS to 131.0.6724.0

* chore: update patches

* chore: update libc++ filenames

* 5844369: controlledframe: Disable Web Bluetooth for <webview> & <controlledframe>
https://chromium-review.googlesource.com/c/chromium/src/+/5844369

* (multiple CLs): Use an opaque type for FrameTreeNode IDs

5807683: Use an opaque type for FrameTreeNode IDs, part 1 | https://chromium-review.googlesource.com/c/chromium/src/+/5807683
5829746: Use an opaque type for FrameTreeNode IDs, part 2 | https://chromium-review.googlesource.com/c/chromium/src/+/5829746
5836903: Use an opaque type for FrameTreeNode IDs, part 7 | https://chromium-review.googlesource.com/c/chromium/src/+/5836903
5837249: Use an opaque type for FrameTreeNode IDs, part 8 | https://chromium-review.googlesource.com/c/chromium/src/+/5837249
5836564: Use an opaque type for FrameTreeNode IDs, part 12 | https://chromium-review.googlesource.com/c/chromium/src/+/5836564
5837180: Use an opaque type for FrameTreeNode IDs, part 15 | https://chromium-review.googlesource.com/c/chromium/src/+/5837180

* 5822889: [task] Make GetForegroundTaskRunner non-virtual
https://chromium-review.googlesource.com/c/v8/v8/+/5822889

* 5833297: Remove unused inner WebContents attach params
https://chromium-review.googlesource.com/c/chromium/src/+/5833297

* 5806403: Shift PowerMonitor to non static
https://chromium-review.googlesource.com/c/chromium/src/+/5806403

* 5666874: [3/N] Remove old OnPowerChange in PowerObserver
https://chromium-review.googlesource.com/c/chromium/src/+/5666874

* 5829085: [v8] Differentiate between UserVisible and BestEffort task runners
https://chromium-review.googlesource.com/c/chromium/src/+/5829085

* 5791112: [webrtc] Use `c/b/permissions/system` for system permissions
https://chromium-review.googlesource.com/c/chromium/src/+/5791112

* 5825636: [Extensions] Create WebContentsObservers with ExtensionsBrowserClient
https://chromium-review.googlesource.com/c/chromium/src/+/5825636

* fixup! (multiple CLs): Use an opaque type for FrameTreeNode IDs

* fixup! 5791112: [webrtc] Use `c/b/permissions/system` for system permissions https://chromium-review.googlesource.com/c/chromium/src/+/5791112

* chore: bump chromium in DEPS to 131.0.6726.0

* chore: update patches

* chore: update libc++ filenames

* 5858119: Declutter: Allow opening to a specific feature
https://chromium-review.googlesource.com/c/chromium/src/+/5858119

* fix: macOS SDK 15 error

Not sure exactly what changed in the upgrade to macOS SDK 15, but it triggered a new error:

```
electron/shell/browser/ui/message_box_mac.mm:84:7: error: multiple methods named 'highlight:' found with mismatched result, parameter type or attributes
```

The `highlight:` selector a few lines down was ambiguous because the object type of the `NSArray` was not specified. Specifying `NSButton` as the element type makes the selector unambiguous for type checking.

* 5854143: [File Download Access Prevention] Obfuscate download file for enterprise deep scan
https://chromium-review.googlesource.com/c/chromium/src/+/5854143

* 5854811: Use kNotAllowedError instead of kSecurityError for Web MIDI
https://chromium-review.googlesource.com/c/chromium/src/+/5854811

* chore: bump chromium in DEPS to 131.0.6728.0

* chore: update patches

* disable invalid test

* chore: bump chromium in DEPS to 131.0.6730.0

* chore: update patches

* update build tools target commit for new macOS SDK

* chore: update libc++ file names

* chore: bump chromium in DEPS to 131.0.6732.0

* chore: bump chromium in DEPS to 131.0.6734.0

* 5856527: [UI] Use mojo enum for `WindowShowState` in ui/

https://chromium-review.googlesource.com/c/chromium/src/+/5856527

* chore: update build-tools sha to include macOD 15.0 SDK

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: alice <alice@makenotion.com>
2024-09-25 06:19:39 -05:00

147 lines
4.8 KiB
C++

// 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.
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_WEB_FRAME_MAIN_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_WEB_FRAME_MAIN_H_
#include <optional>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process.h"
#include "content/public/browser/frame_tree_node_id.h"
#include "gin/wrappable.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/common/api/api.mojom.h"
#include "shell/common/gin_helper/constructible.h"
#include "shell/common/gin_helper/pinnable.h"
#include "third_party/blink/public/mojom/page/page_visibility_state.mojom-forward.h"
class GURL;
namespace content {
class RenderFrameHost;
}
namespace gin {
class Arguments;
template <typename T>
class Handle;
} // namespace gin
namespace electron::api {
class WebContents;
// Bindings for accessing frames from the main process.
class WebFrameMain final : public gin::Wrappable<WebFrameMain>,
public gin_helper::EventEmitterMixin<WebFrameMain>,
public gin_helper::Pinnable<WebFrameMain>,
public gin_helper::Constructible<WebFrameMain> {
public:
// Create a new WebFrameMain and return the V8 wrapper of it.
static gin::Handle<WebFrameMain> New(v8::Isolate* isolate);
static gin::Handle<WebFrameMain> From(
v8::Isolate* isolate,
content::RenderFrameHost* render_frame_host);
static gin::Handle<WebFrameMain> FromOrNull(
v8::Isolate* isolate,
content::RenderFrameHost* render_frame_host);
static WebFrameMain* FromFrameTreeNodeId(
content::FrameTreeNodeId frame_tree_node_id);
static WebFrameMain* FromRenderFrameHost(
content::RenderFrameHost* render_frame_host);
// gin_helper::Constructible
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "WebFrameMain"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
const char* GetTypeName() override;
content::RenderFrameHost* render_frame_host() const { return render_frame_; }
// disable copy
WebFrameMain(const WebFrameMain&) = delete;
WebFrameMain& operator=(const WebFrameMain&) = delete;
protected:
explicit WebFrameMain(content::RenderFrameHost* render_frame);
~WebFrameMain() override;
private:
friend class WebContents;
// Called when FrameTreeNode is deleted.
void Destroyed();
// Mark RenderFrameHost as disposed and to no longer access it. This can
// happen when the WebFrameMain v8-forward.handle is GC'd or when a
// FrameTreeNode is removed.
void MarkRenderFrameDisposed();
// Swap out the internal RFH when cross-origin navigation occurs.
void UpdateRenderFrameHost(content::RenderFrameHost* rfh);
const mojo::Remote<mojom::ElectronRenderer>& GetRendererApi();
void MaybeSetupMojoConnection();
void TeardownMojoConnection();
void OnRendererConnectionError();
// WebFrameMain can outlive its RenderFrameHost pointer so we need to check
// whether its been disposed of prior to accessing it.
bool CheckRenderFrame() const;
v8::Local<v8::Promise> ExecuteJavaScript(gin::Arguments* args,
const std::u16string& code);
bool Reload();
void Send(v8::Isolate* isolate,
bool internal,
const std::string& channel,
v8::Local<v8::Value> args);
void PostMessage(v8::Isolate* isolate,
const std::string& channel,
v8::Local<v8::Value> message_value,
std::optional<v8::Local<v8::Value>> transfer);
int FrameTreeNodeIDAsInt() const;
std::string Name() const;
base::ProcessId OSProcessID() const;
int ProcessID() const;
int RoutingID() const;
GURL URL() const;
std::string Origin() const;
blink::mojom::PageVisibilityState VisibilityState() const;
content::RenderFrameHost* Top() const;
content::RenderFrameHost* Parent() const;
std::vector<content::RenderFrameHost*> Frames() const;
std::vector<content::RenderFrameHost*> FramesInSubtree() const;
void DOMContentLoaded();
mojo::Remote<mojom::ElectronRenderer> renderer_api_;
mojo::PendingReceiver<mojom::ElectronRenderer> pending_receiver_;
content::FrameTreeNodeId frame_tree_node_id_;
raw_ptr<content::RenderFrameHost> render_frame_ = nullptr;
// Whether the RenderFrameHost has been removed and that it should no longer
// be accessed.
bool render_frame_disposed_ = false;
base::WeakPtrFactory<WebFrameMain> weak_factory_{this};
};
} // namespace electron::api
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_WEB_FRAME_MAIN_H_