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.
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
// Include this first to avoid type conflicts with CEF headers.
|
|
|
|
#include "tests/unittests/chromium_includes.h"
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
#include "tests/unittests/routing_test_handler.h"
|
|
|
|
#include "tests/cefclient/client_app.h"
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
using client::ClientApp;
|
|
|
|
|
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.
|
|
|
|
class RoutingRenderDelegate : public ClientApp::RenderDelegate {
|
|
|
|
public:
|
|
|
|
RoutingRenderDelegate() {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnWebKitInitialized(CefRefPtr<ClientApp> 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);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnContextCreated(CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnContextCreated(browser, frame, context);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnContextReleased(CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnContextReleased(browser, frame, context);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnProcessMessageReceived(
|
2014-01-28 00:31:03 +01:00
|
|
|
CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
return message_router_->OnProcessMessageReceived(
|
|
|
|
browser, source_process, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRefPtr<CefMessageRouterRendererSide> message_router_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(RoutingRenderDelegate);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
RoutingTestHandler::RoutingTestHandler() {
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
TerminationStatus status) {
|
|
|
|
message_router_->OnRenderProcessTerminated(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RoutingTestHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
bool is_redirect) {
|
|
|
|
message_router_->OnBeforeBrowse(browser, frame);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RoutingTestHandler::OnProcessMessageReceived(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) {
|
|
|
|
return message_router_->OnProcessMessageReceived(
|
|
|
|
browser, source_process, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point for creating the test delegate.
|
|
|
|
// Called from client_app_delegates.cc.
|
|
|
|
void CreateRoutingTestHandlerDelegate(
|
|
|
|
ClientApp::RenderDelegateSet& delegates) {
|
|
|
|
delegates.insert(new RoutingRenderDelegate);
|
|
|
|
}
|