mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add CefTaskManager::GetTaskIdForBrowserId
Update https://tests/task_manager to show the current browser's renderer task in bold. Approved-by: Nik Pavlov
This commit is contained in:
@ -33,7 +33,7 @@
|
|||||||
// by hand. See the translator.README.txt file in the tools directory for
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
// more information.
|
// more information.
|
||||||
//
|
//
|
||||||
// $hash=944e04f8c3213981c3955d6b5ede036b887d4d9e$
|
// $hash=324b0399edef39e64fb54fce053e7f8e347e07de$
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CEF_INCLUDE_CAPI_CEF_TASK_MANAGER_CAPI_H_
|
#ifndef CEF_INCLUDE_CAPI_CEF_TASK_MANAGER_CAPI_H_
|
||||||
@ -92,6 +92,16 @@ typedef struct _cef_task_manager_t {
|
|||||||
///
|
///
|
||||||
int(CEF_CALLBACK* kill_task)(struct _cef_task_manager_t* self,
|
int(CEF_CALLBACK* kill_task)(struct _cef_task_manager_t* self,
|
||||||
int64_t task_id);
|
int64_t task_id);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Returns the task ID associated with the main task for |browser_id| (value
|
||||||
|
/// from cef_browser_t::GetIdentifier). Returns -1 if |browser_id| is invalid,
|
||||||
|
/// does not currently have an associated task, or the function was called
|
||||||
|
/// from the incorrect thread.
|
||||||
|
///
|
||||||
|
int64_t(CEF_CALLBACK* get_task_id_for_browser_id)(
|
||||||
|
struct _cef_task_manager_t* self,
|
||||||
|
int browser_id);
|
||||||
} cef_task_manager_t;
|
} cef_task_manager_t;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -42,13 +42,13 @@
|
|||||||
// way that may cause binary incompatibility with other builds. The universal
|
// way that may cause binary incompatibility with other builds. The universal
|
||||||
// hash value will change if any platform is affected whereas the platform hash
|
// hash value will change if any platform is affected whereas the platform hash
|
||||||
// values will change only if that particular platform is affected.
|
// values will change only if that particular platform is affected.
|
||||||
#define CEF_API_HASH_UNIVERSAL "af31a52a9b7a67e9e43aecc3dca57be096bd3c52"
|
#define CEF_API_HASH_UNIVERSAL "9428a74387b371a45469c91f7dbd648b2dc74132"
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
#define CEF_API_HASH_PLATFORM "b24a9d79201dabc26957dc207746d8b6248e0e58"
|
#define CEF_API_HASH_PLATFORM "e76d3804b2419a0bf024e97d6b9e10df53d93dad"
|
||||||
#elif defined(OS_MAC)
|
#elif defined(OS_MAC)
|
||||||
#define CEF_API_HASH_PLATFORM "1b1e2db70d324c123a5be09fd9c528acbf49b9a4"
|
#define CEF_API_HASH_PLATFORM "c88c77c84ecbd81cbf4489c1b1ab4bf0396c26c3"
|
||||||
#elif defined(OS_LINUX)
|
#elif defined(OS_LINUX)
|
||||||
#define CEF_API_HASH_PLATFORM "9d549b9917bc2f0be789a75179e1aeea134798ef"
|
#define CEF_API_HASH_PLATFORM "84373e28b1ed172ce6a08da2ea33ca787f92d6dc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -95,6 +95,15 @@ class CefTaskManager : public virtual CefBaseRefCounted {
|
|||||||
///
|
///
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual bool KillTask(int64_t task_id) = 0;
|
virtual bool KillTask(int64_t task_id) = 0;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Returns the task ID associated with the main task for |browser_id|
|
||||||
|
/// (value from CefBrowser::GetIdentifier). Returns -1 if |browser_id| is
|
||||||
|
/// invalid, does not currently have an associated task, or the method was
|
||||||
|
/// called from the incorrect thread.
|
||||||
|
///
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual int64_t GetTaskIdForBrowserId(int browser_id) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CEF_INCLUDE_CEF_TASK_MANAGER_H_
|
#endif // CEF_INCLUDE_CEF_TASK_MANAGER_H_
|
||||||
|
@ -217,6 +217,23 @@ CefBrowserHostBase::GetBrowserForTopLevelNativeWindow(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForBrowserId(
|
||||||
|
int browser_id) {
|
||||||
|
DCHECK_GT(browser_id, 0);
|
||||||
|
|
||||||
|
for (const auto& browser_info :
|
||||||
|
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
|
||||||
|
if (auto browser = browser_info->browser()) {
|
||||||
|
if (browser->GetIdentifier() == browser_id) {
|
||||||
|
return browser;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetLikelyFocusedBrowser() {
|
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetLikelyFocusedBrowser() {
|
||||||
CEF_REQUIRE_UIT();
|
CEF_REQUIRE_UIT();
|
||||||
|
@ -151,6 +151,8 @@ class CefBrowserHostBase : public CefBrowserHost,
|
|||||||
// Returns the browser associated with the specified top-level window.
|
// Returns the browser associated with the specified top-level window.
|
||||||
static CefRefPtr<CefBrowserHostBase> GetBrowserForTopLevelNativeWindow(
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForTopLevelNativeWindow(
|
||||||
gfx::NativeWindow owning_window);
|
gfx::NativeWindow owning_window);
|
||||||
|
// Returns the browser associated with the specified browser ID.
|
||||||
|
static CefRefPtr<CefBrowserHostBase> GetBrowserForBrowserId(int browser_id);
|
||||||
|
|
||||||
// Returns the browser most likely to be focused. This may be somewhat iffy
|
// Returns the browser most likely to be focused. This may be somewhat iffy
|
||||||
// with windowless browsers as there is no guarantee that the client has only
|
// with windowless browsers as there is no guarantee that the client has only
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "base/check.h"
|
#include "base/check.h"
|
||||||
#include "base/ranges/algorithm.h"
|
#include "base/ranges/algorithm.h"
|
||||||
#include "base/system/sys_info.h"
|
#include "base/system/sys_info.h"
|
||||||
|
#include "cef/libcef/browser/browser_host_base.h"
|
||||||
#include "cef/libcef/browser/context.h"
|
#include "cef/libcef/browser/context.h"
|
||||||
#include "cef/libcef/browser/thread_util.h"
|
#include "cef/libcef/browser/thread_util.h"
|
||||||
#include "chrome/browser/task_manager/task_manager_interface.h"
|
#include "chrome/browser/task_manager/task_manager_interface.h"
|
||||||
@ -148,6 +149,22 @@ bool CefTaskManagerImpl::KillTask(int64_t task_id) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t CefTaskManagerImpl::GetTaskIdForBrowserId(int browser_id) {
|
||||||
|
CEF_REQUIRE_UIT_RETURN(-1);
|
||||||
|
|
||||||
|
auto browser = CefBrowserHostBase::GetBrowserForBrowserId(browser_id);
|
||||||
|
if (!browser) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* web_contents = browser->GetWebContents();
|
||||||
|
if (!web_contents) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return task_manager_->GetTaskIdForWebContents(web_contents);
|
||||||
|
}
|
||||||
|
|
||||||
bool CefTaskManagerImpl::IsValidTaskId(int64_t task_id) const {
|
bool CefTaskManagerImpl::IsValidTaskId(int64_t task_id) const {
|
||||||
return base::ranges::find(tasks_, task_id) != tasks_.end();
|
return base::ranges::find(tasks_, task_id) != tasks_.end();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ class CefTaskManagerImpl : public task_manager::TaskManagerObserver,
|
|||||||
bool GetTaskIdsList(TaskIdList& task_ids) override;
|
bool GetTaskIdsList(TaskIdList& task_ids) override;
|
||||||
bool GetTaskInfo(int64_t task_id, CefTaskInfo& info) override;
|
bool GetTaskInfo(int64_t task_id, CefTaskInfo& info) override;
|
||||||
bool KillTask(int64_t task_id) override;
|
bool KillTask(int64_t task_id) override;
|
||||||
|
int64_t GetTaskIdForBrowserId(int browser_id) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool IsValidTaskId(int64_t task_id) const;
|
bool IsValidTaskId(int64_t task_id) const;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=07933b22615488a634fd4df87e9691156ae23ec4$
|
// $hash=93050197dccd1c7999c7b90700a6144e5225c773$
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "libcef_dll/cpptoc/task_manager_cpptoc.h"
|
#include "libcef_dll/cpptoc/task_manager_cpptoc.h"
|
||||||
@ -155,6 +155,26 @@ int CEF_CALLBACK task_manager_kill_task(struct _cef_task_manager_t* self,
|
|||||||
return _retval;
|
return _retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t CEF_CALLBACK
|
||||||
|
task_manager_get_task_id_for_browser_id(struct _cef_task_manager_t* self,
|
||||||
|
int browser_id) {
|
||||||
|
shutdown_checker::AssertNotShutdown();
|
||||||
|
|
||||||
|
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||||
|
|
||||||
|
DCHECK(self);
|
||||||
|
if (!self) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
int64_t _retval =
|
||||||
|
CefTaskManagerCppToC::Get(self)->GetTaskIdForBrowserId(browser_id);
|
||||||
|
|
||||||
|
// Return type: simple
|
||||||
|
return _retval;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// CONSTRUCTOR - Do not edit by hand.
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
@ -164,6 +184,8 @@ CefTaskManagerCppToC::CefTaskManagerCppToC() {
|
|||||||
GetStruct()->get_task_ids_list = task_manager_get_task_ids_list;
|
GetStruct()->get_task_ids_list = task_manager_get_task_ids_list;
|
||||||
GetStruct()->get_task_info = task_manager_get_task_info;
|
GetStruct()->get_task_info = task_manager_get_task_info;
|
||||||
GetStruct()->kill_task = task_manager_kill_task;
|
GetStruct()->kill_task = task_manager_kill_task;
|
||||||
|
GetStruct()->get_task_id_for_browser_id =
|
||||||
|
task_manager_get_task_id_for_browser_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DESTRUCTOR - Do not edit by hand.
|
// DESTRUCTOR - Do not edit by hand.
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=56907c5bc7334bc3289f0a97dbc4a70c3ac9b41a$
|
// $hash=5838ce3611dda9523ff072eceb36137663828dd6$
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "libcef_dll/ctocpp/task_manager_ctocpp.h"
|
#include "libcef_dll/ctocpp/task_manager_ctocpp.h"
|
||||||
@ -132,6 +132,24 @@ NO_SANITIZE("cfi-icall") bool CefTaskManagerCToCpp::KillTask(int64_t task_id) {
|
|||||||
return _retval ? true : false;
|
return _retval ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NO_SANITIZE("cfi-icall")
|
||||||
|
int64_t CefTaskManagerCToCpp::GetTaskIdForBrowserId(int browser_id) {
|
||||||
|
shutdown_checker::AssertNotShutdown();
|
||||||
|
|
||||||
|
cef_task_manager_t* _struct = GetStruct();
|
||||||
|
if (CEF_MEMBER_MISSING(_struct, get_task_id_for_browser_id)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
int64_t _retval = _struct->get_task_id_for_browser_id(_struct, browser_id);
|
||||||
|
|
||||||
|
// Return type: simple
|
||||||
|
return _retval;
|
||||||
|
}
|
||||||
|
|
||||||
// CONSTRUCTOR - Do not edit by hand.
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
CefTaskManagerCToCpp::CefTaskManagerCToCpp() {}
|
CefTaskManagerCToCpp::CefTaskManagerCToCpp() {}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=d51db130ffb459b22574d7393e63e87c87dd75e0$
|
// $hash=2d35ee921c7a1abda4c83b66708bce2451b38f20$
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_TASK_MANAGER_CTOCPP_H_
|
#ifndef CEF_LIBCEF_DLL_CTOCPP_TASK_MANAGER_CTOCPP_H_
|
||||||
@ -38,6 +38,7 @@ class CefTaskManagerCToCpp : public CefCToCppRefCounted<CefTaskManagerCToCpp,
|
|||||||
bool GetTaskIdsList(TaskIdList& task_ids) override;
|
bool GetTaskIdsList(TaskIdList& task_ids) override;
|
||||||
bool GetTaskInfo(int64_t task_id, CefTaskInfo& info) override;
|
bool GetTaskInfo(int64_t task_id, CefTaskInfo& info) override;
|
||||||
bool KillTask(int64_t task_id) override;
|
bool KillTask(int64_t task_id) override;
|
||||||
|
int64_t GetTaskIdForBrowserId(int browser_id) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CEF_LIBCEF_DLL_CTOCPP_TASK_MANAGER_CTOCPP_H_
|
#endif // CEF_LIBCEF_DLL_CTOCPP_TASK_MANAGER_CTOCPP_H_
|
||||||
|
@ -49,7 +49,8 @@ std::string TaskTypeToString(cef_task_type_t type) {
|
|||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TasksToJsonString(const std::vector<CefTaskInfo>& tasks) {
|
std::string TasksToJsonString(const std::vector<CefTaskInfo>& tasks,
|
||||||
|
int64_t browser_task_id) {
|
||||||
std::string json = "[";
|
std::string json = "[";
|
||||||
for (size_t i = 0; i < tasks.size(); ++i) {
|
for (size_t i = 0; i < tasks.size(); ++i) {
|
||||||
const auto& task = tasks[i];
|
const auto& task = tasks[i];
|
||||||
@ -68,7 +69,9 @@ std::string TasksToJsonString(const std::vector<CefTaskInfo>& tasks) {
|
|||||||
json += "\"memory\":" + std::to_string(task.memory) + ",";
|
json += "\"memory\":" + std::to_string(task.memory) + ",";
|
||||||
json += "\"gpu_memory\":" + std::to_string(task.gpu_memory) + ",";
|
json += "\"gpu_memory\":" + std::to_string(task.gpu_memory) + ",";
|
||||||
json += "\"is_gpu_memory_inflated\":";
|
json += "\"is_gpu_memory_inflated\":";
|
||||||
json += (task.is_gpu_memory_inflated ? "true" : "false");
|
json += std::string(task.is_gpu_memory_inflated ? "true" : "false") + ",";
|
||||||
|
json += "\"is_this_browser\":";
|
||||||
|
json += (task.id == browser_task_id ? "true" : "false");
|
||||||
json += "}";
|
json += "}";
|
||||||
}
|
}
|
||||||
json += "]";
|
json += "]";
|
||||||
@ -102,7 +105,11 @@ class Handler final : public CefMessageRouterBrowserSide::Handler {
|
|||||||
task_manager_->GetTaskInfo(task_id, info);
|
task_manager_->GetTaskInfo(task_id, info);
|
||||||
tasks.push_back(info);
|
tasks.push_back(info);
|
||||||
}
|
}
|
||||||
callback->Success(TasksToJsonString(tasks));
|
|
||||||
|
int64_t browser_task_id =
|
||||||
|
task_manager_->GetTaskIdForBrowserId(browser->GetIdentifier());
|
||||||
|
|
||||||
|
callback->Success(TasksToJsonString(tasks, browser_task_id));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
th {
|
th {
|
||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
}
|
}
|
||||||
|
.highlight {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -106,6 +109,10 @@
|
|||||||
endButton.onclick = () => endProcess(task.id);
|
endButton.onclick = () => endProcess(task.id);
|
||||||
actionCell.appendChild(endButton);
|
actionCell.appendChild(endButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (task.is_this_browser) {
|
||||||
|
row.classList.add('highlight');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching tasks:", error);
|
console.error("Error fetching tasks:", error);
|
||||||
|
Reference in New Issue
Block a user