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,7 +9,7 @@ | ||||
| // implementations. See the translator.README.txt file in the tools directory | ||||
| // for more information. | ||||
| // | ||||
| // $hash=a84451b4f759f2a4a0fe673d90be1fb5053bfd1a$ | ||||
| // $hash=516b55b7ea53e2de2b096e85ba0eb83f2a2693f3$ | ||||
| // | ||||
|  | ||||
| #include "libcef_dll/cpptoc/browser_host_cpptoc.h" | ||||
| @@ -18,8 +18,10 @@ | ||||
| #include "libcef_dll/cpptoc/drag_data_cpptoc.h" | ||||
| #include "libcef_dll/cpptoc/extension_cpptoc.h" | ||||
| #include "libcef_dll/cpptoc/navigation_entry_cpptoc.h" | ||||
| #include "libcef_dll/cpptoc/registration_cpptoc.h" | ||||
| #include "libcef_dll/cpptoc/request_context_cpptoc.h" | ||||
| #include "libcef_dll/ctocpp/client_ctocpp.h" | ||||
| #include "libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.h" | ||||
| #include "libcef_dll/ctocpp/download_image_callback_ctocpp.h" | ||||
| #include "libcef_dll/ctocpp/navigation_entry_visitor_ctocpp.h" | ||||
| #include "libcef_dll/ctocpp/pdf_print_callback_ctocpp.h" | ||||
| @@ -522,6 +524,81 @@ int CEF_CALLBACK browser_host_has_dev_tools(struct _cef_browser_host_t* self) { | ||||
|   return _retval; | ||||
| } | ||||
|  | ||||
| int CEF_CALLBACK | ||||
| browser_host_send_dev_tools_message(struct _cef_browser_host_t* self, | ||||
|                                     const void* message, | ||||
|                                     size_t message_size) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return 0; | ||||
|   // Verify param: message; type: simple_byaddr | ||||
|   DCHECK(message); | ||||
|   if (!message) | ||||
|     return 0; | ||||
|  | ||||
|   // Execute | ||||
|   bool _retval = CefBrowserHostCppToC::Get(self)->SendDevToolsMessage( | ||||
|       message, message_size); | ||||
|  | ||||
|   // Return type: bool | ||||
|   return _retval; | ||||
| } | ||||
|  | ||||
| int CEF_CALLBACK | ||||
| browser_host_execute_dev_tools_method(struct _cef_browser_host_t* self, | ||||
|                                       int message_id, | ||||
|                                       const cef_string_t* method, | ||||
|                                       struct _cef_dictionary_value_t* params) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return 0; | ||||
|   // Verify param: method; type: string_byref_const | ||||
|   DCHECK(method); | ||||
|   if (!method) | ||||
|     return 0; | ||||
|   // Unverified params: params | ||||
|  | ||||
|   // Execute | ||||
|   int _retval = CefBrowserHostCppToC::Get(self)->ExecuteDevToolsMethod( | ||||
|       message_id, CefString(method), CefDictionaryValueCppToC::Unwrap(params)); | ||||
|  | ||||
|   // Return type: simple | ||||
|   return _retval; | ||||
| } | ||||
|  | ||||
| struct _cef_registration_t* CEF_CALLBACK | ||||
| browser_host_add_dev_tools_message_observer( | ||||
|     struct _cef_browser_host_t* self, | ||||
|     struct _cef_dev_tools_message_observer_t* observer) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return NULL; | ||||
|   // Verify param: observer; type: refptr_diff | ||||
|   DCHECK(observer); | ||||
|   if (!observer) | ||||
|     return NULL; | ||||
|  | ||||
|   // Execute | ||||
|   CefRefPtr<CefRegistration> _retval = | ||||
|       CefBrowserHostCppToC::Get(self)->AddDevToolsMessageObserver( | ||||
|           CefDevToolsMessageObserverCToCpp::Wrap(observer)); | ||||
|  | ||||
|   // Return type: refptr_same | ||||
|   return CefRegistrationCppToC::Wrap(_retval); | ||||
| } | ||||
|  | ||||
| void CEF_CALLBACK | ||||
| browser_host_get_navigation_entries(struct _cef_browser_host_t* self, | ||||
|                                     cef_navigation_entry_visitor_t* visitor, | ||||
| @@ -1285,6 +1362,10 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() { | ||||
|   GetStruct()->show_dev_tools = browser_host_show_dev_tools; | ||||
|   GetStruct()->close_dev_tools = browser_host_close_dev_tools; | ||||
|   GetStruct()->has_dev_tools = browser_host_has_dev_tools; | ||||
|   GetStruct()->send_dev_tools_message = browser_host_send_dev_tools_message; | ||||
|   GetStruct()->execute_dev_tools_method = browser_host_execute_dev_tools_method; | ||||
|   GetStruct()->add_dev_tools_message_observer = | ||||
|       browser_host_add_dev_tools_message_observer; | ||||
|   GetStruct()->get_navigation_entries = browser_host_get_navigation_entries; | ||||
|   GetStruct()->set_mouse_cursor_change_disabled = | ||||
|       browser_host_set_mouse_cursor_change_disabled; | ||||
|   | ||||
							
								
								
									
										184
									
								
								libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,184 @@ | ||||
| // 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=c4a7b4d679f1f2ed47fc31df3e2099962d5cb9d6$ | ||||
| // | ||||
|  | ||||
| #include "libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.h" | ||||
| #include "libcef_dll/ctocpp/browser_ctocpp.h" | ||||
| #include "libcef_dll/shutdown_checker.h" | ||||
|  | ||||
| namespace { | ||||
|  | ||||
| // MEMBER FUNCTIONS - Body may be edited by hand. | ||||
|  | ||||
| int CEF_CALLBACK dev_tools_message_observer_on_dev_tools_message( | ||||
|     struct _cef_dev_tools_message_observer_t* self, | ||||
|     cef_browser_t* browser, | ||||
|     const void* message, | ||||
|     size_t message_size) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return 0; | ||||
|   // Verify param: browser; type: refptr_diff | ||||
|   DCHECK(browser); | ||||
|   if (!browser) | ||||
|     return 0; | ||||
|   // Verify param: message; type: simple_byaddr | ||||
|   DCHECK(message); | ||||
|   if (!message) | ||||
|     return 0; | ||||
|  | ||||
|   // Execute | ||||
|   bool _retval = CefDevToolsMessageObserverCppToC::Get(self)->OnDevToolsMessage( | ||||
|       CefBrowserCToCpp::Wrap(browser), message, message_size); | ||||
|  | ||||
|   // Return type: bool | ||||
|   return _retval; | ||||
| } | ||||
|  | ||||
| void CEF_CALLBACK dev_tools_message_observer_on_dev_tools_method_result( | ||||
|     struct _cef_dev_tools_message_observer_t* self, | ||||
|     cef_browser_t* browser, | ||||
|     int message_id, | ||||
|     int success, | ||||
|     const void* result, | ||||
|     size_t result_size) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return; | ||||
|   // Verify param: browser; type: refptr_diff | ||||
|   DCHECK(browser); | ||||
|   if (!browser) | ||||
|     return; | ||||
|   // Unverified params: result | ||||
|  | ||||
|   // Execute | ||||
|   CefDevToolsMessageObserverCppToC::Get(self)->OnDevToolsMethodResult( | ||||
|       CefBrowserCToCpp::Wrap(browser), message_id, success ? true : false, | ||||
|       result, result_size); | ||||
| } | ||||
|  | ||||
| void CEF_CALLBACK dev_tools_message_observer_on_dev_tools_event( | ||||
|     struct _cef_dev_tools_message_observer_t* self, | ||||
|     cef_browser_t* browser, | ||||
|     const cef_string_t* method, | ||||
|     const void* params, | ||||
|     size_t params_size) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return; | ||||
|   // Verify param: browser; type: refptr_diff | ||||
|   DCHECK(browser); | ||||
|   if (!browser) | ||||
|     return; | ||||
|   // Verify param: method; type: string_byref_const | ||||
|   DCHECK(method); | ||||
|   if (!method) | ||||
|     return; | ||||
|   // Unverified params: params | ||||
|  | ||||
|   // Execute | ||||
|   CefDevToolsMessageObserverCppToC::Get(self)->OnDevToolsEvent( | ||||
|       CefBrowserCToCpp::Wrap(browser), CefString(method), params, params_size); | ||||
| } | ||||
|  | ||||
| void CEF_CALLBACK dev_tools_message_observer_on_dev_tools_agent_attached( | ||||
|     struct _cef_dev_tools_message_observer_t* self, | ||||
|     cef_browser_t* browser) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return; | ||||
|   // Verify param: browser; type: refptr_diff | ||||
|   DCHECK(browser); | ||||
|   if (!browser) | ||||
|     return; | ||||
|  | ||||
|   // Execute | ||||
|   CefDevToolsMessageObserverCppToC::Get(self)->OnDevToolsAgentAttached( | ||||
|       CefBrowserCToCpp::Wrap(browser)); | ||||
| } | ||||
|  | ||||
| void CEF_CALLBACK dev_tools_message_observer_on_dev_tools_agent_detached( | ||||
|     struct _cef_dev_tools_message_observer_t* self, | ||||
|     cef_browser_t* browser) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return; | ||||
|   // Verify param: browser; type: refptr_diff | ||||
|   DCHECK(browser); | ||||
|   if (!browser) | ||||
|     return; | ||||
|  | ||||
|   // Execute | ||||
|   CefDevToolsMessageObserverCppToC::Get(self)->OnDevToolsAgentDetached( | ||||
|       CefBrowserCToCpp::Wrap(browser)); | ||||
| } | ||||
|  | ||||
| }  // namespace | ||||
|  | ||||
| // CONSTRUCTOR - Do not edit by hand. | ||||
|  | ||||
| CefDevToolsMessageObserverCppToC::CefDevToolsMessageObserverCppToC() { | ||||
|   GetStruct()->on_dev_tools_message = | ||||
|       dev_tools_message_observer_on_dev_tools_message; | ||||
|   GetStruct()->on_dev_tools_method_result = | ||||
|       dev_tools_message_observer_on_dev_tools_method_result; | ||||
|   GetStruct()->on_dev_tools_event = | ||||
|       dev_tools_message_observer_on_dev_tools_event; | ||||
|   GetStruct()->on_dev_tools_agent_attached = | ||||
|       dev_tools_message_observer_on_dev_tools_agent_attached; | ||||
|   GetStruct()->on_dev_tools_agent_detached = | ||||
|       dev_tools_message_observer_on_dev_tools_agent_detached; | ||||
| } | ||||
|  | ||||
| // DESTRUCTOR - Do not edit by hand. | ||||
|  | ||||
| CefDevToolsMessageObserverCppToC::~CefDevToolsMessageObserverCppToC() { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
| } | ||||
|  | ||||
| template <> | ||||
| CefRefPtr<CefDevToolsMessageObserver> | ||||
| CefCppToCRefCounted<CefDevToolsMessageObserverCppToC, | ||||
|                     CefDevToolsMessageObserver, | ||||
|                     cef_dev_tools_message_observer_t>:: | ||||
|     UnwrapDerived(CefWrapperType type, cef_dev_tools_message_observer_t* s) { | ||||
|   NOTREACHED() << "Unexpected class type: " << type; | ||||
|   return nullptr; | ||||
| } | ||||
|  | ||||
| template <> | ||||
| CefWrapperType | ||||
|     CefCppToCRefCounted<CefDevToolsMessageObserverCppToC, | ||||
|                         CefDevToolsMessageObserver, | ||||
|                         cef_dev_tools_message_observer_t>::kWrapperType = | ||||
|         WT_DEV_TOOLS_MESSAGE_OBSERVER; | ||||
							
								
								
									
										40
									
								
								libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| // 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=d48f93f3817dab7daf0e30a6fa94b1a173356383$ | ||||
| // | ||||
|  | ||||
| #ifndef CEF_LIBCEF_DLL_CPPTOC_DEV_TOOLS_MESSAGE_OBSERVER_CPPTOC_H_ | ||||
| #define CEF_LIBCEF_DLL_CPPTOC_DEV_TOOLS_MESSAGE_OBSERVER_CPPTOC_H_ | ||||
| #pragma once | ||||
|  | ||||
| #if !defined(WRAPPING_CEF_SHARED) | ||||
| #error This file can be included wrapper-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/cpptoc/cpptoc_ref_counted.h" | ||||
|  | ||||
| // Wrap a C++ class with a C structure. | ||||
| // This class may be instantiated and accessed wrapper-side only. | ||||
| class CefDevToolsMessageObserverCppToC | ||||
|     : public CefCppToCRefCounted<CefDevToolsMessageObserverCppToC, | ||||
|                                  CefDevToolsMessageObserver, | ||||
|                                  cef_dev_tools_message_observer_t> { | ||||
|  public: | ||||
|   CefDevToolsMessageObserverCppToC(); | ||||
|   virtual ~CefDevToolsMessageObserverCppToC(); | ||||
| }; | ||||
|  | ||||
| #endif  // CEF_LIBCEF_DLL_CPPTOC_DEV_TOOLS_MESSAGE_OBSERVER_CPPTOC_H_ | ||||
| @@ -9,7 +9,7 @@ | ||||
| // implementations. See the translator.README.txt file in the tools directory | ||||
| // for more information. | ||||
| // | ||||
| // $hash=68840d18a25efe4d749e480225d7ac3caacd4723$ | ||||
| // $hash=716501855da0203723eb18bfb9e518c7b155f110$ | ||||
| // | ||||
|  | ||||
| #include "libcef_dll/cpptoc/request_handler_cpptoc.h" | ||||
| @@ -396,6 +396,26 @@ void CEF_CALLBACK request_handler_on_render_process_terminated( | ||||
|       CefBrowserCToCpp::Wrap(browser), status); | ||||
| } | ||||
|  | ||||
| void CEF_CALLBACK request_handler_on_document_available_in_main_frame( | ||||
|     struct _cef_request_handler_t* self, | ||||
|     cef_browser_t* browser) { | ||||
|   shutdown_checker::AssertNotShutdown(); | ||||
|  | ||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||
|  | ||||
|   DCHECK(self); | ||||
|   if (!self) | ||||
|     return; | ||||
|   // Verify param: browser; type: refptr_diff | ||||
|   DCHECK(browser); | ||||
|   if (!browser) | ||||
|     return; | ||||
|  | ||||
|   // Execute | ||||
|   CefRequestHandlerCppToC::Get(self)->OnDocumentAvailableInMainFrame( | ||||
|       CefBrowserCToCpp::Wrap(browser)); | ||||
| } | ||||
|  | ||||
| }  // namespace | ||||
|  | ||||
| // CONSTRUCTOR - Do not edit by hand. | ||||
| @@ -414,6 +434,8 @@ CefRequestHandlerCppToC::CefRequestHandlerCppToC() { | ||||
|   GetStruct()->on_render_view_ready = request_handler_on_render_view_ready; | ||||
|   GetStruct()->on_render_process_terminated = | ||||
|       request_handler_on_render_process_terminated; | ||||
|   GetStruct()->on_document_available_in_main_frame = | ||||
|       request_handler_on_document_available_in_main_frame; | ||||
| } | ||||
|  | ||||
| // DESTRUCTOR - Do not edit by hand. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user