2014-01-28 00:31:03 +01:00
|
|
|
// Copyright (c) 2014 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.
|
|
|
|
|
|
|
|
#include "include/wrapper/cef_message_router.h"
|
|
|
|
|
2023-10-05 17:34:40 +02:00
|
|
|
#include <limits>
|
2014-01-28 00:31:03 +01:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
|
2021-06-17 21:40:57 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2014-01-28 00:31:03 +01:00
|
|
|
#include "include/cef_task.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2014-07-11 22:10:05 +02:00
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2014-01-28 00:31:03 +01:00
|
|
|
#include "libcef_dll/wrapper/cef_browser_info_map.h"
|
2023-10-25 20:20:55 +02:00
|
|
|
#include "libcef_dll/wrapper/cef_message_router_utils.h"
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// ID value reserved for internal use.
|
|
|
|
const int kReservedId = 0;
|
|
|
|
|
|
|
|
// Appended to the JS function name for related IPC messages.
|
|
|
|
const char kMessageSuffix[] = "Msg";
|
|
|
|
|
|
|
|
// JS object member argument names for cefQuery.
|
|
|
|
const char kMemberRequest[] = "request";
|
|
|
|
const char kMemberOnSuccess[] = "onSuccess";
|
|
|
|
const char kMemberOnFailure[] = "onFailure";
|
|
|
|
const char kMemberPersistent[] = "persistent";
|
|
|
|
|
|
|
|
// Default error information when a query is canceled.
|
|
|
|
const int kCanceledErrorCode = -1;
|
|
|
|
const char kCanceledErrorMessage[] = "The query has been canceled";
|
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
// Value of 16KB is chosen as a result of performance tests available at
|
|
|
|
// http://tests/ipc_performance
|
|
|
|
constexpr size_t kResponseSizeThreshold = 16384;
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Validate configuration settings.
|
|
|
|
bool ValidateConfig(CefMessageRouterConfig& config) {
|
|
|
|
// Must specify function names.
|
2017-05-17 11:29:28 +02:00
|
|
|
if (config.js_cancel_function.empty() || config.js_query_function.empty()) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
namespace cmru = cef_message_router_utils;
|
2022-07-04 11:49:15 +02:00
|
|
|
|
2023-10-05 17:34:40 +02:00
|
|
|
/**
|
|
|
|
* @brief A helper template for generating ID values.
|
|
|
|
*
|
|
|
|
* This class generates monotonically increasing ID values within the interval
|
|
|
|
* [kReservedId + 1, numeric_limits<T>::max()].
|
|
|
|
*
|
|
|
|
* @tparam T The data type for the ID values.
|
|
|
|
*/
|
2014-01-28 00:31:03 +01:00
|
|
|
template <typename T>
|
|
|
|
class IdGenerator {
|
|
|
|
public:
|
|
|
|
IdGenerator() : next_id_(kReservedId) {}
|
|
|
|
|
2021-12-06 22:59:14 +01:00
|
|
|
IdGenerator(const IdGenerator&) = delete;
|
|
|
|
IdGenerator& operator=(const IdGenerator&) = delete;
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
T GetNextId() {
|
2023-10-05 17:34:40 +02:00
|
|
|
if (next_id_ == std::numeric_limits<T>::max()) {
|
|
|
|
next_id_ = kReservedId;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2023-10-05 17:34:40 +02:00
|
|
|
return ++next_id_;
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T next_id_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Browser-side router implementation.
|
|
|
|
class CefMessageRouterBrowserSideImpl : public CefMessageRouterBrowserSide {
|
|
|
|
public:
|
|
|
|
// Implementation of the Callback interface.
|
|
|
|
class CallbackImpl : public CefMessageRouterBrowserSide::Callback {
|
|
|
|
public:
|
|
|
|
CallbackImpl(CefRefPtr<CefMessageRouterBrowserSideImpl> router,
|
|
|
|
int browser_id,
|
2023-06-01 16:07:20 +02:00
|
|
|
int64_t query_id,
|
2023-10-25 20:20:55 +02:00
|
|
|
bool persistent,
|
|
|
|
size_t message_size_threshold,
|
|
|
|
const std::string& query_message_name)
|
2014-01-28 00:31:03 +01:00
|
|
|
: router_(router),
|
|
|
|
browser_id_(browser_id),
|
|
|
|
query_id_(query_id),
|
2023-10-25 20:20:55 +02:00
|
|
|
persistent_(persistent),
|
|
|
|
message_size_threshold_(message_size_threshold),
|
|
|
|
query_message_name_(query_message_name) {}
|
2021-12-06 22:59:14 +01:00
|
|
|
|
|
|
|
CallbackImpl(const CallbackImpl&) = delete;
|
|
|
|
CallbackImpl& operator=(const CallbackImpl&) = delete;
|
|
|
|
|
2024-01-20 18:34:13 +01:00
|
|
|
~CallbackImpl() override {
|
2014-01-28 00:31:03 +01:00
|
|
|
// Hitting this DCHECK means that you didn't call Success or Failure
|
|
|
|
// on the Callback after returning true from Handler::OnQuery. You must
|
|
|
|
// call Failure to terminate persistent queries.
|
|
|
|
DCHECK(!router_);
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void Success(const CefString& response) override {
|
2023-10-25 20:20:55 +02:00
|
|
|
auto builder = cmru::CreateBrowserResponseBuilder(
|
|
|
|
message_size_threshold_, query_message_name_, response);
|
|
|
|
|
|
|
|
// We need to post task here for two reasons:
|
|
|
|
// 1) To safely access member variables.
|
|
|
|
// 2) To let the router to persist the query information before
|
|
|
|
// the Success callback is executed.
|
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&CallbackImpl::SuccessImpl, this, builder));
|
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
void Success(const void* data, size_t size) override {
|
|
|
|
auto builder = cmru::CreateBrowserResponseBuilder(
|
|
|
|
message_size_threshold_, query_message_name_, data, size);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
// We need to post task here for two reasons:
|
|
|
|
// 1) To safely access member variables.
|
|
|
|
// 2) To let the router to persist the query information before
|
|
|
|
// the Success callback is executed.
|
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&CallbackImpl::SuccessImpl, this, builder));
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void Failure(int error_code, const CefString& error_message) override {
|
2023-10-25 20:20:55 +02:00
|
|
|
// We need to post task here for two reasons:
|
|
|
|
// 1) To safely access member variables.
|
|
|
|
// 2) To give previosly submitted tasks by the Success calls to execute
|
|
|
|
// before we invalidate the callback.
|
|
|
|
CefPostTask(TID_UI, base::BindOnce(&CallbackImpl::FailureImpl, this,
|
|
|
|
error_code, error_message));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Detach() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
router_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SuccessImpl(const CefRefPtr<cmru::BrowserResponseBuilder>& builder) {
|
|
|
|
if (!router_) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
router_->OnCallbackSuccess(browser_id_, query_id_, builder);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
if (!persistent_) {
|
|
|
|
// Non-persistent callbacks are only good for a single use.
|
2020-01-15 14:36:24 +01:00
|
|
|
router_ = nullptr;
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
void FailureImpl(int error_code, const CefString& error_message) {
|
|
|
|
if (!router_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
router_->OnCallbackFailure(browser_id_, query_id_, error_code,
|
|
|
|
error_message);
|
|
|
|
|
|
|
|
// Failure always invalidates the callback.
|
2020-01-15 14:36:24 +01:00
|
|
|
router_ = nullptr;
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefMessageRouterBrowserSideImpl> router_;
|
|
|
|
const int browser_id_;
|
2023-06-01 16:07:20 +02:00
|
|
|
const int64_t query_id_;
|
2014-01-28 00:31:03 +01:00
|
|
|
const bool persistent_;
|
2023-10-25 20:20:55 +02:00
|
|
|
const size_t message_size_threshold_;
|
|
|
|
const std::string query_message_name_;
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CallbackImpl);
|
2014-01-28 00:31:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit CefMessageRouterBrowserSideImpl(const CefMessageRouterConfig& config)
|
|
|
|
: config_(config),
|
2017-05-17 11:29:28 +02:00
|
|
|
query_message_name_(config.js_query_function.ToString() +
|
|
|
|
kMessageSuffix),
|
|
|
|
cancel_message_name_(config.js_cancel_function.ToString() +
|
|
|
|
kMessageSuffix) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2021-12-06 22:59:14 +01:00
|
|
|
CefMessageRouterBrowserSideImpl(const CefMessageRouterBrowserSideImpl&) =
|
|
|
|
delete;
|
|
|
|
CefMessageRouterBrowserSideImpl& operator=(
|
|
|
|
const CefMessageRouterBrowserSideImpl&) = delete;
|
|
|
|
|
2024-01-20 18:34:13 +01:00
|
|
|
~CefMessageRouterBrowserSideImpl() override {
|
2014-01-28 00:31:03 +01:00
|
|
|
// There should be no pending queries when the router is deleted.
|
|
|
|
DCHECK(browser_query_info_map_.empty());
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
bool AddHandler(Handler* handler, bool first) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-08-13 20:30:35 +02:00
|
|
|
if (std::find(handlers_.begin(), handlers_.end(), handler) ==
|
|
|
|
handlers_.end()) {
|
|
|
|
handlers_.insert(first ? handlers_.begin() : handlers_.end(), handler);
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
bool RemoveHandler(Handler* handler) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-08-13 20:30:35 +02:00
|
|
|
auto it = std::find(handlers_.begin(), handlers_.end(), handler);
|
|
|
|
if (it != handlers_.end()) {
|
|
|
|
handlers_.erase(it);
|
2020-01-15 14:36:24 +01:00
|
|
|
CancelPendingFor(nullptr, handler, true);
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void CancelPending(CefRefPtr<CefBrowser> browser, Handler* handler) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CancelPendingFor(browser, handler, true);
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
int GetPendingCount(CefRefPtr<CefBrowser> browser,
|
2021-06-17 21:43:06 +02:00
|
|
|
Handler* handler) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_query_info_map_.empty()) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
if (handler) {
|
|
|
|
// Need to iterate over each QueryInfo object to test the handler.
|
|
|
|
class Visitor : public BrowserQueryInfoMap::Visitor {
|
|
|
|
public:
|
2024-01-20 18:34:13 +01:00
|
|
|
explicit Visitor(Handler* handler) : handler_(handler) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnNextInfo(int browser_id,
|
|
|
|
InfoIdType info_id,
|
|
|
|
InfoObjectType info,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* remove) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (info->handler == handler_) {
|
2014-01-28 00:31:03 +01:00
|
|
|
count_++;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count() const { return count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Handler* handler_;
|
2024-01-20 18:34:13 +01:00
|
|
|
int count_ = 0;
|
2014-01-28 00:31:03 +01:00
|
|
|
};
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
Visitor visitor(handler);
|
|
|
|
|
|
|
|
if (browser.get()) {
|
|
|
|
// Count queries associated with the specified browser.
|
2017-05-17 11:29:28 +02:00
|
|
|
browser_query_info_map_.FindAll(browser->GetIdentifier(), &visitor);
|
2014-01-28 00:31:03 +01:00
|
|
|
} else {
|
|
|
|
// Count all queries for all browsers.
|
|
|
|
browser_query_info_map_.FindAll(&visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return visitor.count();
|
|
|
|
} else if (browser.get()) {
|
2014-01-28 17:58:44 +01:00
|
|
|
return static_cast<int>(
|
|
|
|
browser_query_info_map_.size(browser->GetIdentifier()));
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 11:06:23 +02:00
|
|
|
return static_cast<int>(browser_query_info_map_.size());
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {
|
2020-01-15 14:36:24 +01:00
|
|
|
CancelPendingFor(browser, nullptr, false);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser) override {
|
2020-01-15 14:36:24 +01:00
|
|
|
CancelPendingFor(browser, nullptr, false);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame->IsMain()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CancelPendingFor(browser, nullptr, false);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefProcessId source_process,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
const std::string& message_name = message->GetName();
|
|
|
|
if (message_name == query_message_name_) {
|
2023-10-25 20:20:55 +02:00
|
|
|
cmru::RendererMessage content = cmru::ParseRendererMessage(message);
|
|
|
|
const int context_id = content.context_id;
|
|
|
|
const int request_id = content.request_id;
|
|
|
|
const bool persistent = content.is_persistent;
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2024-08-13 20:30:35 +02:00
|
|
|
if (handlers_.empty()) {
|
2014-01-28 00:31:03 +01:00
|
|
|
// No handlers so cancel the query.
|
2019-05-24 22:23:43 +02:00
|
|
|
CancelUnhandledQuery(browser, frame, context_id, request_id);
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int browser_id = browser->GetIdentifier();
|
2023-06-01 16:07:20 +02:00
|
|
|
const int64_t query_id = query_id_generator_.GetNextId();
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
CefRefPtr<CallbackImpl> callback =
|
|
|
|
new CallbackImpl(this, browser_id, query_id, persistent,
|
|
|
|
config_.message_size_threshold, query_message_name_);
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Make a copy of the handler list in case the user adds or removes a
|
|
|
|
// handler while we're iterating.
|
2024-08-13 20:30:35 +02:00
|
|
|
const HandlerSet handlers = handlers_;
|
2023-10-25 20:20:55 +02:00
|
|
|
|
|
|
|
Handler* handler = std::visit(
|
|
|
|
[&](const auto& arg) -> CefMessageRouterBrowserSide::Handler* {
|
|
|
|
for (auto handler : handlers) {
|
|
|
|
bool handled = handler->OnQuery(browser, frame, query_id, arg,
|
|
|
|
persistent, callback.get());
|
|
|
|
if (handled) {
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
},
|
|
|
|
content.payload);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// If the query isn't handled nothing should be keeping a reference to
|
|
|
|
// the callback.
|
2023-10-25 20:20:55 +02:00
|
|
|
DCHECK(handler != nullptr || callback->HasOneRef());
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
if (handler) {
|
2014-01-28 00:31:03 +01:00
|
|
|
// Persist the query information until the callback executes.
|
|
|
|
// It's safe to do this here because the callback will execute
|
|
|
|
// asynchronously.
|
2023-10-25 20:20:55 +02:00
|
|
|
QueryInfo* info =
|
|
|
|
new QueryInfo{browser, frame, context_id, request_id,
|
|
|
|
persistent, callback, handler};
|
2014-01-28 00:31:03 +01:00
|
|
|
browser_query_info_map_.Add(browser_id, query_id, info);
|
|
|
|
} else {
|
|
|
|
// Invalidate the callback.
|
|
|
|
callback->Detach();
|
|
|
|
|
|
|
|
// No one chose to handle the query so cancel it.
|
2019-05-24 22:23:43 +02:00
|
|
|
CancelUnhandledQuery(browser, frame, context_id, request_id);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else if (message_name == cancel_message_name_) {
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
DCHECK_EQ(args->GetSize(), 2U);
|
|
|
|
|
|
|
|
const int browser_id = browser->GetIdentifier();
|
|
|
|
const int context_id = args->GetInt(0);
|
|
|
|
const int request_id = args->GetInt(1);
|
|
|
|
|
|
|
|
CancelPendingRequest(browser_id, context_id, request_id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Structure representing a pending query.
|
|
|
|
struct QueryInfo {
|
|
|
|
// Browser and frame originated the query.
|
|
|
|
CefRefPtr<CefBrowser> browser;
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame;
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// IDs that uniquely identify the query in the renderer process. These
|
|
|
|
// values are opaque to the browser process but must be returned with the
|
|
|
|
// response.
|
|
|
|
int context_id;
|
|
|
|
int request_id;
|
|
|
|
|
|
|
|
// True if the query is persistent.
|
|
|
|
bool persistent;
|
|
|
|
|
|
|
|
// Callback associated with the query that must be detached when the query
|
|
|
|
// is canceled.
|
|
|
|
CefRefPtr<CallbackImpl> callback;
|
|
|
|
|
|
|
|
// Handler that should be notified if the query is automatically canceled.
|
|
|
|
Handler* handler;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Retrieve a QueryInfo object from the map based on the browser-side query
|
|
|
|
// ID. If |always_remove| is true then the QueryInfo object will always be
|
|
|
|
// removed from the map. Othewise, the QueryInfo object will only be removed
|
|
|
|
// if the query is non-persistent. If |removed| is true the caller is
|
|
|
|
// responsible for deleting the returned QueryInfo object.
|
|
|
|
QueryInfo* GetQueryInfo(int browser_id,
|
2023-06-01 16:07:20 +02:00
|
|
|
int64_t query_id,
|
2014-01-28 00:31:03 +01:00
|
|
|
bool always_remove,
|
|
|
|
bool* removed) {
|
|
|
|
class Visitor : public BrowserQueryInfoMap::Visitor {
|
|
|
|
public:
|
2024-01-20 18:34:13 +01:00
|
|
|
explicit Visitor(bool always_remove) : always_remove_(always_remove) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnNextInfo(int browser_id,
|
|
|
|
InfoIdType info_id,
|
|
|
|
InfoObjectType info,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* remove) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
*remove = removed_ = (always_remove_ || !info->persistent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool removed() const { return removed_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const bool always_remove_;
|
2024-01-20 18:34:13 +01:00
|
|
|
bool removed_ = false;
|
2014-01-28 00:31:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Visitor visitor(always_remove);
|
|
|
|
QueryInfo* info =
|
|
|
|
browser_query_info_map_.Find(browser_id, query_id, &visitor);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (info) {
|
2014-01-28 00:31:03 +01:00
|
|
|
*removed = visitor.removed();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by CallbackImpl on success.
|
2023-10-25 20:20:55 +02:00
|
|
|
void OnCallbackSuccess(
|
|
|
|
int browser_id,
|
|
|
|
int64_t query_id,
|
|
|
|
const CefRefPtr<cmru::BrowserResponseBuilder>& builder) {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
bool removed;
|
|
|
|
QueryInfo* info = GetQueryInfo(browser_id, query_id, false, &removed);
|
|
|
|
if (info) {
|
2023-10-25 20:20:55 +02:00
|
|
|
SendQuerySuccess(info->browser, info->frame, info->context_id,
|
|
|
|
info->request_id, builder);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (removed) {
|
2014-01-28 00:31:03 +01:00
|
|
|
delete info;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by CallbackImpl on failure.
|
|
|
|
void OnCallbackFailure(int browser_id,
|
2023-06-01 16:07:20 +02:00
|
|
|
int64_t query_id,
|
2014-01-28 00:31:03 +01:00
|
|
|
int error_code,
|
|
|
|
const CefString& error_message) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
bool removed;
|
|
|
|
QueryInfo* info = GetQueryInfo(browser_id, query_id, true, &removed);
|
|
|
|
if (info) {
|
|
|
|
SendQueryFailure(info, error_code, error_message);
|
|
|
|
DCHECK(removed);
|
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
void SendQuerySuccess(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int context_id,
|
|
|
|
int request_id,
|
|
|
|
const CefRefPtr<cmru::BrowserResponseBuilder>& builder) {
|
|
|
|
if (auto message = builder->Build(context_id, request_id)) {
|
2022-07-04 11:49:15 +02:00
|
|
|
frame->SendProcessMessage(PID_RENDERER, message);
|
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendQueryFailure(QueryInfo* info,
|
|
|
|
int error_code,
|
|
|
|
const CefString& error_message) {
|
2019-05-24 22:23:43 +02:00
|
|
|
SendQueryFailure(info->browser, info->frame, info->context_id,
|
|
|
|
info->request_id, error_code, error_message);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendQueryFailure(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-01-28 00:31:03 +01:00
|
|
|
int context_id,
|
|
|
|
int request_id,
|
|
|
|
int error_code,
|
|
|
|
const CefString& error_message) {
|
|
|
|
CefRefPtr<CefProcessMessage> message =
|
|
|
|
CefProcessMessage::Create(query_message_name_);
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
args->SetInt(0, context_id);
|
|
|
|
args->SetInt(1, request_id);
|
|
|
|
args->SetBool(2, false); // Indicates a failure result.
|
|
|
|
args->SetInt(3, error_code);
|
|
|
|
args->SetString(4, error_message);
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_RENDERER, message);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel a query that has not been sent to a handler.
|
2017-05-17 11:29:28 +02:00
|
|
|
void CancelUnhandledQuery(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2017-05-17 11:29:28 +02:00
|
|
|
int context_id,
|
2014-01-28 00:31:03 +01:00
|
|
|
int request_id) {
|
2019-05-24 22:23:43 +02:00
|
|
|
SendQueryFailure(browser, frame, context_id, request_id, kCanceledErrorCode,
|
2017-05-17 11:29:28 +02:00
|
|
|
kCanceledErrorMessage);
|
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// Cancel a query that has already been sent to a handler.
|
2023-06-01 16:07:20 +02:00
|
|
|
void CancelQuery(int64_t query_id, QueryInfo* info, bool notify_renderer) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (notify_renderer) {
|
2014-01-28 00:31:03 +01:00
|
|
|
SendQueryFailure(info, kCanceledErrorCode, kCanceledErrorMessage);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
info->handler->OnQueryCanceled(info->browser, info->frame, query_id);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// Invalidate the callback.
|
|
|
|
info->callback->Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel all pending queries associated with either |browser| or |handler|.
|
|
|
|
// If both |browser| and |handler| are NULL all pending queries will be
|
|
|
|
// canceled. Set |notify_renderer| to true if the renderer should be notified.
|
|
|
|
void CancelPendingFor(CefRefPtr<CefBrowser> browser,
|
|
|
|
Handler* handler,
|
|
|
|
bool notify_renderer) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Must execute on the UI thread.
|
2021-06-19 21:35:12 +02:00
|
|
|
CefPostTask(
|
|
|
|
TID_UI,
|
|
|
|
base::BindOnce(&CefMessageRouterBrowserSideImpl::CancelPendingFor,
|
|
|
|
this, browser, handler, notify_renderer));
|
2014-01-28 00:31:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_query_info_map_.empty()) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
class Visitor : public BrowserQueryInfoMap::Visitor {
|
|
|
|
public:
|
|
|
|
Visitor(CefMessageRouterBrowserSideImpl* router,
|
|
|
|
Handler* handler,
|
|
|
|
bool notify_renderer)
|
|
|
|
: router_(router),
|
|
|
|
handler_(handler),
|
|
|
|
notify_renderer_(notify_renderer) {}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnNextInfo(int browser_id,
|
|
|
|
InfoIdType info_id,
|
|
|
|
InfoObjectType info,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* remove) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
if (!handler_ || info->handler == handler_) {
|
|
|
|
*remove = true;
|
|
|
|
router_->CancelQuery(info_id, info, notify_renderer_);
|
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefMessageRouterBrowserSideImpl* router_;
|
|
|
|
Handler* handler_;
|
|
|
|
const bool notify_renderer_;
|
|
|
|
};
|
|
|
|
|
|
|
|
Visitor visitor(this, handler, notify_renderer);
|
|
|
|
|
|
|
|
if (browser.get()) {
|
|
|
|
// Cancel all queries associated with the specified browser.
|
2017-05-17 11:29:28 +02:00
|
|
|
browser_query_info_map_.FindAll(browser->GetIdentifier(), &visitor);
|
2014-01-28 00:31:03 +01:00
|
|
|
} else {
|
|
|
|
// Cancel all queries for all browsers.
|
|
|
|
browser_query_info_map_.FindAll(&visitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel a query based on the renderer-side IDs. If |request_id| is
|
|
|
|
// kReservedId all requests associated with |context_id| will be canceled.
|
|
|
|
void CancelPendingRequest(int browser_id, int context_id, int request_id) {
|
|
|
|
class Visitor : public BrowserQueryInfoMap::Visitor {
|
|
|
|
public:
|
|
|
|
Visitor(CefMessageRouterBrowserSideImpl* router,
|
|
|
|
int context_id,
|
|
|
|
int request_id)
|
2017-05-17 11:29:28 +02:00
|
|
|
: router_(router), context_id_(context_id), request_id_(request_id) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnNextInfo(int browser_id,
|
|
|
|
InfoIdType info_id,
|
|
|
|
InfoObjectType info,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* remove) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
if (info->context_id == context_id_ &&
|
|
|
|
(request_id_ == kReservedId || info->request_id == request_id_)) {
|
|
|
|
*remove = true;
|
|
|
|
router_->CancelQuery(info_id, info, false);
|
|
|
|
delete info;
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Stop iterating if only canceling a single request.
|
|
|
|
return (request_id_ == kReservedId);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefMessageRouterBrowserSideImpl* router_;
|
|
|
|
const int context_id_;
|
|
|
|
const int request_id_;
|
|
|
|
};
|
|
|
|
|
|
|
|
Visitor visitor(this, context_id, request_id);
|
|
|
|
browser_query_info_map_.FindAll(browser_id, &visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CefMessageRouterConfig config_;
|
|
|
|
const std::string query_message_name_;
|
|
|
|
const std::string cancel_message_name_;
|
|
|
|
|
2023-06-01 16:07:20 +02:00
|
|
|
IdGenerator<int64_t> query_id_generator_;
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// Set of currently registered handlers. An entry is added when a handler is
|
|
|
|
// registered and removed when a handler is unregistered.
|
2024-08-13 20:30:35 +02:00
|
|
|
using HandlerSet = std::vector<Handler*>;
|
|
|
|
HandlerSet handlers_;
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// Map of query ID to QueryInfo instance. An entry is added when a Handler
|
|
|
|
// indicates that it will handle the query and removed when either the query
|
|
|
|
// is completed via the Callback, the query is explicitly canceled from the
|
|
|
|
// renderer process, or the associated context is (or will be) released.
|
2023-06-01 16:07:20 +02:00
|
|
|
using BrowserQueryInfoMap = CefBrowserInfoMap<int64_t, QueryInfo*>;
|
2014-01-28 00:31:03 +01:00
|
|
|
BrowserQueryInfoMap browser_query_info_map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer-side router implementation.
|
|
|
|
class CefMessageRouterRendererSideImpl : public CefMessageRouterRendererSide {
|
|
|
|
public:
|
|
|
|
class V8HandlerImpl : public CefV8Handler {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
V8HandlerImpl(CefRefPtr<CefMessageRouterRendererSideImpl> router,
|
|
|
|
const CefMessageRouterConfig& config)
|
|
|
|
: router_(router), config_(config), context_id_(kReservedId) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2021-12-06 22:59:14 +01:00
|
|
|
V8HandlerImpl(const V8HandlerImpl&) = delete;
|
|
|
|
V8HandlerImpl& operator=(const V8HandlerImpl&) = delete;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool Execute(const CefString& name,
|
|
|
|
CefRefPtr<CefV8Value> object,
|
|
|
|
const CefV8ValueList& arguments,
|
|
|
|
CefRefPtr<CefV8Value>& retval,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefString& exception) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
if (name == config_.js_query_function) {
|
|
|
|
if (arguments.size() != 1 || !arguments[0]->IsObject()) {
|
|
|
|
exception = "Invalid arguments; expecting a single object";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> arg = arguments[0];
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> requestVal = arg->GetValue(kMemberRequest);
|
2023-10-25 20:20:55 +02:00
|
|
|
if (!requestVal.get()) {
|
|
|
|
exception = "Invalid arguments; object member '" +
|
|
|
|
std::string(kMemberRequest) + "' is required";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!requestVal->IsString() && !requestVal->IsArrayBuffer()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
exception = "Invalid arguments; object member '" +
|
|
|
|
std::string(kMemberRequest) +
|
2023-10-25 20:20:55 +02:00
|
|
|
"' must have type string or ArrayBuffer";
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
CefRefPtr<CefV8Value> successVal = nullptr;
|
2014-01-28 00:31:03 +01:00
|
|
|
if (arg->HasValue(kMemberOnSuccess)) {
|
|
|
|
successVal = arg->GetValue(kMemberOnSuccess);
|
|
|
|
if (!successVal->IsFunction()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
exception = "Invalid arguments; object member '" +
|
|
|
|
std::string(kMemberOnSuccess) +
|
|
|
|
"' must have type function";
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
CefRefPtr<CefV8Value> failureVal = nullptr;
|
2014-01-28 00:31:03 +01:00
|
|
|
if (arg->HasValue(kMemberOnFailure)) {
|
|
|
|
failureVal = arg->GetValue(kMemberOnFailure);
|
|
|
|
if (!failureVal->IsFunction()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
exception = "Invalid arguments; object member '" +
|
|
|
|
std::string(kMemberOnFailure) +
|
|
|
|
"' must have type function";
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
CefRefPtr<CefV8Value> persistentVal = nullptr;
|
2014-01-28 00:31:03 +01:00
|
|
|
if (arg->HasValue(kMemberPersistent)) {
|
|
|
|
persistentVal = arg->GetValue(kMemberPersistent);
|
|
|
|
if (!persistentVal->IsBool()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
exception = "Invalid arguments; object member '" +
|
|
|
|
std::string(kMemberPersistent) +
|
|
|
|
"' must have type boolean";
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
|
|
|
const int context_id = GetIDForContext(context);
|
|
|
|
const bool persistent =
|
|
|
|
(persistentVal.get() && persistentVal->GetBoolValue());
|
|
|
|
|
|
|
|
const int request_id = router_->SendQuery(
|
2023-10-25 20:20:55 +02:00
|
|
|
context->GetBrowser(), context->GetFrame(), context_id, requestVal,
|
|
|
|
persistent, successVal, failureVal);
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
retval = CefV8Value::CreateInt(request_id);
|
2023-10-25 20:20:55 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
} else if (name == config_.js_cancel_function) {
|
|
|
|
if (arguments.size() != 1 || !arguments[0]->IsInt()) {
|
|
|
|
exception = "Invalid arguments; expecting a single integer";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
const int request_id = arguments[0]->GetIntValue();
|
|
|
|
if (request_id != kReservedId) {
|
|
|
|
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
|
|
|
const int context_id = GetIDForContext(context);
|
2019-05-24 22:23:43 +02:00
|
|
|
result =
|
|
|
|
router_->SendCancel(context->GetBrowser(), context->GetFrame(),
|
|
|
|
context_id, request_id);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
retval = CefV8Value::CreateBool(result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Don't create the context ID until it's actually needed.
|
|
|
|
int GetIDForContext(CefRefPtr<CefV8Context> context) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (context_id_ == kReservedId) {
|
2014-01-28 00:31:03 +01:00
|
|
|
context_id_ = router_->CreateIDForContext(context);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return context_id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefMessageRouterRendererSideImpl> router_;
|
|
|
|
const CefMessageRouterConfig config_;
|
|
|
|
int context_id_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(V8HandlerImpl);
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit CefMessageRouterRendererSideImpl(
|
|
|
|
const CefMessageRouterConfig& config)
|
2014-01-28 00:31:03 +01:00
|
|
|
: config_(config),
|
2017-05-17 11:29:28 +02:00
|
|
|
query_message_name_(config.js_query_function.ToString() +
|
|
|
|
kMessageSuffix),
|
|
|
|
cancel_message_name_(config.js_cancel_function.ToString() +
|
|
|
|
kMessageSuffix) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2021-12-06 22:59:14 +01:00
|
|
|
CefMessageRouterRendererSideImpl(const CefMessageRouterRendererSideImpl&) =
|
|
|
|
delete;
|
|
|
|
CefMessageRouterRendererSideImpl& operator=(
|
|
|
|
const CefMessageRouterRendererSideImpl&) = delete;
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
int GetPendingCount(CefRefPtr<CefBrowser> browser,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefV8Context> context) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_request_info_map_.empty()) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
if (context.get()) {
|
|
|
|
const int context_id = GetIDForContext(context, false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (context_id == kReservedId) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return 0; // Nothing associated with the specified context.
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// Need to iterate over each RequestInfo object to test the context.
|
|
|
|
class Visitor : public BrowserRequestInfoMap::Visitor {
|
|
|
|
public:
|
2024-01-20 18:34:13 +01:00
|
|
|
explicit Visitor(int context_id) : context_id_(context_id) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnNextInfo(int browser_id,
|
|
|
|
InfoIdType info_id,
|
|
|
|
InfoObjectType info,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* remove) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (info_id.first == context_id_) {
|
2014-01-28 00:31:03 +01:00
|
|
|
count_++;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count() const { return count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int context_id_;
|
2024-01-20 18:34:13 +01:00
|
|
|
int count_ = 0;
|
2014-01-28 00:31:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Visitor visitor(context_id);
|
|
|
|
|
|
|
|
if (browser.get()) {
|
|
|
|
// Count requests associated with the specified browser.
|
2017-05-17 11:29:28 +02:00
|
|
|
browser_request_info_map_.FindAll(browser->GetIdentifier(), &visitor);
|
2014-01-28 00:31:03 +01:00
|
|
|
} else {
|
|
|
|
// Count all requests for all browsers.
|
|
|
|
browser_request_info_map_.FindAll(&visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return visitor.count();
|
|
|
|
} else if (browser.get()) {
|
2014-01-28 17:58:44 +01:00
|
|
|
return static_cast<int>(
|
|
|
|
browser_request_info_map_.size(browser->GetIdentifier()));
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2021-09-20 11:06:23 +02:00
|
|
|
return static_cast<int>(browser_request_info_map_.size());
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefV8Context> context) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
// Register function handlers with the 'window' object.
|
|
|
|
CefRefPtr<CefV8Value> window = context->GetGlobal();
|
|
|
|
|
|
|
|
CefRefPtr<V8HandlerImpl> handler = new V8HandlerImpl(this, config_);
|
|
|
|
CefV8Value::PropertyAttribute attributes =
|
|
|
|
static_cast<CefV8Value::PropertyAttribute>(
|
2017-05-17 11:29:28 +02:00
|
|
|
V8_PROPERTY_ATTRIBUTE_READONLY | V8_PROPERTY_ATTRIBUTE_DONTENUM |
|
2014-01-28 00:31:03 +01:00
|
|
|
V8_PROPERTY_ATTRIBUTE_DONTDELETE);
|
|
|
|
|
|
|
|
// Add the query function.
|
|
|
|
CefRefPtr<CefV8Value> query_func =
|
|
|
|
CefV8Value::CreateFunction(config_.js_query_function, handler.get());
|
|
|
|
window->SetValue(config_.js_query_function, query_func, attributes);
|
|
|
|
|
|
|
|
// Add the cancel function.
|
|
|
|
CefRefPtr<CefV8Value> cancel_func =
|
|
|
|
CefV8Value::CreateFunction(config_.js_cancel_function, handler.get());
|
|
|
|
window->SetValue(config_.js_cancel_function, cancel_func, attributes);
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void OnContextReleased(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefV8Context> context) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
// Get the context ID and remove the context from the map.
|
|
|
|
const int context_id = GetIDForContext(context, true);
|
|
|
|
if (context_id != kReservedId) {
|
|
|
|
// Cancel all pending requests for the context.
|
2019-05-24 22:23:43 +02:00
|
|
|
SendCancel(browser, frame, context_id, kReservedId);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefProcessId source_process,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
if (message->GetName() != query_message_name_) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
cmru::BrowserMessage content = cmru::ParseBrowserMessage(message);
|
|
|
|
if (content.is_success) {
|
|
|
|
std::visit(
|
|
|
|
[&](const auto& arg) {
|
|
|
|
ExecuteSuccessCallback(browser->GetIdentifier(), content.context_id,
|
|
|
|
content.request_id, arg);
|
|
|
|
},
|
|
|
|
content.payload);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ExecuteFailureCallback(browser->GetIdentifier(), content.context_id,
|
|
|
|
content.request_id, content.error_code,
|
|
|
|
std::get<CefString>(content.payload));
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
return true;
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Structure representing a pending request.
|
|
|
|
struct RequestInfo {
|
|
|
|
// True if the request is persistent.
|
|
|
|
bool persistent;
|
|
|
|
|
|
|
|
// Success callback function. May be NULL.
|
|
|
|
CefRefPtr<CefV8Value> success_callback;
|
|
|
|
|
|
|
|
// Failure callback function. May be NULL.
|
|
|
|
CefRefPtr<CefV8Value> failure_callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Retrieve a RequestInfo object from the map based on the renderer-side
|
|
|
|
// IDs. If |always_remove| is true then the RequestInfo object will always be
|
|
|
|
// removed from the map. Othewise, the RequestInfo object will only be removed
|
|
|
|
// if the query is non-persistent. If |removed| is true the caller is
|
|
|
|
// responsible for deleting the returned QueryInfo object.
|
|
|
|
RequestInfo* GetRequestInfo(int browser_id,
|
|
|
|
int context_id,
|
2020-04-23 20:37:05 +02:00
|
|
|
int request_id,
|
2014-01-28 00:31:03 +01:00
|
|
|
bool always_remove,
|
|
|
|
bool* removed) {
|
|
|
|
class Visitor : public BrowserRequestInfoMap::Visitor {
|
|
|
|
public:
|
2024-01-20 18:34:13 +01:00
|
|
|
explicit Visitor(bool always_remove) : always_remove_(always_remove) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnNextInfo(int browser_id,
|
|
|
|
InfoIdType info_id,
|
|
|
|
InfoObjectType info,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* remove) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
*remove = removed_ = (always_remove_ || !info->persistent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool removed() const { return removed_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const bool always_remove_;
|
2024-01-20 18:34:13 +01:00
|
|
|
bool removed_ = false;
|
2014-01-28 00:31:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Visitor visitor(always_remove);
|
2017-05-17 11:29:28 +02:00
|
|
|
RequestInfo* info = browser_request_info_map_.Find(
|
2020-04-23 20:37:05 +02:00
|
|
|
browser_id, std::make_pair(context_id, request_id), &visitor);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (info) {
|
2014-01-28 00:31:03 +01:00
|
|
|
*removed = visitor.removed();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the new request ID.
|
|
|
|
int SendQuery(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-01-28 00:31:03 +01:00
|
|
|
int context_id,
|
2023-10-25 20:20:55 +02:00
|
|
|
CefRefPtr<CefV8Value> request,
|
2014-01-28 00:31:03 +01:00
|
|
|
bool persistent,
|
|
|
|
CefRefPtr<CefV8Value> success_callback,
|
|
|
|
CefRefPtr<CefV8Value> failure_callback) {
|
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
const int request_id = request_id_generator_.GetNextId();
|
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
auto* info =
|
|
|
|
new RequestInfo{persistent, success_callback, failure_callback};
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
browser_request_info_map_.Add(browser->GetIdentifier(),
|
2017-05-17 11:29:28 +02:00
|
|
|
std::make_pair(context_id, request_id), info);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
CefRefPtr<CefProcessMessage> message = cmru::BuildRendererMsg(
|
|
|
|
config_.message_size_threshold, query_message_name_, context_id,
|
|
|
|
request_id, request, persistent);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, message);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
return request_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If |request_id| is kReservedId all requests associated with |context_id|
|
|
|
|
// will be canceled, otherwise only the specified |request_id| will be
|
2017-05-17 11:29:28 +02:00
|
|
|
// canceled. Returns true if any request was canceled.
|
2014-01-28 00:31:03 +01:00
|
|
|
bool SendCancel(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-01-28 00:31:03 +01:00
|
|
|
int context_id,
|
|
|
|
int request_id) {
|
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
const int browser_id = browser->GetIdentifier();
|
|
|
|
|
|
|
|
int cancel_count = 0;
|
|
|
|
if (request_id != kReservedId) {
|
|
|
|
// Cancel a single request.
|
|
|
|
bool removed;
|
|
|
|
RequestInfo* info =
|
|
|
|
GetRequestInfo(browser_id, context_id, request_id, true, &removed);
|
|
|
|
if (info) {
|
|
|
|
DCHECK(removed);
|
|
|
|
delete info;
|
|
|
|
cancel_count = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Cancel all requests with the specified context ID.
|
|
|
|
class Visitor : public BrowserRequestInfoMap::Visitor {
|
|
|
|
public:
|
2024-01-20 18:34:13 +01:00
|
|
|
explicit Visitor(int context_id) : context_id_(context_id) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool OnNextInfo(int browser_id,
|
|
|
|
InfoIdType info_id,
|
|
|
|
InfoObjectType info,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* remove) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
if (info_id.first == context_id_) {
|
|
|
|
*remove = true;
|
|
|
|
delete info;
|
|
|
|
cancel_count_++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cancel_count() const { return cancel_count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int context_id_;
|
2024-01-20 18:34:13 +01:00
|
|
|
int cancel_count_ = 0;
|
2014-01-28 00:31:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Visitor visitor(context_id);
|
|
|
|
browser_request_info_map_.FindAll(browser_id, &visitor);
|
|
|
|
cancel_count = visitor.cancel_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cancel_count > 0) {
|
|
|
|
CefRefPtr<CefProcessMessage> message =
|
|
|
|
CefProcessMessage::Create(cancel_message_name_);
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
args->SetInt(0, context_id);
|
|
|
|
args->SetInt(1, request_id);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, message);
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute the onSuccess JavaScript callback.
|
2017-05-17 11:29:28 +02:00
|
|
|
void ExecuteSuccessCallback(int browser_id,
|
|
|
|
int context_id,
|
|
|
|
int request_id,
|
2014-01-28 00:31:03 +01:00
|
|
|
const CefString& response) {
|
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
bool removed;
|
|
|
|
RequestInfo* info =
|
|
|
|
GetRequestInfo(browser_id, context_id, request_id, false, &removed);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!info) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> context = GetContextByID(context_id);
|
|
|
|
if (context && info->success_callback) {
|
|
|
|
CefV8ValueList args;
|
|
|
|
args.push_back(CefV8Value::CreateString(response));
|
2020-01-15 14:36:24 +01:00
|
|
|
info->success_callback->ExecuteFunctionWithContext(context, nullptr,
|
|
|
|
args);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (removed) {
|
2014-01-28 00:31:03 +01:00
|
|
|
delete info;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
// Execute the onSuccess JavaScript callback.
|
|
|
|
void ExecuteSuccessCallback(int browser_id,
|
|
|
|
int context_id,
|
|
|
|
int request_id,
|
|
|
|
const CefRefPtr<CefBinaryBuffer>& response) {
|
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
bool removed;
|
|
|
|
RequestInfo* info =
|
|
|
|
GetRequestInfo(browser_id, context_id, request_id, false, &removed);
|
|
|
|
if (!info) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> context = GetContextByID(context_id);
|
|
|
|
if (context && info->success_callback && context->Enter()) {
|
2024-08-05 18:00:58 +02:00
|
|
|
CefRefPtr<CefV8Value> value;
|
|
|
|
#ifdef CEF_V8_ENABLE_SANDBOX
|
|
|
|
value = CefV8Value::CreateArrayBufferWithCopy(response->GetData(),
|
|
|
|
response->GetSize());
|
|
|
|
#else
|
|
|
|
value = CefV8Value::CreateArrayBuffer(
|
|
|
|
response->GetData(), response->GetSize(),
|
|
|
|
new cmru::BinaryValueABRCallback(response));
|
|
|
|
#endif
|
2023-10-25 20:20:55 +02:00
|
|
|
|
|
|
|
context->Exit();
|
|
|
|
|
|
|
|
CefV8ValueList args;
|
|
|
|
args.push_back(value);
|
|
|
|
info->success_callback->ExecuteFunctionWithContext(context, nullptr,
|
|
|
|
args);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (removed) {
|
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Execute the onFailure JavaScript callback.
|
2017-05-17 11:29:28 +02:00
|
|
|
void ExecuteFailureCallback(int browser_id,
|
|
|
|
int context_id,
|
|
|
|
int request_id,
|
|
|
|
int error_code,
|
|
|
|
const CefString& error_message) {
|
2014-01-28 00:31:03 +01:00
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
bool removed;
|
|
|
|
RequestInfo* info =
|
|
|
|
GetRequestInfo(browser_id, context_id, request_id, true, &removed);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!info) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> context = GetContextByID(context_id);
|
|
|
|
if (context && info->failure_callback) {
|
|
|
|
CefV8ValueList args;
|
|
|
|
args.push_back(CefV8Value::CreateInt(error_code));
|
|
|
|
args.push_back(CefV8Value::CreateString(error_message));
|
2020-01-15 14:36:24 +01:00
|
|
|
info->failure_callback->ExecuteFunctionWithContext(context, nullptr,
|
|
|
|
args);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(removed);
|
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CreateIDForContext(CefRefPtr<CefV8Context> context) {
|
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
// The context should not already have an associated ID.
|
|
|
|
DCHECK_EQ(GetIDForContext(context, false), kReservedId);
|
|
|
|
|
|
|
|
const int context_id = context_id_generator_.GetNextId();
|
|
|
|
context_map_.insert(std::make_pair(context_id, context));
|
|
|
|
return context_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieves the existing ID value associated with the specified |context|.
|
|
|
|
// If |remove| is true the context will also be removed from the map.
|
|
|
|
int GetIDForContext(CefRefPtr<CefV8Context> context, bool remove) {
|
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
ContextMap::iterator it = context_map_.begin();
|
|
|
|
for (; it != context_map_.end(); ++it) {
|
|
|
|
if (it->second->IsSame(context)) {
|
|
|
|
int context_id = it->first;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (remove) {
|
2014-01-28 00:31:03 +01:00
|
|
|
context_map_.erase(it);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return context_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return kReservedId;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> GetContextByID(int context_id) {
|
|
|
|
CEF_REQUIRE_RENDERER_THREAD();
|
|
|
|
|
|
|
|
ContextMap::const_iterator it = context_map_.find(context_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != context_map_.end()) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return it->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const CefMessageRouterConfig config_;
|
|
|
|
const std::string query_message_name_;
|
|
|
|
const std::string cancel_message_name_;
|
|
|
|
|
|
|
|
IdGenerator<int> context_id_generator_;
|
|
|
|
IdGenerator<int> request_id_generator_;
|
|
|
|
|
|
|
|
// Map of (request ID, context ID) to RequestInfo for pending queries. An
|
|
|
|
// entry is added when a request is initiated via the bound function and
|
|
|
|
// removed when either the request completes, is canceled via the bound
|
|
|
|
// function, or the associated context is released.
|
2021-12-06 22:59:14 +01:00
|
|
|
using BrowserRequestInfoMap =
|
|
|
|
CefBrowserInfoMap<std::pair<int, int>, RequestInfo*>;
|
2014-01-28 00:31:03 +01:00
|
|
|
BrowserRequestInfoMap browser_request_info_map_;
|
|
|
|
|
|
|
|
// Map of context ID to CefV8Context for existing contexts. An entry is added
|
|
|
|
// when a bound function is executed for the first time in the context and
|
|
|
|
// removed when the context is released.
|
2021-12-06 22:59:14 +01:00
|
|
|
using ContextMap = std::map<int, CefRefPtr<CefV8Context>>;
|
2014-01-28 00:31:03 +01:00
|
|
|
ContextMap context_map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefMessageRouterConfig::CefMessageRouterConfig()
|
2022-07-04 11:49:15 +02:00
|
|
|
: js_query_function("cefQuery"),
|
|
|
|
js_cancel_function("cefQueryCancel"),
|
|
|
|
message_size_threshold(kResponseSizeThreshold) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefMessageRouterBrowserSide> CefMessageRouterBrowserSide::Create(
|
|
|
|
const CefMessageRouterConfig& config) {
|
|
|
|
CefMessageRouterConfig validated_config = config;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!ValidateConfig(validated_config)) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return new CefMessageRouterBrowserSideImpl(validated_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefMessageRouterRendererSide> CefMessageRouterRendererSide::Create(
|
|
|
|
const CefMessageRouterConfig& config) {
|
|
|
|
CefMessageRouterConfig validated_config = config;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!ValidateConfig(validated_config)) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
return new CefMessageRouterRendererSideImpl(validated_config);
|
|
|
|
}
|