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/macros.h" 16 #include "base/memory/ref_counted.h" 17 #include "base/memory/weak_ptr.h" 18 #include "base/values.h" 19 #include "content/public/browser/devtools_agent_host.h" 20 #include "content/public/browser/devtools_frontend_host.h" 21 #include "content/public/browser/web_contents_observer.h" 22 23 namespace base { 24 class Value; 25 } 26 27 namespace content { 28 class NavigationHandle; 29 class RenderViewHost; 30 class WebContents; 31 } // namespace content 32 33 class PrefService; 34 35 enum class ProtocolMessageType { 36 METHOD, 37 RESULT, 38 EVENT, 39 }; 40 41 class CefDevToolsFrontend : public content::WebContentsObserver, 42 public content::DevToolsAgentHostClient { 43 public: 44 static CefDevToolsFrontend* Show( 45 AlloyBrowserHostImpl* inspected_browser, 46 const CefWindowInfo& windowInfo, 47 CefRefPtr<CefClient> client, 48 const CefBrowserSettings& settings, 49 const CefPoint& inspect_element_at, 50 base::OnceClosure frontend_destroyed_callback); 51 52 void Activate(); 53 void Focus(); 54 void InspectElementAt(int x, int y); 55 void Close(); 56 57 void CallClientFunction(const std::string& function_name, 58 const base::Value* arg1, 59 const base::Value* arg2, 60 const base::Value* arg3); 61 62 private: 63 CefDevToolsFrontend(AlloyBrowserHostImpl* frontend_browser, 64 content::WebContents* inspected_contents, 65 const CefPoint& inspect_element_at, 66 base::OnceClosure destroyed_callback); 67 ~CefDevToolsFrontend() override; 68 69 // content::DevToolsAgentHostClient implementation. 70 void AgentHostClosed(content::DevToolsAgentHost* agent_host) override; 71 void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host, 72 base::span<const uint8_t> message) override; 73 void HandleMessageFromDevToolsFrontend(const std::string& message); 74 75 private: 76 // WebContentsObserver overrides 77 void ReadyToCommitNavigation( 78 content::NavigationHandle* navigation_handle) override; 79 void DocumentAvailableInMainFrame( 80 content::RenderFrameHost* render_frame_host) override; 81 void WebContentsDestroyed() override; 82 83 void SendMessageAck(int request_id, const base::Value* arg1); 84 85 bool ProtocolLoggingEnabled() const; 86 void LogProtocolMessage(ProtocolMessageType type, 87 const base::StringPiece& message); 88 89 PrefService* GetPrefs() const; 90 91 CefRefPtr<AlloyBrowserHostImpl> frontend_browser_; 92 content::WebContents* inspected_contents_; 93 scoped_refptr<content::DevToolsAgentHost> agent_host_; 94 CefPoint inspect_element_at_; 95 base::OnceClosure frontend_destroyed_callback_; 96 std::unique_ptr<content::DevToolsFrontendHost> frontend_host_; 97 98 class NetworkResourceLoader; 99 std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator> 100 loaders_; 101 102 using ExtensionsAPIs = std::map<std::string, std::string>; 103 ExtensionsAPIs extensions_api_; 104 CefDevToolsFileManager file_manager_; 105 106 const base::FilePath protocol_log_file_; 107 108 base::WeakPtrFactory<CefDevToolsFrontend> weak_factory_; 109 110 DISALLOW_COPY_AND_ASSIGN(CefDevToolsFrontend); 111 }; 112 113 #endif // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_H_ 114