-
Notifications
You must be signed in to change notification settings - Fork 7
/
SchemeHandlerHelper.cpp
76 lines (68 loc) · 2.59 KB
/
SchemeHandlerHelper.cpp
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
68
69
70
71
72
73
74
75
76
//! ========================================================================================
//! ExecutionGraph
//! Copyright (C) 2014 by Gabriel Nützi <gnuetzi (at) gmail (døt) com>
//!
//! @date Fri Feb 09 2018
//! @author Gabriel Nützi, gnuetzi (at) gmail (døt) com
//!
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/.
//! ========================================================================================
#include "cefapp/SchemeHandlerHelper.hpp"
#include <executionGraph/common/FileSystem.hpp>
namespace schemeHandlerHelper
{
//! Split the prefix `prefix` from the path `path`
std::optional<std::path> splitPrefixFromPath(const std::string& path, const std::path& prefix)
{
// path e.g. "////host/folderA/folderB/file.ext"
// Split all leeding slashes
auto itC = path.begin();
while(itC != path.end() && *itC == '/')
{
++itC;
}
std::path tempPath(itC, path.end());
// e.g. tempPath : "host/folderA/folderB/file.ext""
// Split pathPrefix from front (e.g prefix := "host/folderA")
auto it = tempPath.begin();
auto itEnd = tempPath.end();
auto itPref = prefix.begin();
auto itPrefEnd = prefix.end();
for(; it != itEnd && itPref != itPrefEnd; ++it, ++itPref)
{
if(*itPref != *it)
{
break;
}
}
if(itPref != itPrefEnd)
{
// Could not split pathPrefix
return {};
}
// Concat the tempPath together
std::path filePath;
while(it != itEnd)
{
filePath /= *it++;
}
return filePath;
}
//! Register all custom schemes for the application as standard and secure.
//! Must be the same implementation in all processes.
void registerCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
for(auto& scheme : getCustomSchemes())
{
registrar->AddCustomScheme(scheme,
true /* is standart*/,
false /* is local */,
false /* is display_isolated */,
true /* is secure */,
true /* is cors enabled*/,
false /* is_csp_bypassing*/);
}
}
} // namespace schemeHandlerHelper