mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	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.
		
			
				
	
	
		
			113 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
// Copyright 2013 The Chromium Authors. All rights reserved.
 | 
						|
// Use of this source code is governed by a BSD-style license that can be
 | 
						|
// found in the LICENSE file.
 | 
						|
 | 
						|
#ifndef CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_H_
 | 
						|
#define CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_H_
 | 
						|
 | 
						|
#include <memory>
 | 
						|
 | 
						|
#include "libcef/browser/browser_host_impl.h"
 | 
						|
#include "libcef/browser/devtools/devtools_file_manager.h"
 | 
						|
 | 
						|
#include "base/compiler_specific.h"
 | 
						|
#include "base/files/file_path.h"
 | 
						|
#include "base/macros.h"
 | 
						|
#include "base/memory/ref_counted.h"
 | 
						|
#include "base/memory/weak_ptr.h"
 | 
						|
#include "base/values.h"
 | 
						|
#include "content/public/browser/devtools_agent_host.h"
 | 
						|
#include "content/public/browser/devtools_frontend_host.h"
 | 
						|
#include "content/public/browser/web_contents_observer.h"
 | 
						|
 | 
						|
namespace base {
 | 
						|
class Value;
 | 
						|
}
 | 
						|
 | 
						|
namespace content {
 | 
						|
class NavigationHandle;
 | 
						|
class RenderViewHost;
 | 
						|
class WebContents;
 | 
						|
}  // namespace content
 | 
						|
 | 
						|
class PrefService;
 | 
						|
 | 
						|
enum class ProtocolMessageType {
 | 
						|
  METHOD,
 | 
						|
  RESULT,
 | 
						|
  EVENT,
 | 
						|
};
 | 
						|
 | 
						|
class CefDevToolsFrontend : public content::WebContentsObserver,
 | 
						|
                            public content::DevToolsAgentHostClient {
 | 
						|
 public:
 | 
						|
  static CefDevToolsFrontend* Show(
 | 
						|
      CefBrowserHostImpl* inspected_browser,
 | 
						|
      const CefWindowInfo& windowInfo,
 | 
						|
      CefRefPtr<CefClient> client,
 | 
						|
      const CefBrowserSettings& settings,
 | 
						|
      const CefPoint& inspect_element_at,
 | 
						|
      base::OnceClosure frontend_destroyed_callback);
 | 
						|
 | 
						|
  void Activate();
 | 
						|
  void Focus();
 | 
						|
  void InspectElementAt(int x, int y);
 | 
						|
  void Close();
 | 
						|
 | 
						|
  void CallClientFunction(const std::string& function_name,
 | 
						|
                          const base::Value* arg1,
 | 
						|
                          const base::Value* arg2,
 | 
						|
                          const base::Value* arg3);
 | 
						|
 | 
						|
 private:
 | 
						|
  CefDevToolsFrontend(CefBrowserHostImpl* frontend_browser,
 | 
						|
                      content::WebContents* inspected_contents,
 | 
						|
                      const CefPoint& inspect_element_at,
 | 
						|
                      base::OnceClosure destroyed_callback);
 | 
						|
  ~CefDevToolsFrontend() override;
 | 
						|
 | 
						|
  // content::DevToolsAgentHostClient implementation.
 | 
						|
  void AgentHostClosed(content::DevToolsAgentHost* agent_host) override;
 | 
						|
  void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
 | 
						|
                               base::span<const uint8_t> message) override;
 | 
						|
  void HandleMessageFromDevToolsFrontend(const std::string& message);
 | 
						|
 | 
						|
 private:
 | 
						|
  // WebContentsObserver overrides
 | 
						|
  void ReadyToCommitNavigation(
 | 
						|
      content::NavigationHandle* navigation_handle) override;
 | 
						|
  void DocumentAvailableInMainFrame() override;
 | 
						|
  void WebContentsDestroyed() override;
 | 
						|
 | 
						|
  void SendMessageAck(int request_id, const base::Value* arg1);
 | 
						|
 | 
						|
  bool ProtocolLoggingEnabled() const;
 | 
						|
  void LogProtocolMessage(ProtocolMessageType type,
 | 
						|
                          const base::StringPiece& message);
 | 
						|
 | 
						|
  PrefService* GetPrefs() const;
 | 
						|
 | 
						|
  CefRefPtr<CefBrowserHostImpl> frontend_browser_;
 | 
						|
  content::WebContents* inspected_contents_;
 | 
						|
  scoped_refptr<content::DevToolsAgentHost> agent_host_;
 | 
						|
  CefPoint inspect_element_at_;
 | 
						|
  base::OnceClosure frontend_destroyed_callback_;
 | 
						|
  std::unique_ptr<content::DevToolsFrontendHost> frontend_host_;
 | 
						|
 | 
						|
  class NetworkResourceLoader;
 | 
						|
  std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
 | 
						|
      loaders_;
 | 
						|
 | 
						|
  using ExtensionsAPIs = std::map<std::string, std::string>;
 | 
						|
  ExtensionsAPIs extensions_api_;
 | 
						|
  CefDevToolsFileManager file_manager_;
 | 
						|
 | 
						|
  const base::FilePath protocol_log_file_;
 | 
						|
 | 
						|
  base::WeakPtrFactory<CefDevToolsFrontend> weak_factory_;
 | 
						|
 | 
						|
  DISALLOW_COPY_AND_ASSIGN(CefDevToolsFrontend);
 | 
						|
};
 | 
						|
 | 
						|
#endif  // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_H_
 |