mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@@ -9,11 +9,12 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=9073823898d373a435ccdc56f2914aad91cbba1e$
|
||||
// $hash=a362e11e85ce68488bbb0f5232b01f53cffeec1d$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/browser_host_ctocpp.h"
|
||||
#include "libcef_dll/cpptoc/client_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/download_image_callback_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/navigation_entry_visitor_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/pdf_print_callback_cpptoc.h"
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "libcef_dll/ctocpp/drag_data_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/extension_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/navigation_entry_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/registration_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/request_context_ctocpp.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
#include "libcef_dll/transfer_util.h"
|
||||
@@ -468,6 +470,81 @@ NO_SANITIZE("cfi-icall") bool CefBrowserHostCToCpp::HasDevTools() {
|
||||
return _retval ? true : false;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
bool CefBrowserHostCToCpp::SendDevToolsMessage(const void* message,
|
||||
size_t message_size) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_browser_host_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, send_dev_tools_message))
|
||||
return false;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: message; type: simple_byaddr
|
||||
DCHECK(message);
|
||||
if (!message)
|
||||
return false;
|
||||
|
||||
// Execute
|
||||
int _retval = _struct->send_dev_tools_message(_struct, message, message_size);
|
||||
|
||||
// Return type: bool
|
||||
return _retval ? true : false;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
int CefBrowserHostCToCpp::ExecuteDevToolsMethod(
|
||||
int message_id,
|
||||
const CefString& method,
|
||||
CefRefPtr<CefDictionaryValue> params) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_browser_host_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, execute_dev_tools_method))
|
||||
return 0;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: method; type: string_byref_const
|
||||
DCHECK(!method.empty());
|
||||
if (method.empty())
|
||||
return 0;
|
||||
// Unverified params: params
|
||||
|
||||
// Execute
|
||||
int _retval = _struct->execute_dev_tools_method(
|
||||
_struct, message_id, method.GetStruct(),
|
||||
CefDictionaryValueCToCpp::Unwrap(params));
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
CefRefPtr<CefRegistration> CefBrowserHostCToCpp::AddDevToolsMessageObserver(
|
||||
CefRefPtr<CefDevToolsMessageObserver> observer) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_browser_host_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, add_dev_tools_message_observer))
|
||||
return nullptr;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: observer; type: refptr_diff
|
||||
DCHECK(observer.get());
|
||||
if (!observer.get())
|
||||
return nullptr;
|
||||
|
||||
// Execute
|
||||
cef_registration_t* _retval = _struct->add_dev_tools_message_observer(
|
||||
_struct, CefDevToolsMessageObserverCppToC::Wrap(observer));
|
||||
|
||||
// Return type: refptr_same
|
||||
return CefRegistrationCToCpp::Wrap(_retval);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefBrowserHostCToCpp::GetNavigationEntries(
|
||||
CefRefPtr<CefNavigationEntryVisitor> visitor,
|
||||
|
@@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=a9c5f9224663a0c2f2a29c35c2dea3f47973b82f$
|
||||
// $hash=c9abd1293472afbac964aac4cd7dd4cac9dd8e58$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_BROWSER_HOST_CTOCPP_H_
|
||||
@@ -76,6 +76,12 @@ class CefBrowserHostCToCpp : public CefCToCppRefCounted<CefBrowserHostCToCpp,
|
||||
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;
|
||||
|
174
libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.cc
Normal file
174
libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.cc
Normal file
@@ -0,0 +1,174 @@
|
||||
// Copyright (c) 2020 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.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// This file was generated by the CEF translator tool. If making changes by
|
||||
// hand only do so within the body of existing method and function
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=e8d1eaf4b8cdfd79a260de33fb3be05a2948c81e$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.h"
|
||||
#include "libcef_dll/cpptoc/browser_cpptoc.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
bool CefDevToolsMessageObserverCToCpp::OnDevToolsMessage(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
const void* message,
|
||||
size_t message_size) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_dev_tools_message_observer_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_dev_tools_message))
|
||||
return false;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return false;
|
||||
// Verify param: message; type: simple_byaddr
|
||||
DCHECK(message);
|
||||
if (!message)
|
||||
return false;
|
||||
|
||||
// Execute
|
||||
int _retval = _struct->on_dev_tools_message(
|
||||
_struct, CefBrowserCppToC::Wrap(browser), message, message_size);
|
||||
|
||||
// Return type: bool
|
||||
return _retval ? true : false;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefDevToolsMessageObserverCToCpp::OnDevToolsMethodResult(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
int message_id,
|
||||
bool success,
|
||||
const void* result,
|
||||
size_t result_size) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_dev_tools_message_observer_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_dev_tools_method_result))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return;
|
||||
// Unverified params: result
|
||||
|
||||
// Execute
|
||||
_struct->on_dev_tools_method_result(_struct, CefBrowserCppToC::Wrap(browser),
|
||||
message_id, success, result, result_size);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefDevToolsMessageObserverCToCpp::OnDevToolsEvent(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
const CefString& method,
|
||||
const void* params,
|
||||
size_t params_size) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_dev_tools_message_observer_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_dev_tools_event))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return;
|
||||
// Verify param: method; type: string_byref_const
|
||||
DCHECK(!method.empty());
|
||||
if (method.empty())
|
||||
return;
|
||||
// Unverified params: params
|
||||
|
||||
// Execute
|
||||
_struct->on_dev_tools_event(_struct, CefBrowserCppToC::Wrap(browser),
|
||||
method.GetStruct(), params, params_size);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefDevToolsMessageObserverCToCpp::OnDevToolsAgentAttached(
|
||||
CefRefPtr<CefBrowser> browser) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_dev_tools_message_observer_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_dev_tools_agent_attached))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
_struct->on_dev_tools_agent_attached(_struct,
|
||||
CefBrowserCppToC::Wrap(browser));
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefDevToolsMessageObserverCToCpp::OnDevToolsAgentDetached(
|
||||
CefRefPtr<CefBrowser> browser) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_dev_tools_message_observer_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_dev_tools_agent_detached))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
_struct->on_dev_tools_agent_detached(_struct,
|
||||
CefBrowserCppToC::Wrap(browser));
|
||||
}
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefDevToolsMessageObserverCToCpp::CefDevToolsMessageObserverCToCpp() {}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefDevToolsMessageObserverCToCpp::~CefDevToolsMessageObserverCToCpp() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
|
||||
template <>
|
||||
cef_dev_tools_message_observer_t* CefCToCppRefCounted<
|
||||
CefDevToolsMessageObserverCToCpp,
|
||||
CefDevToolsMessageObserver,
|
||||
cef_dev_tools_message_observer_t>::UnwrapDerived(CefWrapperType type,
|
||||
CefDevToolsMessageObserver*
|
||||
c) {
|
||||
NOTREACHED() << "Unexpected class type: " << type;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <>
|
||||
CefWrapperType
|
||||
CefCToCppRefCounted<CefDevToolsMessageObserverCToCpp,
|
||||
CefDevToolsMessageObserver,
|
||||
cef_dev_tools_message_observer_t>::kWrapperType =
|
||||
WT_DEV_TOOLS_MESSAGE_OBSERVER;
|
56
libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.h
Normal file
56
libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2020 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.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// This file was generated by the CEF translator tool. If making changes by
|
||||
// hand only do so within the body of existing method and function
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=26b1ef9d351b0ce4a7ca0d61c53a8374ba21168b$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_DEV_TOOLS_MESSAGE_OBSERVER_CTOCPP_H_
|
||||
#define CEF_LIBCEF_DLL_CTOCPP_DEV_TOOLS_MESSAGE_OBSERVER_CTOCPP_H_
|
||||
#pragma once
|
||||
|
||||
#if !defined(BUILDING_CEF_SHARED)
|
||||
#error This file can be included DLL-side only
|
||||
#endif
|
||||
|
||||
#include "include/capi/cef_browser_capi.h"
|
||||
#include "include/capi/cef_devtools_message_observer_capi.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_devtools_message_observer.h"
|
||||
#include "libcef_dll/ctocpp/ctocpp_ref_counted.h"
|
||||
|
||||
// Wrap a C structure with a C++ class.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefDevToolsMessageObserverCToCpp
|
||||
: public CefCToCppRefCounted<CefDevToolsMessageObserverCToCpp,
|
||||
CefDevToolsMessageObserver,
|
||||
cef_dev_tools_message_observer_t> {
|
||||
public:
|
||||
CefDevToolsMessageObserverCToCpp();
|
||||
virtual ~CefDevToolsMessageObserverCToCpp();
|
||||
|
||||
// CefDevToolsMessageObserver methods.
|
||||
bool OnDevToolsMessage(CefRefPtr<CefBrowser> browser,
|
||||
const void* message,
|
||||
size_t message_size) override;
|
||||
void OnDevToolsMethodResult(CefRefPtr<CefBrowser> browser,
|
||||
int message_id,
|
||||
bool success,
|
||||
const void* result,
|
||||
size_t result_size) override;
|
||||
void OnDevToolsEvent(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& method,
|
||||
const void* params,
|
||||
size_t params_size) override;
|
||||
void OnDevToolsAgentAttached(CefRefPtr<CefBrowser> browser) override;
|
||||
void OnDevToolsAgentDetached(CefRefPtr<CefBrowser> browser) override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_DLL_CTOCPP_DEV_TOOLS_MESSAGE_OBSERVER_CTOCPP_H_
|
@@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=72e6ec9a5095a99eaa78ff867ca429f8cd28b101$
|
||||
// $hash=fdcb73f79369fe74f65f75d54f08aaec0f0e4dbf$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/request_handler_ctocpp.h"
|
||||
@@ -394,6 +394,27 @@ void CefRequestHandlerCToCpp::OnRenderProcessTerminated(
|
||||
_struct, CefBrowserCppToC::Wrap(browser), status);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefRequestHandlerCToCpp::OnDocumentAvailableInMainFrame(
|
||||
CefRefPtr<CefBrowser> browser) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_document_available_in_main_frame))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
_struct->on_document_available_in_main_frame(_struct,
|
||||
CefBrowserCppToC::Wrap(browser));
|
||||
}
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefRequestHandlerCToCpp::CefRequestHandlerCToCpp() {}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=0d67e24bf6d8079bcdfd8b36ba48543a05a9d2fd$
|
||||
// $hash=be2bb80e8816f0eaad34382f05e2bec59dfe7fa7$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_HANDLER_CTOCPP_H_
|
||||
@@ -82,6 +82,7 @@ class CefRequestHandlerCToCpp
|
||||
void OnRenderViewReady(CefRefPtr<CefBrowser> browser) override;
|
||||
void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
||||
TerminationStatus status) override;
|
||||
void OnDocumentAvailableInMainFrame(CefRefPtr<CefBrowser> browser) override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_DLL_CTOCPP_REQUEST_HANDLER_CTOCPP_H_
|
||||
|
Reference in New Issue
Block a user