Skip to content

Support chrome windows with CEF callbacks #2969

Closed

Description

@magreenblatt

Original report by me.


The Chromium code base is composed of architectural layers, with the primary application layers being “content” and “chrome”. The “content” layer includes WebContents as the primary browser object and provides implementations for most of the generic web platform and application/process management functionality. The “chrome” layer includes Browser as the primary browser object and provides implementations for many advanced features including datalist/autofill (issue #906), extensions (issue #1947), gamepad (issue #1751), webhid (issue #2847), webmidi (issue #1028), async clipboard (issue #2921), input_type=color (issue #899), etc.

For historical reasons CEF browser windows are based on the “content” layer WebContents object. Adding support for additional “chrome” layer features is a serious effort because it involves careful understanding and cherry-picking of the related functionality from “chrome” into the CEF code base. Over time we have added dependencies on the “chrome” layer targets to support some features in CEF (extensions, print preview, etc) and to avoid code duplication. As a result, CEF binaries already contain most/all of the code that would be required to launch a stand-alone “chrome” Browser window.

If we could create a CEF browser window based on the “chrome” Browser object we would get much of the “chrome” layer functionality “for free”. To be usable in CEF the “chrome” window would need to support a subset of existing CEF callbacks/intercepts (e.g. loading progress, network requests, etc.), and be inserted into the existing Views framework structure (issue #1749). The “chrome” window would not support off-screen rendering, though parenting to a native (non-Views) window should be possible and likely required on macOS.

Given the above, the scope for this issue is to identify the subset of “chrome” initialization code that is required to launch and embed a Views-based Browser window object, and then hook up a TBD minimum subset of existing CEF callbacks to work with that object. MVP is an off-by-default option to create “chrome”-based browsers in cefclient/cefsimple. These browsers will initially contain many chrome-specific UI features (shortcut keys, dialogs, etc.) that might not be desired in release-quality client applications. Additional callback functionality and behavioral tweaks may be added over time as needed/appropriate.

Activity

  1. magreenblatt commented on Jun 23, 2020

    @magreenblatt
    CollaboratorAuthor

    One important technical aspect of this change is the usage of BUILDFLAG(ENABLE_CEF) when patching Chromium code. We will need to introduce a runtime check for choosing between CEF and Chrome behaviors in these patches, instead of just compiling in the CEF-specific behaviors when building CEF.

    ‌

  2. magreenblatt commented on Jun 26, 2020

    @magreenblatt
    CollaboratorAuthor

    GTK is required for the Chrome runtime on Linux (see here), so use_gtk=true must be specified via GN_DEFINES on that platform.

  3. magreenblatt commented on Jun 29, 2020

    @magreenblatt
    CollaboratorAuthor

    Refactor process execution logic (see issue #2969)

    CefContext implements the public CEF API functions and delegates
    the stages of content & service_manager process execution to
    CefMainRunner. CEF-specific runtime logic (which may be replaced
    with chrome-specific runtime logic) is then delegated to
    CefMainDelegate which implements content::ContentMainDelegate.

    → <<cset 049caf913106 (bb)>>

  4. magreenblatt commented on Jun 29, 2020

    @magreenblatt
    CollaboratorAuthor

    Add initial chrome runtime support (see issue #2969)

    Running cefsimple --enable-chrome-runtime will create and run a
    Chrome browser window using the CEF app methods, and call
    CefApp::OnContextInitialized as expected. CEF task methods also
    work as expected in the main process. No browser-related methods or
    callbacks are currently supported for the Chrome window, and the
    application will exit when the last Chrome window closes.

    The Chrome runtime requires resources.pak, chrome_100_percent.pak
    and chrome_200_percent.pak files which were not previously built
    with CEF. It shares the existing locales pak files which have been
    updated to include additional Chrome-specific strings.

    On Linux, the Chrome runtime requires GTK so use_gtk=true must be
    specified via GN_DEFINES when building.

    This change also refactors the CEF runtime, which can be tested in
    the various supported modes by running:
    $ cefclient
    $ cefclient --multi-threaded-message-loop
    $ cefclient --external-message-pump

    → <<cset 117499421184 (bb)>>

  5. magreenblatt commented on Jun 29, 2020

    @magreenblatt
    CollaboratorAuthor

    Set enable_background_mode=false by default (see issue #2969)

    This mode doesn't make sense with CEF, and it was causing strange
    shutdown crashes when running with Chrome mode enabled.

    → <<cset f5587b74f0aa (bb)>>

  6. magreenblatt commented on Jun 29, 2020

    @magreenblatt
    CollaboratorAuthor

    Rename the current CEF runtime to Alloy (see issue #2969)

    As part of introducing the Chrome runtime we now need to distinguish
    between the classes that implement the current CEF runtime and the
    classes the implement the shared CEF library/runtime structure and
    public API. We choose the name Alloy for the current CEF runtime
    because it describes a combination of Chrome and other elements.

    Shared CEF library/runtime classes will continue to use the Cef
    prefix. Classes that implement the Alloy or Chrome runtime will use
    the Alloy or Chrome prefixes respectively. Classes that extend an
    existing Chrome-prefixed class will add the Cef or Alloy suffix,
    thereby following the existing naming pattern of Chrome-derived
    classes.

    This change applies the new naming pattern to an initial set of
    runtime-related classes. Additional classes/files will be renamed
    and moved as the Chrome runtime implementation progresses.

    → <<cset 84f3ff2afda7 (bb)>>

  7. magreenblatt commented on Jun 29, 2020

    @magreenblatt
    CollaboratorAuthor

    Add CefAppManager and remove global ContentClient accessors (see issue #2969)

    This is the first pass in removing direct dependencies on the Alloy
    runtime from code that can potentially be shared between runtimes.

    CefBrowserHost and CefRequestContext APIs (including CefCookieManager,
    CefURLRequest, etc.) are not yet implemented for the Chrome runtime.
    Assert early if these API methods are called while the Chrome runtime
    is enabled.

    → <<cset b3a8da9b25dc (bb)>>

  8. magreenblatt commented on Jul 1, 2020

    @magreenblatt
    CollaboratorAuthor

    Make CefBrowserContext an abstract base class (see issue #2969)

    Existing CefBrowserContext functionality is now split between
    CefBrowserContext and AlloyBrowserContext. Runtime implementations of
    CefBrowserContext will provide access to the content::BrowserContext and
    Profile types via different inheritance paths. For example, the Alloy
    runtime uses ChromeProfileAlloy and the Chrome runtime uses ProfileImpl.

    This change also renames CefResourceContext to CefIOThreadState to more
    accurately represent its purpose as it no longer needs to extend
    content::ResourceContext.

    → <<cset 48fc0bd2206d (bb)>>

  9. magreenblatt commented on Jul 6, 2020

    @magreenblatt
    CollaboratorAuthor

    Move browser runtime-specific logic to CefBrowserPlatformDelegate (see issue #2969)

    This change moves the runtime-specific implementations of CefBrowserHostImpl
    methods to CefBrowserPlatformDelegate. Some WebContentsDelegate methods
    implemented by CefBrowserHostImpl set state or trigger client callbacks.
    Those implementations will likely stay with CefBrowserHostImpl and will
    need to be called from the Browser equivalents when using the Chrome runtime.

    → <<cset 6cb9f0c695b9 (bb)>>

  10. magreenblatt commented on Jul 6, 2020

    @magreenblatt
    CollaboratorAuthor

    Add initial Chrome runtime support for browser APIs (see issue #2969)

    This change adds basic Chrome runtime implementations for CefBrowserContext
    and CefBrowserPlatformDelegate. A Chrome browser window with default frame
    and styling can now be created using CefBrowserHost::CreateBrowser and some
    CefClient callbacks will be triggered via the WebContentsObserver
    implementation in CefBrowserHostImpl.

    Any additional browser windows created via the Chrome UI will be unmanaged
    by CEF. The application message loop will block until all browser windows
    have been closed by the user.

    → <<cset e9bf3cdb9852 (bb)>>

  11. magreenblatt commented on Jul 6, 2020

    @magreenblatt
    CollaboratorAuthor

    Move Alloy-specific logic to CefBrowserPlatformDelegateAlloy (see issue #2969)

    Also remove OSR-related methods where the attributes can instead be passed
    to the OSR platform delegate constructor directly.

    → <<cset 02cdf05848ea (bb)>>

  12. magreenblatt commented on Jul 6, 2020

    @magreenblatt
    CollaboratorAuthor

    Fix build and initial Chrome runtime issues on macOS (see issue #2969)

    This change moves shared resource initialization to a common location and
    disables crash reporting initialization in chrome/ code via patch files.

    When using the Chrome runtime on macOS the Chrome application window will
    display, but web content is currently blank and the application does not
    exit cleanly. This will need to be debugged further in the future.

    → <<cset 03c9156c803c (bb)>>

  13. magreenblatt commented on Jul 16, 2020

    @magreenblatt
    CollaboratorAuthor

    Fix official build errors caused by chrome runtime changes (see issue #2969)

    → <<cset 13e3c8b42a7a (bb)>>

  14. magreenblatt commented on Sep 16, 2020

    @magreenblatt
    CollaboratorAuthor

    The next step is supporting observers and delegates on the chrome Browser object.

    ‌

  15. magreenblatt commented on Sep 17, 2020

    @magreenblatt
    CollaboratorAuthor

    Update chrome_browser_net_export patch for chrome runtime (see issue #2969)

    → <<cset 7ca9e9c54bc3 (bb)>>

  16. 158 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Frameworkproposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions