Skip to content

Commit 626e8ba

Browse files
committed
Merge pull request element-hq#283 from vector-im/kegan/blocking
Add feature-based browser blocking
2 parents f4ca30b + 633bbd8 commit 626e8ba

6 files changed

Lines changed: 157 additions & 6 deletions

File tree

‎.modernizr.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"minify": true,
3+
"classPrefix": "modernizr_",
4+
"options": [
5+
"setClasses"
6+
],
7+
"feature-detects": [
8+
"test/css/displaytable",
9+
"test/css/flexbox",
10+
"test/es5/specification",
11+
"test/css/objectfit",
12+
"test/storage/localstorage"
13+
]
14+
}

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"style": "bundle.css",
1212
"scripts": {
1313
"reskindex": "reskindex vector -h src/skins/vector/header",
14+
"build:modernizr": "modernizr -c .modernizr.json -d src/vector/modernizr.js",
1415
"build:css": "catw \"src/skins/vector/css/**/*.css\" -o vector/bundle.css -c uglifycss --no-watch",
1516
"build:compile": "babel --source-maps -d lib src",
1617
"build:bundle": "NODE_ENV=production webpack -p lib/vector/index.js vector/bundle.js",
@@ -27,6 +28,7 @@
2728
"filesize": "^3.1.2",
2829
"flux": "~2.0.3",
2930
"linkifyjs": "^2.0.0-beta.4",
31+
"modernizr": "^3.1.0",
3032
"matrix-js-sdk": "^0.3.0",
3133
"matrix-react-sdk": "^0.0.2",
3234
"q": "^1.4.1",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.mx_CompatibilityPage {
2+
width: 100%;
3+
height: 100%;
4+
background-color: #e55;
5+
}
6+
7+
.mx_CompatibilityPage_box {
8+
position: absolute;
9+
top: 0;
10+
bottom: 0;
11+
left: 0;
12+
right: 0;
13+
margin: auto;
14+
width: 500px;
15+
height: 300px;
16+
border: 1px solid;
17+
padding: 10px;
18+
background-color: #fcc;
19+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
21+
module.exports = React.createClass({
22+
displayName: 'CompatibilityPage',
23+
propTypes: {
24+
onAccept: React.PropTypes.func
25+
},
26+
27+
getDefaultProps: function() {
28+
return {
29+
onAccept: function() {} // NOP
30+
};
31+
},
32+
33+
onAccept: function() {
34+
this.props.onAccept();
35+
},
36+
37+
render: function() {
38+
39+
return (
40+
<div className="mx_CompatibilityPage">
41+
<div className="mx_CompatibilityPage_box">
42+
<p>Sorry, your browser is <b>not</b> able to run Vector.</p>
43+
<p>
44+
Buttons and images may appear out of place, communication may
45+
not be possible and all manner of chaos may be unleashed.
46+
</p>
47+
<p>
48+
Please install <a href={"https://www.google.com/chrome"}>Chrome</a> for
49+
the best experience.
50+
</p>
51+
<p>
52+
Though if you like taking risks with your life, you can still try it
53+
out by clicking that you understand the risks involved.
54+
</p>
55+
<button onClick={this.onAccept}>
56+
I understand the risks and wish to continue
57+
</button>
58+
</div>
59+
</div>
60+
);
61+
}
62+
});

‎src/vector/index.js‎

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

1717
'use strict';
1818

19+
var RunModernizrTests = require("./modernizr"); // this side-effects a global
1920
var React = require("react");
2021
var sdk = require("matrix-react-sdk");
2122
sdk.loadSkin(require('../skins/vector/skindex'));
@@ -25,6 +26,34 @@ var qs = require("querystring");
2526

2627
var lastLocationHashSet = null;
2728

29+
function checkBrowserFeatures(featureList) {
30+
if (!window.Modernizr) {
31+
console.error("Cannot check features - Modernizr global is missing.");
32+
return false;
33+
}
34+
var featureComplete = true;
35+
for (var i = 0; i < featureList.length; i++) {
36+
if (window.Modernizr[featureList[i]] === undefined) {
37+
console.error(
38+
"Looked for feature '%s' but Modernizr has no results for this. " +
39+
"Has it been configured correctly?", featureList[i]
40+
);
41+
return false;
42+
}
43+
if (window.Modernizr[featureList[i]] === false) {
44+
console.error("Browser missing feature: '%s'", featureList[i]);
45+
// toggle flag rather than return early so we log all missing features
46+
// rather than just the first.
47+
featureComplete = false;
48+
}
49+
}
50+
return featureComplete;
51+
}
52+
53+
var validBrowser = checkBrowserFeatures([
54+
"displaytable", "flexbox", "es5object", "es5function", "localstorage",
55+
"objectfit"
56+
]);
2857

2958
// We want to support some name / value pairs in the fragment
3059
// so we're re-using query string like format
@@ -84,14 +113,11 @@ var makeRegistrationUrl = function() {
84113
'#/register';
85114
}
86115

87-
var MatrixChat = sdk.getComponent('pages.MatrixChat');
88-
window.matrixChat = React.render(
89-
<MatrixChat onNewScreen={onNewScreen} registrationUrl={makeRegistrationUrl()} />,
90-
document.getElementById('matrixchat')
91-
);
92-
93116
window.addEventListener('hashchange', onHashChange);
94117
window.onload = function() {
118+
if (!validBrowser) {
119+
return;
120+
}
95121
routeUrl(window.location);
96122
loaded = true;
97123
if (lastLoadedScreen) {
@@ -100,3 +126,28 @@ window.onload = function() {
100126
}
101127
}
102128

129+
function loadApp() {
130+
if (validBrowser) {
131+
var MatrixChat = sdk.getComponent('pages.MatrixChat');
132+
window.matrixChat = React.render(
133+
<MatrixChat onNewScreen={onNewScreen} registrationUrl={makeRegistrationUrl()} />,
134+
document.getElementById('matrixchat')
135+
);
136+
}
137+
else {
138+
console.error("Browser is missing required features.");
139+
// take to a different landing page to AWOOOOOGA at the user
140+
var CompatibilityPage = require("../skins/vector/views/pages/CompatibilityPage");
141+
window.matrixChat = React.render(
142+
<CompatibilityPage onAccept={function() {
143+
validBrowser = true;
144+
console.log("User accepts the compatibility risks.");
145+
loadApp();
146+
window.onload(); // still do the same code paths for compatible clients
147+
}} />,
148+
document.getElementById('matrixchat')
149+
);
150+
}
151+
}
152+
153+
loadApp();

‎src/vector/modernizr.js‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)