Created
January 29, 2015 11:11
-
-
Save rexboy7/91b5e16f481a03e43146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/apps/system/js/app_window_factory.js b/apps/system/js/app_window_factory.js | |
index 59fb9f3..e4a5a72 100644 | |
--- a/apps/system/js/app_window_factory.js | |
+++ b/apps/system/js/app_window_factory.js | |
@@ -1,5 +1,6 @@ | |
'use strict'; | |
-/* global applications, BrowserConfigHelper, AppWindow */ | |
+/* globals applications, BrowserConfigHelper, AppWindow, | |
+ WrapperFactory */ | |
/* jshint nonew: false */ | |
(function(exports) { | |
@@ -10,7 +11,7 @@ | |
* | |
* If gecko is asking us to open a webapp, | |
* AppWindowFactory would do the instantiation and let | |
- * AppWindowManager to do the following app opening control via | |
+ * appWindowManager to do the following app opening control via | |
* event <code>launchapp</code>. | |
* | |
* If gecko is asking us to open an inline activity page, | |
@@ -50,6 +51,7 @@ | |
window.addEventListener('open-app', this.preHandleEvent); | |
window.addEventListener('openwindow', this.preHandleEvent); | |
window.addEventListener('appopenwindow', this.preHandleEvent); | |
+ window.addEventListener('mozChromeEvent', this.preHandleEvent); | |
window.addEventListener('applicationready', (function appReady(e) { | |
window.removeEventListener('applicationready', appReady); | |
this._handlePendingEvents(); | |
@@ -97,8 +99,65 @@ | |
} | |
}, | |
+ handlePresentation: function awf_handlePresentation(detail) { | |
+ var parseUrl = detail.url.split('/'); | |
+ var protocol = parseUrl[0].toUpperCase(); | |
+ var manifestURL; | |
+ | |
+ parseUrl.length = 3; | |
+ if (protocol == 'APP:') { | |
+ manifestURL = parseUrl.join('/') + '/manifest.webapp'; | |
+ } else { | |
+ manifestURL = null; | |
+ } | |
+ var config = new BrowserConfigHelper({ | |
+ url: detail.url, | |
+ manifestURL: manifestURL | |
+ }); | |
+ | |
+ var cb = function(receivedapp) { | |
+ var evt = new CustomEvent('mozContentEvent', { | |
+ bubbles: true, | |
+ cancelable: false, | |
+ detail: { | |
+ type: 'presentation-receiver-launched', | |
+ id: detail.id, | |
+ frame: receivedapp.iframe | |
+ } | |
+ }); | |
+ window.dispatchEvent(evt); | |
+ }; | |
+ var app = window.appWindowManager.getApp(config.origin, config.manifestURL); | |
+ if (app) { | |
+ app.kill(); | |
+ } | |
+ window.addEventListener('appcreated', function awf_appcreated(evt) { | |
+ app = evt.detail; | |
+ | |
+ if (app.config.url == config.url) { | |
+ window.removeEventListener('appcreated', awf_appcreated); | |
+ cb(app); | |
+ } | |
+ }); | |
+ config.timestamp = detail.timestamp; | |
+ if (protocol == 'APP:') { | |
+ config.stayBackground = true; | |
+ this.launch(config); | |
+ } else { | |
+ config.oop = true; | |
+ WrapperFactory.launchWrapper(config); | |
+ } | |
+ }, | |
+ | |
handleEvent: function awf_handleEvent(evt) { | |
var detail = evt.detail; | |
+ | |
+ if (evt.type == 'mozChromeEvent' && | |
+ detail.type == 'presentation-launch-receiver') { | |
+ this.handlePresentation(evt.detail); | |
+ return; | |
+ } | |
+ | |
if (!detail.url && !detail.manifestURL) { | |
return; | |
} | |
@@ -212,3 +271,50 @@ | |
exports.AppWindowFactory = AppWindowFactory; | |
}(window)); | |
+ | |
+/** | |
+ * Test codes for Presentation APIs. | |
+ */ | |
+ | |
+/* | |
+setTimeout(function() { | |
+ window.addEventListener('mozContentEvent', function appopentest(evt) { | |
+ if (evt.detail.type == 'presentation-receiver-launched') { | |
+ window.removeEventListener('mozContentEvent', appopentest); | |
+ console.log("successful"); | |
+ console.log(evt.detail.frame); | |
+ } | |
+ }); | |
+ window.dispatchEvent(new CustomEvent('mozChromeEvent', {detail: { | |
+ type: 'presentation-launch-receiver', | |
+ url: 'app://email.gaiamobile.org/index.html' | |
+ }})); | |
+}, 20000); | |
+ | |
+setTimeout(function() { | |
+ window.addEventListener('mozContentEvent', function appopentest(evt) { | |
+ if (evt.detail.type == 'presentation-receiver-launched') { | |
+ window.removeEventListener('mozContentEvent', appopentest); | |
+ console.log("successful"); | |
+ console.log(evt.detail.frame); | |
+ } | |
+ }); | |
+ window.dispatchEvent(new CustomEvent('mozChromeEvent', {detail: { | |
+ type: 'presentation-launch-receiver', | |
+ url: 'app://email.gaiamobile.org/index.html' | |
+ }})); | |
+}, 40000); | |
+ | |
+setTimeout(function() { | |
+ window.addEventListener('mozContentEvent', function webpageopentest(evt) { | |
+ if (evt.detail.type == 'presentation-receiver-launched') { | |
+ window.removeEventListener('mozContentEvent', webpageopentest); | |
+ console.log("successful"); | |
+ console.log(evt.detail.frame); | |
+ } | |
+ }); | |
+ window.dispatchEvent(new CustomEvent('mozChromeEvent', {detail: { | |
+ type: 'presentation-launch-receiver', | |
+ url: 'http://www.google.com/' | |
+ }})); | |
+}, 30000); */ | |
diff --git a/apps/system/js/browser_config_helper.js b/apps/system/js/browser_config_helper.js | |
index 844fa53..1cc768e 100644 | |
--- a/apps/system/js/browser_config_helper.js | |
+++ b/apps/system/js/browser_config_helper.js | |
@@ -32,7 +32,7 @@ | |
* * oop: indicate it's running out of process or in process. | |
* | |
* @param {Object} [config] Config for creating appWindow. | |
- * @param {String} [config.appURL] The URL of the app or the page to be | |
+ * @param {String} [config.url] The URL of the app or the page to be | |
* opened. | |
* @param {String} [config.manifestURL] The manifest URL of the app. | |
* @param {String} [config.name] - optional The name of the app. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment