From 70c2e3a2b688378bdecce849e0d7db809662b872 Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Fri, 20 Jan 2017 23:04:59 +0100 Subject: [PATCH 1/4] fix($snifferProvider): allow history for nwjs applications Previously`sniffer` incorrectly detected NW.js applications as `chromePackagedApp` disallowing them to make use of the history API. This commit does detect NW.js applications allowing them to make use of the History API. Fixes #15474 --- src/ng/sniffer.js | 3 ++- test/ng/snifferSpec.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ng/sniffer.js b/src/ng/sniffer.js index be6af00029ed..11a396c87686 100644 --- a/src/ng/sniffer.js +++ b/src/ng/sniffer.js @@ -29,7 +29,8 @@ function $SnifferProvider() { $window.chrome && ($window.chrome.app && $window.chrome.app.runtime || !$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id), - hasHistoryPushState = !isChromePackagedApp && $window.history && $window.history.pushState, + isNw = $window.nw && $window.nw.process, + hasHistoryPushState = (isNw || !isChromePackagedApp) && $window.history && $window.history.pushState, android = toInt((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]), boxee = /Boxee/i.test(($window.navigator || {}).userAgent), diff --git a/test/ng/snifferSpec.js b/test/ng/snifferSpec.js index 50f90ec842c7..cb71688730f7 100644 --- a/test/ng/snifferSpec.js +++ b/test/ng/snifferSpec.js @@ -25,6 +25,25 @@ describe('$sniffer', function() { }); + it('should be true if running inside nw.js', function() { + var mockWindow = { + nw: { + process: noop + }, + history: { + pushState: noop + }, + chrome: { + app: { + runtime: noop + } + } + }; + + expect(sniffer(mockWindow).history).toBe(true); + }); + + it('should be false if history or pushState not defined', function() { expect(sniffer({}).history).toBe(false); expect(sniffer({history: {}}).history).toBe(false); From b874d7e413bc696960b73d4f69698610a75188f4 Mon Sep 17 00:00:00 2001 From: "PRIJCK Frederik (FPRJ)" Date: Thu, 26 Jan 2017 13:28:46 +0100 Subject: [PATCH 2/4] fixup! fix($snifferProvider): allow history for nwjs applications --- src/ng/sniffer.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ng/sniffer.js b/src/ng/sniffer.js index 11a396c87686..88852a0cb9e6 100644 --- a/src/ng/sniffer.js +++ b/src/ng/sniffer.js @@ -20,17 +20,19 @@ function $SnifferProvider() { this.$get = ['$window', '$document', function($window, $document) { var eventSupport = {}, + isNw = $window.nw && $window.nw.process, // Chrome Packaged Apps are not allowed to access `history.pushState`. // If not sandboxed, they can be detected by the presence of `chrome.app.runtime` // (see https://developer.chrome.com/apps/api_index). If sandboxed, they can be detected by // the presence of an extension runtime ID and the absence of other Chrome runtime APIs // (see https://developer.chrome.com/apps/manifest/sandbox). isChromePackagedApp = + !isNw && $window.chrome && ($window.chrome.app && $window.chrome.app.runtime || !$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id), - isNw = $window.nw && $window.nw.process, - hasHistoryPushState = (isNw || !isChromePackagedApp) && $window.history && $window.history.pushState, + + hasHistoryPushState = !isChromePackagedApp && $window.history && $window.history.pushState, android = toInt((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]), boxee = /Boxee/i.test(($window.navigator || {}).userAgent), From 0bf1d8a3b5e8baff35addc1ab9db918f5043fb31 Mon Sep 17 00:00:00 2001 From: "PRIJCK Frederik (FPRJ)" Date: Thu, 26 Jan 2017 13:30:33 +0100 Subject: [PATCH 3/4] fixup! fix($snifferProvider): allow history for nwjs applications --- src/ng/sniffer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ng/sniffer.js b/src/ng/sniffer.js index 88852a0cb9e6..2b0a8c9651b9 100644 --- a/src/ng/sniffer.js +++ b/src/ng/sniffer.js @@ -31,7 +31,6 @@ function $SnifferProvider() { $window.chrome && ($window.chrome.app && $window.chrome.app.runtime || !$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id), - hasHistoryPushState = !isChromePackagedApp && $window.history && $window.history.pushState, android = toInt((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]), From 4a750d1cf9efcd9efe3ddf73a0b54c47c9dba36d Mon Sep 17 00:00:00 2001 From: "PRIJCK Frederik (FPRJ)" Date: Thu, 26 Jan 2017 15:10:45 +0100 Subject: [PATCH 4/4] fixup! fix($snifferProvider): allow history for nwjs applications --- src/ng/sniffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/sniffer.js b/src/ng/sniffer.js index 2b0a8c9651b9..5de405e8c570 100644 --- a/src/ng/sniffer.js +++ b/src/ng/sniffer.js @@ -27,7 +27,7 @@ function $SnifferProvider() { // the presence of an extension runtime ID and the absence of other Chrome runtime APIs // (see https://developer.chrome.com/apps/manifest/sandbox). isChromePackagedApp = - !isNw && + !isNw && $window.chrome && ($window.chrome.app && $window.chrome.app.runtime || !$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id),