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_BROWSER_DELEGATE_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_CHROME_BROWSER_DELEGATE_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2024-01-12 00:32:08 +01:00
|
|
|
#include <optional>
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
#include "base/memory/scoped_refptr.h"
|
2023-03-07 00:21:57 +01:00
|
|
|
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
2024-04-23 22:06:00 +02:00
|
|
|
#include "third_party/blink/public/mojom/page/draggable_region.mojom-forward.h"
|
2023-09-07 19:28:27 +02:00
|
|
|
#include "third_party/skia/include/core/SkRegion.h"
|
2022-03-22 19:31:30 +01:00
|
|
|
#include "ui/base/window_open_disposition.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
|
|
|
|
class Browser;
|
2023-11-14 18:16:43 +01:00
|
|
|
class Profile;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2024-04-23 22:06:00 +02:00
|
|
|
namespace content {
|
|
|
|
class NavigationHandle;
|
|
|
|
}
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
namespace cef {
|
|
|
|
|
|
|
|
// Delegate for the chrome Browser object. Lifespan is controlled by the Browser
|
|
|
|
// object. See the ChromeBrowserDelegate documentation for additional details.
|
|
|
|
// Only accessed on the UI thread.
|
|
|
|
class BrowserDelegate : public content::WebContentsDelegate {
|
|
|
|
public:
|
|
|
|
// Opaque ref-counted base class for CEF-specific parameters passed via
|
|
|
|
// Browser::CreateParams::cef_params and possibly shared by multiple Browser
|
|
|
|
// instances.
|
|
|
|
class CreateParams : public base::RefCounted<CreateParams> {
|
|
|
|
public:
|
2024-01-20 23:48:57 +01:00
|
|
|
virtual ~CreateParams() = default;
|
2020-09-18 00:24:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Called from the Browser constructor to create a new delegate.
|
|
|
|
static std::unique_ptr<BrowserDelegate> Create(
|
|
|
|
Browser* browser,
|
2023-09-07 19:28:27 +02:00
|
|
|
scoped_refptr<CreateParams> cef_params,
|
|
|
|
const Browser* opener);
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// Optionally override Browser creation in
|
|
|
|
// DevToolsWindow::CreateDevToolsBrowser. The returned Browser, if any, will
|
|
|
|
// take ownership of |devtools_contents|.
|
2024-04-17 18:01:26 +02:00
|
|
|
static Browser* CreateDevToolsBrowser(
|
2023-11-14 18:16:43 +01:00
|
|
|
Profile* profile,
|
|
|
|
Browser* opener,
|
2024-04-17 18:01:26 +02:00
|
|
|
content::WebContents* inspected_web_contents,
|
|
|
|
std::unique_ptr<content::WebContents>& devtools_contents);
|
|
|
|
|
|
|
|
~BrowserDelegate() override = default;
|
2023-11-14 18:16:43 +01:00
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
// Optionally override chrome::AddWebContents behavior. This is most often
|
|
|
|
// called via Browser::AddNewContents for new popup browsers and provides an
|
|
|
|
// opportunity for CEF to create a new Browser instead of proceeding with
|
|
|
|
// default Browser or tab creation.
|
|
|
|
virtual std::unique_ptr<content::WebContents> AddWebContents(
|
|
|
|
std::unique_ptr<content::WebContents> new_contents) = 0;
|
|
|
|
|
|
|
|
// Called immediately after |new_contents| is created via chrome::Navigate.
|
|
|
|
// This is most often called for navigations targeting a new tab without a
|
|
|
|
// pre-existing WebContents.
|
2020-09-25 03:40:47 +02:00
|
|
|
virtual void OnWebContentsCreated(content::WebContents* new_contents) = 0;
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Add or remove ownership of the WebContents.
|
|
|
|
virtual void SetAsDelegate(content::WebContents* web_contents,
|
|
|
|
bool set_delegate) = 0;
|
2022-03-21 22:22:07 +01:00
|
|
|
|
|
|
|
// Return true to show the status bubble. This should consistently return the
|
|
|
|
// same value for the lifespan of a Browser.
|
|
|
|
virtual bool ShowStatusBubble(bool show_by_default) {
|
|
|
|
return show_by_default;
|
|
|
|
}
|
2022-03-22 19:31:30 +01:00
|
|
|
|
|
|
|
// Return true to handle (or disable) a command. ID values come from
|
|
|
|
// chrome/app/chrome_command_ids.h.
|
|
|
|
virtual bool HandleCommand(int command_id,
|
|
|
|
WindowOpenDisposition disposition) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-08 09:40:35 +02:00
|
|
|
|
2023-03-07 00:21:57 +01:00
|
|
|
// Return true if the app menu item should be visible. ID values come from
|
|
|
|
// chrome/app/chrome_command_ids.h.
|
|
|
|
virtual bool IsAppMenuItemVisible(int command_id) { return true; }
|
|
|
|
|
|
|
|
// Return true if the app menu item should be enabled. ID values come from
|
|
|
|
// chrome/app/chrome_command_ids.h.
|
|
|
|
virtual bool IsAppMenuItemEnabled(int command_id) { return true; }
|
|
|
|
|
|
|
|
// Return true if the page action icon should be visible.
|
|
|
|
virtual bool IsPageActionIconVisible(PageActionIconType icon_type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class ToolbarButtonType {
|
|
|
|
kCast = 0,
|
|
|
|
kDownload,
|
|
|
|
kSendTabToSelf,
|
|
|
|
kSidePanel,
|
|
|
|
kMaxValue = kSidePanel,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return true if the toolbar button should be visible.
|
|
|
|
virtual bool IsToolbarButtonVisible(ToolbarButtonType button_type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-04-12 20:34:39 +02:00
|
|
|
// Optionally modify the bounding box for the Find bar.
|
|
|
|
virtual void UpdateFindBarBoundingBox(gfx::Rect* bounds) {}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
// Optionally modify the top inset for dialogs.
|
|
|
|
virtual void UpdateDialogTopInset(int* dialog_top_y) {}
|
|
|
|
|
2022-07-08 09:40:35 +02:00
|
|
|
// Same as RequestMediaAccessPermission but returning |callback| if the
|
|
|
|
// request is unhandled.
|
|
|
|
[[nodiscard]] virtual content::MediaResponseCallback
|
|
|
|
RequestMediaAccessPermissionEx(content::WebContents* web_contents,
|
|
|
|
const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback) {
|
|
|
|
return callback;
|
|
|
|
}
|
2023-09-07 19:28:27 +02:00
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
// Same as RendererUnresponsive but returning false if unhandled.
|
|
|
|
virtual bool RendererUnresponsiveEx(
|
|
|
|
content::WebContents* source,
|
|
|
|
content::RenderWidgetHost* render_widget_host,
|
|
|
|
base::RepeatingClosure hang_monitor_restarter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as RendererResponsive but returning false if unhandled.
|
|
|
|
virtual bool RendererResponsiveEx(
|
|
|
|
content::WebContents* source,
|
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
// Optionally override support for the specified window feature of type
|
|
|
|
// Browser::WindowFeature.
|
2024-01-12 00:32:08 +01:00
|
|
|
virtual std::optional<bool> SupportsWindowFeature(int feature) const {
|
|
|
|
return std::nullopt;
|
2023-09-07 19:28:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if draggable regions are supported.
|
|
|
|
virtual bool SupportsDraggableRegion() const { return false; }
|
|
|
|
|
|
|
|
// Returns the draggable region, if any, relative to the web contents.
|
|
|
|
// Called from PictureInPictureBrowserFrameView::NonClientHitTest and
|
|
|
|
// BrowserView::ShouldDescendIntoChildForEventHandling.
|
2024-01-12 00:32:08 +01:00
|
|
|
virtual const std::optional<SkRegion> GetDraggableRegion() const {
|
|
|
|
return std::nullopt;
|
2023-09-07 19:28:27 +02:00
|
|
|
}
|
|
|
|
|
2023-09-25 21:40:17 +02:00
|
|
|
// Called at the end of a fullscreen transition.
|
|
|
|
virtual void WindowFullscreenStateChanged() {}
|
2024-02-06 19:55:01 +01:00
|
|
|
|
|
|
|
// Returns true if this browser has a Views-hosted opener. Only
|
|
|
|
// applicable for Browsers of type picture_in_picture and devtools.
|
|
|
|
virtual bool HasViewsHostedOpener() const { return false; }
|
2024-04-23 22:06:00 +02:00
|
|
|
|
|
|
|
// Same as OpenURLFromTab but only taking |navigation_handle_callback|
|
|
|
|
// if the return value is non-nullptr.
|
|
|
|
virtual content::WebContents* OpenURLFromTabEx(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::OpenURLParams& params,
|
|
|
|
base::OnceCallback<void(content::NavigationHandle&)>&
|
|
|
|
navigation_handle_callback) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-09-18 00:24:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cef
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_CHROME_BROWSER_DELEGATE_H_
|