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_DELEGATE_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_DELEGATE_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_host_base.h"
|
|
|
|
#include "libcef/browser/browser_info.h"
|
|
|
|
#include "libcef/browser/chrome/browser_delegate.h"
|
|
|
|
|
2021-06-04 03:34:56 +02:00
|
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
class CefBrowserContentsDelegate;
|
|
|
|
class CefRequestContextImpl;
|
|
|
|
class ChromeBrowserHostImpl;
|
|
|
|
|
|
|
|
// Implementation of the cef::BrowserDelegate interface. Lifespan is controlled
|
|
|
|
// by the Browser object. Only accessed on the UI thread.
|
|
|
|
//
|
|
|
|
// The Browser object represents the top-level Chrome browser window. One or
|
|
|
|
// more tabs (WebContents) are then owned by the Browser object via
|
|
|
|
// TabStripModel. A new Browser object can be created programmatically using
|
|
|
|
// "new Browser" or Browser::Create, or as a result of user action such as
|
|
|
|
// dragging a tab out of an existing window. New or existing tabs can also be
|
|
|
|
// added to an already existing Browser object.
|
|
|
|
//
|
|
|
|
// The Browser object acts as the WebContentsDelegate for all attached tabs. CEF
|
|
|
|
// integration requires WebContentsDelegate callbacks and notification of tab
|
|
|
|
// attach/detach. To support this integration a cef::BrowserDelegate
|
|
|
|
// (ChromeBrowserDelegate) member is created in the Browser constructor and
|
|
|
|
// receives delegation for the Browser callbacks. ChromeBrowserDelegate creates
|
|
|
|
// a new ChromeBrowserHostImpl when a tab is added to a Browser for the first
|
|
|
|
// time, and that ChromeBrowserHostImpl continues to exist until the tab's
|
|
|
|
// WebContents is destroyed. The associated WebContents object does not change,
|
|
|
|
// but the Browser object will change when the tab is dragged between windows.
|
|
|
|
class ChromeBrowserDelegate : public cef::BrowserDelegate {
|
|
|
|
public:
|
|
|
|
ChromeBrowserDelegate(Browser* browser,
|
2023-09-07 19:28:27 +02:00
|
|
|
const CefBrowserCreateParams& create_params,
|
|
|
|
const Browser* opener);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
ChromeBrowserDelegate(const ChromeBrowserDelegate&) = delete;
|
|
|
|
ChromeBrowserDelegate& operator=(const ChromeBrowserDelegate&) = delete;
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
~ChromeBrowserDelegate() override;
|
|
|
|
|
|
|
|
// cef::BrowserDelegate methods:
|
2023-02-09 19:15:15 +01:00
|
|
|
std::unique_ptr<content::WebContents> AddWebContents(
|
|
|
|
std::unique_ptr<content::WebContents> new_contents) override;
|
2020-09-25 03:40:47 +02:00
|
|
|
void OnWebContentsCreated(content::WebContents* new_contents) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void SetAsDelegate(content::WebContents* web_contents,
|
|
|
|
bool set_delegate) override;
|
2022-03-21 22:22:07 +01:00
|
|
|
bool ShowStatusBubble(bool show_by_default) override;
|
2022-03-22 19:31:30 +01:00
|
|
|
bool HandleCommand(int command_id,
|
|
|
|
WindowOpenDisposition disposition) override;
|
2023-03-07 00:21:57 +01:00
|
|
|
bool IsAppMenuItemVisible(int command_id) override;
|
|
|
|
bool IsAppMenuItemEnabled(int command_id) override;
|
|
|
|
bool IsPageActionIconVisible(PageActionIconType icon_type) override;
|
|
|
|
bool IsToolbarButtonVisible(ToolbarButtonType button_type) override;
|
2023-04-12 20:34:39 +02:00
|
|
|
void UpdateFindBarBoundingBox(gfx::Rect* bounds) override;
|
2022-07-08 09:40:35 +02:00
|
|
|
[[nodiscard]] content::MediaResponseCallback RequestMediaAccessPermissionEx(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback) override;
|
2023-09-07 19:28:27 +02:00
|
|
|
absl::optional<bool> SupportsWindowFeature(int feature) const override;
|
|
|
|
bool SupportsDraggableRegion() const override;
|
|
|
|
const absl::optional<SkRegion> GetDraggableRegion() const override;
|
|
|
|
void UpdateDraggableRegion(const SkRegion& region) override;
|
2023-09-25 21:40:17 +02:00
|
|
|
void WindowFullscreenStateChanged() override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// WebContentsDelegate methods:
|
2020-09-25 03:40:47 +02:00
|
|
|
void WebContentsCreated(content::WebContents* source_contents,
|
|
|
|
int opener_render_process_id,
|
|
|
|
int opener_render_frame_id,
|
|
|
|
const std::string& frame_name,
|
|
|
|
const GURL& target_url,
|
|
|
|
content::WebContents* new_contents) override;
|
|
|
|
content::WebContents* OpenURLFromTab(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::OpenURLParams& params) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void LoadingStateChanged(content::WebContents* source,
|
2021-12-16 23:35:54 +01:00
|
|
|
bool should_show_loading_ui) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
|
|
|
|
bool DidAddMessageToConsole(content::WebContents* source,
|
|
|
|
blink::mojom::ConsoleMessageLevel log_level,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& message,
|
2020-09-18 00:24:08 +02:00
|
|
|
int32_t line_no,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& source_id) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
void EnterFullscreenModeForTab(
|
|
|
|
content::RenderFrameHost* requesting_frame,
|
|
|
|
const blink::mojom::FullscreenOptions& options) override;
|
|
|
|
void ExitFullscreenModeForTab(content::WebContents* web_contents) override;
|
2022-03-22 22:40:28 +01:00
|
|
|
void CanDownload(const GURL& url,
|
|
|
|
const std::string& request_method,
|
|
|
|
base::OnceCallback<void(bool)> callback) override;
|
2020-09-25 03:40:47 +02:00
|
|
|
content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) override;
|
|
|
|
bool HandleKeyboardEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) override;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
Browser* browser() const { return browser_; }
|
|
|
|
|
|
|
|
private:
|
2020-09-25 03:40:47 +02:00
|
|
|
void CreateBrowser(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
CefBrowserSettings settings,
|
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
2021-04-02 22:53:17 +02:00
|
|
|
CefRefPtr<ChromeBrowserHostImpl> opener,
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefRequestContextImpl> request_context_impl);
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
CefBrowserContentsDelegate* GetDelegateForWebContents(
|
|
|
|
content::WebContents* web_contents);
|
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
bool SupportsFramelessPictureInPicture() const;
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
Browser* const browser_;
|
2023-09-07 19:28:27 +02:00
|
|
|
base::WeakPtr<ChromeBrowserHostImpl> opener_host_;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
// Used when creating a new browser host.
|
2020-09-25 03:40:47 +02:00
|
|
|
const CefBrowserCreateParams create_params_;
|
2022-03-21 22:22:07 +01:00
|
|
|
|
|
|
|
absl::optional<bool> show_status_bubble_;
|
2023-09-07 19:28:27 +02:00
|
|
|
absl::optional<SkRegion> draggable_region_;
|
|
|
|
mutable absl::optional<bool> frameless_pip_;
|
2020-09-18 00:24:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_DELEGATE_H_
|