2012-06-11 17:52:49 +02:00
|
|
|
// Copyright (c) 2012 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 00:52:42 +01:00
|
|
|
#include "tests/cefclient/renderer/client_renderer.h"
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#include "include/cef_crash_util.h"
|
2012-06-11 17:52:49 +02:00
|
|
|
#include "include/cef_dom.h"
|
2014-07-11 22:10:05 +02:00
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2014-01-28 00:31:03 +01:00
|
|
|
#include "include/wrapper/cef_message_router.h"
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
namespace client::renderer {
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
// Must match the value in client_handler.cc.
|
|
|
|
const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged";
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
class ClientRenderDelegate : public ClientAppRenderer::Delegate {
|
2012-06-11 17:52:49 +02:00
|
|
|
public:
|
2024-01-20 03:22:56 +01:00
|
|
|
ClientRenderDelegate() = default;
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app) override {
|
2016-12-12 11:05:29 +01:00
|
|
|
if (CefCrashReportingEnabled()) {
|
|
|
|
// Set some crash keys for testing purposes. Keys must be defined in the
|
|
|
|
// "crash_reporter.cfg" file. See cef_crash_util.h for details.
|
2018-02-15 01:12:09 +01:00
|
|
|
CefSetCrashKeyValue("testkey_small1", "value1_small_renderer");
|
|
|
|
CefSetCrashKeyValue("testkey_small2", "value2_small_renderer");
|
|
|
|
CefSetCrashKeyValue("testkey_medium1", "value1_medium_renderer");
|
|
|
|
CefSetCrashKeyValue("testkey_medium2", "value2_medium_renderer");
|
|
|
|
CefSetCrashKeyValue("testkey_large1", "value1_large_renderer");
|
|
|
|
CefSetCrashKeyValue("testkey_large2", "value2_large_renderer");
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Create the renderer-side router for query handling.
|
|
|
|
CefMessageRouterConfig config;
|
|
|
|
message_router_ = CefMessageRouterRendererSide::Create(config);
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
void OnContextCreated(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2021-06-17 21:43:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
void OnContextReleased(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2021-06-17 21:43:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
void OnFocusedNodeChanged(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefDOMNode> node) override {
|
2012-06-11 17:52:49 +02:00
|
|
|
bool is_editable = (node.get() && node->IsEditable());
|
|
|
|
if (is_editable != last_node_is_editable_) {
|
|
|
|
// Notify the browser of the change in focused element type.
|
|
|
|
last_node_is_editable_ = is_editable;
|
|
|
|
CefRefPtr<CefProcessMessage> message =
|
|
|
|
CefProcessMessage::Create(kFocusedNodeChangedMessage);
|
|
|
|
message->GetArgumentList()->SetBool(0, is_editable);
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, message);
|
2012-06-11 17:52:49 +02: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,
|
2021-06-17 21:43:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
private:
|
2024-01-20 03:22:56 +01:00
|
|
|
bool last_node_is_editable_ = false;
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Handles the renderer side of query routing.
|
|
|
|
CefRefPtr<CefMessageRouterRendererSide> message_router_;
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ClientRenderDelegate);
|
2012-06-11 17:52:49 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(ClientRenderDelegate);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void CreateDelegates(ClientAppRenderer::DelegateSet& delegates) {
|
2012-06-11 17:52:49 +02:00
|
|
|
delegates.insert(new ClientRenderDelegate);
|
|
|
|
}
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
} // namespace client::renderer
|