1 // Copyright (c) 2020 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ 6 #define CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ 7 #pragma once 8 9 #include "include/cef_browser.h" 10 11 #include "base/memory/weak_ptr.h" 12 13 class CefBrowserHostBase; 14 class CefDevToolsController; 15 class CefDevToolsFrontend; 16 17 namespace content { 18 class WebContents; 19 } 20 21 // Manages DevTools instances. Methods must be called on the UI thread unless 22 // otherwise indicated. 23 class CefDevToolsManager { 24 public: 25 // |inspected_browser| will outlive this object. 26 explicit CefDevToolsManager(CefBrowserHostBase* inspected_browser); 27 ~CefDevToolsManager(); 28 29 // See CefBrowserHost methods of the same name for documentation. 30 void ShowDevTools(const CefWindowInfo& windowInfo, 31 CefRefPtr<CefClient> client, 32 const CefBrowserSettings& settings, 33 const CefPoint& inspect_element_at); 34 void CloseDevTools(); 35 bool HasDevTools(); 36 bool SendDevToolsMessage(const void* message, size_t message_size); 37 int ExecuteDevToolsMethod(int message_id, 38 const CefString& method, 39 CefRefPtr<CefDictionaryValue> param); 40 41 // These methods are used to implement 42 // CefBrowserHost::AddDevToolsMessageObserver. CreateRegistration is safe to 43 // call on any thread. InitializeRegistrationOnUIThread should be called 44 // immediately afterwards on the UI thread. 45 static CefRefPtr<CefRegistration> CreateRegistration( 46 CefRefPtr<CefDevToolsMessageObserver> observer); 47 void InitializeRegistrationOnUIThread( 48 CefRefPtr<CefRegistration> registration); 49 50 private: 51 void OnFrontEndDestroyed(); 52 53 bool EnsureController(); 54 55 CefBrowserHostBase* const inspected_browser_; 56 57 // CefDevToolsFrontend will delete itself when the frontend WebContents is 58 // destroyed. 59 CefDevToolsFrontend* devtools_frontend_ = nullptr; 60 61 // Used for sending DevTools protocol messages without an active frontend. 62 std::unique_ptr<CefDevToolsController> devtools_controller_; 63 64 base::WeakPtrFactory<CefDevToolsManager> weak_ptr_factory_; 65 66 DISALLOW_COPY_AND_ASSIGN(CefDevToolsManager); 67 }; 68 69 #endif // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ 70