1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_H_ 6 #define CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_H_ 7 8 #include <memory> 9 10 #include "libcef/browser/alloy/alloy_browser_host_impl.h" 11 #include "libcef/browser/devtools/devtools_file_manager.h" 12 13 #include "base/compiler_specific.h" 14 #include "base/files/file_path.h" 15 #include "base/memory/ref_counted.h" 16 #include "base/memory/weak_ptr.h" 17 #include "base/values.h" 18 #include "content/public/browser/devtools_agent_host.h" 19 #include "content/public/browser/devtools_frontend_host.h" 20 #include "content/public/browser/web_contents_observer.h" 21 22 namespace base { 23 class Value; 24 } 25 26 namespace content { 27 class NavigationHandle; 28 class RenderViewHost; 29 class WebContents; 30 } // namespace content 31 32 class PrefService; 33 34 enum class ProtocolMessageType { 35 METHOD, 36 RESULT, 37 EVENT, 38 }; 39 40 class CefDevToolsFrontend : public content::WebContentsObserver, 41 public content::DevToolsAgentHostClient { 42 public: 43 CefDevToolsFrontend(const CefDevToolsFrontend&) = delete; 44 CefDevToolsFrontend& operator=(const CefDevToolsFrontend&) = delete; 45 46 static CefDevToolsFrontend* Show( 47 AlloyBrowserHostImpl* inspected_browser, 48 const CefWindowInfo& windowInfo, 49 CefRefPtr<CefClient> client, 50 const CefBrowserSettings& settings, 51 const CefPoint& inspect_element_at, 52 base::OnceClosure frontend_destroyed_callback); 53 54 void Activate(); 55 void Focus(); 56 void InspectElementAt(int x, int y); 57 void Close(); 58 59 void CallClientFunction( 60 const std::string& object_name, 61 const std::string& method_name, 62 const base::Value arg1 = {}, 63 const base::Value arg2 = {}, 64 const base::Value arg3 = {}, 65 base::OnceCallback<void(base::Value)> cb = base::NullCallback()); 66 67 private: 68 CefDevToolsFrontend(AlloyBrowserHostImpl* frontend_browser, 69 content::WebContents* inspected_contents, 70 const CefPoint& inspect_element_at, 71 base::OnceClosure destroyed_callback); 72 ~CefDevToolsFrontend() override; 73 74 // content::DevToolsAgentHostClient implementation. 75 void AgentHostClosed(content::DevToolsAgentHost* agent_host) override; 76 void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host, 77 base::span<const uint8_t> message) override; 78 void HandleMessageFromDevToolsFrontend(base::Value message); 79 80 private: 81 // WebContentsObserver overrides 82 void ReadyToCommitNavigation( 83 content::NavigationHandle* navigation_handle) override; 84 void DocumentAvailableInMainFrame( 85 content::RenderFrameHost* render_frame_host) override; 86 void WebContentsDestroyed() override; 87 88 void SendMessageAck(int request_id, base::Value arg); 89 90 bool ProtocolLoggingEnabled() const; 91 void LogProtocolMessage(ProtocolMessageType type, 92 const base::StringPiece& message); 93 94 PrefService* GetPrefs() const; 95 96 CefRefPtr<AlloyBrowserHostImpl> frontend_browser_; 97 content::WebContents* inspected_contents_; 98 scoped_refptr<content::DevToolsAgentHost> agent_host_; 99 CefPoint inspect_element_at_; 100 base::OnceClosure frontend_destroyed_callback_; 101 std::unique_ptr<content::DevToolsFrontendHost> frontend_host_; 102 103 class NetworkResourceLoader; 104 std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator> 105 loaders_; 106 107 using ExtensionsAPIs = std::map<std::string, std::string>; 108 ExtensionsAPIs extensions_api_; 109 CefDevToolsFileManager file_manager_; 110 111 const base::FilePath protocol_log_file_; 112 113 base::WeakPtrFactory<CefDevToolsFrontend> weak_factory_; 114 }; 115 116 #endif // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_H_ 117