// 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_COMMON_CLIENT_APP_H_ #define CEF_TESTS_CEFCLIENT_COMMON_CLIENT_APP_H_ #pragma once #include #include #include #include #include #include "include/cef_app.h" namespace client { class ClientApp : public CefApp, public CefBrowserProcessHandler, public CefRenderProcessHandler { public: // Interface for browser delegates. All BrowserDelegates must be returned via // CreateBrowserDelegates. Do not perform work in the BrowserDelegate // constructor. See CefBrowserProcessHandler for documentation. class BrowserDelegate : public virtual CefBase { public: virtual void OnContextInitialized(CefRefPtr app) {} virtual void OnBeforeChildProcessLaunch( CefRefPtr app, CefRefPtr command_line) {} virtual void OnRenderProcessThreadCreated( CefRefPtr app, CefRefPtr extra_info) {} }; typedef std::set > BrowserDelegateSet; // Interface for renderer delegates. All RenderDelegates must be returned via // CreateRenderDelegates. Do not perform work in the RenderDelegate // constructor. See CefRenderProcessHandler for documentation. class RenderDelegate : public virtual CefBase { public: virtual void OnRenderThreadCreated(CefRefPtr app, CefRefPtr extra_info) {} virtual void OnWebKitInitialized(CefRefPtr app) {} virtual void OnBrowserCreated(CefRefPtr app, CefRefPtr browser) {} virtual void OnBrowserDestroyed(CefRefPtr app, CefRefPtr browser) {} virtual CefRefPtr GetLoadHandler(CefRefPtr app) { return NULL; } virtual bool OnBeforeNavigation(CefRefPtr app, CefRefPtr browser, CefRefPtr frame, CefRefPtr request, cef_navigation_type_t navigation_type, bool is_redirect) { return false; } virtual void OnContextCreated(CefRefPtr app, CefRefPtr browser, CefRefPtr frame, CefRefPtr context) {} virtual void OnContextReleased(CefRefPtr app, CefRefPtr browser, CefRefPtr frame, CefRefPtr context) {} virtual void OnUncaughtException(CefRefPtr app, CefRefPtr browser, CefRefPtr frame, CefRefPtr context, CefRefPtr exception, CefRefPtr stackTrace) {} virtual void OnFocusedNodeChanged(CefRefPtr app, CefRefPtr browser, CefRefPtr frame, CefRefPtr node) {} // Called when a process message is received. Return true if the message was // handled and should not be passed on to other handlers. RenderDelegates // should check for unique message names to avoid interfering with each // other. virtual bool OnProcessMessageReceived( CefRefPtr app, CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { return false; } }; typedef std::set > RenderDelegateSet; ClientApp(); private: // Creates all of the BrowserDelegate objects. Implemented in // client_app_delegates. static void CreateBrowserDelegates(BrowserDelegateSet& delegates); // Creates all of the RenderDelegate objects. Implemented in // client_app_delegates. static void CreateRenderDelegates(RenderDelegateSet& delegates); // Registers custom schemes. Implemented in client_app_delegates. static void RegisterCustomSchemes(CefRefPtr registrar, std::vector& cookiable_schemes); // Create the Linux print handler. Implemented in client_app_delegates. static CefRefPtr CreatePrintHandler(); // CefApp methods. void OnRegisterCustomSchemes( CefRefPtr registrar) OVERRIDE; CefRefPtr GetBrowserProcessHandler() OVERRIDE { return this; } CefRefPtr GetRenderProcessHandler() OVERRIDE { return this; } // CefBrowserProcessHandler methods. void OnContextInitialized() OVERRIDE; void OnBeforeChildProcessLaunch( CefRefPtr command_line) OVERRIDE; void OnRenderProcessThreadCreated( CefRefPtr extra_info) OVERRIDE; CefRefPtr GetPrintHandler() OVERRIDE { return print_handler_; } // CefRenderProcessHandler methods. void OnRenderThreadCreated(CefRefPtr extra_info) OVERRIDE; void OnWebKitInitialized() OVERRIDE; void OnBrowserCreated(CefRefPtr browser) OVERRIDE; void OnBrowserDestroyed(CefRefPtr browser) OVERRIDE; CefRefPtr GetLoadHandler() OVERRIDE; bool OnBeforeNavigation(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, NavigationType navigation_type, bool is_redirect) OVERRIDE; void OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; void OnUncaughtException(CefRefPtr browser, CefRefPtr frame, CefRefPtr context, CefRefPtr exception, CefRefPtr stackTrace) OVERRIDE; void OnFocusedNodeChanged(CefRefPtr browser, CefRefPtr frame, CefRefPtr node) OVERRIDE; bool OnProcessMessageReceived( CefRefPtr browser, CefProcessId source_process, CefRefPtr message) OVERRIDE; // Set of supported BrowserDelegates. Only used in the browser process. BrowserDelegateSet browser_delegates_; // Set of supported RenderDelegates. Only used in the renderer process. RenderDelegateSet render_delegates_; // Schemes that will be registered with the global cookie manager. Used in // both the browser and renderer process. std::vector cookieable_schemes_; CefRefPtr print_handler_; IMPLEMENT_REFCOUNTING(ClientApp); }; } // namespace client #endif // CEF_TESTS_CEFCLIENT_COMMON_CLIENT_APP_H_