1 // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_SHARED_RENDERER_CLIENT_APP_RENDERER_H_ 6 #define CEF_TESTS_SHARED_RENDERER_CLIENT_APP_RENDERER_H_ 7 #pragma once 8 9 #include <set> 10 11 #include "tests/shared/common/client_app.h" 12 13 namespace client { 14 15 // Client app implementation for the renderer process. 16 class ClientAppRenderer : public ClientApp, public CefRenderProcessHandler { 17 public: 18 // Interface for renderer delegates. All Delegates must be returned via 19 // CreateDelegates. Do not perform work in the Delegate 20 // constructor. See CefRenderProcessHandler for documentation. 21 class Delegate : public virtual CefBaseRefCounted { 22 public: OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app)23 virtual void OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app) {} 24 OnBrowserCreated(CefRefPtr<ClientAppRenderer> app,CefRefPtr<CefBrowser> browser,CefRefPtr<CefDictionaryValue> extra_info)25 virtual void OnBrowserCreated(CefRefPtr<ClientAppRenderer> app, 26 CefRefPtr<CefBrowser> browser, 27 CefRefPtr<CefDictionaryValue> extra_info) {} 28 OnBrowserDestroyed(CefRefPtr<ClientAppRenderer> app,CefRefPtr<CefBrowser> browser)29 virtual void OnBrowserDestroyed(CefRefPtr<ClientAppRenderer> app, 30 CefRefPtr<CefBrowser> browser) {} 31 GetLoadHandler(CefRefPtr<ClientAppRenderer> app)32 virtual CefRefPtr<CefLoadHandler> GetLoadHandler( 33 CefRefPtr<ClientAppRenderer> app) { 34 return nullptr; 35 } 36 OnContextCreated(CefRefPtr<ClientAppRenderer> app,CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefV8Context> context)37 virtual void OnContextCreated(CefRefPtr<ClientAppRenderer> app, 38 CefRefPtr<CefBrowser> browser, 39 CefRefPtr<CefFrame> frame, 40 CefRefPtr<CefV8Context> context) {} 41 OnContextReleased(CefRefPtr<ClientAppRenderer> app,CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefV8Context> context)42 virtual void OnContextReleased(CefRefPtr<ClientAppRenderer> app, 43 CefRefPtr<CefBrowser> browser, 44 CefRefPtr<CefFrame> frame, 45 CefRefPtr<CefV8Context> context) {} 46 OnUncaughtException(CefRefPtr<ClientAppRenderer> app,CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefV8Context> context,CefRefPtr<CefV8Exception> exception,CefRefPtr<CefV8StackTrace> stackTrace)47 virtual void OnUncaughtException(CefRefPtr<ClientAppRenderer> app, 48 CefRefPtr<CefBrowser> browser, 49 CefRefPtr<CefFrame> frame, 50 CefRefPtr<CefV8Context> context, 51 CefRefPtr<CefV8Exception> exception, 52 CefRefPtr<CefV8StackTrace> stackTrace) {} 53 OnFocusedNodeChanged(CefRefPtr<ClientAppRenderer> app,CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefDOMNode> node)54 virtual void OnFocusedNodeChanged(CefRefPtr<ClientAppRenderer> app, 55 CefRefPtr<CefBrowser> browser, 56 CefRefPtr<CefFrame> frame, 57 CefRefPtr<CefDOMNode> node) {} 58 59 // Called when a process message is received. Return true if the message was 60 // handled and should not be passed on to other handlers. Delegates 61 // should check for unique message names to avoid interfering with each 62 // other. OnProcessMessageReceived(CefRefPtr<ClientAppRenderer> app,CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefProcessId source_process,CefRefPtr<CefProcessMessage> message)63 virtual bool OnProcessMessageReceived( 64 CefRefPtr<ClientAppRenderer> app, 65 CefRefPtr<CefBrowser> browser, 66 CefRefPtr<CefFrame> frame, 67 CefProcessId source_process, 68 CefRefPtr<CefProcessMessage> message) { 69 return false; 70 } 71 }; 72 73 typedef std::set<CefRefPtr<Delegate>> DelegateSet; 74 75 ClientAppRenderer(); 76 77 private: 78 // Creates all of the Delegate objects. Implemented by cefclient in 79 // client_app_delegates_renderer.cc 80 static void CreateDelegates(DelegateSet& delegates); 81 82 // CefApp methods. GetRenderProcessHandler()83 CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override { 84 return this; 85 } 86 87 // CefRenderProcessHandler methods. 88 void OnWebKitInitialized() override; 89 void OnBrowserCreated(CefRefPtr<CefBrowser> browser, 90 CefRefPtr<CefDictionaryValue> extra_info) override; 91 void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override; 92 CefRefPtr<CefLoadHandler> GetLoadHandler() override; 93 void OnContextCreated(CefRefPtr<CefBrowser> browser, 94 CefRefPtr<CefFrame> frame, 95 CefRefPtr<CefV8Context> context) override; 96 void OnContextReleased(CefRefPtr<CefBrowser> browser, 97 CefRefPtr<CefFrame> frame, 98 CefRefPtr<CefV8Context> context) override; 99 void OnUncaughtException(CefRefPtr<CefBrowser> browser, 100 CefRefPtr<CefFrame> frame, 101 CefRefPtr<CefV8Context> context, 102 CefRefPtr<CefV8Exception> exception, 103 CefRefPtr<CefV8StackTrace> stackTrace) override; 104 void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser, 105 CefRefPtr<CefFrame> frame, 106 CefRefPtr<CefDOMNode> node) override; 107 bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, 108 CefRefPtr<CefFrame> frame, 109 CefProcessId source_process, 110 CefRefPtr<CefProcessMessage> message) override; 111 112 private: 113 // Set of supported Delegates. 114 DelegateSet delegates_; 115 116 IMPLEMENT_REFCOUNTING(ClientAppRenderer); 117 DISALLOW_COPY_AND_ASSIGN(ClientAppRenderer); 118 }; 119 120 } // namespace client 121 122 #endif // CEF_TESTS_SHARED_RENDERER_CLIENT_APP_RENDERER_H_ 123