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_BROWSER_HOST_BASE_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_BROWSER_HOST_BASE_H_
|
|
|
|
#pragma once
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
#include "base/observer_list.h"
|
|
|
|
#include "base/synchronization/lock.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_browser.h"
|
|
|
|
#include "cef/include/cef_client.h"
|
|
|
|
#include "cef/include/cef_unresponsive_process_callback.h"
|
|
|
|
#include "cef/include/views/cef_browser_view.h"
|
|
|
|
#include "cef/libcef/browser/browser_contents_delegate.h"
|
|
|
|
#include "cef/libcef/browser/browser_info.h"
|
|
|
|
#include "cef/libcef/browser/browser_platform_delegate.h"
|
|
|
|
#include "cef/libcef/browser/devtools/devtools_protocol_manager.h"
|
|
|
|
#include "cef/libcef/browser/devtools/devtools_window_runner.h"
|
|
|
|
#include "cef/libcef/browser/file_dialog_manager.h"
|
|
|
|
#include "cef/libcef/browser/frame_host_impl.h"
|
2024-06-04 18:19:14 +02:00
|
|
|
#include "cef/libcef/browser/javascript_dialog_manager.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/media_stream_registrar.h"
|
|
|
|
#include "cef/libcef/browser/request_context_impl.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
class RenderViewContextMenuObserver;
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Parameters that are passed to the runtime-specific Create methods.
|
|
|
|
struct CefBrowserCreateParams {
|
2024-01-20 23:48:57 +01:00
|
|
|
CefBrowserCreateParams() = default;
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Copy constructor used with Chrome style only.
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserCreateParams(const CefBrowserCreateParams& that) {
|
|
|
|
operator=(that);
|
|
|
|
}
|
|
|
|
CefBrowserCreateParams& operator=(const CefBrowserCreateParams& that) {
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK(that.IsChromeStyle());
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Not all parameters can be copied.
|
|
|
|
client = that.client;
|
|
|
|
url = that.url;
|
|
|
|
settings = that.settings;
|
|
|
|
request_context = that.request_context;
|
|
|
|
extra_info = that.extra_info;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (that.window_info) {
|
2024-04-17 18:01:26 +02:00
|
|
|
MaybeSetWindowInfo(*that.window_info, /*allow_alloy_style=*/false,
|
|
|
|
/*allow_chrome_style=*/true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-02-18 02:58:25 +01:00
|
|
|
browser_view = that.browser_view;
|
2020-09-25 03:40:47 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Initialize |window_info| with expected defaults before passing to a client
|
|
|
|
// callback. |opener| will be non-nullptr for popups, DevTools windows, etc.
|
|
|
|
static void InitWindowInfo(CefWindowInfo* window_info,
|
|
|
|
CefBrowserHostBase* opener);
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
// Set |window_info| if appropriate (see below).
|
2024-04-17 18:01:26 +02:00
|
|
|
void MaybeSetWindowInfo(const CefWindowInfo& window_info,
|
|
|
|
bool allow_alloy_style,
|
|
|
|
bool allow_chrome_style);
|
|
|
|
|
|
|
|
// Returns true if |window_info| indicates creation of a Chrome style window.
|
|
|
|
static bool IsChromeStyle(const CefWindowInfo* window_info);
|
|
|
|
bool IsChromeStyle() const;
|
|
|
|
|
|
|
|
// Returns true if parameters indicate windowless (off-screen) rendering.
|
|
|
|
bool IsWindowless() const;
|
2022-04-08 22:48:56 +02:00
|
|
|
|
|
|
|
// Platform-specific window creation info. Will be nullptr for Views-hosted
|
2024-06-26 02:12:37 +02:00
|
|
|
// browsers except when using Chrome style with a native parent handle.
|
2020-09-25 03:40:47 +02:00
|
|
|
std::unique_ptr<CefWindowInfo> window_info;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
// The BrowserView that will own a Views-hosted browser. Will be nullptr for
|
2021-04-02 22:53:17 +02:00
|
|
|
// popup browsers.
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefBrowserView> browser_view;
|
2021-04-02 22:53:17 +02:00
|
|
|
|
|
|
|
// True if this browser is a popup and has a Views-hosted opener, in which
|
|
|
|
// case the BrowserView for this browser will be created later (from
|
|
|
|
// PopupWebContentsCreated).
|
|
|
|
bool popup_with_views_hosted_opener = false;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// True if this browser is a popup and has an Alloy style opener. Only used
|
2024-06-26 02:12:37 +02:00
|
|
|
// with Chrome style.
|
2024-04-17 18:01:26 +02:00
|
|
|
bool popup_with_alloy_style_opener = false;
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Client implementation. May be nullptr.
|
|
|
|
CefRefPtr<CefClient> client;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Initial URL to load. May be empty. If this is a valid extension URL then
|
|
|
|
// the browser will be created as an app view extension host.
|
2021-04-15 01:28:22 +02:00
|
|
|
CefString url;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Browser settings.
|
|
|
|
CefBrowserSettings settings;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Request context to use when creating the browser. If nullptr the global
|
|
|
|
// request context will be used.
|
|
|
|
CefRefPtr<CefRequestContext> request_context;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Extra information that will be passed to
|
|
|
|
// CefRenderProcessHandler::OnBrowserCreated.
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info;
|
|
|
|
};
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Base class for CefBrowserHost implementations. Includes functionality that is
|
2024-06-26 02:12:37 +02:00
|
|
|
// shared by Alloy and Chrome styles. All methods are thread-safe unless
|
2020-09-25 03:40:47 +02:00
|
|
|
// otherwise indicated.
|
|
|
|
class CefBrowserHostBase : public CefBrowserHost,
|
|
|
|
public CefBrowser,
|
|
|
|
public CefBrowserContentsDelegate::Observer {
|
|
|
|
public:
|
2020-09-18 00:24:08 +02:00
|
|
|
// Interface to implement for observers that wish to be informed of changes
|
|
|
|
// to the CefBrowserHostBase. All methods will be called on the UI thread.
|
|
|
|
class Observer : public base::CheckedObserver {
|
|
|
|
public:
|
|
|
|
// Called before |browser| is destroyed. Any references to |browser| should
|
|
|
|
// be cleared when this method is called.
|
|
|
|
virtual void OnBrowserDestroyed(CefBrowserHostBase* browser) = 0;
|
|
|
|
|
|
|
|
protected:
|
2024-01-20 23:48:57 +01:00
|
|
|
~Observer() override = default;
|
2020-09-18 00:24:08 +02:00
|
|
|
};
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
// Create a new CefBrowserHost instance of the current runtime type with
|
|
|
|
// owned WebContents.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> Create(
|
|
|
|
CefBrowserCreateParams& create_params);
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Safe conversion from CefBrowserHostBase to CefBrowserHostBase.
|
|
|
|
// Use this method instead of static_cast.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> FromBrowser(
|
|
|
|
CefRefPtr<CefBrowser> browser);
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Returns the browser associated with the specified RenderViewHost.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForHost(
|
|
|
|
const content::RenderViewHost* host);
|
|
|
|
// Returns the browser associated with the specified RenderFrameHost.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForHost(
|
|
|
|
const content::RenderFrameHost* host);
|
|
|
|
// Returns the browser associated with the specified WebContents.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForContents(
|
|
|
|
const content::WebContents* contents);
|
2021-08-19 23:07:44 +02:00
|
|
|
// Returns the browser associated with the specified global ID.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForGlobalId(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id);
|
2024-01-26 03:12:43 +01:00
|
|
|
// Returns the browser associated with the specified global token.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForGlobalToken(
|
|
|
|
const content::GlobalRenderFrameHostToken& global_token);
|
2022-06-02 11:49:50 +02:00
|
|
|
// Returns the browser associated with the specified top-level window.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForTopLevelNativeWindow(
|
|
|
|
gfx::NativeWindow owning_window);
|
2024-07-19 17:19:06 +02:00
|
|
|
// Returns the browser associated with the specified browser ID.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForBrowserId(int browser_id);
|
2022-06-02 11:49:50 +02:00
|
|
|
|
|
|
|
// Returns the browser most likely to be focused. This may be somewhat iffy
|
|
|
|
// with windowless browsers as there is no guarantee that the client has only
|
|
|
|
// one browser focused at a time.
|
|
|
|
static CefRefPtr<CefBrowserHostBase> GetLikelyFocusedBrowser();
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserHostBase(
|
|
|
|
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-12-06 21:40:25 +01:00
|
|
|
CefBrowserHostBase(const CefBrowserHostBase&) = delete;
|
|
|
|
CefBrowserHostBase& operator=(const CefBrowserHostBase&) = delete;
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Called on the UI thread after the associated WebContents is created.
|
|
|
|
virtual void InitializeBrowser();
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
// Called on the UI thread when the OS window hosting the browser is
|
|
|
|
// destroyed.
|
|
|
|
virtual void WindowDestroyed() = 0;
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
// Returns true if the browser is in the process of being destroyed. Called on
|
|
|
|
// the UI thread only.
|
|
|
|
virtual bool WillBeDestroyed() const = 0;
|
|
|
|
|
2024-05-13 23:36:09 +02:00
|
|
|
// Called on the UI thread to complete WebContents tear-down. In most cases
|
|
|
|
// this will be called via WebContentsObserver::WebContentsDestroyed. Any
|
|
|
|
// remaining objects that reference the WebContents (including RFH, etc)
|
|
|
|
// should be cleared in this callback.
|
|
|
|
virtual void DestroyWebContents(content::WebContents* web_contents);
|
|
|
|
|
|
|
|
// Called on the UI thread to complete CefBrowserHost tear-down.
|
|
|
|
//
|
|
|
|
// With Chrome style the WebContents is owned by the Browser's TabStripModel
|
|
|
|
// and will usually be destroyed first: CloseBrowser -> (async) DoCloseBrowser
|
|
|
|
// -> [TabStripModel deletes the WebContents] -> OnWebContentsDestroyed ->
|
|
|
|
// DestroyWebContents -> (async) DestroyBrowser.
|
|
|
|
//
|
|
|
|
// With Alloy style the WebContents is owned by the
|
|
|
|
// CefBrowserPlatformDelegateAlloy and will usually be destroyed at the same
|
|
|
|
// time: CloseBrowser -> [OS/platform logic] -> (async) DestroyBrowser ->
|
|
|
|
// [CefBrowserPlatformDelegateAlloy deletes the WebContents]
|
|
|
|
// -> WebContentsDestroyed -> DestoyWebContents.
|
|
|
|
//
|
|
|
|
// There are a few exceptions to the above rules:
|
|
|
|
// 1. If the CefBrowserHost still exists at CefShutdown, in which case
|
|
|
|
// DestroyBrowser will be called first via
|
|
|
|
// CefBrowserInfoManager::DestroyAllBrowsers.
|
|
|
|
// 2. If a popup WebContents is still pending when the parent WebContents is
|
|
|
|
// destroyed, in which case WebContentsDestroyed will be called first via
|
|
|
|
// the parent WebContents destructor.
|
2020-09-18 00:24:08 +02:00
|
|
|
virtual void DestroyBrowser();
|
|
|
|
|
|
|
|
// CefBrowserHost methods:
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() override;
|
|
|
|
CefRefPtr<CefClient> GetClient() override;
|
|
|
|
CefRefPtr<CefRequestContext> GetRequestContext() override;
|
2023-10-05 01:46:45 +02:00
|
|
|
bool CanZoom(cef_zoom_command_t command) override;
|
|
|
|
void Zoom(cef_zoom_command_t command) override;
|
|
|
|
double GetDefaultZoomLevel() override;
|
|
|
|
double GetZoomLevel() override;
|
|
|
|
void SetZoomLevel(double zoomLevel) override;
|
2021-02-18 02:58:25 +01:00
|
|
|
bool HasView() override;
|
2022-04-08 22:48:56 +02:00
|
|
|
void SetFocus(bool focus) override;
|
2022-04-15 21:55:23 +02:00
|
|
|
void RunFileDialog(FileDialogMode mode,
|
|
|
|
const CefString& title,
|
|
|
|
const CefString& default_file_path,
|
|
|
|
const std::vector<CefString>& accept_filters,
|
|
|
|
CefRefPtr<CefRunFileDialogCallback> callback) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void StartDownload(const CefString& url) override;
|
|
|
|
void DownloadImage(const CefString& image_url,
|
|
|
|
bool is_favicon,
|
2023-06-01 16:06:15 +02:00
|
|
|
uint32_t max_image_size,
|
2020-09-18 00:24:08 +02:00
|
|
|
bool bypass_cache,
|
|
|
|
CefRefPtr<CefDownloadImageCallback> callback) override;
|
2022-10-12 23:53:06 +02:00
|
|
|
void Print() override;
|
|
|
|
void PrintToPDF(const CefString& path,
|
|
|
|
const CefPdfPrintSettings& settings,
|
|
|
|
CefRefPtr<CefPdfPrintCallback> callback) override;
|
2023-11-14 18:16:43 +01:00
|
|
|
void ShowDevTools(const CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
const CefPoint& inspect_element_at) override;
|
2024-04-17 18:01:26 +02:00
|
|
|
void CloseDevTools() override;
|
|
|
|
bool HasDevTools() override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void ReplaceMisspelling(const CefString& word) override;
|
|
|
|
void AddWordToDictionary(const CefString& word) override;
|
2020-09-25 03:40:47 +02:00
|
|
|
void SendKeyEvent(const CefKeyEvent& event) override;
|
|
|
|
void SendMouseClickEvent(const CefMouseEvent& event,
|
|
|
|
MouseButtonType type,
|
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) override;
|
|
|
|
void SendMouseMoveEvent(const CefMouseEvent& event, bool mouseLeave) override;
|
|
|
|
void SendMouseWheelEvent(const CefMouseEvent& event,
|
|
|
|
int deltaX,
|
|
|
|
int deltaY) override;
|
2021-03-18 18:17:33 +01:00
|
|
|
bool SendDevToolsMessage(const void* message, size_t message_size) override;
|
|
|
|
int ExecuteDevToolsMethod(int message_id,
|
|
|
|
const CefString& method,
|
|
|
|
CefRefPtr<CefDictionaryValue> params) override;
|
|
|
|
CefRefPtr<CefRegistration> AddDevToolsMessageObserver(
|
|
|
|
CefRefPtr<CefDevToolsMessageObserver> observer) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void GetNavigationEntries(CefRefPtr<CefNavigationEntryVisitor> visitor,
|
|
|
|
bool current_only) override;
|
|
|
|
CefRefPtr<CefNavigationEntry> GetVisibleNavigationEntry() override;
|
2022-04-08 22:48:56 +02:00
|
|
|
void NotifyMoveOrResizeStarted() override;
|
2023-11-07 22:40:29 +01:00
|
|
|
bool IsFullscreen() override;
|
|
|
|
void ExitFullscreen(bool will_cause_resize) override;
|
2024-03-12 20:47:10 +01:00
|
|
|
bool IsRenderProcessUnresponsive() override;
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t GetRuntimeStyle() override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// CefBrowser methods:
|
2021-05-21 03:42:58 +02:00
|
|
|
bool IsValid() override;
|
2020-09-18 00:24:08 +02:00
|
|
|
CefRefPtr<CefBrowserHost> GetHost() override;
|
|
|
|
bool CanGoBack() override;
|
2020-09-25 03:40:47 +02:00
|
|
|
void GoBack() override;
|
2020-09-18 00:24:08 +02:00
|
|
|
bool CanGoForward() override;
|
2020-09-25 03:40:47 +02:00
|
|
|
void GoForward() override;
|
2020-09-18 00:24:08 +02:00
|
|
|
bool IsLoading() override;
|
2020-09-25 03:40:47 +02:00
|
|
|
void Reload() override;
|
|
|
|
void ReloadIgnoreCache() override;
|
|
|
|
void StopLoad() override;
|
2020-09-18 00:24:08 +02:00
|
|
|
int GetIdentifier() override;
|
|
|
|
bool IsSame(CefRefPtr<CefBrowser> that) override;
|
|
|
|
bool HasDocument() override;
|
|
|
|
bool IsPopup() override;
|
|
|
|
CefRefPtr<CefFrame> GetMainFrame() override;
|
|
|
|
CefRefPtr<CefFrame> GetFocusedFrame() override;
|
2024-01-26 03:12:43 +01:00
|
|
|
CefRefPtr<CefFrame> GetFrameByIdentifier(
|
|
|
|
const CefString& identifier) override;
|
|
|
|
CefRefPtr<CefFrame> GetFrameByName(const CefString& name) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
size_t GetFrameCount() override;
|
2024-01-26 03:12:43 +01:00
|
|
|
void GetFrameIdentifiers(std::vector<CefString>& identifiers) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void GetFrameNames(std::vector<CefString>& names) override;
|
2024-02-20 17:27:48 +01:00
|
|
|
void SetAccessibilityState(cef_state_t accessibility_state) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// CefBrowserContentsDelegate::Observer methods:
|
|
|
|
void OnStateChanged(CefBrowserContentsState state_changed) override;
|
2020-09-25 03:40:47 +02:00
|
|
|
void OnWebContentsDestroyed(content::WebContents* web_contents) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Returns the frame object matching the specified |host| or nullptr if no
|
2024-04-24 23:23:47 +02:00
|
|
|
// match is found. Must be called on the UI thread.
|
|
|
|
CefRefPtr<CefFrame> GetFrameForHost(const content::RenderFrameHost* host);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
// Returns the frame associated with the specified global ID/token. See
|
|
|
|
// documentation on RenderFrameHost::GetFrameTreeNodeId/Token() for why the
|
|
|
|
// global ID/token is preferred.
|
2021-08-19 23:07:44 +02:00
|
|
|
CefRefPtr<CefFrame> GetFrameForGlobalId(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id);
|
2024-01-26 03:12:43 +01:00
|
|
|
CefRefPtr<CefFrame> GetFrameForGlobalToken(
|
|
|
|
const content::GlobalRenderFrameHostToken& global_token);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// Manage observer objects. The observer must either outlive this object or
|
|
|
|
// be removed before destruction. Must be called on the UI thread.
|
|
|
|
void AddObserver(Observer* observer);
|
|
|
|
void RemoveObserver(Observer* observer);
|
|
|
|
bool HasObserver(Observer* observer) const;
|
|
|
|
|
|
|
|
// Methods called from CefFrameHostImpl.
|
2020-09-25 03:40:47 +02:00
|
|
|
void LoadMainFrameURL(const content::OpenURLParams& params);
|
2020-09-18 00:24:08 +02:00
|
|
|
virtual void OnSetFocus(cef_focus_source_t source) = 0;
|
2020-09-25 03:40:47 +02:00
|
|
|
void ViewText(const std::string& text);
|
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
// Calls CefFileDialogManager methods.
|
|
|
|
void RunFileChooserForBrowser(
|
|
|
|
const blink::mojom::FileChooserParams& params,
|
|
|
|
CefFileDialogManager::RunFileChooserCallback callback);
|
|
|
|
void RunSelectFile(ui::SelectFileDialog::Listener* listener,
|
|
|
|
std::unique_ptr<ui::SelectFilePolicy> policy,
|
|
|
|
ui::SelectFileDialog::Type type,
|
|
|
|
const std::u16string& title,
|
|
|
|
const base::FilePath& default_path,
|
|
|
|
const ui::SelectFileDialog::FileTypeInfo* file_types,
|
|
|
|
int file_type_index,
|
|
|
|
const base::FilePath::StringType& default_extension,
|
2024-07-29 19:09:20 +02:00
|
|
|
gfx::NativeWindow owning_window);
|
2022-04-15 21:55:23 +02:00
|
|
|
void SelectFileListenerDestroyed(ui::SelectFileDialog::Listener* listener);
|
|
|
|
|
2024-06-04 18:19:14 +02:00
|
|
|
// Called from AlloyBrowserHostImpl::GetJavaScriptDialogManager and
|
|
|
|
// ChromeBrowserDelegate::GetJavaScriptDialogManager.
|
|
|
|
content::JavaScriptDialogManager* GetJavaScriptDialogManager();
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Called from CefBrowserInfoManager::MaybeAllowNavigation.
|
|
|
|
virtual bool MaybeAllowNavigation(content::RenderFrameHost* opener,
|
|
|
|
const content::OpenURLParams& params);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// Helpers for executing client callbacks. Must be called on the UI thread.
|
|
|
|
void OnAfterCreated();
|
|
|
|
void OnBeforeClose();
|
|
|
|
void OnBrowserDestroyed();
|
|
|
|
|
|
|
|
// Thread-safe accessors.
|
|
|
|
const CefBrowserSettings& settings() const { return settings_; }
|
|
|
|
CefRefPtr<CefClient> client() const { return client_; }
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info() const { return browser_info_; }
|
|
|
|
int browser_id() const;
|
|
|
|
CefRefPtr<CefRequestContextImpl> request_context() const {
|
|
|
|
return request_context_;
|
|
|
|
}
|
2021-02-18 02:58:25 +01:00
|
|
|
bool is_views_hosted() const { return is_views_hosted_; }
|
2021-04-18 03:12:54 +02:00
|
|
|
SkColor GetBackgroundColor() const;
|
|
|
|
|
|
|
|
// Returns true if windowless rendering is enabled.
|
2024-04-17 18:01:26 +02:00
|
|
|
virtual bool IsWindowless() const = 0;
|
|
|
|
|
|
|
|
// Returns the runtime style of this browser.
|
|
|
|
virtual bool IsAlloyStyle() const = 0;
|
|
|
|
bool IsChromeStyle() const { return !IsAlloyStyle(); }
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// Accessors that must be called on the UI thread.
|
|
|
|
content::WebContents* GetWebContents() const;
|
|
|
|
content::BrowserContext* GetBrowserContext() const;
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserPlatformDelegate* platform_delegate() const {
|
|
|
|
return platform_delegate_.get();
|
|
|
|
}
|
2024-07-18 19:50:37 +02:00
|
|
|
CefBrowserContentsDelegate* contents_delegate() {
|
|
|
|
return &contents_delegate_;
|
2020-09-18 00:24:08 +02:00
|
|
|
}
|
2022-06-30 14:22:28 +02:00
|
|
|
CefMediaStreamRegistrar* GetMediaStreamRegistrar();
|
2024-04-17 18:01:26 +02:00
|
|
|
CefDevToolsWindowRunner* GetDevToolsWindowRunner();
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
CefRefPtr<CefUnresponsiveProcessCallback> unresponsive_process_callback()
|
|
|
|
const {
|
|
|
|
return unresponsive_process_callback_;
|
|
|
|
}
|
|
|
|
void set_unresponsive_process_callback(
|
|
|
|
CefRefPtr<CefUnresponsiveProcessCallback> callback) {
|
|
|
|
unresponsive_process_callback_ = callback;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
RenderViewContextMenuObserver* context_menu_observer() const {
|
|
|
|
return context_menu_observer_;
|
|
|
|
}
|
|
|
|
void set_context_menu_observer(RenderViewContextMenuObserver* observer) {
|
|
|
|
context_menu_observer_ = observer;
|
|
|
|
}
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
// Returns the Widget owner for the browser window. Only used with windowed
|
2022-04-15 21:55:23 +02:00
|
|
|
// browsers.
|
2021-02-18 02:58:25 +01:00
|
|
|
views::Widget* GetWindowWidget() const;
|
|
|
|
|
|
|
|
// Returns the BrowserView associated with this browser. Only used with Views-
|
|
|
|
// based browsers.
|
|
|
|
CefRefPtr<CefBrowserView> GetBrowserView() const;
|
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
// Returns the top-level native window for this browser. With windowed
|
|
|
|
// browsers this will be an aura::Window* on Aura platforms (Windows/Linux)
|
|
|
|
// and an NSWindow wrapper object from native_widget_types.h on MacOS. With
|
|
|
|
// windowless browsers this method will always return an empty value.
|
|
|
|
gfx::NativeWindow GetTopLevelNativeWindow() const;
|
|
|
|
|
|
|
|
// Returns true if this browser is currently focused. A browser is considered
|
|
|
|
// focused when the top-level RenderFrameHost is in the parent chain of the
|
|
|
|
// currently focused RFH within the frame tree. In addition, its associated
|
|
|
|
// RenderWidgetHost must also be focused. With windowed browsers only one
|
|
|
|
// browser should be focused at a time. With windowless browsers this relies
|
|
|
|
// on the client to properly configure focus state.
|
|
|
|
bool IsFocused() const;
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
// Returns true if this browser is currently visible.
|
|
|
|
virtual bool IsVisible() const;
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
protected:
|
2024-04-17 18:01:26 +02:00
|
|
|
bool EnsureDevToolsProtocolManager();
|
2021-03-18 18:17:33 +01:00
|
|
|
void InitializeDevToolsRegistrationOnUIThread(
|
|
|
|
CefRefPtr<CefRegistration> registration);
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Called from LoadMainFrameURL to perform the actual navigation.
|
|
|
|
virtual bool Navigate(const content::OpenURLParams& params);
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// Called from ShowDevTools to perform the actual show.
|
2024-04-17 18:01:26 +02:00
|
|
|
void ShowDevToolsOnUIThread(std::unique_ptr<CefShowDevToolsParams> params);
|
2023-11-14 18:16:43 +01:00
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
// Create the CefFileDialogManager if it doesn't already exist.
|
|
|
|
bool EnsureFileDialogManager();
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Thread-safe members.
|
|
|
|
CefBrowserSettings settings_;
|
|
|
|
CefRefPtr<CefClient> client_;
|
2020-09-25 03:40:47 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate_;
|
2020-09-18 00:24:08 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info_;
|
|
|
|
CefRefPtr<CefRequestContextImpl> request_context_;
|
2021-02-18 02:58:25 +01:00
|
|
|
const bool is_views_hosted_;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// Only accessed on the UI thread.
|
2024-07-18 19:50:37 +02:00
|
|
|
CefBrowserContentsDelegate contents_delegate_;
|
2024-03-12 20:47:10 +01:00
|
|
|
CefRefPtr<CefUnresponsiveProcessCallback> unresponsive_process_callback_;
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<RenderViewContextMenuObserver> context_menu_observer_ = nullptr;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// Observers that want to be notified of changes to this object.
|
|
|
|
// Only accessed on the UI thread.
|
|
|
|
base::ObserverList<Observer> observers_;
|
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
// Used for creating and managing file dialogs.
|
|
|
|
std::unique_ptr<CefFileDialogManager> file_dialog_manager_;
|
|
|
|
|
2024-06-04 18:19:14 +02:00
|
|
|
// Used for creating and managing JavaScript dialogs.
|
|
|
|
std::unique_ptr<CefJavaScriptDialogManager> javascript_dialog_manager_;
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Volatile state accessed from multiple threads. All access must be protected
|
|
|
|
// by |state_lock_|.
|
|
|
|
base::Lock state_lock_;
|
|
|
|
bool is_loading_ = false;
|
|
|
|
bool can_go_back_ = false;
|
|
|
|
bool can_go_forward_ = false;
|
|
|
|
bool has_document_ = false;
|
|
|
|
bool is_fullscreen_ = false;
|
|
|
|
CefRefPtr<CefFrameHostImpl> focused_frame_;
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Used for managing DevTools instances without a frontend.
|
|
|
|
std::unique_ptr<CefDevToolsProtocolManager> devtools_protocol_manager_;
|
|
|
|
|
|
|
|
// Used for creating and running the DevTools window frontend.
|
|
|
|
std::unique_ptr<CefDevToolsWindowRunner> devtools_window_runner_;
|
2021-03-18 18:17:33 +01:00
|
|
|
|
2022-06-30 14:22:28 +02:00
|
|
|
std::unique_ptr<CefMediaStreamRegistrar> media_stream_registrar_;
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
private:
|
|
|
|
IMPLEMENT_REFCOUNTING(CefBrowserHostBase);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_BROWSER_HOST_BASE_H_
|