Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7003)

Unified Diff: chrome/renderer/resources/offline.js

Issue 638233005: Fix broken icon on iOS offline interstitial (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/resources/offline.js
diff --git a/chrome/renderer/resources/offline.js b/chrome/renderer/resources/offline.js
index d0f60c9f9626c90c62927c2694870affd9c40ab0..27f9d80847abfe283f635e5c5c60e2ada204da94 100644
--- a/chrome/renderer/resources/offline.js
+++ b/chrome/renderer/resources/offline.js
@@ -87,6 +87,8 @@ var IS_MOBILE = window.navigator.userAgent.indexOf('Mobi') > -1;
/** @const */
var IS_TOUCH_ENABLED = 'ontouchstart' in window;
+/** @const */
+var IS_IOS = window.navigator.userAgent.indexOf('CriOS') > -1;
/**
* Default game configuration.
@@ -251,19 +253,22 @@ Runner.prototype = {
* Load and decode base 64 encoded sounds.
*/
loadSounds: function() {
- this.audioContext = new AudioContext();
- var resourceTemplate =
- document.getElementById(this.config.RESOURCE_TEMPLATE_ID).content;
-
- for (var sound in Runner.sounds) {
- var soundSrc = resourceTemplate.getElementById(Runner.sounds[sound]).src;
- soundSrc = soundSrc.substr(soundSrc.indexOf(',') + 1);
- var buffer = decodeBase64ToArrayBuffer(soundSrc);
-
- // Async, so no guarantee of order in array.
- this.audioContext.decodeAudioData(buffer, function(index, audioData) {
- this.soundFx[index] = audioData;
- }.bind(this, sound));
+ if (!IS_IOS) {
+ this.audioContext = new AudioContext();
+ var resourceTemplate =
+ document.getElementById(this.config.RESOURCE_TEMPLATE_ID).content;
+
+ for (var sound in Runner.sounds) {
+ var soundSrc =
+ resourceTemplate.getElementById(Runner.sounds[sound]).src;
+ soundSrc = soundSrc.substr(soundSrc.indexOf(',') + 1);
+ var buffer = decodeBase64ToArrayBuffer(soundSrc);
+
+ // Async, so no guarantee of order in array.
+ this.audioContext.decodeAudioData(buffer, function(index, audioData) {
+ this.soundFx[index] = audioData;
+ }.bind(this, sound));
+ }
}
},
@@ -457,7 +462,7 @@ Runner.prototype = {
update: function() {
this.drawPending = false;
- var now = performance.now();
+ var now = getTimeStamp();
var deltaTime = now - (this.time || now);
this.time = now;
@@ -623,7 +628,7 @@ Runner.prototype = {
this.tRex.speedDrop = false;
} else if (this.crashed) {
// Check that enough time has elapsed before allowing jump key to restart.
- var deltaTime = performance.now() - this.time;
+ var deltaTime = getTimeStamp() - this.time;
if (Runner.keycodes.RESTART[keyCode] ||
(e.type == Runner.events.MOUSEUP && e.target == this.canvas) ||
@@ -683,7 +688,7 @@ Runner.prototype = {
}
// Reset the time clock.
- this.time = performance.now();
+ this.time = getTimeStamp();
},
stop: function() {
@@ -698,7 +703,7 @@ Runner.prototype = {
this.activated = true;
this.paused = false;
this.tRex.update(0, Trex.status.RUNNING);
- this.time = performance.now();
+ this.time = getTimeStamp();
this.update();
}
},
@@ -712,7 +717,7 @@ Runner.prototype = {
this.distanceRan = 0;
this.setSpeed(this.config.SPEED);
- this.time = performance.now();
+ this.time = getTimeStamp();
this.containerEl.classList.remove(Runner.classes.CRASHED);
this.clearCanvas();
this.distanceMeter.reset(this.highestScore);
@@ -808,8 +813,8 @@ function getRandomNum(min, max) {
* @param {number} duration Duration of the vibration in milliseconds.
*/
function vibrate(duration) {
- if (IS_MOBILE) {
- window.navigator['vibrate'](duration);
+ if (IS_MOBILE && window.navigator.vibrate) {
+ window.navigator.vibrate(duration);
}
}
@@ -851,6 +856,15 @@ function decodeBase64ToArrayBuffer(base64String) {
}
+/**
+ * Return the current timestamp.
+ * @return {number}
+ */
+function getTimeStamp() {
+ return IS_IOS ? new Date().getTime() : performance.now();
+}
+
+
//******************************************************************************
@@ -1424,7 +1438,7 @@ Trex.prototype = {
this.currentAnimFrames = Trex.animFrames[opt_status].frames;
if (opt_status == Trex.status.WAITING) {
- this.animStartTime = performance.now();
+ this.animStartTime = getTimeStamp();
this.setBlinkDelay();
}
}
@@ -1436,7 +1450,7 @@ Trex.prototype = {
}
if (this.status == Trex.status.WAITING) {
- this.blink(performance.now());
+ this.blink(getTimeStamp());
} else {
this.draw(this.currentAnimFrames[this.currentFrame], 0);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698