2020-09-18 00:24:08 +02:00
|
|
|
// Copyright 2020 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_CHROME_CHROME_BROWSER_HOST_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_HOST_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2023-09-07 19:28:27 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_host_base.h"
|
|
|
|
#include "cef/libcef/browser/chrome/browser_delegate.h"
|
2023-11-14 18:16:43 +01:00
|
|
|
#include "chrome/browser/ui/browser.h"
|
2023-09-07 19:28:27 +02:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
class ChromeBrowserDelegate;
|
2023-09-07 19:28:27 +02:00
|
|
|
class ChromeBrowserView;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-06-26 02:12:37 +02:00
|
|
|
// CefBrowser implementation for Chrome style. Method calls are delegated
|
2020-09-18 00:24:08 +02:00
|
|
|
// to the chrome Browser object or the WebContents as appropriate. See the
|
|
|
|
// ChromeBrowserDelegate documentation for additional details. All methods are
|
|
|
|
// thread-safe unless otherwise indicated.
|
|
|
|
class ChromeBrowserHostImpl : public CefBrowserHostBase {
|
|
|
|
public:
|
|
|
|
// CEF-specific parameters passed via Browser::CreateParams::cef_params and
|
|
|
|
// possibly shared by multiple Browser instances.
|
|
|
|
class DelegateCreateParams : public cef::BrowserDelegate::CreateParams {
|
|
|
|
public:
|
2024-01-20 23:48:57 +01:00
|
|
|
explicit DelegateCreateParams(const CefBrowserCreateParams& create_params)
|
2020-09-18 00:24:08 +02:00
|
|
|
: create_params_(create_params) {}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserCreateParams create_params_;
|
2020-09-18 00:24:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create a new Browser with a single tab (WebContents) and associated
|
|
|
|
// ChromeBrowserHostImpl instance.
|
2020-09-25 03:40:47 +02:00
|
|
|
static CefRefPtr<ChromeBrowserHostImpl> Create(
|
|
|
|
const CefBrowserCreateParams& params);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Safe (checked) conversion from CefBrowserHostBase to ChromeBrowserHostImpl.
|
|
|
|
// Use this method instead of static_cast.
|
|
|
|
static CefRefPtr<ChromeBrowserHostImpl> FromBaseChecked(
|
|
|
|
CefRefPtr<CefBrowserHostBase> host_base);
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Returns the browser associated with the specified RenderViewHost.
|
|
|
|
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForHost(
|
|
|
|
const content::RenderViewHost* host);
|
|
|
|
// Returns the browser associated with the specified RenderFrameHost.
|
|
|
|
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForHost(
|
|
|
|
const content::RenderFrameHost* host);
|
|
|
|
// Returns the browser associated with the specified WebContents.
|
|
|
|
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForContents(
|
|
|
|
const content::WebContents* contents);
|
2021-08-19 23:07:44 +02:00
|
|
|
// Returns the browser associated with the specified global ID.
|
|
|
|
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForGlobalId(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id);
|
2022-03-21 22:22:07 +01:00
|
|
|
// Returns the browser associated with the specified Browser.
|
|
|
|
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForBrowser(
|
|
|
|
const Browser* browser);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
~ChromeBrowserHostImpl() override;
|
|
|
|
|
|
|
|
// CefBrowserContentsDelegate::Observer methods:
|
2020-09-25 03:40:47 +02:00
|
|
|
void OnWebContentsDestroyed(content::WebContents* web_contents) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// CefBrowserHostBase methods called from CefFrameHostImpl:
|
|
|
|
void OnSetFocus(cef_focus_source_t source) override;
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// CefBrowserHostBase methods:
|
|
|
|
bool IsWindowless() const override { return false; }
|
|
|
|
bool IsAlloyStyle() const override { return false; }
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// CefBrowserHost methods:
|
|
|
|
void CloseBrowser(bool force_close) override;
|
|
|
|
bool TryCloseBrowser() override;
|
|
|
|
CefWindowHandle GetWindowHandle() override;
|
|
|
|
CefWindowHandle GetOpenerWindowHandle() override;
|
2022-02-17 19:17:29 +01:00
|
|
|
void Find(const CefString& searchText,
|
2020-09-18 00:24:08 +02:00
|
|
|
bool forward,
|
|
|
|
bool matchCase,
|
|
|
|
bool findNext) override;
|
|
|
|
void StopFinding(bool clearSelection) override;
|
2024-04-17 18:01:26 +02:00
|
|
|
bool IsWindowRenderingDisabled() override { return false; }
|
2020-09-18 00:24:08 +02:00
|
|
|
void WasResized() override;
|
|
|
|
void WasHidden(bool hidden) override;
|
|
|
|
void NotifyScreenInfoChanged() override;
|
|
|
|
void Invalidate(PaintElementType type) override;
|
|
|
|
void SendExternalBeginFrame() override;
|
|
|
|
void SendTouchEvent(const CefTouchEvent& event) override;
|
|
|
|
void SendCaptureLostEvent() override;
|
|
|
|
int GetWindowlessFrameRate() override;
|
|
|
|
void SetWindowlessFrameRate(int frame_rate) override;
|
|
|
|
void ImeSetComposition(const CefString& text,
|
|
|
|
const std::vector<CefCompositionUnderline>& underlines,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
const CefRange& selection_range) override;
|
|
|
|
void ImeCommitText(const CefString& text,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
int relative_cursor_pos) override;
|
|
|
|
void ImeFinishComposingText(bool keep_selection) override;
|
|
|
|
void ImeCancelComposition() override;
|
|
|
|
void DragTargetDragEnter(CefRefPtr<CefDragData> drag_data,
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
DragOperationsMask allowed_ops) override;
|
|
|
|
void DragTargetDragOver(const CefMouseEvent& event,
|
|
|
|
DragOperationsMask allowed_ops) override;
|
|
|
|
void DragTargetDragLeave() override;
|
|
|
|
void DragTargetDrop(const CefMouseEvent& event) override;
|
|
|
|
void DragSourceSystemDragEnded() override;
|
|
|
|
void DragSourceEndedAt(int x, int y, DragOperationsMask op) override;
|
|
|
|
void SetAudioMuted(bool mute) override;
|
|
|
|
bool IsAudioMuted() override;
|
|
|
|
void SetAutoResizeEnabled(bool enabled,
|
|
|
|
const CefSize& min_size,
|
|
|
|
const CefSize& max_size) override;
|
2023-11-14 18:16:43 +01:00
|
|
|
bool CanExecuteChromeCommand(int command_id) override;
|
|
|
|
void ExecuteChromeCommand(int command_id,
|
|
|
|
cef_window_open_disposition_t disposition) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
Browser* browser() const { return browser_; }
|
|
|
|
|
|
|
|
// Return the CEF specialization of BrowserView.
|
|
|
|
ChromeBrowserView* chrome_browser_view() const;
|
|
|
|
|
|
|
|
base::WeakPtr<ChromeBrowserHostImpl> GetWeakPtr() {
|
|
|
|
return weak_ptr_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
protected:
|
|
|
|
bool Navigate(const content::OpenURLParams& params) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class ChromeBrowserDelegate;
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
ChromeBrowserHostImpl(
|
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
|
|
|
CefRefPtr<CefRequestContextImpl> request_context);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2021-04-02 22:53:17 +02:00
|
|
|
// Create a new Browser without initializing the WebContents.
|
2023-11-14 18:16:43 +01:00
|
|
|
// |browser_create_params| may be empty for default Browser creation behavior.
|
|
|
|
static Browser* CreateBrowser(
|
|
|
|
const CefBrowserCreateParams& params,
|
|
|
|
std::optional<Browser::CreateParams> browser_create_params);
|
2021-04-02 22:53:17 +02:00
|
|
|
|
|
|
|
// Called from ChromeBrowserDelegate::CreateBrowser when this object is first
|
2020-09-18 00:24:08 +02:00
|
|
|
// created. Must be called on the UI thread.
|
2021-04-02 22:53:17 +02:00
|
|
|
void Attach(content::WebContents* web_contents,
|
2023-11-14 18:16:43 +01:00
|
|
|
bool is_devtools_popup,
|
2024-04-17 18:01:26 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> opener);
|
2021-04-02 22:53:17 +02:00
|
|
|
|
|
|
|
// Called from ChromeBrowserDelegate::AddNewContents to take ownership of a
|
2023-11-14 18:16:43 +01:00
|
|
|
// popup WebContents. |browser_create_params| may be empty for default Browser
|
|
|
|
// creation behavior.
|
|
|
|
void AddNewContents(
|
|
|
|
std::unique_ptr<content::WebContents> contents,
|
|
|
|
std::optional<Browser::CreateParams> browser_create_params);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2021-04-02 22:53:17 +02:00
|
|
|
// Called when this object changes Browser ownership (e.g. initially created,
|
|
|
|
// dragging between windows, etc). The old Browser, if any, will be cleared
|
|
|
|
// before the new Browser is added. Must be called on the UI thread.
|
2020-09-18 00:24:08 +02:00
|
|
|
void SetBrowser(Browser* browser);
|
|
|
|
|
|
|
|
// CefBrowserHostBase methods:
|
2021-02-18 02:58:25 +01:00
|
|
|
void WindowDestroyed() override;
|
2022-06-02 11:49:50 +02:00
|
|
|
bool WillBeDestroyed() const override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void DestroyBrowser() override;
|
|
|
|
|
2024-10-17 17:05:30 +02:00
|
|
|
void DoCloseBrowser();
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Returns the current tab index for the associated WebContents, or
|
|
|
|
// TabStripModel::kNoTab if not found.
|
|
|
|
int GetCurrentTabIndex() const;
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<Browser> browser_ = nullptr;
|
2022-04-19 19:45:03 +02:00
|
|
|
CefWindowHandle host_window_handle_ = kNullWindowHandle;
|
2024-05-13 23:36:09 +02:00
|
|
|
bool is_destroying_browser_ = false;
|
2023-09-07 19:28:27 +02:00
|
|
|
|
|
|
|
base::WeakPtrFactory<ChromeBrowserHostImpl> weak_ptr_factory_{this};
|
2020-09-18 00:24:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_HOST_IMPL_H_
|