Skip to content

Commit 9d5d384

Browse files
donny-dontaperezdc
authored andcommitted
Add Process Management API
Allows the launching and termination of processes through the WPE API. (cherry picked from commit 600e18e)
1 parent b461dd3 commit 9d5d384

File tree

6 files changed

+251
-0
lines changed

6 files changed

+251
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ set(WPE_PUBLIC_HEADERS
6868
include/wpe/keysyms.h
6969
include/wpe/loader.h
7070
include/wpe/pasteboard.h
71+
include/wpe/process.h
7172
include/wpe/renderer-backend-egl.h
7273
include/wpe/renderer-host.h
7374
include/wpe/view-backend.h
@@ -83,6 +84,7 @@ add_library(
8384
src/pasteboard.c
8485
src/pasteboard-generic.cpp
8586
src/pasteboard-noop.cpp
87+
src/process.c
8688
src/renderer-backend-egl.c
8789
src/renderer-host.c
8890
src/version.c

include/wpe/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ api_headers = [
77
'libwpe-version.h',
88
'loader.h',
99
'pasteboard.h',
10+
'process.h',
1011
'renderer-backend-egl.h',
1112
'renderer-host.h',
1213
'version.h',

include/wpe/process.h

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright (C) 2022 Sony Interactive Entertainment Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
#if !defined(__WPE_H_INSIDE__) && !defined(WPE_COMPILATION)
28+
#error "Only <wpe/wpe.h> can be included directly."
29+
#endif
30+
31+
#ifndef wpe_process_h
32+
#define wpe_process_h
33+
34+
/**
35+
* SECTION:process
36+
* @short_description: Process management
37+
* @title: Process
38+
*/
39+
40+
#if defined(WPE_COMPILATION)
41+
#include "export.h"
42+
#endif
43+
44+
#include <stdint.h>
45+
46+
#ifdef __cplusplus
47+
extern "C" {
48+
#endif
49+
50+
/**
51+
* wpe_process_type:
52+
* @WPE_PROCESS_TYPE_WEB: WebKit's WebProcess.
53+
* @WPE_PROCESS_TYPE_NETWORK: WebKit's NetworkProcess.
54+
* @WPE_PROCESS_TYPE_GPU: WebKit's GPUProcess.
55+
* @WPE_PROCESS_TYPE_WEB_AUTHN: WebKit's WebAuthNProcess.
56+
*
57+
* Maps to the processes launched by WebKit.
58+
*/
59+
enum wpe_process_type {
60+
WPE_PROCESS_TYPE_WEB,
61+
WPE_PROCESS_TYPE_NETWORK,
62+
WPE_PROCESS_TYPE_GPU,
63+
WPE_PROCESS_TYPE_WEB_AUTHN,
64+
};
65+
66+
struct wpe_process_provider;
67+
68+
/**
69+
* wpe_process_provider_interface:
70+
* @create: create an internal representation of a process provider.
71+
* @destroy: destroy instance process provider.
72+
* @launch: launches the specified WebKit process.
73+
* @terminate: terminates the specified Webkit process.
74+
*
75+
* Methods called by WebKit requesting process provider operations to implementator.
76+
*
77+
* Since: 1.14
78+
*/
79+
struct wpe_process_provider_interface {
80+
void* (*create)(struct wpe_process_provider*);
81+
void (*destroy)(void*);
82+
int64_t (*launch)(void*, enum wpe_process_type, void*);
83+
void (*terminate)(void*, int64_t);
84+
85+
/*< private >*/
86+
void (*_wpe_reserved1)(void);
87+
void (*_wpe_reserved2)(void);
88+
void (*_wpe_reserved3)(void);
89+
void (*_wpe_reserved4)(void);
90+
void (*_wpe_reserved5)(void);
91+
};
92+
93+
/**
94+
* wpe_process_provider_create:
95+
*
96+
* This method is called by WPEWebKit.
97+
*
98+
* Returns: an opaque object representing the process provider in libwpe.
99+
*
100+
* Since: 1.14
101+
*/
102+
WPE_EXPORT
103+
struct wpe_process_provider* wpe_process_provider_create(void);
104+
105+
/**
106+
* wpe_process_provider_destroy:
107+
* @provider: opaque libwpe's representation of the process provider.
108+
*
109+
* Frees the internal resources used by @provider.
110+
*
111+
* This method is called by WPEWebKit.
112+
*
113+
* Since: 1.14
114+
*/
115+
WPE_EXPORT
116+
void wpe_process_provider_destroy(struct wpe_process_provider*);
117+
118+
/**
119+
* wpe_process_launch:
120+
* @provider: opaque libwpe's representation of the process provider.
121+
* @type: the process type to launch.
122+
* @userdata: user data passed needed to launch the process.
123+
*
124+
* Launches the specified WebKit process.
125+
*
126+
* Returns: an identifier for the process.
127+
*
128+
* Since: 1.14
129+
*/
130+
WPE_EXPORT
131+
int64_t wpe_process_launch(struct wpe_process_provider*, enum wpe_process_type, void*);
132+
133+
/**
134+
* wpe_process_terminate:
135+
* @provider: opaque libwpe's representation of the process provider.
136+
* @process: identifier for the process to terminate.
137+
*
138+
* Terminates the specified WebKit process.
139+
*
140+
* Since: 1.14
141+
*/
142+
WPE_EXPORT
143+
void wpe_process_terminate(struct wpe_process_provider*, int64_t);
144+
145+
/**
146+
* wpe_process_provider_register_interface:
147+
* @iface: interface for the process provider.
148+
*
149+
* Sets the process provider interface.
150+
*
151+
* This method is called by WPEWebKit.
152+
*
153+
* Since: 1.14
154+
*/
155+
WPE_EXPORT
156+
void wpe_process_provider_register_interface(const struct wpe_process_provider_interface*);
157+
158+
#ifdef __cplusplus
159+
}
160+
#endif
161+
162+
#endif /* wpe_process_h */

include/wpe/wpe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "libwpe-version.h"
4242
#include "loader.h"
4343
#include "pasteboard.h"
44+
#include "process.h"
4445
#include "renderer-host.h"
4546
#include "version-deprecated.h"
4647
#include "version.h"

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ libwpe = library('wpe-' + api_version,
8888
'src/pasteboard.c',
8989
'src/pasteboard-generic.cpp',
9090
'src/pasteboard-noop.cpp',
91+
'src/process.c',
9192
'src/renderer-backend-egl.c',
9293
'src/renderer-host.c',
9394
'src/version.c',

src/process.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (C) 2022 Sony Interactive Entertainment Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
#include "../include/wpe/process.h"
28+
#include <stdlib.h>
29+
30+
struct wpe_process_provider {
31+
void* backend;
32+
};
33+
34+
static const struct wpe_process_provider_interface* provider_interface = NULL;
35+
36+
struct wpe_process_provider*
37+
wpe_process_provider_create()
38+
{
39+
if (!provider_interface)
40+
return NULL;
41+
42+
struct wpe_process_provider* provider = calloc(1, sizeof(struct wpe_process_provider));
43+
if (!provider)
44+
return NULL;
45+
46+
if (provider_interface->create)
47+
provider->backend = provider_interface->create(provider);
48+
49+
return provider;
50+
}
51+
52+
void
53+
wpe_process_provider_destroy(struct wpe_process_provider* provider)
54+
{
55+
if (!provider)
56+
return;
57+
58+
if (provider_interface && provider_interface->destroy)
59+
provider_interface->destroy(provider);
60+
provider->backend = NULL;
61+
free(provider);
62+
}
63+
64+
int64_t
65+
wpe_process_launch(struct wpe_process_provider* provider, enum wpe_process_type type, void* userdata)
66+
{
67+
if (provider && provider_interface && provider_interface->launch)
68+
return provider_interface->launch(provider->backend, type, userdata);
69+
return -1;
70+
}
71+
72+
void
73+
wpe_process_terminate(struct wpe_process_provider* provider, int64_t process)
74+
{
75+
if (provider && provider_interface && provider_interface->terminate)
76+
provider_interface->terminate(provider->backend, process);
77+
}
78+
79+
void
80+
wpe_process_provider_register_interface(const struct wpe_process_provider_interface* iface)
81+
{
82+
if (iface && !provider_interface)
83+
provider_interface = iface;
84+
}

0 commit comments

Comments
 (0)