Skip to content

Commit 5e1ccb5

Browse files
GuriaChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Fix dino runner initialization to not happen in subframes
+ introducing isSubFrame variable for better conditionals handling. + updateIconClass refactored to: * not to have game initialization under implicit condition * do not use additional undocumented property on classList object * decide which icon element to modify based on isSubFrame flag * keep only base 'icon' class and one that were passed in argument + updateIconClass call removed from jseval attribute in templates, to callback that run on document loads and updates + game initialization moved to callback that run on document loads and updates under proper conditions + neterror class is permanently added to body + `.offline button` removed since `offline` classname is used for gaming styling only Bug: 1223340 Change-Id: Id34e21d9b6129e7c4da11d95f4c0b5b79eb58939 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2987982 Reviewed-by: Edward Jung (EMEA) <edwardjung@chromium.org> Reviewed-by: Rebekah Potter <rbpotter@chromium.org> Commit-Queue: Edward Jung (EMEA) <edwardjung@chromium.org> Cr-Commit-Position: refs/heads/master@{#897867}
1 parent 5eda2a5 commit 5e1ccb5

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

components/neterror/resources/neterror.html

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
<script src="error_page_controller_ios.js"></script>
1919
</if>
2020
</head>
21-
<body id="t" style="font-family: $i18n{fontfamily}; font-size: $i18n{fontsize}">
21+
<body id="t" class="neterror" style="font-family: $i18n{fontfamily}; font-size: $i18n{fontsize}">
2222
<div id="main-frame-error" class="interstitial-wrapper">
2323
<div id="main-content">
24-
<div class="icon"
25-
jseval="updateIconClass(this.classList, iconClass)" alt=""></div>
24+
<div class="icon"></div>
2625
<div id="main-message">
2726
<h1>
2827
<span jsselect="heading" jsvalues=".innerHTML:msg"></span>
@@ -128,8 +127,7 @@ <h1>
128127
<div id="sub-frame-error">
129128
<!-- Show details when hovering over the icon, in case the details are
130129
hidden because they're too large. -->
131-
<div class="icon"
132-
jseval="updateIconClass(this.classList, iconClass)"></div>
130+
<div class="icon"></div>
133131
<div id="sub-frame-error-details" jsselect="summary" jsvalues=".innerHTML:msg"></div>
134132
</div>
135133

components/neterror/resources/neterror.js

+20-26
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ function diagnoseErrors() {
6565
// easier to support platforms that load the error page via different
6666
// mechanisms (Currently just iOS). We also use the subframe style for portals
6767
// as they are embedded like subframes and can't be interacted with by the user.
68+
let isSubFrame = false;
6869
if (window.top.location !== window.location || window.portalHost) {
6970
document.documentElement.setAttribute('subframe', '');
71+
isSubFrame = true;
7072
}
7173

7274
// Re-renders the error page using |strings| as the dictionary of values.
@@ -77,38 +79,20 @@ function updateForDnsProbe(strings) {
7779
onDocumentLoadOrUpdate();
7880
}
7981

80-
// Given the classList property of an element, adds an icon class to the list
81-
// and removes the icon class previously set with this method. Previous value
82-
// stored in 'last_icon_class' property of passed classList for future reference.
83-
// Initializes Dino Runner instance in case 'icon-offline' class was set.
84-
function updateIconClass(classList, newClass) {
85-
let oldClass;
86-
87-
if (classList.hasOwnProperty('last_icon_class')) {
88-
oldClass = classList['last_icon_class'];
89-
if (oldClass === newClass) {
90-
return;
91-
}
92-
}
82+
// Adds an icon class to the list and removes classes previously set.
83+
function updateIconClass(newClass) {
84+
const frameSelector = isSubFrame ? '#sub-frame-error' : '#main-frame-error';
85+
const iconEl = document.querySelector(frameSelector + ' .icon');
9386

94-
classList.add(newClass);
95-
if (oldClass !== undefined) {
96-
classList.remove(oldClass);
87+
if (iconEl.classList.contains(newClass)) {
88+
return;
9789
}
9890

99-
classList['last_icon_class'] = newClass;
100-
101-
if (newClass === 'icon-offline') {
102-
document.firstElementChild.classList.add('offline');
103-
new Runner('.interstitial-wrapper');
104-
} else {
105-
document.body.classList.add('neterror');
106-
}
91+
iconEl.className = 'icon ' + newClass;
10792
}
10893

10994
// Implements button clicks. This function is needed during the transition
110-
// between implementing these in trunk chromium and implementing them in
111-
// iOS.
95+
// between implementing these in trunk chromium and implementing them in iOS.
11296
function reloadButtonClick(url) {
11397
if (window.errorPageController) {
11498
errorPageController.reloadButtonClick();
@@ -359,6 +343,16 @@ function onDocumentLoadOrUpdate() {
359343
const controlButtonDiv = document.getElementById('control-buttons');
360344
controlButtonDiv.hidden =
361345
offlineContentVisible || !(reloadButtonVisible || downloadButtonVisible);
346+
347+
const iconClass = loadTimeData.valueExists('iconClass') &&
348+
loadTimeData.getValue('iconClass');
349+
350+
updateIconClass(iconClass);
351+
352+
if (!isSubFrame && iconClass === 'icon-offline') {
353+
document.documentElement.classList.add('offline');
354+
new Runner('.interstitial-wrapper');
355+
}
362356
}
363357

364358
function onDocumentLoad() {

components/security_interstitials/core/common/resources/interstitial_common.css

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ button {
2626
.lookalike-url button,
2727
.main-frame-blocked button,
2828
.neterror button,
29-
.offline button,
3029
.pdf button,
3130
.ssl button,
3231
.safe-browsing-billing button {

0 commit comments

Comments
 (0)