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_BROWSER_FRAME_HOST_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_FRAME_HOST_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
#include <memory>
|
2024-01-26 03:12:43 +01:00
|
|
|
#include <optional>
|
2019-05-24 22:23:43 +02:00
|
|
|
#include <queue>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/synchronization/lock.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_frame.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "cef/libcef/common/mojom/cef.mojom.h"
|
2024-01-26 03:12:43 +01:00
|
|
|
#include "content/public/browser/global_routing_id.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "mojo/public/cpp/bindings/receiver_set.h"
|
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "ui/base/page_transition_types.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
2019-05-24 22:23:43 +02:00
|
|
|
struct Referrer;
|
|
|
|
} // namespace content
|
|
|
|
|
|
|
|
class GURL;
|
|
|
|
|
|
|
|
class CefBrowserInfo;
|
2020-09-18 00:24:08 +02:00
|
|
|
class CefBrowserHostBase;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Implementation of CefFrame. CefFrameHostImpl objects should always be created
|
|
|
|
// or retrieved via CefBrowerInfo.
|
2021-05-14 18:58:55 +02:00
|
|
|
class CefFrameHostImpl : public CefFrame, public cef::mojom::BrowserFrame {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2021-05-21 03:42:58 +02:00
|
|
|
// Create a temporary sub-frame.
|
2024-01-26 03:12:43 +01:00
|
|
|
CefFrameHostImpl(
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
|
|
|
std::optional<content::GlobalRenderFrameHostToken> parent_frame_token);
|
2019-05-24 22:23:43 +02:00
|
|
|
|
|
|
|
// Create a frame backed by a RFH and owned by CefBrowserInfo.
|
|
|
|
CefFrameHostImpl(scoped_refptr<CefBrowserInfo> browser_info,
|
|
|
|
content::RenderFrameHost* render_frame_host);
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
CefFrameHostImpl(const CefFrameHostImpl&) = delete;
|
|
|
|
CefFrameHostImpl& operator=(const CefFrameHostImpl&) = delete;
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefFrameHostImpl() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefFrame methods
|
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;
|
|
|
|
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;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
void SetFocused(bool focused);
|
2019-05-24 22:23:43 +02:00
|
|
|
void RefreshAttributes();
|
|
|
|
|
2023-01-06 19:33:32 +01:00
|
|
|
// Notification that a move or resize of the renderer's containing window has
|
2024-06-26 02:12:37 +02:00
|
|
|
// started. Used on Windows and Linux with Alloy style.
|
2023-01-06 19:33:32 +01:00
|
|
|
void NotifyMoveOrResizeStarted();
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Load the specified request.
|
|
|
|
void LoadRequest(cef::mojom::RequestParamsPtr params);
|
2019-05-24 22:23:43 +02:00
|
|
|
|
|
|
|
// Load the specified URL.
|
|
|
|
void LoadURLWithExtras(const std::string& url,
|
|
|
|
const content::Referrer& referrer,
|
|
|
|
ui::PageTransition transition,
|
|
|
|
const std::string& extra_headers);
|
|
|
|
|
|
|
|
// Send a command to the renderer for execution.
|
2021-05-14 18:58:55 +02:00
|
|
|
void SendCommand(const std::string& command);
|
|
|
|
void SendCommandWithResponse(
|
|
|
|
const std::string& command,
|
|
|
|
cef::mojom::RenderFrame::SendCommandWithResponseCallback
|
|
|
|
response_callback);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Send JavaScript to the renderer for execution.
|
2021-05-14 18:58:55 +02:00
|
|
|
void SendJavaScript(const std::u16string& jsCode,
|
2012-10-18 00:45:49 +02:00
|
|
|
const std::string& scriptUrl,
|
|
|
|
int startLine);
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Called from CefBrowserHostBase::DidStopLoading.
|
2019-05-24 22:23:43 +02:00
|
|
|
void MaybeSendDidStopLoading();
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
void ExecuteJavaScriptWithUserGestureForTests(const CefString& javascript);
|
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
// Returns the RFH currently associated with this frame. May return nullptr if
|
|
|
|
// this frame is currenly detached. Do not directly compare RFH pointers; use
|
|
|
|
// IsSameFrame() instead. Must be called on the UI thread.
|
2019-05-24 22:23:43 +02:00
|
|
|
content::RenderFrameHost* GetRenderFrameHost() const;
|
2019-05-11 00:14:48 +02:00
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
// Returns true if this frame and |frame_host| represent the same frame.
|
|
|
|
// Frames are considered the same if they share the same frame token value,
|
|
|
|
// so this method is safe to call even for detached frames. Must be called on
|
|
|
|
// the UI thread.
|
|
|
|
bool IsSameFrame(content::RenderFrameHost* frame_host) const;
|
|
|
|
|
|
|
|
// Returns true if this frame is currently detached (e.g. no associated RFH).
|
|
|
|
// Must be called on the UI thread.
|
|
|
|
bool IsDetached() const;
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
enum class DetachReason {
|
|
|
|
RENDER_FRAME_DELETED,
|
|
|
|
NEW_MAIN_FRAME,
|
|
|
|
BROWSER_DESTROYED,
|
|
|
|
};
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Owned frame objects will be detached explicitly when the associated
|
|
|
|
// RenderFrame is deleted. Temporary frame objects will be detached
|
2021-07-25 19:31:39 +02:00
|
|
|
// implicitly via CefBrowserInfo::browser() returning nullptr. Returns true
|
|
|
|
// if this was the first call to Detach() for the frame.
|
2022-08-16 19:10:43 +02:00
|
|
|
bool Detach(DetachReason reason);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-09-15 13:40:08 +02:00
|
|
|
// A frame has swapped to active status from prerendering or the back-forward
|
|
|
|
// cache. We may need to re-attach if the RFH has changed. See
|
|
|
|
// https://crbug.com/1179502#c8 for additional background.
|
|
|
|
void MaybeReAttach(scoped_refptr<CefBrowserInfo> browser_info,
|
2024-05-13 23:36:09 +02:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
bool require_detached);
|
2021-09-15 13:40:08 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// cef::mojom::BrowserFrame methods forwarded from CefBrowserFrame.
|
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;
|
2022-02-10 22:52:36 +01:00
|
|
|
void FrameAttached(mojo::PendingRemote<cef::mojom::RenderFrame> render_frame,
|
|
|
|
bool reattached) override;
|
2021-05-14 18:58:55 +02:00
|
|
|
void UpdateDraggableRegions(
|
2024-03-19 22:11:42 +01:00
|
|
|
std::optional<std::vector<cef::mojom::DraggableRegionEntryPtr>> regions)
|
2021-05-14 18:58:55 +02:00
|
|
|
override;
|
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
bool is_temporary() const { return !frame_token_.has_value(); }
|
|
|
|
std::optional<content::GlobalRenderFrameHostToken> frame_token() const {
|
|
|
|
return frame_token_;
|
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2020-02-14 22:58:58 +01:00
|
|
|
// PageTransition type for explicit navigations. This must pass the check in
|
|
|
|
// ContentBrowserClient::IsExplicitNavigation for debug URLs (HandleDebugURL)
|
|
|
|
// to work as expected.
|
|
|
|
static const ui::PageTransition kPageTransitionExplicit;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
private:
|
2021-05-21 03:42:58 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> GetBrowserInfo() const;
|
2020-09-18 00:24:08 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> GetBrowserHostBase() const;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Send an action to the remote RenderFrame. This will queue the action if the
|
|
|
|
// remote frame is not yet attached.
|
2022-02-10 22:52:36 +01:00
|
|
|
using RenderFrameType = mojo::Remote<cef::mojom::RenderFrame>;
|
2021-05-14 18:58:55 +02:00
|
|
|
using RenderFrameAction = base::OnceCallback<void(const RenderFrameType&)>;
|
2021-05-21 03:42:58 +02:00
|
|
|
void SendToRenderFrame(const std::string& function_name,
|
|
|
|
RenderFrameAction action);
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
void OnRenderFrameDisconnect();
|
2021-09-15 13:40:08 +02:00
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
std::string GetDebugString() const;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
const bool is_main_frame_;
|
2024-01-26 03:12:43 +01:00
|
|
|
const std::optional<content::GlobalRenderFrameHostToken> frame_token_;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
// The following members are only modified on the UI thread but may be read
|
|
|
|
// from any thread. Any modification on the UI thread, or any access from
|
|
|
|
// non-UI threads, must be protected by |state_lock_|.
|
2019-05-24 22:23:43 +02:00
|
|
|
mutable base::Lock state_lock_;
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info_;
|
2012-04-03 03:34:16 +02:00
|
|
|
bool is_focused_;
|
|
|
|
CefString url_;
|
|
|
|
CefString name_;
|
2024-01-26 03:12:43 +01:00
|
|
|
std::optional<content::GlobalRenderFrameHostToken> parent_frame_token_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// The following members are only accessed on the UI thread.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<content::RenderFrameHost> render_frame_host_ = nullptr;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
std::queue<std::pair<std::string, RenderFrameAction>>
|
|
|
|
queued_renderer_actions_;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
mojo::Remote<cef::mojom::RenderFrame> render_frame_;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefFrameHostImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_FRAME_HOST_IMPL_H_
|