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.
|
|
|
|
|
|
|
|
#include "cefclient/client_renderer.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
namespace client_renderer {
|
|
|
|
|
|
|
|
const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged";
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ClientRenderDelegate : public ClientApp::RenderDelegate {
|
|
|
|
public:
|
|
|
|
ClientRenderDelegate()
|
|
|
|
: last_node_is_editable_(false) {
|
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
virtual void OnWebKitInitialized(CefRefPtr<ClientApp> app) OVERRIDE {
|
|
|
|
// Create the renderer-side router for query handling.
|
|
|
|
CefMessageRouterConfig config;
|
|
|
|
message_router_ = CefMessageRouterRendererSide::Create(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnContextCreated(CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) OVERRIDE {
|
|
|
|
message_router_->OnContextCreated(browser, frame, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnContextReleased(CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) OVERRIDE {
|
|
|
|
message_router_->OnContextReleased(browser, frame, context);
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual void OnFocusedNodeChanged(CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefDOMNode> node) OVERRIDE {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
virtual bool OnProcessMessageReceived(
|
|
|
|
CefRefPtr<ClientApp> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) OVERRIDE {
|
|
|
|
return message_router_->OnProcessMessageReceived(
|
|
|
|
browser, source_process, message);
|
|
|
|
}
|
|
|
|
|
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_;
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(ClientRenderDelegate);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) {
|
|
|
|
delegates.insert(new ClientRenderDelegate);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace client_renderer
|