FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/core/BrowserUtils.cpp at main · ssh352/rstudio · GitHub
ssh352
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
BrowserUtils.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
150 lines (127 loc) · 3.78 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
BrowserUtils.cpp
Copy path
File metadata and controls
150 lines (127 loc) · 3.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* BrowserUtils.cpp
*
* Copyright (C) 2022 by Posit Software, PBC
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
boost/algorithm/string/predicate.hpp
>
#
include
<
core/BrowserUtils.hpp
>
#
include
<
core/RegexUtils.hpp
>
#
include
<
shared_core/SafeConvert.hpp
>
using
namespace
boost
::algorithm
;
namespace
rstudio
{
namespace
core
{
namespace
browser_utils
{
namespace
{
bool
hasRequiredBrowserVersion
(
const
std::string& userAgent,
const
boost::regex& versionRegEx,
double
requiredVersion)
{
double
detectedVersion = requiredVersion;
boost::smatch match;
if
(
regex_utils::search
(userAgent, match, versionRegEx))
{
std::string versionString = match[
1
];
detectedVersion = safe_convert::stringTo<
double
>(versionString,
detectedVersion);
if
(detectedVersion < requiredVersion)
return
false
;
}
return
true
;
}
}
//
anonymous namespace
bool
isChrome
(
const
std::string& userAgent)
{
return
contains
(userAgent,
"
Chrome
"
);
}
bool
isChromeOlderThan
(
const
std::string& userAgent,
double
version)
{
if
(
isChrome
(userAgent))
{
boost::regex
chromeRegEx
(
"
(?:Chrome)/(
\\
d{1,4})
"
);
return
!
hasRequiredBrowserVersion
(userAgent, chromeRegEx, version);
}
else
{
return
false
;
}
}
bool
isFirefox
(
const
std::string& userAgent)
{
return
contains
(userAgent,
"
Firefox
"
);
}
bool
isFirefoxOlderThan
(
const
std::string& userAgent,
double
version)
{
if
(
isFirefox
(userAgent))
{
boost::regex
ffRegEx
(
"
Firefox/(
\\
d{1,4})
"
);
return
!
hasRequiredBrowserVersion
(userAgent, ffRegEx, version);
}
else
{
return
false
;
}
}
bool
isSafari
(
const
std::string& userAgent)
{
return
(
contains
(userAgent,
"
Safari
"
) ||
contains
(userAgent,
"
AppleWebKit
"
)) &&
!
contains
(userAgent,
"
Chrome
"
);
}
bool
isQt
(
const
std::string& userAgent)
{
return
(
contains
(userAgent,
"
AppleWebKit
"
)) &&
contains
(userAgent,
"
Qt
"
);
}
bool
isSafariOlderThan
(
const
std::string& userAgent,
double
version)
{
if
(
isSafari
(userAgent))
{
boost::regex
safariRegEx
(
"
Version/(
\\
d{1,4}
\\
.
\\
d)
"
);
return
!
hasRequiredBrowserVersion
(userAgent, safariRegEx, version);
}
else
{
return
false
;
}
}
bool
hasRequiredBrowser
(
const
std::string& userAgent)
{
if
(
isChromeOlderThan
(userAgent,
69
))
{
//
Chrome user agent based on oldest supported Chrome release.
//
Ideally this should be version 71, but our QT browser in use for RDP is pinned at version 69.
//
See: https://endoflife.software/applications/browsers/google-chrome
return
false
;
}
else
if
(
isFirefoxOlderThan
(userAgent,
68
))
{
//
Firefox user agent based on oldest ESR release. See:
//
https://support.mozilla.org/en-US/kb/firefox-esr-release-cycle
return
false
;
}
else
if
(
isSafariOlderThan
(userAgent,
12.1
))
{
//
Safari user agent based on the Safari version on the oldest supported version of macOS.
//
See:
//
https://en.wikipedia.org/wiki/Safari_version_history
return
false
;
}
else
{
return
isChrome
(userAgent) ||
isFirefox
(userAgent) ||
isSafari
(userAgent);
}
}
}
//
namespace browser_utils
}
//
namespace core
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL