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
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_frame.h"
|
|
|
|
#include "include/cef_v8.h"
|
2022-04-05 19:22:32 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2012-04-03 03:34:16 +02: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"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "cef/libcef/common/mojom/cef.mojom.h"
|
|
|
|
#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;
|
2020-12-02 23:31:49 +01:00
|
|
|
class WebURLLoader;
|
2019-05-11 00:14:48 +02:00
|
|
|
class WebURLLoaderFactory;
|
|
|
|
} // 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:
|
2018-07-09 20:36:37 +02:00
|
|
|
CefFrameImpl(CefBrowserImpl* browser,
|
|
|
|
blink::WebLocalFrame* frame,
|
|
|
|
int64_t frame_id);
|
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;
|
|
|
|
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;
|
|
|
|
int64 GetIdentifier() override;
|
|
|
|
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
|
|
|
|
|
|
|
// Used by CefRenderURLRequest.
|
2020-12-02 23:31:49 +01:00
|
|
|
std::unique_ptr<blink::WebURLLoader> CreateURLLoader();
|
|
|
|
std::unique_ptr<blink::ResourceLoadInfoNotifierWrapper>
|
|
|
|
CreateResourceLoadInfoNotifierWrapper();
|
2012-04-03 03:34:16 +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();
|
|
|
|
void OnDraggableRegionsChanged();
|
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:
|
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-02-10 22:52:36 +01:00
|
|
|
// Initiate the connection to the BrowserFrame channel.
|
|
|
|
void ConnectBrowserFrame();
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Called if/when the BrowserFrame channel is disconnected. 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).
|
|
|
|
void OnBrowserFrameDisconnect();
|
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:
|
2022-02-10 22:52:36 +01:00
|
|
|
void FrameAttachedAck() override;
|
2021-05-14 18:58:55 +02:00
|
|
|
void SendMessage(const std::string& name, base::Value arguments) override;
|
2022-07-04 11:49:15 +02:00
|
|
|
void SendSharedMemoryRegion(const std::string& name,
|
|
|
|
base::ReadOnlySharedMemoryRegion 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;
|
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_;
|
2019-05-24 22:23:43 +02:00
|
|
|
const int64 frame_id_;
|
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_;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
base::OneShotTimer browser_connect_timer_;
|
|
|
|
|
|
|
|
std::queue<std::pair<std::string, BrowserFrameAction>>
|
|
|
|
queued_browser_actions_;
|
2021-05-21 03:42:58 +02:00
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
std::unique_ptr<blink::WebURLLoaderFactory> url_loader_factory_;
|
|
|
|
|
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_
|