• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_APP_H_
38 #define CEF_INCLUDE_CEF_APP_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 #include "include/cef_browser_process_handler.h"
43 #include "include/cef_command_line.h"
44 #include "include/cef_render_process_handler.h"
45 #include "include/cef_resource_bundle_handler.h"
46 #include "include/cef_scheme.h"
47 
48 class CefApp;
49 
50 ///
51 // This function should be called from the application entry point function to
52 // execute a secondary process. It can be used to run secondary processes from
53 // the browser client executable (default behavior) or from a separate
54 // executable specified by the CefSettings.browser_subprocess_path value. If
55 // called for the browser process (identified by no "type" command-line value)
56 // it will return immediately with a value of -1. If called for a recognized
57 // secondary process it will block until the process should exit and then return
58 // the process exit code. The |application| parameter may be empty. The
59 // |windows_sandbox_info| parameter is only used on Windows and may be NULL (see
60 // cef_sandbox_win.h for details).
61 ///
62 /*--cef(api_hash_check,optional_param=application,
63         optional_param=windows_sandbox_info)--*/
64 int CefExecuteProcess(const CefMainArgs& args,
65                       CefRefPtr<CefApp> application,
66                       void* windows_sandbox_info);
67 
68 ///
69 // This function should be called on the main application thread to initialize
70 // the CEF browser process. The |application| parameter may be empty. A return
71 // value of true indicates that it succeeded and false indicates that it failed.
72 // The |windows_sandbox_info| parameter is only used on Windows and may be NULL
73 // (see cef_sandbox_win.h for details).
74 ///
75 /*--cef(api_hash_check,optional_param=application,
76         optional_param=windows_sandbox_info)--*/
77 bool CefInitialize(const CefMainArgs& args,
78                    const CefSettings& settings,
79                    CefRefPtr<CefApp> application,
80                    void* windows_sandbox_info);
81 
82 ///
83 // This function should be called on the main application thread to shut down
84 // the CEF browser process before the application exits.
85 ///
86 /*--cef()--*/
87 void CefShutdown();
88 
89 ///
90 // Perform a single iteration of CEF message loop processing. This function is
91 // provided for cases where the CEF message loop must be integrated into an
92 // existing application message loop. Use of this function is not recommended
93 // for most users; use either the CefRunMessageLoop() function or
94 // CefSettings.multi_threaded_message_loop if possible. When using this function
95 // care must be taken to balance performance against excessive CPU usage. It is
96 // recommended to enable the CefSettings.external_message_pump option when using
97 // this function so that CefBrowserProcessHandler::OnScheduleMessagePumpWork()
98 // callbacks can facilitate the scheduling process. This function should only be
99 // called on the main application thread and only if CefInitialize() is called
100 // with a CefSettings.multi_threaded_message_loop value of false. This function
101 // will not block.
102 ///
103 /*--cef()--*/
104 void CefDoMessageLoopWork();
105 
106 ///
107 // Run the CEF message loop. Use this function instead of an application-
108 // provided message loop to get the best balance between performance and CPU
109 // usage. This function should only be called on the main application thread and
110 // only if CefInitialize() is called with a
111 // CefSettings.multi_threaded_message_loop value of false. This function will
112 // block until a quit message is received by the system.
113 ///
114 /*--cef()--*/
115 void CefRunMessageLoop();
116 
117 ///
118 // Quit the CEF message loop that was started by calling CefRunMessageLoop().
119 // This function should only be called on the main application thread and only
120 // if CefRunMessageLoop() was used.
121 ///
122 /*--cef()--*/
123 void CefQuitMessageLoop();
124 
125 ///
126 // Set to true before calling Windows APIs like TrackPopupMenu that enter a
127 // modal message loop. Set to false after exiting the modal message loop.
128 ///
129 /*--cef()--*/
130 void CefSetOSModalLoop(bool osModalLoop);
131 
132 ///
133 // Call during process startup to enable High-DPI support on Windows 7 or newer.
134 // Older versions of Windows should be left DPI-unaware because they do not
135 // support DirectWrite and GDI fonts are kerned very badly.
136 ///
137 /*--cef(capi_name=cef_enable_highdpi_support)--*/
138 void CefEnableHighDPISupport();
139 
140 ///
141 // Implement this interface to provide handler implementations. Methods will be
142 // called by the process and/or thread indicated.
143 ///
144 /*--cef(source=client,no_debugct_check)--*/
145 class CefApp : public virtual CefBaseRefCounted {
146  public:
147   ///
148   // Provides an opportunity to view and/or modify command-line arguments before
149   // processing by CEF and Chromium. The |process_type| value will be empty for
150   // the browser process. Do not keep a reference to the CefCommandLine object
151   // passed to this method. The CefSettings.command_line_args_disabled value
152   // can be used to start with an empty command-line object. Any values
153   // specified in CefSettings that equate to command-line arguments will be set
154   // before this method is called. Be cautious when using this method to modify
155   // command-line arguments for non-browser processes as this may result in
156   // undefined behavior including crashes.
157   ///
158   /*--cef(optional_param=process_type)--*/
OnBeforeCommandLineProcessing(const CefString & process_type,CefRefPtr<CefCommandLine> command_line)159   virtual void OnBeforeCommandLineProcessing(
160       const CefString& process_type,
161       CefRefPtr<CefCommandLine> command_line) {}
162 
163   ///
164   // Provides an opportunity to register custom schemes. Do not keep a reference
165   // to the |registrar| object. This method is called on the main thread for
166   // each process and the registered schemes should be the same across all
167   // processes.
168   ///
169   /*--cef()--*/
OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)170   virtual void OnRegisterCustomSchemes(
171       CefRawPtr<CefSchemeRegistrar> registrar) {}
172 
173   ///
174   // Return the handler for resource bundle events. If
175   // CefSettings.pack_loading_disabled is true a handler must be returned. If no
176   // handler is returned resources will be loaded from pack files. This method
177   // is called by the browser and render processes on multiple threads.
178   ///
179   /*--cef()--*/
GetResourceBundleHandler()180   virtual CefRefPtr<CefResourceBundleHandler> GetResourceBundleHandler() {
181     return nullptr;
182   }
183 
184   ///
185   // Return the handler for functionality specific to the browser process. This
186   // method is called on multiple threads in the browser process.
187   ///
188   /*--cef()--*/
GetBrowserProcessHandler()189   virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() {
190     return nullptr;
191   }
192 
193   ///
194   // Return the handler for functionality specific to the render process. This
195   // method is called on the render process main thread.
196   ///
197   /*--cef()--*/
GetRenderProcessHandler()198   virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() {
199     return nullptr;
200   }
201 };
202 
203 #endif  // CEF_INCLUDE_CEF_APP_H_
204