2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2011 The Chromium 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_BROWSER_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_RENDERER_BROWSER_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <map>
|
2019-05-24 22:23:43 +02:00
|
|
|
#include <memory>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "include/cef_client.h"
|
2012-04-27 23:19:06 +02:00
|
|
|
#include "libcef/common/tracker.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/frame_impl.h"
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "third_party/blink/public/web/web_view_observer.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
namespace blink {
|
2017-07-27 01:19:27 +02:00
|
|
|
class WebFrame;
|
2017-05-31 17:33:30 +02:00
|
|
|
class WebNode;
|
2022-07-21 19:26:10 +02:00
|
|
|
class WebView;
|
2017-07-27 01:19:27 +02:00
|
|
|
} // namespace blink
|
2017-05-31 17:33:30 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Renderer plumbing for CEF features. There is a one-to-one relationship
|
|
|
|
// between RenderView on the renderer side and RenderViewHost on the browser
|
|
|
|
// side.
|
|
|
|
//
|
2019-05-24 22:23:43 +02:00
|
|
|
// RenderViewObserver: Interface for observing RenderView notifications.
|
2021-03-04 23:36:57 +01:00
|
|
|
class CefBrowserImpl : public CefBrowser, public blink::WebViewObserver {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
|
|
|
// Returns the browser associated with the specified RenderView.
|
2022-07-21 19:26:10 +02:00
|
|
|
static CefRefPtr<CefBrowserImpl> GetBrowserForView(blink::WebView* view);
|
2012-04-03 03:34:16 +02:00
|
|
|
// Returns the browser associated with the specified main WebFrame.
|
|
|
|
static CefRefPtr<CefBrowserImpl> GetBrowserForMainFrame(
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebFrame* frame);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefBrowser methods.
|
2021-05-21 03:42:58 +02:00
|
|
|
bool IsValid() override;
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefBrowserHost> GetHost() override;
|
|
|
|
bool CanGoBack() override;
|
|
|
|
void GoBack() override;
|
|
|
|
bool CanGoForward() override;
|
|
|
|
void GoForward() override;
|
|
|
|
bool IsLoading() override;
|
|
|
|
void Reload() override;
|
|
|
|
void ReloadIgnoreCache() override;
|
|
|
|
void StopLoad() override;
|
|
|
|
int GetIdentifier() override;
|
|
|
|
bool IsSame(CefRefPtr<CefBrowser> that) override;
|
|
|
|
bool IsPopup() override;
|
|
|
|
bool HasDocument() override;
|
|
|
|
CefRefPtr<CefFrame> GetMainFrame() override;
|
|
|
|
CefRefPtr<CefFrame> GetFocusedFrame() override;
|
2023-06-01 16:06:15 +02:00
|
|
|
CefRefPtr<CefFrame> GetFrame(int64_t identifier) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefFrame> GetFrame(const CefString& name) override;
|
|
|
|
size_t GetFrameCount() override;
|
2023-06-01 16:06:15 +02:00
|
|
|
void GetFrameIdentifiers(std::vector<int64_t>& identifiers) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void GetFrameNames(std::vector<CefString>& names) override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-07-21 19:26:10 +02:00
|
|
|
CefBrowserImpl(blink::WebView* web_view,
|
2012-11-20 21:08:36 +01:00
|
|
|
int browser_id,
|
2014-07-01 00:30:29 +02:00
|
|
|
bool is_popup,
|
|
|
|
bool is_windowless);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefBrowserImpl(const CefBrowserImpl&) = delete;
|
|
|
|
CefBrowserImpl& operator=(const CefBrowserImpl&) = delete;
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefBrowserImpl() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Returns the matching CefFrameImpl reference or creates a new one.
|
2017-07-27 01:19:27 +02:00
|
|
|
CefRefPtr<CefFrameImpl> GetWebFrameImpl(blink::WebLocalFrame* frame);
|
2016-01-06 20:20:54 +01:00
|
|
|
CefRefPtr<CefFrameImpl> GetWebFrameImpl(int64_t frame_id);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
// Frame objects will be deleted immediately before the frame is closed.
|
2016-01-06 20:20:54 +01:00
|
|
|
void AddFrameObject(int64_t frame_id, CefTrackNode* tracked_object);
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
int browser_id() const { return browser_id_; }
|
|
|
|
bool is_popup() const { return is_popup_; }
|
2014-07-01 00:30:29 +02:00
|
|
|
bool is_windowless() const { return is_windowless_; }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
// blink::WebViewObserver methods.
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnDestruct() override;
|
2019-05-24 22:23:43 +02:00
|
|
|
void FrameDetached(int64_t frame_id);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
void OnLoadingStateChange(bool isLoading);
|
2022-04-05 19:22:32 +02:00
|
|
|
void OnEnterBFCache();
|
2019-05-24 22:23:43 +02:00
|
|
|
|
|
|
|
private:
|
2012-12-30 12:17:49 +01:00
|
|
|
// ID of the browser that this RenderView is associated with. During loading
|
|
|
|
// of cross-origin requests multiple RenderViews may be associated with the
|
|
|
|
// same browser ID.
|
|
|
|
int browser_id_;
|
2012-04-03 03:34:16 +02:00
|
|
|
bool is_popup_;
|
2014-07-01 00:30:29 +02:00
|
|
|
bool is_windowless_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Map of unique frame ids to CefFrameImpl references.
|
2023-06-01 16:06:15 +02:00
|
|
|
using FrameMap = std::map<int64_t, CefRefPtr<CefFrameImpl>>;
|
2012-04-03 03:34:16 +02:00
|
|
|
FrameMap frames_;
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
// True if the browser was in the BFCache.
|
|
|
|
bool was_in_bfcache_ = false;
|
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
// Map of unique frame ids to CefTrackManager objects that need to be cleaned
|
|
|
|
// up when the frame is deleted.
|
2023-06-01 16:06:15 +02:00
|
|
|
using FrameObjectMap = std::map<int64_t, CefRefPtr<CefTrackManager>>;
|
2012-04-27 23:19:06 +02:00
|
|
|
FrameObjectMap frame_objects_;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
struct LoadingState {
|
|
|
|
LoadingState(bool is_loading, bool can_go_back, bool can_go_forward)
|
|
|
|
: is_loading_(is_loading),
|
|
|
|
can_go_back_(can_go_back),
|
|
|
|
can_go_forward_(can_go_forward) {}
|
|
|
|
|
|
|
|
bool IsMatch(bool is_loading, bool can_go_back, bool can_go_forward) const {
|
|
|
|
return is_loading_ == is_loading && can_go_back_ == can_go_back &&
|
|
|
|
can_go_forward_ == can_go_forward;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_loading_;
|
|
|
|
bool can_go_back_;
|
|
|
|
bool can_go_forward_;
|
|
|
|
};
|
|
|
|
std::unique_ptr<LoadingState> last_loading_state_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefBrowserImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_RENDERER_BROWSER_IMPL_H_
|