Skip to content

Commit

Permalink
Bug 1050164 - Investigate to implement standalone shrinking library
Browse files Browse the repository at this point in the history
  • Loading branch information
cctuan committed Aug 22, 2014
1 parent 0e9ccaa commit faec291
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 55 deletions.
23 changes: 17 additions & 6 deletions apps/system/js/nfc_manager.js
Expand Up @@ -147,7 +147,8 @@
switch (tech) {
case 'P2P':
if (!msg.records.length) {
this._triggerP2PUI();
// this._triggerP2PUI();
this.checkP2PRegistration();
} else {
// if there are records in the msg we've got NDEF message shared
// by other device via P2P, this should be handled as regular NDEF
Expand Down Expand Up @@ -212,8 +213,9 @@
case 'shrinking-sent':
window.removeEventListener('shrinking-sent', this);
// Notify lower layers that User has acknowledged to send NDEF msg
window.dispatchEvent(new CustomEvent(
'dispatch-p2p-user-response-on-active-app', {detail: this}));
this.dispatchP2PUserResponse();
// window.dispatchEvent(new CustomEvent(
// 'dispatch-p2p-user-response-on-active-app', {detail: this}));
// Stop the P2P UI
window.dispatchEvent(new CustomEvent('shrinking-stop'));
break;
Expand Down Expand Up @@ -324,15 +326,21 @@
* @memberof NfcManager.prototype
* @param {string} manifestURL - manifest url of app to check
*/
checkP2PRegistration: function nm_checkP2PRegistration(manifestURL) {
checkP2PRegistration: function nm_checkP2PRegistration() {
var nfcdom = window.navigator.mozNfc;
if (!nfcdom) {
return;
}
var activeApp = window.AppWindowManager.getActiveApp();
var manifestURL = activeApp.getTopMostWindow().manifestURL ||
window.System.manifestURL;

var status = nfcdom.checkP2PRegistration(manifestURL);
status.onsuccess = () => {
if (status.result) {
var bottomMost = activeApp.getBottomMostWindow();
window.shrinkingUI.setElements(bottomMost.element,
bottomMost.element.parentNode);
// Top visible application's manifest Url is registered;
// Start Shrink / P2P UI and wait for user to accept P2P event
window.dispatchEvent(new CustomEvent('shrinking-start'));
Expand All @@ -356,12 +364,15 @@
* @memberof NfcManager.prototype
* @param {string} manifestURL - manifest url of the sharing app
*/
dispatchP2PUserResponse: function nm_dispatchP2PUserResponse(manifestURL) {
dispatchP2PUserResponse: function nm_dispatchP2PUserResponse() {
var nfcdom = window.navigator.mozNfc;
if (!nfcdom) {
return;
}

var activeApp = window.AppWindowManager.getActiveApp();
var manifestURL = activeApp.getTopMostWindow().manifestURL ||
window.System.manifestURL;
console.log(' dispatchP2PUserResponse ' + manifestURL);
nfcdom.notifyUserAcceptedP2P(manifestURL);
},

Expand Down

0 comments on commit faec291

Please sign in to comment.