2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 2016 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_VIEWS_BROWSER_VIEW_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "include/cef_client.h"
|
|
|
|
#include "include/views/cef_browser_view.h"
|
|
|
|
#include "include/views/cef_browser_view_delegate.h"
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "libcef/browser/browser_host_base.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "libcef/browser/views/browser_view_view.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "libcef/browser/views/view_impl.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/callback_forward.h"
|
2021-01-21 19:32:46 +01:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2017-02-17 00:19:43 +01:00
|
|
|
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
class CefBrowserHostBase;
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
class CefBrowserViewImpl
|
|
|
|
: public CefViewImpl<views::View, CefBrowserView, CefBrowserViewDelegate>,
|
|
|
|
public CefBrowserViewView::Delegate {
|
2016-01-19 21:09:01 +01:00
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
using ParentClass =
|
|
|
|
CefViewImpl<views::View, CefBrowserView, CefBrowserViewDelegate>;
|
|
|
|
|
|
|
|
CefBrowserViewImpl(const CefBrowserViewImpl&) = delete;
|
|
|
|
CefBrowserViewImpl& operator=(const CefBrowserViewImpl&) = delete;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Create a new CefBrowserView instance. |delegate| may be nullptr.
|
2022-04-08 22:48:56 +02:00
|
|
|
// |window_info| will only be used when creating a Chrome child window.
|
2016-01-19 21:09:01 +01:00
|
|
|
static CefRefPtr<CefBrowserViewImpl> Create(
|
2022-04-08 22:48:56 +02:00
|
|
|
const CefWindowInfo& window_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefString& url,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context,
|
|
|
|
CefRefPtr<CefBrowserViewDelegate> delegate);
|
|
|
|
|
|
|
|
// Create a new CefBrowserView instance for a popup. |delegate| may be
|
|
|
|
// nullptr.
|
|
|
|
static CefRefPtr<CefBrowserViewImpl> CreateForPopup(
|
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefBrowserViewDelegate> delegate);
|
|
|
|
|
|
|
|
// Called from CefBrowserPlatformDelegateViews.
|
|
|
|
void WebContentsCreated(content::WebContents* web_contents);
|
2020-09-25 03:40:47 +02:00
|
|
|
void BrowserCreated(CefBrowserHostBase* browser,
|
2019-07-17 20:47:27 +02:00
|
|
|
base::RepeatingClosure on_bounds_changed);
|
2020-09-25 03:40:47 +02:00
|
|
|
void BrowserDestroyed(CefBrowserHostBase* browser);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Called to handle accelerators when the event is unhandled by the web
|
|
|
|
// content and the browser client.
|
2018-11-03 02:15:09 +01:00
|
|
|
bool HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event);
|
2017-02-17 00:19:43 +01:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// CefBrowserView methods:
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() override;
|
2021-04-11 22:10:11 +02:00
|
|
|
CefRefPtr<CefView> GetChromeToolbar() override;
|
2017-02-17 00:19:43 +01:00
|
|
|
void SetPreferAccelerators(bool prefer_accelerators) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefView methods:
|
|
|
|
CefRefPtr<CefBrowserView> AsBrowserView() override { return this; }
|
2021-01-21 19:32:46 +01:00
|
|
|
void RequestFocus() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void SetBackgroundColor(cef_color_t color) override;
|
|
|
|
|
|
|
|
// CefViewAdapter methods:
|
|
|
|
void Detach() override;
|
|
|
|
std::string GetDebugType() override { return "BrowserView"; }
|
2023-01-30 22:42:40 +01:00
|
|
|
void GetDebugInfo(base::Value::Dict* info, bool include_children) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefBrowserViewView::Delegate methods:
|
|
|
|
void OnBrowserViewAdded() override;
|
2019-07-17 20:47:27 +02:00
|
|
|
void OnBoundsChanged() override;
|
2023-05-26 11:05:33 +02:00
|
|
|
void OnGestureCommand(cef_gesture_command_t command) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
// Return the WebView representation of this object.
|
|
|
|
views::WebView* web_view() const;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
private:
|
|
|
|
// Create a new implementation object.
|
|
|
|
// Always call Initialize() after creation.
|
|
|
|
// |delegate| may be nullptr.
|
|
|
|
explicit CefBrowserViewImpl(CefRefPtr<CefBrowserViewDelegate> delegate);
|
|
|
|
|
|
|
|
void SetPendingBrowserCreateParams(
|
2022-04-08 22:48:56 +02:00
|
|
|
const CefWindowInfo& window_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefString& url,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context);
|
|
|
|
|
|
|
|
void SetDefaults(const CefBrowserSettings& settings);
|
|
|
|
|
|
|
|
// CefViewImpl methods:
|
2021-02-18 02:58:25 +01:00
|
|
|
views::View* CreateRootView() override;
|
2016-07-21 23:21:32 +02:00
|
|
|
void InitializeRootView() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Logic extracted from UnhandledKeyboardEventHandler::HandleKeyboardEvent for
|
|
|
|
// the handling of accelerators. Returns true if the event was handled by the
|
|
|
|
// accelerator.
|
|
|
|
bool HandleAccelerator(const content::NativeWebKeyboardEvent& event,
|
|
|
|
views::FocusManager* focus_manager);
|
|
|
|
|
2021-01-21 19:32:46 +01:00
|
|
|
void RequestFocusInternal();
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
std::unique_ptr<CefBrowserCreateParams> pending_browser_create_params_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
|
|
|
|
bool ignore_next_char_event_ = false;
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
base::RepeatingClosure on_bounds_changed_;
|
|
|
|
|
2021-01-21 19:32:46 +01:00
|
|
|
base::WeakPtrFactory<CefBrowserViewImpl> weak_ptr_factory_;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefBrowserViewImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_
|