// 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. #ifndef CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ #define CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ #pragma once #include #include #include #include #include "include/cef_app.h" class ClientApp : public CefApp, public CefProxyHandler, public CefRenderProcessHandler { public: // Interface for renderer delegates. All RenderDelegates must be returned via // CreateRenderDelegates. Do not perform work in the RenderDelegate // constructor. class RenderDelegate : public virtual CefBase { public: // Called when WebKit is initialized. Used to register V8 extensions. virtual void OnWebKitInitialized(CefRefPtr app) { }; // Called when a V8 context is created. Used to create V8 window bindings // and set message callbacks. RenderDelegates should check for unique URLs // to avoid interfering with each other. virtual void OnContextCreated(CefRefPtr app, CefRefPtr browser, CefRefPtr frame, CefRefPtr context) { }; // Called when a V8 context is released. Used to clean up V8 window // bindings. RenderDelegates should check for unique URLs to avoid // interfering with each other. virtual void OnContextReleased(CefRefPtr app, CefRefPtr browser, CefRefPtr frame, CefRefPtr context) { }; // 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 OnProcessMessageRecieved( CefRefPtr app, CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { return false; } }; typedef std::set > RenderDelegateSet; ClientApp(); // Set the proxy configuration. Should only be called during initialization. void SetProxyConfig(cef_proxy_type_t proxy_type, const CefString& proxy_config) { proxy_type_ = proxy_type; proxy_config_ = proxy_config; } // Set a JavaScript callback for the specified |message_name| and |browser_id| // combination. Will automatically be removed when the associated context is // released. Callbacks can also be set in JavaScript using the // app.setMessageCallback function. void SetMessageCallback(const std::string& message_name, int browser_id, CefRefPtr context, CefRefPtr function); // Removes the JavaScript callback for the specified |message_name| and // |browser_id| combination. Returns true if a callback was removed. Callbacks // can also be removed in JavaScript using the app.removeMessageCallback // function. bool RemoveMessageCallback(const std::string& message_name, int browser_id); private: // 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); // CefApp methods. virtual void OnRegisterCustomSchemes( CefRefPtr registrar) OVERRIDE { RegisterCustomSchemes(registrar); } virtual CefRefPtr GetRenderProcessHandler() OVERRIDE { return this; } virtual CefRefPtr GetProxyHandler() OVERRIDE { return this; } // CefProxyHandler methods. virtual void GetProxyForUrl(const CefString& url, CefProxyInfo& proxy_info) OVERRIDE; // CefRenderProcessHandler methods. virtual void OnWebKitInitialized() OVERRIDE; virtual void OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; virtual void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; virtual bool OnProcessMessageRecieved( CefRefPtr browser, CefProcessId source_process, CefRefPtr message) OVERRIDE; // Proxy configuration. cef_proxy_type_t proxy_type_; CefString proxy_config_; // Map of message callbacks. typedef std::map, std::pair, CefRefPtr > > CallbackMap; CallbackMap callback_map_; // Set of supported RenderDelegates. RenderDelegateSet render_delegates_; IMPLEMENT_REFCOUNTING(ClientApp); }; #endif // CEF_TESTS_CEFCLIENT_CLIENT_APP_H_