e70ce89235
* chore: iwyu shell/browser/electron_pdf_document_helper_client.h * chore: iwyu shell/browser/hid/electron_hid_delegate.h * chore: iwyu content/public/browser/web_contents.h * chore: iwyu shell/browser/usb/electron_usb_delegate.h * chore: iwyu shell/browser/browser_observer.h * chore: iwyu shell/browser/bluetooth/electron_bluetooth_delegate.h * chore: iwyu shell/browser/serial/electron_serial_delegate.h * chore: iwyu shell/browser/api/frame_subscriber.h * chore: iwyu mojo/public/cpp/bindings/ * chore: iwyu components/ * chore: iwyu extensions/ * chore: iwyu shell/common/gin_helper/ * chore: iwyu v8/ * chore: iwyu base/containers/linked_list.h * chore: iwyu shell/browser/native_window.h * chore: iwyu shell/browser/api/electron_api_base_window.h * chore: iwyu shell/common/node_includes.h * chore: iwyu gin/handle.h * chore: iwyu base/functional/callback.h * chore: iwyu ui/gfx/ * chore: iwyu content/public/browser/render_frame_host.h * fix: mac * fix: mac * fix: win * chore: iwyu base/files/file_path.h * chore: iwyu base/unguessable_token.h * chore: iwyu ui/display/screen.h * chore: iwyu chrome/browser/predictors/preconnect_manager.h * chore: iwyu base/observer_list_types.h * chore: iwyu content/public/browser/web_contents.h * chore: iwyu chrome/browser/devtools/devtools_eye_dropper.h * chore: iwyu shell/browser/ui/inspectable_web_contents.h * chore: iwyu content/public/browser/keyboard_event_processing_result.h * chore: iwyu net/cookies/canonical_cookie.h * chore: iwyu net/base/address_list.h * chore: iwyu net/cert/x509_certificate.h * chore: iwyu net/cookies/cookie_change_dispatcher.h * chore: iwyu net/dns/public/host_resolver_results.h * fix: mac * Revert "chore: iwyu net/cert/x509_certificate.h" This reverts commit 002896f71146e90f1e29e090a1d6eede48cee11e.
144 lines
4.6 KiB
C++
144 lines
4.6 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 "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/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 : 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(int 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 FrameTreeNodeID() 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_;
|
|
|
|
int 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_
|