2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_RENDERER_FRAME_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_RENDERER_FRAME_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
#include <queue>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2022-02-10 22:52:36 +01:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2022-02-10 22:52:36 +01:00
|
|
|
#include "base/timer/timer.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_frame.h"
|
|
|
|
#include "cef/include/cef_v8.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "cef/libcef/common/mojom/cef.mojom.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/renderer/blink_glue.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
2022-02-10 22:52:36 +01:00
|
|
|
#include "mojo/public/cpp/bindings/receiver.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
namespace base {
|
|
|
|
class ListValue;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
namespace blink {
|
2020-12-02 23:31:49 +01:00
|
|
|
class ResourceLoadInfoNotifierWrapper;
|
2017-07-27 01:19:27 +02:00
|
|
|
class WebLocalFrame;
|
2019-05-11 00:14:48 +02:00
|
|
|
} // namespace blink
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
class GURL;
|
|
|
|
|
|
|
|
class CefBrowserImpl;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Implementation of CefFrame. CefFrameImpl objects are owned by the
|
|
|
|
// CefBrowerImpl and will be detached when the browser is notified that the
|
|
|
|
// associated renderer WebFrame will close.
|
2022-04-05 19:22:32 +02:00
|
|
|
class CefFrameImpl
|
|
|
|
: public CefFrame,
|
|
|
|
public cef::mojom::RenderFrame,
|
|
|
|
public blink_glue::CefExecutionContextLifecycleStateObserver {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2024-01-26 03:12:43 +01:00
|
|
|
CefFrameImpl(CefBrowserImpl* browser, blink::WebLocalFrame* frame);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefFrameImpl(const CefFrameImpl&) = delete;
|
|
|
|
CefFrameImpl& operator=(const CefFrameImpl&) = delete;
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefFrameImpl() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefFrame implementation.
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsValid() override;
|
|
|
|
void Undo() override;
|
|
|
|
void Redo() override;
|
|
|
|
void Cut() override;
|
|
|
|
void Copy() override;
|
|
|
|
void Paste() override;
|
2024-10-18 20:49:52 +02:00
|
|
|
void PasteAndMatchStyle() override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void Delete() override;
|
|
|
|
void SelectAll() override;
|
|
|
|
void ViewSource() override;
|
|
|
|
void GetSource(CefRefPtr<CefStringVisitor> visitor) override;
|
|
|
|
void GetText(CefRefPtr<CefStringVisitor> visitor) override;
|
|
|
|
void LoadRequest(CefRefPtr<CefRequest> request) override;
|
|
|
|
void LoadURL(const CefString& url) override;
|
|
|
|
void ExecuteJavaScript(const CefString& jsCode,
|
|
|
|
const CefString& scriptUrl,
|
|
|
|
int startLine) override;
|
|
|
|
bool IsMain() override;
|
|
|
|
bool IsFocused() override;
|
|
|
|
CefString GetName() override;
|
2024-01-26 03:12:43 +01:00
|
|
|
CefString GetIdentifier() override;
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefFrame> GetParent() override;
|
|
|
|
CefString GetURL() override;
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() override;
|
|
|
|
CefRefPtr<CefV8Context> GetV8Context() override;
|
|
|
|
void VisitDOM(CefRefPtr<CefDOMVisitor> visitor) override;
|
2019-05-11 00:14:48 +02:00
|
|
|
CefRefPtr<CefURLRequest> CreateURLRequest(
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefURLRequestClient> client) override;
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendProcessMessage(CefProcessId target_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) override;
|
2019-05-11 00:14:48 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Forwarded from CefRenderFrameObserver.
|
2022-02-10 22:52:36 +01:00
|
|
|
void OnAttached();
|
|
|
|
void OnWasShown();
|
2022-06-17 15:28:55 +02:00
|
|
|
void OnDidCommitProvisionalLoad();
|
2019-05-24 22:23:43 +02:00
|
|
|
void OnDidFinishLoad();
|
2022-04-05 19:22:32 +02:00
|
|
|
void OnContextCreated(v8::Local<v8::Context> context);
|
|
|
|
void OnContextReleased();
|
2019-05-24 22:23:43 +02:00
|
|
|
void OnDetached();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
blink::WebLocalFrame* web_frame() const { return frame_; }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
private:
|
2024-04-23 22:06:00 +02:00
|
|
|
// Called for draggable region changes due to navigation. This is in addition
|
|
|
|
// to the standard notifications delivered via
|
|
|
|
// WebContentsDelegate::DraggableRegionsChanged.
|
|
|
|
void OnDraggableRegionsChanged();
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
// Execute an action on the associated WebLocalFrame. This will queue the
|
|
|
|
// action if the JavaScript context is not yet created.
|
|
|
|
using LocalFrameAction =
|
|
|
|
base::OnceCallback<void(blink::WebLocalFrame* frame)>;
|
|
|
|
void ExecuteOnLocalFrame(const std::string& function_name,
|
|
|
|
LocalFrameAction action);
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
enum class ConnectReason {
|
|
|
|
RENDER_FRAME_CREATED,
|
|
|
|
WAS_SHOWN,
|
|
|
|
RETRY,
|
|
|
|
};
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
// Initiate the connection to the BrowserFrame channel.
|
2022-08-16 19:10:43 +02:00
|
|
|
void ConnectBrowserFrame(ConnectReason reason);
|
2022-02-10 22:52:36 +01:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Returns the remote BrowserFrame object.
|
2022-02-10 22:52:36 +01:00
|
|
|
using BrowserFrameType = mojo::Remote<cef::mojom::BrowserFrame>;
|
|
|
|
const BrowserFrameType& GetBrowserFrame(bool expect_acked = true);
|
|
|
|
|
|
|
|
// Called if the BrowserFrame connection attempt times out.
|
|
|
|
void OnBrowserFrameTimeout();
|
|
|
|
|
2024-03-08 20:20:11 +01:00
|
|
|
// Called if the BrowserFrame connection is disconnected.
|
|
|
|
void OnBrowserFrameDisconnect(uint32_t custom_reason,
|
|
|
|
const std::string& description);
|
|
|
|
// Called if the RenderFrame connection is disconnected.
|
|
|
|
void OnRenderFrameDisconnect(uint32_t custom_reason,
|
|
|
|
const std::string& description);
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
enum class DisconnectReason {
|
|
|
|
DETACHED,
|
2022-08-16 20:47:47 +02:00
|
|
|
BROWSER_FRAME_DETACHED,
|
2022-08-16 19:10:43 +02:00
|
|
|
CONNECT_TIMEOUT,
|
|
|
|
RENDER_FRAME_DISCONNECT,
|
|
|
|
BROWSER_FRAME_DISCONNECT,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Called if/when a disconnect occurs. This may occur due to frame navigation,
|
|
|
|
// destruction, or insertion into the bfcache (when the browser-side frame
|
|
|
|
// representation is destroyed and closes the connection).
|
2024-03-08 20:20:11 +01:00
|
|
|
void OnDisconnect(DisconnectReason reason, const std::string& description);
|
2021-05-14 18:58:55 +02:00
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
// Send an action to the remote BrowserFrame. This will queue the action if
|
|
|
|
// the remote frame is not yet attached.
|
|
|
|
using BrowserFrameAction = base::OnceCallback<void(const BrowserFrameType&)>;
|
|
|
|
void SendToBrowserFrame(const std::string& function_name,
|
|
|
|
BrowserFrameAction action);
|
2021-05-14 18:58:55 +02:00
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
void MaybeInitializeScriptContext();
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// cef::mojom::RenderFrame methods:
|
2024-04-17 18:01:26 +02:00
|
|
|
void FrameAttachedAck(bool allow) override;
|
2022-08-16 20:47:47 +02:00
|
|
|
void FrameDetached() override;
|
2023-01-30 22:42:40 +01:00
|
|
|
void SendMessage(const std::string& name,
|
|
|
|
base::Value::List arguments) override;
|
2022-07-04 11:49:15 +02:00
|
|
|
void SendSharedMemoryRegion(const std::string& name,
|
2023-10-17 00:43:29 +02:00
|
|
|
base::WritableSharedMemoryRegion region) override;
|
2021-05-14 18:58:55 +02:00
|
|
|
void SendCommand(const std::string& command) override;
|
|
|
|
void SendCommandWithResponse(
|
|
|
|
const std::string& command,
|
|
|
|
cef::mojom::RenderFrame::SendCommandWithResponseCallback callback)
|
|
|
|
override;
|
|
|
|
void SendJavaScript(const std::u16string& jsCode,
|
|
|
|
const std::string& scriptUrl,
|
|
|
|
int32_t startLine) override;
|
|
|
|
void LoadRequest(cef::mojom::RequestParamsPtr params) override;
|
|
|
|
void DidStopLoading() override;
|
2023-01-06 19:33:32 +01:00
|
|
|
void MoveOrResizeStarted() override;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
// blink_glue::CefExecutionContextLifecycleStateObserver methods:
|
|
|
|
void ContextLifecycleStateChanged(
|
|
|
|
blink::mojom::blink::FrameLifecycleState state) override;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefBrowserImpl* browser_;
|
2017-07-27 01:19:27 +02:00
|
|
|
blink::WebLocalFrame* frame_;
|
2024-01-26 03:12:43 +01:00
|
|
|
const std::string frame_debug_str_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
bool did_commit_provisional_load_ = false;
|
|
|
|
bool did_initialize_script_context_ = false;
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
bool context_created_ = false;
|
2022-02-10 22:52:36 +01:00
|
|
|
std::queue<std::pair<std::string, LocalFrameAction>> queued_context_actions_;
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
bool attach_denied_ = false;
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
// Number of times that browser reconnect has been attempted.
|
|
|
|
size_t browser_connect_retry_ct_ = 0;
|
|
|
|
|
|
|
|
// Current browser connection state.
|
|
|
|
enum class ConnectionState {
|
|
|
|
DISCONNECTED,
|
|
|
|
CONNECTION_PENDING,
|
|
|
|
CONNECTION_ACKED,
|
|
|
|
RECONNECT_PENDING,
|
|
|
|
} browser_connection_state_ = ConnectionState::DISCONNECTED;
|
|
|
|
|
2024-03-08 20:20:11 +01:00
|
|
|
static std::string GetDisconnectDebugString(ConnectionState connection_state,
|
|
|
|
bool frame_is_valid,
|
|
|
|
DisconnectReason reason,
|
|
|
|
const std::string& description);
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
base::OneShotTimer browser_connect_timer_;
|
|
|
|
|
|
|
|
std::queue<std::pair<std::string, BrowserFrameAction>>
|
|
|
|
queued_browser_actions_;
|
2021-05-21 03:42:58 +02:00
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
mojo::Receiver<cef::mojom::RenderFrame> receiver_{this};
|
2021-05-14 18:58:55 +02:00
|
|
|
|
|
|
|
mojo::Remote<cef::mojom::BrowserFrame> browser_frame_;
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
std::unique_ptr<blink_glue::CefObserverRegistration>
|
|
|
|
execution_context_lifecycle_state_observer_;
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
base::WeakPtrFactory<CefFrameImpl> weak_ptr_factory_{this};
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefFrameImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_RENDERER_FRAME_IMPL_H_
|