55/**
66 * Send
77 * - current URL
8- * - cookies of this page
98 * - all links found in this page
109 * to the native application.
1110 */
1211function sendCurrentState ( ) {
1312 let message = {
1413 'url' : document . location . href ,
15- 'urls' : getLinks ( ) ,
16- 'cookies' : getCookies ( )
14+ 'urls' : getLinks ( )
1715 } ;
1816
1917 webkit . messageHandlers . adsMessageHandler . postMessage ( message ) ;
@@ -38,56 +36,6 @@ function getLinks() {
3836 return urls ;
3937}
4038
41- /**
42- * Get all cookies for the current document.
43- *
44- * @return {Array<{name: string, value: string}> } containing all cookies.
45- */
46- function getCookies ( ) {
47- let cookiesList = safeCookiesList ( ) ;
48- let result = [ ] ;
49-
50- cookiesList . forEach ( cookie => {
51- var [ name , ...value ] = cookie . split ( '=' ) ;
52- // For that special cases where the value contains '='.
53- value = value . join ( "=" )
54-
55- result . push ( {
56- "name" : name ,
57- "value" : value
58- } ) ;
59- } ) ;
60-
61- return result ;
62- }
63-
64- // FXIOS-13891: WebKit process crashes on cross-origin cookie operation on about:blank tabs
65- // Helper method to verify via SecurityError earlier than touching the document crashes it
66- function safeCookiesList ( ) {
67- let documentCookies = [ ] ;
68-
69- const isNewTab = window . location . protocol == "about:" ;
70- const hasOpener = ! ! window . opener ;
71- const hasParent = hasOpener && window . opener . parent != window . opener ;
72-
73- // Special-casing only different origins coming from different frames in new tabs
74- if ( isNewTab && hasOpener && hasParent ) {
75- const frameParent = window . opener . parent ;
76- // Positively catch the SecurityError on the conditional as a way to not touch the cookie inside
77- try {
78- if ( frameParent . location . origin == window . opener . location . origin ) {
79- documentCookies = document . cookie . split ( "; " ) ;
80- }
81- } catch {
82- documentCookies = [ "" ] ;
83- }
84- } else {
85- documentCookies = document . cookie . split ( "; " ) ;
86- }
87-
88- return documentCookies ;
89- }
90-
9139// Whenever a page is first accessed or when loaded from cache
9240// send all needed data about the ads provider to the app.
9341const events = [ "pageshow" , "load" ] ;
0 commit comments