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 #24642 from cctuan/1049439
Browse files Browse the repository at this point in the history
Bug 1049439 - change appWindowManager from singleton to class
  • Loading branch information
cctuan committed Oct 13, 2014
2 parents 6d50870 + c0ad769 commit c44510b
Show file tree
Hide file tree
Showing 52 changed files with 359 additions and 376 deletions.
4 changes: 2 additions & 2 deletions apps/system/js/activity_window_manager.js
@@ -1,4 +1,4 @@
/* global AppWindowManager */
/* global System */
'use strict';
(function(exports) {
/**
Expand Down Expand Up @@ -104,7 +104,7 @@
case 'activityrequesting':
// The request may come from the top most window
// or the system app, but we don't care here.
var caller = AppWindowManager.getActiveApp().getTopMostWindow();
var caller = System.currentApp.getTopMostWindow();
if (!this.activityPool.size) {
this.activityPool.set(caller.instanceID, true);
} else {
Expand Down
5 changes: 3 additions & 2 deletions apps/system/js/app_window_factory.js
@@ -1,5 +1,5 @@
'use strict';
/* global applications, BrowserConfigHelper, AppWindowManager, AppWindow */
/* global applications, BrowserConfigHelper, AppWindow */
/* jshint nonew: false */

(function(exports) {
Expand Down Expand Up @@ -181,7 +181,8 @@
config.url.indexOf('newtab.html') === -1) {
return;
}
var app = AppWindowManager.getApp(config.origin, config.manifestURL);
var app = window.appWindowManager.getApp(config.origin,
config.manifestURL);
if (app) {
if (config.evtType == 'appopenwindow') {
app.browser.element.src = config.url;
Expand Down
16 changes: 8 additions & 8 deletions apps/system/js/app_window_manager.js
Expand Up @@ -3,8 +3,6 @@
'use strict';

(function(exports) {
var screenElement = document.getElementById('screen');

/**
* AppWindowManager manages the interaction of AppWindow instances.
*
Expand All @@ -16,12 +14,14 @@
*
* @module AppWindowManager
*/
var AppWindowManager = {
var AppWindowManager = function() {};
AppWindowManager.prototype = {
DEBUG: false,
CLASS_NAME: 'AppWindowManager',
continuousTransition: false,

element: document.getElementById('windows'),
screen: document.getElementById('screen'),

/**
* Test the app is already running.
Expand Down Expand Up @@ -144,7 +144,7 @@
document.mozCancelFullScreen();
}

screenElement.classList.remove('fullscreen-app');
this.screen.classList.remove('fullscreen-app');

var switching = appCurrent && !appCurrent.isHomescreen &&
!appNext.isHomescreen;
Expand Down Expand Up @@ -257,7 +257,7 @@
*
* @memberOf module:AppWindowManager
*/
init: function awm_init() {
start: function awm_start() {
if (System.slowTransition) {
this.element.classList.add('slow-transition');
} else {
Expand Down Expand Up @@ -356,7 +356,7 @@
* tests to avoid breaking other tests.
* @memberOf module:AppWindowManager
*/
uninit: function awm_uninit() {
stop: function awm_stop() {
window.removeEventListener('launchapp', this);
window.removeEventListener('home', this);
window.removeEventListener('appcreated', this);
Expand Down Expand Up @@ -733,10 +733,10 @@
return;
}
var fullscreen = this._activeApp.isFullScreen();
screenElement.classList.toggle('fullscreen-app', fullscreen);
this.screen.classList.toggle('fullscreen-app', fullscreen);

var fullScreenLayout = this._activeApp.isFullScreenLayout();
screenElement.classList.toggle('fullscreen-layout-app', fullScreenLayout);
this.screen.classList.toggle('fullscreen-layout-app', fullScreenLayout);

// Resize when opened.
// Note: we will not trigger reflow if the final size
Expand Down
8 changes: 4 additions & 4 deletions apps/system/js/attention_window_manager.js
@@ -1,4 +1,4 @@
/* globals System, AppWindowManager, homescreenLauncher, SettingsListener,
/* globals System, homescreenLauncher, SettingsListener,
AttentionIndicator */
'use strict';

Expand Down Expand Up @@ -45,7 +45,7 @@

screen: document.getElementById('screen'),

start: function attwm_init() {
start: function attwm_start() {
this._instances = [];
this._openedInstances = new Map();
this.attentionIndicator = new AttentionIndicator(this);
Expand All @@ -69,7 +69,7 @@
window.addEventListener('rocketbar-overlayopened', this);
},

stop: function attwm_init() {
stop: function attwm_stop() {
this._instances = null;
this._openedInstances = null;
this.attentionIndicator.stop();
Expand Down Expand Up @@ -124,7 +124,7 @@
var candidate = null;
if (this._openedInstances.size === 0) {
this._topMostWindow = null;
candidate = AppWindowManager.getActiveApp();
candidate = System.currentApp;
} else {
this._openedInstances.forEach(function(instance) {
candidate = instance;
Expand Down
8 changes: 5 additions & 3 deletions apps/system/js/bootstrap.js
Expand Up @@ -15,7 +15,7 @@
ExternalStorageMonitor,
BrowserSettings, AppMigrator, SettingsMigrator, EuRoamingManager,
CellBroadcastSystem, EdgeSwipeDetector, QuickSettings,
BatteryOverlay, BaseModule */
BatteryOverlay, BaseModule, AppWindowManager */
'use strict';


Expand All @@ -40,9 +40,9 @@ window.addEventListener('load', function startup() {
* Register global instances and constructors here.
*/
function registerGlobalEntries() {
/** @global */
/** @global */
window.activityWindowManager = new ActivityWindowManager();
window.activityWindowManager.start();
/** @global */
window.secureWindowManager = window.secureWindowManager ||
new SecureWindowManager();
Expand All @@ -62,7 +62,7 @@ window.addEventListener('load', function startup() {

// To initilaize it after LockScreenWindowManager to block home button
// when the screen is locked.
window.AppWindowManager.init();
window.activityWindowManager.start();

/** @global */
window.textSelectionDialog = new TextSelectionDialog();
Expand Down Expand Up @@ -122,6 +122,8 @@ window.addEventListener('load', function startup() {
window.homescreenWindowManager.start();

// Please sort it alphabetically
window.appWindowManager = new AppWindowManager();
window.appWindowManager.start();
window.activities = new Activities();
window.accessibility = new Accessibility();
window.accessibility.start();
Expand Down
6 changes: 3 additions & 3 deletions apps/system/js/edge_swipe_detector.js
@@ -1,5 +1,5 @@
'use strict';
/* global AppWindowManager */
/* global System */
/* global FtuLauncher */
/* global layoutManager */
/* global SettingsListener */
Expand Down Expand Up @@ -344,8 +344,8 @@
// but we still want to redispatch touch events to the "overlayed"
// software home button
var softwareButtonOverlayed =
AppWindowManager.getActiveApp() &&
AppWindowManager.getActiveApp().isFullScreenLayout();
System.currentApp &&
System.currentApp.isFullScreenLayout();
if (softwareButtonOverlayed) {
return x > (layoutManager.width - softwareButtonManager.width) ||
y > (layoutManager.height - softwareButtonManager.height);
Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/icc_worker.js
Expand Up @@ -229,7 +229,7 @@ var icc_worker = {
var options = message.command.options;

// Check if device is idle or settings
var activeApp = AppWindowManager.getActiveApp();
var activeApp = System.currentApp;
var settingsOrigin = window.location.origin.replace('system', 'settings');
if (!options.isHighPriority && activeApp && !activeApp.isHomescreen &&
activeApp.origin !== settingsOrigin) {
Expand Down Expand Up @@ -344,7 +344,7 @@ var icc_worker = {
'icc.data': JSON.stringify(message)
});
reqIccData.onsuccess = function icc_getIccData() {
if (AppWindowManager.getApp(application)) {
if (window.appWindowManager.getApp(application)) {
return DUMP('Settings is running. Ignoring');
}
navigator.mozApps.mgmt.getAll().onsuccess = function gotApps(evt) {
Expand Down
9 changes: 4 additions & 5 deletions apps/system/js/layout_manager.js
@@ -1,5 +1,4 @@
/* global KeyboardManager, softwareButtonManager, System,
AppWindowManager */
/* global KeyboardManager, softwareButtonManager, System */
'use strict';

(function(exports) {
Expand Down Expand Up @@ -49,7 +48,7 @@
* @memberOf LayoutManager
*/
get height() {
var activeApp = AppWindowManager.getActiveApp();
var activeApp = System.currentApp;
var isFullScreenLayout = activeApp && activeApp.isFullScreenLayout();
var softwareButtonHeight = System.locked || isFullScreenLayout ?
0 : softwareButtonManager.height;
Expand All @@ -74,8 +73,8 @@
*/
get width() {
return window.innerWidth -
((AppWindowManager.getActiveApp() &&
AppWindowManager.getActiveApp().isFullScreenLayout()) ?
((System.currentApp &&
System.currentApp.isFullScreenLayout()) ?
0 : softwareButtonManager.width);
},

Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/media_playback.js
@@ -1,4 +1,4 @@
/* global Bluetooth, AppWindowManager, IACHandler */
/* global Bluetooth, IACHandler, appWindowManager */

'use strict';

Expand Down Expand Up @@ -124,7 +124,7 @@ MediaPlaybackWidget.prototype = {
var evt = new CustomEvent('displayapp', {
bubbles: true,
cancelable: true,
detail: AppWindowManager.getApp(this.origin)
detail: appWindowManager.getApp(this.origin)
});
window.dispatchEvent(evt);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/system/js/payment.js
Expand Up @@ -131,7 +131,7 @@ var Payment = {
_openTrustedUI: function _openTrustedUI(frame) {
// The payment flow is shown within the trusted UI with the name of
// the mozPay caller application as title.
var title = AppWindowManager.getActiveApp().name;
var title = System.currentApp.name;
title = title ? title : navigator.mozL10n.get('payment-flow');
TrustedUIManager.open(title, frame, this.chromeEventId);
},
Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/permission_manager.js
@@ -1,4 +1,4 @@
/* global LazyLoader, AppWindowManager, applications, ManifestHelper*/
/* global LazyLoader, System, applications, ManifestHelper*/
/* global Template*/
'use strict';
(function(exports) {
Expand Down Expand Up @@ -300,7 +300,7 @@
this.cancelRequest(this.fullscreenRequest);
this.fullscreenRequest = undefined;
}
if (detail.fullscreenorigin !== AppWindowManager.getActiveApp().origin) {
if (detail.fullscreenorigin !== System.currentApp.origin) {
var _ = navigator.mozL10n.get;
// The message to be displayed on the approval UI.
var message =
Expand Down
6 changes: 3 additions & 3 deletions apps/system/js/places.js
@@ -1,5 +1,5 @@
'use strict';
/* globals Promise, AppWindowManager, asyncStorage */
/* globals Promise, appWindowManager, asyncStorage */
/* exported Places */

(function(exports) {
Expand Down Expand Up @@ -142,7 +142,7 @@
* @memberof Places.prototype
*/
screenshotRequested: function(url) {
var app = AppWindowManager.getAppByURL(url);
var app = appWindowManager.getAppByURL(url);
if (!app || app.loading) {
this.screenshotQueue[url] = setTimeout(() => {
this.takeScreenshot(url);
Expand All @@ -158,7 +158,7 @@
delete this.screenshotQueue[url];
}

var app = AppWindowManager.getAppByURL(url);
var app = appWindowManager.getAppByURL(url);
if (!app) {
console.error('Couldnt find app for:', url);
return false;
Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/rocketbar.js
@@ -1,5 +1,5 @@
'use strict';
/* global AppWindowManager, SearchWindow, places */
/* global System, SearchWindow, places */

(function(exports) {

Expand Down Expand Up @@ -260,7 +260,7 @@
case 'global-search-request':
// XXX: fix the WindowManager coupling
// but currently the transition sequence is crucial for performance
var app = AppWindowManager.getActiveApp();
var app = System.currentApp;

// If the app is not a browser, retain the search value and activate.
if (app && !app.isBrowser()) {
Expand Down
5 changes: 2 additions & 3 deletions apps/system/js/screen_manager.js
@@ -1,6 +1,6 @@
'use strict';

/* globals SettingsListener, Bluetooth, StatusBar, AppWindowManager */
/* globals SettingsListener, Bluetooth, StatusBar, System */

var ScreenManager = {
/*
Expand Down Expand Up @@ -468,8 +468,7 @@ var ScreenManager = {
_reconfigScreenTimeout: function scm_reconfigScreenTimeout() {
// Remove idle timer if screen wake lock is acquired or
// if no app has been displayed yet.
if (this._screenWakeLocked || typeof(AppWindowManager) !== 'object' ||
!AppWindowManager.getActiveApp()) {
if (this._screenWakeLocked || !System.currentApp) {
this._setIdleTimeout(0);
// The screen should be turn off with shorter timeout if
// it was never unlocked.
Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/shrinking_ui.js
Expand Up @@ -25,7 +25,7 @@
*
*/

/* globals dump, Promise, AppWindowManager */
/* globals dump, Promise, System */
(function(exports) {
var ShrinkingUI = function() {
this._clearPreviousTilting = false;
Expand Down Expand Up @@ -60,7 +60,7 @@

get current() {
if (!this._clearPreviousTilting || !this.state.activeApp) {
var currentApp = AppWindowManager && AppWindowManager.getActiveApp();
var currentApp = System.currentApp;
if (!currentApp) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/software_button_manager.js
Expand Up @@ -3,7 +3,7 @@
/* global ScreenLayout */
/* global SettingsListener */
/* global OrientationManager */
/* global AppWindowManager */
/* global System */

(function(exports) {

Expand Down Expand Up @@ -96,7 +96,7 @@
_buttonRect: null,
_updateButtonRect: function() {
var isFullscreen = !!document.mozFullScreenElement;
var activeApp = AppWindowManager.getActiveApp();
var activeApp = System.currentApp;
var isFullscreenLayout = activeApp && activeApp.isFullScreenLayout();

var button;
Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/source_view.js
@@ -1,7 +1,7 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

/*global AppWindowManager, ScreenManager*/
/*global System, ScreenManager*/

'use strict';

Expand Down Expand Up @@ -101,7 +101,7 @@
document.body.appendChild(viewsource);
}

var url = AppWindowManager.getActiveApp().origin;
var url = System.currentApp.origin;
if (!url) {
// Assume the home screen is the visible app.
url = window.location.toString();
Expand Down

0 comments on commit c44510b

Please sign in to comment.