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
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
namespace client {
|
|
|
|
namespace 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:
|
2017-05-17 11:29:28 +02:00
|
|
|
ClientRenderDelegate() : last_node_is_editable_(false) {}
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OnRenderThreadCreated(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefListValue> extra_info) 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app) OVERRIDE {
|
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,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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);
|
|
|
|
browser->SendProcessMessage(PID_BROWSER, message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool OnProcessMessageReceived(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) OVERRIDE {
|
|
|
|
return message_router_->OnProcessMessageReceived(browser, source_process,
|
|
|
|
message);
|
2014-01-28 00:31:03 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
private:
|
|
|
|
bool last_node_is_editable_;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
} // namespace renderer
|
|
|
|
} // namespace client
|