mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
cefclient: Split ClientApp into process-specific types (issue #1500).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@2015 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cefclient/common/client_app.h"
|
||||
#include "cefclient/renderer/client_app_renderer.h"
|
||||
#include "cefclient/renderer/client_renderer.h"
|
||||
#include "cefclient/renderer/performance_test.h"
|
||||
|
||||
namespace client {
|
||||
|
||||
// static
|
||||
void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) {
|
||||
renderer::CreateRenderDelegates(delegates);
|
||||
performance_test::CreateRenderDelegates(delegates);
|
||||
void ClientAppRenderer::CreateDelegates(DelegateSet& delegates) {
|
||||
renderer::CreateDelegates(delegates);
|
||||
performance_test::CreateDelegates(delegates);
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
|
@@ -1,21 +0,0 @@
|
||||
// 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/common/client_app.h"
|
||||
|
||||
namespace client {
|
||||
|
||||
// Stub implementations of ClientApp methods that are only used in the browser
|
||||
// process.
|
||||
|
||||
// static
|
||||
void ClientApp::CreateBrowserDelegates(BrowserDelegateSet& delegates) {
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefPrintHandler> ClientApp::CreatePrintHandler() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace client
|
118
tests/cefclient/renderer/client_app_renderer.cc
Normal file
118
tests/cefclient/renderer/client_app_renderer.cc
Normal file
@@ -0,0 +1,118 @@
|
||||
// Copyright (c) 2013 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/renderer/client_app_renderer.h"
|
||||
|
||||
namespace client {
|
||||
|
||||
ClientAppRenderer::ClientAppRenderer() {
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnRenderThreadCreated(
|
||||
CefRefPtr<CefListValue> extra_info) {
|
||||
CreateDelegates(delegates_);
|
||||
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it)
|
||||
(*it)->OnRenderThreadCreated(this, extra_info);
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnWebKitInitialized() {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it)
|
||||
(*it)->OnWebKitInitialized(this);
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it)
|
||||
(*it)->OnBrowserCreated(this, browser);
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it)
|
||||
(*it)->OnBrowserDestroyed(this, browser);
|
||||
}
|
||||
|
||||
CefRefPtr<CefLoadHandler> ClientAppRenderer::GetLoadHandler() {
|
||||
CefRefPtr<CefLoadHandler> load_handler;
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end() && !load_handler.get(); ++it)
|
||||
load_handler = (*it)->GetLoadHandler(this);
|
||||
|
||||
return load_handler;
|
||||
}
|
||||
|
||||
bool ClientAppRenderer::OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavigationType navigation_type,
|
||||
bool is_redirect) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it) {
|
||||
if ((*it)->OnBeforeNavigation(this, browser, frame, request,
|
||||
navigation_type, is_redirect)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it)
|
||||
(*it)->OnContextCreated(this, browser, frame, context);
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnContextReleased(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it)
|
||||
(*it)->OnContextReleased(this, browser, frame, context);
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnUncaughtException(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context,
|
||||
CefRefPtr<CefV8Exception> exception,
|
||||
CefRefPtr<CefV8StackTrace> stackTrace) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it) {
|
||||
(*it)->OnUncaughtException(this, browser, frame, context, exception,
|
||||
stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientAppRenderer::OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefDOMNode> node) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it)
|
||||
(*it)->OnFocusedNodeChanged(this, browser, frame, node);
|
||||
}
|
||||
|
||||
bool ClientAppRenderer::OnProcessMessageReceived(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) {
|
||||
DCHECK_EQ(source_process, PID_BROWSER);
|
||||
|
||||
bool handled = false;
|
||||
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end() && !handled; ++it) {
|
||||
handled = (*it)->OnProcessMessageReceived(this, browser, source_process,
|
||||
message);
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
} // namespace client
|
138
tests/cefclient/renderer/client_app_renderer.h
Normal file
138
tests/cefclient/renderer/client_app_renderer.h
Normal file
@@ -0,0 +1,138 @@
|
||||
// Copyright (c) 2013 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.
|
||||
|
||||
#ifndef CEF_TESTS_CEFCLIENT_RENDERER_CLIENT_APP_RENDERER_H_
|
||||
#define CEF_TESTS_CEFCLIENT_RENDERER_CLIENT_APP_RENDERER_H_
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "cefclient/common/client_app.h"
|
||||
|
||||
namespace client {
|
||||
|
||||
// Client app implementation for the renderer process.
|
||||
class ClientAppRenderer : public ClientApp,
|
||||
public CefRenderProcessHandler {
|
||||
public:
|
||||
// Interface for renderer delegates. All Delegates must be returned via
|
||||
// CreateDelegates. Do not perform work in the Delegate
|
||||
// constructor. See CefRenderProcessHandler for documentation.
|
||||
class Delegate : public virtual CefBase {
|
||||
public:
|
||||
virtual void OnRenderThreadCreated(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefListValue> extra_info) {}
|
||||
|
||||
virtual void OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app) {}
|
||||
|
||||
virtual void OnBrowserCreated(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser) {}
|
||||
|
||||
virtual void OnBrowserDestroyed(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser) {}
|
||||
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler(
|
||||
CefRefPtr<ClientAppRenderer> app) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void OnContextCreated(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {}
|
||||
|
||||
virtual void OnContextReleased(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {}
|
||||
|
||||
virtual void OnUncaughtException(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context,
|
||||
CefRefPtr<CefV8Exception> exception,
|
||||
CefRefPtr<CefV8StackTrace> stackTrace) {}
|
||||
|
||||
virtual void OnFocusedNodeChanged(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefDOMNode> node) {}
|
||||
|
||||
// Called when a process message is received. Return true if the message was
|
||||
// handled and should not be passed on to other handlers. Delegates
|
||||
// should check for unique message names to avoid interfering with each
|
||||
// other.
|
||||
virtual bool OnProcessMessageReceived(
|
||||
CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::set<CefRefPtr<Delegate> > DelegateSet;
|
||||
|
||||
ClientAppRenderer();
|
||||
|
||||
private:
|
||||
// Creates all of the Delegate objects. Implemented in
|
||||
// client_app_delegates.
|
||||
static void CreateDelegates(DelegateSet& delegates);
|
||||
|
||||
// CefApp methods.
|
||||
CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE {
|
||||
return this;
|
||||
}
|
||||
|
||||
// CefRenderProcessHandler methods.
|
||||
void OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info) OVERRIDE;
|
||||
void OnWebKitInitialized() OVERRIDE;
|
||||
void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE;
|
||||
bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavigationType navigation_type,
|
||||
bool is_redirect) OVERRIDE;
|
||||
void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
void OnContextReleased(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
void OnUncaughtException(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context,
|
||||
CefRefPtr<CefV8Exception> exception,
|
||||
CefRefPtr<CefV8StackTrace> stackTrace) OVERRIDE;
|
||||
void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefDOMNode> node) OVERRIDE;
|
||||
bool OnProcessMessageReceived(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
|
||||
private:
|
||||
// Set of supported Delegates.
|
||||
DelegateSet delegates_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(ClientAppRenderer);
|
||||
DISALLOW_COPY_AND_ASSIGN(ClientAppRenderer);
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
|
||||
#endif // CEF_TESTS_CEFCLIENT_RENDERER_CLIENT_APP_RENDERER_H_
|
@@ -19,33 +19,33 @@ namespace {
|
||||
// Must match the value in client_handler.cc.
|
||||
const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged";
|
||||
|
||||
class ClientRenderDelegate : public ClientApp::RenderDelegate {
|
||||
class ClientRenderDelegate : public ClientAppRenderer::Delegate {
|
||||
public:
|
||||
ClientRenderDelegate()
|
||||
: last_node_is_editable_(false) {
|
||||
}
|
||||
|
||||
virtual void OnWebKitInitialized(CefRefPtr<ClientApp> app) OVERRIDE {
|
||||
virtual void OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app) OVERRIDE {
|
||||
// Create the renderer-side router for query handling.
|
||||
CefMessageRouterConfig config;
|
||||
message_router_ = CefMessageRouterRendererSide::Create(config);
|
||||
}
|
||||
|
||||
virtual void OnContextCreated(CefRefPtr<ClientApp> app,
|
||||
virtual void OnContextCreated(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE {
|
||||
message_router_->OnContextCreated(browser, frame, context);
|
||||
}
|
||||
|
||||
virtual void OnContextReleased(CefRefPtr<ClientApp> app,
|
||||
virtual void OnContextReleased(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE {
|
||||
message_router_->OnContextReleased(browser, frame, context);
|
||||
}
|
||||
|
||||
virtual void OnFocusedNodeChanged(CefRefPtr<ClientApp> app,
|
||||
virtual void OnFocusedNodeChanged(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefDOMNode> node) OVERRIDE {
|
||||
@@ -61,7 +61,7 @@ class ClientRenderDelegate : public ClientApp::RenderDelegate {
|
||||
}
|
||||
|
||||
virtual bool OnProcessMessageReceived(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE {
|
||||
@@ -80,7 +80,7 @@ class ClientRenderDelegate : public ClientApp::RenderDelegate {
|
||||
|
||||
} // namespace
|
||||
|
||||
void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) {
|
||||
void CreateDelegates(ClientAppRenderer::DelegateSet& delegates) {
|
||||
delegates.insert(new ClientRenderDelegate);
|
||||
}
|
||||
|
||||
|
@@ -7,13 +7,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_base.h"
|
||||
#include "cefclient/common/client_app.h"
|
||||
#include "cefclient/renderer/client_app_renderer.h"
|
||||
|
||||
namespace client {
|
||||
namespace renderer {
|
||||
|
||||
// Create the render delegate.
|
||||
void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates);
|
||||
void CreateDelegates(ClientAppRenderer::DelegateSet& delegates);
|
||||
|
||||
} // namespace renderer
|
||||
} // namespace client
|
||||
|
@@ -126,15 +126,15 @@ class V8Handler : public CefV8Handler {
|
||||
};
|
||||
|
||||
// Handle bindings in the render process.
|
||||
class RenderDelegate : public ClientApp::RenderDelegate {
|
||||
class RenderDelegate : public ClientAppRenderer::Delegate {
|
||||
public:
|
||||
RenderDelegate() {
|
||||
}
|
||||
|
||||
virtual void OnContextCreated(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE {
|
||||
virtual void OnContextCreated(CefRefPtr<ClientAppRenderer> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE {
|
||||
CefRefPtr<CefV8Value> object = context->GetGlobal();
|
||||
|
||||
CefRefPtr<CefV8Handler> handler = new V8Handler();
|
||||
@@ -157,7 +157,7 @@ class RenderDelegate : public ClientApp::RenderDelegate {
|
||||
|
||||
} // namespace
|
||||
|
||||
void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) {
|
||||
void CreateDelegates(ClientAppRenderer::DelegateSet& delegates) {
|
||||
delegates.insert(new RenderDelegate);
|
||||
}
|
||||
|
||||
|
@@ -6,13 +6,13 @@
|
||||
#define CEF_TESTS_CEFCLIENT_RENDERER_PERFORMANCE_TEST_H_
|
||||
#pragma once
|
||||
|
||||
#include "cefclient/common/client_app.h"
|
||||
#include "cefclient/renderer/client_app_renderer.h"
|
||||
|
||||
namespace client {
|
||||
namespace performance_test {
|
||||
|
||||
// Render delegate creation. Called from client_app_delegates.cc.
|
||||
void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates);
|
||||
void CreateDelegates(ClientAppRenderer::DelegateSet& delegates);
|
||||
|
||||
} // namespace performance_test
|
||||
} // namespace client
|
||||
|
@@ -4,16 +4,34 @@
|
||||
|
||||
#include "include/cef_app.h"
|
||||
|
||||
// This file is shared by cefclient and cef_unittests so don't include using
|
||||
// a qualified path.
|
||||
#include "../common/client_app.h" // NOLINT(build/include)
|
||||
#include "cefclient/common/client_app_other.h"
|
||||
#include "cefclient/renderer/client_app_renderer.h"
|
||||
|
||||
// Process entry point.
|
||||
int main(int argc, char* argv[]) {
|
||||
namespace client {
|
||||
|
||||
int RunMain(int argc, char* argv[]) {
|
||||
CefMainArgs main_args(argc, argv);
|
||||
|
||||
CefRefPtr<CefApp> app(new client::ClientApp);
|
||||
|
||||
// Parse command-line arguments.
|
||||
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||||
command_line->InitFromArgv(argc, argv);
|
||||
|
||||
// Create a ClientApp of the correct type.
|
||||
CefRefPtr<CefApp> app;
|
||||
ClientApp::ProcessType process_type = ClientApp::GetProcessType(command_line);
|
||||
if (process_type == ClientApp::RendererProcess)
|
||||
app = new ClientAppRenderer();
|
||||
else if (process_type == ClientApp::OtherProcess)
|
||||
app = new ClientAppOther();
|
||||
|
||||
// Execute the secondary process.
|
||||
return CefExecuteProcess(main_args, app, NULL);
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
|
||||
|
||||
// Process entry point.
|
||||
int main(int argc, char* argv[]) {
|
||||
return client::RunMain(argc, argv);
|
||||
}
|
||||
|
Reference in New Issue
Block a user