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 #15793 from alivedise/bugzilla/956938_v1.3/active-…
Browse files Browse the repository at this point in the history
…activity

Bug 956938 - Fix active activity reference
  • Loading branch information
alivedise committed Jan 29, 2014
2 parents 86f0489 + 6546e9a commit e31472a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 45 deletions.
19 changes: 12 additions & 7 deletions apps/system/js/activity_window.js
Expand Up @@ -203,7 +203,12 @@
if (this.activityCallee) {
this.activityCallee.kill();
}
if (this.activityCaller instanceof AppWindow) {
this.debug('request caller to open again');
if (this.activityCaller instanceof ActivityWindow) {
if (evt) {
this.activityCaller.open();
}
} else if (this.activityCaller instanceof AppWindow) {
// If we're killed by event handler, display the caller.
if (evt) {
// XXX: We should just request this.activityCaller.open()
Expand All @@ -215,21 +220,21 @@
WindowManager.setDisplayedApp(this.activityCaller.origin);
}
}
} else if (this.activityCaller instanceof ActivityWindow) {
if (evt) {
this.activityCaller.open();
}
} else {
console.warn('unknown window type of activity caller.');
}
this.containerElement.removeChild(this.element);
var e = this.containerElement.removeChild(this.element);
this.debug('removed ' + e);
this.publish('removed');
}.bind(this));
} else {
this.publish('terminated');
if (this.activityCallee) {
this.activityCallee.kill();
}
this.containerElement.removeChild(this.element);
var e = this.containerElement.removeChild(this.element);
this.debug('removed ' + e);
this.publish('removed');
}
this.debug('killed by ', evt ? evt.type : 'direct function call.');
this.activityCaller.unsetActivityCallee();
Expand Down
49 changes: 42 additions & 7 deletions apps/system/js/activity_window_factory.js
@@ -1,4 +1,6 @@
(function(window) {
var DEBUG = false;

var ActivityWindowFactory = {
// Last created activtiy window object.
_lastActivity: null,
Expand All @@ -7,6 +9,14 @@

_activities: [],

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

init: function acwf_init() {
window.addEventListener('mozChromeEvent', this);
window.addEventListener('launchapp', this);
Expand All @@ -28,6 +38,7 @@
},

handleEvent: function acwf_handleEvent(evt) {
this.debug('handling ' + evt.type);
switch (evt.type) {
// XXX: Move into appWindow.
case 'appopen':
Expand Down Expand Up @@ -70,9 +81,10 @@

case 'launchapp':
if (evt.detail.isActivity && evt.detail.inline) {
if (this._lastActivity && this._lastActivity.isActive()) {
if (this._activeActivity) {
this.debug('caller is an activity: ', this._activeActivity.name);
// If we already has a callee, remove it.
var callee = this._lastActivity.activityCallee;
var callee = this._activeActivity.activityCallee;
if (callee) {
// XXX: We don't know the activity is the same request
// or not here. The data passed may be different.
Expand All @@ -99,15 +111,16 @@
});
// If the lastActivity is the same as launch request, we don't
// need to create another activity.
if (this._lastActivity.manifestURL === evt.detail.manifestURL &&
this._lastActivity.url === evt.detail.url) {
if (this._activeActivity.manifestURL === evt.detail.manifestURL &&
this._activeActivity.url === evt.detail.url) {
return;
}
this._lastActivity = new ActivityWindow(evt.detail,
this._lastActivity);
this._activeActivity);
break;
}
var app = WindowManager.getCurrentActiveAppWindow();
this.debug('caller is an app: ' + (app && app.name));
var callee = app.activityCallee;
if (callee) {
// XXX: We don't know the activity is the same request
Expand Down Expand Up @@ -160,16 +173,38 @@
break;

case 'activitywillopen':
this._activeActivity = evt.detail;
var activity = evt.detail;
this.debug('activity: ' + activity.name +
' is opening, its caller is ' + activity.activityCaller.name);
this._activeActivity = activity;
break;

/**
* We should implement API to find out real active frame
* but now we only try to guess.
*/
case 'activitywillclose':
if (this._activeActivity &&
var activity = evt.detail;
this.debug('activity: ' + activity.name +
' is closing, its caller is ' + activity.activityCaller.name);
if (activity.activityCaller &&
activity.activityCaller instanceof ActivityWindow) {
this._activeActivity = activity.activityCaller;
} else if (this._activeActivity &&
this._activeActivity.instanceID == evt.detail.instanceID) {
this._activeActivity = null;
}
break;
}
},
_dump: function() {
if (DEBUG) {
this.debug('dump all activity windows');
var a = document.querySelectorAll('.activityWindow > iframe');
for (var i = 0; i < a.length; i++) {
this.debug(a[i].src);
}
}
}
};

Expand Down
40 changes: 9 additions & 31 deletions apps/system/test/unit/activity_window_factory_test.js
Expand Up @@ -177,32 +177,34 @@ suite('system/ActivityWindowFactory', function() {
})
};
MockWindowManager.mDisplayedApp = 'fake';
resetActivityWindowFactory();
});
teardown(function() {
});

function resetActivityWindowFactory() {
ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activeActivity = null;
ActivityWindowFactory._activities = [];
};
test('activity request', function() {
ActivityWindowFactory.handleEvent(fakeLaunchConfig1);

assert.isTrue(ActivityWindowFactory._lastActivity != null);

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});

test('back to home: one inline activity', function() {
ActivityWindowFactory._activeActivity = null;
ActivityWindowFactory.handleEvent(fakeLaunchConfig1);
var activity = ActivityWindowFactory._lastActivity;
console.log(ActivityWindowFactory);
var stubKill = this.sinon.stub(activity, 'kill');

ActivityWindowFactory.handleEvent({
'type': 'home'
});

assert.isTrue(stubKill.called);
stubKill.restore();

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});

test('second activity request on the same caller', function() {
Expand All @@ -216,11 +218,6 @@ suite('system/ActivityWindowFactory', function() {
ActivityWindowFactory.handleEvent(fakeLaunchConfig2);

assert.isTrue(stubKill.called);
stubKill.restore();
stubActive.restore();

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});


Expand All @@ -232,9 +229,6 @@ suite('system/ActivityWindowFactory', function() {
// launch again.
ActivityWindowFactory.handleEvent(fakeLaunchConfig1);
assert.equal(ActivityWindowFactory._activities.length, 1);

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});

test('maintain activity: created', function() {
Expand All @@ -247,8 +241,6 @@ suite('system/ActivityWindowFactory', function() {
});

assert.isTrue(ActivityWindowFactory._activities.length === current + 1);
ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});

test('maintain activity: terminated', function() {
Expand All @@ -263,9 +255,6 @@ suite('system/ActivityWindowFactory', function() {
});

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

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});

test('show current activity', function() {
Expand All @@ -279,10 +268,6 @@ suite('system/ActivityWindowFactory', function() {
});

assert.isTrue(stubSetVisible.calledWith(true));
stubSetVisible.restore();

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});

test('hide current activity', function() {
Expand All @@ -296,10 +281,6 @@ suite('system/ActivityWindowFactory', function() {
});

assert.isTrue(stubSetVisible.calledWith(false));
stubSetVisible.restore();

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});

test('update active activity', function() {
Expand All @@ -324,9 +305,6 @@ suite('system/ActivityWindowFactory', function() {
});

assert.equal(ActivityWindowFactory._activeActivity, activity);

ActivityWindowFactory._lastActivity = null;
ActivityWindowFactory._activities = [];
});
});
});

0 comments on commit e31472a

Please sign in to comment.