From 2aab30b7a6df013492bed1ce698f9fb4a6333c7d Mon Sep 17 00:00:00 2001 From: Kin Blas Date: Fri, 18 Mar 2011 17:53:06 -0700 Subject: [PATCH 1/2] Initial changes to allow for cross-domain URLs to be loaded as pages within Phone Gap's web view. I still need to figure out how we're going to set the application URL hash for these cross-domain URLs, and allow for reloading the URL via deep links. --- js/jquery.mobile.navigation.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index a89851e0..0db6b86e 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -279,6 +279,9 @@ //history stack $.mobile.urlHistory = urlHistory; + //enable cross-domain page support + $.mobile.allowCrossDomainPages = false; + // changepage function $.mobile.changePage = function( to, transition, reverse, changeHash, fromHashChange ){ //from is always the currently viewed page @@ -667,10 +670,8 @@ //rel set to external isEmbeddedPage = path.isEmbeddedPage( url ), - //check for protocol or rel and its not an embedded page - //TODO overlap in logic from isExternal, rel=external check should be - // moved into more comprehensive isExternalLink - isExternal = path.isExternal( url ) || (isRelExternal && !isEmbeddedPage), + //is the url something browser should handle? + isExternal = false, //if target attr is specified we mimic _blank... for now hasTarget = $this.is( "[target]" ), @@ -678,6 +679,22 @@ //if data-ajax attr is set to false, use the default behavior of a link hasAjaxDisabled = $this.is( "[data-ajax='false']" ); + //check for protocol or rel and its not an embedded page + //TODO overlap in logic from isExternal, rel=external check should be + // moved into more comprehensive isExternalLink + if (path.isExternal(url)) { + // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR + // requests if the document doing the request was loaded via the file:// protocol. + // This is usually to allow the application to "phone home" and fetch app specific + // data. We normally let the browser handle external/cross-domain urls, but if the + // allowCrossDomainPages option is true, we will allow cross-domain http/https + // requests to go through our page loading logic. + isExternal = ($.mobile.allowCrossDomainPages && location.protocol === "file:" && url.search(/^https?:/) != -1) ? false : true; + } + else { + isExternal = (isRelExternal && !isEmbeddedPage); + } + //if there's a data-rel=back attr, go back in history if( $this.is( "[data-rel='back']" ) ){ window.history.back(); From 08fa6a2ac85f63ecc5124e5157119528fc760bbb Mon Sep 17 00:00:00 2001 From: Kin Blas Date: Mon, 21 Mar 2011 10:32:24 -0700 Subject: [PATCH 2/2] Got rid of the if/else isExternal check because we need to make sure we check cross domain URLs against isRelExternal. --- js/jquery.mobile.navigation.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 0db6b86e..348385b0 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -670,30 +670,24 @@ //rel set to external isEmbeddedPage = path.isEmbeddedPage( url ), - //is the url something browser should handle? - isExternal = false, - - //if target attr is specified we mimic _blank... for now - hasTarget = $this.is( "[target]" ), - - //if data-ajax attr is set to false, use the default behavior of a link - hasAjaxDisabled = $this.is( "[data-ajax='false']" ); - - //check for protocol or rel and its not an embedded page - //TODO overlap in logic from isExternal, rel=external check should be - // moved into more comprehensive isExternalLink - if (path.isExternal(url)) { // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR // requests if the document doing the request was loaded via the file:// protocol. // This is usually to allow the application to "phone home" and fetch app specific // data. We normally let the browser handle external/cross-domain urls, but if the // allowCrossDomainPages option is true, we will allow cross-domain http/https // requests to go through our page loading logic. - isExternal = ($.mobile.allowCrossDomainPages && location.protocol === "file:" && url.search(/^https?:/) != -1) ? false : true; - } - else { - isExternal = (isRelExternal && !isEmbeddedPage); - } + isCrossDomainPageLoad = ($.mobile.allowCrossDomainPages && location.protocol === "file:" && url.search(/^https?:/) != -1), + + //check for protocol or rel and its not an embedded page + //TODO overlap in logic from isExternal, rel=external check should be + // moved into more comprehensive isExternalLink + isExternal = (path.isExternal(url) && !isCrossDomainPageLoad) || (isRelExternal && !isEmbeddedPage), + + //if target attr is specified we mimic _blank... for now + hasTarget = $this.is( "[target]" ), + + //if data-ajax attr is set to false, use the default behavior of a link + hasAjaxDisabled = $this.is( "[data-ajax='false']" ); //if there's a data-rel=back attr, go back in history if( $this.is( "[data-rel='back']" ) ){