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.
|
|
|
|
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/routing_test_handler.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/renderer/client_app_renderer.h"
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
using client::ClientAppRenderer;
|
2015-01-23 20:09:34 +01:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void SetRouterConfig(CefMessageRouterConfig& config) {
|
|
|
|
config.js_query_function = "testQuery";
|
|
|
|
config.js_cancel_function = "testQueryCancel";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle the renderer side of the routing implementation.
|
2015-01-31 05:41:36 +01:00
|
|
|
class RoutingRenderDelegate : public ClientAppRenderer::Delegate {
|
2014-01-28 00:31:03 +01:00
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
RoutingRenderDelegate() = default;
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
// Create the renderer-side router for query handling.
|
|
|
|
CefMessageRouterConfig config;
|
|
|
|
SetRouterConfig(config);
|
|
|
|
message_router_ = CefMessageRouterRendererSide::Create(config);
|
|
|
|
}
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnContextCreated(CefRefPtr<ClientAppRenderer> app,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) override {
|
2017-05-17 11:29:28 +02:00
|
|
|
message_router_->OnContextCreated(browser, frame, context);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnContextReleased(CefRefPtr<ClientAppRenderer> app,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) override {
|
2017-05-17 11:29:28 +02:00
|
|
|
message_router_->OnContextReleased(browser, frame, context);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool OnProcessMessageReceived(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2019-05-24 22:23:43 +02:00
|
|
|
return message_router_->OnProcessMessageReceived(browser, frame,
|
|
|
|
source_process, message);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRefPtr<CefMessageRouterRendererSide> message_router_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(RoutingRenderDelegate);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
RoutingTestHandler::RoutingTestHandler(CompletionState* completion_state)
|
|
|
|
: TestHandler(completion_state) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
void RoutingTestHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
2014-09-27 01:48:19 +02:00
|
|
|
if (!message_router_.get()) {
|
2014-01-28 00:31:03 +01:00
|
|
|
// Create the browser-side router for query handling.
|
|
|
|
CefMessageRouterConfig config;
|
|
|
|
SetRouterConfig(config);
|
|
|
|
message_router_ = CefMessageRouterBrowserSide::Create(config);
|
|
|
|
message_router_->AddHandler(this, false);
|
|
|
|
}
|
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoutingTestHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
|
|
|
message_router_->OnBeforeClose(browser);
|
|
|
|
TestHandler::OnBeforeClose(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoutingTestHandler::OnRenderProcessTerminated(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
2024-03-12 20:47:10 +01:00
|
|
|
TerminationStatus status,
|
|
|
|
int error_code,
|
|
|
|
const CefString& error_string) {
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnRenderProcessTerminated(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RoutingTestHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2018-04-27 17:11:53 +02:00
|
|
|
bool user_gesture,
|
2014-01-28 00:31:03 +01:00
|
|
|
bool is_redirect) {
|
|
|
|
message_router_->OnBeforeBrowse(browser, frame);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RoutingTestHandler::OnProcessMessageReceived(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-01-28 00:31:03 +01:00
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) {
|
2019-05-24 22:23:43 +02:00
|
|
|
return message_router_->OnProcessMessageReceived(browser, frame,
|
|
|
|
source_process, message);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point for creating the test delegate.
|
|
|
|
// Called from client_app_delegates.cc.
|
|
|
|
void CreateRoutingTestHandlerDelegate(
|
2015-01-31 05:41:36 +01:00
|
|
|
ClientAppRenderer::DelegateSet& delegates) {
|
2014-01-28 00:31:03 +01:00
|
|
|
delegates.insert(new RoutingRenderDelegate);
|
|
|
|
}
|