mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: win/linux: Add support for browser with native parent (see issue #3294)
This change adds Chrome runtime support on Windows and Linux for creating a browser parented to a native window supplied by the client application. Expected API usage and window behavior is similar to what already exists with the Alloy runtime. The parent window handle should be specified by using CefWindowInfo::SetAsChild in combination with the CefBrowserHost::CreateBrowser and CefLifeSpanHandler::OnBeforePopup callbacks. The previously existing behavior of creating a fully-featured Chrome browser window when empty CefWindowInfo is used with CreateBrowser remains unchanged and Views is still the preferred API for creating top-level Chrome windows with custom styling (e.g. title bar only, frameless, etc). The cefclient Popup Window test with a native parent window continues to crash on Linux with both the Alloy and Chrome runtimes (see issue #3165). Also adds Chrome runtime support for CefDisplayHandler::OnCursorChange. To test: - Run `cefclient --enable-chrome-runtime [--use-views]` for the default (and previously existing) Views-based behavior. - Run `cefclient --enable-chrome-runtime --use-native` for the new native parent window behavior. - Run `cefclient --enable-chrome-runtime --use-native --no-activate` and the window will not be activated (take input focus) on launch (Windows only). - Run `cefclient --enable-chrome-runtime [--use-views|--use-native] --mouse-cursor-change-disabled` and the mouse cursor will not change on mouseover of DOM elements.
This commit is contained in:
@ -18,7 +18,6 @@
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/devtools/devtools_manager.h"
|
||||
#include "libcef/browser/media_capture_devices_dispatcher.h"
|
||||
#include "libcef/browser/native/cursor_util.h"
|
||||
#include "libcef/browser/osr/osr_util.h"
|
||||
#include "libcef/browser/request_context_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
@ -35,7 +34,6 @@
|
||||
#include "base/command_line.h"
|
||||
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
|
||||
#include "content/browser/gpu/compositor_util.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/public/browser/desktop_media_id.h"
|
||||
#include "content/public/browser/file_select_listener.h"
|
||||
#include "content/public/browser/host_zoom_map.h"
|
||||
@ -47,12 +45,11 @@
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
#include "content/public/browser/render_widget_host_observer.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "extensions/common/extension.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "third_party/blink/public/mojom/widget/platform_widget.mojom-test-utils.h"
|
||||
#include "ui/events/base_event_utils.h"
|
||||
|
||||
using content::KeyboardEventProcessingResult;
|
||||
@ -86,48 +83,6 @@ void ShowDevToolsWithHelper(ShowDevToolsHelper* helper) {
|
||||
delete helper;
|
||||
}
|
||||
|
||||
class CefWidgetHostInterceptor
|
||||
: public blink::mojom::WidgetHostInterceptorForTesting,
|
||||
public content::RenderWidgetHostObserver {
|
||||
public:
|
||||
CefWidgetHostInterceptor(AlloyBrowserHostImpl* browser,
|
||||
content::RenderViewHost* render_view_host)
|
||||
: browser_(browser),
|
||||
render_widget_host_(
|
||||
content::RenderWidgetHostImpl::From(render_view_host->GetWidget())),
|
||||
impl_(render_widget_host_->widget_host_receiver_for_testing()
|
||||
.SwapImplForTesting(this)) {
|
||||
render_widget_host_->AddObserver(this);
|
||||
}
|
||||
|
||||
CefWidgetHostInterceptor(const CefWidgetHostInterceptor&) = delete;
|
||||
CefWidgetHostInterceptor& operator=(const CefWidgetHostInterceptor&) = delete;
|
||||
|
||||
blink::mojom::WidgetHost* GetForwardingInterface() override { return impl_; }
|
||||
|
||||
// WidgetHostInterceptorForTesting method:
|
||||
void SetCursor(const ui::Cursor& cursor) override {
|
||||
if (cursor_util::OnCursorChange(browser_, cursor)) {
|
||||
// Don't change the cursor.
|
||||
return;
|
||||
}
|
||||
|
||||
GetForwardingInterface()->SetCursor(cursor);
|
||||
}
|
||||
|
||||
// RenderWidgetHostObserver method:
|
||||
void RenderWidgetHostDestroyed(
|
||||
content::RenderWidgetHost* widget_host) override {
|
||||
widget_host->RemoveObserver(this);
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
AlloyBrowserHostImpl* const browser_;
|
||||
content::RenderWidgetHostImpl* const render_widget_host_;
|
||||
blink::mojom::WidgetHost* const impl_;
|
||||
};
|
||||
|
||||
static constexpr base::TimeDelta kRecentlyAudibleTimeout = base::Seconds(2);
|
||||
|
||||
} // namespace
|
||||
@ -243,7 +198,15 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
|
||||
// Notify that the browser has been created. These must be delivered in the
|
||||
// expected order.
|
||||
|
||||
// 1. Notify the browser's LifeSpanHandler. This must always be the first
|
||||
if (opener && opener->platform_delegate_) {
|
||||
// 1. Notify the opener browser's platform delegate. With Views this will
|
||||
// result in a call to CefBrowserViewDelegate::OnPopupBrowserViewCreated().
|
||||
// Do this first for consistency with the Chrome runtime.
|
||||
opener->platform_delegate_->PopupBrowserCreated(browser.get(),
|
||||
is_devtools_popup);
|
||||
}
|
||||
|
||||
// 2. Notify the browser's LifeSpanHandler. This must always be the first
|
||||
// notification for the browser. Block navigation to avoid issues with focus
|
||||
// changes being sent to an unbound interface.
|
||||
{
|
||||
@ -251,17 +214,10 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
|
||||
browser->OnAfterCreated();
|
||||
}
|
||||
|
||||
// 2. Notify the platform delegate. With Views this will result in a call to
|
||||
// 3. Notify the platform delegate. With Views this will result in a call to
|
||||
// CefBrowserViewDelegate::OnBrowserCreated().
|
||||
browser->platform_delegate_->NotifyBrowserCreated();
|
||||
|
||||
if (opener && opener->platform_delegate_) {
|
||||
// 3. Notify the opener browser's platform delegate. With Views this will
|
||||
// result in a call to CefBrowserViewDelegate::OnPopupBrowserViewCreated().
|
||||
opener->platform_delegate_->PopupBrowserCreated(browser.get(),
|
||||
is_devtools_popup);
|
||||
}
|
||||
|
||||
return browser;
|
||||
}
|
||||
|
||||
@ -355,20 +311,6 @@ bool AlloyBrowserHostImpl::TryCloseBrowser() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::SetFocus(bool focus) {
|
||||
// Always execute asynchronously to work around issue #3040.
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::SetFocusInternal,
|
||||
this, focus));
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::SetFocusInternal(bool focus) {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (focus)
|
||||
OnSetFocus(FOCUS_SOURCE_SYSTEM);
|
||||
else if (platform_delegate_)
|
||||
platform_delegate_->SetFocus(false);
|
||||
}
|
||||
|
||||
CefWindowHandle AlloyBrowserHostImpl::GetWindowHandle() {
|
||||
if (is_views_hosted_ && CEF_CURRENTLY_ON_UIT()) {
|
||||
// Always return the most up-to-date window handle for a views-hosted
|
||||
@ -664,20 +606,6 @@ void AlloyBrowserHostImpl::SendCaptureLostEvent() {
|
||||
platform_delegate_->SendCaptureLostEvent();
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::NotifyMoveOrResizeStarted() {
|
||||
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(
|
||||
CEF_UIT,
|
||||
base::BindOnce(&AlloyBrowserHostImpl::NotifyMoveOrResizeStarted, this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform_delegate_)
|
||||
platform_delegate_->NotifyMoveOrResizeStarted();
|
||||
#endif
|
||||
}
|
||||
|
||||
int AlloyBrowserHostImpl::GetWindowlessFrameRate() {
|
||||
// Verify that this method is being called on the UI thread.
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
@ -1490,19 +1418,6 @@ bool AlloyBrowserHostImpl::IsPrerender2Supported(
|
||||
// content::WebContentsObserver methods.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void AlloyBrowserHostImpl::RenderFrameCreated(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
if (render_frame_host->GetParent() == nullptr) {
|
||||
auto render_view_host = render_frame_host->GetRenderViewHost();
|
||||
new CefWidgetHostInterceptor(this, render_view_host);
|
||||
platform_delegate_->RenderViewCreated(render_view_host);
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::RenderViewReady() {
|
||||
platform_delegate_->RenderViewReady();
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::DidFinishNavigation(
|
||||
content::NavigationHandle* navigation_handle) {
|
||||
if (web_contents()) {
|
||||
|
Reference in New Issue
Block a user