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 #12414 from alivedise/bugzilla/905116_master_v7
Browse files Browse the repository at this point in the history
Bug 905116 - Implement Homescreen Window + Homescreen Launcher, r=timdream
  • Loading branch information
alivedise committed Sep 25, 2013
2 parents 7ddf9a8 + afd555a commit afb7f95
Show file tree
Hide file tree
Showing 17 changed files with 985 additions and 353 deletions.
2 changes: 2 additions & 0 deletions apps/system/index.html
Expand Up @@ -258,6 +258,8 @@
<script defer src="js/error.js"></script>
<script defer src="js/window.js"></script>
<script defer src="js/wrapper_factory.js"></script>
<script defer src="js/homescreen_window.js"></script>
<script defer src="js/homescreen_launcher.js"></script>
<script defer src="js/window_manager.js"></script>
<script defer src="js/app_window_factory.js"></script>

Expand Down
42 changes: 41 additions & 1 deletion apps/system/js/bootstrap.js
Expand Up @@ -5,7 +5,11 @@

window.addEventListener('load', function startup() {
function safelyLaunchFTU() {
WindowManager.retrieveHomescreen(FtuLauncher.retrieve.bind(FtuLauncher));
window.addEventListener('homescreen-ready', function onHomescreenReady() {
window.removeEventListener('homescreen-ready', onHomescreenReady);
FtuLauncher.retrieve();
});
HomescreenLauncher.init();
}

if (Applications.ready) {
Expand Down Expand Up @@ -34,6 +38,16 @@ window.addEventListener('load', function startup() {
// if the phone goes to sleep before any user interaction.
// Apparently it works because no other window has the focus at this point.
window.focus();

// With all important event handlers in place, we can now notify
// Gecko that we're ready for certain system services to send us
// messages (e.g. the radio).
// Note that shell.js starts listen for the mozContentEvent event at
// mozbrowserloadstart, which sometimes does not happen till window.onload.
var evt = new CustomEvent('mozContentEvent',
{ bubbles: true, cancelable: false,
detail: { type: 'system-message-listener-ready' } });
window.dispatchEvent(evt);
});

/* === Shortcuts === */
Expand Down Expand Up @@ -70,6 +84,32 @@ SettingsListener.observe(
}
);

// Use a setting in order to be "called" by settings app
navigator.mozSettings.addObserver(
'clear.remote-windows.data',
function clearRemoteWindowsData(setting) {
var shouldClear = setting.settingValue;
if (!shouldClear)
return;

// Delete all storage and cookies from our content processes
var request = navigator.mozApps.getSelf();
request.onsuccess = function() {
request.result.clearBrowserData();
};

// Reset the setting value to false
var lock = navigator.mozSettings.createLock();
lock.set({'clear.remote-windows.data': false});
});

// Cancel dragstart event to workaround
// https://bugzilla.mozilla.org/show_bug.cgi?id=783076
// which stops OOP home screen pannable with left mouse button on
// B2G/Desktop.
windows.addEventListener('dragstart', function(evt) {
evt.preventDefault();
}, true);

/* === XXX Bug 900512 === */
// On some devices touching the hardware home button triggers
Expand Down
9 changes: 7 additions & 2 deletions apps/system/js/browser_frame.js
Expand Up @@ -39,6 +39,11 @@ var BrowserFrame = (function invocation() {
// platform.
browser.setAttribute('mozbrowser', 'true');

// Give a name to the frame for differentiating between main frame and
// inline frame. With the name we can get frames of the same app using the
// window.open method.
browser.name = 'main';

if (config.oop)
browser.setAttribute('remote', 'true');

Expand Down Expand Up @@ -68,8 +73,8 @@ var BrowserFrame = (function invocation() {
// XXX: Those urls needs to be built dynamically.
if (config.url.startsWith(window.location.protocol +
'//communications.gaiamobile.org' +
window.location.port ?
'' : (':' + window.location.port) +
(window.location.port ?
'' : (':' + window.location.port)) +
'/dialer') ||
config.url.startsWith(window.location.protocol +
'//clock.gaiamobile.org')) {
Expand Down
89 changes: 89 additions & 0 deletions apps/system/js/homescreen_launcher.js
@@ -0,0 +1,89 @@
(function(window) {
var currentManifestURL = '';
var instance = undefined;
var _inited = false;

var HomescreenLauncher = {
ready: false,

get origin() {
// We don't really care the origin of homescreen,
// and it may change when we swap the homescreen app.
// So we use a fixed string here.
// XXX: We shall change WindowManager to use manifestURL
// to identify an app.
// See http://bugzil.la/913323
return 'homescreen';
},

init: function hl_init() {
if (_inited)
return;

_inited = true;

var self = this;
if (Applications.ready) {
this.fetchSettings();
} else {
window.addEventListener('applicationready', function onAppReady() {
window.removeEventListener('applicationready', onAppReady);
self.fetchSettings();
});
}

window.addEventListener('trusteduishow', this);
window.addEventListener('trusteduihide', this);
},

handleEvent: function hl_handleEvent(evt) {
switch (evt.type) {
case 'trusteduishow':
this.getHomescreen().toggle(true);
break;
case 'trusteduihide':
this.getHomescreen().toggle(false);
break;
}
},

fetchSettings: function hl_fetchSettings() {
var self = this;
SettingsListener.observe('homescreen.manifestURL', '',
function onRetrievingHomescreenManifestURL(value) {
var previousManifestURL = currentManifestURL;
currentManifestURL = value;
if (typeof(instance) !== 'undefined') {
if (previousManifestURL !== '' &&
previousManifestURL !== currentManifestURL) {
instance.kill();
instance = new HomescreenWindow(value);
// Dispatch 'homescreen is changed' event.
window.dispatchEvent(new CustomEvent('homescreen-changed'));
} else {
instance.ensure();
}
}

self.ready = true;
window.dispatchEvent(new CustomEvent('homescreen-ready'));
});
},

getHomescreen: function hl_getHomescreen() {
if (currentManifestURL === '') {
console.warn('HomescreenLauncher: not ready right now.');
return null;
}
if (typeof instance == 'undefined') {
instance = new HomescreenWindow(currentManifestURL);
return instance;
} else {
instance.ensure();
return instance;
}
}
};

window.HomescreenLauncher = HomescreenLauncher;
}(this));

0 comments on commit afb7f95

Please sign in to comment.