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:
Marshall Greenblatt
2022-04-08 16:48:56 -04:00
parent 5f4bccd672
commit 3000bc8748
43 changed files with 702 additions and 245 deletions

View File

@@ -39,14 +39,19 @@ struct CefBrowserCreateParams {
settings = that.settings;
request_context = that.request_context;
extra_info = that.extra_info;
if (that.window_info)
MaybeSetWindowInfo(*that.window_info);
#if defined(TOOLKIT_VIEWS)
browser_view = that.browser_view;
#endif
return *this;
}
// Platform-specific window creation info. Will be nullptr when creating a
// views-hosted browser. Currently used with the alloy runtime only.
// Set |window_info| if appropriate (see below).
void MaybeSetWindowInfo(const CefWindowInfo& window_info);
// Platform-specific window creation info. Will be nullptr for Views-hosted
// browsers except when using the Chrome runtime with a native parent handle.
std::unique_ptr<CefWindowInfo> window_info;
#if defined(TOOLKIT_VIEWS)
@@ -154,6 +159,7 @@ class CefBrowserHostBase : public CefBrowserHost,
CefRefPtr<CefClient> GetClient() override;
CefRefPtr<CefRequestContext> GetRequestContext() override;
bool HasView() override;
void SetFocus(bool focus) override;
void StartDownload(const CefString& url) override;
void DownloadImage(const CefString& image_url,
bool is_favicon,
@@ -180,6 +186,7 @@ class CefBrowserHostBase : public CefBrowserHost,
void GetNavigationEntries(CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) override;
CefRefPtr<CefNavigationEntry> GetVisibleNavigationEntry() override;
void NotifyMoveOrResizeStarted() override;
// CefBrowser methods:
bool IsValid() override;
@@ -283,6 +290,8 @@ class CefBrowserHostBase : public CefBrowserHost,
// Called from LoadMainFrameURL to perform the actual navigation.
virtual bool Navigate(const content::OpenURLParams& params);
void SetFocusInternal(bool focus);
// Thread-safe members.
CefBrowserSettings settings_;
CefRefPtr<CefClient> client_;