Skip to content

Commit

Permalink
updates to fix local caching for xdomain_only instances of the class,…
Browse files Browse the repository at this point in the history
… and better origin checking
  • Loading branch information
ecaroth committed Aug 25, 2016
1 parent 41e9cfd commit bdc82dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/xdomain_cookie.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
window.addEventListener('message', function(event){

var origin = event.origin || event.originalEvent.origin; // For Chrome, the origin property is in the event.originalEvent object.
if (origin !== _iframe_origin) return; //incoming message not from iframe page

if ( [_window_origin,_iframe_origin].indexOf(origin) === -1 ) return; //incoming message not from iframe page
//We must filter messages here to verify that it's the specific message/type we are looking for, and not from another script
var data = null;
try{
data = JSON.parse(event.data);
}catch(e){}

if(data && typeof data==='object' && 'msg_type' in data && data.msg_type==='xdsc_write' && 'namespace' in data && data.namespace === _namespace){
_set_local_cookie( data.cookie_name, data.cookie_val, parseInt(data.expires_days,10) );
//ping down to page again to update values of xdomain cookie data
Expand Down
3 changes: 3 additions & 0 deletions src/xdomain_cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
_set_cookie_in_iframe( cookie_name, cookie_value, expires_days );
}

//set local cached value
_xdomain_cookie_data[cookie_name] = cookie_value;

}

//function to call after instantiation to sync a cookie, supplying a cookie name, value to write if it does NOT exist, expires
Expand Down
2 changes: 2 additions & 0 deletions test/test_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

if(!cookie_val){

if(is_dev) console.log("SETTING EMPTY COOKIE", cookie_test_val);

xd_cookie.set( 'test_cookie', cookie_test_val, 30, xdomain_only );

//get again to verify that it was set
Expand Down

0 comments on commit bdc82dd

Please sign in to comment.