Skip to content

Commit

Permalink
Merge pull request mozilla-b2g#6860 from ochameau/wm-exception@816099
Browse files Browse the repository at this point in the history
Bug 816099: Fix various exeption when trying to run apps too "quickly".
  • Loading branch information
alivedise committed Dec 7, 2012
2 parents 35728c9 + 4dfd44f commit 33536a0
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions apps/system/js/window_manager.js
Expand Up @@ -275,6 +275,8 @@ var WindowManager = (function() {
function setOpenFrame(frame) {
if (openFrame) {
removeFrameClasses(openFrame);
} else if (openTimer) {
clearTimeout(openTimer);
}

openFrame = frame;
Expand All @@ -287,6 +289,8 @@ var WindowManager = (function() {
removeFrameClasses(closeFrame);
// closeFrame should not be set to active
closeFrame.classList.remove('active');
} else if (closeTimer) {
clearTimeout(closeTimer);
}

closeFrame = frame;
Expand Down Expand Up @@ -315,7 +319,8 @@ var WindowManager = (function() {

if (classList.contains('inlineActivity')) {
if (classList.contains('active')) {
openFrame.focus();
if (openFrame)
openFrame.focus();

setOpenFrame(null);
} else {
Expand All @@ -330,11 +335,14 @@ var WindowManager = (function() {
classList.remove('closing');
classList.add('closing-card');

openFrame.classList.remove('opening-card');
openFrame.classList.add('opening-switching');
if (openFrame) {
openFrame.classList.remove('opening-card');
openFrame.classList.add('opening-switching');
}
} else if (classList.contains('closing-card')) {
windowClosed(frame);
setTimeout(closeCallback);
closeCallback = null;

} else if (classList.contains('opening-switching')) {
// If the opening app need to be full screen, switch to full screen
Expand All @@ -351,7 +359,9 @@ var WindowManager = (function() {
});
} else if (classList.contains('opening')) {
windowOpened(frame);

setTimeout(openCallback);
openCallback = null;

setCloseFrame(null);
setOpenFrame(null);
Expand All @@ -363,12 +373,16 @@ var WindowManager = (function() {

if (classList.contains('opening')) {
windowOpened(frame);

setTimeout(openCallback);
openCallback = null;

setOpenFrame(null);
} else if (classList.contains('closing')) {
windowClosed(frame);

setTimeout(closeCallback);
closeCallback = null;

setCloseFrame(null);
}
Expand Down Expand Up @@ -637,7 +651,13 @@ var WindowManager = (function() {
// setFrameBackground(openFrame, gotBackground, true);
// will simply work here.

openCallback();
// Call the openCallback only once. We have to use tmp var as
// openCallback can be a method calling the callback
// (like the `removeFrame` callback in `kill()` ).
var tmpCallback = openCallback;
openCallback = null;
tmpCallback();

windows.classList.add('active');
openFrame.classList.add('homescreen');
openFrame.focus();
Expand All @@ -654,6 +674,8 @@ var WindowManager = (function() {
setFrameBackground(openFrame, function gotBackground() {
// Start the transition when this async/sync callback is called.
openTimer = setTimeout(function startOpeningTransition() {
if (!openFrame)
return;
if (!screenElement.classList.contains('switch-app')) {
openFrame.classList.add('opening');
} else {
Expand Down Expand Up @@ -878,8 +900,7 @@ var WindowManager = (function() {
if (!isFirstRunApplication) {
toggleHomescreen(true);
}
clearTimeout(openTimer);
clearTimeout(closeTimer);

setOpenFrame(null);
setCloseFrame(null);
screenElement.classList.remove('switch-app');
Expand Down Expand Up @@ -1109,10 +1130,12 @@ var WindowManager = (function() {
if (openFrame == frame) {
setOpenFrame(null);
setTimeout(openCallback);
openCallback = null;
}
if (closeFrame == frame) {
setCloseFrame(null);
setTimeout(closeCallback);
closeCallback = null;
}

delete runningApps[origin];
Expand Down Expand Up @@ -1453,6 +1476,7 @@ var WindowManager = (function() {
});
}


// Stop running the app with the specified origin
function kill(origin, callback) {
if (!isRunning(origin))
Expand Down

0 comments on commit 33536a0

Please sign in to comment.