Sorry for all the comments. This code is pretty good. I'm just trying to help ...
6 years, 3 months ago
(2014-09-16 14:20:21 UTC)
#7
Sorry for all the comments. This code is pretty good. I'm just trying to help
you make it perfect.
https://codereview.chromium.org/545973003/diff/60001/chrome/renderer/resource...
File chrome/renderer/resources/neterror.html (right):
https://codereview.chromium.org/545973003/diff/60001/chrome/renderer/resource...
chrome/renderer/resources/neterror.html:83: <div id="offline-resources">
On 2014/09/16 13:14:30, edwardjung wrote:
> On 2014/09/15 17:35:43, arv wrote:
> > Can these be moved to js so you don't have to map them or duplicate the
> > name/lookup?
>
> As the page will be offline I can't access the resources via XHR or chrome://
so
> they have to be base 64 encoded. I wanted to manually base 64 encode all these
> assets and have them in the JS as you suggest but it causes a failure in the
> presubmit checks, 80 char width.
>
> I was also wondering in terms of maintenance whether this was a better
solution
> since you just leave all the encoding to grit. Ideally the I would just have
> grit be able to parse the JS and base 64 encode urls but I couldn't get it
> working.
>
> Do you have any other suggestions on this front?
I was thinking doing new Audio(src) and new Image(src)
But now that I understand that you are relying on grit to inline the resources I
can't think of any better solution that what you are already doing.
We could extend grit to do this kind of inlining in js files but I'm not sure it
is worth it.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
File chrome/renderer/resources/neterror.js (right):
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/neterror.js:138: setButtonLayout();
Wrong indentation. When you line break after function() { you only indent 2,
like this:
document.addEventListener('DOMContentLoaded', function() {
setButtonLayout();
if (document.querySelector('.icon-offline')) {
document.body.classList.add('offline');
new Runner('.interstitial-wrapper');
}
});
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
File chrome/renderer/resources/offline.js (right):
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:5: /**
Maybe 'use strict' to catch errors?
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:18: var Runner = function(outerContainerId,
opt_config) {
Prefer function declarations where allowed.
function Runner(outerContainerId, opt_config) {
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:62: // Singleton
Do we need this singleton pattern enforced in the code?
If you really want to enforce it you can use the following pattern:
function Runner(...) {
if (Runner.instance_) {
return Runner.instance_;
}
Runner.instance_ = this;
...
}
Since if the function returns an object when you do new Runner, that object is
used instead of the one that was allocated for new.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:70: window['Runner'] = Runner;
I think you should be able to just do @export on Runner
/** @export */
function Runner() {
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:91: Runner.prototype.updateConfigSetting =
function(setting, value) {
How about using an object literal so you do not have to repeat yourself all
over?
Runner.prototype = {
updateConfigSetting: function(setting, value) {
...
},
loadImages: function() {
...
}
};
// Statics are not as pretty :'(
Runner.config = { ... };
Runner.DEFAULT_WIDTH = ...;
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:137: Runner.DEFAULT_WIDTH = 600;
Now that you have an IIFE, there is really no reason to make these properties of
Runner. Just do:
var DEFAULT_WIDTH = 600;
or
/** @const */
var DEFAULT_WIDTH = 600;
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:238: Runner.audioContext = new
AudioContext();
Since you are using a singleton, maybe just create this in the constructor?
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:264: var buffer =
Runner.decodeBase64ToArrayBuffer(soundSrc);
Since you are doing the decoding here, you can put your resources inside a
<template> element so that the browser does not have to process them twice (once
as the page loads and once here).
To get the elements out of the template you need an extra step here.
var templateContent = document.getElementById(templateId).content;
for (...) {
var soundSrc = templateContent.getElementById(soundId).src;
}
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:2095: Runner.HorizonLine = function(canvas,
bgImg) {
Why not just HorizontalLine? The IIFE creates the scoping already.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:2247: 'CACTUS_SMALL':
images['CACTUS_SMALL'],
Wrong indentation.
this.obstacleImgs = {
'CACTUS_SMALL': images['CACTUS_SMALL'],
'CACTUS_LARGE': images['CACTUS_LARGE']
};
Why are these quoted?
this.obstacleImgs = {
CACTUS_SMALL: images.CACTUS_SMALL,
CACTUS_LARGE: images.CACTUS_LARGE
};
The only reason to quote them is that they are used by some external code that
is not part of your JSCompiler set of files.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:2310: var cloudSpeed = ((this.cloudSpeed /
1000) * deltaTime) * speed;
Too many parens
var cloudSpeed = this.cloudSpeed / 1000 * deltaTime * speed;
Is the end result of this that the security warnings and neterrors have the same ...
6 years, 3 months ago
(2014-09-16 15:08:34 UTC)
#9
Is the end result of this that the security warnings and neterrors have the same
visual appearance but different code? (Is there a refactoring step after this
one?)
edwardjung
On 2014/09/16 15:08:34, felt wrote: > Is the end result of this that the security ...
6 years, 3 months ago
(2014-09-17 09:13:21 UTC)
#10
On 2014/09/16 15:08:34, felt wrote:
> Is the end result of this that the security warnings and neterrors have the
same
> visual appearance but different code? (Is there a refactoring step after this
> one?)
This is correct. Same appearance but different template, using the same
interstitial_v2 styles. There will be some refactoring as mentioned in the
email.
edwardjung
Gone through and updated. Thanks. https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resources/neterror.js File chrome/renderer/resources/neterror.js (right): https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resources/neterror.js#newcode138 chrome/renderer/resources/neterror.js:138: setButtonLayout(); On 2014/09/16 14:20:20, ...
6 years, 3 months ago
(2014-09-17 12:12:35 UTC)
#11
Gone through and updated. Thanks.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
File chrome/renderer/resources/neterror.js (right):
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/neterror.js:138: setButtonLayout();
On 2014/09/16 14:20:20, arv wrote:
> Wrong indentation. When you line break after function() { you only indent 2,
> like this:
>
> document.addEventListener('DOMContentLoaded', function() {
> setButtonLayout();
> if (document.querySelector('.icon-offline')) {
> document.body.classList.add('offline');
> new Runner('.interstitial-wrapper');
> }
> });
Done.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
File chrome/renderer/resources/offline.js (right):
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:5: /**
On 2014/09/16 14:20:20, arv wrote:
> Maybe 'use strict' to catch errors?
Done.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:18: var Runner = function(outerContainerId,
opt_config) {
On 2014/09/16 14:20:21, arv wrote:
> Prefer function declarations where allowed.
>
> function Runner(outerContainerId, opt_config) {
Done.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:62: // Singleton
On 2014/09/16 14:20:21, arv wrote:
> Do we need this singleton pattern enforced in the code?
>
> If you really want to enforce it you can use the following pattern:
>
> function Runner(...) {
> if (Runner.instance_) {
> return Runner.instance_;
> }
> Runner.instance_ = this;
> ...
> }
>
> Since if the function returns an object when you do new Runner, that object is
> used instead of the one that was allocated for new.
Done.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:70: window['Runner'] = Runner;
On 2014/09/16 14:20:20, arv wrote:
> I think you should be able to just do @export on Runner
>
> /** @export */
> function Runner() {
As I'm no longer using the compiler, I'm removing these exports.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:91: Runner.prototype.updateConfigSetting =
function(setting, value) {
On 2014/09/16 14:20:21, arv wrote:
> How about using an object literal so you do not have to repeat yourself all
> over?
>
> Runner.prototype = {
> updateConfigSetting: function(setting, value) {
> ...
> },
> loadImages: function() {
> ...
> }
> };
>
> // Statics are not as pretty :'(
> Runner.config = { ... };
> Runner.DEFAULT_WIDTH = ...;
Done, here and elsewhere
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:137: Runner.DEFAULT_WIDTH = 600;
On 2014/09/16 14:20:21, arv wrote:
> Now that you have an IIFE, there is really no reason to make these properties
of
> Runner. Just do:
>
> var DEFAULT_WIDTH = 600;
>
> or
>
> /** @const */
> var DEFAULT_WIDTH = 600;
Done.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:238: Runner.audioContext = new
AudioContext();
On 2014/09/16 14:20:21, arv wrote:
> Since you are using a singleton, maybe just create this in the constructor?
Refactored.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:264: var buffer =
Runner.decodeBase64ToArrayBuffer(soundSrc);
On 2014/09/16 14:20:21, arv wrote:
> Since you are doing the decoding here, you can put your resources inside a
> <template> element so that the browser does not have to process them twice
(once
> as the page loads and once here).
>
> To get the elements out of the template you need an extra step here.
>
> var templateContent = document.getElementById(templateId).content;
> for (...) {
> var soundSrc = templateContent.getElementById(soundId).src;
> }
Done. Nice.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:2095: Runner.HorizonLine = function(canvas,
bgImg) {
On 2014/09/16 14:20:21, arv wrote:
> Why not just HorizontalLine? The IIFE creates the scoping already.
I guess this is from the habit of writing Closure JS keeping everything tightly
name spaced.
Renamed all the assets classes.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:2247: 'CACTUS_SMALL':
images['CACTUS_SMALL'],
On 2014/09/16 14:20:21, arv wrote:
> Wrong indentation.
>
> this.obstacleImgs = {
> 'CACTUS_SMALL': images['CACTUS_SMALL'],
> 'CACTUS_LARGE': images['CACTUS_LARGE']
> };
>
> Why are these quoted?
>
> this.obstacleImgs = {
> CACTUS_SMALL: images.CACTUS_SMALL,
> CACTUS_LARGE: images.CACTUS_LARGE
> };
>
> The only reason to quote them is that they are used by some external code that
> is not part of your JSCompiler set of files.
Fixed.
https://codereview.chromium.org/545973003/diff/80001/chrome/renderer/resource...
chrome/renderer/resources/offline.js:2310: var cloudSpeed = ((this.cloudSpeed /
1000) * deltaTime) * speed;
On 2014/09/16 14:20:20, arv wrote:
> Too many parens
>
> var cloudSpeed = this.cloudSpeed / 1000 * deltaTime * speed;
Done.
edwardjung
@arv did you have any more comments?
6 years, 3 months ago
(2014-09-19 09:02:30 UTC)
#12
@arv did you have any more comments?
arv (Not doing code reviews)
Sorry, this fell off my radar. A few more style nits. https://codereview.chromium.org/545973003/diff/120001/chrome/renderer/resources/offline.js File chrome/renderer/resources/offline.js (right): ...
6 years, 3 months ago
(2014-09-19 15:50:42 UTC)
#13
Did another pass to correct the comments. Thanks. https://codereview.chromium.org/545973003/diff/140001/chrome/renderer/resources/offline.js File chrome/renderer/resources/offline.js (right): https://codereview.chromium.org/545973003/diff/140001/chrome/renderer/resources/offline.js#newcode142 chrome/renderer/resources/offline.js:142: ], ...
6 years, 3 months ago
(2014-09-21 20:26:53 UTC)
#16
Thanks for the all the tips, learnt a lot. https://codereview.chromium.org/545973003/diff/200001/chrome/renderer/resources/offline.js File chrome/renderer/resources/offline.js (right): https://codereview.chromium.org/545973003/diff/200001/chrome/renderer/resources/offline.js#newcode81 chrome/renderer/resources/offline.js:81: ...
6 years, 3 months ago
(2014-09-22 17:50:26 UTC)
#20
Still LGTM Thanks for the extra cleanup. https://codereview.chromium.org/545973003/diff/220001/chrome/renderer/resources/offline.js File chrome/renderer/resources/offline.js (right): https://codereview.chromium.org/545973003/diff/220001/chrome/renderer/resources/offline.js#newcode87 chrome/renderer/resources/offline.js:87: var IS_TOUCHENABLED ...
6 years, 3 months ago
(2014-09-22 18:05:33 UTC)
#21
Try jobs failed on following builders: linux_chromium_rel_swarming on tryserver.chromium.linux (http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_rel_swarming/builds/18825)
6 years, 3 months ago
(2014-09-23 09:44:48 UTC)
#25
Nicely done! Didn't take long for the game to be discovered: http://thenextweb.com/google/2014/09/25/googles-latest-chrome-build-hidden-game-can-play-offline/
6 years, 2 months ago
(2014-09-25 17:41:19 UTC)
#31
Issue 545973003: Update network error template to new design
(Closed)
Created 6 years, 3 months ago by edwardjung
Modified 6 years, 2 months ago
Reviewers: arv (Not doing code reviews), felt, sky, dmazzoni
Base URL: https://chromium.googlesource.com/chromium/src.git@master
Comments: 154