forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcefSchemeRegistrar.c
67 lines (49 loc) · 2.56 KB
/
cefSchemeRegistrar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2014 The cef2go authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/fromkeith/cef2go
#include "_cgo_export.h"
#include "cefBase.h"
#include "include/capi/cef_scheme_capi.h"
#include "include/capi/cef_origin_whitelist_capi.h"
struct _cef_resource_handler_t* CEF_CALLBACK cef_scheme_handler_factory_t_create(
struct _cef_scheme_handler_factory_t* self,
struct _cef_browser_t* browser, struct _cef_frame_t* frame,
const cef_string_t* scheme_name, struct _cef_request_t* request) {
cef_string_utf8_t * out = cefStringToUtf8(scheme_name);
return go_CreateSchemeHandler(self, browser, frame, out, request);
}
void intialize_cef_scheme_handler_factory(struct _cef_scheme_handler_factory_t * factory) {
goDebugLog("initializeSchemeHandler\n");
factory->base.size = sizeof(cef_scheme_handler_factory_t);
initialize_cef_base((cef_base_t*) factory, "scheme_handler_factory");
go_AddRef((cef_base_t*) factory);
factory->create = cef_scheme_handler_factory_t_create;
}
int cef_scheme_handler_register(char * schemeName, char * domainName, struct _cef_scheme_handler_factory_t* factory) {
cef_string_t * schemeNameCef = cef_string_userfree_utf16_alloc();
cef_string_from_utf8(schemeName, strlen(schemeName), schemeNameCef);
cef_string_t * domainNameCef = cef_string_userfree_utf16_alloc();
cef_string_from_utf8(domainName, strlen(domainName), domainNameCef);
int ret =
cef_register_scheme_handler_factory(schemeNameCef, domainNameCef, factory);
cef_string_userfree_utf16_free(domainNameCef);
cef_string_userfree_utf16_free(schemeNameCef);
return ret;
}
int whitelist_cef_add_cross_origin_whitelist_entry(
char* sourceOrigin,
char* targetProtocol,
char* targetDomain,
int allow_target_subdomains) {
cef_string_t * sourceOriginCef = cef_string_userfree_utf16_alloc();
cef_string_from_utf8(sourceOrigin, strlen(sourceOrigin), sourceOriginCef);
cef_string_t * targetProtocolCef = cef_string_userfree_utf16_alloc();
cef_string_from_utf8(targetProtocol, strlen(targetProtocol), targetProtocolCef);
cef_string_t * targetDomainCef = cef_string_userfree_utf16_alloc();
cef_string_from_utf8(targetDomain, strlen(targetDomain), targetDomainCef);
int ret = cef_add_cross_origin_whitelist_entry(sourceOriginCef, targetProtocolCef, targetDomainCef, allow_target_subdomains);
cef_string_userfree_utf16_free(targetDomainCef);
cef_string_userfree_utf16_free(targetProtocolCef);
cef_string_userfree_utf16_free(sourceOriginCef);
return ret;
}