]> git.sesse.net Git - casparcg/blob - dependencies/berkelium/include/berkelium/Berkelium.hpp
Manually merged pull request #222
[casparcg] / dependencies / berkelium / include / berkelium / Berkelium.hpp
1 /*  Berkelium - Embedded Chromium
2  *  Berkelium.hpp
3  *
4  *  Copyright (c) 2009, Daniel Reiter Horn
5  *  All rights reserved.
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions are
9  *  met:
10  *  * Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *  * Neither the name of Sirikata nor the names of its contributors may
17  *    be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
24  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _BERKELIUM_HPP_
34 #define _BERKELIUM_HPP_
35 #include "berkelium/Platform.hpp"
36 #include "berkelium/WeakString.hpp"
37 namespace sandbox {
38 class BrokerServices;
39 class TargetServices;
40 #ifdef _WIN32
41 enum DepEnforcement;
42 #endif
43 }
44 namespace Berkelium {
45
46 /** May be implemented to handle global errors gracefully.
47  */
48 class BERKELIUM_EXPORT ErrorDelegate {
49 public:
50     virtual ~ErrorDelegate() {}
51 };
52
53 /* TODO: Allow forkedProcessHook to be called without requiring the
54    library to be initialized/in memory (unless this is a sub-process).
55    i.e. an inline function that first searches for "--type=" in argv,
56    then uses dlopen or GetProcAddress.
57 */
58
59 /** Called by child processes.
60  * Should only ever be called from subprocess.cpp (berkelium.exe).
61  */
62 #ifdef _WIN32
63 void BERKELIUM_EXPORT forkedProcessHook(
64     sandbox::BrokerServices* (*ptrGetBrokerServices)(),
65     sandbox::TargetServices* (*ptrGetTargetServices)(),
66     bool (*ptrSetCurrentProcessDEP)(enum sandbox::DepEnforcement));
67 #else
68 void BERKELIUM_EXPORT forkedProcessHook(int argc, char **argv);
69 #endif
70
71 /** Iniitialize berkelium's global object.
72  *  \param homeDirectory  Just like Chrome's --user-data-dir command line flag.
73  *    If homeDirectory is null or empty, creates a temporary data directory.
74  *  \param subprocessDirectory  Path to berkelium.exe.
75  */
76 bool BERKELIUM_EXPORT init(FileString homeDirectory, FileString subprocessDirectory);
77
78 /** Iniitialize berkelium's global object.
79  *  \param homeDirectory  Just like Chrome's --user-data-dir command line flag.
80  *    If homeDirectory is null or empty, creates a temporary data directory.
81  */
82 bool BERKELIUM_EXPORT init(FileString homeDirectory);
83
84 /** Destroys Berkelium and attempts to free as much memory as possible.
85  *  Note: You must destroy all Window and Context objects before calling
86  *  Berkelium::destroy()!
87  */
88 void BERKELIUM_EXPORT destroy();
89
90 void BERKELIUM_EXPORT setErrorHandler(ErrorDelegate * errorHandler);
91
92 /** Runs the message loop until all pending messages are processed.
93  *  Must be called from the same thread as all other Berkelium functions,
94  *  usually your program's main (UI) thread.
95  *  For now, you have to poll to receive updates without blocking indefinitely.
96  *
97  *  Your WindowDelegate's should only receive callbacks synchronously with
98  *  this call to update.
99  */
100 void BERKELIUM_EXPORT update();
101 void BERKELIUM_EXPORT runUntilStopped();
102 void BERKELIUM_EXPORT stopRunning();
103
104 }
105
106 #endif