Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #15764 from alivedise/bugzilla/956938/fix-activie-…
Browse files Browse the repository at this point in the history
…activity

Bug 956938 - Fix active activity
  • Loading branch information
alivedise committed Jan 29, 2014
2 parents 8a96149 + f0f0e89 commit c856a85
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 41 deletions.
10 changes: 8 additions & 2 deletions apps/system/js/activity_window.js
Expand Up @@ -218,6 +218,7 @@
// If caller is an instance of appWindow,
// tell AppWindowManager to open it.
// XXX: Call this.activityCaller.open() if open logic is done.
self.debug('request caller to open again');
if (self.activityCallee) {
self.activityCallee.kill();
}
Expand All @@ -233,15 +234,20 @@
} else {
console.warn('unknown window type of activity caller.');
}
self.element.parentNode.removeChild(self.element);

var e = self.element.parentNode.removeChild(self.element);
self.debug('removing ' + e);
self.publish('removed');
});
this.close();
} else {
this.publish('terminated');
if (this.activityCallee) {
this.activityCallee.kill();
}
this.element.parentNode.removeChild(this.element);
var e = this.element.parentNode.removeChild(this.element);
this.debug('removing ' + e);
this.publish('removed');
}
this.debug('killed by ', evt ? evt.type : 'direct function call.');
this.activityCaller.unsetActivityCallee();
Expand Down
39 changes: 29 additions & 10 deletions apps/system/js/activity_window_factory.js
@@ -1,4 +1,5 @@
(function(window) {
var DEBUG = false;
/**
* ActivityWindowFactory creates the inline activity window instance
* on demand.
Expand Down Expand Up @@ -38,13 +39,21 @@
*/
_activities: [],

debug: function awm_debug() {
if (DEBUG) {
console.log('[ActivityWindowFactory]' +
'[' + System.currentTime() + ']' +
Array.slice(arguments).concat());
}
},

init: function acwf_init() {
window.addEventListener('mozChromeEvent', this);
window.addEventListener('launchactivity', this);
window.addEventListener('activitycreated', this);
window.addEventListener('activityterminated', this);
window.addEventListener('activitywillopen', this);
window.addEventListener('activitywillclose', this);
window.addEventListener('activityopening', this);
window.addEventListener('activityclosing', this);
window.addEventListener('hidewindow', this);
window.addEventListener('showwindow', this);
window.addEventListener('appopen', this);
Expand Down Expand Up @@ -80,9 +89,10 @@
* @memberOf module:ActivityWindowFactory
*/
launchActivity: function acwf_launchActivity(configuration) {
if (this._lastActivity && this._lastActivity.isActive()) {
if (this._activeActivity) {
// If we already has a callee, remove it.
var callee = this._lastActivity.activityCallee;
var callee = this._activeActivity.activityCallee;
this.debug('caller is an activity ' + this._lastActivity);
if (callee) {
// XXX: We don't know the activity is the same request
// or not here. The data passed may be different.
Expand All @@ -109,15 +119,16 @@
});
// If the lastActivity is the same as launch request, we don't need to
// create another activity.
if (this._lastActivity.manifestURL === configuration.manifestURL &&
this._lastActivity.url === configuration.url) {
if (this._activeActivity.manifestURL === configuration.manifestURL &&
this._activeActivity.url === configuration.url) {
return;
}
this._lastActivity = new ActivityWindow(configuration,
this._lastActivity);
this._activeActivity);
return;
}
var app = AppWindowManager.getActiveApp();
this.debug('caller is an app: ', app && app.name);
if (app) {
var callee = app.activityCallee;
// XXX: We don't know the activity is the same request
Expand Down Expand Up @@ -207,12 +218,20 @@
this._lastActivity = evt.detail;
break;

case 'activitywillopen':
case 'activityopening':
this._activeActivity = evt.detail;
break;

case 'activitywillclose':
if (this._activeActivity &&
/**
* We should implement API to find out real active frame
* but now we only try to guess.
*/
case 'activityclosing':
var activity = evt.detail;
if (activity.activityCaller &&
activity.activityCaller instanceof ActivityWindow) {
this._activeActivity = activity.activityCaller;
} else if (this._activeActivity &&
this._activeActivity.instanceID == evt.detail.instanceID) {
this._activeActivity = null;
}
Expand Down
3 changes: 2 additions & 1 deletion apps/system/js/app_transition_controller.js
Expand Up @@ -283,7 +283,8 @@

var classes = ['enlarge', 'reduce', 'to-cardview', 'from-cardview',
'invoking', 'invoked', 'zoom-in', 'zoom-out',
'transition-opening', 'transition-closing', 'immediate'];
'transition-opening', 'transition-closing', 'immediate',
'slideleft', 'slideright'];

classes.forEach(function iterator(cls) {
this.app.element.classList.remove(cls);
Expand Down
34 changes: 6 additions & 28 deletions apps/system/test/unit/activity_window_factory_test.js
Expand Up @@ -129,8 +129,8 @@ suite('system/ActivityWindowFactory', function() {
}
};

var fakeOpenConfig4 = {
type: 'activitywillopen',
var fakeOpenConfig = {
type: 'activityopening',
detail: {
'isActivity': true,
'url': 'app://fakeact4.gaiamobile.org/pick.html',
Expand Down Expand Up @@ -199,11 +199,9 @@ suite('system/ActivityWindowFactory', function() {
ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activeActivity = null;
ActivityWindowFactory._activities = [];
ActivityWindowFactory.handleEvent(fakeOpenConfig4);
ActivityWindowFactory.handleEvent(fakeOpenConfig);

assert.isTrue(ActivityWindowFactory._activeActivity != null);
assert.equal(ActivityWindowFactory.getActiveWindow(),
ActivityWindowFactory._activeActivity);
});

test('back to home: one inline activity', function() {
Expand Down Expand Up @@ -234,26 +232,6 @@ suite('system/ActivityWindowFactory', function() {
delete activity1.activityCallee;
});

test('second activity request on the same caller which is an app',
function() {
ActivityWindowFactory._activities = [activity1, activity2, activity3];
ActivityWindowFactory._lastActivity = activity1;
ActivityWindowFactory._activeActivity = activity1;
var stubActive = this.sinon.stub(activity1, 'isActive');
stubActive.returns(false);
var stubGetActiveApp =
this.sinon.stub(MockAppWindowManager, 'getActiveApp');
stubGetActiveApp.returns(app1);
var stubActiveApp = this.sinon.stub(app1, 'isActive');
stubActiveApp.returns(true);
app1.activityCallee = activity1;
var stubKill = this.sinon.stub(activity1, 'kill');
ActivityWindowFactory.handleEvent(fakeLaunchConfig2);

assert.isTrue(stubKill.called);
delete activity1.activityCallee;
});

test('second activity request is the same as first activity',
function() {
ActivityWindowFactory._activities = [activity1];
Expand Down Expand Up @@ -320,17 +298,17 @@ suite('system/ActivityWindowFactory', function() {

test('update active activity', function() {
ActivityWindowFactory._activities = [activity1, activity2, activity3];
ActivityWindowFactory._lastActivity = activity1;
ActivityWindowFactory._activeActivity = activity1;
ActivityWindowFactory.handleEvent({
type: 'activitywillclose',
type: 'activityclosing',
detail: activity1,
stopImmediatePropagation: function() {}
});

assert.isTrue(ActivityWindowFactory._activeActivity == null);

ActivityWindowFactory.handleEvent({
type: 'activitywillopen',
type: 'activityopening',
detail: activity1,
stopImmediatePropagation: function() {}
});
Expand Down

0 comments on commit c856a85

Please sign in to comment.