// Copyright (c) 2024 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. #ifndef CEF_TESTS_CEFCLIENT_BROWSER_BASE_CLIENT_HANDLER_H_ #define CEF_TESTS_CEFCLIENT_BROWSER_BASE_CLIENT_HANDLER_H_ #pragma once #include "include/cef_client.h" #include "include/wrapper/cef_message_router.h" #include "tests/cefclient/browser/test_runner.h" namespace client { // Abstract base class for client handlers. class BaseClientHandler : public CefClient, public CefLifeSpanHandler, public CefRequestHandler, public CefResourceRequestHandler { public: BaseClientHandler(); // Returns the BaseClientHandler associated with |browser|. static CefRefPtr GetForBrowser( CefRefPtr browser); // CefClient methods CefRefPtr GetLifeSpanHandler() override { return this; } CefRefPtr GetRequestHandler() override { return this; } bool OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, CefProcessId source_process, CefRefPtr message) override; // CefLifeSpanHandler methods void OnAfterCreated(CefRefPtr browser) override; void OnBeforeClose(CefRefPtr browser) override; // CefRequestHandler methods bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool user_gesture, bool is_redirect) override; CefRefPtr GetResourceRequestHandler( CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool is_navigation, bool is_download, const CefString& request_initiator, bool& disable_default_handling) override { return this; } bool OnRenderProcessUnresponsive( CefRefPtr browser, CefRefPtr callback) override; void OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status, int error_code, const CefString& error_string) override; // CefResourceRequestHandler methods cef_return_value_t OnBeforeResourceLoad( CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr callback) override; CefRefPtr GetResourceHandler( CefRefPtr browser, CefRefPtr frame, CefRefPtr request) override; CefRefPtr GetResourceResponseFilter( CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) override; // Returns the number of browsers currently using this handler. Can only be // called on the CEF UI thread. int GetBrowserCount() const; // Set a string resource for loading via StringResourceProvider. void SetStringResource(const std::string& page, const std::string& data); // Action to be taken when the render process becomes unresponsive. enum class HangAction { kDefault, kWait, kTerminate, }; void SetHangAction(HangAction action); HangAction GetHangAction() const; protected: CefRefPtr GetResourceManager() const { return resource_manager_; } private: // The current number of browsers using this handler. int browser_count_ = 0; // Handles the browser side of query routing. The renderer side is handled // in client_renderer.cc. CefRefPtr message_router_; // Set of Handlers registered with the message router. test_runner::MessageHandlerSet message_handler_set_; // Manages the registration and delivery of resources. CefRefPtr resource_manager_; // Used to manage string resources in combination with StringResourceProvider. // Only accessed on the IO thread. test_runner::StringResourceMap string_resource_map_; HangAction hang_action_ = HangAction::kDefault; DISALLOW_COPY_AND_ASSIGN(BaseClientHandler); }; } // namespace client #endif // CEF_TESTS_CEFCLIENT_BROWSER_BASE_CLIENT_HANDLER_H_