Add support for direct DevTools protocol messaging (fixes issue #2961).

This change allows the client to directly send and receive DevTools
protocol messages (send method calls, and receive method results and
events) without requiring a DevTools front-end or remote-debugging
session.

This change includes additional supporting changes:
- Add a new CefRequestHandler::OnDocumentAvailableInMainFrame
  callback (see issue #1454).
- Add a CefParseJSON variant that accepts a UTF8-encoded buffer.
- Add a `--devtools-protocol-log-file=<path>` command-line flag for
  logging protocol messages sent to/from the DevTools front-end
  while it is displayed. This is useful for understanding existing
  DevTools protocol usage.
- Add a new "libcef_static_unittests" executable target to support
  light-weight unit tests of libcef_static internals (e.g. without
  requiring exposure via the CEF API). Files to be unittested are
  placed in the new "libcef_static_unittested" source_set which is
  then included by both the existing libcef_static library and the
  new unittests executable target.
- Linux: Remove use_bundled_fontconfig=false, which is no longer
  required and causes unittest build errors (see issue #2424).

This change also adds a cefclient demo for configuring offline mode
using the DevTools protocol (fixes issue #245). This is controlled
by the "Offline mode" context menu option and the `--offline`
command-line switch which will launch cefclient in offline mode. When
cefclient is offline all network requests will fail with
ERR_INTERNET_DISCONNECTED and navigator.onLine will return false when
called from JavaScript in any frame. This mode is per-browser so
newly created browser windows will have the default mode. Note that
configuring offline mode in this way will not update the Network tab
UI ("Throtting" option) in a displayed DevTools front-end instance.
This commit is contained in:
Marshall Greenblatt
2020-06-12 20:54:08 -04:00
parent a9aef28966
commit 39aed35644
46 changed files with 2824 additions and 146 deletions

View File

@ -51,7 +51,7 @@ class Widget;
class CefAudioCapturer;
class CefBrowserInfo;
class CefBrowserPlatformDelegate;
class CefDevToolsFrontend;
class CefDevToolsManager;
class SiteInstance;
// Implementation of CefBrowser.
@ -192,6 +192,12 @@ class CefBrowserHostImpl : public CefBrowserHost,
const CefPoint& inspect_element_at) override;
void CloseDevTools() override;
bool HasDevTools() override;
bool SendDevToolsMessage(const void* message, size_t message_size) override;
int ExecuteDevToolsMethod(int message_id,
const CefString& method,
CefRefPtr<CefDictionaryValue> params) override;
CefRefPtr<CefRegistration> AddDevToolsMessageObserver(
CefRefPtr<CefDevToolsMessageObserver> observer) override;
void GetNavigationEntries(CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) override;
void SetMouseCursorChangeDisabled(bool disabled) override;
@ -523,8 +529,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
std::unique_ptr<NavigationLock> CreateNavigationLock();
private:
class DevToolsWebContentsObserver;
static CefRefPtr<CefBrowserHostImpl> CreateInternal(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
@ -581,8 +585,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
void OnFullscreenModeChange(bool fullscreen);
void OnTitleChange(const base::string16& title);
void OnDevToolsWebContentsDestroyed();
// Create the CefFileDialogManager if it doesn't already exist.
void EnsureFileDialogManager();
@ -591,6 +593,10 @@ class CefBrowserHostImpl : public CefBrowserHost,
void StartAudioCapturer();
void OnRecentlyAudibleTimerFired();
bool EnsureDevToolsManager();
void InitializeDevToolsRegistrationOnUIThread(
CefRefPtr<CefRegistration> registration);
CefBrowserSettings settings_;
CefRefPtr<CefClient> client_;
scoped_refptr<CefBrowserInfo> browser_info_;
@ -599,7 +605,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate_;
const bool is_windowless_;
const bool is_views_hosted_;
CefWindowHandle host_window_handle_;
CefWindowHandle host_window_handle_ = kNullWindowHandle;
// Non-nullptr if this object owns the WebContents. Will be nullptr for popup
// browsers between the calls to WebContentsCreated() and AddNewContents(),
@ -609,18 +615,18 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Volatile state information. All access must be protected by the state lock.
base::Lock state_lock_;
bool is_loading_;
bool can_go_back_;
bool can_go_forward_;
bool has_document_;
bool is_fullscreen_;
bool is_loading_ = false;
bool can_go_back_ = false;
bool can_go_forward_ = false;
bool has_document_ = false;
bool is_fullscreen_ = false;
// The currently focused frame, or nullptr if the main frame is focused.
CefRefPtr<CefFrameHostImpl> focused_frame_;
// Represents the current browser destruction state. Only accessed on the UI
// thread.
DestructionState destruction_state_;
DestructionState destruction_state_ = DESTRUCTION_STATE_NONE;
// Navigation will not occur while |navigation_lock_count_| > 0.
// |pending_navigation_action_| will be executed when the lock is released.
@ -630,18 +636,18 @@ class CefBrowserHostImpl : public CefBrowserHost,
// True if the OS window hosting the browser has been destroyed. Only accessed
// on the UI thread.
bool window_destroyed_;
bool window_destroyed_ = false;
// True if currently in the OnSetFocus callback. Only accessed on the UI
// thread.
bool is_in_onsetfocus_;
bool is_in_onsetfocus_ = false;
// True if the focus is currently on an editable field on the page. Only
// accessed on the UI thread.
bool focus_on_editable_field_;
bool focus_on_editable_field_ = false;
// True if mouse cursor change is disabled.
bool mouse_cursor_change_disabled_;
bool mouse_cursor_change_disabled_ = false;
// Used for managing notification subscriptions.
std::unique_ptr<content::NotificationRegistrar> registrar_;
@ -655,12 +661,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Used for creating and managing context menus.
std::unique_ptr<CefMenuManager> menu_manager_;
// Track the lifespan of the frontend WebContents associated with this
// browser.
std::unique_ptr<DevToolsWebContentsObserver> devtools_observer_;
// CefDevToolsFrontend will delete itself when the frontend WebContents is
// destroyed.
CefDevToolsFrontend* devtools_frontend_;
// Used for creating and managing DevTools instances.
std::unique_ptr<CefDevToolsManager> devtools_manager_;
// Observers that want to be notified of changes to this object.
base::ObserverList<Observer>::Unchecked observers_;